hplstm25pm.nc

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

NC
142
字号
// $Id: HPLSTM25PM.nc,v 1.2 2005/01/12 01:41:13 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." *//* * @author: Jonathan Hui <jwhui@cs.berkeley.edu> */module HPLSTM25PM {  provides {    interface StdControl;    interface HPLSTM25P;  }  uses {    interface BusArbitration;    interface HPLUSARTControl as USARTControl;      }}implementation {  command result_t StdControl.init() {     call USARTControl.setModeSPI();    call USARTControl.disableRxIntr();    call USARTControl.disableTxIntr();    return SUCCESS;   }    command result_t StdControl.start() {     call USARTControl.setModeSPI();    call USARTControl.disableRxIntr();    call USARTControl.disableTxIntr();    return SUCCESS;   }  command result_t StdControl.stop() {     call USARTControl.disableSPI();    return SUCCESS;   }  async command result_t HPLSTM25P.getBus() {    return call BusArbitration.getBus();  }    async command result_t HPLSTM25P.releaseBus() {    return call BusArbitration.releaseBus();  }  async command result_t HPLSTM25P.beginCmd(uint8_t cmd) {    TOSH_CLR_FLASH_CS_PIN();    call HPLSTM25P.unhold();    // send command byte    call USARTControl.tx(cmd);    while(!(call USARTControl.isTxIntrPending()));    return SUCCESS;  }  async command result_t HPLSTM25P.endCmd() {    while(!(call USARTControl.isTxEmpty()));    TOSH_SET_FLASH_CS_PIN();    return SUCCESS;  }  async command result_t HPLSTM25P.hold() {    TOSH_CLR_FLASH_HOLD_PIN();    return SUCCESS;  }  async command result_t HPLSTM25P.unhold() {    TOSH_SET_FLASH_HOLD_PIN();    return SUCCESS;  }  async command result_t HPLSTM25P.txBuf(uint8_t* buf, stm25p_addr_t len) {    stm25p_addr_t i;    for ( i = 0; i < len; i++ ) {      call USARTControl.tx(*buf++);      while(!(call USARTControl.isTxIntrPending()));    }    return SUCCESS;  }  async command result_t HPLSTM25P.rxBuf(uint8_t* buf, stm25p_addr_t len) {    stm25p_addr_t i;    call USARTControl.rx(); // clear receive interrupt    for ( i = 0; i < len; i++ ) {      call USARTControl.tx(0);      while(!(call USARTControl.isRxIntrPending()));      *buf++ = call USARTControl.rx();    }    return SUCCESS;      }  async command result_t HPLSTM25P.computeCrc(uint16_t* crcResult, stm25p_addr_t len) {    stm25p_addr_t i;    uint16_t crc = 0;    call USARTControl.rx(); // clear receive interrupt    for ( i = 0; i < len; i++ ) {      call USARTControl.tx(0);      while(!(call USARTControl.isRxIntrPending()));      crc = crcByte(crc, call USARTControl.rx());    }    *crcResult = crc;    return SUCCESS;  }  event result_t BusArbitration.busFree() { return SUCCESS; }}

⌨️ 快捷键说明

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