|
NetBurner 3.5.8
PDF Version |
Example Path: examples/EFFS/Fat/MultiTask
This program illustrates accessing the file system from multiple tasks at the same time. The EFFS FAT library lets up to 10 tasks share one flash drive concurrently, with the library serializing the underlying card access. UserMain plus two additional tasks (Task1 and Task2) each:
Because each task works on its own file and loops on its own timer, their output interleaves on the debug serial port, demonstrating that several tasks can safely operate on the card at once.
The EFFS FAT file system is a single shared resource that any number of RTOS tasks may use at the same time. To make that safe, the library keeps a small amount of per-task state, and each task must register itself before it makes any file system call. That registration is what f_enterFS() does. Specifically:
f_chdir() doesn't move another task out from under it. f_enterFS() creates the slot that holds this task's context; until it is called, the library has no place to store that state for the task.f_* function before f_enterFS() is undefined and will fail.f_releaseFS() to free its slot for another task.This example puts that to work directly: UserMain(), Task1(), and Task2() each call f_enterFS() once before doing any file work, which is exactly what lets all three operate on the card concurrently without corrupting one another's state. The Basic example shows the simpler single-task case.