sharedmsgbufm.nc

来自「tinyos最新版」· NC 代码 · 共 89 行

NC
89
字号
// $Id: SharedMsgBufM.nc,v 1.4 2004/07/27 18:29:48 jwhui Exp $/*									tab:4 * * * "Copyright (c) 2000-2004 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." * *//** * Simple component that allows sharing of message * buffers through a * parameterized interface. * * @author Jonathan Hui <jwhui@cs.berkeley.edu> */module SharedMsgBufM {  provides {    interface SharedMsgBuf[uint8_t id];    interface StdControl;  }  uses interface BitVecUtils;}implementation {#include <BitVecUtils.h>  enum {    SMB_NUM_BUFS = uniqueCount("SharedMsgBuf"),    SMB_LOCK_BITVEC_SIZE = (((SMB_NUM_BUFS-1)/8)+1),  };  TOS_Msg msgBufs[SMB_NUM_BUFS];  uint8_t lockedMsgBufs[SMB_LOCK_BITVEC_SIZE];  command result_t StdControl.init() {    memset(lockedMsgBufs, 0x0, SMB_LOCK_BITVEC_SIZE);    return SUCCESS;  }    command result_t StdControl.start() { return SUCCESS; }  command result_t StdControl.stop() { return SUCCESS; }  command TOS_MsgPtr SharedMsgBuf.getMsgBuf[uint8_t id]() {    if (id >= SMB_NUM_BUFS)      return NULL;    return &(msgBufs[id]);  }  command result_t SharedMsgBuf.lock[uint8_t id]() {    if (id >= SMB_NUM_BUFS || BITVEC_GET(lockedMsgBufs, id))      return FAIL;    BITVEC_SET(lockedMsgBufs, id);    return SUCCESS;  }  command result_t SharedMsgBuf.unlock[uint8_t id]() {    if (id >= SMB_NUM_BUFS)      return FAIL;    BITVEC_CLEAR(lockedMsgBufs, id);    return SUCCESS;  }  command bool SharedMsgBuf.isLocked[uint8_t id]() {    if (BITVEC_GET(lockedMsgBufs, id))      return TRUE;    return FALSE;  }}

⌨️ 快捷键说明

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