-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
71 lines (64 loc) · 1.79 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "stm32f4xx.h" // Device header
#include "FreeRTOSConfig.h" // ARM.FreeRTOS::RTOS:Config
#include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core
#include "task.h" // ARM.FreeRTOS::RTOS:Core
#include "semphr.h" // ARM.FreeRTOS::RTOS:Core
void Blinking(void* xSemaphore)
{
while(1)
{
if(xSemaphoreTake(xSemaphore, 0))
{ // blinking 4 sec
for(int count = 0; count < 4 ; count++)
{
GPIOA -> ODR |= GPIO_ODR_ODR_5; // turning LED on
vTaskDelay(500);
GPIOA -> ODR &= ~GPIO_ODR_ODR_5;
vTaskDelay(500);
}
xSemaphoreGive(xSemaphore);
}
vTaskDelay(1); // time need to give chance for check Mutex for SOS task
}
}
void SOS(void* xSemaphore)
{
int n = pdMS_TO_TICKS(50);
int m = 0;
while(1)
{
if(xSemaphoreTake(xSemaphore, 0))
{
for(int count = 0; count < 18 ; count++)
{ // blinking 4 sec
if (m == 3)
n = pdMS_TO_TICKS(233);
if (m == 6)
n =pdMS_TO_TICKS(50);
if (m == 9){
m = 0;
n = pdMS_TO_TICKS(50);}
GPIOA -> ODR |= GPIO_ODR_ODR_5;
vTaskDelay(n);
GPIOA -> ODR &= ~GPIO_ODR_ODR_5;
vTaskDelay(n);
m++;
}
xSemaphoreGive(xSemaphore);
}
vTaskDelay(1); // time need to give chance for check Mutex for Blinking task
}
}
int main(void)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // turning on GPIOA
GPIOA->MODER |= GPIO_MODER_MODER5_0; // setting A5 to output
SemaphoreHandle_t xSemaphore = NULL; // initializing semaphore's handle
xSemaphore = xSemaphoreCreateMutex(); // creating Mutex
xTaskCreate(Blinking, "Task1", configMINIMAL_STACK_SIZE, xSemaphore, 8, NULL);
xTaskCreate(SOS, "Task2", configMINIMAL_STACK_SIZE, xSemaphore, 8, NULL);
vTaskStartScheduler();
while(1)
{
}
}