CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
uart_handler.c File Reference
#include "uart_handler/uart_handler.h"
#include "debug_tools/debug_uart.h"
#include "mpi/mpi_command_handling.h"
#include "uart_handler/uart_error_tracking.h"
#include "camera/camera_capture.h"
#include "log/log.h"
#include "mpi/mpi_transceiver.h"
#include "main.h"
#include <string.h>
Include dependency graph for uart_handler.c:

Macros

#define KISS_FEND   0xC0
 
#define KISS_FESC   0xDB
 
#define KISS_TFEND   0xDC
 
#define KISS_TFESC   0xDD
 

Functions

static uint8_t kiss_queue_is_full (void)
 
static void kiss_enqueue_frame (const volatile uint8_t *data, uint16_t len)
 
void HAL_UART_RxCpltCallback (UART_HandleTypeDef *huart)
 
void HAL_UART_RxHalfCpltCallback (UART_HandleTypeDef *huart)
 
void GNSS_set_uart_interrupt_state (uint8_t new_enabled)
 Sets the UART interrupt state (enabled/disabled)
 
uint8_t CAMERA_set_expecting_data (uint8_t new_enabled)
 Sets the UART interrupt state (enabled/disabled)
 
void HAL_UART_ErrorCallback (UART_HandleTypeDef *huart)
 
void UART_init_uart_handlers (void)
 

Variables

UART_HandleTypeDef * UART_telecommand_port_handle = &hlpuart1
 
UART_HandleTypeDef * UART_mpi_port_handle = &huart1
 
UART_HandleTypeDef * UART_ax100_port_handle = &huart2
 
UART_HandleTypeDef * UART_gnss_port_handle = &huart3
 
UART_HandleTypeDef * UART_camera_port_handle = &huart4
 
UART_HandleTypeDef * UART_eps_port_handle = &huart5
 
const uint16_t UART_telecommand_buffer_len = 256
 
volatile uint8_t UART_telecommand_buffer [256]
 
volatile uint16_t UART_telecommand_buffer_write_idx = 0
 
volatile uint32_t UART_telecommand_last_write_time_ms = 0
 
volatile uint8_t UART_telecommand_buffer_last_rx_byte = 0
 
const uint16_t UART_mpi_buffer_len = 256
 
volatile uint8_t UART_mpi_buffer [256]
 
volatile uint8_t UART_mpi_last_rx_byte = 0
 
volatile uint32_t UART_mpi_last_write_time_ms = 0
 
volatile uint16_t UART_mpi_buffer_write_idx = 0
 
volatile uint16_t UART_ax100_buffer_write_idx = 0
 
volatile uint32_t UART_ax100_last_write_time_ms = 0
 
volatile uint8_t UART_ax100_buffer_last_rx_byte = 0
 
const uint16_t UART_camera_dma_buffer_len = CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK*2
 
const uint16_t UART_camera_dma_buffer_len_half = CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK
 
volatile uint8_t UART_camera_dma_buffer [CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK *2]
 
volatile uint8_t UART_camera_pending_fs_write_half_1_buf [CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK]
 
volatile uint8_t UART_camera_pending_fs_write_half_2_buf [CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK]
 
volatile uint32_t UART_camera_last_write_time_ms = 0
 
volatile CAMERA_uart_write_state_enum_t CAMERA_uart_half_1_state = CAMERA_UART_WRITE_STATE_IDLE
 
volatile CAMERA_uart_write_state_enum_t CAMERA_uart_half_2_state = CAMERA_UART_WRITE_STATE_IDLE
 
const uint16_t UART_eps_buffer_len = 310
 
volatile uint8_t UART_eps_buffer [310]
 
volatile uint16_t UART_eps_buffer_write_idx = 0
 
volatile uint32_t UART_eps_last_write_time_ms = 0
 
volatile uint8_t UART_eps_is_expecting_data = 0
 
volatile uint8_t UART_eps_buffer_last_rx_byte = 0
 
const uint16_t UART_mpi_rx_buffer_len = 50
 
volatile uint8_t UART_mpi_rx_buffer [50]
 
