add P4 & P5
This commit is contained in:
95
P5_SETR2/Core/Src/Tasks.c
Normal file
95
P5_SETR2/Core/Src/Tasks.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Tareas.c
|
||||
*
|
||||
* Created on: 29 nov. 2020
|
||||
* Author: rpaz
|
||||
*/
|
||||
|
||||
#include "Tasks.h"
|
||||
|
||||
extern UART_HandleTypeDef huart1;
|
||||
|
||||
TaskHandle_t sensorTaskHandle;
|
||||
SemaphoreHandle_t xSemaphore;
|
||||
QueueHandle_t xQueue;
|
||||
QueueHandle_t xQueueLED;
|
||||
QueueHandle_t xQueueSensors;
|
||||
|
||||
void CreateSerialObjects()
|
||||
{
|
||||
xSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive (xSemaphore);
|
||||
|
||||
xQueue = xQueueCreate(5, sizeof (char*));
|
||||
xQueueLED = xQueueCreate(1, sizeof (char*));
|
||||
xQueueSensors = xQueueCreate(1, sizeof (SensorData_t));
|
||||
}
|
||||
|
||||
void QueueLed(char ch)
|
||||
{
|
||||
xQueueSend(xQueueLED,&ch, portMAX_DELAY);
|
||||
}
|
||||
|
||||
SensorData_t GetSensors()
|
||||
{
|
||||
SensorData_t aux;
|
||||
xTaskNotifyGive(sensorTaskHandle);
|
||||
xQueueReceive(xQueueSensors, &aux, portMAX_DELAY);
|
||||
return aux;
|
||||
}
|
||||
|
||||
void CreateTasks()
|
||||
{
|
||||
xTaskCreate(
|
||||
TaskSensors,
|
||||
"TaskSensors",
|
||||
128,
|
||||
NULL,
|
||||
1,
|
||||
&sensorTaskHandle
|
||||
);
|
||||
|
||||
xTaskCreate(
|
||||
TaskWebServer,
|
||||
"TaskWebServer",
|
||||
256,
|
||||
NULL,
|
||||
1,
|
||||
NULL
|
||||
);
|
||||
|
||||
xTaskCreate(
|
||||
TaskLed,
|
||||
"TaskLed",
|
||||
128,
|
||||
NULL,
|
||||
1,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
void TaskSensors(void* pArg)
|
||||
{
|
||||
InitSensors();
|
||||
while(1)
|
||||
{
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
ReadSensors();
|
||||
xQueueSend(xQueueSensors, (SensorData_t*) pArg, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskWebServer(void* pArg)
|
||||
{
|
||||
WifiServer();
|
||||
}
|
||||
|
||||
void TaskLed(void* pArg)
|
||||
{
|
||||
char ch;
|
||||
while(1)
|
||||
{
|
||||
xQueueReceive(xQueueLED, &ch, portMAX_DELAY);
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, ch);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user