Wednesday, January 29, 2014

Starting to build my own operating system

I was missing something obvious. If my groovebox was going to be built around a microcontroller, I would need to design and program my own RTOS for it (Real-Time Operating System).

It's responsibilities would include things like reading button presses on the user interface of the groovebox, controlling which LEDs are on and which are off, handling the MIDI communication, running the sequencer and synthesis routines, etc.

A quick browsing through the Amazon bookstore revealed quite a few books covering the basics of ARM microcontroller programming. I ended up buying couple of books covering the hardware side of the microcontroller and one book covering the assembly language used for the low level programming. Now I was ready to dive into the wonderful world of figuring out how to make my very own RTOS.

The first thing on my feature wish list was multitasking. A little bit of head scratching was needed to get it up and running. Fortunately ARM based micro controllers have been designed with multitasking in mind. They automatically take care of some of the time consuming things, such as pushing the most used registers on stack, when interrupt/exception happens.

I've uploaded my first small and simple multithread test on GitHub. You can check it out HERE if you're interested in doing some multitasking on ARM based microcontrollers. The test program uses SysTick timer to switch back and forth between two threads.

Once I was confident that I understood what was needed to get multitasking working, I modified and expanded the code. This time I used STM32F373 microcontroller specific timer to trigger the thread switching in the RTOS. This same timer also triggered the DAC and starts a "critical thread" simultaneously. This thread would be used to calculate the next sample for the DAC and what ever parameters would be needed to control the analog audio generation circuitry later in the development.

I also added support for multiple threads and Yield() command to switch to the next thread whenever needed. This was the base code for my RTOS which I would be expanding, modifying and refactoring throughout the rest of the project.


No comments:

Post a Comment