📄 timerjiffyasyncm.nc.svn-base
字号:
//$Id: TimerJiffyAsyncM.nc,v 1.1 2004/06/10 01:32:22 jpolastre Exp $// @author Joe Polastre/*****************************************************************************Provides a highresolution (32uSec interval) timer for CC2420Radio stackUses ATMega128 Timer2 via HPLTimer2*****************************************************************************/module TimerJiffyAsyncM{ provides interface StdControl; provides interface TimerJiffyAsync; uses interface Clock as Timer;}implementation{#define JIFFY_SCALE 0x4 //cpu clk/256 ~ 32uSec#define JIFFY_INTERVAL 2 uint8_t jiffy; uint32_t jiffyCycles; bool bSet; command result_t StdControl.init() {// call Alarm.setControlAsTimer(); return SUCCESS; } command result_t StdControl.start() { atomic bSet = FALSE; return SUCCESS; } command result_t StdControl.stop() { atomic { bSet = FALSE; call Timer.intDisable(); } return SUCCESS; }// async event void Alarm.fired()async event result_t Timer.fire() { uint32_t localJiffyCycles; uint8_t localJiffy; atomic localJiffyCycles = jiffyCycles; if (localJiffyCycles == 0) { atomic localJiffy = jiffy; if (localJiffy) { atomic jiffy = 0; call Timer.setIntervalAndScale(localJiffy, JIFFY_SCALE); //sets timer,starts and enables interrupt } else { call Timer.intDisable(); atomic bSet = FALSE; signal TimerJiffyAsync.fired(); //finished! } } else { localJiffyCycles -= 1; atomic jiffyCycles = localJiffyCycles; call Timer.setIntervalAndScale(0xFF, JIFFY_SCALE); //sets timer,starts and enables interrupt } return(SUCCESS); } async command result_t TimerJiffyAsync.setOneShot( uint32_t _jiffy ) { // BUG fix: Nuno Pereira // TimerJiffy was not working correctly when _jiffy > 0XFF // now, when _jiffy > xxFF, jiffyCyles counts the number of 0xFF jiffy intervals if (_jiffy > 0xFF) { if (_jiffy > 0xFFFF) { atomic { _jiffy = _jiffy+1 + ((_jiffy+1) >> 8) + (_jiffy >> 16); jiffyCycles = (_jiffy >> 8)-1; jiffy = _jiffy; bSet = TRUE; } } else { atomic { _jiffy = _jiffy+1 + (_jiffy >> 8); jiffyCycles = (_jiffy >> 8)-1; jiffy = _jiffy; bSet = TRUE; } } call Timer.setIntervalAndScale(0xFF, JIFFY_SCALE ); //sets timer,starts and enables interrupt } else { atomic { jiffy = 0; bSet = TRUE; jiffyCycles = 0; } call Timer.setIntervalAndScale((uint8_t)_jiffy, JIFFY_SCALE ); // enables timer interrupt } return SUCCESS; } async command bool TimerJiffyAsync.isSet( ) { return bSet; } async command result_t TimerJiffyAsync.stop() { atomic { bSet = FALSE; call Timer.intDisable(); } return SUCCESS; }}//TimerJiffyAsync
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -