Skip to content

Commit 0b99860

Browse files
authored
Merge pull request #36 from JorgeMinjares/add_lab_13
Added Lab 13 and changed html/ and latex/
2 parents e90489f + a550769 commit 0b99860

3 files changed

Lines changed: 512 additions & 0 deletions

File tree

Additional_Labs/Lab_13/README.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# **Lab 13: Assignment of Task to Cores**
2+
3+
# **Objective**
4+
The objective of this lab is to learn how to assign tasks to each of the cores manually. Up until now, you have been making tasks, but never had any control of the actual CPU core. In this lab, you will be assigning each task to the CPU core and will be using a semaphore for some of the tasks!
5+
6+
7+
| Tasks | Core Assigned | Execution Time|
8+
| :--- | :--- | :--- |
9+
| Task 1 | Core 0 | 2.5 seconds |
10+
| Task 2 | Core 1 | 1 second |
11+
| Task 3 | Core 0 | 0.5 second or 500 msec|
12+
| Task 4 | Core 1 | 0.5 second or 500 msec |
13+
| Task 5 | Core 0 | 2 seconds |
14+
15+
## **ESP32 Pinout**
16+
~~~
17+
+-----------------------+
18+
| O | USB | O |
19+
| ------- |
20+
3V3 | [ ] [ ] | VIN
21+
GND | [ ] [ ] | GND
22+
Touch3 / HSPI_CS0 / ADC2_3 / GPIO15 | [ ] [ ] | GPIO13 / ADC2_4 / HSPI_ID / Touch4
23+
CS / Touch2 / HSPI_WP / ADC2_2 / GPIO2 | [ ] [ ] | GPIO12 / ADC2_5 / HSPI_Q / Touch5
24+
Touch0 / HSPI_HD / ADC2_0 / GPIO4 | [ ] [ ] | GPIO14 / ADC2_6 / HSPI_CLK / Touch6
25+
U2_RXD / GPIO16 | [ ] [ ] | GPIO27 / ADC2_7 / Touch7
26+
U2_TXD / GPIO17 | [ ] [ ] | GPIO26 / ADC2_9 / DAC2
27+
V_SPI_CS0 / GPIO5 | [ ] ___________ [ ] | GPIO25 / ADC2_8 / DAC1
28+
SCK / V_SPI_CLK / GPIO18 | [ ] | | [ ] | GPIO33 / ADC1_5 / Touch8 / XTAL32
29+
U0_CTS / MSIO / V_SPI_Q / GPIO19 | [ ] | | [ ] | GPIO32 / ADC1_4 / Touch9 / XTAL32
30+
SDA / V_SPI_HD / GPIO21 | [ ] | | [ ] | GPIO35 / ADC1_7
31+
CLK2 / U0_RXD / GPIO3 | [ ] | | [ ] | GPIO34 / ADC1_6
32+
CLK3 / U0_TXD / GPIO1 | [ ] | | [ ] | GPIO39 / ADC1_3 / SensVN
33+
SCL / U0_RTS / V_SPI_WP / GPIO22 | [ ] | | [ ] | GPIO36 / ADC1_0 / SensVP
34+
MOSI / V_SPI_WP / GPIO23 | [ ] |___________| [ ] | EN
35+
| |
36+
| | | ____ ____ | |
37+
| | | | | | | | |
38+
| |__|__| |__| |__| |
39+
| O O |
40+
+-----------------------+
41+
~~~
42+
43+
# **Pre-lab**
44+
Analyze the example code and demonstrate some understanding from the sample code below.
45+
46+
~~~c
47+
#include <stdio.h>
48+
#include "freertos/FreeRTOS.h"
49+
#include "freertos/task.h"
50+
#include "freertos/semphr.h"
51+
/*
52+
Code was made by Christopher A. Mendoza
53+
UTEP 2022
54+
last edited: 11/3/2022
55+
*/
56+
57+
/*Task Handlers*/
58+
TaskHandle_t Task1;
59+
TaskHandle_t Task2;
60+
61+
void Task_code1(void *parameter)
62+
{
63+
while(1)
64+
{
65+
printf("Task 1 running [%i]\n", xTaskGetTickCount());
66+
vTaskDelay(2500 / portTICK_PERIOD_MS);
67+
}
68+
69+
}
70+
void Task_code2(void *parameter)
71+
{
72+
while(1)
73+
{
74+
printf("Task 2 running [%i]\n", xTaskGetTickCount());
75+
76+
vTaskDelay(1000 / portTICK_PERIOD_MS);
77+
78+
}
79+
}
80+
~~~
81+
82+
# **Lab Template**
83+
~~~c
84+
#include <stdio.h>
85+
#include "freertos/FreeRTOS.h"
86+
#include "freertos/task.h"
87+
#include "freertos/semphr.h"
88+
89+
/*Task Handlers*/
90+
TaskHandle_t Task1;
91+
TaskHandle_t Task2;
92+
TaskHandle_t Task3;
93+
TaskHandle_t Task4;
94+
TaskHandle_t Task5;
95+
/* Semaphores are placed as global */
96+
SemaphoreHandle_t mySemaphore3 = NULL;
97+
SemaphoreHandle_t mySemaphore4 = NULL;
98+
SemaphoreHandle_t mySemaphore6 = NULL;
99+
100+
/*
101+
xTaskGetTickCount() keeps track of the timing.
102+
It was used to keep as a check that to be sure
103+
that timing was correct, to a degree
104+
105+
And the arrow "->" was used to as an indicator
106+
that the task recieved a semaphore, once again
107+
just to make easier if it needs debugging later
108+
on.
109+
*/
110+
111+
void Task_code1(void *parameter)
112+
{
113+
while(1)
114+
{
115+
printf("Task 1 running [%i]\n", xTaskGetTickCount());
116+
vTaskDelay(2500 / portTICK_PERIOD_MS);
117+
}
118+
119+
}
120+
void Task_code2(void *parameter)
121+
{
122+
while(1)
123+
{
124+
printf("Task 2 running [%i]\n", xTaskGetTickCount());
125+
xSemaphoreGive(mySemaphore3);
126+
vTaskDelay(1000 / portTICK_PERIOD_MS);
127+
128+
}
129+
}
130+
void Task_code3(void *parameter)
131+
{
132+
while(1)
133+
{
134+
if(xSemaphoreTake(mySemaphore3, 100/portTICK_PERIOD_MS) == pdTRUE)
135+
{
136+
printf("Task 3 running [%i]\n", xTaskGetTickCount());
137+
vTaskDelay(500/portTICK_RATE_MS);
138+
xSemaphoreGive(mySemaphore4);
139+
}
140+
else
141+
{
142+
vTaskDelay(100/portTICK_RATE_MS);
143+
}
144+
}
145+
}
146+
void Task_code4(void *parameter)
147+
{
148+
while(1)
149+
{
150+
if(xSemaphoreTake(mySemaphore4, 100/portTICK_PERIOD_MS) == pdTRUE)
151+
{
152+
printf("Task 4 running [%i]\n", xTaskGetTickCount());
153+
vTaskDelay(500/portTICK_RATE_MS);
154+
xSemaphoreGive(mySemaphore6);
155+
}
156+
else
157+
{
158+
vTaskDelay(100/portTICK_RATE_MS);
159+
}
160+
}
161+
}
162+
void Task_code5(void *parameter)
163+
{
164+
while(1)
165+
{
166+
if(xSemaphoreTake(mySemaphore6, 100/portTICK_PERIOD_MS) == pdTRUE)
167+
{
168+
printf("Task 5 running [%i]\n", xTaskGetTickCount());
169+
vTaskDelay(2000/portTICK_RATE_MS);
170+
}
171+
else
172+
{
173+
vTaskDelay(100/portTICK_RATE_MS);
174+
}
175+
}
176+
}
177+
178+
179+
180+
void app_main(void)
181+
{
182+
183+
/* Created 3 mySemaphores which are going*/
184+
mySemaphore3 = xSemaphoreCreateBinary();
185+
mySemaphore4 = xSemaphoreCreateBinary();
186+
mySemaphore6 = xSemaphoreCreateBinary();
187+
188+
/*Creation of the Task pinned to a core*/
189+
xTaskCreatePinnedToCore(Task_code1,"Task_1",2048,NULL,2, &Task1 ,0);
190+
xTaskCreatePinnedToCore(Task_code2,"Task_2",2048,NULL,2, &Task2 ,1);
191+
xTaskCreatePinnedToCore(Task_code3,"Task_2",2048,NULL,2, &Task3 ,0);
192+
xTaskCreatePinnedToCore(Task_code4,"Task_2",2048,NULL,2, &Task4 ,1);
193+
xTaskCreatePinnedToCore(Task_code5,"Task_2",2048,NULL,2, &Task5 ,0);
194+
195+
}
196+
~~~
197+
198+
# Author
199+
* Christopher Mendoza
200+
* **Bachelor of Science in Electrical Engineering**

Additional_Labs/Lab_13/main.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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

Comments
 (0)