Advertisement
ganryu

Untitled

Nov 9th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <FreeRTOS_v821.h>
  2.  
  3. //Pines Leds
  4.  
  5. const int ledRed = 42
  6. const int ledYellow = 40;
  7. const int ledGreen = 41;
  8.  
  9. void initLeds(){
  10.     pinMode(ledRed, OUTPUT);
  11.     pinMode(ledYellow, OUTPUT);
  12.     pinMode(ledGreen, OUTPUT);
  13. }
  14.  
  15. static void task_red(void* params );
  16. static void task_green(void* params);
  17.  
  18. void setup(){
  19.     Serial.begin(115200);
  20.     initLeds();
  21.  
  22.     xTaskCreate(
  23.         task_red,
  24.         "idRed",
  25.         256,
  26.         NULL,
  27.         2,
  28.         NULL
  29.     );
  30.  
  31.     xTaskCreate(
  32.         task_yellow,
  33.         "idYellow",
  34.         256,
  35.         NULL,
  36.         1,
  37.         NULL
  38.     );
  39.  
  40.     vTaskStartScheduler();
  41.  
  42.     for (;;);  
  43. }
  44.  
  45. void loop(){
  46. }
  47.  
  48. static void task_red(void* params){
  49.     TickType_t xLastWakeTime; // Despertar a lo último.
  50.     const TickType_t xPeriod = pdMS_TO_TICKS(1000); // Período
  51.     const TickType_t xC = pdMS_TO_TICKS(2000); // WCET
  52.     xLastWakeTime =  xTaskGetTickCount();
  53.     long ticks;
  54.  
  55.     for(;;) {
  56.         digitalWrite(ledRed, HIGH);
  57.         // vTaskDelay(xPeriod);
  58.         vTaskDelayUntil(&xLastWakeTime, xPeriod);
  59.         digitalWrite(ledRed, LOW);
  60.         vTaskDelayUntil(&xLastWakeTime, xC);
  61.         Serial.print("Ticks RED:");
  62.         ticks = xTaskGetTickCount();
  63.         Serial.print(ticks);
  64.     }
  65. }
  66. static void task_yellow(void* params){
  67.     TickType_t xLastWakeTime;
  68.     const TickType_t xPeriod = pdMS_TO_TICKS(3000); // Período
  69.     const TickType_t xC = pdMS_TO_TICKS(1000); // WCET
  70.  
  71.     xLastWakeTime =  xTaskGetTickCount();
  72.  
  73.     for(;;){
  74.         digitalWrite(ledGreen, HIGH);
  75.         // vTaskDelay(xPeriod);
  76.         vTaskDelayUntil(&xLastWakeTime, xC);
  77.         digitalWrite(ledGreen, LOW);
  78.         vTaskDelayUntil(&xLastWakeTime, xPeriod);
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement