Improve furi_hal_serial API

This commit is contained in:
Georgii Surkov 2024-02-07 21:13:38 +03:00
parent fee6f12684
commit c489c956e7
No known key found for this signature in database
GPG Key ID: 44A24455F6ADB5E7
6 changed files with 40 additions and 6 deletions

View File

@ -61,9 +61,14 @@ static void expansion_worker_serial_rx_callback(
ExpansionWorker* instance = context;
if(event == FuriHalSerialRxEventData) {
const uint8_t data = furi_hal_serial_async_rx(handle);
furi_stream_buffer_send(instance->rx_buf, &data, sizeof(data), 0);
if(event & (FuriHalSerialRxEventNoiseError | FuriHalSerialRxEventFrameError |
FuriHalSerialRxEventOverrunError)) {
furi_thread_flags_set(furi_thread_get_id(instance->thread), ExpansionWorkerFlagError);
} else if(event & FuriHalSerialRxEventData) {
while(furi_hal_serial_async_rx_available(handle)) {
const uint8_t data = furi_hal_serial_async_rx(handle);
furi_stream_buffer_send(instance->rx_buf, &data, sizeof(data), 0);
}
furi_thread_flags_set(furi_thread_get_id(instance->thread), ExpansionWorkerFlagData);
}
}
@ -341,7 +346,7 @@ static int32_t expansion_worker(void* context) {
furi_hal_serial_init(instance->serial_handle, EXPANSION_PROTOCOL_DEFAULT_BAUD_RATE);
furi_hal_serial_async_rx_start(
instance->serial_handle, expansion_worker_serial_rx_callback, instance, false);
instance->serial_handle, expansion_worker_serial_rx_callback, instance, true);
if(expansion_worker_send_heartbeat(instance)) {
expansion_worker_state_machine(instance);

View File

@ -189,6 +189,12 @@ bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
furi_assert(session);
furi_assert(istream->bytes_left);
/* TODO FL-3768 this function may be called after
marking the worker for termination */
if(session->terminate) {
return false;
}
uint32_t flags = 0;
size_t bytes_received = 0;

View File

@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,54.0,,
Version,v,54.1,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
@ -1273,6 +1273,7 @@ Function,+,furi_hal_sd_presence_init,void,
Function,+,furi_hal_sd_read_blocks,FuriStatus,"uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_sd_write_blocks,FuriStatus,"const uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_serial_async_rx,uint8_t,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx_available,_Bool,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool"
Function,+,furi_hal_serial_async_rx_stop,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_control_acquire,FuriHalSerialHandle*,FuriHalSerialId

1 entry status name type params
2 Version + v 54.0 54.1
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
1273 Function + furi_hal_sd_read_blocks FuriStatus uint32_t*, uint32_t, uint32_t
1274 Function + furi_hal_sd_write_blocks FuriStatus const uint32_t*, uint32_t, uint32_t
1275 Function + furi_hal_serial_async_rx uint8_t FuriHalSerialHandle*
1276 Function + furi_hal_serial_async_rx_available _Bool FuriHalSerialHandle*
1277 Function + furi_hal_serial_async_rx_start void FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool
1278 Function + furi_hal_serial_async_rx_stop void FuriHalSerialHandle*
1279 Function + furi_hal_serial_control_acquire FuriHalSerialHandle* FuriHalSerialId

View File

@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,54.0,,
Version,+,54.1,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
@ -1439,6 +1439,7 @@ Function,+,furi_hal_sd_presence_init,void,
Function,+,furi_hal_sd_read_blocks,FuriStatus,"uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_sd_write_blocks,FuriStatus,"const uint32_t*, uint32_t, uint32_t"
Function,+,furi_hal_serial_async_rx,uint8_t,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx_available,_Bool,FuriHalSerialHandle*
Function,+,furi_hal_serial_async_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool"
Function,+,furi_hal_serial_async_rx_stop,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_control_acquire,FuriHalSerialHandle*,FuriHalSerialId

1 entry status name type params
2 Version + 54.0 54.1
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/cli/cli.h
1439 Function + furi_hal_sd_read_blocks FuriStatus uint32_t*, uint32_t, uint32_t
1440 Function + furi_hal_sd_write_blocks FuriStatus const uint32_t*, uint32_t, uint32_t
1441 Function + furi_hal_serial_async_rx uint8_t FuriHalSerialHandle*
1442 Function + furi_hal_serial_async_rx_available _Bool FuriHalSerialHandle*
1443 Function + furi_hal_serial_async_rx_start void FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool
1444 Function + furi_hal_serial_async_rx_stop void FuriHalSerialHandle*
1445 Function + furi_hal_serial_control_acquire FuriHalSerialHandle* FuriHalSerialId

View File

@ -782,6 +782,17 @@ void furi_hal_serial_async_rx_stop(FuriHalSerialHandle* handle) {
furi_hal_serial_async_rx_configure(handle, NULL, NULL);
}
bool furi_hal_serial_async_rx_available(FuriHalSerialHandle* handle) {
furi_check(FURI_IS_IRQ_MODE());
furi_assert(handle->id < FuriHalSerialIdMax);
if(handle->id == FuriHalSerialIdUsart) {
return LL_USART_IsActiveFlag_RXNE_RXFNE(USART1);
} else {
return LL_LPUART_IsActiveFlag_RXNE_RXFNE(LPUART1);
}
}
uint8_t furi_hal_serial_async_rx(FuriHalSerialHandle* handle) {
furi_check(FURI_IS_IRQ_MODE());
furi_assert(handle->id < FuriHalSerialIdMax);

View File

@ -130,6 +130,16 @@ void furi_hal_serial_async_rx_start(
*/
void furi_hal_serial_async_rx_stop(FuriHalSerialHandle* handle);
/** Check if there is data available for reading
*
* @warning This function must be called only from the callback
* FuriHalSerialAsyncRxCallback
*
* @param handle Serial handle
* @return true if data is available for reading, false otherwise
*/
bool furi_hal_serial_async_rx_available(FuriHalSerialHandle* handle);
/** Get data Serial receive
*
* @warning This function must be called only from the callback