dirtwillfly 发表于 2014-1-6 20:48
楼主说的我有点晕,能否上传代码看一看?
MSP430F2272芯片内的存储结构如下图:
...
谢谢!
g_SysTime 变量的定义如下:
__no_init volatile u32 g_SysTime@(u16)0x0204; //系统时间戳,单位10ms
TB1中断改变 g_SysTime代码如下:
#pragma vector=TIMERB1_VECTOR
__interrupt void Timer_B1_ISR(void)
{
switch( TBIV )
{
case TBIV_TBCCR1: // TBCCR1 use for a 10ms time interrupt,keep the interrupt enable and reset
TBCCTL1 &= ~CCIFG;
TBCCR1 = TBR + TabCCRCont[ACLK_10MS];
g_SysTime += 1;
break;
case TBIV_TBCCR2: // TBCCR2 use for a long time interrupt
TBCCTL2 &= ~CCIFG;
TBCCTL2 &= ~CCIE;
g_bFlexTimer_标志寄存器 = TRUE;
break;
case TBIV_TBIFG: // overflow
NOP();
break;
}
}
通信过程中对时操作修改g_SysTime的过程:
static void adjust_timer_in_com(void)
{
u16 Temp = 0;
u16 Temp2 = 1638 * (DeviceID[2]-1) + 328; //60ms * (VsID-1) + 10ms
u16 LocalTAR = TAR;
int DVal = 0;
u32 TimeTemp;
Temp |= RX_Sbuff[POSI_SYS_TIME+1];
Temp <<= 8;
Temp |= RX_Sbuff[POSI_SYS_TIME+2];
Temp += RF_AIR_DELAY; //考虑RF传输延迟
if ( Temp >= Temp2)
{
Temp = Temp - Temp2;
TAR = Temp;
}
else
{
DVal = Temp2 - Temp;
TAR = 0;
while (TAR < DVal);
TAR = 0;
}
TimeTemp = RX_Sbuff[10];
TimeTemp <<= 8;
TimeTemp += RX_Sbuff[10+1];
TimeTemp <<= 8;
TimeTemp += RX_Sbuff[10+2];
TimeTemp <<= 8;
TimeTemp += RX_Sbuff[10+3];
DIS_TB1_INT();
g_SysTime = TimeTemp;
EN_TB1_INT();
}
另外还有一些地方会读取g_SysTime的值,读取时没有关闭中断。发现g_SysTime在与接收设备通信后会出错,但是接收到接收设备下发的时间是没有错的。
|