








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









3/3/
See posted lab schedule for pre-lab, in-lab and post-lab due dates.
The purpose of this lab is to:
In lab 5, we developed devices drivers that polled UART registers to determine when the device was ready or had data available. The calculator application does not require much processing bandwidth, so we could afford to spend processing time “polling” or looping and reading the UART. In many real time applications it is not practical to spend process- ing time polling nor is it easy to manage many devices with pooling schemes. The inter- rupt mechanism provides a way to interrupt a software applications in an efficient and organized manner. Although it is possible to avoid polling the UART by programing the UART for interrupts, it is a bit involved for an introduction to interrupts. Instead, we will develop a simple one second timer application that will run with your lab 5 calculator program. The calculator will mimic a processor hungry application by spending most of the processing time read- ing the UART device register status. The one second timer application will interrupt the calculator program to maintain timer accuracy and user interaction. The one second timer will simply count at a one second rate displaying the count on the 7segment display in hex. The count is stopped or started with one of the pushbuttons. A count may be loaded into the counter with the slides witches and one of the pushbuttons. The pushbuttons will be serviced as external interrupts and will be mapped to the PPC via FGPA connections. It is possible to make a one second timer in the FPGA and map it to an external interrupt: however, we will use the Real Time Clock (RTC) device on the PPC823. It can be configured to clock at a one second rate and can be mapped to the exter- nal interrupt.
The timer will count at a one second rate displayed on the right most 2 digits of the 7-seg- ment display. The timer will start and stop alternately with pushbutton S0 (BTN0). The counter should be stopped at program initialization. The timer can be preset by setting the value on the slide switches and loading by pressing pushbutton S1 (BTN1).
To process the one second timer efficiently the clock source and pushbutton SO and S should be interrupt driven.
Interrupt software must be located in specific parts of memory and the hardware initialized in an order dependent manner. It is therefore necessary to organize the software into func- tional modules. A very useful supplement is posted with the lab that goes into much neces- sary detail. Be sure to look it over. A general description of the primary software components follows:
1. Assembly Main
Initializes stack frame, stack pointer and passes control to main c program. See lab 5 for details.
2. Device Initialization Initializes device registers, specifically the one second clock source. The MPC RTC (real time clock) will be used as the clock source. See appendix A and B and the White Book for register details and use. In addition, you will need to initialize the UART with a ser_init() call. 3. Initialize Interrupts Initializes the SIU (System Interface Unit) external interrupt controller registers. The controller is used to manage multiple external and device interrupt sources (see page 12-5 Figure 12-2). The controller provides a single “external interrupt” to the power pc core. The interrupt is enabled by a system register. See appendix A, C and D 4. External Interrupt Service Routine When an external interrupt is passed to the power pc core, execution is passed to location 0x500. A service routine will be located here to determine what the interrupting source is and then pass control to the appropriate device handler. This routine is also responsible for saving and recovering ANY registers (volatile or non-volatile) effected by the interrupt process. If the link register is to be saved, do not save it in the previous stack frame reserved location. Instead, save it in the ISR stack like you would any other GPR. In an interrupt context, you cannot be certain that link register space is provided in the previous stack frame. If you call a C function in your interrupt handler, you will have to provide reserved link register space (stack pointer + 4) in your ISR stack to maintain ABI compli- ance. 5. Interrupt Handlers
the flip-flops.You may choose an addresses between 0x2000000 and 0x3500000 that does not conflict with any of your memory mapped devices: memory, switches, displays, etc.
Note, it is not sufficient to reset the flip-flops with just an address decode. The address is only guaranteed on the address bus during TS and the rising edge of clock. It is possible that an address decoder will decode during an address bus transition providing a unwanted clear of your interrupts. Take care to provide the logic and lessons you learned in lab 3 when creating any memory mapped device register. In addition, you may provide a data path to read the D flip-flops for debugging purposes. As in lab 3, you will have to use tristate buffers and the appropriate bus read logic like that used in lab 3 to read the switches. Two external interrupt inputs IRQ1 and IRQ7 are available in the base project. The fre- quency of interrupt is so low for this lab that the interrupt priority in not important.
The core of the PPC has just one external interrupt. To manage and provide more inter- rupts, an on chip interrupt controller is provided. It is described in the White Book in sec- tion 12.3. The interrupt controller manages 8 external interrupts IRQ0-7 and 8 internal device interrupts LV0-7. The external interrupts are used to interrupt the processor from external sources such as the pushbuttons. The internal interrupts are used to map interrupts from on chip devices such as the UART and RTC. The interrupt controller is accessed via it’s memory mapped registers. For details see the appendix at the end of this document and the White Book.
The MPC823 includes many devices to support various applications including the UART, Real Time Clock (RTC), General Purpose Timers (lab 7), USB controllers, Ethernet Con- trollers and many more. The RTC is typically used to provide date and time information for files systems, etc. It can be programmed to provided a one second clock that interrupts once a second. It will interrupt on one of the internal (level) interrupts. It is accessed via it’s memory mapped registers. See the appendix at the end of this document for details. The RTC is clocked by the PPC system clock via the PPC clock manager. A register (SCCR) in the clock manager must be programmed to provide the correct clock rate to the RTC. For details see the appendix at the end of this document and the White Book
The C language has the provision for writing assembler in line. This can be advantageous for it’s self documenting style and is quite common. Of course, you must take care to fol- low any ABI compliance issues.
For our purposes, we will write in assembler when it is necessary to work at a register level for the sake of simplicity and to give you some practice with assembler. The Device and Interrupt Controller Initialization, External Interrupt Service Routine and Interrupt Handlers are all very register level oriented applications and should written in assembler.
The program code in the past labs was located at 0x10000 and any data was located at 0x11000. The code sections were identified in the code with the .text and .data assembler directives and located during the linking phase. The locations are specified in the link-txt file as follows: Sections { .text ADDRESS 0x10000:
.data ADDRESS 0x11000: } Since the external interrupt service routine must be located at 0x500, it is necessary to add another program section. Like the text and data sections it is necessary to define a section in the code for the service routine with an assembler directive. Lets say the section name will be ext_int_vec. To define the section in the code write: .section ext_int_vec, text All code after this statement will be located at the location defined by ext_int_vec in the link_txt file. To locate the code during linking, the link_txt file should look like this: Sections{ .text ADDRESS 0x10000: .data ADDRESS 0x11000: ext_int_vec ADDRESS 0x500: } Note: there is no period before ext_int_vec. All other assembler and C code should be located in the text (program) section. You can locate all your assembly code in one source file if you like as follows:
declare data arrays, variables, etc.
g. If SIMASK is correct, see if EE bit is set in MSR.
a. Again, disable all other interrupts.
b. Debug the interrupt path by examining the interrupt controller registers via the SingleStep register window.
c. Note, in this case the interrupt event bit is in the external flip-flop. To check it you will have to provide a data path (mentioned in hardware design) or observe on the logic analyzer.
d. Check to see if the handler is performing the desired function by single stepping thru the code.
Pre-lab questions, 1- 9, may be done as a group.
a. The interrupt handler doesn’t call any functions, but uses r0, r3, r4, r30, and r
b. The interrupt handler calls ABI-compliant functions, but doesn’t use any regis- ters itself
See debugging procedure for suggestions on development. Demonstration 1.1: Demonstrate your thoroughly tested system to the lab instructor.
a. How would your system change if you configured IRQ1 as an edge-triggered interrupt?.
b. Focusing on section 12.3.3.1, how do you think the logic inside the MPC that implements edge-triggered interrupts compares to the logic you built to drive the level-sensitive interrupt request line?
System Clock and Reset Control Register (SCCR) (p. 5-3) This register configures several options related to various MPC823 clock signals. The two fields related to the real-time counter are RTSEL and RTDIV. Set these fields so that the RTC uses the crystal oscillator divided by 512. You must preserve all other bit fields. RTCSC – Real-Time Clock Status and Control Register (p. 12-18) The RTCSC register contains both status bits and control bits. The following fields and bits should be set. RTCIRQ: Interrupt priority level should be set to level 0. These bits are one hot coded. For example, set bit 0 to cause a Level 0 interrupt, bit 1 to cause a Level 1 interrupt, etc.
SEC: This is a status bit indicating that a one second event occured. It is mapped to the interrupt controler at the level set in RTCIRQ. This bit must be cleared in the interrupt handler. To clear, a logical 1 is written to it.
ALR: This feature is not used for this lab. It should be a logical 0. Bit 10: Reserved and set to logical 0. 38K Real-Time Clock Source Select: The 32K clock should be selected. Note there is also a 38K selection. SIE Seconds Interrupt Enable: This bit needs to be set (logical 1) to map the SEC bit to the interrupt controller. ALE: This feature is not used for this lab. It should be a logical 0. RTF Real Time Freeze Enable: This feature is not used for this lab. It should be a logical
RTE Rea Time Clock Enable: This bit enables the operation of the Real Time Clock. It should be set to logical 1. Read the referenced section in the White Book for more details. Note this is a half word addressed register.
To prevent buggy software from accidentally writing certain critical registers that could seriously mess up the system, the MPC823 protects these registers using “key” registers. If you write to a protected register without first writing a special “key value” to the corre- sponding “key register”, then the write will fail. The error will be reported as a machine check error. The protected device registers you will use in this lab are RTCSC and SCCR. The corresponding key registers are RTCSCK and SCCRK, respectively. The key value for all of the registers is the same, 0x55CCAA33. It is necessary to write the key register immediately before writing the respective control register. For example, SCCRK<--key code SCCR<-- write value A few notes about debugging the key registers:
module debouncer (
input clkin,
input swin,
output reg swout );
reg [19:0]counter;
always @(posedge clkin) counter <= counter +1;
always @(posedge counter[19])swout <= swin;
endmodule
Print this page and present it to your lab instructor when demonstrating the various lab sections. Turn this sheet in with your post lab or when your in lab demonstration is due. You are required to turn in only one demonstration sheet per group.
D1.1 Demonstrate operational system. Lab instructors initials:
List Partners Names