UART: Minor optimization

Minor runtime performance optimization, by reducing by 1 the
number of timers exposed to the top level.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2024-01-16 16:57:15 +01:00
parent afe84c1aae
commit 6b6ae3652c
2 changed files with 33 additions and 14 deletions

View File

@ -92,7 +92,9 @@ static struct uarte_status nhw_uarte_st[NHW_UARTE_TOTAL_INST];
NRF_UARTE_Type NRF_UARTE_regs[NHW_UARTE_TOTAL_INST];
NRF_UART_Type *NRF_UART_regs[NHW_UARTE_TOTAL_INST];
static bs_time_t Timer_UART = TIME_NEVER;
static bs_time_t Timer_UART_common = TIME_NEVER;
static bs_time_t Timer_UART_peri = TIME_NEVER;
extern bs_time_t nhw_Timer_ULoopback;
static void nhw_UARTE_signal_EVENTS_ERROR(unsigned int inst);
static void nhw_UARTE_signal_EVENTS_RXDRDY(unsigned int inst);
@ -191,14 +193,19 @@ void nhw_UARTE_backend_register(uint inst, struct backend_if *backend) {
memcpy(&u_el->backend, backend, sizeof(struct backend_if));
}
void nhw_uarte_update_common_timer(void) {
Timer_UART_common = BS_MIN(Timer_UART_peri, nhw_Timer_ULoopback);
nsi_hws_find_next_event();
}
static void nhw_uarte_update_timer(void) {
Timer_UART = TIME_NEVER;
Timer_UART_peri = TIME_NEVER;
for (int i = 0; i < NHW_UARTE_TOTAL_INST; i++) {
struct uarte_status * u_el = &nhw_uarte_st[i];
bs_time_t smaller = BS_MIN(u_el->Rx_TO_timer, u_el->Tx_byte_done_timer);
Timer_UART = BS_MIN(Timer_UART, smaller);
Timer_UART_peri = BS_MIN(Timer_UART_peri, smaller);
}
nsi_hws_find_next_event();
nhw_uarte_update_common_timer();
}
static bool uart_enabled(uint inst) {
@ -816,7 +823,7 @@ static void nhw_uart_Tx_byte_done_timer_triggered(int inst, struct uarte_status
static void nhw_uart_timer_triggered(void)
{
bs_time_t current_time = Timer_UART;
bs_time_t current_time = Timer_UART_peri;
for (int inst = 0; inst < NHW_UARTE_TOTAL_INST; inst++) {
struct uarte_status *u_el = &nhw_uarte_st[inst];
@ -831,7 +838,19 @@ static void nhw_uart_timer_triggered(void)
nhw_uarte_update_timer();
}
NSI_HW_EVENT(Timer_UART, nhw_uart_timer_triggered, 50);
static void nhw_uart_timer_common_triggered(void)
{
bs_time_t current_time = Timer_UART_common;
if (current_time == nhw_Timer_ULoopback) {
extern void nhw_ublb_timer_triggered(void);
nhw_ublb_timer_triggered();
}
if (current_time == Timer_UART_peri) {
nhw_uart_timer_triggered();
}
}
NSI_HW_EVENT(Timer_UART_common, nhw_uart_timer_common_triggered, 50);
void nhw_UARTE_TASK_FLUSHRX(int inst) {
if (!uarte_enabled(inst)) {

View File

@ -20,7 +20,7 @@
#include "nsi_hw_scheduler.h"
#include "nsi_hws_models_if.h"
static bs_time_t Timer_ULoopback = TIME_NEVER;
bs_time_t nhw_Timer_ULoopback = TIME_NEVER;
struct ublb_st_t {
bool enabled;
@ -29,6 +29,8 @@ struct ublb_st_t {
char rx_byte;
} ublb_st[NHW_UARTE_TOTAL_INST];
void nhw_uarte_update_common_timer(void);
static void nhw_ublb_tx_byte(uint inst, uint8_t data);
static void nhw_ublb_RTS_pin_toggle(uint inst, bool new_level);
@ -76,14 +78,14 @@ static void nhw_ublb_register_cmdline(void) {
NSI_TASK(nhw_ublb_register_cmdline, PRE_BOOT_1, 200);
static void nhw_ublb_update_timer(void) {
Timer_ULoopback = TIME_NEVER;
nhw_Timer_ULoopback = TIME_NEVER;
for (int i = 0; i < NHW_UARTE_TOTAL_INST; i++) {
if (!ublb_st[i].enabled) {
continue;
}
Timer_ULoopback = BS_MIN(ublb_st[i].Timer, Timer_ULoopback);
nhw_Timer_ULoopback = BS_MIN(ublb_st[i].Timer, nhw_Timer_ULoopback);
}
nsi_hws_find_next_event();
nhw_uarte_update_common_timer();
}
static void nhw_ublb_tx_byte(uint inst, uint8_t data) {
@ -103,8 +105,8 @@ static void nhw_ublb_RTS_pin_toggle(uint inst, bool new_level) {
}
}
static void nhw_ublb_timer_triggered(void) {
bs_time_t current_time = Timer_ULoopback;
void nhw_ublb_timer_triggered(void) {
bs_time_t current_time = nhw_Timer_ULoopback;
for (int i = 0; i < NHW_UARTE_TOTAL_INST; i++) {
if (ublb_st[i].Timer == current_time) {
nhw_UARTE_digest_Rx_byte(i, ublb_st[i].rx_byte);
@ -113,5 +115,3 @@ static void nhw_ublb_timer_triggered(void) {
}
nhw_ublb_update_timer();
}
NSI_HW_EVENT(Timer_ULoopback, nhw_ublb_timer_triggered, 40); /* Before the UART itself */