mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-10 16:45:59 +00:00
README.md aktualisiert
This commit is contained in:
parent
31dc2f83db
commit
7d103cd821
66
README.md
66
README.md
@ -370,9 +370,71 @@ The resulting program switches between the states `PING` and `PONG` and alternat
|
||||
|
||||
### Using Inter-Thread Communication
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Coming soon!
|
||||
The most difficult part of working with TACOS is to design the inter-thread communication. Aside from the features provided by rtos2-utils, TACOS also provides a few helpful features. The main feature are global events.
|
||||
|
||||
#### Tick Events
|
||||
|
||||
Tick events are used for synchronizing threads running concurrently in your system. Right now, TACOS supports tick events that are triggered automatically with a frequency of 1, 10, 20, 50, or 100 Hz. In addition, some of these events have counterparts that run with the same frequency but have an offset. For example, there are the events `STA_TACOS_TICK_50_Hz` and `STA_TACOS_TOCK_50_Hz` which are triggered every 20 ms. The only difference is that `STA_TACOS_TOCK_50_Hz` always happens 10 ms after the last `STA_TACOS_TICK_50_Hz` event.
|
||||
|
||||
The following example shows how this global event can be used to debug print "TICK" every 20 ms.
|
||||
|
||||
```cpp
|
||||
namespace tasks {
|
||||
Task50Hz::Task50Hz() :
|
||||
TacosThread("50Hz", osPriorityNormal){}
|
||||
|
||||
void Task50Hz::func() {
|
||||
STA_DEBUG_PRINTLN("TICK");
|
||||
|
||||
sta::tacos::events::wait(STA_TACOS_TICK_50_Hz)
|
||||
}
|
||||
} // namespace tasks
|
||||
```
|
||||
|
||||
#### Custom Events
|
||||
|
||||
In addition to tick events, TACOS provides custom events to the user. Their usage is similar to the tick events. In total, there are 15 different custom events. Just as the system states, it is good practice to give them name.
|
||||
|
||||
```cpp
|
||||
// path/to/some.hpp
|
||||
|
||||
// Give the first and second custom event names.
|
||||
#define PING_EVENT STA_TACOS_CUSTOM_EVENT(0)
|
||||
#define PONG_EVENT STA_TACOS_CUSTOM_EVENT(1)
|
||||
```
|
||||
|
||||
With these definitions we can implement the statemachine example without the need of expensive state changes:
|
||||
|
||||
```cpp
|
||||
#include <tasks/ping_task.hpp>
|
||||
#include <tasks/pong_task.hpp>
|
||||
#include <path/to/states.hpp>
|
||||
|
||||
namespace tasks {
|
||||
PingTask::PingTask() :
|
||||
TacosThread("PING", osPriorityNormal){}
|
||||
|
||||
void PingTask::func() {
|
||||
sta::tacos::events::wait(PING_EVENT);
|
||||
sleep(100);
|
||||
STA_DEBUG_PRINTLN("PING");
|
||||
sta::tacos::events::signal(PONG_EVENT);
|
||||
}
|
||||
|
||||
PongTask::PongTask() :
|
||||
TacosThread("PONG", osPriorityNormal){}
|
||||
|
||||
void PongTask::func() {
|
||||
sta::tacos::events::signal(PING_EVENT);
|
||||
sta::tacos::events::wait(PONG_EVENT);
|
||||
sleep(100);
|
||||
STA_DEBUG_PRINTLN("PONG");
|
||||
}
|
||||
} // namespace tasks
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Only the 15 least significant bits can be used as custom event flags as the remainder is reserved by TACOS. As a result, using `STA_TACOS_CUSTOM_EVENT(k)` with k >= 15 is prevented by an assertion.
|
||||
|
||||
### Further information
|
||||
To look into other function of TACOS please consult the READMEs in the include folder or the doxygen documentation. Also consult the sta-core and rtos2-utils READMEs for further information on the features that TACOS uses.
|
Loading…
x
Reference in New Issue
Block a user