-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
96 lines (80 loc) · 1.97 KB
/
main.c
File metadata and controls
96 lines (80 loc) · 1.97 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "stm32f4xx.h" // Device header
#include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core
#include "FreeRTOSConfig.h" // ARM.FreeRTOS::RTOS:Config
#include "task.h" // ARM.FreeRTOS::RTOS:Core
#include "semphr.h"
#include "queue.h"
//xSemaphoreHandle x_INTERRUPT;
SemaphoreHandle_t x_INTERRUPT;
xQueueHandle queue;
void exti_init()
{
SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PC;
EXTI->RTSR = EXTI_RTSR_TR13;
//EXTI->PR = EXTI_PR_PR13;
EXTI->IMR = EXTI_IMR_MR13;
NVIC_EnableIRQ(EXTI15_10_IRQn);
NVIC_SetPriority(EXTI15_10_IRQn,5);
__enable_irq();
}
void EXTI15_10_IRQHandler(void)
{
BaseType_t needCS = pdFALSE;
EXTI->PR = EXTI_PR_PR13;
xSemaphoreGiveFromISR(x_INTERRUPT, &needCS);
if(needCS == pdTRUE)
{
portYIELD_FROM_ISR(needCS);
}
}
void IST(void *pvParams)
{
int mode = 0;
while(1)
{
if((xSemaphoreTake(x_INTERRUPT, portMAX_DELAY)) == pdPASS)
{
mode=!mode;
xQueueSendToFrontFromISR(queue,&mode,0);
}
}
}
void vTask1(void *pvParams)
{
int mode = 0;
while(1)
{
//xQueueReceive(queue,&mode,0);
for(uint8_t i = 0; i < 8 && mode; i++)
{
GPIOA->ODR = (1 << (15-i)) | (1 << (i));
vTaskDelay(400);
xQueueReceive(queue,&mode,0);
}
for(uint8_t i = 8; i > 0 && !mode; i--)
{
GPIOA->ODR = (1 << (15-i)) | (1 << (i));
vTaskDelay(400);
xQueueReceive(queue,&mode,0);
}
}
}
int main()
{
RCC->AHB1ENR |=RCC_AHB1ENR_GPIOAEN; //gpio is on
RCC->AHB1ENR |=RCC_AHB1ENR_GPIOCEN;
GPIOA->MODER |= GPIO_MODER_MODER5_0; //5 OUTPUT
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
exti_init();
queue = xQueueCreate(16,sizeof(int));
x_INTERRUPT = xSemaphoreCreateBinary();
if(x_INTERRUPT != NULL)
{
xTaskCreate(IST, "interrupt", configMINIMAL_STACK_SIZE, NULL, 4, NULL);
xTaskCreate(vTask1, "flash", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
vTaskStartScheduler();
}
while(1)
{
}
}