1 | #include <Arduino.h> |
---|
2 | |
---|
3 | SemaphoreHandle_t sem_boss; |
---|
4 | |
---|
5 | void employee_talk(){ |
---|
6 | Serial.println("Employee working..."); |
---|
7 | } |
---|
8 | |
---|
9 | void boss(void *pvParameters){ |
---|
10 | int count=0; |
---|
11 | while(true){ |
---|
12 | Serial.print(count++); |
---|
13 | Serial.println(" Boss giveing the single..."); |
---|
14 | xSemaphoreGive(sem_boss); |
---|
15 | Serial.println("Boss finished giveing the single...\n"); |
---|
16 | vTaskDelay(5000); |
---|
17 | } |
---|
18 | } |
---|
19 | |
---|
20 | void employee(void *pvParameters){ |
---|
21 | while(true){ |
---|
22 | if ( xSemaphoreTake(sem_boss, portMAX_DELAY) ){ |
---|
23 | employee_talk(); |
---|
24 | Serial.println("Employee worked...Done\r\n"); |
---|
25 | } |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | void setup() { |
---|
30 | Serial.begin(115200); |
---|
31 | sem_boss = xSemaphoreCreateBinary(); |
---|
32 | xTaskCreate(boss, "boss", 1024, NULL, 3, NULL); |
---|
33 | xTaskCreate(employee, "employee", 1024, NULL, 2, NULL); |
---|
34 | } |
---|
35 | |
---|
36 | void loop() { } |
---|