?? timer3.c
字號:
//----------------------------------------------------//
//-------Institute Of Computing Technology-----------//
//------------Chinese Academic Science---------------//
//-----中國科學(xué)院計算技術(shù)研究所先進測試技術(shù)實驗室-----//
//----------------------------------------------------//
/**
* @copyright:nbicc_lpp
* @this is timer1 driver code
* @author liulingyi (lingyiliu@ict.ac.cn)
* zhouqiang (zhouhongren@163.com)
*
* @data:2005.11.28
* @version:0.0.1
* @updata:$
*
*/
#include "timer3.h"
extern uint16_t timer3queue_getnextinterval(void);
extern void timer3queue_interrupt(void);
void Timer3_intDisable(void)
{
{ os_atomic_t _nesc_atomic = os_atomic_start();
{
ETIMSK &= 0xef;
//TCCR3B = 5;
//OCR3A=0;
//TCNT3 = 0x0000;
//TCCR3B=0x00;
ETIFR |=(1<<OCF3A);
}
os_atomic_end(_nesc_atomic); }
}
uint8_t Timer3_fire(void)
{
timer3queue_interrupt();
//OS_post(timer3queue_interrupt);
}
uint8_t Timer3_setIntervalAndScale(uint16_t interval, uint8_t scale)
{
if (scale > 7) {
error("\nscale is out of scope\n");
return 0;
}
//uint16_t temp_test_tnt3;
//uint32_t sys_time;
{ os_atomic_t _nesc_atomic = os_atomic_start();
{
//temp_test_tnt3=TCNT3 ;
ETIFR |=(1<<OCF3A);
OCR3A = interval;//this is the scale
OCR3B = 0x0000;
OCR3C = 0x0000;
TCNT3 = 0x0000; //this is the counter
TCCR3A = 0x00;//Output: A: Disconnected, B: Disconnected, C: Disconnected,WGM[1..0]=00
//scale |= 0x08;//
TCCR3B = scale;//clk/(scale),WGM[3..2]=01
TCCR3C = 0x00;//
ETIMSK |= 0x10;//OCIE1A is enable
//sys_time=systime32();
}
os_atomic_end(_nesc_atomic); }
//printf("\n**TCNT3 is %04x\n",temp_test_tnt3);
//printf("sys time is %08lx",sys_time);
return SUCCESS;
}
//供高層調(diào)用的定時開始函數(shù)。
void Timer3_sethalfsymbol(uint16_t symbols)
{
uint32_t halfsymbols;
halfsymbols=((uint32_t)symbols)<<1;
if(halfsymbols<=65535)
Timer3_setIntervalAndScale(halfsymbols, 0x5);
else
Timer3_setIntervalAndScale(halfsymbols-65535, 0x5);
}
//供高層調(diào)用獲得下一次定時的比較寄存器應(yīng)當(dāng)設(shè)置的值
uint32_t Timer3_acquireInterval(uint16_t interval)
{
uint32_t temp;
uint16_t tcnt_3;
tcnt_3=TCNT3;
temp=(uint32_t)tcnt_3+(((uint32_t)interval)<<1);
// (temp>=65535) temp=temp-65535;
return (temp);
}
uint8_t Timer3_adjustInterval(uint16_t interval)
{
{ os_atomic_t _nesc_atomic = os_atomic_start();
{
/*if(interval<65536)*/
OCR3A = interval;//this is the scale
/* else
OCR3A =interval-65535;*/
}
os_atomic_end(_nesc_atomic); }
return 1;
}
//供底層調(diào)用獲得定時器比較寄存器應(yīng)當(dāng)設(shè)置的值,下一個定時任務(wù)
uint16_t Timer3_getnextInterval(void)
{
return timer3queue_getnextinterval();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -