Managing resources... or how to program for ChibiOS?
Posted: Sun Jan 13, 2013 11:20 pm
I am using ChibiOS for a while now, it's really an amazing piece of software, seriously 
But i always wonder how to manage hardware resources correctly.
1) How to determine the work-area size for a thread? Usually i just try to decrease the work area until the system crashes and then give the thread twice as much work area. Is there a proper way to determine the size of work-area for a thread?
2) I noticed that the fatfs file system library needs quite a huge work-area. I created a thread without file system access, then added file system access and noticed that it ran out of work area (system halted).
If i'd have multiple threads that need fatfs I would need to give each thread a huge work-area for fatfs, right? Is there a way to have only one big work-area for fatfs library? Or am I doing something wrong?
3) How can i make sure that multiple threads won't try to use the same hardware resources at the same time?
For example i just tried to read via SDIO (STM32F4) from SD card using fatfs. With one thread it all works fine. But when i start two threads that try to access the SD card it will fail (i guess this is because both threads try to use SDIO hardware). Is there a way to make sure threads will wait for the hardware to become available?
Another example is sound output. Of course only one thread can have sound output. I need a way to signal other threads that the sound output is free or already taken.
Is there something like a beginners tutorial for ChibiOS/threaded programming? A tutorial that goes a bit further than just showing how to create a thread... I'd like to get to know some programming techniques and when it's appropriate to use them.
But i always wonder how to manage hardware resources correctly.
1) How to determine the work-area size for a thread? Usually i just try to decrease the work area until the system crashes and then give the thread twice as much work area. Is there a proper way to determine the size of work-area for a thread?
2) I noticed that the fatfs file system library needs quite a huge work-area. I created a thread without file system access, then added file system access and noticed that it ran out of work area (system halted).
If i'd have multiple threads that need fatfs I would need to give each thread a huge work-area for fatfs, right? Is there a way to have only one big work-area for fatfs library? Or am I doing something wrong?
3) How can i make sure that multiple threads won't try to use the same hardware resources at the same time?
For example i just tried to read via SDIO (STM32F4) from SD card using fatfs. With one thread it all works fine. But when i start two threads that try to access the SD card it will fail (i guess this is because both threads try to use SDIO hardware). Is there a way to make sure threads will wait for the hardware to become available?
Another example is sound output. Of course only one thread can have sound output. I need a way to signal other threads that the sound output is free or already taken.
Is there something like a beginners tutorial for ChibiOS/threaded programming? A tutorial that goes a bit further than just showing how to create a thread... I'd like to get to know some programming techniques and when it's appropriate to use them.