//------------------------------------------------------------------------------ // Function: HdmiTask // Description: One time initialization at startup //------------------------------------------------------------------------------ static void HdmiTask(void) { if ((CurrentStatus.AudioState == STATE_AUDIO__REQUEST_AUDIO) || (CurrentStatus.AudioState == STATE_AUDIO__AUDIO_READY)) { if (TIMER_Expired(TIMER__AUDIO)) { AudioUnmuteHandler(); } } if (CurrentStatus.VideoState == STATE_VIDEO__UNMUTE) { if (TIMER_Expired(TIMER__VIDEO)) { DEBUG_PRINT(("v time out\n")); ResetVideoControl(); } } #if (PEBBLES_VIDEO_STATUS_2ND_CHECK==ENABLE) if (CurrentStatus.VideoState == STATE_VIDEO__ON) { if (TIMER_Expired(TIMER__VIDEO)) { PclkCheck(); TIMER_Set(TIMER__VIDEO, VIDEO_STABLITY_CHECK_INTERVAL); // start the video timer CurrentStatus.VideoStabilityCheckCount++; } if (CurrentStatus.VideoStabilityCheckCount == VIDEO_STABLITY_CHECK_TOTAL/VIDEO_STABLITY_CHECK_INTERVAL) { DEBUG_PRINT(("V CHECK %d times\n",(int)CurrentStatus.VideoStabilityCheckCount)); CurrentStatus.VideoState = STATE_VIDEO__CHECKED; CurrentStatus.VideoStabilityCheckCount = 0; } } #endif //#if (PEBBLES_VIDEO_STATUS_2ND_CHECK==ENABLE) }
//------------------------------------------------------------------------------ // Function: main // Description: Main loop //------------------------------------------------------------------------------ void sii9223a_main(void) { uint16_t wOldTickCnt = 0; uint16_t wNewTickCnt = 0; uint16_t wTickDiff; // HAL_Init(); // DEBUG_INIT(); DEBUG_PRINT(("AMF Pebble ES1_2 starter board version 2.3.0\n")); SystemInit(); while (1) { // if ( (!DEBUG_PAUSE_FIRMWARE) && (!GPIO_GetComMode()) ) // if ( !GPIO_GetComMode() ) { if (TIMER_Expired(TIMER__POLLING)) { TIMER_Set(TIMER__POLLING, 20); //poll every 20ms PollPortSwitch(); PollInterrupt(); } #if (CONF__CEC_ENABLE == ENABLE) CEC_Event_Handler(); #endif HdmiTask(); wNewTickCnt = TIMER_GetTickCounter(); if ( wNewTickCnt > wOldTickCnt ){ wTickDiff = wNewTickCnt - wOldTickCnt; } else { /* counter wrapping */ wTickDiff = ( 0xFFFF - wOldTickCnt ) + wNewTickCnt; } wTickDiff >>= 1; /* scaling ticks to ms */ if ( wTickDiff > 36 ){ wOldTickCnt = wNewTickCnt; HdmiProcIfTo( wTickDiff ); } } msleep(10); // DEBUG_POLL(); } }
int main ( void ) { static UNSIGNED16 checksum; UNSIGNED8 bootCrcValid; UNSIGNED8 appCrcValid; // Disable all interrupts (just in case we jumped here) Disable_interrupt(); // Initialize low-level hardware HW_Init(); // Initialize Flash/EEPROM module and routines FLASH_Init(); // Read node configuration and initialize status/error variables MAIN_Init(); // Initialize Timer TIMER_Init(); // Initialize CAN contoller CANHW_Init(); // Initialize SDO handler SDO_Init(); // Initialize Controls bootCrcValid = 0; appCrcValid = 0; #if 0 // If the bootloader is executed from power-up reset, initiate // waiting period of 60 seconds before attempting to start the // application. // Otherwise, we assume that the bootloader was called from the // application. In this case, send the bootup message (and don't // wait the 60 seconds). if ( gNodeStatus.run_mode == EXECMODE_POWERUP ) { // Set the timer for the main waiting period in number of ticks TIMER_Set(TIMER_MAIN, WAIT_TIMEOUT*(1000/TIMERTICK_MS)); gNodeStatus.run_mode = EXECMODE_TIMER; } else { gNodeStatus.run_mode = EXECMODE_NORMAL; } #endif // Calculat bootloader checksum bootCrcValid = FLASH_Checksum_OK(BL_CHECKSUM_START, BL_CHECKSUM_END, BL_CHECKSUM_ADR, &checksum); // Check the bootloader (provides reference for embedded CRC) if ((0 == bootCrcValid) || (boot_crc == checksum)) { // no error - do nothing ; } else { // Signal error. Extra info is the calculated checksum. MAIN_Signal_Error(ERRCODE_INTERNAL, checksum); } appCrcValid = FLASH_Checksum_OK(AP_CHECKSUM_START, AP_CHECKSUM_END, AP_CHECKSUM_ADR, &checksum); // Check the main application checksum and set error status if wrong if (0 == appCrcValid) { // no error - do nothing ; } else { // Signal error. Extra info is the calculated checksum. MAIN_Signal_Error(ERRCODE_USER, checksum); // Don't auto-start application after timeout gNodeStatus.run_mode = EXECMODE_NORMAL; } // start_code: 0=power-up, 1=external, 2=brown-out, 3=watchdog, 4=J-Tag, 5=jump if ( (0 == bootCrcValid) || (0 == appCrcValid) || (2 == gNodeStatus.start_code) || (3 == gNodeStatus.start_code) ) { CANHW_Send_Boot(); if ( (0 == bootCrcValid) ) { CANHW_Send_Emergency(0x8000, 1, 0, 0, 0, 0); } else if ( (2 == gNodeStatus.start_code) ) { CANHW_Send_Emergency(0x8000, 2, 0, 0, 0, 0); } else if ( (3 == gNodeStatus.start_code) ) { CANHW_Send_Emergency(0x8000, 3, 0, 0, 0, 0); } else if ( (0 == appCrcValid) ) { CANHW_Send_Emergency(0x8000, 4, 0, 0, 0, 0); } gNodeStatus.run_mode = EXECMODE_NORMAL; } else if ( (0 == gNodeStatus.start_code) || (1 == gNodeStatus.start_code) || (4 == gNodeStatus.start_code) ) { TIMER_Set(TIMER_MAIN, WAIT_TIMEOUT*(1000/TIMERTICK_MS)); gNodeStatus.run_mode = EXECMODE_TIMER; } else if ( (5 == gNodeStatus.start_code) ) { gNodeStatus.run_mode = EXECMODE_NORMAL; } else { // Set the location of the interrupt vectors to 0 MCUCR = BIT(IVCE); MCUCR = 0x00; // Call the absolute address RESVEC_ADR ((void(*)(void))RESVEC_ADR)(); } // Endless loop to execute the bootloader. The only exit point is // a jump to the application if the condition for execution is // fulfilled. for ( ;; ) { BOOLEAN message_processed; // Update timers TIMER_Poll(); // Serve the watchdog COP_Serve(); // Check for a waiting CAN message and process them (SDO, NMT). // This can change the execution mode! message_processed = CANHW_Process_Messages(); // If requested, check the application and jump to it, if successful if ( gNodeStatus.run_mode == EXECMODE_RUN ) { // Jump to main application, if the checksum is ok if ( FLASH_Checksum_OK(AP_CHECKSUM_START, AP_CHECKSUM_END, AP_CHECKSUM_ADR, &checksum) ) { // Set the location of the interrupt vectors to 0 MCUCR = BIT(IVCE); MCUCR = 0x00; // Call the absolute address RESVEC_ADR ((void(*)(void))RESVEC_ADR)(); } else { // Checksum not valid: Don't start application and report error, stay here CANHW_Send_Emergency(0x8000, 4, 0, 0, 0, 0); MAIN_Signal_Error(ERRCODE_USER, checksum); // Signal error. Extra info is the calculated checksum. gNodeStatus.run_mode = EXECMODE_NORMAL; } } else if ( gNodeStatus.run_mode == EXECMODE_TIMER ) { // check for other conditions when running in timed mode if ( message_processed ) { // After a successfully received message leave the timed mode gNodeStatus.run_mode = EXECMODE_NORMAL; } else if ( TIMER_Expired(TIMER_MAIN) ) { // Check for initial 60 second waiting period, if expired prepare // for running the application. gNodeStatus.run_mode = EXECMODE_RUN; } else { // do nothing ; } } else { // do nothing ; } } // for ever loop // don't return from here return(0); }