Nonetheless, the real time clock's primary importance is only during boot, when the xtime variable is initialized. The kernel does not typically read the value again however, some supported architectures, such as x86, periodically save the current wall time back to the RTC. On boot, the kernel reads the RTC and uses it to initialize the wall time, which is stored in the xtime variable. On the PC architecture, the RTC and the CMOS are integrated and a single battery keeps the RTC running and the BIOS settings preserved. The RTC continues to keep track of time even when the system is off by way of a small battery typically included on the system board. The real-time clock (RTC) provides a nonvolatile device for storing the system time. The actual behavior and implementation of these devices varies between different machines, but the general purpose and design is about the same for each. Or r4,r4,r3 # Combine bits 0.15 and 16.Architectures provide two hardware devices to help with time keeping: the system timer, which we have been discussing, and the real-time clock. Ldwio r4,20(r7) # Read snapshot bits 16.31 Ldwio r3,16(r7) # Read snapshot bits 0.15 Stwio r0,16(r7) # Tell Timer to take a snapshot of the timer Stwio r2, 4(r7) # Start the timer without continuing or interruptsĪssembly Example 2: Reading the current value of the timer into R4 Stwio r2, 8(r7) # Set the period to be 1000 clock cycles Movia r7, 0xFF202000 # r7 contains the base address for the timer WARNING: Do not try to read the Periodh/l registers directly.Īssembly Example 1: Setting the timer to run for 1000 clock cycles, and stop when it times out By writing to either one of the snapshot registers (the written value is ignored), the current value of Periodh and Periodl, will be copied into the corresponding snapshot registers, which can then be read as in example 2 below. Instead, the Counter Snapshot is used to copy the current time remaining, which can then be safely read by the user. Reading the time remaining in the timer can not be done by reading the Periodh/l registers. The continue bit determines whether the timer will then wait until 1 is written to the start bit again, or continue running immediately. When a timeout occurs, the timer's counter is reset to the period, regardless of the "continue" bit. When a timeout occurs, the Timeout bit in the Control Register will stay as 1 until the user writes 0 to the status register. Both those registers are only 16-bits, even though they take up 32-bits of the address space. The full 32-bit period of the timer is given by the combination of "Periodh" and "Periodl". The timer counts downwards on a 100MHz clock, and runs in terms of clock cycles (a period of 100000000 will cause the timer to timeout in 1 second). Write 0 to status register to clear timeout bit (see address map above) Timer1 use IRQ line 0 Timer2 use IRQ Line 2 None (though a period must be written before running the timer, or it will immediately timeout) Periodh - upper 16 bits of Timeout period Periodl - lower 16 bits of Timeout period Otherwise it will just reload the timeout period, but not start) Tiner 1: 0xFF202000 and Timer2: 0xxFF202020Ġ - Timeout (1 if timer has timed out - write 0 to this address to clear)ġ - cont (if this bit is 1, timer will restart and continue when it times out, DeviceĦ 32-bit mapped registers (only lower 16 bits used) A user loads the timer with the number of clock cycles they'd like to wait, and then polls the "Timeout" bit or optionally enables an interrupt to indicate to the processor that the period has elapsed. The timer is a peripheral that allows the user to measure real-time as a number of clock cycles.
0 Comments
Leave a Reply. |