/** **************************************************************************************** * @brief Restore peripheral setting after wakeup **************************************************************************************** */ void usr_sleep_restore(void) { #if QN_DBG_PRINT uart_init(QN_DEBUG_UART, USARTx_CLK(0), UART_9600); uart_tx_enable(QN_DEBUG_UART, MASK_ENABLE); uart_rx_enable(QN_DEBUG_UART, MASK_ENABLE); #endif #if (defined(QN_ADV_WDT)) if(usr_env.adv_wdt_enable) { wdt_init(1007616, WDT_INT_MOD); // 30.75s } #endif }
int main(void) { /*init all the things*/ motors_init(PHASE_CORRECT, PRESCALE_8); uart_init(BAUD_CALC(9600)); sei(); adc_init(); wdt_init(WDTO_500MS); /********************/ go(0, 0); uart_putc(ACK); over_current_a = 0; over_current_b = 0; while (1) { current_a = analog_read(C_SENS_A); current_b = analog_read(C_SENS_B); req_t = get_request_type(); if (req_t == CURRENT_REQ) { write_current(current_a, current_b); } else if (req_t == MOTORS_SET) { read_motors(&speed_a, &speed_b); wdt_reset(); } //manage current sens #ifdef CURRENT_LIMIT if ((current_a < CURRENT_LIMIT) && (current_b < CURRENT_LIMIT)) { go(speed_a, speed_b); over_current_a = over_current_b = 0; } else { //overcurrent go(0, 0); uart_putc('!'); over_current_a = current_a - CURRENT_LIMIT; over_current_b = current_b - CURRENT_LIMIT; } #endif } return (0); }
/** * main function * \return 0. int return type required by ANSI/ISO standard. */ int main(void) { int i; gpio_init(); gpiote_init(); wdt_init(); //Write the value of RESETREAS to pins 9-15 (LEDs 1-7) nrf_gpio_pin_write(LED_1, NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk); //Bit A in RESETREAS nrf_gpio_pin_write(LED_2, NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk); //Bit B in RESETREAS nrf_gpio_pin_write(LED_3, NRF_POWER->RESETREAS & POWER_RESETREAS_SREQ_Msk); //Bit C in RESETREAS nrf_gpio_pin_write(LED_4, NRF_POWER->RESETREAS & POWER_RESETREAS_LOCKUP_Msk); //Bit D in RESETREAS nrf_gpio_pin_write(LED_5, NRF_POWER->RESETREAS & POWER_RESETREAS_OFF_Msk); //Bit E in RESETREAS nrf_gpio_pin_write(LED_6, NRF_POWER->RESETREAS & POWER_RESETREAS_LPCOMP_Msk); //Bit F in RESETREAS nrf_gpio_pin_write(LED_7, NRF_POWER->RESETREAS & POWER_RESETREAS_DIF_Msk); //Bit G in RESETREAS NRF_POWER->RESETREAS = 0xFFFFFFFF; //Clear the RESETREAS register for(i=0;i<STARTUP_TOGGLE_ITERATIONS;i++) { nrf_gpio_pin_toggle(LED_0); nrf_delay_us(DELAY); } while (true) { //Blink LED 0 fast until watchdog triggers reset nrf_gpio_pin_toggle(LED_0); nrf_delay_us(DELAY/3); // If SYSTEM_OFF_BUTTON is pressed.. enter System Off mode if(nrf_gpio_pin_read(SYSTEM_OFF_BUTTON) == BTN_PRESSED) { // Clear PORT 1 (pins 8-15) nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT1, 0xFF); // Enter system OFF. After wakeup the chip will be reset, and the program will run from the top NRF_POWER->SYSTEMOFF = 1; } // If SOFTWARE_RESET_BUTTON is pressed.. soft-reset if(nrf_gpio_pin_read(SOFTWARE_RESET_BUTTON) == BTN_PRESSED) { NVIC_SystemReset(); } } }
void task_init() { task_timer_setup(); USB_CONNECTED_IRQ_ON; powerdown_lock.Unlock(); //if ftest is not done if (!cfg_factory_passed()) task_set(TASK_ACTIVE); //if is USB connected go directly to USB task if ((usb_state = USB_CONNECTED)) task_set(TASK_USB); wdt_init(wdt_2s); }
int main(void) { /* initialize LED and debug unit */ led_init(); sysirq_init(); AT91F_DBGU_Init(); AT91F_PIOA_CfgPMC(); wdt_init(); pit_init(); blinkcode_init(); /* initialize USB */ req_ctx_init(); usbcmd_gen_init(); udp_open(); /* call application specific init function */ _init_func(); // Enable User Reset and set its minimal assertion to 960 us AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4 << 8) | (unsigned int)(0xA5 << 24); #ifdef DEBUG_CLOCK_PA6 AT91F_PMC_EnablePCK(AT91C_BASE_PMC, 0, AT91C_PMC_CSS_PLL_CLK); AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0, AT91C_PA6_PCK0); #endif /* switch on first led */ led_switch(2, 1); DEBUGPCRF("entering main (idle) loop"); while (1) { /* Call application specific main idle function */ _main_func(); dbgu_rb_flush(); /* restart watchdog timer */ wdt_restart(); #ifdef CONFIG_IDLE //cpu_idle(); #endif } }
void sys_Init(void) { SystemInit(); #if CONFIG_DRIVER_WDT == 1 wdt_init(CONFIG_WDT_PERIOD); #endif time_Init(); #if CONFIG_DRIVER_LED == 1 led_Init(); #endif bsp_init(); #if (CONFIG_IAR_REDIRECT == 1) || (CONFIG_TASK_SHELL == 1) console_Init(); #endif #if (CONFIG_FLASH_NVM == 1) nvm_init(); #endif }
/** **************************************************************************************** * @brief Restore peripheral setting after wakeup **************************************************************************************** */ void usr_sleep_restore(void) { #if (FB_OLED && FB_SPI_OLED) spi_init(QN_SPI1, SPI_BITRATE(10000), SPI_8BIT, SPI_MASTER_MOD); #endif #if QN_DBG_PRINT uart_init(QN_DEBUG_UART, USARTx_CLK(0), UART_9600); uart_tx_enable(QN_DEBUG_UART, MASK_ENABLE); uart_rx_enable(QN_DEBUG_UART, MASK_ENABLE); #endif #if (defined(QN_ADV_WDT)) if(usr_env.adv_wdt_enable) { wdt_init(1007616, WDT_INT_MOD); // 30.75s } #endif }
/** * @brief Initialization of PAL * * This function initializes the PAL. The RC oscillator is calibrated. * * @return MAC_SUCCESS if PAL initialization is successful, FAILURE otherwise */ retval_t pal_init(void) { /* Clear any pending watchdog reset flag */ uint8_t temp = MCUSR; temp++; /* keep compiler happy */ MCUSR = 0; #ifdef WATCHDOG /* Watchdog Initialization. Enables the watchdog and sets the timeout period */ wdt_init(); #else WDT_RESET(); WDT_DISABLE(); #endif mcu_init(); // see pal_mcu_generic.c timer_init(); // see pal_timer.c gpio_init(); // see pal_board.c driver_init(); return MAC_SUCCESS; }
//******************************************************************************** // local functions //******************************************************************************** void init(void) { /* --- MIE Disable --- */ __DI(); /* Set oscillation mode */ clk_setLsclk( CLK_XTM_CRYSTAL ); /* crystal/ceramic oscillation */ /* Wait stables crystal oscillation */ while( (clk_getClkStatus() & FSTAT_LOSCS) != 0 ) {} clk_disHsclk(); // stop HSCLK oscillation clk_setHsclk( (unsigned char)(CLK_SYSC_OSCLK | CLK_OSCM_RC | CLK_OUTC_OSCLK | CLK_LOSCON_DIS), CLK_LOSCON_DIS ); /* set HSCLK */ // BUG620Q504 clk_enaHsclk(); // start HSCLK oscillation clk_setSysclk( CLK_SYSCLK_HSCLK ); // Choose HSCLK clk_block_ctrl_init(); /* Block Control */ // irq handler initialization irq_init(); /* Interrupt */ // Watch dog timer irq_sethandler(IRQ_NO_WDTINT,watch_dog_isr); wdt_init( WDTMOD_WDT1 | WDTMOD_WDT0); wdt_disHaltCount(); // Initializing GPIO lazurite_gpio_init(); // Initializing timer init_timer(); /* MIE Enable */ rst_interrupts(); __EI(); return; }
/** **************************************************************************************** * @brief Restore peripheral setting after wakeup **************************************************************************************** */ void usr_sleep_restore(void) { #if QN_DBG_PRINT uart_init(QN_DEBUG_UART, USARTx_CLK(0), UART_115200); uart_tx_enable(QN_DEBUG_UART, MASK_ENABLE); uart_rx_enable(QN_DEBUG_UART, MASK_ENABLE); #endif #if (defined(QN_ADV_WDT)) if(usr_env.adv_wdt_enable) { wdt_init(1007616, WDT_INT_MOD); // 30.75s } #endif //Initialize I2C master to save time later uint8_t i2cbuffer[3]; i2c_init(I2C_SCL_RATIO(1), i2cbuffer, 3); //QPRINTF("SLEEP RESTORE\r\n"); //send_packet(PROTOCOL_MODE_TX2); }
/** * \brief Application entry point for wdt_irq example. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint32_t wdt_mode, timeout_value; /* Initialize the system */ sysclk_init(); board_init(); /* Configure pins of console UART, LED and push button on board. */ configure_console(); configure_led(); /* Output example information. */ puts(STRING_HEADER); /* Initialize reset counter */ ul_rst_counter = RST_MS_COUNTER; /* Systick configuration. */ puts("Configure systick to get 1ms tick period.\r"); if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("-F- Systick configuration error\r"); } /* Get timeout value. */ timeout_value = wdt_get_timeout_value(WDT_PERIOD * 1000, BOARD_FREQ_SLCK_XTAL); if (timeout_value == WDT_INVALID_ARGUMENT) { while (1) { /* Invalid timeout value, error. */ } } /* Configure WDT to trigger an interrupt (or reset). */ wdt_mode = WDT_MR_WDFIEN | /* Enable WDT fault interrupt. */ WDT_MR_WDRPROC | /* WDT fault resets processor only. */ WDT_MR_WDDBGHLT | /* WDT stops in debug state. */ WDT_MR_WDIDLEHLT; /* WDT stops in idle state. */ /* Initialize WDT with the given parameters. */ wdt_init(WDT, wdt_mode, timeout_value, timeout_value); printf("Enable watchdog with %d microseconds period\n\r", (int)wdt_get_us_timeout_period(WDT, BOARD_FREQ_SLCK_XTAL)); /* Configure and enable WDT interrupt. */ NVIC_DisableIRQ(WDT_IRQn); NVIC_ClearPendingIRQ(WDT_IRQn); NVIC_SetPriority(WDT_IRQn, 0); NVIC_EnableIRQ(WDT_IRQn); printf("After %u seconds the system enters in a deadlock loop.\n\r", (int)ul_rst_counter/1000); 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) { #if (SAM4CM) LED_Toggle(LED4); #else LED_Toggle(LED0); #endif } /* Restart watchdog at the given period. */ if ((g_ul_ms_ticks % WDT_RESTART_PERIOD) == 0) { wdt_restart(WDT); } } /* Simulate deadlock when reset counter is reset. */ if (!ul_rst_counter) { puts("Program enters infinite loop for triggering watchdog interrupt.\r"); while (1) { } } } }
void board_init(void) { #ifndef CONF_BOARD_KEEP_WATCHDOG_AT_INIT struct wdt_dev_inst wdt_inst; struct wdt_config wdt_cfg; wdt_get_config_defaults(&wdt_cfg); wdt_init(&wdt_inst, WDT, &wdt_cfg); wdt_disable(&wdt_inst); #endif // Initialize IOPORTs ioport_init(); // Put all pins to default state (input & pull-up) uint32_t pin; for (pin = PIN_PA00; pin <= PIN_PC31; pin ++) { // Skip output pins to configure later if (pin == LED0_GPIO || pin == LCD_BL_GPIO #ifdef CONF_BOARD_RS485 || pin == RS485_USART_CTS_PIN #endif /* PA02 is not configured as it is driven by hardware configuration */ || pin == PIN_PA02) { continue; } ioport_set_pin_dir(pin, IOPORT_DIR_INPUT); ioport_set_pin_mode(pin, IOPORT_MODE_PULLUP); } /* Configure the pins connected to LEDs as output and set their * default initial state to high (LEDs off). */ ioport_set_pin_dir(LED0_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LED0_GPIO, LED0_INACTIVE_LEVEL); #ifdef CONF_BOARD_EIC // Set push button as external interrupt pin ioport_set_pin_peripheral_mode(GPIO_PUSH_BUTTON_EIC_PIN, GPIO_PUSH_BUTTON_EIC_PIN_MUX); ioport_set_pin_peripheral_mode(GPIO_UNIT_TEST_EIC_PIN, GPIO_UNIT_TEST_EIC_PIN_MUX); #else // Push button as input: already done, it's the default pin state #endif #if (defined CONF_BOARD_BL) // Configure LCD backlight ioport_set_pin_dir(LCD_BL_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LCD_BL_GPIO, LCD_BL_INACTIVE_LEVEL); #endif #if (defined CONF_BOARD_USB_PORT) ioport_set_pin_peripheral_mode(PIN_PA25A_USBC_DM, MUX_PA25A_USBC_DM); ioport_set_pin_peripheral_mode(PIN_PA26A_USBC_DP, MUX_PA26A_USBC_DP); # if defined(CONF_BOARD_USB_VBUS_DETECT) # if defined(USB_VBUS_EIC) ioport_set_pin_peripheral_mode(USB_VBUS_EIC, USB_VBUS_EIC_MUX|USB_VBUS_FLAGS); # elif defined(USB_VBUS_PIN) ioport_set_pin_dir(USB_VBUS_PIN, IOPORT_DIR_INPUT); # else # warning USB_VBUS pin not defined # endif # endif # if defined(CONF_BOARD_USB_ID_DETECT) # if defined(USB_ID_EIC) ioport_set_pin_peripheral_mode(USB_ID_EIC, USB_ID_EIC_MUX|USB_ID_FLAGS); # elif defined(USB_ID_PIN) ioport_set_pin_dir(USB_ID_PIN, IOPORT_DIR_INPUT); # else # warning USB_ID pin not defined # endif # endif # if defined(CONF_BOARD_USB_VBUS_CONTROL) # if defined(USB_VBOF_PIN) ioport_set_pin_dir(USB_VBOF_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL); # else # warning USB_VBOF pin not defined # endif # if defined(CONF_BOARD_USB_VBUS_ERR_DETECT) # if defined(USB_VBERR_EIC) ioport_set_pin_peripheral_mode(USB_VBERR_EIC, USB_VBERR_EIC_MUX|USB_VBERR_FLAGS); # elif defined(USB_VBERR_PIN) ioport_set_pin_dir(USB_VBERR_PIN, IOPORT_DIR_INPUT); # else # warning USB_VBERR pin not defined # endif # endif # endif /* !(defined CONF_BOARD_USB_NO_VBUS_CONTROL) */ #endif /* (defined CONF_BOARD_USB_PORT) */ #if defined (CONF_BOARD_COM_PORT) ioport_set_pin_peripheral_mode(COM_PORT_RX_PIN, COM_PORT_RX_MUX); ioport_set_pin_peripheral_mode(COM_PORT_TX_PIN, COM_PORT_TX_MUX); #endif #if defined (CONF_BOARD_BM_USART) ioport_set_pin_peripheral_mode(BM_USART_RX_PIN, BM_USART_RX_MUX); ioport_set_pin_peripheral_mode(BM_USART_TX_PIN, BM_USART_TX_MUX); #endif #ifdef CONF_BOARD_SPI ioport_set_pin_peripheral_mode(PIN_PC04A_SPI_MISO, MUX_PC04A_SPI_MISO); ioport_set_pin_peripheral_mode(PIN_PC05A_SPI_MOSI, MUX_PC05A_SPI_MOSI); ioport_set_pin_peripheral_mode(PIN_PC06A_SPI_SCK, MUX_PC06A_SPI_SCK); #ifdef CONF_BOARD_SPI_NPCS0 ioport_set_pin_peripheral_mode(PIN_PA02B_SPI_NPCS0, MUX_PA02B_SPI_NPCS0); #endif #ifdef CONF_BOARD_SPI_NPCS2 ioport_set_pin_peripheral_mode(PIN_PC00A_SPI_NPCS2, MUX_PC00A_SPI_NPCS2); #endif #ifdef CONF_BOARD_SPI_NPCS3 ioport_set_pin_peripheral_mode(PIN_PC01A_SPI_NPCS3, MUX_PC01A_SPI_NPCS3); #endif #endif #ifdef CONF_BOARD_RS485 ioport_set_pin_peripheral_mode(RS485_USART_RX_PIN, RS485_USART_RX_MUX); ioport_set_pin_peripheral_mode(RS485_USART_TX_PIN, RS485_USART_TX_MUX); ioport_set_pin_peripheral_mode(RS485_USART_RTS_PIN, RS485_USART_RTS_MUX); ioport_set_pin_dir(RS485_USART_CTS_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(RS485_USART_CTS_PIN, IOPORT_PIN_LEVEL_LOW); #endif #ifdef CONF_BOARD_TWIMS1 ioport_set_pin_peripheral_mode(TWIMS1_TWI_SCL_PIN, TWIMS1_TWI_SCL_MUX); ioport_set_pin_peripheral_mode(TWIMS1_TWI_SDA_PIN, TWIMS1_TWI_SDA_MUX); #endif #ifdef CONF_BOARD_USART0 ioport_set_pin_peripheral_mode(USART0_RX_PIN, USART0_RX_MUX); ioport_set_pin_peripheral_mode(USART0_TX_PIN, USART0_TX_MUX); #endif #ifdef CONF_BOARD_DACC_VOUT ioport_set_pin_peripheral_mode(DACC_VOUT_PIN, DACC_VOUT_MUX); #endif #ifdef CONF_BOARD_ACIFC ioport_set_pin_peripheral_mode(PIN_PA06E_ACIFC_ACAN0, MUX_PA06E_ACIFC_ACAN0); ioport_set_pin_peripheral_mode(PIN_PA07E_ACIFC_ACAP0, MUX_PA07E_ACIFC_ACAP0); #endif #ifdef CONF_BOARD_ABDACB_PORT ioport_set_pin_peripheral_mode(ABDACB_AUDIO0_PIN, ABDACB_AUDIO0_MUX); ioport_set_pin_peripheral_mode(ABDACB_AUDIO1_PIN, ABDACB_AUDIO1_MUX); #endif }
/* \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("."); } } } } } }
void main() { PINSEL0 |= 0X00050005; // selecting UART0 and UART1 PINSEL1 |= 0X00080000; IO1DIR |= 0X0FFF0000; //pins 1.16 to 1.23 output pins IO0DIR |= 0X003E0C00; //port 0 rs and en as output IO0CLR = 0X00FF0000; IO0SET = 0X0FF00400; IO0CLR = BUZZER; //*************************************// // Initialisations // //*************************************// lcd_init(); irq_init(); uart_init(); adc_init(); //wdt_init(); pwm5_init(); timer1_init_interrupt(); rtc_init_interrupt(); //*************************************// // Welcome Note // //*************************************// lcd_line2_disp(&welcome_note1[0],0); lcd_line3_disp(&welcome_note2[0],6); ms_delay(50000); clrscr(); lcd_line1_disp(&lcd_data_sys_chk[0],0); display_dots(); display_dots(); //*************************************// // Displaying Static Messages // //*************************************// clrscr(); default_page(); U0IER = 0; rtc_get_time(); lcd_line4_disp(&Uc_real_time[0],12); lcd_line4_disp(&Uc_set_user_time[0],0); wdt_init(); while(1) { wdt_feed(0x03ffffff); rtc_get_time(); lcd_line4_disp(&Uc_real_time[0],12); if(wdt_timeout == 1) { wdt_timeout = 0; lcd_line3_disp("WDEnable",12); } //*********************************************// // ADC input value // //*********************************************// if(Uc_adc_time_out_flag == 1) { Uc_adc_time_out_flag = 0; Ui_sample1 = adc1_getval(); ms_delay(800); Ui_sample2 = adc1_getval(); ms_delay(800); Ui_sample3 = adc1_getval(); ms_delay(800); Ui_sample4 = adc1_getval(); ms_delay(800); Ui_sample5 = adc1_getval(); adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5, 1); temp_ctrl(); lcd_line1_disp(&Uc_dec_arr[1],5); //*********Sending DATA to User desk*************// //uart0_send_string("\n\r "); uart0_send_byte((Ui_sample1 & 0xff)); uart1_send_byte(0x7E); uart1_send_string(&Uc_dec_arr[1]); uart1_send_byte('\0'); //**********************************************// Ui_sample1 = adc3_getval(); ms_delay(900); Ui_sample2 = adc3_getval(); ms_delay(900); Ui_sample3 = adc3_getval(); ms_delay(900); Ui_sample4 = adc3_getval(); ms_delay(900); Ui_sample5 = adc3_getval(); ms_delay(750); Ui_sample6 = adc3_getval(); ms_delay(750); Ui_sample7 = adc3_getval(); ms_delay(750); Ui_sample8 = adc3_getval(); ms_delay(750); Ui_sample9 = adc3_getval(); Ui_sample6 = ((Ui_sample6 + Ui_sample7 + Ui_sample8 + Ui_sample9) / 4); Ui_sample5 = ((Ui_sample6 + Ui_sample5)/2); adc_val_conv(Ui_sample1, Ui_sample2, Ui_sample3, Ui_sample4, Ui_sample5 , 0); lcd_line3_disp(&Uc_dec_arr[1],5); //*********Sending DATA to User desk*************// uart1_send_string(&Uc_dec_arr[1]); //**********************************************// } //*********************************************// // displaying Real Time & user Set Time // //*********************************************// if(Uc_alrm == 1) { Uc_alrm = 2; pwm5_pulse_width(5000, 100); } /* else if(Uc_alrm == 3) { if(Uc_user_dwn_sec == 0) { Uc_user_dwn_sec = 59; if( (Uc_user_dwn_min + Uc_user_dwn_hr) != 0) { Uc_user_dwn_min -= 1; } Uc_set_user_time[3] = ((Uc_user_dwn_min / 10) + 0x30); Uc_set_user_time[4] = ((Uc_user_dwn_min % 10) + 0x30); } if(Uc_user_dwn_min == 0) { Uc_user_dwn_min = 59; if(Uc_user_dwn_hr != 0) { Uc_user_dwn_hr -= 1; } Uc_set_user_time[0] = ((Uc_user_dwn_hr / 10) + 0x30); Uc_set_user_time[1] = ((Uc_user_dwn_hr % 10) + 0x30); } Uc_set_user_time[6] = ((Uc_user_dwn_sec / 10) + 0x30); Uc_set_user_time[7] = ((Uc_user_dwn_sec % 10) + 0x30); } */ //*********************************************// rtc_get_time(); lcd_line4_disp(&Uc_real_time[0],12); lcd_line4_disp(&Uc_set_user_time[0],0); //*********************************************// // key press on background // //*********************************************// Uc_key_temp = get_key(0); if(Uc_key_temp == 'E') { Uc_key_temp = 0; get_user_time(); } else if((Uc_key_temp == '.')&(Uc_alrm == 2)) { Uc_key_temp = 0; Uc_alrm = 0; pwm_disable(); } else if(Uc_key_temp == 'A') { clrscr(); ms_delay(1000); lcd_line2_disp("Emergency Stop!",3); lcd_line4_disp("Cooling ON",5); IO0CLR = SSR_ON; IO0CLR = HEATER_ON; IO0SET = COOLER_ON; while(1); } else if(Uc_key_temp == 'D') { Uc_key_temp = 0; rtc_change_time(); } } }
int main(int argc, char *argv[]) { int timeout = WDT_TIMEOUT_DEFAULT; int real_timeout = 0; int T; int background = 1; int use_syslog = 1; int c, status; int log_opts = LOG_NDELAY | LOG_NOWAIT | LOG_PID; struct option long_options[] = { {"load-average", 1, 0, 'a'}, {"foreground", 0, 0, 'n'}, {"help", 0, 0, 'h'}, {"interval", 1, 0, 't'}, {"loglevel", 1, 0, 'l'}, {"meminfo", 1, 0, 'm'}, {"filenr", 1, 0, 'f'}, {"pmon", 2, 0, 'p'}, {"safe-exit", 0, 0, 'e'}, {"syslog", 0, 0, 's'}, #ifndef TESTMODE_DISABLED {"test-mode", 0, 0, 'S'}, /* Hidden test mode, not for public use. */ #endif {"version", 0, 0, 'v'}, {"timeout", 1, 0, 'T'}, {NULL, 0, 0, 0} }; uev_ctx_t ctx; while ((c = getopt_long(argc, argv, "a:f:Fhl:Lm:np::sSt:T:Vvx?", long_options, NULL)) != EOF) { switch (c) { case 'a': if (loadavg_set(optarg)) return usage(1); break; case 'f': if (filenr_set(optarg)) return usage(1); break; case 'h': return usage(0); case 'l': loglevel = __wdog_loglevel(optarg); if (-1 == loglevel) return usage(1); break; case 'm': if (meminfo_set(optarg)) return usage(1); break; case 'F': /* BusyBox watchdogd compat. */ case 'n': /* Run in foreground */ background = 0; use_syslog--; break; case 'p': if (pmon_set(optarg)) return usage(1); break; case 's': use_syslog++; break; #ifndef TESTMODE_DISABLED case 'S': /* Simulate: no interaction with kernel, for testing pmon */ __wdt_testmode = 1; break; #endif case 't': /* Watchdog kick interval */ if (!optarg) { ERROR("Missing interval argument."); return usage(1); } period = atoi(optarg); break; case 'T': /* Watchdog timeout */ if (!optarg) { ERROR("Missing timeout argument."); return usage(1); } timeout = atoi(optarg); break; case 'v': printf("v%s\n", VERSION); return 0; case 'x': /* Safe exit, i.e., don't reboot if we exit and close device */ magic = 1; break; default: printf("Unrecognized option \"-%c\".\n", c); return usage(1); } } /* BusyBox watchdogd compat. */ if (optind < argc) { char *dev = argv[optind]; if (!strncmp(dev, "/dev", 4)) strlcpy(devnode, dev, sizeof(devnode)); } if (background) { DEBUG("Daemonizing ..."); if (-1 == daemon(0, 0)) { PERROR("Failed daemonizing"); return 1; } } if (!background && use_syslog < 1) log_opts |= LOG_PERROR; setlogmask(LOG_UPTO(loglevel)); openlog(NULL, log_opts, LOG_DAEMON); INFO("watchdogd v%s %s ...", PACKAGE_VERSION, wdt_testmode() ? "test mode" : "starting"); uev_init(&ctx); /* Setup callbacks for SIGUSR1 and, optionally, exit magic on SIGINT/SIGTERM */ setup_signals(&ctx); if (wdt_init()) { PERROR("Failed connecting to kernel watchdog driver"); return 1; } /* Set requested WDT timeout right before we enter the event loop. */ if (wdt_set_timeout(timeout)) PERROR("Failed setting HW watchdog timeout: %d", timeout); /* Sanity check with driver that setting actually took. */ real_timeout = wdt_get_timeout(); if (real_timeout < 0) { PERROR("Failed reading current watchdog timeout"); } else { if (real_timeout <= period) { ERROR("Warning, watchdog timeout <= kick interval: %d <= %d", real_timeout, period); } } /* If user did not provide '-k' argument, set to half actual timeout */ if (-1 == period) { if (real_timeout < 0) period = WDT_KICK_DEFAULT; else period = real_timeout / 2; if (!period) period = 1; } /* Calculate period (T) in milliseconds for libuEv */ T = period * 1000; DEBUG("Watchdog kick interval set to %d sec.", period); /* Read boot cause from watchdog and save in /var/run/watchdogd.status */ create_bootstatus(real_timeout, period); /* Every period (T) seconds we kick the wdt */ uev_timer_init(&ctx, &period_watcher, period_cb, NULL, T, T); /* Start all enabled plugins */ wdt_plugins_init(&ctx, T); /* Only create pidfile when we're done with all set up. */ if (pidfile(NULL) && !wdt_testmode()) PERROR("Cannot create pidfile"); status = uev_run(&ctx, 0); if (wdt_testmode()) return status; while (wait_reboot) { int reboot_in = 3 * real_timeout; INFO("Waiting for HW WDT reboot ..."); while (reboot_in > 0) { unsigned int rest = sleep(real_timeout); while (rest) rest = sleep(rest); reboot_in -= real_timeout; } INFO("HW WDT dit not reboot, forcing reboot now ..."); reboot(RB_AUTOBOOT); } return status; }
void board_init(void) { #ifndef CONF_BOARD_KEEP_WATCHDOG_AT_INIT struct wdt_dev_inst wdt_inst; struct wdt_config wdt_cfg; wdt_get_config_defaults(&wdt_cfg); wdt_init(&wdt_inst, WDT, &wdt_cfg); wdt_disable(&wdt_inst); #endif /* Initialize IOPORT */ ioport_init(); /* Initialize LEDs, turned off */ ioport_set_port_dir(LED_PORT, LED_MASK, IOPORT_DIR_OUTPUT); ioport_set_port_level(LED_PORT, LED_MASK, LED_INACTIVE); ioport_set_port_mode(LED_PORT, LED_MASK, IOPORT_MODE_DRIVE_STRENGTH); /* Initialize SW0 */ ioport_set_pin_dir(BUTTON_0_PIN, IOPORT_DIR_INPUT); ioport_set_pin_mode(BUTTON_0_PIN, IOPORT_MODE_PULLUP); #ifdef CONF_BOARD_EIC /* Set push button as external interrupt pin */ ioport_set_pin_peripheral_mode(BUTTON_0_EIC_PIN, BUTTON_0_EIC_PIN_MUX | IOPORT_MODE_PULLUP); #else /* Push button as input: already done, it's the default pin state */ #endif #if defined (CONF_BOARD_COM_PORT) ioport_set_pin_peripheral_mode(COM_PORT_RX_PIN, COM_PORT_RX_MUX); ioport_set_pin_peripheral_mode(COM_PORT_TX_PIN, COM_PORT_TX_MUX); #endif #ifdef CONF_BOARD_TWIMS0 ioport_set_pin_peripheral_mode(PIN_PA23B_TWIMS0_TWD, MUX_PA23B_TWIMS0_TWD); ioport_set_pin_peripheral_mode(PIN_PA24B_TWIMS0_TWCK, MUX_PA24B_TWIMS0_TWCK); #endif #ifdef CONF_BOARD_TWIMS3 ioport_set_pin_peripheral_mode(PIN_PB14C_TWIMS3_TWD, MUX_PB14C_TWIMS3_TWD); ioport_set_pin_peripheral_mode(PIN_PB15C_TWIMS3_TWCK, MUX_PB15C_TWIMS3_TWCK); #endif #ifdef CONF_BOARD_USART0 ioport_set_pin_peripheral_mode(EXT1_PIN_UART_RX, EXT1_UART_RX_MUX); ioport_set_pin_peripheral_mode(EXT1_PIN_UART_TX, EXT1_UART_TX_MUX); #endif #if (defined CONF_BOARD_USB_PORT) ioport_set_pin_peripheral_mode(PIN_PA25A_USBC_DM, MUX_PA25A_USBC_DM); ioport_set_pin_peripheral_mode(PIN_PA26A_USBC_DP, MUX_PA26A_USBC_DP); # if defined(CONF_BOARD_USB_VBUS_DETECT) ioport_set_pin_dir(USB_VBUS_PIN, IOPORT_DIR_INPUT); # endif # if defined(CONF_BOARD_USB_ID_DETECT) ioport_set_pin_dir(USB_ID_PIN, IOPORT_DIR_INPUT); # endif # if defined(CONF_BOARD_USB_VBUS_CONTROL) ioport_set_pin_dir(USB_VBOF_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL); # endif #endif #if defined(CONF_BOARD_SPI) || defined(CONF_BOARD_SD_MMC_SPI) ioport_set_pin_peripheral_mode(PIN_PA21A_SPI_MISO, MUX_PA21A_SPI_MISO); ioport_set_pin_peripheral_mode(PIN_PA22A_SPI_MOSI, MUX_PA22A_SPI_MOSI); ioport_set_pin_peripheral_mode(PIN_PC30B_SPI_SCK, MUX_PC30B_SPI_SCK); #ifdef CONF_BOARD_SD_MMC_SPI /* Setting SD detection pin */ ioport_set_pin_dir(SD_MMC_0_CD_GPIO, IOPORT_DIR_INPUT); ioport_set_pin_mode(SD_MMC_0_CD_GPIO, IOPORT_MODE_PULLUP); /* Setting SD CS pin */ ioport_set_pin_peripheral_mode(SPI_NPCS0_GPIO, SPI_NPCS0_FLAGS); #endif #ifdef CONF_BOARD_SPI_NPCS0 ioport_set_pin_peripheral_mode(PIN_PC03A_SPI_NPCS0, MUX_PC03A_SPI_NPCS0); #endif #ifdef CONF_BOARD_SPI_NPCS1 ioport_set_pin_peripheral_mode(PIN_PB13B_SPI_NPCS1, MUX_PB13B_SPI_NPCS1); #endif #ifdef CONF_BOARD_SPI_NPCS2 ioport_set_pin_peripheral_mode(PIN_PB11B_SPI_NPCS2, MUX_PB11B_SPI_NPCS2); #endif #endif #ifdef CONF_BOARD_DACC_VOUT ioport_set_pin_peripheral_mode(DACC_VOUT_PIN, DACC_VOUT_MUX); #endif #ifdef CONF_BOARD_ACIFC ioport_set_pin_peripheral_mode(PIN_PA06E_ACIFC_ACAN0, MUX_PA06E_ACIFC_ACAN0); ioport_set_pin_peripheral_mode(PIN_PA07E_ACIFC_ACAP0, MUX_PA07E_ACIFC_ACAP0); #endif }
/**@brief Function for application main entry. */ int main(void) { // Initialize // nrf_gpio_cfg_output(23); // nrf_gpio_pin_write(23, 0); // nrf_gpio_pin_write(23, 1); // nrf_delay_ms(1000); // nrf_gpio_pin_write(23, 0); uart_init(); leds_init(); timers_init(); gpiote_init(); buttons_init(); app_button_enable(); wdt_init(); #ifdef DEBUG_LOG printf("uart_init\r\n"); printf("leds_init\r\n"); printf("timers_init\r\n"); printf("gpiote_init\r\n"); printf("buttons_init\r\n"); printf("wdt_init\r\n"); #endif bond_manager_init(); ble_stack_init(); gap_params_init(); #ifdef DEBUG_LOG printf("bond_manager_init\r\n"); printf("ble_stack_init\r\n"); printf("gap_params_init\r\n"); #endif advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE); services_init(); conn_params_init(); sec_params_init(); radio_notification_init(); #ifdef DEBUG_LOG printf("advertising_init\r\n"); printf("services_init\r\n"); printf("conn_params_init\r\n"); printf("radio_notification_init\r\n"); #endif advertising_start(); #ifdef DEBUG_LOG printf("advertising_start\r\n"); #endif HTU21D_Init(); #ifdef DEBUG_LOG printf("HTU21D_Init\r\n"); printf("OLED_Init\r\n"); #endif my_timer_init(); Auto_Time_Set(); #ifdef DEBUG_LOG printf("rtc my_timer_init\r\n"); printf("Auto_Time_Set\r\n"); #endif wdt_start(); #ifdef DEBUG_LOG printf("wdt_start\r\n"); printf("Enter main loop\r\n"); #endif OLED_POWER_CONTROL(1); nrf_delay_ms(2000); OLED_POWER_CONTROL(0); for (;;) { updata_by_min(); updata_by_hour(); power_manage(); } }
void board_init(void) { #ifndef CONF_BOARD_KEEP_WATCHDOG_AT_INIT struct wdt_dev_inst wdt_inst; struct wdt_config wdt_cfg; wdt_get_config_defaults(&wdt_cfg); wdt_init(&wdt_inst, WDT, &wdt_cfg); wdt_disable(&wdt_inst); #endif /* Initialize IOPORT */ ioport_init(); /* Initialize LED0, turned off */ ioport_set_pin_dir(LED_0_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LED_0_PIN, IOPORT_PIN_LEVEL_HIGH); /* Initialize SW0 */ ioport_set_pin_dir(BUTTON_0_PIN, IOPORT_DIR_INPUT); ioport_set_pin_mode(BUTTON_0_PIN, IOPORT_MODE_PULLUP); #ifdef CONF_BOARD_EIC /* Set push button as external interrupt pin */ ioport_set_pin_peripheral_mode(BUTTON_0_EIC_PIN, BUTTON_0_EIC_PIN_MUX | IOPORT_MODE_PULLUP); #else /* Push button as input: already done, it's the default pin state */ #endif #if (defined CONF_BOARD_BL) // Configure LCD backlight ioport_set_pin_dir(LCD_BL_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LCD_BL_GPIO, LCD_BL_INACTIVE_LEVEL); #endif #if defined (CONF_BOARD_COM_PORT) ioport_set_pin_peripheral_mode(COM_PORT_RX_PIN, COM_PORT_RX_MUX); ioport_set_pin_peripheral_mode(COM_PORT_TX_PIN, COM_PORT_TX_MUX); #endif #ifdef CONF_BOARD_TWIMS0 ioport_set_pin_peripheral_mode(PIN_PA23B_TWIMS0_TWD, MUX_PA23B_TWIMS0_TWD); ioport_set_pin_peripheral_mode(PIN_PA24B_TWIMS0_TWCK, MUX_PA24B_TWIMS0_TWCK); #endif #ifdef CONF_BOARD_TWIMS3 ioport_set_pin_peripheral_mode(PIN_PB14C_TWIMS3_TWD, MUX_PB14C_TWIMS3_TWD); ioport_set_pin_peripheral_mode(PIN_PB15C_TWIMS3_TWCK, MUX_PB15C_TWIMS3_TWCK); #endif #ifdef CONF_BOARD_USART0 ioport_set_pin_peripheral_mode(EXT1_PIN_UART_RX, EXT1_UART_RX_MUX); ioport_set_pin_peripheral_mode(EXT1_PIN_UART_TX, EXT1_UART_TX_MUX); #endif #if (defined CONF_BOARD_USB_PORT) ioport_set_pin_peripheral_mode(PIN_PA25A_USBC_DM, MUX_PA25A_USBC_DM); ioport_set_pin_peripheral_mode(PIN_PA26A_USBC_DP, MUX_PA26A_USBC_DP); # if defined(CONF_BOARD_USB_VBUS_DETECT) ioport_set_pin_dir(USB_VBUS_PIN, IOPORT_DIR_INPUT); # endif # if defined(CONF_BOARD_USB_ID_DETECT) ioport_set_pin_dir(USB_ID_PIN, IOPORT_DIR_INPUT); # endif # if defined(CONF_BOARD_USB_VBUS_CONTROL) ioport_set_pin_dir(USB_VBOF_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL); # endif #endif #ifdef CONF_BOARD_AT86RFX ioport_set_pin_peripheral_mode(AT86RFX_SPI_MISO, AT86RFX_SPI_MISO_FLAGS); ioport_set_pin_peripheral_mode(AT86RFX_SPI_MOSI, AT86RFX_SPI_MOSI_FLAGS); ioport_set_pin_peripheral_mode(AT86RFX_SPI_SCK, AT86RFX_SPI_SCK_FLAGS); ioport_set_pin_peripheral_mode(AT86RFX_SPI_CS_PIN, AT86RFX_SPI_CS_FLAGS); /* Initialize TRX_RST and SLP_TR as GPIO. */ ioport_set_pin_dir(AT86RFX_RST_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_RST_PIN, IOPORT_PIN_LEVEL_HIGH); ioport_set_pin_dir(AT86RFX_SLP_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_SLP_PIN, IOPORT_PIN_LEVEL_HIGH); #ifdef EXT_RF_FRONT_END_CTRL ioport_set_pin_dir(AT86RFX_CPS, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_CPS, IOPORT_PIN_LEVEL_HIGH); ioport_set_pin_dir(AT86RFX_CSD, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_CSD, IOPORT_PIN_LEVEL_HIGH); #endif #endif #if defined(CONF_BOARD_SPI) || defined(CONF_BOARD_SD_MMC_SPI) ioport_set_pin_peripheral_mode(PIN_PA21A_SPI_MISO, MUX_PA21A_SPI_MISO); ioport_set_pin_peripheral_mode(PIN_PA22A_SPI_MOSI, MUX_PA22A_SPI_MOSI); ioport_set_pin_peripheral_mode(PIN_PC30B_SPI_SCK, MUX_PC30B_SPI_SCK); #ifdef CONF_BOARD_SD_MMC_SPI /* Setting SD detection pin */ ioport_set_pin_dir(SD_MMC_0_CD_GPIO, IOPORT_DIR_INPUT); ioport_set_pin_mode(SD_MMC_0_CD_GPIO, IOPORT_MODE_PULLUP); /* Setting SD CS pin */ ioport_set_pin_peripheral_mode(SPI_NPCS0_GPIO, SPI_NPCS0_FLAGS); #endif #ifdef CONF_BOARD_SPI_NPCS0 ioport_set_pin_peripheral_mode(PIN_PC03A_SPI_NPCS0, MUX_PC03A_SPI_NPCS0); #endif #ifdef CONF_BOARD_SPI_NPCS1 ioport_set_pin_peripheral_mode(PIN_PB13B_SPI_NPCS1, MUX_PB13B_SPI_NPCS1); #endif #ifdef CONF_BOARD_SPI_NPCS2 ioport_set_pin_peripheral_mode(PIN_PB11B_SPI_NPCS2, MUX_PB11B_SPI_NPCS2); #endif #endif #ifdef CONF_BOARD_DACC_VOUT ioport_set_pin_peripheral_mode(DACC_VOUT_PIN, DACC_VOUT_MUX); #endif #ifdef CONF_BOARD_ACIFC ioport_set_pin_peripheral_mode(PIN_PA06E_ACIFC_ACAN0, MUX_PA06E_ACIFC_ACAN0); ioport_set_pin_peripheral_mode(PIN_PA07E_ACIFC_ACAP0, MUX_PA07E_ACIFC_ACAP0); #endif #ifdef CONF_BOARD_PARC ioport_set_pin_peripheral_mode(PIN_PA17D_PARC_PCCK, MUX_PA17D_PARC_PCCK); ioport_set_pin_peripheral_mode(PIN_PA09D_PARC_PCDATA0, MUX_PA09D_PARC_PCDATA0); ioport_set_pin_peripheral_mode(PIN_PA10D_PARC_PCDATA1, MUX_PA10D_PARC_PCDATA1); ioport_set_pin_peripheral_mode(PIN_PA11D_PARC_PCDATA2, MUX_PA11D_PARC_PCDATA2); ioport_set_pin_peripheral_mode(PIN_PA12D_PARC_PCDATA3, MUX_PA12D_PARC_PCDATA3); ioport_set_pin_peripheral_mode(PIN_PA13D_PARC_PCDATA4, MUX_PA13D_PARC_PCDATA4); ioport_set_pin_peripheral_mode(PIN_PA14D_PARC_PCDATA5, MUX_PA14D_PARC_PCDATA5); ioport_set_pin_peripheral_mode(PIN_PA15D_PARC_PCDATA6, MUX_PA15D_PARC_PCDATA6); ioport_set_pin_peripheral_mode(PIN_PA16D_PARC_PCDATA7, MUX_PA16D_PARC_PCDATA7); ioport_set_pin_peripheral_mode(PIN_PA18D_PARC_PCEN1, MUX_PA18D_PARC_PCEN1); ioport_set_pin_peripheral_mode(PIN_PA19D_PARC_PCEN2, MUX_PA19D_PARC_PCEN2); #endif #ifdef CONF_BOARD_OLED_UG_2832HSWEG04 ioport_set_pin_dir(UG_2832HSWEG04_DATA_CMD_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_mode(UG_2832HSWEG04_DATA_CMD_GPIO, IOPORT_MODE_PULLUP); ioport_set_pin_dir(UG_2832HSWEG04_RESET_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_mode(UG_2832HSWEG04_RESET_GPIO, IOPORT_MODE_PULLUP); #endif }
/** * \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."); } }