添加user

This commit is contained in:
RB 2025-04-27 00:30:45 +08:00
parent b3eb3c8f5a
commit b27fc87089
11 changed files with 216 additions and 0 deletions

0
User/bsp/.gitkeep Normal file
View File

17
User/bsp/bsp.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define BSP_OK (0)
#define BSP_ERR (-1)
#define BSP_ERR_NULL (-2)
#define BSP_ERR_INITED (-3)
#define BSP_ERR_NO_DEV (-4)
#define SIGNAL_BSP_USB_BUF_RECV (1u << 0)
#ifdef __cplusplus
}
#endif

0
User/component/.gitkeep Normal file
View File

View File

@ -0,0 +1,12 @@
// /*
// 自定义的数学运算。
// */
// #include "user_math.h"
// #include <stdint.h>
// float Adc_to_Distance(uint16_t adc_data) {
// // return (float)((adc_data * 1000) / 4095);
// return (float)((adc_data * 1000) / 16000000.0f); // 使用浮点数进行计算
// }

View File

@ -0,0 +1,20 @@
// /*
// 自定义的数学运算。
// */
// #pragma once
// #include <math.h>
// #include <stdint.h>
// #ifndef M_PI
// #define M_PI 3.14159265358979323846f
// #endif
// /**
// * @brief 用于计算ADC数据对应的距离mm
// * @param adc_data
// * @return
// */
// float Adc_to_Distance(uint16_t adc_data);

0
User/device/.gitkeep Normal file
View File

0
User/module/.gitkeep Normal file
View File

0
User/task/.gitkeep Normal file
View File

39
User/task/init.c Normal file
View File

@ -0,0 +1,39 @@
/*
*/
/* Includes ----------------------------------------------------------------- */
#include "task\user_task.h"
#include "device\can.h"
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
/**
* \brief
*
* \param argument 使
*/
void Task_Init(void *argument) {
(void)argument; /* 未使用argument消除警告 */
osKernelLock(); // 锁定内核,防止任务切换
// 创建任务,确保任务创建成功
task_runtime.thread.disp = osThreadNew(Task_Disp, NULL, &attr_disp);
task_runtime.thread.can = osThreadNew(Task_Can, NULL, &attr_can);
task_runtime.thread.monitor = osThreadNew(Task_Monitor, NULL, &attr_monitor);
task_runtime.thread.pc = osThreadNew(Task_PC, NULL, &attr_pc);
//创建消息队列
task_runtime.msgq.can.feedback.sick = osMessageQueueNew(2u, sizeof(CAN_t), NULL);
task_runtime.msgq.pc = osMessageQueueNew(2u, sizeof(CAN_t), NULL);
osKernelUnlock(); // 解锁内核
osThreadTerminate(osThreadGetId()); // 任务完成后结束自身
}

34
User/task/user_task.c Normal file
View File

@ -0,0 +1,34 @@
#include "task/user_task.h"
Task_Runtime_t task_runtime;
// 定义任务属性
const osThreadAttr_t attr_init = {
.name = "Task_Init",
.priority = osPriorityRealtime,
.stack_size = 256 * 4,
};
const osThreadAttr_t attr_can = {
.name = "Task_Can",
.priority = osPriorityRealtime,
.stack_size = 128 * 4,
};
const osThreadAttr_t attr_disp = {
.name = "Task_Disp",
.priority = osPriorityRealtime,
.stack_size = 1024 * 4,
};
const osThreadAttr_t attr_monitor = {
.name = "Task_Monitor",
.priority = osPriorityRealtime,
.stack_size = 128 * 4,
};
const osThreadAttr_t attr_pc = {
.name = "Task_PC",
.priority = osPriorityRealtime,
.stack_size = 128 * 4,
};

94
User/task/user_task.h Normal file
View File

@ -0,0 +1,94 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <cmsis_os2.h>
#include "FreeRTOS.h"
#include "task.h"
// 定义任务运行时结构体
typedef struct {
/* 各任务,也可以叫做线程 */
struct {
osThreadId_t can; /* CAN任务 */
osThreadId_t disp; /* ADC任务 */
osThreadId_t pc; /* PC任务 */
osThreadId_t monitor; /* 监控任务 */
} thread;
struct {
struct {
struct {
osMessageQueueId_t sick;
} output;
struct {
osMessageQueueId_t sick;
} feedback;
} can;
osMessageQueueId_t pc; /* PC消息队列 */
} msgq;
struct {
uint32_t can; /* CAN使用 */
uint32_t disp; /* ADC使用 */
uint32_t pc; /* PC使用 */
uint32_t monitor; /* 监控使用 */
} heap_water_mark; /* heap使用 */
struct {
float can; /* CAN任务运行频率 */
float disp; /* ADC任务运行频率 */
float pc; /* PC任务运行频率 */
float monitor; /* 监控任务运行频率 */
} freq; /* 任务运行频率 */
struct {
uint32_t can; /* CAN任务运行时间 */
uint32_t disp; /* ADC任务运行时间 */
uint32_t pc; /* PC任务运行时间 */
uint32_t monitor; /* 监控任务运行时间 */
} last_up_time; /* 任务最近运行时间 */
} Task_Runtime_t;
// 任务频率和初始化延时
#define TASK_FREQ_CAN (100u)
#define TASK_FREQ_DISP (1u)
#define TASK_FREQ_MONITOR (1u)
#define TASK_FREQ_PC (100u)
#define TASK_INIT_DELAY_INFO (500u)
// 任务句柄
typedef struct {
osThreadId_t can;
osThreadId_t disp;
osThreadId_t monitor;
osThreadId_t pc;
} Task_Handles_t;
extern Task_Runtime_t task_runtime;
extern const osThreadAttr_t attr_init;
extern const osThreadAttr_t attr_can;
extern const osThreadAttr_t attr_disp;
extern const osThreadAttr_t attr_monitor;
extern const osThreadAttr_t attr_pc;
void Task_Init(void *argument);
void Task_Can(void *argument);
void Task_Disp(void *argument);
void Task_Monitor(void *argument);
void Task_PC(void *argument);
#ifdef __cplusplus
}
#endif