void sleep_long(unsigned long ms) { // float f_tm_count; // temporary to calcurate timer count unsigned long tmp_target_l; delay_flag = false; tmp_target_l = ((ms % 64000)<<8)/250; delay_time.target_l = (unsigned short)tmp_target_l; delay_time.target_h = ms / 64000; #ifdef _DEBUG Serial.print_long(delay_time.target_h,HEX); Serial.print("\t"); Serial.println_long(delay_time.target_l,HEX); #endif if(delay_time.target_h==0) { timer_16bit_set(6,0xE8,(unsigned short)tmp_target_l,delay_isr); delay_time.target_l = 0; } else { timer_16bit_set(6,0x68,0xFFFF,delay_isr); } // setup timer timer_16bit_start(6); #ifdef PWR_LED drv_digitalWrite(11,HIGH); // PWR LED OFF #endif while(delay_flag == false) { if((uart_tx_sending == true) || (uartf_tx_sending == true)) { lp_setHaltMode(); wdt_clear(); } else { lp_setDeepHaltMode(); wdt_clear(); } } timer_16bit_stop(6); #ifdef PWR_LED drv_digitalWrite(11,LOW); // PWR LED ON #endif return; }
void HALT_Until_Event(HALT_EVENT halt_event) { BOOLEAN cont; cont = true; while(cont) { lp_setHaltMode(); // process during waiting i2c_isr(0); i2c_isr(1); switch(halt_event) { case HALT_I2C1_END: if(i2c_get_status(1) <= I2C_MODE_ERROR) cont = false; break; case HALT_I2C0_END: if(i2c_get_status(0) <= I2C_MODE_ERROR) cont = false; break; default: cont = false; break; } wdt_clear(); } return; }
/** * \brief Asynchronous timer (ASF) handler for the QTouch acquisition. * and clear Watchdog counter - generates interrupt every 100ms */ static void ast_per_callback(void) { touch_sensors_update_time(); event_qtouch_sensors_idle_count++; ast_clear_interrupt_flag(AST, AST_INTERRUPT_PER); wdt_clear(); }
static void cipsend_ok_cb(void) //3分钟没有喂狗说明GPRS流程出现了问题 { xTimerStop(gprs_daemon_timer, 0); xSemaphoreGive(gprs_mutex); wdt_clear(SOFT_WDT); }
//! This function selects a file in EXPLORER mode //! //! @param b_direction direction of navigation (FS_FIND_NEXT or FS_FIND_PREV) //! @param options define extra modes for this function //! //! @return the status of the action //! static uint8_t navauto_mov_explorer_rec(bool b_direction, navauto_mov_options_t options) { navauto_mov_explorer_rec_t result; do { // Clear the WatchDog Timer. wdt_clear(); // If no file is selected - new directory if (!nav_filelist_validpos()) result = navauto_mov_explorer_new_dir(b_direction, options); else if (nav_file_isdir()) // If the selection is on a directory result = navauto_mov_explorer_is_dir(b_direction, options); else // The selection is set on a file result = navauto_mov_explorer_is_file(b_direction, options); } while(result == NAVAUTO_MOV_EXPLORER_RECURSIVE); // Translates returned values switch(result) { case NAVAUTO_MOV_EXPLORER_OK_LOOP: return NAVAUTO_MOV_OK_LOOP; case NAVAUTO_MOV_EXPLORER_OK: return NAVAUTO_MOV_OK; case NAVAUTO_MOV_EXPLORER_EMPTY: return NAVAUTO_MOV_EMPTY; default: return NAVAUTO_MOV_EXPLORER_ERROR; } }
void sv_task(void * param) { uint32_t now, last = time_now(); while (1) { /* Clear watchdog timer */ wdt_clear(); /* Check timeouts */ if (xSemaphoreTake(sv_sem, 1 * configTICK_RATE_HZ) == pdPASS) { sv_task_t * t = sv_head; while (t) { now = time_now(); t->timer += now - last; if (t->timer >= t->timeout) { printf("Supervisor timeout for %s - Rebooting system!\r\n", t->name); if (cpu_set_reset_cause) cpu_set_reset_cause(CPU_RESET_SUPERVISOR); cpu_reset(); } t = t->next; } xSemaphoreGive(sv_sem); } /* Sleep quarter of interval */ last = time_now(); vTaskDelay((interval * configTICK_RATE_HZ / 4) / 1000); } }
bool wait_event_timeout(bool* flag,unsigned long ms) { ms_timer2_set(ms,wait_event_timeout_isr); timeout=false; ms_timer2_start(); while((*flag == false)||(timeout==false)) { if((uart_tx_sending == true) || (uartf_tx_sending == true)) { lp_setHaltMode(); wdt_clear(); } else { lp_setDeepHaltMode(); wdt_clear(); } } ms_timer2_stop(); return timeout; }
void wdt_task( void *pvParameters ){ portTickType xLastWakeTime; wdt_opt_t wdt_options; struct tWatchdogRequest request; unsigned char gpsShutdown = FALSE, usbShutdown = FALSE, dataflashShutdown = FALSE, fuelShutdown = FALSE; debug_log(DEBUG_PRIORITY_INFO, DEBUG_SENDER_WDT, "Task Started"); wdtManagerQueue = xQueueCreate(WATCHDOG_QUEUE_SIZE, sizeof(request)); if( wdt_triggered() ){ debug_log(DEBUG_PRIORITY_WARNING, DEBUG_SENDER_WDT, "Reset from watchdog"); } xLastWakeTime = xTaskGetTickCount(); wdt_options.us_timeout_period = WATCHDOG_TIMEOUT_US; wdt_enable(&wdt_options); while(1){ wdt_clear(); if( xQueueReceive(wdtManagerQueue, &request, pdFALSE) == pdTRUE ){ switch(request.command){ case(WDT_REQUEST_POWEROFF): debug_log(DEBUG_PRIORITY_INFO, DEBUG_SENDER_WDT, "Shutdown requested"); fuel_send_request(FUEL_MGR_REQUEST_SHUTDOWN, NULL, NULL, NULL, NULL); //flash_send_request(FLASH_REQUEST_SHUTDOWN, NULL, NULL, NULL, NULL, NULL); flash_send_request(FLASH_MGR_REQUEST_SHUTDOWN, NULL, NULL, NULL, NULL, NULL); gps_send_request(GPS_MGR_REQUEST_SHUTDOWN, NULL, NULL, NULL, pdFALSE); debug_log(DEBUG_PRIORITY_INFO, DEBUG_SENDER_WDT, "Going down!"); wdt_clear(); // Kick the watchdog one more time to allow debug messages to be sent vTaskSuspend(NULL); break; } } vTaskDelayUntil( &xLastWakeTime, ( WATCHDOG_UPDATE_INTERVAL_MS / portTICK_RATE_MS ) ); } }
void end_of_update(void) { unsigned char n; P51D = 1; // ORANGE LED OFF for(;;) { for(n=0;n<133;n++) // about 2s cycle { wdt_clear(); tbc_wait15ms(); } P51D = ~P51D; // INVERT ORANGE LED } }
void vApplicationIdleHook( void ){ if(xTaskGetTickCount()-saveTimeRCrash>(TIME_CRASH_RX/portTICK_RATE_MS)){ saveTimeRCrash=xTaskGetTickCount(); if(clearRCrash==true){ NVIC_SystemReset(); } else{ clearRCrash=true; } } wdt_clear(); }
void wait_event(bool *flag) { #ifdef PWR_LED drv_digitalWrite(11,HIGH); // PWR LED OFF #endif while(*flag == false) { if((uart_tx_sending == true) || (uartf_tx_sending == true)) { lp_setHaltMode(); wdt_clear(); } else { lp_setDeepHaltMode(); wdt_clear(); } } *flag = false; #ifdef PWR_LED drv_digitalWrite(11,LOW); // PWR LED ON #endif }
void loop(void) { // ########### Main task ############ fly_param.length = SubGHz.readData(rx_data,sizeof(rx_data)); fly_param.current_time = millis(); if(fly_param.length > 0) { fly_param.last_recv_time = fly_param.current_time; memcpy(fly_param.motor,&rx_data[7],8); } if((fly_param.func_mode>=STATE_ERROR) || (fly_param.func_mode < FLY_STATE_DETECTING_ZERO)) { while(1){} // error state } else { fly_param.func_mode = functions[fly_param.func_mode](); } #ifdef DEBUG { static uint32_t last_print_time = 0; if(( fly_param.current_time - last_print_time) > 1000) { Serial.print(print_mode[fly_param.func_mode]); Serial.print(","); Serial.print_long(fly_param.current_time,DEC); Serial.print("\t"); Serial.print_long(last_print_time,DEC); Serial.print("\t"); Serial.print_long((long)fly_param.motor[0],DEC); Serial.print("\t"); Serial.print_long((long)fly_param.motor[1],DEC); Serial.print("\t"); Serial.print_long((long)fly_param.motor[2],DEC); Serial.print("\t"); Serial.println_long((long)fly_param.motor[3],DEC); last_print_time = fly_param.current_time; } } #endif led_ctrl(); wdt_clear(); }
static bool_t gprs_init() { wdt_clear(SOFT_WDT); gprs_info.heart = FALSE; port_init(); uart_init(gprs_info.uart_port, gprs_info.uart_speed); uart_int_cb_reg(gprs_info.uart_port, gprs_uart_inter_recv); ipconfig_get(ipconfig, 50); gprs_info.gprs_state = READY_IDLE; gprs_mutex = xSemaphoreCreateMutex(); guart_Semaphore = xSemaphoreCreateBinary(); xTaskCreate(gprs_task, "gprs_task", 300, NULL, tskIDLE_PRIORITY+6, NULL); xTaskCreate(uart_deal_task, "uart_deal_task", 50, NULL, tskIDLE_PRIORITY+7, NULL); if(gprs_info.mode == TRUE) { xTaskCreate(gprs_heart, "gprs_heart", 50, NULL, tskIDLE_PRIORITY+1, NULL); } gprs_daemon_timer = xTimerCreate("GprsTimer", (6 * configTICK_RATE_HZ), pdTRUE, NULL, gprs_sent_timeout_cb); if (gprs_daemon_timer == NULL) { DBG_ASSERT(FALSE __DBG_LINE); } gprs_queue = xQueueCreate(2, sizeof(esn_msg_t)); if (gprs_queue == NULL) { DBG_ASSERT(FALSE __DBG_LINE); } esn_msg_t esn_msg; esn_msg.event = GPRS_EVENT; xQueueSend(gprs_queue, &esn_msg, portMAX_DELAY); return TRUE; }
void delay_long(unsigned long ms) { // float f_tm_count; // temporary to calcurate timer count unsigned long tmp_target_l; delay_flag = false; tmp_target_l = ((ms % 64000)<<8)/250; delay_time.target_l = (unsigned short)tmp_target_l; delay_time.target_h = ms / 64000; #ifdef _DEBUG Serial.print_long(delay_time.target_h,HEX); Serial.print("\t"); Serial.println_long(delay_time.target_l,HEX); #endif if(delay_time.target_h==0) { timer_16bit_set(6,0xE8,(unsigned short)tmp_target_l,delay_isr); delay_time.target_l = 0; } else { timer_16bit_set(6,0x68,0xFFFF,delay_isr); } // setup timer timer_16bit_start(6); while(delay_flag == false) { lp_setHaltMode(); wdt_clear(); } timer_16bit_stop(6); return; }
static bool_t gprs_write_fifo(const uint8_t *const payload, const uint16_t len) { DBG_ASSERT(payload != NULL __DBG_LINE); if (gprs_info.gprs_state == WORK_ON && len < SEND_SIZE) { if(gprs_info.data_mode) { wdt_clear(SOFT_WDT); led_set(LED_RED, TRUE); osel_memset(send.buf, 0x00, SEND_SIZE); osel_memcpy(send.buf, payload, len); send.len = len; write_fifo(send.buf, send.len); led_set(LED_RED, FALSE); return TRUE; } else { if(xSemaphoreTake(gprs_mutex, 600) == pdTRUE) { led_set(LED_RED, TRUE); //等待数据发送完成 xTimerReset(gprs_daemon_timer, 400); osel_memset(send_data, 0x00, SIZE); tfp_sprintf((char *)send_data, CIPSEND, len); osel_memset(send.buf, 0x00, SEND_SIZE); osel_memcpy(send.buf, payload, len); send.len = len; write_fifo(send_data, mystrlen((char *)send_data)); return TRUE; } } } return FALSE; }
/* \brief Main entry point * This is an example of how to use watchdog. */ int main(void) { struct eic_line_config eic_line_cfg; /* Initialize the SAM system */ sysclk_init(); board_init(); /* Initialize the console uart */ configure_console(); /* Output example information */ printf("\r\n\r\n-- Watchdog example --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); /* Systick configuration. */ if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("-F- Systick configuration error\r"); } /* Configure push button */ eic_line_cfg.eic_mode = EIC_MODE_EDGE_TRIGGERED; eic_line_cfg.eic_edge = EIC_EDGE_FALLING_EDGE; eic_line_cfg.eic_level = EIC_LEVEL_LOW_LEVEL; eic_line_cfg.eic_filter = EIC_FILTER_DISABLED; eic_line_cfg.eic_async = EIC_ASYNCH_MODE; eic_enable(EIC); eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_cfg); eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, set_toggle_flag, EIC_5_IRQn, 1); eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); /* * Intialize and enable the watchdog. * Use default configuration but change timeout period * to about 4.56s (Ttimeout = 2pow(PSEL+1) / Fclk_cnt = 524288 / 115000). */ wdt_get_config_defaults(&g_wdt_cfg); g_wdt_cfg.timeout_period = WDT_PERIOD_524288_CLK; wdt_init(&g_wdt_inst, WDT, &g_wdt_cfg); wdt_enable(&g_wdt_inst); puts("\r\nPlease press PB0 to simulate a deadlock.\r"); while (1) { if (g_b_systick_event == true) { g_b_systick_event = false; /* Toggle LED at the given period. */ if ((g_ul_ms_ticks % BLINK_PERIOD) == 0) { ioport_toggle_pin_level(LED0_GPIO); } /* Clear watchdog at the given period. */ if ((g_ul_ms_ticks % WDT_RESTART_PERIOD) == 0) { wdt_clear(&g_wdt_inst); } } /* Simulate deadlock when button is pressed. */ if (g_b_button_event == true) { puts("The program enters an infinite loop, the WDT reset will " \ "trigger in about 5s.\r"); wdt_clear(&g_wdt_inst); while (1) { if (g_b_systick_event == true) { g_b_systick_event = false; if ((g_ul_ms_ticks % BLINK_PERIOD) == 0) { printf("."); } } } } } }
/** * \brief Test watchdog for all cases. * * \note Because MCU will be reset serval times druing the test, * to simplify the design, only one test case but with many test stages. * * \param test Current test case. */ static void run_wdt_test_all(const struct test_case *test) { struct wdt_dev_inst wdt_inst; struct wdt_config wdt_cfg; uint32_t wdt_window_ms = 0; uint32_t wdt_timeout_ms = 0; uint32_t wdt_ut_stage; /* Get test stage */ wdt_ut_stage = (uint32_t)(*(uint32_t *)WDT_UT_TAG_ADDR); if (is_wdt_reset()) { /* Check if the reset is as expected */ switch (wdt_ut_stage) { case WDT_UT_STAGE_START: test_assert_true(test, 0, "Unexpected watchdog reset at start stage!"); break; case WDT_UT_STAGE_RST_MCU: /* Move to next stage */ wdt_ut_stage = WDT_UT_STAGE_BM_NORMAL; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); break; case WDT_UT_STAGE_BM_NORMAL: test_assert_true(test, 0, "Unexpected watchdog reset at basic mode!"); break; case WDT_UT_STAGE_BM_TIMEOUT_RST: /* Move to next stage */ wdt_ut_stage = WDT_UT_STAGE_WM_NORMAL; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); break; case WDT_UT_STAGE_WM_NORMAL: test_assert_true(test, 0, "Unexpected watchdog reset at window mode!"); break; case WDT_UT_STAGE_WM_TIMEBAN_RST: /* Move to next stage */ wdt_ut_stage = WDT_UT_STAGE_WM_TIMEOUT_RST; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); break; case WDT_UT_STAGE_WM_TIMEOUT_RST: /* Move to next stage */ wdt_ut_stage = WDT_UT_STAGE_END; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); break; case WDT_UT_STAGE_END: test_assert_true(test, 0, "Unexpected watchdog reset at end stage!"); break; default: test_assert_true(test, 0, "Unexpected watchdog reset!"); break; } } else { /* First WDT unit test start at here, set stage flag */ wdt_ut_stage = WDT_UT_STAGE_START; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); } /* * ---- Test reset MCU by the WDT ---- */ if (wdt_ut_stage == WDT_UT_STAGE_START) { bool ret; /* Move to next stage */ wdt_ut_stage = WDT_UT_STAGE_RST_MCU; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); /* Reset MCU by the watchdog. */ ret = wdt_reset_mcu(); test_assert_false(test, ret, "Can't reset MCU by the WDT: failed!"); /* The code should not go to here */ test_assert_true(test, 0, "Reset MCU by the WDT: failed!"); } /* * ---- Test the WDT in basic mode ---- */ if ((wdt_ut_stage & WDT_UT_STAGE_MASK) == WDT_UT_STAGE_BM) { /* * Intialize the watchdog in basic mode: * - Use default configuration. * - But change timeout period to 0.57s * (Ttimeout = 2pow(PSEL+1) / Fclk_cnt = 65535 / 115000). */ wdt_get_config_defaults(&wdt_cfg); wdt_cfg.timeout_period = WDT_PERIOD_65536_CLK; wdt_timeout_ms = 570; wdt_init(&wdt_inst, WDT, &wdt_cfg); wdt_enable(&wdt_inst); wdt_clear(&wdt_inst); mdelay(wdt_timeout_ms / 2); wdt_clear(&wdt_inst); /* The code should reach here */ test_assert_true(test, 1, "Clear the WDT in basic mode: passed."); /* Move to next stage */ wdt_ut_stage = WDT_UT_STAGE_BM_TIMEOUT_RST; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); /* Wait for the WDT reset */ mdelay(wdt_timeout_ms * 2); /* The code should not go to here, disable watchdog for default */ wdt_disable(&wdt_inst); test_assert_true(test, 0, "No WDT reset happened in basic mode!"); } /* * ---- Test the WDT in window mode ---- */ if ((wdt_ut_stage & WDT_UT_STAGE_MASK) == WDT_UT_STAGE_WM) { /* Enable WDT clock source if need */ if (BPM->BPM_PMCON & BPM_PMCON_CK32S) { /* Enable 32K RC oscillator */ if (!osc_is_ready(OSC_ID_RC32K)) { osc_enable(OSC_ID_RC32K); osc_wait_ready(OSC_ID_RC32K); } } else { /* Enable external OSC32 oscillator */ if (!osc_is_ready(OSC_ID_OSC32)) { osc_enable(OSC_ID_OSC32); osc_wait_ready(OSC_ID_OSC32); } } /* * Intialize the watchdog in window mode: * - Use 32K oscillator as WDT clock source. * - Set timeout/timeban period to 0.5s * (Ttimeout = 2pow(PSEL+1) / Fclk_cnt = 16384 / 32768). */ wdt_get_config_defaults(&wdt_cfg); wdt_cfg.wdt_mode = WDT_MODE_WINDOW; wdt_cfg.clk_src = WDT_CLK_SRC_32K; wdt_cfg.window_period = WDT_PERIOD_16384_CLK; wdt_cfg.timeout_period = WDT_PERIOD_16384_CLK; wdt_window_ms = 500; wdt_timeout_ms = 500; wdt_init(&wdt_inst, WDT, &wdt_cfg); wdt_enable(&wdt_inst); mdelay(wdt_window_ms + wdt_timeout_ms / 10); wdt_clear(&wdt_inst); /* The code should reach here */ test_assert_true(test, 1, "Clear the WDT in window mode: passed."); if (wdt_ut_stage == WDT_UT_STAGE_WM_NORMAL) { /* Move to next stage */ wdt_ut_stage = WDT_UT_STAGE_WM_TIMEBAN_RST; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); /* Clear the WDT in time ban window */ wdt_clear(&wdt_inst); /* The WDT reset should happen */ mdelay(50); } else if (wdt_ut_stage == WDT_UT_STAGE_WM_TIMEOUT_RST) { /* Wait for the WDT reset when timeout */ mdelay(wdt_window_ms); mdelay(wdt_timeout_ms * 2); } /* The code should not go to here, disable watchdog for default */ wdt_disable(&wdt_inst); test_assert_true(test, 0, "No WDT reset happened in window mode!"); } /* * ---- Check if all test are OK ---- */ if (wdt_ut_stage == WDT_UT_STAGE_END) { test_assert_true(test, 1, "All test stages done for WDT."); /* Clear flash content */ wdt_ut_stage = 0xFFFFFFFFu; flashcalw_memcpy((void *)WDT_UT_TAG_ADDR, &wdt_ut_stage, 4, true); } else { test_assert_true(test, 0, "WDT test stopped with unexpected stages."); } }
/******************************************************************************* Routine Name: main Form: int main( void ) Parameters: void Return value: int but not return... Description: main ******************************************************************************/ int main( void ) { unsigned long write_addr; unsigned char status; // LED ON, when enter to boot mode P51D = 1; P56D = 1; P56DIR = 0; P56C1 = 1; P56C0 = 1; P56MD0 = 0; P56MD1 = 0; P51DIR = 0; P51C1 = 1; P51C0 = 1; P51MD0 = 0; P51MD1 = 0; memset(XmodemBuf,0,sizeof(XmodemBuf)); /* initialize variables */ #ifndef DEBUG write_addr = (unsigned long)USER_AREA_ADDR; #else write_addr = (unsigned long)0x2000; #endif /* initialize peripheral */ initPeri(); Xmodem_Init( XmodemBuf ); __EI(); // LED ON, when enter to boot mode /* Display program */ uart_send_sync((unsigned char*)msgIspProg, sizeof(msgIspProg)); Xmodem_SendByte('C'); P51D = 0; // Orange LED ON /* main loop */ for(;;){ /* clear WDT */ wdt_clear(); status = Xmodem_ReadStatus(); switch(status){ case RECV_END: P56D = 0; // BLUE LED ON if(write_verify(&write_addr, XmodemBuf+3) != OK){ error_proc(); /* endless loop in error_proc()*/ } else{ Xmodem_SendByte(ACK); } P56D = 1; // BLUE LED OFF break; case EOT_END: // original was remap. change to infinity loop. end_of_update(); // Remap((unsigned long)USER_AREA_ADDR); break; case TIMEOUT_ERR: case RETRY_ERR: case SEND_ERR: #ifdef DEBUG XmodemBuf[2] = status; #endif error_proc(); /* endless loop in error_proc()*/ break; default: break; } } }
inline void bootLoaderInit(void) { watchdogTimeout = 0; wdt_clear(); }
void watch_dog_isr(void) { #ifndef _WDT wdt_clear(); #endif }