/** * \brief Test wakeup functions. * * \param test Current test case. */ static void run_picouart_test(const struct test_case *test) { uint8_t value; Pm *p_pm = PM; struct picouart_dev_inst dev_inst; struct picouart_config config; /* Init the PICOUART */ picouart_get_config_defaults(&config); picouart_init(&dev_inst, PICOUART, &config); /* Enable the PICOUART */ picouart_enable(&dev_inst); delay_ms(30); /* PICOUART can wakeup the device. */ bpm_enable_wakeup_source(BPM, (1 << BPM_BKUPWEN_PICOUART)); p_pm->PM_AWEN = 1 << PM_AWEN_PICOUART; p_pm->PM_IER = PM_IER_WAKE; NVIC_SetPriority(PM_IRQn,1); NVIC_EnableIRQ(PM_IRQn); config.action = PICOUART_ACTION_WAKEUP_ON_STARTBIT; picouart_set_config(&dev_inst, &config); bm_send_picouart_frame('A', 1); bpm_sleep(BPM, BPM_SM_SLEEP_1); config.action = PICOUART_ACTION_WAKEUP_ON_FULLFRAME; picouart_set_config(&dev_inst, &config); bm_send_picouart_frame('T', 5); bpm_sleep(BPM, BPM_SM_SLEEP_3); config.action = PICOUART_ACTION_WAKEUP_ON_FULLFRAME; picouart_set_config(&dev_inst, &config); bm_send_picouart_frame('M', 5); bpm_sleep(BPM, BPM_SM_WAIT); config.action = PICOUART_ACTION_WAKEUP_ON_MATCH; config.match = 'L'; picouart_set_config(&dev_inst, &config); bm_send_picouart_frame('L', 10); bpm_sleep(BPM, BPM_SM_RET); while(!picouart_is_data_ready(&dev_inst)) { } picouart_read(&dev_inst, &value); test_assert_true(test, value == 'L', "Picouart wakeup not work!"); }
/*! * \brief main function : do init and loop (poll if configured so) */ int main(void) { uint8_t key; struct picouart_dev_inst dev_inst; struct picouart_config config; struct ast_config ast_conf; /* Initialize the SAM system */ sysclk_init(); board_init(); /* Initialize the console uart */ configure_console(); /* Output example information */ printf("\r\n"); printf("-- PICOUART Example 1 --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); printf("-- IMPORTANT: This example requires a board " "monitor firmware version V1.3 or greater.\r\n"); /* Enable osc32 oscillator*/ if (!osc_is_ready(OSC_ID_OSC32)) { osc_enable(OSC_ID_OSC32); osc_wait_ready(OSC_ID_OSC32); } /* Disable all AST wake enable bits for safety since the AST is reset only by a POR. */ ast_enable(AST); ast_conf.mode = AST_COUNTER_MODE; ast_conf.osc_type = AST_OSC_32KHZ; ast_conf.psel = AST_PSEL_32KHZ_1HZ; ast_conf.counter = 0; ast_set_config(AST, &ast_conf); ast_disable_wakeup(AST, AST_WAKEUP_ALARM); ast_disable_wakeup(AST, AST_WAKEUP_PER); ast_disable_wakeup(AST, AST_WAKEUP_OVF); ast_disable(AST); /* Config the push button */ config_buttons(); /* Configurate the USART to board monitor */ bm_init(); sysclk_enable_hsb_module(SYSCLK_PBA_BRIDGE); sysclk_enable_peripheral_clock(BM_USART_USART); /* Init the PICOUART */ picouart_get_config_defaults(&config); picouart_init(&dev_inst, PICOUART, &config); /* Enable the PICOUART */ picouart_enable(&dev_inst); /* PICOUART and EIC can wakeup the device */ config_wakeup(); /* Display menu */ display_menu(); while (1) { scanf("%c", (char *)&key); switch (key) { case 'h': display_menu(); break; case 's': if (bm_flag) { printf("Switch off the board monitor to wake up..\r\n"); bm_flag = false; } else { printf("Switch on the board monitor to wake up..\r\n"); bm_flag = true; } break; case '0': printf("Enter Sleep mode with start bit wakeup.\r\n"); config.action = PICOUART_ACTION_WAKEUP_ON_STARTBIT; picouart_set_config(&dev_inst, &config); if (bm_flag) { printf("Board monitor will send frame after 3 seconds.\r\n"); bm_send_picouart_frame('A', 3000); } /* Wait for the printf operation to finish before setting the device in a power save mode. */ delay_ms(30); bpm_sleep(BPM, BPM_SM_SLEEP_2); printf("--Exit Sleep mode.\r\n\r\n"); break; case '1': printf("Enter Retention mode with full frame wakeup.\r\n"); config.action = PICOUART_ACTION_WAKEUP_ON_FULLFRAME; picouart_set_config(&dev_inst, &config); if (bm_flag) { printf("Board monitor will send frame after 3 seconds.\r\n"); bm_send_picouart_frame('T', 3000); } /* Wait for the printf operation to finish before setting the device in a power save mode. */ delay_ms(30); bpm_sleep(BPM, BPM_SM_RET); printf("--Exit Retention mode.\r\n\r\n"); break; case '2': printf("Enter backup mode with character match wakeup.\r\n"); config.action = PICOUART_ACTION_WAKEUP_ON_MATCH; config.match = 'L'; picouart_set_config(&dev_inst, &config); if (bm_flag) { printf("Board monitor will send frame after 3 seconds.\r\n"); bm_send_picouart_frame('L', 3000); } /* Wait for the printf operation to finish before setting the device in a power save mode. */ delay_ms(30); bpm_sleep(BPM, BPM_SM_BACKUP); break; default: break; } } }