Hasso-Plattner-Institut Potsdam Operating Systems and Middleware Group at HPI University of Potsdam, Germany
Operating Systems and Middleware Group at HPI

Operating Systems for Embedded Computing

Lab Assignment 2 - The Nibbles Contest

Nibbles NXT

Within this lab assignment you have to develop a limited version of the famous Snake/Nibbles game for the Lego NXT hardware. The idea of this lab are due to Simon Kågström from BTH (Simons original lab). The primary learning objective of this lab is to get in touch with an embedded developer board and the usage of the basic tool-chain for embedded software  including cross-compilers and boot monitors. The Lego NXT contains a 32-Bit ARM7 RISC-processor produced by Atmel and in addition an ATMEL AVR 8-Bit microcontroller for handling I/O. The availability of many peripherials makes the Lego NXT an ideal candidate for experiencing an embedded system.

The learning objectives of this lab are:
  • architecture and programming of RISC processors (ARM)
  • understanding of the development process for embedded devices
  • tool-chain for ARM (cross compilation, linking, boot assistant/loader)
  • low level assembler programming for RISC-architectures
  • driver development / heardware-near programming
  • code size optimization
The primary task of this lab is to create a version of the Nibbles game with minimal code size. You can use direct assembly programming for optimizing the code size. The Nibbles game must fullfill the following specification:
  • The game must be playable
    • The game area must have at least 16x16 pixel.
    • All 4 buttons must be used.
    • When eating an apple the snake's lengths must increase.
    • The initial lenghts of the snake must be one.
    • The snake and the apples should be visualized as pixels (one apple one pixel). Please use the SuperPixel-functions for bigger pixels.
    • The initial number of apples must be configurable (by implementing the function start_game(int apples)). The number of apples is always greater or equal than one.
    • The configured number of apples must be visable all time (except at the point in time when the snake eats an apple and when the snake is longer than the maximum number of pixels on the play field minus the number of configured apples).
    • The snake should start in the center of the game area.
    • When the snake hits itself the function start_game must return.
    • At the end of the playing field, the snake should "rotate" to the other end
  • The game should be implemented in ARM-Assembler (Thumb- or ARM-Mode).
  • The Assembler-Source must be commented. You are allowed to start from a C-Version of the game.
  • The game should be translated with the arm-elf-gcc cross-compiler.
  • The team with the smallest code size (.text segments and .data segments of all functions - main, start_game plus your own functions - use: "arm-elf-objdump - h sam7s256.o" for determining your code size)
  • You are allowed to use all functions already provided in the start-kit. 

Getting Started

At first you have to set-up a build-environment for the ARM-processor. You need the arm-elf-gcc on your development computer and the libnxt-utils for downloading program images onto the NXT main unit. Libnxt supports 2 modes. One for burning the program image into the internal flash memory and one for direct transfer and execution from RAM. The two modes can be configured in the makefile of the start-kit. There is a good tutorial for setting up a NXT /ARM build environment on Windows/Cygwin and MacOS-X available here and another tutorial for Linux here (works also for Cygwin). The tutorial is part of the NXTMOTE-Project.The start-kit contains a few files from the original Lego firmware and a few ATMEL-specific low-level functions. After the installation of the build environment you can compile a small demo program by entering "make" in the directory of the extracted start-kit. You must connect the Lego NXT main unit via USB and can then download the program image (m_sched.bin) by entering "fwexec m_sched.bin". In order to be able to download the program you must start the NXT main unit in reset mode by pushing the small button at the back (close to the USB-port). The main program of the demo program should be used as the starting point for the nibbles game. You have to edit the file program.c. The start-kit gives already a simple frame for handling the buttons and for drawing on the screen.

Useful ATMEL Documentation:

You should start implementing a version of the game on your desktop computer. For Windows you can use Bernhard Rabe's Win32-SnakeRuntime. Torsten Becker ported Bernhard's runtime to ncurses. You can find it here.
Have fun with this lab and may the smallest nibbler win!

Martin & Wolfgang 0xDC
Arne & Christoph 0xDC
Frederik & Torsten & Lars 0xE1
Stefan & Jan-Arne 0xE4
Andreas R. 0x11C
Frank & Christoph 0x134
Frank & Robert 0x15A
Fabian & Andreas 0x1FE
Ville & Antoine 0x2B6

created by Andreas Rasche