summaryrefslogtreecommitdiff
path: root/ports/nrf/bluetooth
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-02-21 00:19:31 -0500
committerDan Halbert <halbert@halwitz.org>2019-02-21 00:19:31 -0500
commit99da3b9646c22ee8232b0b238ffcaf74b250333f (patch)
tree8c6e31437d82d3d5b56a953c072b7a5528d48546 /ports/nrf/bluetooth
parent4e75aaecd07ea954aeba5dda59ed3d1b37bfc17d (diff)
Use critical section, not lock, in CharacteristicBuffer; use a root pointer for ble_drv list
Diffstat (limited to 'ports/nrf/bluetooth')
-rw-r--r--ports/nrf/bluetooth/ble_drv.c25
-rw-r--r--ports/nrf/bluetooth/ble_drv.h6
2 files changed, 15 insertions, 16 deletions
diff --git a/ports/nrf/bluetooth/ble_drv.c b/ports/nrf/bluetooth/ble_drv.c
index 4e7523691..bb395ce4c 100644
--- a/ports/nrf/bluetooth/ble_drv.c
+++ b/ports/nrf/bluetooth/ble_drv.c
@@ -35,27 +35,20 @@
#include "nrf_soc.h"
#include "nrfx_power.h"
#include "py/misc.h"
+#include "py/mpstate.h"
nrf_nvic_state_t nrf_nvic_state = { 0 };
__attribute__((aligned(4)))
static uint8_t m_ble_evt_buf[sizeof(ble_evt_t) + (BLE_GATT_ATT_MTU_DEFAULT)];
-typedef struct event_handler {
- struct event_handler *next;
- void *param;
- ble_drv_evt_handler_t func;
-} event_handler_t;
-
-static event_handler_t *m_event_handlers = NULL;
-
void ble_drv_reset() {
// Linked list items will be gc'd.
- m_event_handlers = NULL;
+ MP_STATE_VM(ble_drv_evt_handler_entries) = NULL;
}
void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param) {
- event_handler_t *it = m_event_handlers;
+ ble_drv_evt_handler_entry_t *it = MP_STATE_VM(ble_drv_evt_handler_entries);
while (it != NULL) {
// If event handler and its corresponding param are already on the list, don't add again.
if ((it->func == func) && (it->param == param)) {
@@ -65,17 +58,17 @@ void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param) {
}
// Add a new handler to the front of the list
- event_handler_t *handler = m_new_ll(event_handler_t, 1);
- handler->next = m_event_handlers;
+ ble_drv_evt_handler_entry_t *handler = m_new_ll(ble_drv_evt_handler_entry_t, 1);
+ handler->next = MP_STATE_VM(ble_drv_evt_handler_entries);
handler->param = param;
handler->func = func;
- m_event_handlers = handler;
+ MP_STATE_VM(ble_drv_evt_handler_entries) = handler;
}
void ble_drv_remove_event_handler(ble_drv_evt_handler_t func, void *param) {
- event_handler_t *it = m_event_handlers;
- event_handler_t **prev = &m_event_handlers;
+ ble_drv_evt_handler_entry_t *it = MP_STATE_VM(ble_drv_evt_handler_entries);
+ ble_drv_evt_handler_entry_t **prev = &MP_STATE_VM(ble_drv_evt_handler_entries);
while (it != NULL) {
if ((it->func == func) && (it->param == param)) {
// Splice out the matching handler.
@@ -122,7 +115,7 @@ void SD_EVT_IRQHandler(void) {
break;
}
- event_handler_t *it = m_event_handlers;
+ ble_drv_evt_handler_entry_t *it = MP_STATE_VM(ble_drv_evt_handler_entries);
while (it != NULL) {
it->func((ble_evt_t *)m_ble_evt_buf, it->param);
it = it->next;
diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h
index a6f7b9033..8d3846a7b 100644
--- a/ports/nrf/bluetooth/ble_drv.h
+++ b/ports/nrf/bluetooth/ble_drv.h
@@ -50,6 +50,12 @@
typedef void (*ble_drv_evt_handler_t)(ble_evt_t*, void*);
+typedef struct ble_drv_evt_handler_entry {
+ struct ble_drv_evt_handler_entry *next;
+ void *param;
+ ble_drv_evt_handler_t func;
+} ble_drv_evt_handler_entry_t;
+
void ble_drv_reset(void);
void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param);
void ble_drv_remove_event_handler(ble_drv_evt_handler_t func, void *param);