int main(void) { halInit(); /* Initialize ChibiOS core */ chSysInit(); sc_init(SC_MODULE_UART2 | SC_MODULE_GPIO | SC_MODULE_LED | SC_MODULE_SDU | SC_MODULE_RADIO); sc_uart_default_usb(TRUE); sc_log_output_uart(SC_UART_USB); // Start event loop. This will start a new thread and return sc_event_loop_start(); // Register callbacks. // These will be called from Event Loop thread. It's OK to do some // calculations etc. time consuming there, but not to sleep or block // for longer periods of time. sc_event_register_handle_byte(cb_handle_byte); sc_event_register_blob_available(cb_blob_available); sc_event_register_extint(0, cb_pa0_changed); sc_extint_set_event(GPIOA, 0, SC_EXTINT_EDGE_BOTH); // Loop forever waiting for callbacks while(1) { uint8_t msg[] = {'d', ':', ' ', 'p','i','n','g','\r','\n'}; chThdSleepMilliseconds(1000); sc_uart_send_msg(SC_UART_USB, msg, sizeof(msg)); } return 0; }
int main(void) { standby = sc_pwr_get_standby_flag(); wkup = sc_pwr_get_wake_up_flag(); // Enable debugging even with WFI // This increases the power consumption by 1.5mA sc_pwr_set_wfi_dbg(); halInit(); chSysInit(); sc_init(SC_MODULE_GPIO | SC_MODULE_SPI | SC_MODULE_UART2); sc_log_output_uart(SC_UART_2); // Start event loop. This will start a new thread and return sc_event_loop_start(); SC_LOG_PRINTF("started\r\n"); // Register callbacks. // These will be called from Event Loop thread. It's OK to do some // calculations etc. time consuming there, but not to sleep or block // for longer periods of time. sc_event_register_handle_byte(cb_handle_byte); sc_event_register_spirit1_msg_available(cb_spirit1_msg); sc_event_register_spirit1_data_sent(cb_spirit1_sent); sc_event_register_spirit1_data_lost(cb_spirit1_lost); sc_spirit1_init(TOP_SECRET_KEY, MY_ADDRESS); SC_LOG_PRINTF("spirit1 init done\r\n"); while(1) { uint8_t msg[] = {'t', 'e', 's', 't', '\r', '\n', '\0'}; chThdSleepMilliseconds(1000); SC_LOG_PRINTF("sending: test\r\n"); sc_spirit1_send(SPIRIT1_BROADCAST_ADDRESS, msg, sizeof(msg) - 1); } }