8763b25839
- Remove CMSIS-RTOS v1 (cmsis_os.h/cmsis_os.c), add CMSIS-RTOS v2 (cmsis_os2.c/freertos_os2.h/mpool.h) - Update FreeRTOS kernel, port, and headers to match v2 integration - Remove unused heap implementations, keep heap_4 - Update CubeMX project config (.mxproject, .ioc, CMakeLists.txt) - Update FreeRTOSConfig.h, freertos.c, main.c, stm32h7xx_it.c - Update application modules (master_machine, dmmotor) - Add CMSIS-RTOS2 headers, mpu_syscall_numbers.h, newlib/picolibc support
76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
#include "master_machine.h"
|
|
|
|
VisionData_t vision_data;
|
|
|
|
static USARTInstance *cv_usart_instance;
|
|
//static DaemonInstance *vision_daemon_instance;
|
|
|
|
static uint8_t calc_checksum(uint8_t *buf, uint8_t len)
|
|
{
|
|
uint8_t sum = 0;
|
|
for (uint8_t i = 0; i < len - 1; i++)
|
|
sum += buf[i];
|
|
return sum;
|
|
}
|
|
|
|
static void DecodeVision()
|
|
{
|
|
//DaemonReload(vision_daemon_instance);
|
|
|
|
static uint32_t counter;
|
|
float dt = DWT_GetDeltaT(&counter);
|
|
vision_data.frequency = 1.0f / dt;
|
|
|
|
uint8_t *buf = cv_usart_instance->recv_buff;
|
|
uint16_t len = cv_usart_instance->recv_buff_size;
|
|
uint8_t sof = buf[0];
|
|
|
|
if (sof == VISION_SOF_AUTO && len == VISION_AUTO_LEN)
|
|
{
|
|
if (calc_checksum(buf, VISION_AUTO_LEN) != buf[VISION_AUTO_LEN - 1])
|
|
return;
|
|
memcpy(&vision_data.error_x, buf + 1, 4);
|
|
memcpy(&vision_data.error_y, buf + 5, 4);
|
|
vision_data.auto_updated = 1;
|
|
}
|
|
else if (sof == VISION_SOF_MANUAL && len == VISION_MANUAL_LEN)
|
|
{
|
|
if (calc_checksum(buf, VISION_MANUAL_LEN) != buf[VISION_MANUAL_LEN - 1])
|
|
return;
|
|
vision_data.zero_force = buf[1];
|
|
memcpy(&vision_data.yaw_ref, buf + 2, 4);
|
|
memcpy(&vision_data.pitch_ref, buf + 6, 4);
|
|
vision_data.manual_updated = 1;
|
|
}
|
|
else if (sof == VISION_SOF_CMD && len == VISION_CMD_LEN)
|
|
{
|
|
if (calc_checksum(buf, VISION_CMD_LEN) != buf[VISION_CMD_LEN - 1])
|
|
return;
|
|
vision_data.cmd = buf[1];
|
|
vision_data.cmd_pending = 1;
|
|
}
|
|
}
|
|
|
|
static void VisionOfflineCallback(void *id)
|
|
{
|
|
(void)id;
|
|
USARTServiceInit(cv_usart_instance);
|
|
}
|
|
|
|
void Vision_Uart_Init(UART_HandleTypeDef *_handle)
|
|
{
|
|
USART_Init_Config_s conf = {
|
|
.module_callback = DecodeVision,
|
|
.recv_buff_size = 64,
|
|
.usart_handle = _handle,
|
|
};
|
|
cv_usart_instance = USARTRegister(&conf);
|
|
|
|
Daemon_Init_Config_s daemon_conf = {
|
|
.callback = NULL,
|
|
.owner_id = NULL,
|
|
.reload_count = 10,
|
|
};
|
|
//vision_daemon_instance = DaemonRegister(&daemon_conf);
|
|
}
|