volatile uint8_t UART_mpi_rx_last_byte = 0
 
volatile uint32_t UART_mpi_rx_last_byte_write_time_ms = 0
 
volatile uint16_t UART_mpi_rx_buffer_write_idx = 0
 
const uint16_t UART_gnss_buffer_len = 512
 
volatile uint8_t UART_gnss_buffer [512]
 
volatile uint16_t UART_gnss_buffer_write_idx = 0
 
volatile uint32_t UART_gnss_last_write_time_ms = 0
 
volatile uint8_t UART_gnss_buffer_last_rx_byte = 0
 
volatile uint8_t UART_gnss_uart_interrupt_enabled = 0
 
const uint8_t UART_mpi_rx_dma_buffer_len = 160
 
volatile uint8_t UART_mpi_rx_dma_buffer [160]
 
const uint16_t MPI_science_buffer_len = 20480
 Length of the MPI_science_buffer_one and MPI_science_buffer_two arrays.
 
volatile uint8_t MPI_science_buffer_one [20480]
 
volatile uint8_t MPI_science_buffer_two [20480]
 
volatile MPI_buffer_state_enum_t MPI_buffer_one_state = MPI_MEMORY_WRITE_STATUS_READY_TO_FILL
 Current state of the MPI_active_data_median_buffer (pending write vs. written).
 
volatile MPI_buffer_state_enum_t MPI_buffer_two_state = MPI_MEMORY_WRITE_STATUS_READY_TO_FILL
 
volatile uint32_t MPI_buffer_one_last_filled_uptime_ms = 0
 
volatile uint32_t MPI_buffer_two_last_filled_uptime_ms = 0
 
volatile uint16_t UART_MPI_science_buffer_index = 0
 Index into a virtual array that is MPI_science_buffer_one and MPI_science_buffer_two concatenated.
 
volatile AX100_kiss_frame_struct_t UART_AX100_kiss_frame_queue [AX100_MAX_KISS_FRAMES_IN_RX_QUEUE]
 
volatile uint8_t UART_AX100_kiss_frame_queue_head = 0
 
volatile uint8_t UART_AX100_kiss_frame_queue_tail = 0
 
static volatile uint8_t kiss_in_frame = 0
 
static volatile uint8_t kiss_escaped = 0
 
static volatile uint8_t kiss_decode_buf [AX100_MAX_KISS_FRAME_SIZE_BYTES]
 
static volatile uint16_t kiss_decode_len = 0
 

Macro Definition Documentation

◆ KISS_FEND

#define KISS_FEND   0xC0

◆ KISS_FESC

#define KISS_FESC   0xDB

◆ KISS_TFEND

#define KISS_TFEND   0xDC

◆ KISS_TFESC

#define KISS_TFESC   0xDD

Function Documentation

◆ CAMERA_set_expecting_data()

uint8_t CAMERA_set_expecting_data ( uint8_t new_enabled)

Sets the UART interrupt state (enabled/disabled)

Parameters
new_enabled1: command sent, expecting data; 0: not expecting data
Here is the caller graph for this function:

◆ GNSS_set_uart_interrupt_state()

void GNSS_set_uart_interrupt_state ( uint8_t new_enabled)

Sets the UART interrupt state (enabled/disabled)

Parameters
new_enabled1: enable interrupt; 0: disable interrupt
Note
This function must be called very carefully. This type of GNSS is known to, in the wrong mode, spam null bytes, which can lock up the entire system. Thus, the interrupt is disabled by default, and must be enabled explicitly by the GNSS telecommands.
Here is the caller graph for this function:

◆ HAL_UART_ErrorCallback()

void HAL_UART_ErrorCallback ( UART_HandleTypeDef * huart)
Here is the call graph for this function:

◆ HAL_UART_RxCpltCallback()

void HAL_UART_RxCpltCallback ( UART_HandleTypeDef * huart)
Here is the call graph for this function:

◆ HAL_UART_RxHalfCpltCallback()

void HAL_UART_RxHalfCpltCallback ( UART_HandleTypeDef * huart)
Here is the call graph for this function:

◆ kiss_enqueue_frame()

