void openserial_startInput() { INTERRUPT_DECLARATION(); if (openserial_vars.inputBufFill>0) { openserial_printError(COMPONENT_OPENSERIAL,ERR_INPUTBUFFER_LENGTH, (errorparameter_t)openserial_vars.inputBufFill, (errorparameter_t)0); DISABLE_INTERRUPTS(); openserial_vars.inputBufFill=0; ENABLE_INTERRUPTS(); } uart_clearTxInterrupts(); uart_clearRxInterrupts(); // clear possible pending interrupts uart_enableInterrupts(); // Enable USCI_A1 TX & RX interrupt DISABLE_INTERRUPTS(); openserial_vars.busyReceiving = FALSE; openserial_vars.mode = MODE_INPUT; openserial_vars.reqFrameIdx = 0; #ifdef FASTSIM uart_writeBufferByLen_FASTSIM( openserial_vars.reqFrame, sizeof(openserial_vars.reqFrame) ); openserial_vars.reqFrameIdx = sizeof(openserial_vars.reqFrame); #else uart_writeByte(openserial_vars.reqFrame[openserial_vars.reqFrameIdx]); #endif ENABLE_INTERRUPTS(); }
/** \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) { 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(); } }
void openserial_startInput() { INTERRUPT_DECLARATION(); if (openserial_vars.input_buffer_fill_level>0) { openserial_printError(COMPONENT_OPENSERIAL,ERR_INPUTBUFFER_LENGTH, (errorparameter_t)openserial_vars.input_buffer_fill_level, (errorparameter_t)0); openserial_vars.input_buffer_fill_level = 0; } openserial_vars.input_command[4] = SERIAL_INPUT_BUFFER_SIZE; uart_clearTxInterrupts(); uart_clearRxInterrupts(); // clear possible pending interrupts uart_enableInterrupts(); // Enable USCI_A1 TX & RX interrupt DISABLE_INTERRUPTS(); openserial_vars.mode = MODE_INPUT; openserial_vars.input_command_index = 0; openserial_vars.ready_receive_command = FALSE; openserial_vars.ready_receive_length = FALSE; uart_writeByte(openserial_vars.input_command[openserial_vars.input_command_index]); ENABLE_INTERRUPTS(); }
/** \brief The program starts executing here. */ int mote_main(void) { uint8_t i; uint8_t j; // initialize the board board_init(); // setup UART uart_setCallbacks(cb_uartTxDone,cb_uartRxCb); uart_enableInterrupts(); while(1) { // clear local variable memset(app_vars.eui,0,sizeof(app_vars.eui)); memset(app_vars.eui_string,'-',sizeof(app_vars.eui_string)-2); app_vars.eui_string[23] = '\r'; app_vars.eui_string[24] = '\n'; // read EUI64 eui64_get(app_vars.eui); // format EUI64 j = 0; for (i=0;i<8;i++) { app_vars.eui_string[j] = lookup[app_vars.eui[i]>>4 & 0x0f]; j++; app_vars.eui_string[j] = lookup[app_vars.eui[i]>>0 & 0x0f]; j++; j++; } // send string over UART app_vars.uartDone = 0; app_vars.uart_lastTxByteIndex = 0; uart_writeByte(app_vars.eui_string[app_vars.uart_lastTxByteIndex]); while(app_vars.uartDone==0); } }
void openserial_init(void) { // reset variable memset(&openserial_vars,0,sizeof(openserial_vars_t)); // admin openserial_vars.fInhibited = FALSE; openserial_vars.ctsStateChanged = FALSE; openserial_vars.debugPrintCounter = 0; // input openserial_vars.hdlcBusyReceiving = FALSE; openserial_vars.hdlcInputEscaping = FALSE; openserial_vars.inputBufFillLevel = 0; // ouput openserial_vars.outputBufIdxR = 0; openserial_vars.outputBufIdxW = 0; openserial_vars.fBusyFlushing = FALSE; openserial_vars.reset_timerId = opentimers_create(TIMER_GENERAL_PURPOSE, TASKPRIO_OPENSERIAL); openserial_vars.debugPrint_timerId = opentimers_create(TIMER_GENERAL_PURPOSE, TASKPRIO_OPENSERIAL); opentimers_scheduleIn( openserial_vars.debugPrint_timerId, DEBUGPRINT_PERIOD, TIME_MS, TIMER_PERIODIC, openserial_debugPrint_timer_cb ); // UART uart_setCallbacks( isr_openserial_tx, isr_openserial_rx ); uart_enableInterrupts(); }
/** \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() { // 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(); } } }
void openserial_startOutput() { //schedule a task to get new status in the output buffer uint8_t temp_openserial_debugPrintCounter; //to avoid many atomics INTERRUPT_DECLARATION(); DISABLE_INTERRUPTS(); openserial_vars.debugPrintCounter=(openserial_vars.debugPrintCounter+1)%STATUS_MAX; temp_openserial_debugPrintCounter = openserial_vars.debugPrintCounter; ENABLE_INTERRUPTS(); switch (temp_openserial_debugPrintCounter) { case STATUS_ISSYNC: if (debugPrint_isSync()==TRUE) { break; } case STATUS_ID: if (debugPrint_id()==TRUE) { break; } case STATUS_DAGRANK: if (debugPrint_myDAGrank()==TRUE) { break; } case STATUS_OUTBUFFERINDEXES: if(debugPrint_outBufferIndexes()==TRUE) { break; } case STATUS_ASN: if(debugPrint_asn()==TRUE) { break; } case STATUS_MACSTATS: if (debugPrint_macStats()==TRUE) { break; } case STATUS_SCHEDULE: if(debugPrint_schedule()==TRUE) { break; } case STATUS_QUEUE: if(debugPrint_queue()==TRUE) { break; } case STATUS_NEIGHBORS: if(debugPrint_neighbors()==TRUE) { break; } default: DISABLE_INTERRUPTS(); openserial_vars.debugPrintCounter=0; ENABLE_INTERRUPTS(); } //print out what's in the buffer now uart_clearTxInterrupts(); uart_clearRxInterrupts(); // clear possible pending interrupts uart_enableInterrupts(); // Enable USCI_A1 TX & RX interrupt DISABLE_INTERRUPTS(); openserial_vars.mode=MODE_OUTPUT; if (openserial_vars.somethingInOutputBuffer) { uart_writeByte(openserial_vars.output_buffer[output_buffer_index_read_increment()]); } else { openserial_stop(); } ENABLE_INTERRUPTS(); }
void openserial_startOutput() { //schedule a task to get new status in the output buffer uint8_t debugPrintCounter; INTERRUPT_DECLARATION(); DISABLE_INTERRUPTS(); openserial_vars.debugPrintCounter = (openserial_vars.debugPrintCounter+1)%STATUS_MAX; debugPrintCounter = openserial_vars.debugPrintCounter; ENABLE_INTERRUPTS(); // print debug information switch (debugPrintCounter) { case STATUS_ISSYNC: if (debugPrint_isSync()==TRUE) { break; } case STATUS_ID: if (debugPrint_id()==TRUE) { break; } case STATUS_DAGRANK: if (debugPrint_myDAGrank()==TRUE) { break; } case STATUS_OUTBUFFERINDEXES: if (debugPrint_outBufferIndexes()==TRUE) { break; } case STATUS_ASN: if (debugPrint_asn()==TRUE) { break; } case STATUS_MACSTATS: if (debugPrint_macStats()==TRUE) { break; } case STATUS_SCHEDULE: if(debugPrint_schedule()==TRUE) { break; } case STATUS_BACKOFF: if(debugPrint_backoff()==TRUE) { break; } case STATUS_QUEUE: if(debugPrint_queue()==TRUE) { break; } case STATUS_NEIGHBORS: if (debugPrint_neighbors()==TRUE) { break; } case STATUS_KAPERIOD: if (debugPrint_kaPeriod()==TRUE) { break; } default: DISABLE_INTERRUPTS(); openserial_vars.debugPrintCounter=0; ENABLE_INTERRUPTS(); } // flush buffer uart_clearTxInterrupts(); uart_clearRxInterrupts(); // clear possible pending interrupts uart_enableInterrupts(); // Enable USCI_A1 TX & RX interrupt DISABLE_INTERRUPTS(); openserial_vars.mode=MODE_OUTPUT; if (openserial_vars.outputBufFilled) { #ifdef FASTSIM uart_writeCircularBuffer_FASTSIM( openserial_vars.outputBuf, &openserial_vars.outputBufIdxR, &openserial_vars.outputBufIdxW ); #else uart_writeByte(openserial_vars.outputBuf[openserial_vars.outputBufIdxR++]); #endif } else { openserial_stop(); } ENABLE_INTERRUPTS(); }