22#include "configuration.h"
29#define CONSOLE_MODE_CMD 3
77 .usart_data_recv_cbuf.write_position = 0,
80 .console_cbuf.read_position = 0,
81 .console_cbuf.write_position = 0,
83 .console_mode =
false,
93 if(
is_pow(CONFIG_CONSOLE_USART_CBUF_SIZE) ==
false) {
122 uint8_t data_len = 0;
130 uint8_t data[data_len];
146 uint8_t console_text_len = 0;
152 for(uint8_t i = 0; i < console_text_len + 1; i++) {
165 for(uint32_t i = 0; i < data_len; i++) {
166 if(data[i] ==
'\r') {
169 uint8_t console_text_len = 0;
175 char console_text[console_text_len];
182 console_text[console_text_len - 1] =
'\0';
184 uint8_t backspace_counter = 0;
186 for(int16_t j = console_text_len - 1; j >= 0; j--) {
187 while(console_text[j] == 127) {
193 while(backspace_counter) {
200 arr_cmprs((
char*)console_text, console_text_len);
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
Circular buffer module public API.
Command subsystem public API.
Common utility module public API.
#define CONSOLE_MODE_CMD
ASCII control code used to enter and exit console mode (Ctrl+C).
static uint8_t usart_cbuf_mem[CONFIG_CONSOLE_USART_CBUF_SIZE]
Backing memory for the USART receive circular buffer.
static uint8_t console_cbuf_mem[CONFIG_CONSOLE_CBUF_SIZE]
Backing memory for the console command accumulation buffer.
Console subsystem public API.
System-wide error code definitions.
ERR_te cbuf_read(CBUF_HANDLE_ts *cbuf_handle, uint8_t *output_buf_o)
Reads all available data from the circular buffer into an output buffer.
ERR_te cbuf_len(CBUF_HANDLE_ts const *cbuf_handle, uint8_t *len_o)
Returns the number of bytes currently stored in the circular buffer.
ERR_te cbuf_write(CBUF_HANDLE_ts *cbuf_handle, uint8_t *input_buf, uint32_t input_len)
Writes data from an input buffer into the circular buffer.
ERR_te cmd_execute(char *console_text)
Parses and executes a command from a console text string.
bool is_pow(uint32_t num)
Checks whether a number is a power of two.
void arr_cmprs(char *arr, uint8_t len)
Compresses an array by removing null bytes and shifting remaining elements left.
ERR_te console_init(CONSOLE_HANDLE_ts *console_handle)
Initializes the console subsystem.
ERR_te console_run(void)
Runs the console state machine.
ERR_te
Standard return type used by all public API functions.
@ ERR_INVALID_CONFIGURATION
ERR_te init_log(void)
Initializes the logging subsystem.
ERR_te log_set_force_disable(bool bool_status)
Enables or disables forced suppression of all log output.
void gpio_init(GPIO_CFG_ts *gpio_cfg)
Initializes a GPIO pin according to the given configuration.
@ GPIO_MODE_ALTERNATE_FUNCTION
void usart_init(USART_CFG_ts *usart_cfg)
Initializes the USART peripheral with the given configuration.
void usart_set_reception(USART_REGDEF_ts *usart_instance, EN_STATUS_te en_status)
Enables or disables the USART receiver (RE bit).
void usart1_irq_data_recv_callback(uint8_t data)
USART RXNE interrupt callback. Writes the received byte into the USART receive buffer.
void usart_send(USART_REGDEF_ts *usart_instance, uint8_t *tx_buffer, uint32_t len)
Blocking USART transmit. Sends len bytes from tx_buffer.
@ USART_INTERRUPT_EN_TRUE
Common initialization public API.
Log subsystem public API.
STM32F401RE MCU-specific peripheral register definitions and bit position enumerations.
STM32F401RE GPIO driver public API.
STM32F401RE USART driver public API.
Handle representing a circular buffer instance.
Configuration handle for initializing the console subsystem.
USART_BAUD_RATE_te usart_baud_rate
GPIO_ALTERNATE_FUNCTION_te gpio_alternate_function
GPIO_REGDEF_ts * gpio_port
USART_REGDEF_ts * usart_instance
Configuration structure for initializing a GPIO pin.
GPIO_ALTERNATE_FUNCTION_te alternate_function
Configuration structure for initializing a USART peripheral.
USART_BAUD_RATE_te baud_rate
USART_REGDEF_ts * instance
USART_INTERRUPT_EN_te interrupt_en
USART peripheral register map.
Internal state of the SysTick driver.
CBUF_HANDLE_ts console_cbuf
CBUF_HANDLE_ts usart_data_recv_cbuf
USART_REGDEF_ts * usart_instance