Vxworks取日历时间程序
2013-02-08
标签: VxWorks

在vxworks里取的系统时间是从开机到现在的时间,如果想取到日历时间的话只能借助外界的硬件支持了。在X86系统里,可以通过读取71端口来读取日历时间,以下是一个C程序,可以在vxworks下用。

#include

void ReadTime(int* pYear,int* pMonth,int* pDate,int* pDay,int* pHour,int* pMinute,int* pSecond);

void ReadTime(int* pYear,int* pMonth,int* pDate,int* pDay,int* pHour,int* pMinute,int* pSecond)

{

int OldYear,OldMonth,OldDate,OldDay,OldHour,OldMinute,OldSecond;

int YearTemp,MonthTemp,DateTemp,DayTemp,HourTemp,MinuteTemp,SecondTemp;

int Century;

OldYear="OldMonth"=OldDate=OldDay=OldHour=OldMinute=OldSecond=-1;

sysOutByte(0x70,0x32);

Century=(int)sysInByte(0x71);

for(;;)

{

asm pushf;//Save interrupt enable|disable status

asm cli;//Disable interrupt

sysOutByte(0x70,0xa);

if((0x80&sysInByte(0x71))!=0)

{

asm popf;//Restore interrupt enable|disable status

continue;

}

sysOutByte(0x70,9);

YearTemp=(int)sysInByte(0x71);

sysOutByte(0x70,8);

MonthTemp=(int)sysInByte(0x71);

sysOutByte(0x70,7);

DateTemp=(int)sysInByte(0x71);

sysOutByte(0x70,6);

DayTemp=(int)sysInByte(0x71);

sysOutByte(0x70,4);

HourTemp=(int)sysInByte(0x71);

sysOutByte(0x70,2);

MinuteTemp=(int)sysInByte(0x71);

sysOutByte(0x70,0);

SecondTemp=(int)sysInByte(0x71);

sysOutByte(0x70,0xa);

if((0x80&sysInByte(0x71))!=0)

{

asm popf;//Restore interrupt enable|disable status

continue;

}

if((OldYear!=YearTemp)||(OldMonth!=MonthTemp)||(OldDate!=DateTemp)

||(OldDay!=DayTemp)||(OldHour!=HourTemp)||(OldMinute!=MinuteTemp)

||(OldSecond!=SecondTemp))

{

OldYear="YearTemp";

OldMonth="MonthTemp";

OldDate="DateTemp";

OldDay="DayTemp";

OldHour="HourTemp";

OldMinute="MinuteTemp";

OldSecond="SecondTemp";

asm popf;

continue;

}

asm popf;//Restore interrupt enable|disable status

break;

}

*pYear=(Century>>4)*1000+(Century&0xf)*100+(YearTemp>>4)*10+(YearTemp&0xf);

*pMonth=(MonthTemp>>4)*10+(MonthTemp&0xf);

*pDate=(DateTemp>>4)*10+(DateTemp&0xf);

*pDay=DayTemp;

*pHour=(HourTemp>>4)*10+(HourTemp&0xf);

*pMinute=(MinuteTemp>>4)*10+(MinuteTemp&0xf);

*pSecond=(SecondTemp>>4)*10+(SecondTemp&0xf);

}

void main(void)

{

int t1,t2,t3,t4,t5,t6,t7;

ReadTime(&t1,&t2,&t3,&t4,&t5,&t6,&t7);

printf("%d %d %d %d %d %d %d\n",t1,t2,t3,t4,t5,t6,t7);

}

可能会用到的工具/仪表
本站简介 | 意见建议 | 免责声明 | 版权声明 | 联系我们
CopyRight@2024-2039 嵌入式资源网
蜀ICP备2021025729号