1+ #include <stdio.h>
2+ #include "freertos/FreeRTOS.h"
3+ #include "freertos/task.h"
4+ #include "freertos/semphr.h"
5+
6+ /*Task Handlers*/
7+ TaskHandle_t Task1 ;
8+ TaskHandle_t Task2 ;
9+ TaskHandle_t Task3 ;
10+ TaskHandle_t Task4 ;
11+ TaskHandle_t Task5 ;
12+ /* Semaphores are placed as global */
13+ SemaphoreHandle_t mySemaphore3 = NULL ;
14+ SemaphoreHandle_t mySemaphore4 = NULL ;
15+ SemaphoreHandle_t mySemaphore6 = NULL ;
16+
17+ /*
18+ xTaskGetTickCount() keeps track of the timing.
19+ It was used to keep as a check that to be sure
20+ that timing was correct, to a degree
21+
22+ And the arrow "->" was used to as an indicator
23+ that the task recieved a semaphore, once again
24+ just to make easier if it needs debugging later
25+ on.
26+ */
27+
28+ void Task_code1 (void * parameter )
29+ {
30+ while (1 )
31+ {
32+ printf ("Task 1 running [%i]\n" , xTaskGetTickCount ());
33+ vTaskDelay (2500 / portTICK_PERIOD_MS );
34+ }
35+
36+ }
37+ void Task_code2 (void * parameter )
38+ {
39+ while (1 )
40+ {
41+ printf ("Task 2 running [%i]\n" , xTaskGetTickCount ());
42+ xSemaphoreGive (mySemaphore3 );
43+ vTaskDelay (1000 / portTICK_PERIOD_MS );
44+
45+ }
46+ }
47+ void Task_code3 (void * parameter )
48+ {
49+ while (1 )
50+ {
51+ if (xSemaphoreTake (mySemaphore3 , 100 /portTICK_PERIOD_MS ) == pdTRUE )
52+ {
53+ printf ("Task 3 running [%i]\n" , xTaskGetTickCount ());
54+ vTaskDelay (500 /portTICK_RATE_MS );
55+ xSemaphoreGive (mySemaphore4 );
56+ }
57+ else
58+ {
59+ vTaskDelay (100 /portTICK_RATE_MS );
60+ }
61+ }
62+ }
63+ void Task_code4 (void * parameter )
64+ {
65+ while (1 )
66+ {
67+ if (xSemaphoreTake (mySemaphore4 , 100 /portTICK_PERIOD_MS ) == pdTRUE )
68+ {
69+ printf ("Task 4 running [%i]\n" , xTaskGetTickCount ());
70+ vTaskDelay (500 /portTICK_RATE_MS );
71+ xSemaphoreGive (mySemaphore6 );
72+ }
73+ else
74+ {
75+ vTaskDelay (100 /portTICK_RATE_MS );
76+ }
77+ }
78+ }
79+ void Task_code5 (void * parameter )
80+ {
81+ while (1 )
82+ {
83+ if (xSemaphoreTake (mySemaphore6 , 100 /portTICK_PERIOD_MS ) == pdTRUE )
84+ {
85+ printf ("Task 5 running [%i]\n" , xTaskGetTickCount ());
86+ vTaskDelay (2000 /portTICK_RATE_MS );
87+ }
88+ else
89+ {
90+ vTaskDelay (100 /portTICK_RATE_MS );
91+ }
92+ }
93+ }
94+
95+
96+
97+ void app_main (void )
98+ {
99+
100+ /* Created 3 mySemaphores which are going*/
101+ mySemaphore3 = xSemaphoreCreateBinary ();
102+ mySemaphore4 = xSemaphoreCreateBinary ();
103+ mySemaphore6 = xSemaphoreCreateBinary ();
104+
105+ /*Creation of the Task pinned to a core*/
106+ xTaskCreatePinnedToCore (Task_code1 ,"Task_1" ,2048 ,NULL ,2 , & Task1 ,0 );
107+ xTaskCreatePinnedToCore (Task_code2 ,"Task_2" ,2048 ,NULL ,2 , & Task2 ,1 );
108+ xTaskCreatePinnedToCore (Task_code3 ,"Task_2" ,2048 ,NULL ,2 , & Task3 ,0 );
109+ xTaskCreatePinnedToCore (Task_code4 ,"Task_2" ,2048 ,NULL ,2 , & Task4 ,1 );
110+ xTaskCreatePinnedToCore (Task_code5 ,"Task_2" ,2048 ,NULL ,2 , & Task5 ,0 );
111+
112+ }
0 commit comments