#include "stm32c0xx_hal.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h" // Ajout de l'en-tête pour la file d'attente
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
void tledR(void* p);
void tledV(void* p);
void tledJ(void* p);
void tledB(void* p);
TaskHandle_t HLR;
TaskHandle_t HLV;
TaskHandle_t HLJ;
TaskHandle_t HLB;
QueueHandle_t Q; // Correction de la déclaration de la file d'attente
GPIO_PinState etat;
void MX_GPIO_Init(void);
void SystemClock_Config(void);
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
xTaskCreate(tledR, "tledR", 128,NULL,1,&HLR);
xTaskCreate(tledV, "tledV", 128,NULL,1,&HLV);
xTaskCreate(tledJ, "tledJ", 128,NULL,1,&HLJ);
xTaskCreate(tledB, "tledB", 128,NULL,1,&HLB);
Q= xQueueCreate(10,sizeof(GPIO_PinState));
vTaskStartScheduler();
while (1)
{
// Votre code principal
}
}
void tledV(void* p)
{
while (2)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0,GPIO_PIN_SET);
etat=HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0);
xQueueSendToBack(Q,&etat,200);
HAL_Delay(15000);
}
}
void tledR(void* p)
{
GPIO_PinState Vcase;
HAL_Delay(5000);
while (1)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0,GPIO_PIN_RESET);
xQueueReceive(Q,&Vcase,200);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1,Vcase);
}
HAL_Delay(15000);
}
void tledJ(void* p)
{
GPIO_PinState Vcase;
while (1)
{
HAL_Delay(10000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1,GPIO_PIN_RESET);
xQueueReceive(Q,&Vcase,200);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4,Vcase);
}
HAL_Delay(15000);
}
void tledB(void* p)
{
GPIO_PinState Vcase;
while (1)
{
HAL_Delay(15000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4,GPIO_PIN_RESET);
xQueueReceive(Q,&Vcase,200);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11,Vcase);
}
HAL_Delay(15000);
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct ={0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pins : PA0, PA1, PA4 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
// Gérer l'erreur de manière appropriée
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
// Gérer l'erreur de manière appropriée
}
}
// Fonction de ralentissement de FreeRTOS
void vApplicationIdleHook(void)
{
// Fonction de ralentissement de FreeRTOS
}