Table of Contents

  1. Compiling and degubbing code for Tiva
  2. Hardware Abstraction Layer
  3. Debugging, heap, and display
  4. Analog Digital Converter and Timers
  5. Playing Nokia Tunes
  6. Random Number Generator, Rendering Engine, and the Game
  7. A real-time operating system

Timers

Tiva has 12 timer modules that can be configured in various relatively complex ways. However, for the purpose of this game, we don't need anything fancy. We will, therefore, represent a timer as an IO_io device with the IO_set function (generalized from IO_gpio_set) setting and arming it. When it counts to 0, the IO_TICK event will be reported to the event handler.

 1void timer_event(IO_io *io, uint16_t event)
 2{
 3
 4  IO_set(&timer, 500000000); // fire in half second
 5}
 6
 7int main()
 8{
 9  IO_init();
10  IO_timer_init(&timer, 0);
11  timer.event = timer_event;
12  IO_set(&timer, 500000000); // fire in half second
13
14  while(1)
15    IO_wait_for_interrupt();
16}

See TM4C_timer.c and test-07-timer.c.

ADC

Similarly to the timers, the ADC sequencers on Tiva may be set up in fairly sophisticated ways. There are 12 analog pins, two modules with four sequencers each. Again, we don't need anything sophisticated here, so we will just use the first eight pins and assign them to a separate sequencer each. In the blocking mode, IO_get initiates the readout and returns the value. In the non-blocking and asynchronous mode IO_set, requests sampling and IO_get returns it when ready. An IO_DONE event is reported to the event handler if enabled.

 1IO_io slider;
 2IO_io timer;
 3uint64_t sliderR = 0;
 4
 5void timer_event(IO_io *io, uint16_t event)
 6{
 7  IO_set(&slider, 0); // request a sample
 8}
 9
10void slider_event(IO_io *io, uint16_t event)
11{
12  IO_get(&slider, &sliderR);
13  IO_set(&timer, 100000000); // fire in 0.1 sec
14}
15
16int main()
17{
18  IO_init();
19
20  IO_timer_init(&timer, 0);
21  IO_slider_init(&slider, 0, IO_ASYNC);
22
23  timer.event     = timer_event;
24  slider.event    = slider_event;
25
26  IO_event_enable(&slider,    IO_EVENT_DONE);
27
28  IO_set(&slider, 0); // request a sample
29
30  while(1)
31    IO_wait_for_interrupt();
32}

See TM4C_adc.c and test-08-input.c.

The game board

Everything works fine when soldered together as well.

Buttons and the Slider

If you like this kind of content, you can subscribe to my newsletter, follow me on Twitter, or subscribe to my RSS channel.