vxworks for x86读取bios时间的解决方法
2014-04-29 17:13
253 查看
vxworks for x86读取bios时间的解决方法
系统时间与bsp有关,在vzworks for x86系列的目标没有直接读取RTC(实时时钟控制器)的函数,用time.h中的函数读到的始终是 00:00:00, Jan. 1 1970.
所以在x86系列的机器中,我们可以从bios中读取当前的时钟。用sysInByte(),sysOutByte(),在70,和71端口读取或写bios里的时间.
首先要分析bios的内容,找出秒,分,时,天,月,年的存放地址。
他们分别是: 0x00,0x02,0x04,0x07,0x08,0x09
然后从71端口读出相应的值,进行转换。
如:秒
sysOutByte(0x70,0x00);
second = sysInByte(0x71);
读出的second进行转换,:
second = (second &0x0F) + 10*((second &0xF0)>>4);
示例代码:
time_t biostime()
{
struct tm ahora;
unsigned char cHour, cMin, cSec;
unsigned char cDay, cMonth, cYear;
sysOutByte(0x70,0x00/*second*/);
cSec = sysInByte(0x71);
ahora.tm_sec = (cSec&0x0F) + 10*((cSec&0xF0)>>4);
sysOutByte(0x70,0x02/*minut*/);
cMin = sysInByte(0x71);
ahora.tm_min = (cMin&0x0F) + 10*((cMin&0xF0)>>4);
sysOutByte(0x70,0x04/*hour*/);
cHour = sysInByte(0x71);
ahora.tm_hour = (cHour&0x0F) + 10*((cHour&0xF0)>>4);
sysOutByte(0x70,0x07/*day*/);
cDay = sysInByte(0x71);
ahora.tm_mday = (cDay&0x0F) + 10*((cDay&0xF0)>>4);
sysOutByte(0x70,0x08/*month*/);
cMonth = sysInByte(0x71);
ahora.tm_mon = (cMonth&0x0F) + 10*((cMonth&0xF0)>>4) - 1;
sysOutByte(0x70,0x09/*year*/);
cYear = sysInByte(0x71);
ahora.tm_year = 100 + (cYear&0x0F) + 10*((cYear&0xF0)>>4);
return mktime(&ahora);
}
我们在系统初始化时读取bios时间一次,然后修改系统时钟:
用
clock_settime(..)
以后我们得到的时间就都是当前的正确时间
示例:
void inittime()
{
int res;
struct timespec ts;
struct tm daytime;
time_t stime;
ts.tv_sec = biostime();
ts.tv_nsec = 0;
res = clock_settime(CLOCK_REALTIME, &ts);
stime = time(NULL);
daytime = *localtime(&stime);
printf ( "time is :%s\n", asctime(&daytime) );
}
系统时间与bsp有关,在vzworks for x86系列的目标没有直接读取RTC(实时时钟控制器)的函数,用time.h中的函数读到的始终是 00:00:00, Jan. 1 1970.
所以在x86系列的机器中,我们可以从bios中读取当前的时钟。用sysInByte(),sysOutByte(),在70,和71端口读取或写bios里的时间.
首先要分析bios的内容,找出秒,分,时,天,月,年的存放地址。
他们分别是: 0x00,0x02,0x04,0x07,0x08,0x09
然后从71端口读出相应的值,进行转换。
如:秒
sysOutByte(0x70,0x00);
second = sysInByte(0x71);
读出的second进行转换,:
second = (second &0x0F) + 10*((second &0xF0)>>4);
示例代码:
time_t biostime()
{
struct tm ahora;
unsigned char cHour, cMin, cSec;
unsigned char cDay, cMonth, cYear;
sysOutByte(0x70,0x00/*second*/);
cSec = sysInByte(0x71);
ahora.tm_sec = (cSec&0x0F) + 10*((cSec&0xF0)>>4);
sysOutByte(0x70,0x02/*minut*/);
cMin = sysInByte(0x71);
ahora.tm_min = (cMin&0x0F) + 10*((cMin&0xF0)>>4);
sysOutByte(0x70,0x04/*hour*/);
cHour = sysInByte(0x71);
ahora.tm_hour = (cHour&0x0F) + 10*((cHour&0xF0)>>4);
sysOutByte(0x70,0x07/*day*/);
cDay = sysInByte(0x71);
ahora.tm_mday = (cDay&0x0F) + 10*((cDay&0xF0)>>4);
sysOutByte(0x70,0x08/*month*/);
cMonth = sysInByte(0x71);
ahora.tm_mon = (cMonth&0x0F) + 10*((cMonth&0xF0)>>4) - 1;
sysOutByte(0x70,0x09/*year*/);
cYear = sysInByte(0x71);
ahora.tm_year = 100 + (cYear&0x0F) + 10*((cYear&0xF0)>>4);
return mktime(&ahora);
}
我们在系统初始化时读取bios时间一次,然后修改系统时钟:
用
clock_settime(..)
以后我们得到的时间就都是当前的正确时间
示例:
void inittime()
{
int res;
struct timespec ts;
struct tm daytime;
time_t stime;
ts.tv_sec = biostime();
ts.tv_nsec = 0;
res = clock_settime(CLOCK_REALTIME, &ts);
stime = time(NULL);
daytime = *localtime(&stime);
printf ( "time is :%s\n", asctime(&daytime) );
}
相关文章推荐
- vxworks for x86读取bios时间的解决方法
- vxworks for x86读取bios时间的解决方法 分类: vxWorks 2014-04-29 17:13 478人阅读 评论(0) 收藏
- vxworks for x86读取bios时间的解决方法
- vxworks for x86读取bios时间的解决方法(转)
- matlab读取excel自定义时间非常规解决方法
- 关于解决从F1BOOK中读取时间类型的数据的方法
- PHP——读取时间小时显示不正确的解决方法
- OLEDB方式读取Excel丢失数据的原因和解决方法
- detectMultiScale 读取冲突的一个解决方法
- 主板BIOS被破坏时的解决方法
- 关于vsftpd下显示的修改时间与系统时间不一致的解决方法
- 关于 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。的解决方法
- ifstream(一)之 eof() 函数——解决读取文件最后一个数据多读一次的方法
- ubuntu 状态栏没显示时间 解决方法
- js处理php输出时间戳对不上号的解决方法
- BIOS常见故障及解决方法
- elf_i386或elf_x86_64:没有那个文件或目录 解决方法
- 真正解决方法之装不上vcredist_x86 提示Command line option syntax error. Type Command /? for Help.
- 在Asp.net的HttpCookie中写入汉字,读取时为乱码的解决方法!
- PHP-代码-读取文本换行符的小问题解决方法