Thank you guys for your responses.
And I agree getting in to a project and figuring out problems, stumbling along the way and learning is the best way and that's what my process has been till date.
I haven't work on any type of real time system and that will be the next thing that I will like to tackle. Please do share any resources you happen to like.
FreeRTOS has been ported to hundreds of boards. Find a board that is supported and start with that.
FreeRTOS has been in use for many years and the documentation is excellent. Many manufacturers include a ported version in their toolkit. The Cypress PSOC 6 includes FreeRTOS in such a way that you just select an option button, decide on the stack size and the tools configure it for you. All you have to do is add in the task code.
An RTOS lets you partition your code into separate tasks that communicate through structures. The main loop doesn't need to know how the menuing system works, it only needs to become aware of the results. More important than even the "real time" bit, partitioning makes the program easier to understand. A bunch of tasks, doing their own thing,
commuting communicating through structures (semaphores, mailboxes, queues, etc). It let's you focus your efforts on the 'task' at hand while pretty much ignoring everything else. Yes, the pun was intended.
I really like the way Cypress integrated FreeRTOS and you really owe it to yourself to play with a PSOC 4 or PSOC 6 (especially the PSOC 6 BLE Pioneer Kit). Watch the video series and follow along!
http://www.cypress.com/training/psoc-101-video-tutorial-series-how-use-arm-cortex-m4-based-psoc-6Yes, the board costs more than many but education has never been free.
What about the 'superloop'? Every embedded program has one:
while(1) {
// do everything
}
Inside the loop there will usually be some kind of FSM which is nothing more than a C 'switch' statement (on steroids).
int WinMain(void) { // ignore the WinMain vs main thing, it's a compiler issue...
// setup code goes here
int condition = 1;
int state = 1;
while (1) { // the superloop
switch (state) { // the FSM
case 1 : // do something in this first state
state = 2; // we're done with state 1
case 2 : // do something in this second state
if (condition) {
state = 1;
}
else {
state = 2; // loop here again
}
}
}
}
Clearly, a real project will be a lot more complex but, as a structure for a program, this works well in many cases. As mentioned above, an array of function pointers also works well. Sometimes the function calls are just coded into the switch() statement. It depends entirely on the complexity of the function code whether to use an array of pointers to functions or just a simple switch statement.
By all means, start with the video series above. It's quite a leap to go from Arduino to a project with FreeRTOS. I recommended the PSOC 6 board but I would go along with any ARM board that already has a port.