Exemple #1
0
// executed in ISR, called from scheduler.c
void isr_openserial_tx(void) {
    if (openserial_vars.ctsStateChanged==TRUE) {
        // set CTS

        if (openserial_vars.fInhibited==TRUE) {
            uart_setCTS(FALSE);
            openserial_vars.fBusyFlushing = FALSE;
        } else {
            uart_setCTS(TRUE);
        }
        openserial_vars.ctsStateChanged = FALSE;
    } else if (openserial_vars.fInhibited==TRUE) {
        // currently inhibited

        openserial_vars.fBusyFlushing = FALSE;
    } else {
        // not inhibited

        if (openserial_vars.outputBufIdxW!=openserial_vars.outputBufIdxR) {
            // I have some bytes to transmit

            uart_writeByte(openserial_vars.outputBuf[OUTPUT_BUFFER_MASK & (openserial_vars.outputBufIdxR++)]);
            openserial_vars.fBusyFlushing = TRUE;
        } else {
            // I'm done sending bytes

            openserial_vars.fBusyFlushing = FALSE;
        }
    }
}
Exemple #2
0
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();
}
Exemple #3
0
/**
\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);
   }
}
Exemple #4
0
void cb_uartTxDone(void) {
   app_vars.uart_lastTxByteIndex++;
   if (app_vars.uart_lastTxByteIndex<sizeof(app_vars.eui_string)) {
      uart_writeByte(app_vars.eui_string[app_vars.uart_lastTxByteIndex]);
   } else {
      app_vars.uartDone = 1;
   }
}
Exemple #5
0
void cb_uartTxDone(void) {
   app_vars.uart_lastTxByteIndex++;
   if (app_vars.uart_lastTxByteIndex<sizeof(stringToSend)) {
      uart_writeByte(stringToSend[app_vars.uart_lastTxByteIndex]);
   } else {
      app_vars.uartDone = 1;
   }
}
Exemple #6
0
void cb_uartTxDone() {
   uart_clearTxInterrupts();
   app_vars.uart_lastTxByte++;
   if (app_vars.uart_lastTxByte<sizeof(stringToSend)) {
      uart_writeByte(stringToSend[app_vars.uart_lastTxByte]);
   }else{
      app_vars.uart_end=TRUE;
   }
}
Exemple #7
0
void uart_writeString(const char* text) {
    for (uint8_t i = 0; i < 255; i++) { //allow max 255 characters
        if (text[i] == '\0') {
            break;
        } else {
            uart_writeByte(text[i]);
        }
    }
}
Exemple #8
0
void cb_uartRxCb() {
   uint8_t byte;
   
   // toggle LED
   leds_error_toggle();
   
   // read received byte
   byte = uart_readByte();
   
   // echo that byte over serial
   uart_writeByte(byte);
}
Exemple #9
0
//executed in ISR, called from scheduler.c
void isr_openserial_tx() {
   switch (openserial_vars.mode) {
      case MODE_INPUT:
         openserial_vars.reqFrameIdx++;
         if (openserial_vars.reqFrameIdx<sizeof(openserial_vars.reqFrame)) {
            uart_writeByte(openserial_vars.reqFrame[openserial_vars.reqFrameIdx]);
         }
         break;
      case MODE_OUTPUT:
         if (openserial_vars.outputBufIdxW==openserial_vars.outputBufIdxR) {
            openserial_vars.outputBufFilled = FALSE;
         }
         if (openserial_vars.outputBufFilled) {
            uart_writeByte(openserial_vars.outputBuf[openserial_vars.outputBufIdxR++]);
         }
         break;
      case MODE_OFF:
      default:
         break;
   }
}
Exemple #10
0
void uart_writeUInt16(uint16_t number) {
    uint8_t chars[5] = { 0 };
    uint8_t i = 0;
    for (; i < sizeof(chars); i++) {
        chars[i] = 0x30 + (number % 10);
        number /= 10;
        if (number == 0) { break; }
    }
    for (; i != 255; i--) {
        if (chars[i] != 0) { uart_writeByte(chars[i]); }
    }
}
Exemple #11
0
void cb_uartTxDone(void) {
   
   uart_clearTxInterrupts();
   
   // prepare to send the next byte
   app_vars.uart_lastTxByte++;
   
   if (app_vars.uart_lastTxByte<sizeof(app_vars.uart_txFrame)) {
      uart_writeByte(app_vars.uart_txFrame[app_vars.uart_lastTxByte]);
   } else {
      app_vars.uart_done=1;
   }
}
Exemple #12
0
//executed in ISR, called from scheduler.c
void isr_openserial_tx() {
    switch (openserial_vars.mode) {
    case MODE_INPUT:
        openserial_vars.input_command_index++;
        if (openserial_vars.input_command_index<sizeof(openserial_vars.input_command)) {
            uart_writeByte(openserial_vars.input_command[openserial_vars.input_command_index]);
        } else {
            openserial_vars.ready_receive_command = TRUE;
        }
        break;
    case MODE_OUTPUT:
        if (openserial_vars.output_buffer_index_write==openserial_vars.output_buffer_index_read) {
            openserial_vars.somethingInOutputBuffer=FALSE;
        }
        if (openserial_vars.somethingInOutputBuffer) {
            uart_writeByte(openserial_vars.output_buffer[output_buffer_index_read_increment()]);
        }
        break;
    case MODE_OFF:
    default:
        break;
    }
}
Exemple #13
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();
   }
}
Exemple #14
0
void openserial_flush(void) {
    INTERRUPT_DECLARATION();

    //<<<<<<<<<<<<<<<<<<<<<<<
    DISABLE_INTERRUPTS();
    if (openserial_vars.fBusyFlushing==FALSE) {
        if (openserial_vars.ctsStateChanged==TRUE) {
            // send CTS
#ifdef FASTSIM
#else
            if (openserial_vars.fInhibited==TRUE) {
                uart_setCTS(FALSE);
            } else {
                uart_setCTS(TRUE);
            }
#endif
            openserial_vars.ctsStateChanged = FALSE;
        } else {
            if (openserial_vars.fInhibited==TRUE) {
                // currently inhibited
            } else {
                // not inhibited
                if (openserial_vars.outputBufIdxW!=openserial_vars.outputBufIdxR) {
                    // I have some bytes to transmit

#ifdef FASTSIM
                    uart_writeCircularBuffer_FASTSIM(
                        openserial_vars.outputBuf,
                        &openserial_vars.outputBufIdxR,
                        &openserial_vars.outputBufIdxW
                    );
#else
                    uart_writeByte(openserial_vars.outputBuf[OUTPUT_BUFFER_MASK & (openserial_vars.outputBufIdxR++)]);
                    openserial_vars.fBusyFlushing = TRUE;
#endif
                }
            }
        }
    }
    ENABLE_INTERRUPTS();
    //>>>>>>>>>>>>>>>>>>>>>>>
}
Exemple #15
0
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();
}
Exemple #16
0
/**
\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);
   }
}
Exemple #17
0
/**
\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();
   }
}
Exemple #18
0
void uart_writeHexDigit(uint8_t value) {
    uint8_t data = 0x30 + (value & 0x0F);
    if (data > 0x39) { data += 7; }
    uart_writeByte(data);
}
Exemple #19
0
/**
\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(); 
      }
   }
}
Exemple #20
0
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();
}
Exemple #21
0
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();
}