Amit Levy
Published © MIT

Building Your First Tock App

In this project we will compile the Tock kernel and a simple blink app, and install both onto the Hail development board.

BeginnerProtip1 hour965
Building Your First Tock App

Things used in this project

Hardware components

Hail
×1

Software apps and online services

Tock

Story

Read more

Schematics

Hail

Code

Simple Blink App

C/C++
Toggles a single LED on the board every 250ms.
#include <led.h>
#include <timer.h>

int main(void) {
  for (;;) {
    led_toggle(0);
    delay_ms(250);
  }
}

Fancy Blink App

C/C++
Toggles each LED on the board in a binary count pattern. The Hail has three LEDs, a red, green and blue one, in the same location, so this app will result in a changing color.
#include <led.h>
#include <timer.h>

int main(void) {
  // Ask the kernel how many LEDs
  // are on this board.
  int num_leds = led_count();

  // Blink the LEDs in a binary count
  // pattern and scale to the number
  // of LEDs on the board.
  for (int count = 0; ; count++) {
    for (int i = 0; i < num_leds; i++) {
      if (count & (1 << i)) {
        led_on(i);
      } else {
        led_off(i);
      }
    }
    delay_ms(250);
  }
}

Tock Embedded Operating System

Credits

Amit Levy

Amit Levy

0 projects • 0 followers
Thanks to Tock Team.

Comments