Я использую STMCubeMX с FreeRTOS / CMSIS_RTOS_V2. Однако я думаю, что я не понял логи c за создание файлов.
- CubeMX создал файл "app_freertos. c" без заголовочного файла, и созданный семафор находится внутри этого файла.
- У меня есть два других файла "busA.h" и «busA. c», где я использую несколько ISR таймера с API-интерфейсами низкого уровня STM. "busA.h" включен в "stm32g0xx_it. c".
Мне нужно вызвать osSemaphoreRelease ( semaphoreId ) внутри одного из этих ISR обратные вызовы, но поскольку CubeMX создал семафор внутри "app_freertos. c", я просто не могу получить к нему доступ. Кажется, область видимости семафора ограничена "app_freertos. c". Проблема в том, что внутри моих файлов много чего происходит (busA. c), куча переменных и т. Д. c. Я на 90% уверен, что если я попытаюсь переместить все в «app_freertos. c», это будет беспорядок.
Должен ли я вручную создать файл заголовка для «app_freertos. c», а именно « app_freertos.h "и вернуть адрес семафора в мой файл" busA. c "(с функцией)?
Вот упрощенные коды:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : app_freertos.c
* Description : Code for freertos applications
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* 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 "../eecBus/bus_signal.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_t taskLedsHandle;
osThreadId_t BusAHandle;
osThreadId_t taskBusAFSHandle;
osMutexId_t rx_dataHandle;
osSemaphoreId_t smp_busA_rxHandle;
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
/* USER CODE END FunctionPrototypes */
void StartTaskLeds(void *argument);
void BusATask(void *argument);
void StartTaskBusAFS(void *argument);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
/**
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
/* USER CODE END Init */
osKernelInitialize();
/* Create the mutex(es) */
/* definition and creation of rx_data */
const osMutexAttr_t rx_data_attributes = {
.name = "rx_data"
};
rx_dataHandle = osMutexNew(&rx_data_attributes);
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* Create the semaphores(s) */
/* definition and creation of smp_busA_rx */
const osSemaphoreAttr_t smp_busA_rx_attributes = {
.name = "smp_busA_rx"
};
smp_busA_rxHandle = osSemaphoreNew(1, 1, &smp_busA_rx_attributes);
/* 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 taskLeds */
const osThreadAttr_t taskLeds_attributes = {
.name = "taskLeds",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128
};
taskLedsHandle = osThreadNew(StartTaskLeds, NULL, &taskLeds_attributes);
/* definition and creation of BusA */
const osThreadAttr_t BusA_attributes = {
.name = "BusA",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128
};
BusAHandle = osThreadNew(BusATask, NULL, &BusA_attributes);
/* definition and creation of taskBusAFS */
const osThreadAttr_t taskBusAFS_attributes = {
.name = "taskBusAFS",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128
};
taskBusAFSHandle = osThreadNew(StartTaskBusAFS, NULL, &taskBusAFS_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
}
/* USER CODE BEGIN Header_StartTaskLeds */
/**
* @brief Function implementing the taskLeds thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTaskLeds */
void StartTaskLeds(void *argument)
{
/* USER CODE BEGIN StartTaskLeds */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END StartTaskLeds */
}
/* USER CODE BEGIN Header_BusATask */
/**
* @brief Function implementing the BusA thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_BusATask */
void BusATask(void *argument)
{
/* USER CODE BEGIN BusATask */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END BusATask */
}
/* USER CODE BEGIN Header_StartTaskBusAFS */
/**
* @brief Function implementing the taskBusAFS thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTaskBusAFS */
void StartTaskBusAFS(void *argument)
{
/* USER CODE BEGIN StartTaskBusAFS */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END StartTaskBusAFS */
}
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
/* USER CODE END Application */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
busA. c :
#include <stdbool.h>
#include <stdlib.h>
#include "busA.h"
#include "gpio.h"
#include "cmsis_os.h"
//all variables, functions etc.
void busA_edge_callback()
{
xxx
}
void busA_bitTimer_callback()
{
if (!g_busA_signal.rx_error)
{
osSemaphoreRelease(smp_busA_rxHandle);
}
}
stm32g0xx. c: (по какой-то причине cubeMX включает в себя FREERTOS.h и task.h внутри stm32g0xx. c)
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32g0xx_it.h"
#include "FreeRTOS.h"
#include "task.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "../eecBus/bus_signal.h"
/* USER CODE END Includes */
/**
* @brief This function handles EXTI line 4 to 15 interrupts.
*/
void EXTI4_15_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_15_IRQn 0 */
/* USER CODE END EXTI4_15_IRQn 0 */
if (LL_EXTI_IsActiveFallingFlag_0_31(LL_EXTI_LINE_4) != RESET)
{
LL_EXTI_ClearFallingFlag_0_31(LL_EXTI_LINE_4);
/* USER CODE BEGIN LL_EXTI_LINE_4_FALLING */
/* USER CODE END LL_EXTI_LINE_4_FALLING */
}
if (LL_EXTI_IsActiveRisingFlag_0_31(LL_EXTI_LINE_4) != RESET)
{
LL_EXTI_ClearRisingFlag_0_31(LL_EXTI_LINE_4);
/* USER CODE BEGIN LL_EXTI_LINE_4_RISING */
/* USER CODE END LL_EXTI_LINE_4_RISING */
}
if (LL_EXTI_IsActiveFallingFlag_0_31(LL_EXTI_LINE_5) != RESET)
{
LL_EXTI_ClearFallingFlag_0_31(LL_EXTI_LINE_5);
/* USER CODE BEGIN LL_EXTI_LINE_5_FALLING */
busA_edge_callback();
/* USER CODE END LL_EXTI_LINE_5_FALLING */
}
if (LL_EXTI_IsActiveRisingFlag_0_31(LL_EXTI_LINE_5) != RESET)
{
LL_EXTI_ClearRisingFlag_0_31(LL_EXTI_LINE_5);
/* USER CODE BEGIN LL_EXTI_LINE_5_RISING */
busA_edge_callback();
/* USER CODE END LL_EXTI_LINE_5_RISING */
}
/* USER CODE BEGIN EXTI4_15_IRQn 1 */
/* USER CODE END EXTI4_15_IRQn 1 */
}
/**
* @brief This function handles TIM6 global interrupt.
*/
void TIM6_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_IRQn 0 */
/* USER CODE END TIM6_IRQn 0 */
HAL_TIM_IRQHandler(&htim6);
/* USER CODE BEGIN TIM6_IRQn 1 */
/* USER CODE END TIM6_IRQn 1 */
}
/**
* @brief This function handles TIM16 global interrupt.
*/
void TIM16_IRQHandler(void)
{
/* USER CODE BEGIN TIM16_IRQn 0 */
if(LL_TIM_IsActiveFlag_UPDATE(BUSA_TIMER) == 1U)
{
busA_bitTimer_callback();
LL_TIM_ClearFlag_UPDATE(BUSA_TIMER);
}
/* USER CODE END TIM16_IRQn 0 */
/* USER CODE BEGIN TIM16_IRQn 1 */
/* USER CODE END TIM16_IRQn 1 */
}