Download - Controlling Modules with MMRs
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Controlling Modules with MMRsControlling Modules with MMRs
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
MPC555 Block DiagramMPC555 Block Diagram
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
How Do I Control These Modules?How Do I Control These Modules?
• These devices get their operating instructions through a set of registers
• The CPU can modify these registers through memory addresses– “Memory-Mapped Registers”
• What do these registers do?• Where do I find them?
• The Controller’s Users Manual is the definitive source!
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Internal Memory MapInternal Memory Map(MPC555 user’s manual, Appendix A)
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
A Simple MMR-Driven DeviceA Simple MMR-Driven Device
Periodic Interrupt Timer
• This basic timer has many uses– To implement a clock– To check user input periodically– To monitor environment changes– To switch between programs
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Periodic Interrupt TimerPeriodic Interrupt Timer
A timer is basically a counter of clock cycles.
count register
Adder
-1
mux
count
reset
clock zero? timer expires
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Periodic Interrupt TimerPeriodic Interrupt TimerTime Period
= (count + 1) × clock cycle time= (count + 1) / clock frequency
EX: The clock frequency is 5MHz.The needed time period is 10ms.What is the count value?
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Periodic Interrupt TimerPeriodic Interrupt TimerTime Period
= (count + 1) × clock cycle time= (count + 1) / clock frequency
EX 2: The clock frequency is 5MHz.The needed time period is 1 sec.What is the count value?
FYI: The count register is 16-bit
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Periodic Interrupt TimerPeriodic Interrupt Timer
• How to program a timer?– Set up count value– Check if the timer expires– Configure interrupt, if interrupt is to be used– Read current value (if supported)
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
What does the manual say?What does the manual say?
• Check the table of contents:
(Page 6-15 has a short description of what the timer does)
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Internal Memory MapInternal Memory Map
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
MPC555 PIT ProgrammingMPC555 PIT Programming
3 Registers form the MPC555 PIT programming interface
1. PICSR: Periodic Interrupt Control & Select Register
2. PITC: PIT Counter
3. PITR: Periodic Interrupt Timer Register
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
MPC555 PIT ProgrammingMPC555 PIT Programming
PIT Enable0: enable decrement counter1: disable decrement counter
PInterrupt Enable0: disable interrupt1: enable interrupt
PIT Freeze0: no effect1: disable decrement counter if internal signal FREEZE is asserted
PIT Status0: no PIT int asserted1: PIT int asserted
0x002FC240
PS PIE PITF PTE
0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
PIRQ
Interrupt levelfor PIT
PICSR: Periodic Interrupt Control & Select Register
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
MPC555 PIT ProgrammingMPC555 PIT Programming
PTE: PIT enable PIF: PIT freezePITC: PIT count value PS: PIT statusPIE: PIT interrupt enable PITR: current counter value (Read-Only)
PTE
ClockDisable
PIF
16-bitModuluscounter
PITC
PS
PIE
PIT Interrupt
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
PITC: PIT CounterPITC: PIT Counter
0
PITC
16
PITC: PIT counter
PIT Time-out period = (PITC+1)/(PIT Frequency)
PIT Frequency depends on another module…
0x2F C244
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
PITR: Periodic Interrupt Timer RegisterPITR: Periodic Interrupt Timer Register
16Reserved
31
PIT: Leftover (current) count in PIT counter
Writes to PITR have no effect: read only.
If you want to read the current PIT count to estimate time to next PIT interrupt?
0x2F C248
PIT150
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
PIT InitializationPIT Initialization; r4 base address of SIU regs
lis r4, 0x2f
; set PISCR bits: PIRQ=08, PS=PS, PIE=1, PITF=0, PTE=0; so flag is cleared, interrupt is enabled, timer is; enabled, and level is assigned (Level 0)
li r0,0x0804 sth r0,0xC240(r4)
;PITC = 33000 = 0x80e8 and store it in PITC (0x2fc244) li r5, 0x80e8
sth r5, 0xC244(r4)
;now enable PIT: PTE = 1 lhz r0, 0xC240(r4) ori r0, r0, 0x1 sth r0, 0xC240(r4)
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
How to handle a PIT InterruptHow to handle a PIT Interrupt
Easy, as far as module handlers go
Write a ‘1’ to the PS field. This indicates that you’ve handled the interrupt, and the count will immediately start over again with the same period (from PITC)
If you want to change the period, modify PITC.
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Software Watchdog TimerSoftware Watchdog Timer• Timer used to guarantee forward progress for the processor.
• SWT must get attention every so often, or it will generate a NMI (reset)
CS 478: Microcontroller SystemsUniversity of Wisconsin-Eau Claire Dan Ernst
Configuring the SWTConfiguring the SWT