Skip to content

Commit

Permalink
referee + orin comm tested
Browse files Browse the repository at this point in the history
  • Loading branch information
jia-xie committed Mar 23, 2024
1 parent 4ea5c86 commit 591824e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 47 deletions.
4 changes: 3 additions & 1 deletion src/app/src/robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <math.h>
#include "imu_task.h"
#include "user_math.h"
#include "referee_system.h"

extern DJI_Motor_Handle_t *g_yaw;
#define SPIN_TOP_OMEGA (1.0f)
Expand All @@ -33,7 +34,8 @@ void Robot_Init()
Launch_Task_Init();
Remote_Init();
CAN_Service_Init();
Jetson_Orin_Init();
Referee_System_Init(&huart1);
Jetson_Orin_Init(&huart6);
// Initialize all tasks
Robot_Tasks_Start();
}
Expand Down
12 changes: 5 additions & 7 deletions src/bsp/Src/bsp_uart.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include "bsp_uart.h"

//#include "referee_system.h"
#include "referee_system.h"
#include "jetson_orin.h"

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
// if (huart->Instance == &huart6)
// {
// Referee_Get_Data(REFEREE_BUFFER_LEN);
// }

if (huart->Instance == huart1.Instance)
if (huart == Referee_System.huart) {
Referee_Get_Data();
}
if (huart == g_orin_data.huartx)
{
Jetson_Orin_Decode();
}
Expand Down
5 changes: 4 additions & 1 deletion src/devices/inc/jetson_orin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#define JETSON_ORIN_H

#include <stdint.h>
#include "usart.h"

typedef struct
{
UART_HandleTypeDef *huartx;

uint8_t rx_buffer[20];
uint8_t tx_buffer[33];

Expand Down Expand Up @@ -63,7 +66,7 @@ typedef struct
} Jetson_Orin_Data_t;

extern Jetson_Orin_Data_t g_orin_data;
void Jetson_Orin_Init(void);
void Jetson_Orin_Init(UART_HandleTypeDef *huartx);
void Jetson_Orin_Decode(void);
void Jetson_Orin_Send_Data(void);

Expand Down
1 change: 1 addition & 0 deletions src/devices/inc/referee_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ typedef struct

typedef struct
{
UART_HandleTypeDef *huart;
uint16_t DMA_Counter;
uint8_t Buffer[REFEREE_BUFFER_LEN];

Expand Down
7 changes: 4 additions & 3 deletions src/devices/src/jetson_orin.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ void Jetson_Orin_Decode(void)
}
}

void Jetson_Orin_Init(void)
void Jetson_Orin_Init(UART_HandleTypeDef *huartx)
{
HAL_UART_Receive_DMA(&huart1, g_orin_data.rx_buffer, 20);
g_orin_data.huartx = huartx;
HAL_UART_Receive_DMA(huartx, g_orin_data.rx_buffer, sizeof(g_orin_data.rx_buffer));
}

void Jetson_Orin_Send_Data(void)
Expand All @@ -70,5 +71,5 @@ void Jetson_Orin_Send_Data(void)
g_orin_data.tx_buffer[0] = 0xAA;
memcpy(&g_orin_data.tx_buffer[1],&g_orin_data.sending.float_byte.data_bytes[0], 32*sizeof(uint8_t));

HAL_UART_Transmit_DMA(&huart1, g_orin_data.tx_buffer, sizeof(g_orin_data.tx_buffer));
HAL_UART_Transmit_DMA(g_orin_data.huartx, g_orin_data.tx_buffer, sizeof(g_orin_data.tx_buffer));
}
36 changes: 1 addition & 35 deletions src/devices/src/referee_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
Referee_System_t Referee_System;
Referee_Robot_State_t Referee_Robot_State;

HAL_StatusTypeDef Referee_UART_Receive_DMA_No_Interrupt(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
HAL_StatusTypeDef Referee_UART_Receive_Interrupt(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
void Referee_Get_Data(void);
void Referee_Set_Robot_State(void);

Expand Down Expand Up @@ -73,34 +71,9 @@ void Referee_Set_Robot_State(void)
// }
}

HAL_StatusTypeDef Referee_UART_Receive_DMA_No_Interrupt(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0))
{
return HAL_ERROR;
}

huart->pRxBuffPtr = pData;
huart->RxXferSize = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;

/* Enable the DMA Stream */
HAL_DMA_Start(huart->hdmarx, (uint32_t)&huart->Instance->DR, (uint32_t)pData, Size);
/* Enable the DMA transfer for the receiver request by setting the DMAR bit in the UART CR3 register */
SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);

return HAL_OK;
}
else
{
return HAL_BUSY;
}
}

void Referee_System_Init(UART_HandleTypeDef *huart)
{
Referee_System.huart = huart;
HAL_UART_Receive_DMA(huart, Referee_System.Buffer, REFEREE_BUFFER_LEN);
}

Expand Down Expand Up @@ -238,11 +211,4 @@ void Referee_Get_Data(void)
else
n++;
}
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if (huart->Instance == huart1.Instance)
{
Referee_Get_Data();
}
}

0 comments on commit 591824e

Please sign in to comment.