-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from RoboMaster-Club/18-daemon-watchdog-implem…
…entation daemon + remote + bsp_uart
- Loading branch information
Showing
10 changed files
with
158 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule typec-board-base
updated
6 files
+1 −0 | Core/Inc/stm32f4xx_it.h | |
+1 −9 | Core/Src/freertos.c | |
+16 −1 | Core/Src/stm32f4xx_it.c | |
+7 −1 | Core/Src/usart.c | |
+4 −2 | Makefile | |
+4 −1 | typec-board-base.ioc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef BSP_DAEMON_H | ||
#define BSP_DAEMON_H | ||
|
||
#include <stdint.h> | ||
|
||
#define DAEMON_PERIOD (10) // unit: ms | ||
|
||
typedef struct | ||
{ | ||
uint8_t id; | ||
uint16_t counter; | ||
uint16_t reload_value; | ||
|
||
void (*callback)(void); | ||
} Daemon_Instance_t; | ||
|
||
void Daemon_Init(void); | ||
Daemon_Instance_t* Daemon_Register(uint16_t reload_value, uint16_t initial_counter, void (*callback)(void)); | ||
void Daemon_Reload(Daemon_Instance_t *daemon); | ||
void Daemon_Task_Loop(void); | ||
|
||
#endif // BSP_DAEMON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "bsp_daemon.h" | ||
#include <stdlib.h> | ||
|
||
#define DAEMON_INSTANCE_MAX (3) | ||
Daemon_Instance_t *g_daemon_instances[DAEMON_INSTANCE_MAX]; | ||
uint8_t g_daemon_instance_count = 0; | ||
|
||
Daemon_Instance_t *Daemon_Register(uint16_t reload_value, uint16_t initial_counter, void (*callback)(void)) | ||
{ | ||
Daemon_Instance_t *daemon = (Daemon_Instance_t *)malloc(sizeof(Daemon_Instance_t)); | ||
|
||
daemon->counter = initial_counter; | ||
daemon->reload_value = reload_value; | ||
daemon->callback = callback; | ||
|
||
g_daemon_instances[g_daemon_instance_count++] = daemon; | ||
return daemon; | ||
} | ||
|
||
void Daemon_Reload(Daemon_Instance_t *daemon) | ||
{ | ||
daemon->counter = daemon->reload_value; | ||
} | ||
|
||
void Daemon_Task_Loop() | ||
{ | ||
for (int i = 0; i < g_daemon_instance_count; i++) | ||
{ | ||
g_daemon_instances[i]->counter--; | ||
if (g_daemon_instances[i]->counter == 0) | ||
{ | ||
g_daemon_instances[i]->callback(); | ||
g_daemon_instances[i]->counter = g_daemon_instances[i]->reload_value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
#include "bsp_uart.h" | ||
|
||
#include "referee_system.h" | ||
#include "jetson_orin.h" | ||
#include <stdlib.h> | ||
#include "memory.h" | ||
|
||
/** | ||
* @brief This is the callback function for the UART receive interrupt. | ||
* This function overrides the weak implementation in stm32f4xx_hal_uart.c. | ||
*/ | ||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { | ||
// Check which UART is calling the callback | ||
if (huart == Referee_System.huart) { | ||
// Decode Referee system data | ||
Referee_Get_Data(); | ||
} | ||
if (huart == g_orin_data.huartx) | ||
#define UART_INSTANCE_MAX 3 | ||
UART_Instance_t *g_uart_insatnces[UART_INSTANCE_MAX]; | ||
uint8_t g_uart_instance_count = 0; | ||
|
||
void UART_Service_Init(UART_Instance_t *uart_insatce) | ||
{ | ||
HAL_UARTEx_ReceiveToIdle_DMA(uart_insatce->uart_handle, uart_insatce->rx_buffer, uart_insatce->rx_buffer_size); | ||
__HAL_DMA_DISABLE_IT(uart_insatce->uart_handle->hdmarx, DMA_IT_HT); // disable half transfer interrupt | ||
} | ||
|
||
UART_Instance_t *UART_Register(UART_HandleTypeDef *huart, uint8_t *rx_buffer, uint8_t rx_buffer_size, void (*callback)(UART_Instance_t *uart_instance)) | ||
{ | ||
UART_Instance_t *uart_instance = (UART_Instance_t *)malloc(sizeof(UART_Instance_t)); | ||
uart_instance->uart_handle = huart; | ||
uart_instance->rx_buffer = rx_buffer; | ||
uart_instance->rx_buffer_size = rx_buffer_size; | ||
uart_instance->callback = callback; | ||
|
||
UART_Service_Init(uart_instance); | ||
|
||
g_uart_insatnces[g_uart_instance_count++] = uart_instance; | ||
return uart_instance; | ||
} | ||
|
||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) | ||
{ | ||
for (int i = 0; i < g_uart_instance_count; i++) | ||
{ | ||
// Decode Jetson Orin data | ||
Jetson_Orin_Decode(); | ||
if (g_uart_insatnces[i]->uart_handle == huart) | ||
{ | ||
if (g_uart_insatnces[i]->callback != NULL) | ||
{ | ||
g_uart_insatnces[i]->callback(g_uart_insatnces[i]); | ||
|
||
HAL_UARTEx_ReceiveToIdle_DMA(huart, g_uart_insatnces[i]->rx_buffer, g_uart_insatnces[i]->rx_buffer_size); | ||
__HAL_DMA_DISABLE_IT(huart3.hdmarx, DMA_IT_HT); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters