Unformatted text preview:

The PC’s Real-Time ClockNon-Volatile MemoryMotorola’s MC146818AFeatures of DS12887Programming InterfaceTen clock/calendar bytesOperating CapabilitiesFour Status/Control bytesOther NVRAM locationsExample: Diagnostic StatusNote on the NMI circuitryNon-Maskable Interrupt gateExample: setting alarm timeSet the alarm for 6:30:00 amFinish SET (and reenable NMI)Our ‘rtcdemo.s’ programEvent-Queue paradigmAn important ‘design pattern’In-class exerciseSuggested implementationThe PC’s Real-Time ClockAn introduction to the capabilities and programming of the Real-Time Clock and CMOS memoryNon-Volatile Memory•The original IBM-PC had no internal clock•Users had to run a utility program to reset the date and time after any system reboot •This defect was eliminated in the IBM-AT•A special battery-powered peripheral was added to keep track of the time and date•It also provided a small amount of memory which could retain configuration settingsMotorola’s MC146818A•PC-AT’s Real-Time Clock plus RAM was manufactured by Motorola Corporation•Other companies have ‘cloned’ this chip•Its capabilities are described online in an official datasheet by Dallas Semiconductor (see ‘Maxim’ integrated circuit: DS12887)•You can also get the Motorola datasheet (by writing to its corporate headquarters)Features of DS12887•Can operate over ten years without power•Counts seconds, minutes, hours, days, day-of-the-week, date, month, and year (with leap-year compensation), valid up until the year 2100 AD, with options for 12/24-hour clock and Daylight Savings •Can use binary or BCD representation•Provides 114 bytes of nonvolative storageProgramming Interface•The RTC interfaces with system software as an array of 128 bytes, accessed via i/o ports 0x70 and 0x71 using a multiplexing scheme:port 0x70: address-portport 0x71: data-port•A system quirk: The most significant bit at port 0x70 is used to control a gate that can ‘mask’ the Non-Maskable Interrupt circuitryTen clock/calendar bytesCurrent secondsAlarm secondsCurrent minutesAlarm minutesCurrent hoursAlarm hoursDay-of-the-WeekDate of the MonthCurrent MonthCurrent Year0x00x10x20x30x40x50x60x70x80x9Range is 0..59Range is 0..59Range is 0..59Range is 0..59Range is 0..23 or 1..12Range is 0..23 or 1..12Range is 1..7 (Sunday=1)Range is 1..31 Range is 1..12 (January=1)Range is 0..99Operating Capabilities•The RTC can be programmed to generate an interrupt under any combination of the following three conditions:1) time/date counters were updated2) current time equals the alarm time 3) periodic frequency interval restarts•The frequency of the periodic interrupt is a selectable rate (e.g., from 122 to 500ms)Four Status/Control bytesUIP Divider bitsSET PIE AIE UIE SQWE DM 24/12 DSEIRQF PF AF UF0 0 0 0VRT0xA0xB0xC0xDRate-Select0 0 0 0 0 0 0Other NVRAM locations•Besides these 14 dedicated RTC bytes, there are 114 byte locations which can serve as nonvolatile storage in whatever manner the system designer decides•IBM has established some ‘standard’ uses for many (but not all) of these locations•A fairly complete CMOS Memory Map is accessible online (see course website)Example: Diagnostic StatusPowerStatusfailureCheckSumbadPOSTConfiginvalidRAMSizewrongFixedDiskbadCMOSTimeinvalidreserved reserved0xEDuring the Power-On Self-Test, the ROM-BIOS routines perform tests of the memory and peripheral devices, and record any failures/errors in this Diagnostic Status byteNote on the NMI circuitry•The CPU has a special input-signal that is ‘non-maskable’ (i.e., CLI / STI instructions have no effect on it), intended to be used for signaling urgent or catastrophic events (such as loss of power or memory failures)•But sometimes, during a “critical section” of system code, it is necessary to prohibit even these urgent interrupts (e.g., when stack or Interrupt Descriptors are invalid)Non-Maskable Interrupt gateCPUAND NMIError-signals Logic GATE(port 0x70, bit 7)PICIRQ 0-7INTRPICIRQ 8-15IFExample: setting alarm time; inhibit clock updates while reprogrammingmov $0x8B, %al # access register Bout %al, $0x70 # and disable NMIin $0x71, %al # read register Bor $0x80, %al # set the SET bitout %al, $0x71 # write register BSet the alarm for 6:30:00 ammov $0x0685, %ax # hoursout %ax, $0x70mov $0x3083, %ax # minutesout %ax, $0x70mov $0x0081, %ax # seconsout %ax, $0x70Finish SET (and reenable NMI)# clear the ‘SET’ bit in register Bmov $0x8B, %al # select register Bout %al, $0x70 # for access w/o NMIin $0x71, %al # read register Band $0x7F, %al # clear its SET bitout %al, $0x71 # write register B# reenable the Non-Maskable Interruptsmov $0x0D, %al # select register Dout %ax, $0x70 # and reenable NMIOur ‘rtcdemo.s’ program•We illustrate the Real-Time Clock chip’s ‘update’ interrupt by redisplaying the time whenever the clock-counters are updated•Register B controls which interrupts occur•But don’t change bits 0, 1, 2 (they control the data-format (binary or BCD), select 12 or 24 hour clock, and activate the Daylight Savings Time counter-compensationEvent-Queue paradigmfree freeEventrecordEventrecordEventrecordfree free freeHEADTAILbase edgeThe Interrupt Service Routine(s) insert new event-records in the queue,while the main application-loop removes event-records from the queue.An important ‘design pattern’•Many modern user-centered applications use the ‘event-queue’ paradigm:initialize_the_system();while ( !done ){dequeue_next_event( &event_record);process_that_event( &event_record );}cleanup_the_system();exit(0);In-class exercise•Modify our ‘rtcdemo.s’ program so that an ‘alarm’ interrupt will get triggered after an agreed amount of time has elapsed (for example, 10 seconds) and use that event to exit the program’s main loop (instead of using the built-in loop-counter variable)Suggested implementation•Easiest and most elegant way to achieve the requested program modification is to adjust the Interrupt-Service Routine so it will save a 4-part event-record (instead of a 3-part event-record), the new item to be included is the RTC status-register value•Then the main loop can test the status it finds within an event-record, and can either loop or exit, depending on which event-type it


View Full Document

USF CS 630 - The PC’s Real-Time Clock

Documents in this Course
Load more
Download The PC’s Real-Time Clock
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The PC’s Real-Time Clock and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The PC’s Real-Time Clock 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?