202 lines
5.5 KiB
C
202 lines
5.5 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* File Name : freertos.c
|
|
* Description : Code for freertos applications
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2025 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* @file freertos.c
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "main.h"
|
|
#include "cmsis_os.h"
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
/* USER CODE BEGIN Includes */
|
|
#include "dac161s997.h"
|
|
#include "ch438q.h"
|
|
#include "tcpserverc.h"
|
|
/* USER CODE END Includes */
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* USER CODE BEGIN PTD */
|
|
|
|
/* USER CODE END PTD */
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* USER CODE BEGIN PD */
|
|
|
|
/* USER CODE END PD */
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* USER CODE BEGIN PM */
|
|
|
|
/* USER CODE END PM */
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN Variables */
|
|
|
|
/* USER CODE END Variables */
|
|
osThreadId lwip_taskHandle;
|
|
osThreadId dac_taskHandle;
|
|
osThreadId ch438_taskHandle;
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* USER CODE BEGIN FunctionPrototypes */
|
|
|
|
/* USER CODE END FunctionPrototypes */
|
|
|
|
void start_lwip_task(void const *argument);
|
|
void start_dac_task(void const *argument);
|
|
void start_ch438_task(void const *argument);
|
|
|
|
extern void MX_LWIP_Init(void);
|
|
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
|
|
|
/* GetIdleTaskMemory prototype (linked to static allocation support) */
|
|
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize);
|
|
|
|
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
|
|
static StaticTask_t xIdleTaskTCBBuffer;
|
|
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
|
|
|
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize)
|
|
{
|
|
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
|
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
|
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
|
/* place for user code */
|
|
}
|
|
/* USER CODE END GET_IDLE_TASK_MEMORY */
|
|
|
|
/**
|
|
* @brief FreeRTOS initialization
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void MX_FREERTOS_Init(void)
|
|
{
|
|
/* USER CODE BEGIN Init */
|
|
|
|
/* USER CODE END Init */
|
|
|
|
/* USER CODE BEGIN RTOS_MUTEX */
|
|
/* add mutexes, ... */
|
|
/* USER CODE END RTOS_MUTEX */
|
|
|
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
|
/* add semaphores, ... */
|
|
/* USER CODE END RTOS_SEMAPHORES */
|
|
|
|
/* USER CODE BEGIN RTOS_TIMERS */
|
|
/* start timers, add new ones, ... */
|
|
/* USER CODE END RTOS_TIMERS */
|
|
|
|
/* USER CODE BEGIN RTOS_QUEUES */
|
|
/* add queues, ... */
|
|
/* USER CODE END RTOS_QUEUES */
|
|
|
|
/* Create the thread(s) */
|
|
/* definition and creation of lwip_task */
|
|
osThreadDef(lwip_task, start_lwip_task, osPriorityNormal, 0, 12040);
|
|
lwip_taskHandle = osThreadCreate(osThread(lwip_task), NULL);
|
|
|
|
/* definition and creation of dac_task */
|
|
osThreadDef(dac_task, start_dac_task, osPriorityNormal, 0, 512);
|
|
dac_taskHandle = osThreadCreate(osThread(dac_task), NULL);
|
|
|
|
/* definition and creation of ch438_task */
|
|
osThreadDef(ch438_task, start_ch438_task, osPriorityNormal, 0, 512);
|
|
ch438_taskHandle = osThreadCreate(osThread(ch438_task), NULL);
|
|
|
|
/* USER CODE BEGIN RTOS_THREADS */
|
|
/* add threads, ... */
|
|
/* USER CODE END RTOS_THREADS */
|
|
}
|
|
|
|
/* USER CODE BEGIN Header_start_lwip_task */
|
|
/**
|
|
* @brief Function implementing the lwip_task thread.
|
|
* @param argument: Not used
|
|
* @retval None
|
|
*/
|
|
/* USER CODE END Header_start_lwip_task */
|
|
void start_lwip_task(void const *argument)
|
|
{
|
|
/* init code for LWIP */
|
|
MX_LWIP_Init();
|
|
/* USER CODE BEGIN start_lwip_task */
|
|
/* Infinite loop */
|
|
tcp_echo_init();
|
|
for (;;)
|
|
{
|
|
// osThreadTerminate(NULL);
|
|
ch438_interrupt_handler_data_ch438_chip_1();
|
|
ch438_interrupt_handler_data_ch438_chip_2();
|
|
|
|
vTaskDelay(10);
|
|
}
|
|
/* USER CODE END start_lwip_task */
|
|
}
|
|
|
|
/* USER CODE BEGIN Header_start_dac_task */
|
|
/**
|
|
* @brief Function implementing the dac_task thread.
|
|
* @param argument: Not used
|
|
* @retval None
|
|
*/
|
|
/* USER CODE END Header_start_dac_task */
|
|
void start_dac_task(void const *argument)
|
|
{
|
|
/* USER CODE BEGIN start_dac_task */
|
|
/* Infinite loop */
|
|
dac161s997_init();
|
|
for (;;)
|
|
{
|
|
uint8_t ch = 0;
|
|
for (ch = 0; ch < DAC_MAX_NUM; ch++)
|
|
{
|
|
dac161s997_output(ch, 12.0f);
|
|
}
|
|
vTaskDelay(100);
|
|
}
|
|
/* USER CODE END start_dac_task */
|
|
}
|
|
|
|
/* USER CODE BEGIN Header_start_ch438_task */
|
|
/**
|
|
* @brief Function implementing the ch438_task thread.
|
|
* @param argument: Not used
|
|
* @retval None
|
|
*/
|
|
/* USER CODE END Header_start_ch438_task */
|
|
void start_ch438_task(void const *argument)
|
|
{
|
|
/* USER CODE BEGIN start_ch438_task */
|
|
/* Infinite loop */
|
|
ch438_init();
|
|
for (;;)
|
|
{
|
|
osThreadTerminate(NULL);
|
|
// vTaskDelay(500);
|
|
}
|
|
/* USER CODE END start_ch438_task */
|
|
}
|
|
|
|
/* Private application code --------------------------------------------------*/
|
|
/* USER CODE BEGIN Application */
|
|
|
|
/* USER CODE END Application */
|