25_R1_chassis/User/task/nuc_task.c

64 lines
1.4 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 "user_task.h"
#include "nuc.h"
extern Chassis_t chassis; //没用消息队列,以后有闲情雅致再说
#ifdef DEBUG
NUC_t nuc_raw;
CMD_NUC_t cmd_fromnuc;
CMD_t cmd_nuc;
#else
static NUC_t nuc_raw;
static CMD_NUC_t cmd_fromnuc;
static CMD_t cmd_nuc;
#endif
fp32 send_data[4];
int a = 0;
void Task_nuc(void *argument){
(void)argument; /**/
// osDelay(TASK_INIT_DELAY_NUC);
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_NUC;
NUC_Init(&nuc_raw);
uint32_t tick = osKernelGetTickCount();
while (1)
{
#ifdef DEBUG
task_runtime.stack_water_mark.nuc= osThreadGetStackSpace(osThreadGetId());
#endif
osMessageQueueGet(task_runtime.msgq.cmd.nuc,&cmd_nuc, NULL, 0);
if (chassis.SICK_FALG == 1) {
send_data[0] = 1;
send_data[1] = 2;
send_data[2] = 3;
send_data[3] = 4;
}
else {
memset(send_data, 0, sizeof(send_data)); // 全部置0
}
NUC_Send(send_data); // 发送数据(无论 SICK_FALG 是 0 还是 1
//接收nuc数据
NUC_StartReceiving();
if (NUC_WaitDmaCplt()){
NUC_RawParse(&cmd_fromnuc);
}
else{
NUC_HandleOffline(&cmd_fromnuc);
a++;
}
osMessageQueueReset(task_runtime.msgq.cmd.raw.nuc);
osMessageQueuePut(task_runtime.msgq.cmd.raw.nuc,&(cmd_fromnuc),0,0);
tick += delay_tick; /* 计算下一个唤醒时刻*/
osDelayUntil(tick);
}
}