Compare commits
2 Commits
8ad28e5e39
...
eaf764636d
Author | SHA1 | Date | |
---|---|---|---|
eaf764636d | |||
2f20ebeba4 |
37
main.c
37
main.c
@ -19,15 +19,21 @@
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
osThreadId_t idTask1;
|
||||
osThreadId_t idTask1, idTask2;
|
||||
osEventFlagsId_t evt_id;
|
||||
|
||||
const osThreadAttr_t AttrTask1 = {
|
||||
.stack_size = 512, // Create the thread stack size
|
||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||
.priority = osPriorityHigh, //Set initial thread priority to high
|
||||
.name = "Task 1"
|
||||
};
|
||||
|
||||
const osThreadAttr_t AttrTask2 = {
|
||||
.stack_size = 512, // Create the thread stack size
|
||||
.priority = osPriorityNormal, //Set initial thread priority to high
|
||||
.name = "Task 2"
|
||||
};
|
||||
|
||||
void init_button(void)
|
||||
{
|
||||
/* Configure GPIO pin: PI2 (BTN_0) as interrupt */
|
||||
@ -51,19 +57,33 @@ void EXTI2_IRQHandler(void)
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_PIN)
|
||||
{
|
||||
//button interrupt
|
||||
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_9);
|
||||
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, 1);
|
||||
osEventFlagsSet(evt_id, 0x1U);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread 1
|
||||
*---------------------------------------------------------------------------*/
|
||||
__NO_RETURN static void taskCounter(void *argument) {
|
||||
__NO_RETURN static void task1(void *argument) {
|
||||
|
||||
|
||||
for (;;) {
|
||||
osEventFlagsWait(evt_id);
|
||||
osEventFlagsClear(evt_id, );
|
||||
osEventFlagsWait(evt_id, 0x1U, osFlagsNoClear, osWaitForever);
|
||||
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread 2
|
||||
*---------------------------------------------------------------------------*/
|
||||
__NO_RETURN static void task2(void *argument) {
|
||||
|
||||
|
||||
for (;;) {
|
||||
osEventFlagsWait(evt_id, 0x1U, osFlagsNoClear, osWaitForever);
|
||||
osEventFlagsClear(evt_id, 0x1U);
|
||||
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,8 +136,9 @@ int main (void) {
|
||||
|
||||
osKernelInitialize(); // Initialize CMSIS-RTOS
|
||||
|
||||
idTask1 = osThreadNew(taskCounter, NULL, &AttrTask1);
|
||||
|
||||
idTask1 = osThreadNew(task1, NULL, &AttrTask1);
|
||||
idTask2 = osThreadNew(task2, NULL, &AttrTask2);
|
||||
|
||||
//events
|
||||
evt_id = osEventFlagsNew(NULL);
|
||||
|
||||
|
Reference in New Issue
Block a user