Thursday, February 25, 2016

OSA rtos - First try

Task scheduler has been a very convenient way to manage the task flow without having multiple flags  raised at certain time interval. By optimising the timer interrupt on MCU, one can control the task at almost precise timing but as the tasks get complicated and larger, the readability and maintenance effort also significantly increased.

RTOS - real time operating system is the answer to all these hardships. 
Many people are doubt on using rtos on small mcu as the ram consumption is significantly higher and reliability/support of open source rtos has shunt most novice away.

OSA rtos is chosen for this study because it is using the cooperative scheduling and the next running task is chosen based on priority after the task before run to completion. So the ram consumption for each task is fixed and small.

I will be using PIC18f4553 and mplab c18, so the ram is 4 bytes per task which is small. Also, by enable a full rtos function - only 1214 bytes of rom and 16 bytes of ram are needed. It is small scale enough to implement an adequate system on PIC18f.

OSA rtos has stop it's development but it is still worth trying for hobby project. The OSA seem to be very popular among Russian developers and the tutorials are much complete in Russian language compared with English.

After spending much time on reading and trying to implement the OSA rtos on pic18f4553, I make some progress. I was able to make two leds blinking at different rates. It is simple but I will employ different rtos functions later.

At the introduction part, there are certain limitation on compiler that need cautions such as:
For MICROCHIP C18
-You can't use procedural abstraction optimization
-You can't use Stack Model: Multi-bank

It is not a big deal as you are not enjoying these benefits when using the free version of c18.

One thing that shunt people away is the step to step guide to implement the OSA on pic18f and very few tutorials or examples which are using c18 compiler.

So in this tutorial, I will show a step by step guide to compile in c18.
note: I am using pic18f4553, c18 version 3.47 and mplab v8.92.
1. First step is download the OSA. There are several implementation examples in this link.
2. Secondly, create a mplab project folder and copy the whole OSA folder inside the mplab project folder.

3. Add the necessary header file of OSA. 
Only osa.c is suffice but I add in osa.h for ease of troubleshooting. OSAcfg,h is the settings file which can be referred at this document. Although there is a GUI software to choose the OSA settings but it doesn't work on win 7 (or just maybe my computer).

4. Right right at the project name "osa.mcp" and choose Build Options. At the Directories, click on the "include search path" and add in the osa folder in the search path.  

5. Now, go to MPLAB C18 and type in "disable procedural abstraction optimization" -Opa- . 
If "-Opa-" instruction is at the settings there, then just maintain it as it is. (dont change anything).

6. Choose the single bank model at MPLAB C18 -> Memory Model -> Stack Model as shown below

7. To configure the OSAcfg.h, I will be blinking two leds, so OS_TASKS = 2; simple blinking cant show the task priority so OS_DISABLE_PRIORITY. The OS_ENABLE_TTIMERS and OS_ENABLE_TIMER are defined to enable OS_delay function.

8. My blinking task, led1 with 1 second blinking rate; led2 with 2 second blinking rate.

9. The OS tick increase every 10 ms. The timer interrupt setting is as follow (You can refer to my blog on setting the timer interrupt)
10. The main routine is as follow:
Actually, I havent study the OS_EI() function, I suspect that I can skip some redundant code.

11. You can check the task address using the debugger mode. You can check whether the task is switching or not.

Basically that all, this is the simple implementation.
The whole project zip file can be downloaded at here.



No comments:

Post a Comment