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

📄 hplatm1281timer3p.nc

📁 tinyos2.0版本驱动
💻 NC
字号:
/* * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH  * DAMAGE.  * * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR  * MODIFICATIONS. *//* * Copyright (c) 2007, Vanderbilt University * 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 VANDERBILT UNIVERSITY 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 VANDERBILT * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * *//** * Internal component of the HPL interface to Atmega1281 timer 3. * * @author Martin Turon <mturon@xbow.com> * @author Janos Sallai <janos.sallai@vanderbilt.edu> */#include <Atm128Timer.h>module HplAtm1281Timer3P{  provides {    // 16-bit Timers    interface HplAtm128Timer<uint16_t>   as Timer;    interface HplAtm128TimerCtrl16       as TimerCtrl;    interface HplAtm128Capture<uint16_t> as Capture;    interface HplAtm128Compare<uint16_t> as CompareA;    interface HplAtm128Compare<uint16_t> as CompareB;    interface HplAtm128Compare<uint16_t> as CompareC;  }  uses interface PlatformInterrupt;}implementation{  //=== Read the current timer value. ===================================  async command uint16_t Timer.get() { return TCNT3; }  //=== Set/clear the current timer value. ==============================  async command void Timer.set(uint16_t t) { TCNT3 = t; }  //=== Read the current timer scale. ===================================  async command uint8_t Timer.getScale() { return TCCR3B & 0x7; }  //=== Turn off the timers. ============================================  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }  //=== Write a new timer scale. ========================================  async command void Timer.setScale(uint8_t s)  {     Atm128_TCCRB_t x = (Atm128_TCCRB_t) call TimerCtrl.getControlB();    x.bits.cs = s;    call TimerCtrl.setControlB(x.flat);    }  //=== Read the control registers. =====================================  async command uint8_t TimerCtrl.getControlA() {     return TCCR3A;   }  async command uint8_t TimerCtrl.getControlB() {     return TCCR3B;   }  async command uint8_t TimerCtrl.getControlC() {     return TCCR3C;   }  //=== Write the control registers. ====================================  async command void TimerCtrl.setControlA( uint8_t x ) {     TCCR3A = x;   }  async command void TimerCtrl.setControlB( uint8_t x ) {     TCCR3B = x;   }  async command void TimerCtrl.setControlC( uint8_t x ) {     TCCR3C = x;   }  //=== Read the interrupt mask. =====================================  async command uint8_t TimerCtrl.getInterruptMask() {     return TIMSK3;   }  //=== Write the interrupt mask. ====================================  async command void TimerCtrl.setInterruptMask( uint8_t x ) {     TIMSK3 = x;   }  //=== Read the interrupt flags. =====================================  async command uint8_t TimerCtrl.getInterruptFlag() {     return TIFR3;   }  //=== Write the interrupt flags. ====================================  async command void TimerCtrl.setInterruptFlag( uint8_t x ) {     TIFR3 = x;   }  //=== Capture 16-bit implementation. ===================================  async command void Capture.setEdge(bool up) { WRITE_BIT(TCCR3B, ICES3, up); }  //=== Timer 16-bit implementation. ===================================  async command void Timer.reset()    { TIFR3 = 1 << TOV3; }  async command void Capture.reset()  { TIFR3 = 1 << ICF3; }  async command void CompareA.reset() { TIFR3 = 1 << OCF3A; }  async command void CompareB.reset() { TIFR3 = 1 << OCF3B; }  async command void CompareC.reset() { TIFR3 = 1 << OCF3C; }  async command void Timer.start()    { SET_BIT(TIMSK3,TOIE3); }  async command void Capture.start()  { SET_BIT(TIMSK3,ICIE3); }  async command void CompareA.start() { SET_BIT(TIMSK3,OCIE3A); }  async command void CompareB.start() { SET_BIT(TIMSK3,OCIE3B); }  async command void CompareC.start() { SET_BIT(TIMSK3,OCIE3C); }  async command void Timer.stop()    { CLR_BIT(TIMSK3,TOIE3); }  async command void Capture.stop()  { CLR_BIT(TIMSK3,ICIE3); }  async command void CompareA.stop() { CLR_BIT(TIMSK3,OCIE3A); }  async command void CompareB.stop() { CLR_BIT(TIMSK3,OCIE3B); }  async command void CompareC.stop() { CLR_BIT(TIMSK3,OCIE3C); }  async command bool Timer.test() {     return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.tov;   }  async command bool Capture.test()  {     return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.icf;   }  async command bool CompareA.test() {     return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfa;   }  async command bool CompareB.test() {     return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfb;   }  async command bool CompareC.test() {     return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfc;   }  async command bool Timer.isOn() {    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.toie;  }  async command bool Capture.isOn()  {    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.icie;  }  async command bool CompareA.isOn() {    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ociea;  }  async command bool CompareB.isOn() {    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ocieb;  }  async command bool CompareC.isOn() {    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ociec;  }  //=== Read the compare registers. =====================================  async command uint16_t CompareA.get() { return OCR3A; }  async command uint16_t CompareB.get() { return OCR3B; }  async command uint16_t CompareC.get() { return OCR3C; }  //=== Write the compare registers. ====================================  async command void CompareA.set(uint16_t t) { OCR3A = t; }  async command void CompareB.set(uint16_t t) { OCR3B = t; }  async command void CompareC.set(uint16_t t) { OCR3C = t; }  //=== Read the capture registers. =====================================  async command uint16_t Capture.get() { return ICR3; }  //=== Write the capture registers. ====================================  async command void Capture.set(uint16_t t)  { ICR3 = t; }  //=== Timer interrupts signals ========================================  default async event void CompareA.fired() { }  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3A) {    signal CompareA.fired();    call PlatformInterrupt.postAmble();  }  default async event void CompareB.fired() { }  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3B) {    signal CompareB.fired();    call PlatformInterrupt.postAmble();  }  default async event void CompareC.fired() { }  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3C) {    signal CompareC.fired();    call PlatformInterrupt.postAmble();  }  default async event void Capture.captured(uint16_t time) { }  AVR_NONATOMIC_HANDLER(SIG_INPUT_CAPTURE3) {    signal Capture.captured(call Timer.get());    call PlatformInterrupt.postAmble();  }  default async event void Timer.overflow() { }  AVR_NONATOMIC_HANDLER(SIG_OVERFLOW3) {    signal Timer.overflow();    call PlatformInterrupt.postAmble();  }}

⌨️ 快捷键说明

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