Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 KB | None | 0 0
  1. #include <MeAurigaLab.h>
  2. #include "scheduler.h"
  3. #include <Arduino_FreeRTOS.h>
  4. #include "semphr.h"
  5.  
  6. SemaphoreHandle_t xSemaphore;
  7.  
  8. TaskHandle_t xHandle1 = NULL;
  9. TaskHandle_t xHandle2 = NULL;
  10. TaskHandle_t xHandle3 = NULL;
  11.  
  12. char c1 = 'a';
  13. char c2 = 'b';
  14. char c3 = 'c';
  15.  
  16. void TaskA (void *pvParameters) {
  17.  
  18.   if(xSemaphoreTake(xSemaphore, 1000)) {
  19.     Serial.println("111");
  20.     xSemaphoreGive(xSemaphore);
  21.   } else {
  22.     Serial.println("TaskA didn't get semaphore");
  23.   }
  24.  
  25.   vTaskDelay(10);
  26.  
  27. }
  28.  
  29. void TaskB (void *pvParameters) {
  30.   if(xSemaphoreTake(xSemaphore, 1000)) {
  31.     Serial.println("222");
  32.     xSemaphoreGive(xSemaphore);
  33.   } else {
  34.     Serial.println("TaskB didn't get semaphore");
  35.   }
  36.  
  37.     vTaskDelay(10);
  38. }
  39.  
  40. void TaskC (void *pvParameters) {
  41.     if(xSemaphoreTake(xSemaphore, 1000)) {
  42.     Serial.println("333");
  43.     xSemaphoreGive(xSemaphore);
  44.   } else {
  45.     Serial.println("TaskC didn't get semaphore");
  46.   }
  47.  
  48.   while(1) {
  49.     Serial.println("OƤndlig");
  50.     delay(100);
  51.   }
  52.  
  53.     vTaskDelay(10);
  54. }
  55.  
  56. void setup() {
  57.   // put your setup code here, to run once:
  58.  
  59.   Serial.begin(9600);
  60.  
  61.   xSemaphore = xSemaphoreCreateMutex();
  62.  
  63.   vSchedulerInit();
  64.                                                                                             //Phase           //Period          //Worst-case exec time    //deadline
  65.   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));
  66.   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));
  67.   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));
  68.  
  69.   vSchedulerStart();
  70. }
  71.  
  72. void loop() {
  73.   // put your main code here, to run repeatedly:
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement