R2_UP/User/task/action_task.c
2025-03-12 10:46:02 +08:00

76 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
码盘解析任务
处理码盘测量的实际距离
将需要的数据共享给其他的线程
*/
#include "action_task.h"
#include "Action.h"
#include "user_task.h"
#ifdef DEBUG
Action_POS_t pos;
#else
static Action_POS pos;
#endif
void Task_action(void *argument)
{
(void)argument;
// osDelay(TASK_INIT_DELAY_ACTION);
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_ACTION;
ACTIONRECV_Init(&pos);
uint32_t tick = osKernelGetTickCount(); /* 获取当前控制任务运行频率的tick*/
while (1)
{
#ifdef DEBUG
/* 记录任务使用的的栈空闄*/
task_runtime.stack_water_mark.action =
osThreadGetStackSpace(osThreadGetId());
#endif
ACTION_StartReceiving();
ACTION_DataRefresh(&pos);
/* 使用下面的错误处理函数遇到一些问题
每10ms置标志位 ACTION_WaitDmaCplt 判断此标志位,通过后会执行速度计算
根据计算任务运行频率大于中断产生频率每一次运行判断标志位不通过会导致结构体内数据清0的操作
目前的处理方法注释掉Action_HandleOffline函数中对结构体数据清零的函数memset
*/
if(ACTION_WaitDmaCplt()){
ACTION_Parse(&pos);
}
else{
Action_HandleOffline(&pos);
}
//将解算后的码盘位置值放入消息队列供其他任务使用
osMessageQueueReset(task_runtime.msgq.cmd.raw.Action);
osMessageQueuePut(task_runtime.msgq.cmd.raw.Action,(&pos),0,0);
tick += delay_tick; /* 计算下一个唤醒时刻*/
osDelayUntil(tick);
}
}