VxWorks for x86系統(tǒng)中實(shí)時(shí)時(shí)鐘的應(yīng)用

函數(shù)BIOSTimeGet ()用來從端口讀取BIOS時(shí)間,在該函數(shù)內(nèi)部調(diào)用BCD2BIN()函數(shù),其返回值為tm型結(jié)構(gòu)的日期和時(shí)間。具體內(nèi)容如下:


函數(shù)SetSysTime ()可用來將系統(tǒng)時(shí)間設(shè)置為實(shí)時(shí)時(shí)鐘時(shí)間,在該函數(shù)的內(nèi)部調(diào)用BIOSTimeGet ()函數(shù)的內(nèi)容如下:

調(diào)用SetSysTime()函數(shù)后再調(diào)用GetSysTime()函數(shù),其顯示內(nèi)容就是當(dāng)前實(shí)時(shí)時(shí)鐘的時(shí)間,這表明系統(tǒng)時(shí)間和實(shí)時(shí)時(shí)鐘已實(shí)現(xiàn)了同步。
3實(shí)時(shí)時(shí)鐘的特定時(shí)間設(shè)置
在某些應(yīng)用中,有時(shí)我們也希望能校正實(shí)時(shí)時(shí)鐘,也就是能將BIOS中的實(shí)時(shí)時(shí)鐘設(shè)置為某個(gè)特定時(shí)間。這個(gè)功能同樣可以通過訪問端口0x70,0x71來實(shí)現(xiàn)。
需要注意的是,寫入到端口的數(shù)據(jù),其格式為BCD碼,因此在使用前,需要將數(shù)據(jù)從十進(jìn)制數(shù)轉(zhuǎn)換為BCD碼。
函數(shù)BIN2BCD()可用來將十進(jìn)制數(shù)轉(zhuǎn)換為BCD碼,它的輸入為十進(jìn)制數(shù),返回值為BCD碼。其內(nèi)容如下:

評(píng)論