Advertisement
Guest User

Untitled

a guest
Nov 26th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <Arduino_FreeRTOS.h>
  2.  
  3. const int N = 20;
  4. int tab_valeur[N];
  5.  
  6. TaskHandle_t ProdHandle_1;
  7. TaskHandle_t ProdHandle_2;
  8. TaskHandle_t ConsoHandle;
  9.  
  10. SemaphoreHandle_t xSemProd_1;
  11. SemaphoreHandle_t xSemProd_2;
  12. SemaphoreHandle_t xSemConso;
  13. SemaphoreHandle_t xSemAffichage;
  14.  
  15. void setup() {
  16. Serial.begin(9600);
  17.  
  18. vSemaphoreCreateBinary(xSemProd_1);
  19. vSemaphoreCreateBinary(xSemProd_2);
  20. vSemaphoreCreateBinary(xSemConso);
  21.  
  22. xSemaphoreTake(xSemProd_2, portMAX_DELAY);
  23. xSemaphoreTake(xSemConso, portMAX_DELAY);
  24.  
  25. xSemAffichage = xSemaphoreCreateMutex();
  26.  
  27. xTaskCreate(Prod_1, "Production_1", 200, NULL, 3, &ProdHandle_1);
  28. xTaskCreate(Prod_2, "Production_2", 200, NULL, 3, &ProdHandle_2);
  29. //xTaskCreate(Cons, "Consommation", 200, NULL, 3, &ConsoHandle);
  30. }
  31.  
  32. void loop() {
  33. }
  34.  
  35. void Prod_1(void* pvParameters)
  36. {
  37. int counter_1 = 0;
  38.  
  39. while(1)
  40. {
  41. xSemaphoreTake(xSemProd_1, portMAX_DELAY);
  42.  
  43. for(int i = 0; i < N/2; i++){
  44. counter_1 ++;
  45. tab_valeur[i] = 59 - i;
  46. vTaskDelay(2/portTICK_PERIOD_MS);
  47. }
  48.  
  49. if(counter_1 == 10){
  50. counter_1 = 0;
  51. xSemaphoreTake(xSemAffichage, portMAX_DELAY);
  52. Serial.println("****** 10 Values generated ******");
  53. xSemaphoreGive(xSemAffichage);
  54. }
  55.  
  56. xSemaphoreGive(xSemProd_2);
  57. }
  58. }
  59.  
  60. void Prod_2(void* pvParameters)
  61. {
  62. int counter_2 = 0;
  63.  
  64. while(1)
  65. {
  66. xSemaphoreTake(xSemProd_2, portMAX_DELAY);
  67.  
  68. tab_valeur[N/2] = 20;
  69. for(int i = N/2; i < N; i++){
  70. counter_2++;
  71. tab_valeur[i + 1] = tab_valeur[i] + 2;
  72. vTaskDelay(4/portTICK_PERIOD_MS);
  73. }
  74.  
  75. if(counter_2 == 10){
  76. counter_2 = 0;
  77. xSemaphoreTake(xSemAffichage, portMAX_DELAY);
  78. Serial.println("****** 10 Values generated ******");
  79. xSemaphoreGive(xSemAffichage);
  80. }
  81.  
  82. xSemaphoreGive(xSemConso);
  83. }
  84. }
  85.  
  86. /*void Cons(void* pvParameters)
  87. {
  88. while(1)
  89. {
  90. xSemaphoreTake(xSemConso, portMAX_DELAY);
  91.  
  92.  
  93. xSemaphoreGive(xSemProd_1);
  94. }
  95. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement