/* USER CODE BEGIN Header */ /** ****************************************************************************** * File Name : freertos.c * Description : Code for freertos applications ****************************************************************************** * @attention * * Copyright (c) 2024 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. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* 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 "task_ec800_upload.h" #include "task_communication.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 */ /* Definitions for defaultTask */ osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = { .name = "defaultTask", .stack_size = 128 * 4, .priority = (osPriority_t) osPriorityNormal, }; /* Definitions for ec800_dataUploa */ osThreadId_t ec800_dataUploaHandle; const osThreadAttr_t ec800_dataUploa_attributes = { .name = "ec800_dataUploa", .stack_size = 256 * 4, .priority = (osPriority_t) osPriorityBelowNormal, }; /* Definitions for communication */ osThreadId_t communicationHandle; const osThreadAttr_t communication_attributes = { .name = "communication", .stack_size = 256 * 4, .priority = (osPriority_t) osPriorityBelowNormal1, }; /* Definitions for Time2_ */ osTimerId_t Time2_Handle; const osTimerAttr_t Time2__attributes = { .name = "Time2_" }; /* Definitions for mutex_rs485RecDate */ osMutexId_t mutex_rs485RecDateHandle; const osMutexAttr_t mutex_rs485RecDate_attributes = { .name = "mutex_rs485RecDate" }; /* Definitions for mutex_ec800Date */ osMutexId_t mutex_ec800DateHandle; const osMutexAttr_t mutex_ec800Date_attributes = { .name = "mutex_ec800Date" }; /* Definitions for s_messageDate_location */ osMutexId_t s_messageDate_locationHandle; const osMutexAttr_t s_messageDate_location_attributes = { .name = "s_messageDate_location" }; /* Definitions for semphore_ */ osSemaphoreId_t semphore_Handle; const osSemaphoreAttr_t semphore__attributes = { .name = "semphore_" }; /* Definitions for count_semphore_ */ osSemaphoreId_t count_semphore_Handle; const osSemaphoreAttr_t count_semphore__attributes = { .name = "count_semphore_" }; /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ /* USER CODE END FunctionPrototypes */ void StartDefaultTask(void *argument); void Task_ec800_upload(void *argument); void Task_communication(void *argument); void Time2_Callback(void *argument); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ /* Hook prototypes */ void configureTimerForRunTimeStats(void); unsigned long getRunTimeCounterValue(void); /* USER CODE BEGIN 1 */ /* Functions needed when configGENERATE_RUN_TIME_STATS is on */ __weak void configureTimerForRunTimeStats(void) { } __weak unsigned long getRunTimeCounterValue(void) { return 0; } /* USER CODE END 1 */ /* USER CODE BEGIN PREPOSTSLEEP */ __weak void PreSleepProcessing(uint32_t *ulExpectedIdleTime) { /* place for user code */ } __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime) { /* place for user code */ } /* USER CODE END PREPOSTSLEEP */ /** * @brief FreeRTOS initialization * @param None * @retval None */ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Create the mutex(es) */ /* creation of mutex_rs485RecDate */ mutex_rs485RecDateHandle = osMutexNew(&mutex_rs485RecDate_attributes); /* creation of mutex_ec800Date */ mutex_ec800DateHandle = osMutexNew(&mutex_ec800Date_attributes); /* creation of s_messageDate_location */ s_messageDate_locationHandle = osMutexNew(&s_messageDate_location_attributes); /* USER CODE BEGIN RTOS_MUTEX */ /* add mutexes, ... */ /* USER CODE END RTOS_MUTEX */ /* Create the semaphores(s) */ /* creation of semphore_ */ semphore_Handle = osSemaphoreNew(1, 1, &semphore__attributes); /* creation of count_semphore_ */ count_semphore_Handle = osSemaphoreNew(1, 1, &count_semphore__attributes); /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ /* USER CODE END RTOS_SEMAPHORES */ /* Create the timer(s) */ /* creation of Time2_ */ Time2_Handle = osTimerNew(Time2_Callback, osTimerPeriodic, NULL, &Time2__attributes); /* 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) */ /* creation of defaultTask */ defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* creation of ec800_dataUploa */ ec800_dataUploaHandle = osThreadNew(Task_ec800_upload, NULL, &ec800_dataUploa_attributes); /* creation of communication */ communicationHandle = osThreadNew(Task_communication, NULL, &communication_attributes); /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ /* USER CODE END RTOS_EVENTS */ } /* USER CODE BEGIN Header_StartDefaultTask */ /** * @brief Function implementing the defaultTask thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_StartDefaultTask */ void StartDefaultTask(void *argument) { /* USER CODE BEGIN StartDefaultTask */ /* Infinite loop */ for(;;) { osDelay(1); } /* USER CODE END StartDefaultTask */ } /* USER CODE BEGIN Header_Task_ec800_upload */ /** * @brief Function implementing the ec800_dataUploa thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_Task_ec800_upload */ void Task_ec800_upload(void *argument) { /* USER CODE BEGIN Task_ec800_upload */ uint8_t recBack = 0; recBack = atk_ms6050_init(); if(recBack != 0){ printf("ATK-MS6050 init failed!\r\n"); BIT_SET(s_comData.Malfunction, gyroscope); // 置位陀螺仪数据异常故障 } printf("ATK-MS6050 init\r\n"); recBack = atk_ms6050_dmp_init(); if(recBack != 0){ printf("ATK-MS6050 DMP init failed!\r\n"); BIT_SET(s_comData.Malfunction, gyroscope); // 置位陀螺仪数据异常故障 } printf("ATK-MS6050 DMP init!\r\n"); /* Infinite loop */ for(;;) { task_ec800_content(); osDelay(1); } /* USER CODE END Task_ec800_upload */ } /* USER CODE BEGIN Header_Task_communication */ /** * @brief Function implementing the communication thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_Task_communication */ void Task_communication(void *argument) { /* USER CODE BEGIN Task_communication */ /* Infinite loop */ for(;;) { task_communication_content(); osDelay(1); } /* USER CODE END Task_communication */ } /* Time2_Callback function */ void Time2_Callback(void *argument) { /* USER CODE BEGIN Time2_Callback */ /* USER CODE END Time2_Callback */ } /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ /* USER CODE END Application */