Download Bus Interfacing for 1 and 0 Devices - Design Microprocessor Systems | EECS 373 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!
EECS 373
Lab 3: Bus Interfacing for I/O Devices
1/28/
Schedule
See posted lab schedule for pre-lab, in-lab and post-lab due dates.
Objectives
The purpose of this lab is to:
- Introduce you to the basic logic required to interface a device to the MPC823 bus.
- Observe the interaction of hardware and software in a very simple environment.
- Gain very basic experience with system design involving hardware, software, and integration.
Overview
Peripherals such as memory, USB controllers, keypads and displays transfer data between the general purpose processor via an external bus interface. The interface allows the pro- cessor to read or write registers in peripheral devices. The hardware interface is com- pletely transparent from the perspective of a programmer. IO registers are simply read or written with software instructions. For this lab, you will design, develop and debug an external bus interface to the switches and led displays. You will also write a simple program in assembler that will use the switches as inputs and the LEDs as outputs.
Design Specifications
Hardware Design The hardware interface will consist of two I/O device registers:
- A 32 bit read register that provides the contents of the slide switches and pushbutton switches. The register is located at the address 0x02900000. The switches are mapped such that the eight slide switches are in bits 24-31(SW0-SW7) and the push button switches are in bits 20-23 (BTN0-BTN3).
Although we will design the hardware interface to the switches as though we are reading a register or memory location, it will not be necessary to use a register device. The switches maintain their state, so it is only necessary to enable the switch states on to the processor data bus during the read cycle.
- A 32 bit write register that will allow data to be displayed on the single bar leds (LDO-LD7) and the two most right 7 segment displays. The register is located at address 0x02900004. The data is mapped such that the right most 2, seven-segment displays must show the hexadecimal value contained in bits 24-31. The bar-graph display should show the binary value contained in bits 16-23 (0 = off, 1 = on). Although all 32 bits of each register are not mapped to devices, each register will be treated as a 32 bit quantity or is âword addressedâ. That means the software will read a 32 bit quantity and write a 32 bit quantity. The software selects (masks) the appropriate infor- mation. You can assume the unused bits are indeterminate.
Software Design The software component consists of an assembly-language program that continuously reads the state of the switches and sets the LED displays accordingly. The program will have the following features:
- When push button S1 is pressed, the seven-segment display should be updated to show the binary value entered on the slide switches. The software should detect the transition of S1 from unpressed to pressed. If a transition is detected on S1 while S3 is in the pressed state, the twoâs complement (negative) of the slide switch should be dis- played.
- When push button S2 is pressed, the bar-graph display should be updated to show the binary value entered on the slide switches. The software should detect the transition of S2 from unpressed to pressed. If a transition is detected on S2 while S3 is in the pressed state, the 1âs complement (bitwise inversion) of the slide switch should be dis- played.
- You can assume S1 and S2 are not activated at the same time.
Design Notes and Hints
- Review pages 13-9 through 13-14 of the Motorola PowerPC MPC823 Userâs Manual.
- The connections to the MPC823 data bus, address bus and bus control signals are pro- vided in the base project. A description of each signal or signal set follows:
DATA BUS
DATA TO PROC DATA FROM PROC
ADDR BUS
TS
FPGA
32 BIT READ REG 32 BIT WRITE REG
Control Logic
Switches
LEDs
TA
CLK
RDWR
PPC EXT BUS
- The MPC823 will sample its input signals TA_BAR and on a read the data bus on each rising edge of the clock following TS_BAR. You need to provide a minimum setup time of 10ns and minimum hold time of 2ns with respect to the clock edge. An easy way to do this is to drive the signals from one falling clock edge to the next, pro- viding roughly one-half of a clock cycle of setup and hold each.
- To save on address decoding logic, you should check only the upper six external address lines (A[6:11]ârecall that A[0:5] are not available off the processor chip) to determine whether your registers are being accessed. and one low-order address line (which one?) to determine which of your two registers is being accessed. The remain- ing address bits are donât-cares.
- TA must be asserted for exactly one rising edge of the bus clock.
- The 7 segment display connection takes a 16-bit binary input, converts it to the appro- priate hexadecimal seven-segment on/off patterns, and multiplexes it onto the dual seven-segment display. The CLK is supplied, so you do not have to connect a clock.
In this lab only 2 of the 7 segment displays will be used. The remaining 2 may be set to zero or no illumination.
- You will need to select a device to implement your LED register. Consider a clocked device such as the FD8CE. This is a macro consisting of 8 D flip-flops in parallel and a CE (clock enable) control. The clock enable is used to clock data into the register at the appropriate time.
- As suggested in Lab1, consider using merged nets to make your connections to the processor and devices to promote organization and avoid spaghetti style schematics.
- Create ISE custom symbols to encapsulate portions of your design. Custom symbols improve reliability by allowing you to reuse known functionality and improving the organization and readability of your schematic.
- The Xilinx software requires that all IO be instantiated in the top level design entry. If you wish to observe signals in a symbol that you create, you must port the signals up to the top level schematic and connect them to the test points.
- Multiple net tristate buffers are not provided in the ISE software device list. A 8, 16 and 32 bit custom symbol is provided in the base project for you convenience. These are implemented in Verilog. Take a look at the Verilog by pushing into the symbol.
- When a bit file is loaded to the FPGA, it can cause a disruption with the SingleStep connection to the processor. Always, reload the ELF file or initiate debug without a file in SingleStep after loading a bit file to be sure the connection is established
Individual Pre-lab Assignment
Note : Pre-lab assignments are divided into individual and group assignments. Individual assignments are to be completed alone with the collaboration policy in mind and the honor code signed and included with the assignment. Group assignments generally consist of an initial design attempt or some other common lab goal and are to be completed with the members of your group. Be sure all group members names are included.
- Write an instruction or instruction sequence that will perform each of the following single-bit operations on the value in register r4. All other bits in r4 should remain unchanged. See the appendix for suggestions on bit manipulation. ( 7 points, 1 point each )
a. Set bit 29.
b. Set bit 18.
c. Set bit 4.
d. Toggle (complement) bit 15.
e. Toggle bit 6.
f. Clear bit 21.
g. Set the bit indicated by the value in r6. Assume that r6 holds a value between 0 and 31.
- Give an instruction sequence that will execute the lwz in the code fragment below if and only if bit 21 of r4 is 1. ( 4 points ) (your code goes here) lwz r5, 0(r6) skipload: (more code)
- Why is the LED register at 0x02900004 and not 0x02900001? ( 4 points )
- Besides the address you designed your registers to be accessed from, how many other word-aligned addresses (shadow locations) will they respond to? See appendix A. What are these addresses? You can specify a range. Remember, the MPC external bus consists of address lines A6 â A31, so you can assume A0 â A5 are zero. ( 4 points )
Group Pre-lab Assignment
- You will need an address decoder to uniquely identify the bus transactions that will read and write the switches and LEDs respectively. Design both a schematic version and Verilog version of the address decoder. Submit a copy of both. ( 3 points )
- Using the SingleStep Simulator, write the software for this lab. Working hardware is not required to develop and debug the software. Since the switches and leds are treated as memory mapped locations, you can simulate input by writing memory locations with the SingleStep command lines or memory editor. For example, to set SW0 simply set bit 24 to 1 in a memory location associated with the 32 bit switch register. To observe the results, simple observe the memory location associated with the leds. ( 8 points ). NOTE: The SingleStep Simulator and SingleStep On a Chip are different programs with different applications. The SingleStep Simulator runs exclusively on a PC. The address space (memory) is strictly on the PC. It can be used to debug your code inde- pendently of MPC823 Kit hardware. The SingleStep Simulator is available in the demo pack on the course web page and is listed on under Programs-->SingleStep in the lab. SingleStep On a Chip program is used to debug software on the MPC Kit. Software is loaded to the Kit at initialization (ELF file). SingleStep executes the software on the kit either line by line (source line debugging) or by running or set- ting breakpoints. If you are using memory mapped IO like the switches or Leds, you will have to have working hardware loaded into the kit if the software is expected to run successfully. SingleStep will report a âMachine Checkâ error if your hardware
another transaction changes the state of the bus. Consequently, when the data bus is observed with just one transaction, the data hold time appears to be artificially long. Since PDOUTEN defines the time that the data bus is guaranteed to be driven, measuring the hold time with respect to this signal should give a good indication of the hold time. Demonstration 1.1: Show your captured read transaction to the lab instructor and indicate that you can measure the TA and the data setup and hold times.
Capture a write transaction to your output register on the logic analyzer. What are the TA and data setup and hold times relative to the clock edge? As previously stated, the data bus is constructed such that values on the bus are held until another transaction changes the state of the bus. Consequently, the data hold time may appear to by artificially long. During a write cycle, the data bus is not driven after TA is recognized by the processor. According to the timing specifications, the data is guaranteed to be on the data bus a minimum of 5ns after the rising clock during TA. Measure and ver- ify that this minimum occurs. Demonstration 1.2: Show your captured write transaction to the lab instructor and indi- cate that you can measure the TA and the data setup and hold times. Step 3. Experiment with access size Access your I/O registers using byte rather than word operations. You can do this from the SingleStep command line by using â-bâ instead of â-lâ (i.e., âread ârbxâ and âwrite âbâ). Record what happens for the post-lab.
Part II: Debugging your software
Thoroughly test your program using the SingleStep simulator. The simulator will assume that 0x02900000 and 0x02900004 are regular memory locations. You can emulate the effects of changing the switches by changing the contents of location 0x02900000 in the memory window. You can observe changes to LEDS by checking the values written to location 0x02900004.
Part III: Integration
Once your hardware and software appear to work in isolation, download your program to the processor and trace through it using the debugger. Once you are satisfied that your pro- gram works, click the green âgoâ icon and let your program run. Adjust the switches on the target board to test your system. Demonstration 2.1: Demonstrate your system for the lab instructor.
Post-Lab
- List the steps to design and verify the hardware interface between the processor and the device. ( 4 points )
- Submit timing diagrams in the appendix with our final timing design. ( 3 points )
- On the timing diagrams in question 2, show the Data and TA setup and hold times your design is providing. Write the values you measured in Part I. Did you make the minimum Data and TA setup and hold requirements (10ns and 2ns respectively). ( 4 points )
- Provide a high level (C like) description of your software. List one method you used to debug your software independently of the hardware. ( 4 points )
- In Lab 1, the contents of the slide switches are displayed directly on the BAR LEDs. In this Lab, we used generalized hardware and software to essentially perform the
same function. What are the advantages and disadvantages of using a microproces- sor instead of hard-wired control logic? ( 3 points )
- Try to read your LED register. You should discover that you cannot. Why not? Your answer should include data path and bus transaction issues.( 2 points )
- Sketch the logic required to make it do so. ( 2 points )
- How does your input register handle byte reads? Describe what happened when you attempted to use byte reads in Part I. What address would you use to have a byte read return the settings of the eight slide switches? ( 4 points )
- How does your output register handle byte writes? Describe what happened when you attempted to use byte writes in Part I. What address would you use to have a sin- gle byte write set the bar-graph display value without affecting the seven-segment display? Sketch the additional logic needed to make this work. ( 4 points )
Appendix A, Shadow Locations
When implementing address decoders for memory mapped I/O, it is common practice to decode just a subset of the address bus. It is not necessary to uniquely decode every address combination if there are not conflicts with other memory mapped I/O. The exter- nal address bus of the MPC823 consists of address signals A6 - A31 or there are 2^26 pos- sible byte addressable locations. It is not likely that this many I/O locations are needed. So, the address space is partitioned into ranges. A map of these address ranges is often called a memory map. It will show over what ranges I/O devices are decoded. Consider a simple example. Assume that you are working with an address bus consisting of 16 lines, A15 - A0. Also assume the first half of the space 0x0000 to 0x7FFF is for sys- tem memory and the last half from 0x8000 to 0xFFFF is for memory mapped IO. Lets say we need to address 2 word addressable devices. Furthermore, lets say we want to we want to address the two devices with a minimum number of address lines. The IO address space could be divided into the range 0x8000 to 0xBFFF and 0xC000 to 0xFFFF. To achieve minimal decoding, device 1 can be assigned to the first range and device 2 to the second range. Only address lines A15 and A14 need be decoded. A15 distinguishes the devices from the memory address space and A14 distinguishes device 1 from 2.
Device 1 responds to addresses 0x8000 to 0xBFFF and device 2 responds to addresses 0xC000 to 0xFFFF. The first address of the address range that the device responds to is itâs designated address. For device 1, this is 0x8000 and for device 2, it is 0xC000. The remaining addresses are called shadow locations.
The total number of byte locations in the first device address range is (0xBFFF - 0x8000)
- 1 = 0x4000 = 16,384 = 2^14. The total number of word addressable locations is 16,384/4= 4,096 = 2^12. So the total number of word addressable shadow locations are 2^12 - 1. The word addressable range of the first device responds to is 0x8000 to 0xBFFC. The word addressable shadow range is from 0x8004 to 0xBFFC. The address space for the second device is from 0xC000 to 0xFFFF. The total number bytes, word addressable locations and shadow locations is the same as for device 2. The word addessable range is from 0xC000 - 0xFFFC. The word addessable shadow range if from 0xC004 to 0xFFFC.
Table 1:
A15 A14 A7 A6 A5 A4 A3 A2 A1 A0 Device
1 0 0 0 0 0 0 0 0 0 1 lower bound
1 0 1 1 1 1 1 1 0 0 1 upper bound
1 1 0 0 0 0 0 0 0 0 2 lower bound
1 1 1 1 1 1 1 1 0 0 2 upper bound
Appendix B, Bit Manipulation
Setting, clearing and toggling specific bits is a common task when working at a register level with simple hardware. These functions can be accomplished with the AND, OR and XOR logic functions and the appropriate mask constant. For example, to set the bit 29 in the r4 register without effecting any of the other bits: ori r4, r4, 0x Your code will âself documentâ if you define the mask with a constant. The assembler directive .equ can be used as follows: .equ b29, 0x then
ori r4, r4, b Anyone who knows a bit about assembly can read this line and realize the author likely intends to set b29. Of course, you need to realize the Endian reference for you system.
There are many other assemble directives available for manipulating constants: +, <<, >>, ~, |, &. The << shift operator can be utilized to create a single bit mask as follows. Consider the expression: 1<<2. In this example the bit one is shifted left 2 places while all other bit places are filled with zeros producing the mask 0x0000 0004. Remember, in the PPC con- vention bit 0 is the MSB and bit 31is the LSB with bits numbered left to right bit0...............bit31. To further clarify, consider the following assembled code segment from a listing file. The code sets bit 29 in the general purpose register r4. The far left 8 digits represent the mem-
ory location. The next 8 digits represent the assembled machine code for the instruction. Notice the general form: 1<<(31-bit position) is used to specify the mask where âbit positionâ follows the bit ordering convention bit 0............ bit 31. Also, notice that the bit pattern 0x0000 is produced from (1<<(31-29)@h and is repre- sented by the last 4 digits of location 30. Likewise, notice that the bit pattern 0x0004 is produced from (1<<(31-29))@l and is represented by the last 4 digits of location 34. Notice that .equ b29, (1 << (31-29)) is equivalent to .equ b29, 0x You should use one or the other form when coding.
29
Appendix D, Write Timing
BUS CLK
TS*
Address Bus
Data Bus
TA*
PD_OUT_EN
100ns period
Led_Latch_CE