As promised, I am back to continue my series of posts on working on a FreeRTOS port for the AEMB core. Yet before I go in any further, let me give a short introduction about FreeRTOS and walk you through my overall plan for getting my project done before I finish my internship at AESTE.

FreeRTOS Intro

FreeRTOS is a small real-time kernel that supports two mode of operations; Cooperative and Preemptive multitasking. The kernel itself is three or four files (one optional file). It is mostly written in C with some in-line assembly functions. FreeRTOS provides 27 ports for different processor architectures and different compilers.

Project Plan

I have divided my project into six phases:

  1. Compiling and Linking FreeRTOS for the AEMB
  2. Simulating the port using Icarus Verilog and GTKWave
  3. Running a simple FreeRTOS task
  4. Demonstrate the Cooperative Multitasking between tasks
  5. Implement timer interrupt and interrupt handling
  6. Demonstrate the Preemptive Multitasking between tasks

Now the first phase of the project is to compile and link FreeRTOS for our hardware. In order to do that , the following questions had to be answered:

  • What C files and libraries are to be included in the compile of the kernel?
  • Which port of the 27 existing ports to choose?
  • What Compiler to use?
  • How to manage the project directory? Should i keep the original FreeRTOS directory or change it?

The answers to these questions were essential to get me stated. FreeRTOS includes some simulations that I decided to run so I could have an idea on how to answer the first question. Along with that, provides a documentation for almost every part of the implementation of the kernel and the demo applications. After reading some of the documentation, I managed to run both Window and Linux FreeRTOS simulations using Eclipse IDE and so I had an overview on how my kernel should look like at the end of the road.

This is a screen-shot for the simulation on the company PC that runs Ubuntu LTS.

Because it is more difficult to start a port from a scratch, a suitable existing port had to be chosen to base the work on. Therefore, the Microblaze FreeRTOS port was chosen for the following reasons:

  • It uses GCC Compiler (what i intend to use)
  • Has a lot of similarities e.g. the number of registers and stack growth.

Although there are major architectural differences between the two processors, such as the number of threads, that can be treated by replacing some hooks for AEMB.

Different processor architectures have different sets of instructions. By that I mean that we can only compile and link source code for an architecture that is different than the one used by the machine compiling the code yet we can not run it. For example in my case, I used a PC, which if i just simply use gcc -o < file.c . . . > to compile a code, then link it using gcc < file.o . . . > the compiler will generate executable file “a.out” that can only run on machines with a similar processor architecture.

Consequently, to compile the code so it can be used for our hardware simulation a cross compiler is used to generate the instruction set that AEMB requires. The following is the details of the compiler in use:

  • Compiler name: mb-gcc or mb-g++
  • Target: microblaze-xilinx-elf
  • Thread model: single
  • gcc version 4.1.1

It was been decided to maintain the original FreeRTOS directory. The reason for doing that is as soon as the AEMB FreeRTOS port is up and running it will be a contribution to the FreeRTOS family and so it should fit the original directory managed by FreeRTOS.

In fact, compiling and linking a project that has several source code files residing within different subdirectories is a difficult task without using a means to manage it. Thus, here is when a Makefile comes in handy. If you don’t know how to use Makefile and you have the curiosity to learn how to create one, do check this link out. At this point, my build environment is set and it is time for checking FreeRTOS functions and libraries

Problem Faced While Compiling

Considering my limited knowledge in C programming, I expected a lot of problems in handling the compile of the kernel. The first problem that I faced was an error of undefined functions caused by missing hardware library headers which are used by the original Microblaze port to simulate the kernel on a Virtex-4FPGA. So to solve this problem i created some fake functions that do nothing but just to get rid of the error first and build the kernel. At the end, the kernel was successfully compiled and linked so it was the time to replace some libraries with AEMB ones, in other words compiling FreeRTOS against AEMB libraries. Finally the compilation and the linking was done and everything was set for the next phase which is the simulation.

Till I write again, I wish the best of luck 😉


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.