コード例 #1
0
ファイル: openserial.c プロジェクト: apullin/openwsn-fw
void openserial_stop() {
    uint16_t temp_openserial_input_buffer_fill_level;
    INTERRUPT_DECLARATION();
    DISABLE_INTERRUPTS();
    temp_openserial_input_buffer_fill_level = openserial_vars.input_buffer_fill_level;
    ENABLE_INTERRUPTS();
    uart_disableInterrupts();              // disable USCI_A1 TX & RX interrupt
    DISABLE_INTERRUPTS();
    openserial_vars.mode=MODE_OFF;
    ENABLE_INTERRUPTS();
    if (temp_openserial_input_buffer_fill_level>0) {
        uint8_t temp_openserial_received_command;
        DISABLE_INTERRUPTS();
        temp_openserial_received_command = openserial_vars.received_command;
        ENABLE_INTERRUPTS();
        switch (temp_openserial_received_command) {
        case 'R': //Trigger IDManager about isRoot
            idmanager_triggerAboutRoot();
            break;
        case 'B': //Trigger IDManager about isBridge
            idmanager_triggerAboutBridge();
            break;
        case 'T': //Trigger TCPInject
            tcpinject_trigger();
            break;
        case 'U': //Trigger UDPInject
            udpinject_trigger();
            break;
        case 'E': //Trigger ICMPv6Echo
            icmpv6echo_trigger();
            break;
        case 'O': //Trigger ICMPv6Router
            icmpv6router_trigger();
            break;
        case 'P': //Trigger ICMPv6RPL
            icmpv6rpl_trigger();
            break;
        case 'D': //Trigger OpenBridge (called only by moteProbe)
            openbridge_trigger();
            break;
        default:
            openserial_printError(COMPONENT_OPENSERIAL,ERR_UNSUPPORTED_COMMAND,
                                  (errorparameter_t)temp_openserial_received_command,
                                  (errorparameter_t)0);
            DISABLE_INTERRUPTS();
            openserial_vars.input_buffer_fill_level = 0;
            ENABLE_INTERRUPTS();
            break;
        }
    }
}
コード例 #2
0
ファイル: 01bsp_radio_rx.c プロジェクト: Babody/openwsn-fw
/**
\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();
   }
}
コード例 #3
0
ファイル: 01bsp_radio_rx.c プロジェクト: giu7ppe/openwsn
/**
\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(); 
      }
   }
}
コード例 #4
0
ファイル: openserial.c プロジェクト: renfernand/OWSNRIT
void openserial_stop() {
   uint8_t inputBufFill;
   uint8_t cmdByte;
   bool busyReceiving;
   INTERRUPT_DECLARATION();
   
   DISABLE_INTERRUPTS();
   busyReceiving = openserial_vars.busyReceiving;
   inputBufFill = openserial_vars.inputBufFill;
   ENABLE_INTERRUPTS();
   
   // disable USCI_A1 TX & RX interrupt
   uart_disableInterrupts();
   
   DISABLE_INTERRUPTS();
   openserial_vars.mode=MODE_OFF;
   ENABLE_INTERRUPTS();
   //the inputBuffer has to be reset if it is not reset where the data is read.
   //or the function openserial_getInputBuffer is called (which resets the buffer)
   if (busyReceiving==TRUE){
      openserial_printError(COMPONENT_OPENSERIAL,ERR_BUSY_RECEIVING,
                                  (errorparameter_t)0,
                                  (errorparameter_t)inputBufFill);
   }
   
   if (busyReceiving == FALSE && inputBufFill>0) {
      DISABLE_INTERRUPTS();
      cmdByte = openserial_vars.inputBuf[0];
      ENABLE_INTERRUPTS();
      switch (cmdByte) {
         case SERFRAME_PC2MOTE_SETROOTBRIDGE:
            idmanager_triggerAboutRoot();
            idmanager_triggerAboutBridge();
            break;
         case SERFRAME_PC2MOTE_SETROOT:
            idmanager_triggerAboutRoot();
            break;
         case SERFRAME_PC2MOTE_SETBRIDGE:
            idmanager_triggerAboutBridge();
            break;
         case SERFRAME_PC2MOTE_DATA:
            openbridge_triggerData();
            break;
         case SERFRAME_PC2MOTE_TRIGGERSERIALECHO:
            //echo function must reset input buffer after reading the data.
            openserial_echo(&openserial_vars.inputBuf[1],inputBufFill-1);
            break;   
         default:
            openserial_printError(COMPONENT_OPENSERIAL,ERR_UNSUPPORTED_COMMAND,
                                  (errorparameter_t)cmdByte,
                                  (errorparameter_t)0);
            //reset here as it is not being reset in any other callback
            DISABLE_INTERRUPTS();
            openserial_vars.inputBufFill = 0;
            ENABLE_INTERRUPTS();
            break;
      }
   }
   
   DISABLE_INTERRUPTS();
   openserial_vars.inputBufFill  = 0;
   openserial_vars.busyReceiving = FALSE;
   ENABLE_INTERRUPTS();
}