Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MeAurigaLab.h>
- #include "scheduler.h"
- #include <Arduino_FreeRTOS.h>
- #include "semphr.h"
- SemaphoreHandle_t xSemaphore;
- TaskHandle_t xHandle1 = NULL;
- TaskHandle_t xHandle2 = NULL;
- TaskHandle_t xHandle3 = NULL;
- char c1 = 'a';
- char c2 = 'b';
- char c3 = 'c';
- void TaskA (void *pvParameters) {
- if(xSemaphoreTake(xSemaphore, 1000)) {
- Serial.println("111");
- xSemaphoreGive(xSemaphore);
- } else {
- Serial.println("TaskA didn't get semaphore");
- }
- vTaskDelay(10);
- }
- void TaskB (void *pvParameters) {
- if(xSemaphoreTake(xSemaphore, 1000)) {
- Serial.println("222");
- xSemaphoreGive(xSemaphore);
- } else {
- Serial.println("TaskB didn't get semaphore");
- }
- vTaskDelay(10);
- }
- void TaskC (void *pvParameters) {
- if(xSemaphoreTake(xSemaphore, 1000)) {
- Serial.println("333");
- xSemaphoreGive(xSemaphore);
- } else {
- Serial.println("TaskC didn't get semaphore");
- }
- while(1) {
- Serial.println("OƤndlig");
- delay(100);
- }
- vTaskDelay(10);
- }
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- xSemaphore = xSemaphoreCreateMutex();
- vSchedulerInit();
- //Phase //Period //Worst-case exec time //deadline
- vSchedulerPeriodicTaskCreate(TaskA, "t1", configMINIMAL_STACK_SIZE, &c1, 30, &xHandle1, pdMS_TO_TICKS(0), pdMS_TO_TICKS(10), pdMS_TO_TICKS(100), pdMS_TO_TICKS(10));
- vSchedulerPeriodicTaskCreate(TaskB, "t2", configMINIMAL_STACK_SIZE, &c2, 20, &xHandle2, pdMS_TO_TICKS(0), pdMS_TO_TICKS(20), pdMS_TO_TICKS(100), pdMS_TO_TICKS(20));
- vSchedulerPeriodicTaskCreate(TaskC, "t3", configMINIMAL_STACK_SIZE, &c3, 10, &xHandle3, pdMS_TO_TICKS(0), pdMS_TO_TICKS(30), pdMS_TO_TICKS(100), pdMS_TO_TICKS(30));
- vSchedulerStart();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement