dr16好了
This commit is contained in:
parent
21c0f7a4cd
commit
31147537b5
@ -57,20 +57,10 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
|
||||
# User/component sources
|
||||
User/component/ahrs.c
|
||||
|
||||
# User/component/ahrs sources
|
||||
User/component/ahrs/ahrs.c
|
||||
|
||||
# User/component sources
|
||||
User/component/crc16.c
|
||||
User/component/crc8.c
|
||||
User/component/error_detect.c
|
||||
User/component/filter.c
|
||||
|
||||
# User/component/filter sources
|
||||
User/component/filter/filter.c
|
||||
|
||||
# User/component sources
|
||||
User/component/freertos_cli.c
|
||||
User/component/limiter.c
|
||||
User/component/pid.c
|
||||
@ -92,6 +82,7 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
# User/task sources
|
||||
User/task/ai.c
|
||||
User/task/init.c
|
||||
User/task/rc.c
|
||||
User/task/user_task.c
|
||||
)
|
||||
|
||||
|
||||
@ -80,14 +80,6 @@ int main(void)
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* Enable the CPU Cache */
|
||||
|
||||
/* Enable I-Cache---------------------------------------------------------*/
|
||||
SCB_EnableICache();
|
||||
|
||||
/* Enable D-Cache---------------------------------------------------------*/
|
||||
SCB_EnableDCache();
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
|
||||
@ -229,6 +229,17 @@ SECTIONS
|
||||
PROVIDE( __bss_start = __tbss_start );
|
||||
PROVIDE( __bss_size = __bss_end - __bss_start );
|
||||
|
||||
/* DMA buffer section in RAM_D2 (SRAM1/2) for STM32H7 DMA access */
|
||||
.dma_buffer (NOLOAD) : ALIGN(32)
|
||||
{
|
||||
. = ALIGN(32);
|
||||
_sdma_buffer = .;
|
||||
*(.dma_buffer)
|
||||
*(.dma_buffer*)
|
||||
. = ALIGN(32);
|
||||
_edma_buffer = .;
|
||||
} >RAM_D2
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack (NOLOAD) :
|
||||
{
|
||||
|
||||
@ -5,3 +5,10 @@
|
||||
function: Task_ai
|
||||
name: ai
|
||||
stack: 256
|
||||
- delay: 0
|
||||
description: ''
|
||||
freq_control: true
|
||||
frequency: 500.0
|
||||
function: Task_rc
|
||||
name: rc
|
||||
stack: 256
|
||||
|
||||
@ -31,6 +31,7 @@ void Task_Init(void *argument) {
|
||||
|
||||
/* 创建任务线程 */
|
||||
task_runtime.thread.ai = osThreadNew(Task_ai, NULL, &attr_ai);
|
||||
task_runtime.thread.rc = osThreadNew(Task_rc, NULL, &attr_rc);
|
||||
|
||||
// 创建消息队列
|
||||
/* USER MESSAGE BEGIN */
|
||||
|
||||
56
User/task/rc.c
Normal file
56
User/task/rc.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
rc Task
|
||||
遥控器接收任务 - 处理DR16遥控器数据接收
|
||||
*/
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "task/user_task.h"
|
||||
/* USER INCLUDE BEGIN */
|
||||
#include "device/dr16.h"
|
||||
/* USER INCLUDE END */
|
||||
|
||||
/* Private typedef ---------------------------------------------------------- */
|
||||
/* Private define ----------------------------------------------------------- */
|
||||
/* Private macro ------------------------------------------------------------ */
|
||||
/* Private variables -------------------------------------------------------- */
|
||||
/* USER STRUCT BEGIN */
|
||||
/* STM32H7: 整个DR16结构体放在DMA可访问的SRAM区域 */
|
||||
static DR16_t dr16 __attribute__((section(".dma_buffer"))) __attribute__((aligned(32)));
|
||||
/* USER STRUCT END */
|
||||
|
||||
/* Private function --------------------------------------------------------- */
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void Task_rc(void *argument) {
|
||||
(void)argument; /* 未使用argument,消除警告 */
|
||||
|
||||
|
||||
/* 计算任务运行到指定频率需要等待的tick数 */
|
||||
const uint32_t delay_tick = osKernelGetTickFreq() / RC_FREQ;
|
||||
|
||||
osDelay(RC_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||||
|
||||
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||
/* USER CODE INIT BEGIN */
|
||||
/* 初始化DR16遥控器 */
|
||||
DR16_Init(&dr16);
|
||||
/* USER CODE INIT END */
|
||||
|
||||
while (1) {
|
||||
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||
/* USER CODE BEGIN */
|
||||
/* 启动DMA接收 */
|
||||
DR16_StartDmaRecv(&dr16);
|
||||
|
||||
/* 等待DMA接收完成,超时时间20ms */
|
||||
if (DR16_WaitDmaCplt(20)) {
|
||||
/* DMA接收成功,解析数据 */
|
||||
DR16_ParseData(&dr16);
|
||||
} else {
|
||||
/* DMA接收超时,标记离线 */
|
||||
DR16_Offline(&dr16);
|
||||
}
|
||||
/* USER CODE END */
|
||||
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,3 +14,8 @@ const osThreadAttr_t attr_ai = {
|
||||
.priority = osPriorityNormal,
|
||||
.stack_size = 256 * 4,
|
||||
};
|
||||
const osThreadAttr_t attr_rc = {
|
||||
.name = "rc",
|
||||
.priority = osPriorityNormal,
|
||||
.stack_size = 256 * 4,
|
||||
};
|
||||
@ -14,10 +14,12 @@ extern "C" {
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
/* 任务运行频率 */
|
||||
#define AI_FREQ (500.0)
|
||||
#define RC_FREQ (500.0)
|
||||
|
||||
/* 任务初始化延时ms */
|
||||
#define TASK_INIT_DELAY (100u)
|
||||
#define AI_INIT_DELAY (0)
|
||||
#define RC_INIT_DELAY (0)
|
||||
|
||||
/* Exported defines --------------------------------------------------------- */
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
@ -28,6 +30,7 @@ typedef struct {
|
||||
/* 各任务,也可以叫做线程 */
|
||||
struct {
|
||||
osThreadId_t ai;
|
||||
osThreadId_t rc;
|
||||
} thread;
|
||||
|
||||
/* USER MESSAGE BEGIN */
|
||||
@ -50,16 +53,19 @@ typedef struct {
|
||||
/* 各任务的stack使用 */
|
||||
struct {
|
||||
UBaseType_t ai;
|
||||
UBaseType_t rc;
|
||||
} stack_water_mark;
|
||||
|
||||
/* 各任务运行频率 */
|
||||
struct {
|
||||
float ai;
|
||||
float rc;
|
||||
} freq;
|
||||
|
||||
/* 任务最近运行时间 */
|
||||
struct {
|
||||
float ai;
|
||||
float rc;
|
||||
} last_up_time;
|
||||
|
||||
} Task_Runtime_t;
|
||||
@ -70,10 +76,12 @@ extern Task_Runtime_t task_runtime;
|
||||
/* 初始化任务句柄 */
|
||||
extern const osThreadAttr_t attr_init;
|
||||
extern const osThreadAttr_t attr_ai;
|
||||
extern const osThreadAttr_t attr_rc;
|
||||
|
||||
/* 任务函数声明 */
|
||||
void Task_Init(void *argument);
|
||||
void Task_ai(void *argument);
|
||||
void Task_rc(void *argument);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -38,8 +38,8 @@ Bdma.SPI6_TX.0.SyncSignalID=NONE
|
||||
CAD.formats=
|
||||
CAD.pinconfig=
|
||||
CAD.provider=
|
||||
CORTEX_M7.CPU_DCache=Enabled
|
||||
CORTEX_M7.CPU_ICache=Enabled
|
||||
CORTEX_M7.CPU_DCache=Disabled
|
||||
CORTEX_M7.CPU_ICache=Disabled
|
||||
CORTEX_M7.Enable-Cortex_Memory_Protection_Unit_Region0_Settings=MPU_REGION_ENABLE
|
||||
CORTEX_M7.IPParameters=CPU_DCache,CPU_ICache,MPU_Control,Enable-Cortex_Memory_Protection_Unit_Region0_Settings,default_mode_Activation
|
||||
CORTEX_M7.MPU_Control=__NULL
|
||||
@ -900,3 +900,4 @@ VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
|
||||
VP_SYS_VS_tim4.Mode=TIM4
|
||||
VP_SYS_VS_tim4.Signal=SYS_VS_tim4
|
||||
board=custom
|
||||
rtos.0.ip=FREERTOS
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user