Starting from:

$35

CMPT433-Assignment 5: Bare Metal LED Flasher Solved

Create a bare metal application named lightBouncer.bin to run on the BeagleBone with a Zen cape which provides the following functionality:

1.1    Start-up

On the serial port at start-up:

Print a welcome message with your name.
Print the reset sources (and clear this register) (see page ~1336 in TRM).The reset source register indicates all sources of resets since the register was cleared; print out a comma separated list of all the indicated reset sources.
The reset source register is located at base address 0x44E00F00.
Bits labeled “R/W1toClr-0h” mean that if you write a 1 to the bit it will clear it. You’ll need to do this after you have read the current reset source(s) in order to clean it up for the next reboot.
Do not use any StarterWare methods to access this register (if you find any), other than the HWREG() You'll likely have to define your own base and offset constants because they are not in StarterWare header files.
Hint:
Test with each of: cold boot (unplugging power), external reset (press the reset button beside the LEDs), and watchdog reboot.
Print the help information about accepted serial commands.
1.2    10ms Timer
Configure a timer for repeated 10ms interrupts.
This interrupt will be used for multiple parts of the application.
1.3    Watchdog
Configure the watchdog to reset the board after 5s.
In the background task, hit the watchdog every 10ms.
Hint: Have the timer ISR set a flag, which is checked in the main loop. Have the flag indicate that 10ms have elapsed, and hence will be time to hit the watchdog.
A serial port command can disable hitting the watchdog; more below.
1.4    Serial
Use interrupts for the serial port to read a single character when a key is typed.Use the StarterWare UARTCharGetNonBlocking() function to read the character.
Do not require the user to hit ENTER.
Hint: You should only call IntAINTCInit() once in your entire program (it resets the ARM Interrupt Controller).
This function will remove any currently configured interrupts, and is called in the sample code for both the serial port Rx and the timer (both using interrupts).
Comment-out/delete the call from the second interrupt that you setup. For example, if your main() first initializes the timer and then the serial port, have the serial port not call IntAINTCInit().
In the background task, process the key typed which was read in the ISR.You may assume that the application will have completed processing the first keystroke before a second one is entered by the user (i.e, you don't need a queue to read in key presses for processing: the CPU is fast, the serial port is slow).
Hint: Use a variable to store the key pressed in the ISR which is to be processed in the background task.
Hint: Have your background process repeatedly call a function in your serial prompt module to check if there is any work to be done.
Accepted commands (must be case insensitive):
 ?   : Display this help message.

 0-9 : Set speed 0 (slow) to 9 (fast).  a   : Select pattern A (bounce).  b   : Select pattern B (bar).  x   : Stop hitting the watchdog.

When the user enters a command to change the speed or flash-pattern, call functions in your LED module (below).
When the user enters 'x', stop hitting the watchdog in the background task (board should reboot due to the watchdog).
If you enter an unknown command, print an error message and show the help list. Hint: In addition to the h/.c module provided on the course web page in the “fake typer” program, also create a new serial prompt module which handles your your applications use of the serial port at a higher level.
1.5    LEDs
Flash the four LEDs on the actual BeagleBone in one of two patterns:Bouncing: Turning on one LED at a time, make the lit LED appear to bounce back and forth. The illumination sequence will be (one time-period each): 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, ….
Bar: Turn on multiple LEDs, as needed, such that a bar of LEDs appears to grow and shrink. For one time-period each, turn on LEDs 0 through N (inclusive), where N = 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, ….
The time-period for each flash is given by the following formula:
      flash time-period = 10ms * (speed divider factor) where    speed divider factor = 2 (9 - speed)

Hints:Have the 10ms timer ISR call a function in your LED code which controls the LEDs.
1.6    Joystick
Pressing and releasing a direction on the joystick has the following effect:

Left: Toggle the flash-mode between bounce (pattern A) and bar (pattern B).
i.e., which ever mode it is currently in, switch to the other mode.

Up (bonus): increments the speed by one (clamped to 9).
Down (bonus): decrements the speed by one (clamped to 0).
Suggestion:

Have the 10ms timer ISR call button call a function to check the state of the joystick.
Note that holding the joystick has no effect; it is only on release that has an effect.
When a joystick action is detected, call into the LED module to change the pattern/speed.
If attempting the bonus:
The board support package for the BeagleBone Black in StarterWare defines the following two function which you may want to call to initialize the GPIO: GPIO0ModuleClkConfig, GPIO1ModuleClkConfig.
Find pin numbers for joystick directions by consulting Zen cape schematic. Find GPIO mapping via “header table” files on course website.
1.7    General Requirements
Must have multiple modules, each presenting a clear interface to the rest of the code through a .h
Suggested modules include:

controlling the LEDs,
reading the joystick,
managing the serial port prompt, and
provided hardware abstraction modules: timer, watchdog, serial.
You may add more modules if it improves the readability of your code.

No global variables with external linkage.
Only the functions exposed through .h files may be non-static (except main()). All other non-exported functions must be static.
You must not have any printf-style statements called from within code that is called
while processing an interrupt (i.e., the ISR must not trigger a printf-style): All printf's must be done in the background task.

Code quality is always important:All functions, variables, constants, and files must be well named.
Use perfect indentation (as always!).
Add a brief comment at the top of each .h file (at least) to explain that module’s purpose.
Suggestion: Try to use the size-specific C types. For example use uint8_t instead of char, and uint32_t instead of unsigned int. (No marks for this, but good to work with; must #include <stdint.h>)e`.
3.   Sample Serial Output
LightBouncer:

  by Brian Fraser -----------------

Reset source (0x1) = Cold reset,

Commands:

 ?   : Display this help message.

 0-9 : Set speed 0 (slow) to 9 (fast).  a   : Select pattern A (bounce).  b   : Select pattern B (bar).  x   : Stop hitting the watchdog.  BTN : Push-button to toggle mode.

?

Commands:

 ?   : Display this help message.

 0-9 : Set speed 0 (slow) to 9 (fast).  a   : Select pattern A (bounce).  b   : Select pattern B (bar).  x   : Stop hitting the watchdog.  BTN : Push-button to toggle mode. z Invalid command.

Commands:

 ?   : Display this help message.

 0-9 : Set speed 0 (slow) to 9 (fast).  a   : Select pattern A (bounce).  b   : Select pattern B (bar).  x   : Stop hitting the watchdog.  BTN : Push-button to toggle mode.

0

Setting LED speed to 0

3

Setting LED speed to 3

b

Changing to bar mode. a

Changing to bounce mode.

a

Changing to bounce mode. x

No longer hitting the watchdog.

 
 

More products