Close

Programming - Multitasking Decision

A project log for MyComm

A portable, solar powered, handheld device that provides truly global messaging when you have no alternative.

jack-wellsJack Wells 06/07/2016 at 13:350 Comments

Initial Discussion

Multitasking is obviously vital to pc day to day use. Programs, or tasks, appear to run simultaneously to the user which allows them to run multiple programs even with cross-interactions between them seamlessly. From the processors point of view it's a little bit more complicated. The appearance to the user is that all tasks are running at the same time but this actually untrue in a "single core" environment. This task handling is done by the "OS". The OS keeps track of the running tasks and decides what task gets run at any given moment then switches to the next priority task. Obviously Windows won't run on such a small processor as an Arduino micro-controller but there are real time operating systems available that create the same "task handling" environment which allows for easy multitasking. This is important to our application because the MyComm will need to handle multiple tasks at the same time. There is the screen and gui to handle but also the Iridium modem. The iridium modem communicates over a standard serial port which will need managed. New incoming messages may appear and we can't have the gui shut down while we handle this incomming message. The handling of the Iridium can be thought of as a "background task"; One that the user is essentially unaware off but still a vital component for the MyComm to work. The diagram below highlights the idea behind multitasking:

Free RTOS

Taking advantage of the Arduino echo-system and vast support for the Teensy 3.x meant that finding a free open source real time operating system (RTOS) was a quick google away. FreeRTOS has been ported for Arduino - here - by a user known as Bill Greiman. I found his post through the Teensy forum - here - so I know the Teensy is supported. There is a wealth of information available on Free RTOS and a few good blog posts around too. Getting the library to play ball with my IDE was a bit difficult at first. I eventually went into the specified RTOS Arm folder, ripped out the .c and .h files and bundled everything together into a folder setup that would play nice with Arduino + Atmel Studio + Visual Micro. It was a bit frustrating but I was able to get an example file running after a couple of hours.

The Free RTOS works like a standard Arduino library so I can still use the general core Arduino libraries and functions. It allows the user to define tasks and the Free RTOS library handles the switching between tasks and general mangement. Care has to be taken with memory usage so I'll need to keep an eye on this.

The Plan

I've branched off my git code for now and I have a basic test setup running Free RTOS. My plan is to now port over the current GUI code and have it running fluidly inside a single task. At the same time I'll have a second "debug" task running that prints out details such as memory usage and to ensure the gui task isn't hogging all of the reasources. There's a good basic example in Bill Greiman's port library that blinks an led in one task and prints out debug data in another so I'm using this as the starting point for my code.

JW

Discussions