cc3200: Remove double administration of callback objects.
This commit is contained in:
parent
2b8a718d73
commit
b2cb75efb7
@ -43,7 +43,6 @@
|
|||||||
{ \
|
{ \
|
||||||
{ &pin_type }, \
|
{ &pin_type }, \
|
||||||
.name = MP_QSTR_ ## p_pin_name, \
|
.name = MP_QSTR_ ## p_pin_name, \
|
||||||
.callback = mp_const_none, \
|
|
||||||
.port = PORT_A ## p_port, \
|
.port = PORT_A ## p_port, \
|
||||||
.type = PIN_TYPE_STD, \
|
.type = PIN_TYPE_STD, \
|
||||||
.bit = (p_bit), \
|
.bit = (p_bit), \
|
||||||
|
@ -37,11 +37,6 @@
|
|||||||
#include "mperror.h"
|
#include "mperror.h"
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
DECLARE PRIVATE FUNCTIONS
|
|
||||||
******************************************************************************/
|
|
||||||
STATIC mpcallback_obj_t *mpcallback_find (mp_obj_t parent);
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
DEFINE PUBLIC DATA
|
DEFINE PUBLIC DATA
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
@ -73,6 +68,17 @@ mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
|
||||||
|
for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
|
||||||
|
// search for the object and then remove it
|
||||||
|
mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
|
||||||
|
if (callback_obj->parent == parent) {
|
||||||
|
return callback_obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void mpcallback_remove (const mp_obj_t parent) {
|
void mpcallback_remove (const mp_obj_t parent) {
|
||||||
mpcallback_obj_t *callback_obj;
|
mpcallback_obj_t *callback_obj;
|
||||||
if ((callback_obj = mpcallback_find(parent))) {
|
if ((callback_obj = mpcallback_find(parent))) {
|
||||||
@ -132,20 +138,6 @@ void mpcallback_handler (mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
DEFINE PRIVATE FUNCTIONS
|
|
||||||
******************************************************************************/
|
|
||||||
STATIC mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
|
|
||||||
for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
|
|
||||||
// search for the object and then remove it
|
|
||||||
mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
|
|
||||||
if (callback_obj->parent == parent) {
|
|
||||||
return callback_obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
// Micro Python bindings
|
// Micro Python bindings
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ extern const mp_obj_type_t pyb_callback_type;
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void mpcallback_init0 (void);
|
void mpcallback_init0 (void);
|
||||||
mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_t *methods);
|
mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_t *methods);
|
||||||
|
mpcallback_obj_t *mpcallback_find (mp_obj_t parent);
|
||||||
void mpcallback_remove (const mp_obj_t parent);
|
void mpcallback_remove (const mp_obj_t parent);
|
||||||
void mpcallback_handler (mp_obj_t self_in);
|
void mpcallback_handler (mp_obj_t self_in);
|
||||||
uint mpcallback_translate_priority (uint priority);
|
uint mpcallback_translate_priority (uint priority);
|
||||||
|
@ -79,7 +79,6 @@ typedef enum{
|
|||||||
|
|
||||||
typedef struct _wlan_obj_t {
|
typedef struct _wlan_obj_t {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
mp_obj_t callback;
|
|
||||||
SlWlanMode_t mode;
|
SlWlanMode_t mode;
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
|
|
||||||
@ -151,7 +150,6 @@ typedef struct _wlan_obj_t {
|
|||||||
DECLARE PRIVATE DATA
|
DECLARE PRIVATE DATA
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
STATIC wlan_obj_t wlan_obj = {
|
STATIC wlan_obj_t wlan_obj = {
|
||||||
.callback = mp_const_none,
|
|
||||||
.mode = -1,
|
.mode = -1,
|
||||||
.status = 0,
|
.status = 0,
|
||||||
.ip = 0,
|
.ip = 0,
|
||||||
@ -646,7 +644,8 @@ STATIC mp_obj_t wlan_init_helper(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC void wlan_lpds_callback_enable (mp_obj_t self_in) {
|
STATIC void wlan_lpds_callback_enable (mp_obj_t self_in) {
|
||||||
pybsleep_set_wlan_lpds_callback (wlan_obj.callback);
|
mp_obj_t _callback = mpcallback_find(self_in);
|
||||||
|
pybsleep_set_wlan_lpds_callback (_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void wlan_lpds_callback_disable (mp_obj_t self_in) {
|
STATIC void wlan_lpds_callback_disable (mp_obj_t self_in) {
|
||||||
@ -922,8 +921,9 @@ STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
|
|||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
|
||||||
|
|
||||||
wlan_obj_t *self = pos_args[0];
|
wlan_obj_t *self = pos_args[0];
|
||||||
|
mp_obj_t _callback = mpcallback_find(self);
|
||||||
// check if any parameters were passed
|
// check if any parameters were passed
|
||||||
if (kw_args->used > 0) {
|
if (kw_args->used > 0 || _callback == mp_const_none) {
|
||||||
// check the power mode
|
// check the power mode
|
||||||
if (args[4].u_int != PYB_PWR_MODE_LPDS) {
|
if (args[4].u_int != PYB_PWR_MODE_LPDS) {
|
||||||
// throw an exception since WLAN only supports LPDS mode
|
// throw an exception since WLAN only supports LPDS mode
|
||||||
@ -931,12 +931,12 @@ STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the callback
|
// create the callback
|
||||||
self->callback = mpcallback_new (self, args[1].u_obj, &wlan_cb_methods);
|
_callback = mpcallback_new (self, args[1].u_obj, &wlan_cb_methods);
|
||||||
|
|
||||||
// enable network wakeup
|
// enable network wakeup
|
||||||
pybsleep_set_wlan_lpds_callback (self->callback);
|
pybsleep_set_wlan_lpds_callback (_callback);
|
||||||
}
|
}
|
||||||
return self->callback;
|
return _callback;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_callback_obj, 1, wlan_callback);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_callback_obj, 1, wlan_callback);
|
||||||
|
|
||||||
|
@ -616,7 +616,8 @@ STATIC mp_obj_t pin_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map
|
|||||||
|
|
||||||
pin_obj_t *self = pos_args[0];
|
pin_obj_t *self = pos_args[0];
|
||||||
// check if any parameters were passed
|
// check if any parameters were passed
|
||||||
if (kw_args->used > 0 || self->callback == mp_const_none) {
|
mp_obj_t _callback = mpcallback_find(self);
|
||||||
|
if (kw_args->used > 0 || _callback == mp_const_none) {
|
||||||
// convert the priority to the correct value
|
// convert the priority to the correct value
|
||||||
uint priority = mpcallback_translate_priority (args[2].u_int);
|
uint priority = mpcallback_translate_priority (args[2].u_int);
|
||||||
// verify the interrupt mode
|
// verify the interrupt mode
|
||||||
@ -720,15 +721,15 @@ STATIC mp_obj_t pin_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map
|
|||||||
}
|
}
|
||||||
|
|
||||||
// all checks have passed, now we can create the callback
|
// all checks have passed, now we can create the callback
|
||||||
self->callback = mpcallback_new (self, args[1].u_obj, &pin_cb_methods);
|
_callback = mpcallback_new (self, args[1].u_obj, &pin_cb_methods);
|
||||||
if (pwrmode & PYB_PWR_MODE_LPDS) {
|
if (pwrmode & PYB_PWR_MODE_LPDS) {
|
||||||
pybsleep_set_gpio_lpds_callback (self->callback);
|
pybsleep_set_gpio_lpds_callback (_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable the interrupt just before leaving
|
// enable the interrupt just before leaving
|
||||||
pin_extint_enable(self);
|
pin_extint_enable(self);
|
||||||
}
|
}
|
||||||
return self->callback;
|
return _callback;
|
||||||
|
|
||||||
invalid_args:
|
invalid_args:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
|
||||||
@ -824,12 +825,13 @@ STATIC void GPIOA3IntHandler (void) {
|
|||||||
|
|
||||||
// common interrupt handler
|
// common interrupt handler
|
||||||
STATIC void EXTI_Handler(uint port) {
|
STATIC void EXTI_Handler(uint port) {
|
||||||
pin_obj_t *self;
|
|
||||||
uint32_t bit = MAP_GPIOIntStatus(port, true);
|
uint32_t bit = MAP_GPIOIntStatus(port, true);
|
||||||
|
|
||||||
MAP_GPIOIntClear(port, bit);
|
MAP_GPIOIntClear(port, bit);
|
||||||
if (NULL != (self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit))) {
|
|
||||||
mpcallback_handler(self->callback);
|
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
|
||||||
|
mp_obj_t _callback = mpcallback_find(self);
|
||||||
|
if (_callback) {
|
||||||
|
mpcallback_handler(_callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
const mp_obj_base_t base;
|
const mp_obj_base_t base;
|
||||||
const qstr name;
|
const qstr name;
|
||||||
mp_obj_t callback;
|
|
||||||
const uint32_t port;
|
const uint32_t port;
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
const uint8_t bit;
|
const uint8_t bit;
|
||||||
|
@ -57,7 +57,6 @@
|
|||||||
DECLARE TYPES
|
DECLARE TYPES
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mp_obj_t callback;
|
|
||||||
uint32_t alarm_sec;
|
uint32_t alarm_sec;
|
||||||
uint16_t alarm_msec;
|
uint16_t alarm_msec;
|
||||||
uint8_t pwrmode;
|
uint8_t pwrmode;
|
||||||
@ -66,7 +65,7 @@ typedef struct {
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
DECLARE PRIVATE DATA
|
DECLARE PRIVATE DATA
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
STATIC pybrtc_data_t pybrtc_data = {.callback = mp_const_none};
|
STATIC pybrtc_data_t pybrtc_data;
|
||||||
STATIC const mp_cb_methods_t pybrtc_cb_methods;
|
STATIC const mp_cb_methods_t pybrtc_cb_methods;
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@ -159,7 +158,7 @@ mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
|
||||||
|
|
||||||
/// \method callback(handler, intmode, value, priority, pwrmode)
|
/// \method callback(handler, intmode, value, priority, pwrmode)
|
||||||
/// Creates a callback object associated with the real time clock
|
/// Creates a callback object associated with the real time clock
|
||||||
@ -170,7 +169,8 @@ STATIC mp_obj_t pyb_rtc_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp
|
|||||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
|
||||||
|
|
||||||
// check if any parameters were passed
|
// check if any parameters were passed
|
||||||
if (kw_args->used > 0 || pybrtc_data.callback == mp_const_none) {
|
mp_obj_t _callback = mpcallback_find((mp_obj_t)&pyb_rtc_obj);
|
||||||
|
if (kw_args->used > 0 || _callback == mp_const_none) {
|
||||||
uint32_t seconds;
|
uint32_t seconds;
|
||||||
uint16_t mseconds;
|
uint16_t mseconds;
|
||||||
// get the seconds and the milliseconds from the RTC
|
// get the seconds and the milliseconds from the RTC
|
||||||
@ -195,11 +195,10 @@ STATIC mp_obj_t pyb_rtc_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp
|
|||||||
pybrtc_data.alarm_msec = mseconds;
|
pybrtc_data.alarm_msec = mseconds;
|
||||||
pybrtc_data.pwrmode = args[4].u_int;
|
pybrtc_data.pwrmode = args[4].u_int;
|
||||||
|
|
||||||
// create the callback
|
// create the new callback
|
||||||
pybrtc_data.callback = mpcallback_new ((mp_obj_t)&pyb_rtc_obj, args[1].u_obj, &pybrtc_cb_methods);
|
_callback = mpcallback_new ((mp_obj_t)&pyb_rtc_obj, args[1].u_obj, &pybrtc_cb_methods);
|
||||||
}
|
}
|
||||||
|
return _callback;
|
||||||
return pybrtc_data.callback;
|
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_callback_obj, 1, pyb_rtc_callback);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_callback_obj, 1, pyb_rtc_callback);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user