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

📄 hplusart0c.nc

📁 tinyos-2.x.rar
💻 NC
字号:
// $Id: HplUsart0C.nc,v 1.1 2009/09/23 18:29:24 razvanm 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."
 *
 */

/**
 * @author Jonathan Hui <jwhui@cs.berkeley.edu>
 */

module HplUsart0C {
  provides interface HplUsartControl;
}
implementation {

  command void HplUsartControl.disableSPI() {
    // USART0 SPI module disable
    //ME1 &= ~USPIE0;

    // set to PUC values
    ME1 = 0;
    U0CTL = 1;
    U0TCTL = 1;
    U0RCTL = 0;
  }
  
  command void HplUsartControl.setModeSPI() {

    //U0CTL = SWRST;

    // 8-bit char, SPI-mode, USART as master
    U0CTL = SWRST | CHAR | SYNC | MM;

    // 3-pin + half-cycle delayed UCLK
    U0TCTL |= STC + CKPH + SSEL_SMCLK; 

    // as fast as possible
    U0BR0 = 0x02;
    U0BR1 = 0;

    // enable SPI
    ME1 |= USPIE0;

    U0CTL &= ~SWRST;  
    
    // clear interrupts
    IFG1 = 0;

  }

  command void HplUsartControl.disableI2C() {
    /*
    U0CTL = 1;
    U0TCTL = 1;
    I2CTCTL = 0;
    */
    U0CTL &= ~I2CEN;
    U0CTL &= ~I2C;
    I2CTCTL = 0;
    call HplUsartControl.disableSPI();
  }

  command void HplUsartControl.setModeI2C() {
   
    // Recommended init procedure
    U0CTL = I2C + SYNC + MST;

    // use 1MHz SMCLK as the I2C reference
    I2CTCTL |= I2CSSEL_2 | I2CTRX;

    // Enable I2C
    U0CTL |= I2CEN;

    return;
  }

  command error_t HplUsartControl.isTxEmpty(){
    if (U0TCTL & TXEPT) {
      return SUCCESS;
    }
    return FAIL;
  }
  
  command error_t HplUsartControl.isTxIntrPending(){
    if (IFG1 & UTXIFG0){
      IFG1 &= ~UTXIFG0;
      return SUCCESS;
    }
    return FAIL;
  }

  command error_t HplUsartControl.isRxIntrPending(){
    if (IFG1 & URXIFG0){
      IFG1 &= ~URXIFG0;
      return SUCCESS;
    }
    return FAIL;
  }

  command void HplUsartControl.tx(uint8_t data){
    U0TXBUF = data;
  }
  
  command uint8_t HplUsartControl.rx(){
    return U0RXBUF;
  }

}

⌨️ 快捷键说明

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