static void kiss_enqueue_frame ( const volatile uint8_t * data,
uint16_t len )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kiss_queue_is_full()

static uint8_t kiss_queue_is_full ( void )
inlinestatic
Here is the caller graph for this function:

◆ UART_init_uart_handlers()

void UART_init_uart_handlers ( void )
Here is the caller graph for this function:

Variable Documentation

◆ CAMERA_uart_half_1_state

volatile CAMERA_uart_write_state_enum_t CAMERA_uart_half_1_state = CAMERA_UART_WRITE_STATE_IDLE

◆ CAMERA_uart_half_2_state

volatile CAMERA_uart_write_state_enum_t CAMERA_uart_half_2_state = CAMERA_UART_WRITE_STATE_IDLE

◆ kiss_decode_buf

volatile uint8_t kiss_decode_buf[AX100_MAX_KISS_FRAME_SIZE_BYTES]
static

Temporary buffer to hold the decoded contents of the current KISS frame. Reset when a frame is completed or an error occurs (e.g. overflow or bad escape).

◆ kiss_decode_len

volatile uint16_t kiss_decode_len = 0
static

Current write index into kiss_decode_buf, tracking how many decoded bytes have been accumulated in the current frame.

◆ kiss_escaped

volatile uint8_t kiss_escaped = 0
static

Indicates whether the previous byte was KISS_FESC, meaning the next byte should be interpreted as an escaped control character (TFEND or TFESC).

◆ kiss_in_frame

volatile uint8_t kiss_in_frame = 0
static

Indicates whether we are currently inside a KISS frame. Set to 1 after receiving KISS_FEND, and reset on frame completion or error.

◆ MPI_buffer_one_last_filled_uptime_ms

volatile uint32_t MPI_buffer_one_last_filled_uptime_ms = 0

◆ MPI_buffer_one_state

Current state of the MPI_active_data_median_buffer (pending write vs. written).

◆ MPI_buffer_two_last_filled_uptime_ms

volatile uint32_t MPI_buffer_two_last_filled_uptime_ms = 0

◆ MPI_buffer_two_state

◆ MPI_science_buffer_len

const uint16_t MPI_science_buffer_len = 20480

Length of the MPI_science_buffer_one and MPI_science_buffer_two arrays.

◆ MPI_science_buffer_one

volatile uint8_t MPI_science_buffer_one[20480]

◆ MPI_science_buffer_two

volatile uint8_t MPI_science_buffer_two[20480]

◆ UART_ax100_buffer_last_rx_byte

volatile uint8_t UART_ax100_buffer_last_rx_byte = 0

◆ UART_ax100_buffer_write_idx

volatile uint16_t UART_ax100_buffer_write_idx = 0

◆ UART_AX100_kiss_frame_queue

volatile AX100_kiss_frame_struct_t UART_AX100_kiss_frame_queue[AX100_MAX_KISS_FRAMES_IN_RX_QUEUE]

◆ UART_AX100_kiss_frame_queue_head

volatile uint8_t UART_AX100_kiss_frame_queue_head = 0

◆ UART_AX100_kiss_frame_queue_tail

volatile uint8_t UART_AX100_kiss_frame_queue_tail = 0

◆ UART_ax100_last_write_time_ms

volatile uint32_t UART_ax100_last_write_time_ms = 0

◆ UART_ax100_port_handle

UART_HandleTypeDef* UART_ax100_port_handle = &huart2

◆ UART_camera_dma_buffer

volatile uint8_t UART_camera_dma_buffer[CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK *2]

◆ UART_camera_dma_buffer_len

const uint16_t UART_camera_dma_buffer_len = CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK*2

◆ UART_camera_dma_buffer_len_half

const uint16_t UART_camera_dma_buffer_len_half = CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK

◆ UART_camera_last_write_time_ms

volatile uint32_t UART_camera_last_write_time_ms = 0

◆ UART_camera_pending_fs_write_half_1_buf

volatile uint8_t UART_camera_pending_fs_write_half_1_buf[CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK]

◆ UART_camera_pending_fs_write_half_2_buf

