Operating Systems for Embedded Computing (2007) - lab3

Operating Systems for Embedded Computing

Lab Assignment 3 - Minimal NXT real-time operating system

Within this lab assignment you have to design and implement a minimal operating system for the Lego NXT platform. You should implemented a minimal real-time operating system with the following features:

  • threads (minimal dispatchter + API)
  • miminal memory management (at least static stack memory management for threads)
  • a static priority-based, FIFO scheduler
  • a sleep function, which suspends the current thread for a specified amount of milli-seconds


Your operating system must at least support the following functions:

  • void create_thread(void* entry_point, int stack_size, unsigned char priority, int* thread_id)
    • creates a new thread 
    • starting with a call to entry_point
    • with a stack as spezified by stack_size (you are allowed to demand a fixed stack size - always 512 Byte ...)
    • the thread with the highest priority runs
    • returns an id for the thread
  • int get_thread_id()
    • returns the ID of the thread (just for printing / debugging)
  • void terminate_thread()
    • can only be called by a thread to terminate itself (destroy the thread control block)
  • void sleep(int ms)
    • Thread is suspended for the specified amount of milliseconds
  • int tick_count()
    • returns the number of milli-seconds since the start of the system

Estimate for all functions of your operating system the worst case execution times. Is your operating system predictable? Also specify the time required for a context switch.

Think of an example to demonstrate your operating system. Your demo application should have at least two parallel activities (such as playing nibbles and enabling a light bulb if an external button is pressed. You can also play nibbles and beep with a fixed frequency). For your demo application, please indicate the utilization of the threads. Also specify deadlines, periods and execution times of the parallel activities.

As a starting point you can use an adapted version of the Lego NXT firmware (lab3.tar.gz). This start-kit already contains the configuration of the timer interrupt, which is nesseccary to implement pre-emptive scheduling. Be aware, that in contrast to Lab 2 the implementation of the central interrupt handler/dispatcher (IRQ_Handler_Entry) in common/Cstartup.S has been rewritten, allowing for a better implementation of context switches.

Present the highlights of your nibbles game imlementation and your minimal operating system + your demo application in a short presentation of about 20 minutes in the last lecture of this course.

You may also use the version of the dispatcher presented in the lecture as a starting point. Please try to implement the context switch for youself at first! ( * )

created by Andreas Rasche