/** \brief The program starts executing here. */ int mote_main(void) { // initialize board board_init(); // switch radio LED on leds_radio_on(); // prepare bsp_timer bsp_timer_set_callback(bsp_timer_cb_compare); // prepare radiotimer radiotimer_setOverflowCb(radiotimer_cb_overflow); radiotimer_setCompareCb(radiotimer_cb_compare); // kick off first bsp_timer compare bsp_timer_scheduleIn(BSP_TIMER_PERIOD); // start periodic radiotimer overflow radiotimer_start(RADIOTIMER_OVERFLOW_PERIOD); // kick off first radiotimer compare app_vars.radiotimer_num_compares_left = RADIOTIMER_NUM_COMPARES-1; app_vars.radiotimer_last_compare_val = RADIOTIMER_COMPARE_PERIOD; radiotimer_schedule(app_vars.radiotimer_last_compare_val); while (1) { board_sleep(); } }
/** \brief The program starts executing here. */ int mote_main(void) { // clear local variable memset(&app_vars,0,sizeof(app_vars_t)); // initialize the board board_init(); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); uart_enableInterrupts(); // setup BSP timer bsp_timer_set_callback(cb_compare); bsp_timer_scheduleIn(BSP_TIMER_PERIOD); while(1) { // wait for timer to elapse while (app_vars.uartSendNow==0); app_vars.uartSendNow = 0; // send string over UART app_vars.uartDone = 0; app_vars.uart_lastTxByteIndex = 0; uart_writeByte(stringToSend[app_vars.uart_lastTxByteIndex]); while(app_vars.uartDone==0); } }
/** \brief The program starts executing here. */ int mote_main(void) { // initialize board board_init(); bsp_timer_set_callback(cb_compare); bsp_timer_scheduleIn(BSP_TIMER_PERIOD); while (1) { board_sleep(); } }
/** \brief Initialize this module. Initializes data structures and hardware timer. */ void opentimers_init(){ uint8_t i; // initialize local variables opentimers_vars.running=FALSE; for (i=0;i<MAX_NUM_TIMERS;i++) { opentimers_vars.timersBuf[i].period_ticks = 0; opentimers_vars.timersBuf[i].ticks_remaining = 0; opentimers_vars.timersBuf[i].type = TIMER_ONESHOT; opentimers_vars.timersBuf[i].isrunning = FALSE; opentimers_vars.timersBuf[i].callback = NULL; opentimers_vars.timersBuf[i].hasExpired = FALSE; } // set callback for bsp_timers module bsp_timer_set_callback(opentimers_timer_callback); }
/** \brief The program starts executing here. */ int mote_main(void) { // initialize board board_init(); // prepare bsp_timer bsp_timer_set_callback(bsp_timer_cb_compare); // prepare radiotimer radiotimer_setOverflowCb(radiotimer_cb_overflow); radiotimer_setCompareCb(radiotimer_cb_compare); // kick off first bsp_timer compare bsp_timer_scheduleIn(BSP_TIMER_PERIOD); // start periodic radiotimer overflow radiotimer_start(RADIOTIMER_OVERFLOW_PERIOD); while (1) { board_sleep(); } }
/** \brief The program starts executing here. in order to echo chunks of bytes, each chunk needs to start with character 'H' as openserial takes different actions according to the initial character of the stream. */ int mote_main(void) { board_init(); openserial_init(); bsp_timer_set_callback(cb_compare); bsp_timer_scheduleIn(BSP_TIMER_PERIOD); while(1) { board_sleep(); if (app_vars.timerFired==1) { app_vars.timerFired = 0; if (app_vars.outputting==1) { openserial_startInput(); app_vars.outputting = 0; } else { openserial_startOutput(); app_vars.outputting = 1; } } } }
/** \brief The program starts executing here. */ int mote_main(void) { uint8_t i; // clear local variables memset(&app_vars,0,sizeof(app_vars_t)); // initialize board board_init(); GPIO_Configuration(); EXTI_Configuration(); GPIOD->BRR = (uint32_t)GPIO_Pin_2; #ifdef RADIO_SLEEP PORT_PIN_RADIO_SLP_TR_CNTL_HIGH(); #ifdef RADIO_SLEEP_IN_RUN_MOdE while(1); #endif board_sleep(); #endif #ifdef RADIO_TRXOFF board_sleep(); #endif // add callback functions radio radio_setOverflowCb(cb_radioTimerOverflows); radio_setCompareCb(cb_radioTimerCompare); radio_setStartFrameCb(cb_startFrame); radio_setEndFrameCb(cb_endFrame); // prepare packet app_vars.packet_len = sizeof(app_vars.packet); for (i=0;i<app_vars.packet_len;i++) { app_vars.packet[i] = ID; } // start bsp timer bsp_timer_set_callback(cb_timer); bsp_timer_scheduleIn(TIMER_PERIOD); // prepare radio radio_rfOn(); radio_setFrequency(CHANNEL); // switch in RX by default radio_rxEnable(); app_vars.state = APP_STATE_RX; #ifdef RADIO_RX_ON leds_all_off(); board_sleep(); #endif // start by a transmit app_vars.flags |= APP_FLAG_TIMER; while (1) { // sleep while waiting for at least one of the flags to be set while (app_vars.flags==0x00) { board_sleep(); } // handle and clear every flag while (app_vars.flags) { if (app_vars.flags & APP_FLAG_START_FRAME) { // start of frame switch (app_vars.state) { case APP_STATE_RX: // started receiving a packet leds_error_on(); break; case APP_STATE_TX: // started sending a packet leds_sync_on(); break; } // clear flag app_vars.flags &= ~APP_FLAG_START_FRAME; } if (app_vars.flags & APP_FLAG_END_FRAME) { // end of frame switch (app_vars.state) { case APP_STATE_RX: // done receiving a packet app_vars.packet_len = sizeof(app_vars.packet); for (i=0;i<app_vars.packet_len;i++) { app_vars.packet[i] = 0; } // get packet from radio radio_getReceivedFrame(app_vars.packet, &app_vars.packet_len, sizeof(app_vars.packet), &app_vars.rxpk_rssi, &app_vars.rxpk_lqi, &app_vars.rxpk_crc); leds_error_off(); break; case APP_STATE_TX: // done sending a packet // switch to RX mode radio_rxEnable(); app_vars.state = APP_STATE_RX; leds_sync_off(); break; } // clear flag app_vars.flags &= ~APP_FLAG_END_FRAME; } if (app_vars.flags & APP_FLAG_TIMER) { // timer fired if (app_vars.state==APP_STATE_RX) { // stop listening radio_rfOff(); // prepare packet app_vars.packet_len = sizeof(app_vars.packet); for (i=0;i<app_vars.packet_len;i++) { app_vars.packet[i] = ID; } // start transmitting packet radio_loadPacket(app_vars.packet,app_vars.packet_len); radio_txEnable(); #ifdef RADIO_PLL_ON leds_all_off(); board_sleep(); #endif radio_txNow(); #ifdef RADIO_BUSY_TX leds_all_off(); while(1) { //keep sending PORT_PIN_RADIO_SLP_TR_CNTL_HIGH(); PORT_PIN_RADIO_SLP_TR_CNTL_LOW(); } board_sleep(); #endif app_vars.state = APP_STATE_TX; } // clear flag app_vars.flags &= ~APP_FLAG_TIMER; } } } }
/** \brief The program starts executing here. */ int mote_main(void) { uint8_t i; // clear local variables memset(&app_vars,0,sizeof(app_vars_t)); // initialize board board_init(); // add callback functions radio radio_setOverflowCb(cb_radioTimerOverflows); radio_setCompareCb(cb_radioTimerCompare); radio_setStartFrameCb(cb_startFrame); radio_setEndFrameCb(cb_endFrame); // prepare packet app_vars.packet_len = sizeof(app_vars.packet); for (i=0;i<app_vars.packet_len;i++) { app_vars.packet[i] = ID; } // start bsp timer bsp_timer_set_callback(cb_timer); bsp_timer_scheduleIn(TIMER_PERIOD); // prepare radio radio_rfOn(); radio_setFrequency(CHANNEL); // switch in RX by default radio_rxEnable(); app_vars.state = APP_STATE_RX; // start by a transmit app_vars.flags |= APP_FLAG_TIMER; while (1) { // sleep while waiting for at least one of the flags to be set while (app_vars.flags==0x00) { board_sleep(); } // handle and clear every flag while (app_vars.flags) { //==== APP_FLAG_START_FRAME (TX or RX) if (app_vars.flags & APP_FLAG_START_FRAME) { // start of frame switch (app_vars.state) { case APP_STATE_RX: // started receiving a packet // led leds_error_on(); break; case APP_STATE_TX: // started sending a packet // led leds_sync_on(); break; } // clear flag app_vars.flags &= ~APP_FLAG_START_FRAME; } //==== APP_FLAG_END_FRAME (TX or RX) if (app_vars.flags & APP_FLAG_END_FRAME) { // end of frame switch (app_vars.state) { case APP_STATE_RX: // done receiving a packet app_vars.packet_len = sizeof(app_vars.packet); // get packet from radio radio_getReceivedFrame( app_vars.packet, &app_vars.packet_len, sizeof(app_vars.packet), &app_vars.rxpk_rssi, &app_vars.rxpk_lqi, &app_vars.rxpk_crc ); // led leds_error_off(); break; case APP_STATE_TX: // done sending a packet // switch to RX mode radio_rxEnable(); app_vars.state = APP_STATE_RX; // led leds_sync_off(); break; } // clear flag app_vars.flags &= ~APP_FLAG_END_FRAME; } //==== APP_FLAG_TIMER if (app_vars.flags & APP_FLAG_TIMER) { // timer fired if (app_vars.state==APP_STATE_RX) { // stop listening radio_rfOff(); // prepare packet app_vars.packet_len = sizeof(app_vars.packet); for (i=0;i<app_vars.packet_len;i++) { app_vars.packet[i] = ID; } // start transmitting packet radio_loadPacket(app_vars.packet,app_vars.packet_len); radio_txEnable(); radio_txNow(); app_vars.state = APP_STATE_TX; } // clear flag app_vars.flags &= ~APP_FLAG_TIMER; } } } }