亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? serialdispatcherp.nc

?? tinyos-2.x.rar
?? NC
字號:
//$Id: SerialDispatcherP.nc,v 1.9 2009/09/17 17:58:02 sdhsdh Exp $

/* "Copyright (c) 2000-2005 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."
 */

/**
 * This component provides functionality to send many different kinds
 * of serial packets on top of a general packet sending component. It
 * achieves this by knowing where the different packets in a message_t
 * exist through the SerialPacketInfo interface.
 *
 * @author Philip Levis
 * @author Ben Greenstein
 * @date August 7 2005
 *
 */

#include "Serial.h"

generic module SerialDispatcherP() {
  provides {
    interface Receive[uart_id_t id];
    interface Send[uart_id_t id];
  }
  uses {
    interface SerialPacketInfo as PacketInfo[uart_id_t id];
    interface ReceiveBytePacket;
    interface SendBytePacket;
    interface Leds;
  }
}
implementation {

  typedef enum {
    SEND_STATE_IDLE = 0,
    SEND_STATE_BEGIN = 1,
    SEND_STATE_DATA = 2
  } send_state_t;

  enum {
    RECV_STATE_IDLE = 0,
    RECV_STATE_BEGIN = 1,
    RECV_STATE_DATA = 2,
  }; 
  
  typedef struct {
    uint8_t which:1;
    uint8_t bufZeroLocked:1;
    uint8_t bufOneLocked:1;
    uint8_t state:2;
  } recv_state_t;
  
  // We are not busy, the current buffer to use is zero,
  // neither buffer is locked, and we are idle
  recv_state_t receiveState = {0, 0, 0, RECV_STATE_IDLE};
  uint8_t recvType = TOS_SERIAL_UNKNOWN_ID;
  uint8_t recvIndex = 0;

  /* This component provides double buffering. */
  message_t messages[2];     // buffer allocation
  message_t* ONE messagePtrs[2] = { &messages[0], &messages[1]};
  
  // We store a separate receiveBuffer variable because indexing
  // into a pointer array can be costly, and handling interrupts
  // is time critical.
  uint8_t* COUNT_NOK(sizeof(message_t)) receiveBuffer = (uint8_t* COUNT_NOK(sizeof(message_t)))(&messages[0]);

  uint8_t *COUNT_NOK(sizeof(message_t)) sendBuffer = NULL;
  send_state_t sendState = SEND_STATE_IDLE;
  uint8_t sendLen = 0;
  uint8_t sendIndex = 0;
  norace error_t sendError = SUCCESS;
  bool sendCancelled = FALSE;
  uint8_t sendId = 0;


  uint8_t receiveTaskPending = FALSE;
  uart_id_t receiveTaskType = 0;
  uint8_t receiveTaskWhich;
  message_t * ONE_NOK receiveTaskBuf = NULL;
  uint8_t receiveTaskSize = 0;

  command error_t Send.send[uint8_t id](message_t* msg, uint8_t len) {
    if (sendState != SEND_STATE_IDLE) {
      return EBUSY;
    }

    atomic {
      sendIndex = call PacketInfo.offset[id]();
      if (sendIndex > sizeof(message_header_t)) {
	return ESIZE;
      }
      
      sendError = SUCCESS;
      sendBuffer = (uint8_t*)msg;
      sendState = SEND_STATE_DATA;
      sendId = id;
      sendCancelled = FALSE;
      // If something we're starting past the header, something is wrong
      // Bug fix from John Regehr


      // sendLen is where in the buffer the packet stops.
      // This is the length of the packet, plus its start point
      sendLen = call PacketInfo.dataLinkLength[id](msg, len) + sendIndex;
    }
    if (call SendBytePacket.startSend(id) == SUCCESS) {
      return SUCCESS;
    }
    else {
      sendState = SEND_STATE_IDLE;
      return FAIL;
    }
  }

  command uint8_t Send.maxPayloadLength[uint8_t id]() {
    return (sizeof(message_t));
  }

  command void* Send.getPayload[uint8_t id](message_t* m, uint8_t len) {
    if (len > sizeof(message_t)) {
      return NULL;
    }
    else {
      return m;
    }
  }

    
  task void signalSendDone(){
    error_t error;

    sendState = SEND_STATE_IDLE;
    atomic error = sendError;

    if (sendCancelled) error = ECANCEL;
    signal Send.sendDone[sendId]((message_t *)sendBuffer, error);
  }

  command error_t Send.cancel[uint8_t id](message_t *msg){
    if (sendState == SEND_STATE_DATA && sendBuffer == ((uint8_t *)msg) &&
	id == sendId){
      call SendBytePacket.completeSend();
      sendCancelled = TRUE;
      return SUCCESS;
    }
    return FAIL;
  }

  async event uint8_t SendBytePacket.nextByte() {
    uint8_t b;
    uint8_t indx;
    atomic {
      b = sendBuffer[sendIndex];
      sendIndex++;
      indx = sendIndex;
    }
    if (indx > sendLen) {
      call SendBytePacket.completeSend();
      return 0;
    }
    else {
      return b;
    }
  }
  async event void SendBytePacket.sendCompleted(error_t error){
    atomic sendError = error;
    post signalSendDone();
  }

  bool isCurrentBufferLocked() {
    return (receiveState.which)? receiveState.bufOneLocked : receiveState.bufZeroLocked;
  }

  void lockCurrentBuffer() {
    if (receiveState.which) {
      receiveState.bufOneLocked = 1;
    }
    else {
      receiveState.bufZeroLocked = 1;
    }
  }

  void unlockBuffer(uint8_t which) {
    if (which) {
      receiveState.bufOneLocked = 0;
    }
    else {
      receiveState.bufZeroLocked = 0;
    }
  }
  
  void receiveBufferSwap() {
    receiveState.which = (receiveState.which)? 0: 1;
    receiveBuffer = (uint8_t*)(messagePtrs[receiveState.which]);
  }
  
  async event error_t ReceiveBytePacket.startPacket() {
    error_t result = SUCCESS;
    atomic {
      if (!isCurrentBufferLocked()) {
        // We are implicitly in RECV_STATE_IDLE, as it is the only
        // way our current buffer could be unlocked.
        lockCurrentBuffer();
        receiveState.state = RECV_STATE_BEGIN;
        recvIndex = 0;
        recvType = TOS_SERIAL_UNKNOWN_ID;
      }
      else {
        result = EBUSY;
      }
    }
    return result;
  }

  async event void ReceiveBytePacket.byteReceived(uint8_t b) {
    atomic {
      switch (receiveState.state) {
      case RECV_STATE_BEGIN:
        receiveState.state = RECV_STATE_DATA;
        recvIndex = call PacketInfo.offset[b]();
        recvType = b;
        break;
        
      case RECV_STATE_DATA:
        if (recvIndex < sizeof(message_t)) {
          receiveBuffer[recvIndex] = b;
          recvIndex++;
        }
        else {
          // Drop extra bytes that do not fit in a message_t.
          // We assume that either the higher layer knows what to
          // do with partial packets, or performs sanity checks (e.g.,
          // CRC).
        }
        break;
        
      case RECV_STATE_IDLE:
      default:
        // Do nothing. This case can be reached if the component
        // does not have free buffers: it will ignore a packet start
        // and stay in the IDLE state.
      }
    }
  }
  
  task void receiveTask(){
    uart_id_t myType;
    message_t *myBuf;
    uint8_t mySize;
    uint8_t myWhich;
    atomic {
      myType = receiveTaskType;
      myBuf = receiveTaskBuf;
      mySize = receiveTaskSize;
      myWhich = receiveTaskWhich;
    }
    mySize -= call PacketInfo.offset[myType]();
    mySize = call PacketInfo.upperLength[myType](myBuf, mySize);
    myBuf = signal Receive.receive[myType](myBuf, myBuf, mySize);
    atomic {
      messagePtrs[myWhich] = myBuf;
      unlockBuffer(myWhich);
      receiveTaskPending = FALSE;
    }
  }

  async event void ReceiveBytePacket.endPacket(error_t result) {
    uint8_t postsignalreceive = FALSE;
    atomic {
      if (!receiveTaskPending && result == SUCCESS){
        postsignalreceive = TRUE;
        receiveTaskPending = TRUE;
        receiveTaskType = recvType;
        receiveTaskWhich = receiveState.which;
        receiveTaskBuf = (message_t *)receiveBuffer;
        receiveTaskSize = recvIndex;
        receiveBufferSwap();
        receiveState.state = RECV_STATE_IDLE;
      } else {
        // we can't deliver the packet, better free the current buffer.
        unlockBuffer(receiveState.which);
      }
    }
    if (postsignalreceive){
      post receiveTask();
    }    

    // These are all local variables to release component state that
    // will allow the component to start receiving serial packets
    // ASAP.
    //
    // We need myWhich in case we happen to receive a whole new packet
    // before the signal returns, at which point receiveState.which
    // might revert back to us (via receiveBufferSwap()).
    
/*     uart_id_t myType;   // What is the type of the packet in flight?  */
/*     uint8_t myWhich;  // Which buffer ptr entry is it? */
/*     uint8_t mySize;   // How large is it? */
/*     message_t* myBuf; // A pointer, for buffer swapping */

    // First, copy out all of the important state so we can receive
    // the next packet. Then do a receiveBufferSwap, which will
    // tell the component to use the other available buffer.
    // If the buffer is 
/*     atomic { */
/*       myType = recvType; */
/*       myWhich = receiveState.which; */
/*       myBuf = (message_t*)receiveBuffer; */
/*       mySize = recvIndex; */
/*       receiveBufferSwap(); */
/*       receiveState.state = RECV_STATE_IDLE; */
/*     } */

/*     mySize -= call PacketInfo.offset[myType](); */
/*     mySize = call PacketInfo.upperLength[myType](myBuf, mySize); */

/*     if (result == SUCCESS){ */
/*       // TODO is the payload the same as the message? */
/*       myBuf = signal Receive.receive[myType](myBuf, myBuf, mySize); */
/*     } */
/*     atomic { */
/*       messagePtrs[myWhich] = myBuf; */
/*       if (myWhich) { */
/*         unlockBuffer(myWhich); */
/*       } */
/*     } */
  }

  default async command uint8_t PacketInfo.offset[uart_id_t id](){
    return 0;
  }
  default async command uint8_t PacketInfo.dataLinkLength[uart_id_t id](message_t *msg,
                                                          uint8_t upperLen){
    return 0;
  }
  default async command uint8_t PacketInfo.upperLength[uart_id_t id](message_t *msg,
                                                       uint8_t dataLinkLen){
    return 0;
  }


  default event message_t *Receive.receive[uart_id_t idxxx](message_t *msg,
                                                         void *payload,
                                                         uint8_t len){
    return msg;
  }
  default event void Send.sendDone[uart_id_t idxxx](message_t *msg, error_t error){
    return;
  }

  
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品美女久久久久aⅴ国产馆| 国产自产v一区二区三区c| 国产·精品毛片| 中文字幕欧美日本乱码一线二线| 成人一级片在线观看| 成人免费一区二区三区视频| 91亚洲精华国产精华精华液| 亚洲精品乱码久久久久久| 欧美四级电影网| 六月丁香婷婷色狠狠久久| 久久久久久电影| 99re热视频这里只精品| 亚洲成人资源网| 精品毛片乱码1区2区3区| 国产成+人+日韩+欧美+亚洲| 亚洲色图视频免费播放| 欧美日本韩国一区| 精品一区二区三区视频| 国产精品成人在线观看| 欧美日韩精品欧美日韩精品| 激情综合网av| 亚洲欧美日韩国产一区二区三区| 日本高清免费不卡视频| 蜜桃一区二区三区在线| 国产精品人人做人人爽人人添| 在线免费不卡电影| 黄色日韩网站视频| 一区二区三区四区激情| 精品国产一区二区三区av性色| caoporm超碰国产精品| 视频一区二区三区在线| 国产精品乱人伦| 宅男噜噜噜66一区二区66| 成人三级伦理片| 蜜臀久久99精品久久久久久9| 中文字幕中文字幕一区| 日韩精品一区二| 欧美亚洲动漫制服丝袜| 成人综合日日夜夜| 日韩国产精品大片| 自拍偷拍亚洲综合| 精品播放一区二区| 欧美久久久久久蜜桃| 不卡的av在线播放| 国产专区综合网| 日韩经典一区二区| 一区二区三区毛片| 国产精品高潮呻吟| 国产视频一区在线观看| 91精品国模一区二区三区| 99在线精品一区二区三区| 国产乱码精品一品二品| 蜜臀精品久久久久久蜜臀| 一区二区日韩av| 国产精品理伦片| 久久久久久久久99精品| 日韩欧美国产电影| 欧美久久久一区| 欧美日本视频在线| 欧美人伦禁忌dvd放荡欲情| 91视频www| caoporm超碰国产精品| 国产麻豆视频一区| 国产在线观看一区二区| 蜜桃一区二区三区在线观看| 日韩成人精品在线| 日日骚欧美日韩| 午夜久久久久久| 午夜电影一区二区| 亚洲超碰97人人做人人爱| 亚洲一二三四在线观看| 夜夜嗨av一区二区三区网页 | 国产精品网站在线| 日韩午夜中文字幕| 日韩欧美不卡在线观看视频| 日韩三级视频中文字幕| 欧美一区二区三区四区五区 | 色综合久久综合| 99在线精品免费| 日本高清不卡一区| 欧美精品一卡两卡| 日韩视频免费直播| 精品少妇一区二区三区 | 欧美日韩免费观看一区二区三区| 色老综合老女人久久久| 精品视频在线视频| 欧美日本免费一区二区三区| 欧美一区二区在线免费播放 | 国产精品一区在线观看你懂的| 黑人巨大精品欧美黑白配亚洲| 国产曰批免费观看久久久| 国产成人av电影在线观看| 成人动漫一区二区在线| 91免费观看视频| 欧美高清视频不卡网| 精品日韩在线观看| 国产精品视频麻豆| 亚洲精品一二三区| 奇米精品一区二区三区四区 | 日韩精品一区二区在线观看| 精品91自产拍在线观看一区| 国产精品日韩成人| 亚洲成人激情综合网| 精品亚洲免费视频| 99国内精品久久| 欧美精品色一区二区三区| 久久丝袜美腿综合| 亚洲免费在线电影| 蜜桃精品在线观看| 91在线码无精品| 日韩欧美在线综合网| 国产精品女主播在线观看| 亚洲高清在线视频| 国产一区二区不卡在线| 日本精品裸体写真集在线观看 | 天堂午夜影视日韩欧美一区二区| 久久激情综合网| 色婷婷国产精品| 日韩欧美第一区| 伊人性伊人情综合网| 国产资源在线一区| 欧美日韩精品一区二区三区| 亚洲国产精华液网站w | 一区二区视频在线看| 久久精品久久精品| 欧美在线啊v一区| 亚洲国产高清在线| 狠狠狠色丁香婷婷综合激情| 欧美日韩精品欧美日韩精品一| 日本一区二区三区电影| 免费精品视频在线| 在线观看一区日韩| 国产日韩av一区二区| 日本成人中文字幕在线视频 | 欧美日韩一区不卡| 国产精品久久久久婷婷| 看片的网站亚洲| 8x福利精品第一导航| 国产精品国产三级国产普通话99 | 日韩一二在线观看| 18欧美亚洲精品| 国产成人精品亚洲777人妖| 欧美一区二区在线视频| 亚洲在线观看免费视频| a4yy欧美一区二区三区| 国产亚洲午夜高清国产拍精品| 日本不卡123| 欧美日韩一二三| 一区二区三区在线观看网站| 成人美女视频在线观看18| 欧美精品一区二区三区在线播放| 午夜欧美大尺度福利影院在线看| 91一区二区在线| 国产精品电影一区二区三区| 国产一区999| 精品处破学生在线二十三| 免费在线观看一区| 911精品产国品一二三产区| 一区二区三区四区在线播放| 91蜜桃免费观看视频| 国产精品九色蝌蚪自拍| 成人一区二区在线观看| 国产精品家庭影院| 91丨porny丨首页| 自拍偷在线精品自拍偷无码专区| 99这里只有久久精品视频| 国产精品久久久久婷婷二区次| 成人av电影在线播放| ...av二区三区久久精品| www.爱久久.com| 亚洲美女屁股眼交| 在线视频一区二区三| 亚洲综合清纯丝袜自拍| 欧美精品欧美精品系列| 蜜臀av一区二区| 久久久久久久久久美女| 丰满白嫩尤物一区二区| 日韩一区中文字幕| 91福利小视频| 无码av中文一区二区三区桃花岛| 欧美高清激情brazzers| 韩国女主播成人在线| 国产喷白浆一区二区三区| 成人福利视频网站| 一区二区三区高清在线| 欧美日韩国产首页| 久久超碰97人人做人人爱| 久久婷婷色综合| 91免费视频大全| 日韩精品亚洲一区| 久久久久久久久久久久久女国产乱| 国产传媒一区在线| 亚洲精品一二三四区| 欧美一级黄色片| 成人性色生活片免费看爆迷你毛片| 亚洲免费观看视频| 精品乱人伦小说| 91小视频免费看| 日本视频免费一区| 国产日产欧美一区|