From bc5da1a15819db5dda029c75d61d82959d80dd8c Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 11 Oct 2023 10:50:09 +0200 Subject: [PATCH] native simulator: Get latest from upstream Align with native_simulator's upstream main d32b2504ad2b6d6d541bc71a0f9b16ab7b6a3831 Which includes: * d32b250 Minor format fix * 7b4f35b native HW counter: Provide new API to reset and control * 4f815cb INT CNTLR: Bugfix for more than 32 interrupts * 1d36254 Provide new 64 version of nsi_find_lsb_set Signed-off-by: Alberto Escolar Piedras --- .../common/src/nsi_internal.h | 17 +++++++++++- .../native_simulator/native/src/hw_counter.c | 27 ++++++++++++++++++- .../native/src/include/hw_counter.h | 3 +++ .../native_simulator/native/src/irq_ctrl.c | 2 +- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/scripts/native_simulator/common/src/nsi_internal.h b/scripts/native_simulator/common/src/nsi_internal.h index 00e6389799..ebe8289b17 100644 --- a/scripts/native_simulator/common/src/nsi_internal.h +++ b/scripts/native_simulator/common/src/nsi_internal.h @@ -14,7 +14,6 @@ extern "C" { #endif /** - * * @brief find least significant bit set in a 32-bit word * * This routine finds the first bit set starting from the least significant bit @@ -30,6 +29,22 @@ static inline unsigned int nsi_find_lsb_set(uint32_t op) return __builtin_ffs(op); } +/** + * @brief find least significant bit set in a 64-bit word + * + * This routine finds the first bit set starting from the least significant bit + * in the argument passed in and returns the index of that bit. Bits are + * numbered starting at 1 from the least significant bit. A return value of + * zero indicates that the value passed is zero. + * + * @return least significant bit set, 0 if @a op is 0 + */ + +static inline unsigned int nsi_find_lsb_set64(uint64_t op) +{ + return __builtin_ffsll(op); +} + #ifdef __cplusplus } #endif diff --git a/scripts/native_simulator/native/src/hw_counter.c b/scripts/native_simulator/native/src/hw_counter.c index fc0770dc6a..2429a57f07 100644 --- a/scripts/native_simulator/native/src/hw_counter.c +++ b/scripts/native_simulator/native/src/hw_counter.c @@ -17,6 +17,7 @@ static bool counter_running; static uint64_t counter_value; static uint64_t counter_target; static uint64_t counter_period; +static uint64_t counter_wrap; /** * Initialize the counter with prescaler of HW @@ -28,6 +29,7 @@ static void hw_counter_init(void) counter_value = 0; counter_running = false; counter_period = NSI_NEVER; + counter_wrap = NSI_NEVER; } NSI_TASK(hw_counter_init, HW_INIT, 10); @@ -40,7 +42,7 @@ static void hw_counter_triggered(void) } hw_counter_timer = nsi_hws_get_time() + counter_period; - counter_value = counter_value + 1; + counter_value = (counter_value + 1) % counter_wrap; if (counter_value == counter_target) { hw_irq_ctrl_set_irq(COUNTER_EVENT_IRQ); @@ -58,6 +60,16 @@ void hw_counter_set_period(uint64_t period) counter_period = period; } +/* + * Set the count value at which the counter will wrap + * The counter will count up to (counter_wrap-1), i.e.: + * 0, 1, 2,.., (counter_wrap - 1), 0 + */ +void hw_counter_set_wrap_value(uint64_t wrap_value) +{ + counter_wrap = wrap_value; +} + /** * Starts the counter. It must be previously configured with * hw_counter_set_period() and hw_counter_set_target(). @@ -86,6 +98,11 @@ void hw_counter_stop(void) nsi_hws_find_next_event(); } +bool hw_counter_is_started(void) +{ + return counter_running; +} + /** * Returns the current counter value. */ @@ -94,6 +111,14 @@ uint64_t hw_counter_get_value(void) return counter_value; } +/** + * Resets the counter value. + */ +void hw_counter_reset(void) +{ + counter_value = 0; +} + /** * Configures the counter to generate an interrupt * when its count value reaches target. diff --git a/scripts/native_simulator/native/src/include/hw_counter.h b/scripts/native_simulator/native/src/include/hw_counter.h index 766aa8e27c..9230f930bd 100644 --- a/scripts/native_simulator/native/src/include/hw_counter.h +++ b/scripts/native_simulator/native/src/include/hw_counter.h @@ -22,9 +22,12 @@ void hw_counter_triggered(void); void hw_counter_set_period(uint64_t period); void hw_counter_set_target(uint64_t counter_target); +void hw_counter_set_wrap_value(uint64_t wrap_value); void hw_counter_start(void); void hw_counter_stop(void); +bool hw_counter_is_started(void); uint64_t hw_counter_get_value(void); +void hw_counter_reset(void); #ifdef __cplusplus } diff --git a/scripts/native_simulator/native/src/irq_ctrl.c b/scripts/native_simulator/native/src/irq_ctrl.c index 40ee28487f..2c187f7767 100644 --- a/scripts/native_simulator/native/src/irq_ctrl.c +++ b/scripts/native_simulator/native/src/irq_ctrl.c @@ -95,7 +95,7 @@ int hw_irq_ctrl_get_highest_prio_irq(void) int winner_prio = 256; while (irq_status != 0U) { - int irq_nbr = nsi_find_lsb_set(irq_status) - 1; + int irq_nbr = nsi_find_lsb_set64(irq_status) - 1; irq_status &= ~((uint64_t) 1 << irq_nbr); if ((winner_prio > (int)irq_prio[irq_nbr])