2021-03-09 18:17:28 +08:00
|
|
|
/*
|
|
|
|
* @Description:
|
|
|
|
* @Date: 2020-04-02 21:44:31
|
|
|
|
* @LastEditors: CK.Zh
|
2021-03-10 12:03:49 +08:00
|
|
|
* @LastEditTime: 2021-03-10 11:07:48
|
2021-03-09 18:17:28 +08:00
|
|
|
* @FilePath: \NaviKit_EC_stm32\Core\Src\freertos.c
|
|
|
|
*/
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE BEGIN Header */
|
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* File Name : 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
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2021-03-09 18:17:28 +08:00
|
|
|
|
|
|
|
//TODO:拆分该文件中的功能到不同的文件中,按照任务进行模块化拆分
|
2021-03-10 11:03:35 +08:00
|
|
|
#define LOG_TAG "RTOS"
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Header */
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
2020-12-16 12:02:47 +08:00
|
|
|
/* USER CODE BEGIN Includes */
|
2021-01-05 14:46:47 +08:00
|
|
|
#include "timers.h"
|
2021-03-10 12:03:49 +08:00
|
|
|
#include <th_default.h>
|
2021-03-09 18:17:28 +08:00
|
|
|
#include <th_cdc.h>
|
|
|
|
#include <th_demo.h>
|
|
|
|
#include <th_elog.h>
|
2021-03-10 11:03:35 +08:00
|
|
|
#include <th_led.h>
|
|
|
|
#include <th_coulomb.h>
|
|
|
|
#include <th_power.h>
|
|
|
|
#include <th_button.h>
|
|
|
|
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* 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 */
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2021-03-10 11:03:35 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Variables */
|
2021-03-10 11:03:35 +08:00
|
|
|
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN FunctionPrototypes */
|
2021-01-07 15:11:11 +08:00
|
|
|
|
2021-01-07 19:01:08 +08:00
|
|
|
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END FunctionPrototypes */
|
|
|
|
|
|
|
|
|
|
|
|
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
|
|
|
|
2020-12-17 18:22:19 +08:00
|
|
|
/* Hook prototypes */
|
|
|
|
void configureTimerForRunTimeStats(void);
|
|
|
|
unsigned long getRunTimeCounterValue(void);
|
|
|
|
void vApplicationIdleHook(void);
|
|
|
|
void vApplicationTickHook(void);
|
|
|
|
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
|
|
|
|
__weak void configureTimerForRunTimeStats(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__weak unsigned long getRunTimeCounterValue(void)
|
|
|
|
{
|
2021-03-10 12:03:49 +08:00
|
|
|
return osKernelGetTickCount();
|
2020-12-17 18:22:19 +08:00
|
|
|
}
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
void vApplicationIdleHook( void )
|
|
|
|
{
|
|
|
|
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
|
|
|
|
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
|
|
|
|
task. It is essential that code added to this hook function never attempts
|
|
|
|
to block in any way (for example, call xQueueReceive() with a block time
|
|
|
|
specified, or call vTaskDelay()). If the application makes use of the
|
|
|
|
vTaskDelete() API function (as this demo application does) then it is also
|
|
|
|
important that vApplicationIdleHook() is permitted to return to its calling
|
|
|
|
function, because it is the responsibility of the idle task to clean up
|
|
|
|
memory allocated by the kernel to any task that has since been deleted. */
|
|
|
|
}
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
void vApplicationTickHook( void )
|
|
|
|
{
|
|
|
|
/* This function will be called by each tick interrupt if
|
|
|
|
configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
|
|
|
|
added here, but the tick hook is called from an interrupt context, so
|
|
|
|
code must not attempt to block, and only the interrupt safe FreeRTOS API
|
|
|
|
functions can be used (those that end in FromISR()). */
|
|
|
|
}
|
|
|
|
/* USER CODE END 3 */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 4 */
|
|
|
|
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
|
|
|
|
{
|
|
|
|
/* Run time stack overflow checking is performed if
|
|
|
|
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
|
|
|
|
called if a stack overflow is detected. */
|
|
|
|
}
|
|
|
|
/* USER CODE END 4 */
|
|
|
|
|
2020-12-18 12:46:59 +08:00
|
|
|
/* USER CODE BEGIN PREPOSTSLEEP */
|
|
|
|
__weak void PreSleepProcessing(uint32_t *ulExpectedIdleTime)
|
|
|
|
{
|
|
|
|
/* place for user code */
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-12-18 12:46:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
__weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
|
|
|
|
{
|
|
|
|
/* place for user code */
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-12-18 12:46:59 +08:00
|
|
|
}
|
|
|
|
/* USER CODE END PREPOSTSLEEP */
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/**
|
|
|
|
* @brief FreeRTOS initialization
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
void MX_FREERTOS_Init(void) {
|
|
|
|
/* USER CODE BEGIN Init */
|
2021-03-10 11:03:35 +08:00
|
|
|
|
2021-03-10 12:03:49 +08:00
|
|
|
ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes);
|
2021-03-09 18:17:28 +08:00
|
|
|
my_elog_init();
|
|
|
|
NaviKit_var_init();
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Init */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_MUTEX */
|
|
|
|
/* add mutexes, ... */
|
2021-03-10 12:03:49 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* 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, ... */
|
2021-03-10 12:03:49 +08:00
|
|
|
PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes);
|
|
|
|
CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes);
|
|
|
|
PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes);
|
|
|
|
CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes);
|
|
|
|
IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes);
|
2021-01-07 19:01:08 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END RTOS_TIMERS */
|
|
|
|
|
|
|
|
/* USER CODE BEGIN RTOS_QUEUES */
|
|
|
|
/* add queues, ... */
|
2021-01-07 19:01:08 +08:00
|
|
|
// LogMessageQueueHandle = osMessageQueueNew (1024, sizeof(uint8_t), &LogMessageQueue_attributes);
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END RTOS_QUEUES */
|
|
|
|
|
|
|
|
/* Create the thread(s) */
|
2020-04-06 21:16:18 +08:00
|
|
|
/* creation of defaultTask */
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2020-04-14 17:27:52 +08:00
|
|
|
/* creation of LedBlinkTask */
|
2021-03-10 11:03:35 +08:00
|
|
|
// LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2020-04-27 18:19:02 +08:00
|
|
|
/* creation of CoulombRead */
|
2021-01-07 15:11:11 +08:00
|
|
|
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
|
2020-04-27 18:19:02 +08:00
|
|
|
|
2020-08-25 19:33:15 +08:00
|
|
|
/* creation of PowerMonitTask */
|
2021-01-15 17:04:20 +08:00
|
|
|
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
|
2020-07-15 18:26:22 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
/* creation of EventDetect */
|
2021-03-10 11:03:35 +08:00
|
|
|
// EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes);
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE BEGIN RTOS_THREADS */
|
|
|
|
/* add threads, ... */
|
2021-03-10 11:03:35 +08:00
|
|
|
|
2021-03-10 12:03:49 +08:00
|
|
|
//Default Task
|
|
|
|
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
|
|
|
|
2021-03-10 11:03:35 +08:00
|
|
|
//Power--------------------------------------------
|
|
|
|
// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes);
|
|
|
|
|
|
|
|
|
|
|
|
//Button--------------------------------------------
|
2021-03-10 12:03:49 +08:00
|
|
|
// ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes);
|
2021-03-10 11:03:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
//LED--------------------------------------------
|
2021-03-10 12:03:49 +08:00
|
|
|
// LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes);
|
2021-03-10 11:03:35 +08:00
|
|
|
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2021-03-10 11:03:35 +08:00
|
|
|
//CDC--------------------------------------------
|
2021-03-10 12:03:49 +08:00
|
|
|
// cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes);
|
2021-03-10 11:03:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
//Coulomb--------------------------------------------
|
|
|
|
// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
|
|
|
|
|
|
|
|
|
|
|
|
//Elog--------------------------------------------
|
2021-03-09 18:17:28 +08:00
|
|
|
// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes);
|
2021-03-10 12:03:49 +08:00
|
|
|
#ifdef ELOG_BUF_OUTPUT_ENABLE
|
2021-03-10 11:03:35 +08:00
|
|
|
ElogFlushTaskHandle = osThreadNew(StartElogFlushTask, NULL, &ElogFlushTask_attributes);
|
2021-03-10 12:03:49 +08:00
|
|
|
#endif
|
2021-02-05 18:22:21 +08:00
|
|
|
|
2021-03-10 11:03:35 +08:00
|
|
|
|
|
|
|
//Demo--------------------------------------------
|
|
|
|
// DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes);
|
|
|
|
// DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes);
|
|
|
|
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END RTOS_THREADS */
|
|
|
|
|
2020-12-17 18:22:19 +08:00
|
|
|
/* USER CODE BEGIN RTOS_EVENTS */
|
|
|
|
/* add events, ... */
|
2021-03-10 11:03:35 +08:00
|
|
|
|
2020-12-17 18:22:19 +08:00
|
|
|
/* USER CODE END RTOS_EVENTS */
|
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-10 12:03:49 +08:00
|
|
|
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2020-04-10 19:05:38 +08:00
|
|
|
|
2020-04-29 17:49:27 +08:00
|
|
|
|
2021-01-05 14:46:47 +08:00
|
|
|
|
2021-01-07 15:11:11 +08:00
|
|
|
/* Private application code --------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Application */
|
2021-01-07 19:01:08 +08:00
|
|
|
|
|
|
|
|
2021-03-09 18:17:28 +08:00
|
|
|
|
2020-09-02 18:45:43 +08:00
|
|
|
|
2020-04-02 22:18:11 +08:00
|
|
|
/* USER CODE END Application */
|
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|