/** \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(); } }
void scheduler_start(OpenMote* self) { taskList_item_t* pThisTask; while (1) { while((self->scheduler_vars).task_list!=NULL) { // there is still at least one task in the linked-list of tasks // the task to execute is the one at the head of the queue pThisTask = (self->scheduler_vars).task_list; // shift the queue by one task (self->scheduler_vars).task_list = pThisTask->next; // execute the current task pThisTask->cb(self); // free up this task container pThisTask->cb = NULL; pThisTask->prio = TASKPRIO_NONE; pThisTask->next = NULL; (self->scheduler_dbg).numTasksCur--; } debugpins_task_clr(self); board_sleep(self); debugpins_task_set(self); // IAR should halt here if nothing to do } }
/** \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(); } }
int mote_main(void) { uint8_t status; board_init(); RCC_HSICmd(ENABLE); flash_init(); /* ******************************************************* make page 62~255 becoming written protection by setting WRP3 as WRP3_VALUE or non written protection by setting nWRP3_VALUE *******************************************************/ flash_erase_optByte(); //if you want to add written protection on page 62~255, replace 0xFF by 0x7F status = flash_write_optByte(WRP3_ADDRESS,0xFF); /****************************************************** if non-written protection, write EUI64 to page 255, then make the page written protection ********************************************************/ // checking status of page 62~255 if(flash_read_optByte(WRP3_ADDRESS)&0x80) { // no written protection flash_erasePage(PAGE255_ADDRESS); flash_write(ID_ADDRESS, HEADBYTE_FIR); flash_write(ID_ADDRESS+2,HEADBYTE_SEC); flash_write(ID_ADDRESS+4,HEADBYTE_THR); flash_write(ID_ADDRESS+6,HEADBYTE_FOU); // make page 62~255 written protection flash_erase_optByte(); status = flash_write_optByte(WRP3_ADDRESS,0x7F); // check writing status if(status == 0x04) leds_sync_on(); } else { leds_error_on(); } while (1) { board_sleep(); } }
/** \brief The program starts executing here. */ int mote_main(void) { board_init(); // clear local variable memset(&app_vars,0,sizeof(app_vars_t)); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); uart_enableInterrupts(); // send stringToSend over UART app_vars.uart_lastTxByteIndex = 0; uart_writeByte(stringToSend[app_vars.uart_lastTxByteIndex]); while(1) { board_sleep(); } }
/** \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. */ int mote_main(void) { // initialize board board_init(); // prepare radiotimer radiotimer_setOverflowCb(cb_overflow); radiotimer_setCompareCb(cb_compare); // kick off first compare app_vars.num_compares_left = RADIOTIMER_NUM_COMPARES-1; app_vars.last_compare_val = RADIOTIMER_COMPARE_PERIOD; // start periodic overflow radiotimer_start(RADIOTIMER_OVERFLOW_PERIOD); leds_radio_on(); radiotimer_schedule(app_vars.last_compare_val); 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) { // 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); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); // prepare radio radio_rfOn(); radio_setFrequency(CHANNEL); // switch in RX radio_rxEnable(); while (1) { // sleep while waiting for at least one of the rxpk_done to be set app_vars.rxpk_done = 0; while (app_vars.rxpk_done==0) { board_sleep(); } // if I get here, I just received a packet //===== get packet from radio // led leds_sync_on(); // get packet from radio radio_getReceivedFrame( app_vars.rxpk_buf, &app_vars.rxpk_len, sizeof(app_vars.rxpk_buf), &app_vars.rxpk_rssi, &app_vars.rxpk_lqi, &app_vars.rxpk_crc ); // read the packet number app_vars.rxpk_num = app_vars.rxpk_buf[0]; // led leds_sync_off(); //===== send notification over serial port // led leds_error_on(); // format frame to send over serial port app_vars.uart_txFrame[0] = app_vars.rxpk_len; // packet length app_vars.uart_txFrame[1] = app_vars.rxpk_num; // packet number app_vars.uart_txFrame[2] = app_vars.rxpk_rssi; // RSSI app_vars.uart_txFrame[3] = app_vars.rxpk_lqi; // LQI app_vars.uart_txFrame[4] = app_vars.rxpk_crc; // CRC app_vars.uart_txFrame[5] = 0xff; // closing flag app_vars.uart_txFrame[6] = 0xff; // closing flag app_vars.uart_txFrame[7] = 0xff; // closing flag app_vars.uart_done = 0; app_vars.uart_lastTxByte = 0; // send app_vars.uart_txFrame over UART uart_clearTxInterrupts(); uart_clearRxInterrupts(); uart_enableInterrupts(); uart_writeByte(app_vars.uart_txFrame[app_vars.uart_lastTxByte]); while (app_vars.uart_done==0); // busy wait to finish uart_disableInterrupts(); // led leds_error_off(); } }
/** \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; } } } }
/** \brief The program starts executing here. */ int mote_main() { // needed since we are disabling/enabling interrupts below INTERRUPT_DECLARATION(); // 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); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); app_vars.uart_end=FALSE; // prepare radio radio_rfOn(); radio_setFrequency(CHANNEL); // switch in RX by default radio_rxEnable(); app_vars.flags=0x00; //wait for rx 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) { DISABLE_INTERRUPTS(); leds_sync_on(); // done receiving a 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); app_vars.packet_num=app_vars.packet[0];//packet number leds_error_off(); stringToSend[0]=app_vars.packet_num; stringToSend[1]=app_vars.rxpk_rssi; stringToSend[2]=app_vars.rxpk_lqi; stringToSend[3]=app_vars.rxpk_crc; stringToSend[4]= 0xFF; //clear this interrupt. app_vars.flags = 0x00; app_vars.uart_end=FALSE; app_vars.uart_lastTxByte = 0; ENABLE_INTERRUPTS(); // send stringToSend over UART uart_clearTxInterrupts(); uart_clearRxInterrupts(); uart_enableInterrupts(); uart_writeByte(stringToSend[app_vars.uart_lastTxByte]); while (app_vars.uart_end==FALSE);//wait to finish uart_disableInterrupts(); // clear flag leds_sync_off(); } } }