volatile uint8_t UART_camera_pending_fs_write_half_2_buf[CAM_BYTES_TO_RECEIVE_PER_HALF_CALLBACK]

◆ UART_camera_port_handle

UART_HandleTypeDef* UART_camera_port_handle = &huart4

◆ UART_eps_buffer

volatile uint8_t UART_eps_buffer[310]

◆ UART_eps_buffer_last_rx_byte

volatile uint8_t UART_eps_buffer_last_rx_byte = 0

◆ UART_eps_buffer_len

const uint16_t UART_eps_buffer_len = 310

◆ UART_eps_buffer_write_idx

volatile uint16_t UART_eps_buffer_write_idx = 0

◆ UART_eps_is_expecting_data

volatile uint8_t UART_eps_is_expecting_data = 0

◆ UART_eps_last_write_time_ms

volatile uint32_t UART_eps_last_write_time_ms = 0

◆ UART_eps_port_handle

UART_HandleTypeDef* UART_eps_port_handle = &huart5

◆ UART_gnss_buffer

volatile uint8_t UART_gnss_buffer[512]

◆ UART_gnss_buffer_last_rx_byte

volatile uint8_t UART_gnss_buffer_last_rx_byte = 0

◆ UART_gnss_buffer_len

const uint16_t UART_gnss_buffer_len = 512

◆ UART_gnss_buffer_write_idx

volatile uint16_t UART_gnss_buffer_write_idx = 0

◆ UART_gnss_last_write_time_ms

volatile uint32_t UART_gnss_last_write_time_ms = 0

◆ UART_gnss_port_handle

UART_HandleTypeDef* UART_gnss_port_handle = &huart3

◆ UART_gnss_uart_interrupt_enabled

volatile uint8_t UART_gnss_uart_interrupt_enabled = 0

◆ UART_mpi_buffer

volatile uint8_t UART_mpi_buffer[256]

◆ UART_mpi_buffer_len

const uint16_t UART_mpi_buffer_len = 256

◆ UART_mpi_buffer_write_idx

volatile uint16_t UART_mpi_buffer_write_idx = 0

◆ UART_mpi_last_rx_byte

volatile uint8_t UART_mpi_last_rx_byte = 0

◆ UART_mpi_last_write_time_ms

volatile uint32_t UART_mpi_last_write_time_ms = 0

◆ UART_mpi_port_handle

UART_HandleTypeDef* UART_mpi_port_handle = &huart1

◆ UART_mpi_rx_buffer

volatile uint8_t UART_mpi_rx_buffer[50]

◆ UART_mpi_rx_buffer_len

const uint16_t UART_mpi_rx_buffer_len = 50

◆ UART_mpi_rx_buffer_write_idx

volatile uint16_t UART_mpi_rx_buffer_write_idx = 0

◆ UART_mpi_rx_dma_buffer

volatile uint8_t UART_mpi_rx_dma_buffer[160]

◆ UART_mpi_rx_dma_buffer_len

const uint8_t UART_mpi_rx_dma_buffer_len = 160

◆ UART_mpi_rx_last_byte

volatile uint8_t UART_mpi_rx_last_byte = 0

◆ UART_mpi_rx_last_byte_write_time_ms

volatile uint32_t UART_mpi_rx_last_byte_write_time_ms = 0

◆ UART_MPI_science_buffer_index

volatile uint16_t UART_MPI_science_buffer_index = 0

Index into a virtual array that is MPI_science_buffer_one and MPI_science_buffer_two concatenated.

◆ UART_telecommand_buffer

volatile uint8_t UART_telecommand_buffer[256]

◆ UART_telecommand_buffer_last_rx_byte

volatile uint8_t UART_telecommand_buffer_last_rx_byte = 0

◆ UART_telecommand_buffer_len

const uint16_t UART_telecommand_buffer_len = 256

◆ UART_telecommand_buffer_write_idx

volatile uint16_t UART_telecommand_buffer_write_idx = 0

◆ UART_telecommand_last_write_time_ms

volatile uint32_t UART_telecommand_last_write_time_ms = 0

◆ UART_telecommand_port_handle

UART_HandleTypeDef* UART_telecommand_port_handle = &hlpuart1