User Tools

Site Tools


old_lab_2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

old_lab_2 [2014/09/01 16:43] (current)
hutch created
Line 1: Line 1:
 +====== Lab 2: Bit Manipulation ======
 +===== Overview =====
 +In this lab you will create a program that performs bit manipulations based off input from the switches and keyboard. Keyboard input shall be sent to the Zedboard using Tera Term. The results shall be output to the LEDs. You will learn how to use general purpose I/O (GPIO) cores to allow your software to interact with the switches and LEDs.
 +===== Objective =====
 +Master bit operations in '​C'​ and get more practice with the software and the ZED board. You will also learn how to use the GPIO module to read switch values and to turn on LEDs.
  
 +===== Specifications =====
 +The Zedboard'​s switches and the LEDs above them will be used. Write a program that performs the following operations when the indicated digit is pressed on the keyboard. The result of the operation should be written to the LEDs:
 +  * 0 - Set the LEDs to the switches’ value.
 +  * 1 - NOT the current LED value.
 +  * 2 - AND the current LED value with the switches’ value.
 +  * 3 - OR the current LED value with the switches’ value.
 +  * 4 - XOR the current LED value with the switches’ value.
 +  * 5 - Shift current LED value left, including wraparound of MSB to LSB.
 +  * 6 - Shift current LED value right, including wraparound of LSB to MSB.
 +  * 7 - Reverse the current LED value as shown in Figure 2.7.6 of PES on Zyante.
 +  * 8 - Separate all the 0s from the 1s with the 1s on the right in the current LED value. For example, 01001010 would become 00000111.
 +
 +For example, when 4 is pressed on the keyboard, XOR the current value of the LEDs with the current value of the switches. Then update the LEDs to display the result of the XOR operation.
 +
 +Print out a default message when any unexpected keys are pressed on the keyboard. After the program performs an operation it should wait for another keyboard press so there should be a loop in your program.
 +===== Notes =====
 +When you create your application project use the existing board support package you created in the first lab. Use the Hello World template to generate your project as you did in Lab 1. It is a good idea to rename the automatically generated helloworld.c file to something more fitting for the current lab and write your code in this file.
 +
 +{{ :​documentationexamples.png?​300|}}
 +GPIO cores are included in the hardware used for ECEn 330. The GPIOs are what you will use to write to the LEDs or read from the switches. You will have to figure out how to use the GPIOs by looking at documentation,​ examples, and code. Links to documentation and examples can be found in system.mss as shown to the right. The BSP has header files that you can include in your code. You can find them in the following subfolder of the BSP -> ps7_cortexa9_0 -> include. xgpio.h and xparameters.h will definitely be helpful to you.
 +
 +Use the inbyte() function to get keyboard input via Tera Term. It is a simple way to take in a single keyboard press at a time. The function waits for a key to be pressed on the keyboard and returns the ASCII value of the key that was pressed.
 +
 +Recommended approach: First write program that reads the switches and writes the value to the LEDs in an infinite loop. Then expand from that...
 +
 +The GetBit() and SetBit() functions from Ch. 2 of PES may help.
 +
 +You may add functionality beyond the specifications such as printing out the controls when the user presses '​h'​ or quitting the program when the user presses '​q'​.
 +
 +===== Skeleton File ======
 +There was a lot of questions about how to approach this lab, so here is a skeleton file that should make things easier. Study it and make sure you understand exactly what it does. As you can see, quite a bit of it was copied from the code I provided for Lab 1. You may use this file as a starting point but make sure you understand what it does.
 +
 +<​code>​
 +#include <​stdio.h>​
 +#include "​platform.h"​
 +#include "​xgpio.h"​
 +XGpio Switches;
 +XGpio LEDs;
 +
 +int main()
 +{
 + init_platform();​
 +
 + int xStatus;
 + u32 switchValue;​
 + unsigned char displayValue;​
 + unsigned char buffer, mask;
 + unsigned int dvIndex;
 + print("​starting up Lab 2.\n\r"​);​
 + // The GPIO code was copied directly from the code I gave you in Lab 1.
 + //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + //Step-1 :AXI GPIO Initialization
 + //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + xStatus = XGpio_Initialize(&​Switches,​XPAR_SWS_8BITS_DEVICE_ID);​
 + if(XST_SUCCESS != xStatus)
 + print("​GPIO INIT FAILED\n\r"​);​
 + xStatus = XGpio_Initialize(&​LEDs,​XPAR_LEDS_8BITS_DEVICE_ID);​
 + if(XST_SUCCESS != xStatus)
 + print("​GPIO INIT FAILED\n\r"​);​
 + //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + //Step-2 :AXI GPIO Set the Direction
 + //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + XGpio_SetDataDirection(&​Switches,​ 1, 0xFF);
 + XGpio_SetDataDirection(&​LEDs,​ 1, 0);
 + print("​all initializations were successful\n\r"​);​
 + while(1) {
 +
 + char keycode = inbyte(); ​ // This function waits until the user hits a key on the keyboard.
 + printf("​received keycode:​%c\n\r",​ keycode);
 + // Now, display the various operations.
 + // This code reads the switches
 + u32 ledValue = switchValue;​
 + switchValue = XGpio_DiscreteRead(&​Switches,​ 1);
 + switch(keycode){
 + case '​0':​
 + displayValue = switchValue;​
 + break;
 + default:
 + break;
 + }
 + // This code writes the switch value to the LEDs.
 + XGpio_DiscreteWrite(&​LEDs,​ 1, displayValue);​
 + }
 + return 0;
 +}
 +
 +</​code>​
 +
 +===== Grading =====
 +
 +When you think you have met all the specifications have the TA check your system. If you have not met all specifications the TA will not pass you off until you have met them all.
 +
 +Turn in well commented code, and answers to the following feedback questions:
 +  * How many hours did this lab take you to complete?
 +  * What were the biggest bugs/​challenges you ran into, and how did you fix them?
 +  * Were there any aspects of the lab specs that were confusing or ambiguous?
old_lab_2.txt · Last modified: 2014/09/01 16:43 by hutch