Skip to content

Commit

Permalink
nrf/blue: Remove systick.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl authored and andrewleech committed Mar 31, 2024
1 parent 4c0ee29 commit b765e19
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
1 change: 1 addition & 0 deletions ports/nrf/mpbthciport.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void mp_bluetooth_hci_init(void) {
0,
mp_bluetooth_hci_soft_timer_callback
);
mp_bluetooth_hci_poll_now();
}

void mp_bluetooth_hci_deinit(void) {
Expand Down
4 changes: 1 addition & 3 deletions ports/nrf/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ long unsigned int rng_generate_random_word(void);
// to know the machine-specific values, see irq.h.

#include <nrf.h>
// #include "nrfx_glue.h"

static inline void enable_irq(mp_uint_t state) {
__set_PRIMASK(state);
Expand All @@ -384,9 +385,6 @@ static inline mp_uint_t disable_irq(void) {
return state;
}

#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)

#endif

// Additional entries for use with pendsv_schedule_dispatch.
Expand Down
10 changes: 0 additions & 10 deletions ports/nrf/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@
#include "nrf_clock.h"
#endif


// void SysTick_Handler(void) {
// uint32_t next_tick = uwTick + 1;
// uwTick = next_tick;

// if (soft_timer_next == next_tick) {
// pendsv_schedule_dispatch(PENDSV_DISPATCH_SOFT_TIMER, soft_timer_handler);
// }
// }

#if MICROPY_PY_TIME_TICKS

// Use RTC1 for time ticks generation (ms and us) with 32kHz tick resolution
Expand Down
6 changes: 4 additions & 2 deletions ports/nrf/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "pin.h"
#include "nrf_gpio.h"
#include "nrfx_config.h"
#include "nrfx_glue.h"

typedef enum
{
Expand Down Expand Up @@ -61,12 +62,13 @@ const char *nrfx_error_code_lookup(uint32_t err_code);

static inline uint32_t raise_irq_pri(uint32_t pri) {
(void)pri;
return 0;
return NRFX_CRITICAL_SECTION_ENTER();
}

static inline void restore_irq_pri(uint32_t basepri) {
(void)basepri;
NRFX_CRITICAL_SECTION_EXIT(basepri);
}

#define IRQ_PRI_PENDSV ((1 << __NVIC_PRIO_BITS) - 1)

#else
Expand Down
2 changes: 1 addition & 1 deletion ports/nrf/mpnimbleport.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void mp_bluetooth_hci_controller_init(void) {
ble_ll_hci_send_noop();

// Start polling for date.
mp_bluetooth_hci_poll_now();
mp_bluetooth_hci_init();
}

void mp_bluetooth_hci_controller_deinit(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/nrf/nrfx_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
// #define NRFX_IRQ_IS_ENABLED 1
#define NRFX_POWER_ENABLED 1
#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 2
#define NRFX_SYSTICK_ENABLED 1
#endif

#define NRFX_SYSTICK_ENABLED 1

#define NRFX_GPIOTE_ENABLED 1
#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
#if NRF51
Expand Down
38 changes: 30 additions & 8 deletions ports/nrf/nrfx_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ void mp_hal_delay_us(mp_uint_t us);
#define NRFX_IRQ_PENDING_CLEAR(irq_number) sd_nvic_ClearPendingIRQ(irq_number)
#endif

#define NRFX_CRITICAL_SECTION_ENTER() \
{ \
uint8_t _is_nested_critical_region; \
sd_nvic_critical_region_enter(&_is_nested_critical_region);
#define MICROPY_BEGIN_ATOMIC_SECTION() MICROPY_BEGIN_ATOMIC_SECTION()
#define MICROPY_END_ATOMIC_SECTION(state) MICROPY_END_ATOMIC_SECTION(state)

#define NRFX_CRITICAL_SECTION_EXIT() \
sd_nvic_critical_region_exit(_is_nested_critical_region); \

static inline uint8_t MICROPY_BEGIN_ATOMIC_SECTION() {
uint8_t _is_nested_critical_region;
sd_nvic_critical_region_enter(&_is_nested_critical_region);
return _is_nested_critical_region;
}

static inline void MICROPY_END_ATOMIC_SECTION(uint8_t _is_nested_critical_region) {
sd_nvic_critical_region_exit(_is_nested_critical_region);
}

#else // BLUETOOTH_SD
Expand All @@ -142,11 +147,28 @@ void mp_hal_delay_us(mp_uint_t us);

// Source:
// https://devzone.nordicsemi.com/f/nordic-q-a/8572/disable-interrupts-and-enable-interrupts-if-they-where-enabled/31347#31347
#define NRFX_CRITICAL_SECTION_ENTER() { int _old_primask = __get_PRIMASK(); __disable_irq();
#define NRFX_CRITICAL_SECTION_EXIT() __set_PRIMASK(_old_primask); }
static inline uint8_t MICROPY_BEGIN_ATOMIC_SECTION() {
int _old_primask = __get_PRIMASK();
__disable_irq();
return _old_primask;
}
static inline void MICROPY_END_ATOMIC_SECTION(uint8_t _old_primask) {
__set_PRIMASK(_old_primask);
}

#endif // !BLUETOOTH_SD

/**
* @brief Macro for entering into a critical section.
*/
#define NRFX_CRITICAL_SECTION_ENTER() { uint8_t __state = MICROPY_BEGIN_ATOMIC_SECTION();

/**
* @brief Macro for exiting from a critical section.
*/
#define NRFX_CRITICAL_SECTION_EXIT() MICROPY_END_ATOMIC_SECTION(__state); }

// ------------------------------------------------------------------------------
#define NRFX_IRQ_IS_ENABLED(irq_number) (0 != (NVIC->ISER[irq_number / 32] & (1UL << (irq_number % 32))))

#endif // NRFX_GLUE_H

0 comments on commit b765e19

Please sign in to comment.