⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 micahighspeedradiotinysecm.nc

📁 传感器网络中的嵌入式操作系统源代码
💻 NC
📖 第 1 页 / 共 2 页
字号:
// $Id: MicaHighSpeedRadioTinySecM.nc,v 1.2.2.4 2003/08/22 01:18:48 ckarlof Exp $/*									tab:4 * "Copyright (c) 2000-2003 The Regents of the University  of California.   * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. *  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE      * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,  * 94704.  Attention:  Intel License Inquiry. */includes TimeSyncMsg;includes TosTime;includes crc;module MicaHighSpeedRadioTinySecM{  provides {    interface StdControl as Control;    interface BareSendMsg as Send;    interface ReceiveMsg as Receive;    interface RadioCoordinator as RadioSendCoordinator;    interface RadioCoordinator as RadioReceiveCoordinator;    interface TinySecRadio;  }  uses {    interface RadioEncoding as Code;    interface Random;    interface SpiByteFifo;    interface ChannelMon;    interface RadioTiming;    interface Time;    interface PowerManagement;    interface TinySec;    interface Leds;  }}implementation{  enum { //states    IDLE_STATE,    SEND_WAITING,    HEADER_RX_STATE,    RX_STATE_TINYSEC,    RX_STATE,    TRANSMITTING,    TRANSMITTING_TINYSEC,    WAITING_FOR_ACK,    SENDING_STRENGTH_PULSE,    TRANSMITTING_START,    RX_DONE_STATE,    ACK_SEND_STATE,    STOPPED_STATE  };  enum {    ACK_CNT = 4,    ENCODE_PACKET_LENGTH_DEFAULT  = MSG_DATA_SIZE*3  };  //static char start[3] = {0xab, 0x34, 0xd5}; //10 Kbps  //static char start[6] = {0xcc, 0xcf, 0x0f, 0x30, 0xf3, 0x33}; //20 Kbps  // The C attribute is used here because we are not currently supporting  // intialisers on module variables (because tossim makes it tricky)  char TOSH_MHSR_start[12] __attribute((C)) =     {0xf0, 0xf0, 0xf0, 0xff, 0x00, 0xff, 0x0f, 0x00, 0xff, 0x0f, 0x0f, 0x0f}; //40 Kbps  char state;  char send_state;  char tx_count;  uint16_t calc_crc;  uint8_t ack_count;  char rec_count;  TOS_Msg_TinySecCompat buffer;  TOS_Msg_TinySecCompat* rec_ptr;  TOS_Msg_TinySecCompat* send_ptr;  unsigned char rx_count;  char msg_length;  char buf_head;  char buf_end;  char encoded_buffer[4];  char enc_count;  char decode_byte;  char code_count;  char timeSyncFlag;  bool tx_done;  bool tinysec_rx_done;  /**** TinySec ****/  void swapLengthAndGroup(TOS_Msg* buf) {    uint8_t tmp = buf->group;    ((TOS_Msg_TinySecCompat*) buf)->length = buf->length;    ((TOS_Msg_TinySecCompat*) buf)->group = tmp;  }  /**** TinySec ****/    task void packetReceived(){    TOS_MsgPtr tmp;    atomic {      /**** TinySec ****/      tmp = (TOS_MsgPtr) rec_ptr;      swapLengthAndGroup(tmp);      /**** TinySec ****/      state = IDLE_STATE;    }    tmp = signal Receive.receive(tmp);    if(tmp != 0) {      atomic {	rec_ptr = (TOS_Msg_TinySecCompat*) tmp;      }    }    call ChannelMon.startSymbolSearch();  }  task void packetSent(){    TOS_MsgPtr ptr;    atomic {      send_state = IDLE_STATE;      state = IDLE_STATE;      /**** TinySec ****/      swapLengthAndGroup((TOS_Msg*) send_ptr);      /**** TinySec ****/      ptr = (TOS_MsgPtr) send_ptr;    }    call ChannelMon.startSymbolSearch();    signal Send.sendDone(ptr, SUCCESS);  }  command result_t Send.send(TOS_MsgPtr msg) {    uint8_t oldSendState;    atomic {      oldSendState = send_state;      if (send_state == IDLE_STATE) {	send_state = SEND_WAITING;	/**** TinySec ****/	swapLengthAndGroup(msg);	send_ptr = (TOS_Msg_TinySecCompat*) msg;	tx_done = FALSE;        /**** TinySec ****/	tx_count = 1;      }    }    if(oldSendState == IDLE_STATE){      return call ChannelMon.macDelay();    }else{      return FAIL;    }  }    /* Initialization of this component */  command result_t Control.init() {    atomic {      rec_ptr = &buffer;      send_state = IDLE_STATE;      state = IDLE_STATE;      tx_done = FALSE;      tinysec_rx_done = FALSE;    }    return rcombine(call ChannelMon.init(), call Random.init());    // TODO:  TOSH_RF_COMM_ADC_INIT();  }   /* Command to control the power of the network stack */  command result_t Control.start() {    uint8_t oldState;    result_t rval = SUCCESS;    atomic {      oldState = state;      if (state == STOPPED_STATE) {        state = IDLE_STATE;        send_state = IDLE_STATE;        call PowerManagement.adjustPower();        rval = call ChannelMon.startSymbolSearch();	          }    }        return rval;  }  /* Command to control the power of the network stack */  command result_t Control.stop() {    TOS_MsgPtr ptr = NULL;    result_t ret = rcombine(call ChannelMon.stopMonitorChannel(),			    call SpiByteFifo.idle());    if (ret == SUCCESS) {      bool sigDone = FALSE;      atomic {	call PowerManagement.adjustPower();	state = STOPPED_STATE;	if ((send_state != IDLE_STATE) && (send_state != STOPPED_STATE)) {	  send_state = STOPPED_STATE;	  sigDone = TRUE;	  ptr = (TOS_MsgPtr)send_ptr;	}	send_state = STOPPED_STATE;      }      if (sigDone) {	signal Send.sendDone(ptr, FAIL);      }      return SUCCESS;    }    return ret;  }    async event result_t TinySec.sendDone(result_t result) {    atomic {      tx_done = TRUE;    }    return SUCCESS;  }  async event result_t TinySec.receiveInitDone(result_t result,					       uint16_t length,					       bool ts_enabled) {    atomic {      msg_length = length;      tinysec_rx_done = FALSE;      if(result == SUCCESS) {	if(ts_enabled) {	  state = RX_STATE_TINYSEC;	} else {	  state = RX_STATE;	  // set tinysec_rx_done to TRUE to force post of packetReceived	  // in ACK_SEND_STATE below.	  tinysec_rx_done = TRUE;	}      } else {	rec_ptr->length = 0;	state = IDLE_STATE;      }    }    return SUCCESS;  }  async event result_t TinySec.receiveDone(result_t result) {    atomic {      if(state == RX_DONE_STATE) {	tinysec_rx_done = TRUE;	post packetReceived();      } else {	tinysec_rx_done = TRUE;      }    }    return SUCCESS;  }  // Handles the latest decoded byte propagated by the Byte Level component  async event result_t ChannelMon.startSymDetect() {    uint16_t tmp;    //TOSH_SET_GREEN_LED_PIN();    atomic {      ack_count = 0;      rec_count = 0;      state = HEADER_RX_STATE;    }    tmp = call RadioTiming.getTiming();//TOSH_CLR_GREEN_LED_PIN();    call SpiByteFifo.startReadBytes(tmp);    atomic {      msg_length = MSG_DATA_SIZE - 2;      calc_crc = 0;      rec_ptr->time = tmp;      rec_ptr->strength = 0;    }    signal RadioReceiveCoordinator.startSymbol();    /**** TinySec ****/    call TinySec.receiveInit(rec_ptr);    /**** TinySec ****/    return SUCCESS;  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -