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

📄 msp430timerm.nc

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 NC
📖 第 1 页 / 共 2 页
字号:
//$Id: MSP430TimerM.nc,v 1.13 2005/01/10 12:03:27 janhauer Exp $/* "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." *///@author Cory Sharp <cssharp@eecs.berkeley.edu//@author Joe Polastre//@author Jan Hauer <hauer@tkn.tu-berlin.de>includes MSP430Timer;module MSP430TimerM{  provides interface MSP430Timer as TimerA;  provides interface MSP430TimerControl as ControlA0;  provides interface MSP430TimerControl as ControlA1;  provides interface MSP430TimerControl as ControlA2;  provides interface MSP430Compare as CompareA0;  provides interface MSP430Compare as CompareA1;  provides interface MSP430Compare as CompareA2;  provides interface MSP430Capture as CaptureA0;  provides interface MSP430Capture as CaptureA1;  provides interface MSP430Capture as CaptureA2;  provides interface MSP430Timer as TimerB;  provides interface MSP430TimerControl as ControlB0;  provides interface MSP430TimerControl as ControlB1;  provides interface MSP430TimerControl as ControlB2;  provides interface MSP430TimerControl as ControlB3;  provides interface MSP430TimerControl as ControlB4;  provides interface MSP430TimerControl as ControlB5;  provides interface MSP430TimerControl as ControlB6;  provides interface MSP430Compare as CompareB0;  provides interface MSP430Compare as CompareB1;  provides interface MSP430Compare as CompareB2;  provides interface MSP430Compare as CompareB3;  provides interface MSP430Compare as CompareB4;  provides interface MSP430Compare as CompareB5;  provides interface MSP430Compare as CompareB6;  provides interface MSP430Capture as CaptureB0;  provides interface MSP430Capture as CaptureB1;  provides interface MSP430Capture as CaptureB2;  provides interface MSP430Capture as CaptureB3;  provides interface MSP430Capture as CaptureB4;  provides interface MSP430Capture as CaptureB5;  provides interface MSP430Capture as CaptureB6;}implementation{  MSP430REG_NORACE(TACTL);    MSP430REG_NORACE(TACCTL0);  MSP430REG_NORACE(TACCTL1);  MSP430REG_NORACE(TACCTL2);  MSP430REG_NORACE(TACCR0);  MSP430REG_NORACE(TACCR1);  MSP430REG_NORACE(TACCR2);  MSP430REG_NORACE(TBCCTL0);  MSP430REG_NORACE(TBCCTL1);  MSP430REG_NORACE(TBCCTL2);  MSP430REG_NORACE(TBCCTL3);  MSP430REG_NORACE(TBCCTL4);  MSP430REG_NORACE(TBCCTL5);  MSP430REG_NORACE(TBCCTL6);  MSP430REG_NORACE(TBCCR0);  MSP430REG_NORACE(TBCCR1);  MSP430REG_NORACE(TBCCR2);  MSP430REG_NORACE(TBCCR3);  MSP430REG_NORACE(TBCCR4);  MSP430REG_NORACE(TBCCR5);  MSP430REG_NORACE(TBCCR6);  typedef MSP430CompareControl_t CC_t;  DEFINE_UNION_CAST(CC2int,uint16_t,CC_t)  DEFINE_UNION_CAST(int2CC,CC_t,uint16_t)  uint16_t compareControl()  {    CC_t x = {      cm : 1,    // capture on rising edge      ccis : 0,  // capture/compare input select      clld : 0,  // TBCL1 loads on write to TBCCR1      cap : 0,   // compare mode      ccie : 0,  // capture compare interrupt enable     };    return CC2int(x);  }  uint16_t captureControl(uint8_t l_cm)  {    CC_t x = {      cm : l_cm & 0x03,    // capture on rising edge      ccis : 0,  // capture/compare input select      clld : 0,  // TBCL1 loads on write to TBCCR1      cap : 1,   // compare mode      scs : 1,   // synchronous capture mode      ccie : 0,  // capture compare interrupt enable     };    return CC2int(x);  }  TOSH_SIGNAL(TIMERA0_VECTOR)  {    if ((call ControlA0.getControl()).cap)       signal CaptureA0.captured(call CaptureA0.getEvent());    else      signal CompareA0.fired();  }  TOSH_SIGNAL(TIMERA1_VECTOR)  {    int n = TAIV;    switch( n )    {      case  0: break;      case  2:                if ((call ControlA1.getControl()).cap)                  signal CaptureA1.captured(call CaptureA1.getEvent());               else                 signal CompareA1.fired();               break;      case  4:                if ((call ControlA2.getControl()).cap)                  signal CaptureA2.captured(call CaptureA2.getEvent());               else                 signal CompareA2.fired();               break;      case  6: break;      case  8: break;      case 10: signal TimerA.overflow(); break;      case 12: break;      case 14: break;    }  }  default async event void CompareA0.fired() { }  default async event void CompareA1.fired() { }  default async event void CompareA2.fired() { }  default async event void CaptureA0.captured(uint16_t time) { }  default async event void CaptureA1.captured(uint16_t time) { }  default async event void CaptureA2.captured(uint16_t time) { }  default async event void TimerA.overflow() { }  async command uint16_t TimerA.read() { return TAR; }  async command uint16_t TimerB.read() { return TBR; }  async command bool TimerA.isOverflowPending() { return TACTL & TAIFG; }  async command bool TimerB.isOverflowPending() { return TBCTL & TBIFG; }  async command void TimerA.clearOverflow() { CLR_FLAG(TACTL,TAIFG); }  async command void TimerB.clearOverflow() { CLR_FLAG(TBCTL,TBIFG); }  async command void TimerA.setMode(int mode) { TACTL=(TACTL & ~(MC1|MC0)) | ((mode<<4)&(MC1|MC0)); }  async command void TimerB.setMode(int mode) { TBCTL=(TBCTL & ~(MC1|MC0)) | ((mode<<4)&(MC1|MC0)); }  async command int TimerA.getMode() { return (TACTL & (MC1|MC0)) >> 4; }  async command int TimerB.getMode() { return (TBCTL & (MC1|MC0)) >> 4; }  async command void TimerA.clear() { TACTL |= TACLR; }  async command void TimerB.clear() { TBCTL |= TBCLR; }  async command void TimerA.disableEvents() { TACTL &= ~TAIE;}  async command void TimerB.disableEvents() { TBCTL &= ~TBIE;}  async command void TimerA.setClockSource( uint16_t clockSource )   {     TACTL = (TACTL & ~(TASSEL0|TASSEL1)) | ((clockSource << 8) & (TASSEL0|TASSEL1));  }    async command void TimerB.setClockSource( uint16_t clockSource )  {     TBCTL = (TBCTL & ~(TBSSEL0|TBSSEL1)) | ((clockSource << 8) & (TBSSEL0|TBSSEL1));  }    async command void TimerA.setInputDivider( uint16_t inputDivider )  {    TACTL = (TACTL & ~(ID_1|ID_3)) | ((inputDivider << 8) & (ID_1|ID_3));  }    async command void TimerB.setInputDivider( uint16_t inputDivider )  {    TBCTL = (TBCTL & ~(ID_1|ID_3)) | ((inputDivider << 8) & (ID_1|ID_3));  }    async command CC_t ControlA0.getControl() { return int2CC(TACCTL0); }  async command CC_t ControlA1.getControl() { return int2CC(TACCTL1); }  async command CC_t ControlA2.getControl() { return int2CC(TACCTL2); }  async command bool ControlA0.isInterruptPending() { return TACCTL0 & CCIFG; }  async command bool ControlA1.isInterruptPending() { return TACCTL1 & CCIFG; }  async command bool ControlA2.isInterruptPending() { return TACCTL2 & CCIFG; }  async command void ControlA0.clearPendingInterrupt() { CLR_FLAG(TACCTL0,CCIFG); }  async command void ControlA1.clearPendingInterrupt() { CLR_FLAG(TACCTL1,CCIFG); }  async command void ControlA2.clearPendingInterrupt() { CLR_FLAG(TACCTL2,CCIFG); }  async command void ControlA0.setControl( CC_t x ) { TACCTL0 = CC2int(x); }  async command void ControlA1.setControl( CC_t x ) { TACCTL1 = CC2int(x); }  async command void ControlA2.setControl( CC_t x ) { TACCTL2 = CC2int(x); }  async command void ControlA0.setControlAsCompare() { TACCTL0 = compareControl(); }  async command void ControlA1.setControlAsCompare() { TACCTL1 = compareControl(); }  async command void ControlA2.setControlAsCompare() { TACCTL2 = compareControl(); }  async command void ControlA0.setControlAsCapture(uint8_t cm) { TACCTL0 = captureControl(cm); }  async command void ControlA1.setControlAsCapture(uint8_t cm) { TACCTL1 = captureControl(cm); }  async command void ControlA2.setControlAsCapture(uint8_t cm) { TACCTL2 = captureControl(cm); }  async command void CaptureA0.setEdge(uint8_t cm) { CC_t t = call ControlA0.getControl(); t.cm = cm & 0x03; TACCTL0 = CC2int(t); }  async command void CaptureA1.setEdge(uint8_t cm) { CC_t t = call ControlA1.getControl(); t.cm = cm & 0x03; TACCTL1 = CC2int(t); }  async command void CaptureA2.setEdge(uint8_t cm) { CC_t t = call ControlA2.getControl(); t.cm = cm & 0x03; TACCTL2 = CC2int(t); }  async command void CaptureA0.setSynchronous(bool synch) { if (synch) SET_FLAG(TACCTL0, SCS); else CLR_FLAG(TACCTL0, SCS); }  async command void CaptureA1.setSynchronous(bool synch) { if (synch) SET_FLAG(TACCTL1, SCS); else CLR_FLAG(TACCTL1, SCS); }  async command void CaptureA2.setSynchronous(bool synch) { if (synch) SET_FLAG(TACCTL2, SCS); else CLR_FLAG(TACCTL2, SCS); }  async command void ControlA0.enableEvents() { SET_FLAG( TACCTL0, CCIE ); }  async command void ControlA1.enableEvents() { SET_FLAG( TACCTL1, CCIE ); }  async command void ControlA2.enableEvents() { SET_FLAG( TACCTL2, CCIE ); }  async command void ControlA0.disableEvents() { CLR_FLAG( TACCTL0, CCIE ); }  async command void ControlA1.disableEvents() { CLR_FLAG( TACCTL1, CCIE ); }  async command void ControlA2.disableEvents() { CLR_FLAG( TACCTL2, CCIE ); }  async command bool ControlA0.areEventsEnabled() { return READ_FLAG( TACCTL0, CCIE ); }  async command bool ControlA1.areEventsEnabled() { return READ_FLAG( TACCTL1, CCIE ); }  async command bool ControlA2.areEventsEnabled() { return READ_FLAG( TACCTL2, CCIE ); }

⌨️ 快捷键说明

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