Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino_FreeRTOS.h>
- const int N = 20;
- int tab_valeur[N];
- TaskHandle_t ProdHandle_1;
- TaskHandle_t ProdHandle_2;
- TaskHandle_t ConsoHandle;
- SemaphoreHandle_t xSemProd_1;
- SemaphoreHandle_t xSemProd_2;
- SemaphoreHandle_t xSemConso;
- SemaphoreHandle_t xSemAffichage;
- void setup() {
- Serial.begin(9600);
- vSemaphoreCreateBinary(xSemProd_1);
- vSemaphoreCreateBinary(xSemProd_2);
- vSemaphoreCreateBinary(xSemConso);
- xSemaphoreTake(xSemProd_2, portMAX_DELAY);
- xSemaphoreTake(xSemConso, portMAX_DELAY);
- xSemAffichage = xSemaphoreCreateMutex();
- xTaskCreate(Prod_1, "Production_1", 200, NULL, 3, &ProdHandle_1);
- xTaskCreate(Prod_2, "Production_2", 200, NULL, 3, &ProdHandle_2);
- //xTaskCreate(Cons, "Consommation", 200, NULL, 3, &ConsoHandle);
- }
- void loop() {
- }
- void Prod_1(void* pvParameters)
- {
- int counter_1 = 0;
- while(1)
- {
- xSemaphoreTake(xSemProd_1, portMAX_DELAY);
- for(int i = 0; i < N/2; i++){
- counter_1 ++;
- tab_valeur[i] = 59 - i;
- vTaskDelay(2/portTICK_PERIOD_MS);
- }
- if(counter_1 == 10){
- counter_1 = 0;
- xSemaphoreTake(xSemAffichage, portMAX_DELAY);
- Serial.println("****** 10 Values generated ******");
- xSemaphoreGive(xSemAffichage);
- }
- xSemaphoreGive(xSemProd_2);
- }
- }
- void Prod_2(void* pvParameters)
- {
- int counter_2 = 0;
- while(1)
- {
- xSemaphoreTake(xSemProd_2, portMAX_DELAY);
- tab_valeur[N/2] = 20;
- for(int i = N/2; i < N; i++){
- counter_2++;
- tab_valeur[i + 1] = tab_valeur[i] + 2;
- vTaskDelay(4/portTICK_PERIOD_MS);
- }
- if(counter_2 == 10){
- counter_2 = 0;
- xSemaphoreTake(xSemAffichage, portMAX_DELAY);
- Serial.println("****** 10 Values generated ******");
- xSemaphoreGive(xSemAffichage);
- }
- xSemaphoreGive(xSemConso);
- }
- }
- /*void Cons(void* pvParameters)
- {
- while(1)
- {
- xSemaphoreTake(xSemConso, portMAX_DELAY);
- xSemaphoreGive(xSemProd_1);
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement