UART echo app (#831)

* HAL: add context to UART IRQ's
* Apps: uart echo/log application
* Sync api
* Another api sync
This commit is contained in:
SG
2021-11-20 08:19:31 +10:00
committed by GitHub
parent 4303945748
commit 013ed64cbb
10 changed files with 498 additions and 107 deletions

View File

@@ -24,32 +24,33 @@ void furi_hal_console_init() {
}
void furi_hal_console_enable() {
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL);
while (!LL_USART_IsActiveFlag_TC(USART1));
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
while(!LL_USART_IsActiveFlag_TC(USART1))
;
furi_hal_uart_set_br(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
furi_hal_console_alive = true;
}
void furi_hal_console_disable() {
while (!LL_USART_IsActiveFlag_TC(USART1));
while(!LL_USART_IsActiveFlag_TC(USART1))
;
furi_hal_console_alive = false;
}
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
if (!furi_hal_console_alive)
return;
if(!furi_hal_console_alive) return;
UTILS_ENTER_CRITICAL_SECTION();
// Transmit data
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
// Wait for TC flag to be raised for last char
while (!LL_USART_IsActiveFlag_TC(USART1));
while(!LL_USART_IsActiveFlag_TC(USART1))
;
UTILS_EXIT_CRITICAL_SECTION();
}
void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) {
if (!furi_hal_console_alive)
return;
if(!furi_hal_console_alive) return;
UTILS_ENTER_CRITICAL_SECTION();
// Transmit data
@@ -57,7 +58,8 @@ void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size
// Transmit new line symbols
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)"\r\n", 2);
// Wait for TC flag to be raised for last char
while (!LL_USART_IsActiveFlag_TC(USART1));
while(!LL_USART_IsActiveFlag_TC(USART1))
;
UTILS_EXIT_CRITICAL_SECTION();
}
@@ -71,6 +73,6 @@ void furi_hal_console_printf(const char format[], ...) {
string_clear(string);
}
void furi_hal_console_puts(const char *data) {
void furi_hal_console_puts(const char* data) {
furi_hal_console_tx((const uint8_t*)data, strlen(data));
}