Table of Contents
Overview
In this lab you will write a driver for the GPIO (general purpose input/output) hardware. GPIO hardware allows the processor to interact with the input and output pins on the chip. For this lab, the pins we are interested in are those connected to the slide switches and push buttons. Once you have written your driver, you will be able to easily read button and switch values, and you will build a small test application to verify that your driver is working correct.
Objectives
- Learn about how software interfaces with hardware devices.
- Gain experience writing driver code that interacts with hardware registers.
- Gain experience reading and understanding commercial documentation.
- Write test code that demonstrates the correctness of your driver.
- Practice applying the class coding standard.
Preliminary
-
Read about the Programming Stack.
-
When using programmable processors such as microprocessors, etc., we access low-level hardware via registers. See the GPIO and Registers page to understand how you will access the GPIO hardware.
- Terminology. Learn about some new terminology (reviewed in class):
- memory map
- address bus
- data bus
- IP
- Register
-
Review header files. The buttons.h and switches.h files which are provided in your repository. These header files define the interface to your driver.
-
Including header files. Review the page about header files.
- Compiling. In this lab you will first write driver code, and then write a test application.
- Read the page about CMake files.
-
The driver code will be re-used in later labs, so it will be compiled into a library that can be used by multiple applications. This library, called buttons_switches, will be located in the drivers directory. You are already given a CMakeLists.txt file in this directory that will compile your buttons.c and switches.c code into the ‘‘buttons_switches’’ library.
-
The application code will be a simple test program to ensure your drivers are working correctly. The test application will be placed in your lab2 directory, where you have already been provided a CMakeLists.txt that will compile the Lab 2 executable. You will see that it is almost the same as Lab 1 file, except that line 2 also includes the buttons_switches library.
- The only changes you need to make for this lab is to instruct the top-level CMakeLists.txt file to enter both of these directories and process those CMakeLists.txt files. Add
add_subdirectory(lab2_gpio)
andadd_subdirectory(drivers)
statements to the top-level CMakeLists.txt, after theadd_subdirectory(lab1_helloworld)
statement.
Implementation
Requirements
-
Switches driver. Write a driver for the slide switches. This driver will be located in drivers/switches.c (you will need to create this file) and will implement the functions in switches.h.
-
Buttons driver. Write a driver for the push buttons. This driver will be located in drivers/buttons.c (you will need to create this file) and will implement the functions in buttons.h.
-
Test applications. Create test functions for your two drivers. The provided main.c calls the
gpioTest_buttons()
andgpioTest_switches()
functions. Write both of these functions in lab2_gpio/gpioTest.c (you will need to create this file).- Switches test:
- The switch test program is shown in a video above. It turns on LEDs corresponding to the switches that are in the UP position.
- The test will end once all four switches are UP.
- Buttons test:
- The button test program is also shown in a video above. It will draw colored squares to the LCD dependent on which button is pressed.
- The test will end when all four buttons are pressed simultaneously. (On the emulator, you can press multiple buttons at once using the SHIFT key.)
- You must only draw the rectangle once for each button press and erase it once for each button release. It is okay if there is some button bouncing but continuously drawing or erasing rectangle in a loop is not allowed.
- Switches test:
Files
- Place your driver code in buttons.c and switches.c, located in the drivers directory.
- Place your test application code in gpioTest.c in the lab2_gpio directory.
- Do not modify main.c and do not modify any header files. You can write additional helper functions beyond those defined in the .h file, but the helper functions should be declared and defined in your .c files (remember to declare them static).
Other Notes
- Remember to follow the coding standard.
- You are provided a driver to control the LEDs. See leds.h. Include this header using
#include "leds.h"
. - You should write helper functions for accessing device registers. For example, buttons.c and switches.c could both contain:
static uint32_t readRegister(uint32_t offset); static void writeRegister(uint32_t offset, uint32_t value);
Submission
For each lab, you will follow the instructions on submitting source code to submit your code.
Grade Breakdown
- 80% Functionality. If your code works well and shows no bugs, you should get the full amount.
- 20% Code quality and adherence to the coding standard. You are allowed 10 freebies for this lab.