Skip to content

Commit b2cb75e

Browse files
committed
cc3200: Remove double administration of callback objects.
1 parent 2b8a718 commit b2cb75e

7 files changed

Lines changed: 36 additions & 44 deletions

File tree

cc3200/boards/cc3200_prefix.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
{ \
4444
{ &pin_type }, \
4545
.name = MP_QSTR_ ## p_pin_name, \
46-
.callback = mp_const_none, \
4746
.port = PORT_A ## p_port, \
4847
.type = PIN_TYPE_STD, \
4948
.bit = (p_bit), \

cc3200/misc/mpcallback.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737
#include "mperror.h"
3838

3939

40-
/******************************************************************************
41-
DECLARE PRIVATE FUNCTIONS
42-
******************************************************************************/
43-
STATIC mpcallback_obj_t *mpcallback_find (mp_obj_t parent);
44-
4540
/******************************************************************************
4641
DEFINE PUBLIC DATA
4742
******************************************************************************/
@@ -73,6 +68,17 @@ mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_
7368
return self;
7469
}
7570

71+
mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
72+
for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
73+
// search for the object and then remove it
74+
mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
75+
if (callback_obj->parent == parent) {
76+
return callback_obj;
77+
}
78+
}
79+
return NULL;
80+
}
81+
7682
void mpcallback_remove (const mp_obj_t parent) {
7783
mpcallback_obj_t *callback_obj;
7884
if ((callback_obj = mpcallback_find(parent))) {
@@ -132,20 +138,6 @@ void mpcallback_handler (mp_obj_t self_in) {
132138
}
133139
}
134140

135-
/******************************************************************************
136-
DEFINE PRIVATE FUNCTIONS
137-
******************************************************************************/
138-
STATIC mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
139-
for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
140-
// search for the object and then remove it
141-
mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
142-
if (callback_obj->parent == parent) {
143-
return callback_obj;
144-
}
145-
}
146-
return NULL;
147-
}
148-
149141
/******************************************************************************/
150142
// Micro Python bindings
151143

cc3200/misc/mpcallback.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern const mp_obj_type_t pyb_callback_type;
6262
******************************************************************************/
6363
void mpcallback_init0 (void);
6464
mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_t *methods);
65+
mpcallback_obj_t *mpcallback_find (mp_obj_t parent);
6566
void mpcallback_remove (const mp_obj_t parent);
6667
void mpcallback_handler (mp_obj_t self_in);
6768
uint mpcallback_translate_priority (uint priority);

cc3200/mods/modwlan.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ typedef enum{
7979

8080
typedef struct _wlan_obj_t {
8181
mp_obj_base_t base;
82-
mp_obj_t callback;
8382
SlWlanMode_t mode;
8483
uint32_t status;
8584

@@ -151,7 +150,6 @@ typedef struct _wlan_obj_t {
151150
DECLARE PRIVATE DATA
152151
******************************************************************************/
153152
STATIC wlan_obj_t wlan_obj = {
154-
.callback = mp_const_none,
155153
.mode = -1,
156154
.status = 0,
157155
.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_
646644
}
647645

648646
STATIC void wlan_lpds_callback_enable (mp_obj_t self_in) {
649-
pybsleep_set_wlan_lpds_callback (wlan_obj.callback);
647+
mp_obj_t _callback = mpcallback_find(self_in);
648+
pybsleep_set_wlan_lpds_callback (_callback);
650649
}
651650

652651
STATIC void wlan_lpds_callback_disable (mp_obj_t self_in) {
@@ -922,21 +921,22 @@ STATIC mp_obj_t wlan_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
922921
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
923922

924923
wlan_obj_t *self = pos_args[0];
924+
mp_obj_t _callback = mpcallback_find(self);
925925
// check if any parameters were passed
926-
if (kw_args->used > 0) {
926+
if (kw_args->used > 0 || _callback == mp_const_none) {
927927
// check the power mode
928928
if (args[4].u_int != PYB_PWR_MODE_LPDS) {
929929
// throw an exception since WLAN only supports LPDS mode
930930
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
931931
}
932932

933933
// create the callback
934-
self->callback = mpcallback_new (self, args[1].u_obj, &wlan_cb_methods);
934+
_callback = mpcallback_new (self, args[1].u_obj, &wlan_cb_methods);
935935

936936
// enable network wakeup
937-
pybsleep_set_wlan_lpds_callback (self->callback);
937+
pybsleep_set_wlan_lpds_callback (_callback);
938938
}
939-
return self->callback;
939+
return _callback;
940940
}
941941
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_callback_obj, 1, wlan_callback);
942942

cc3200/mods/pybpin.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ STATIC mp_obj_t pin_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map
616616

617617
pin_obj_t *self = pos_args[0];
618618
// check if any parameters were passed
619-
if (kw_args->used > 0 || self->callback == mp_const_none) {
619+
mp_obj_t _callback = mpcallback_find(self);
620+
if (kw_args->used > 0 || _callback == mp_const_none) {
620621
// convert the priority to the correct value
621622
uint priority = mpcallback_translate_priority (args[2].u_int);
622623
// 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
720721
}
721722

722723
// all checks have passed, now we can create the callback
723-
self->callback = mpcallback_new (self, args[1].u_obj, &pin_cb_methods);
724+
_callback = mpcallback_new (self, args[1].u_obj, &pin_cb_methods);
724725
if (pwrmode & PYB_PWR_MODE_LPDS) {
725-
pybsleep_set_gpio_lpds_callback (self->callback);
726+
pybsleep_set_gpio_lpds_callback (_callback);
726727
}
727728

728729
// enable the interrupt just before leaving
729730
pin_extint_enable(self);
730731
}
731-
return self->callback;
732+
return _callback;
732733

733734
invalid_args:
734735
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
@@ -824,12 +825,13 @@ STATIC void GPIOA3IntHandler (void) {
824825

825826
// common interrupt handler
826827
STATIC void EXTI_Handler(uint port) {
827-
pin_obj_t *self;
828828
uint32_t bit = MAP_GPIOIntStatus(port, true);
829-
830829
MAP_GPIOIntClear(port, bit);
831-
if (NULL != (self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit))) {
832-
mpcallback_handler(self->callback);
830+
831+
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
832+
mp_obj_t _callback = mpcallback_find(self);
833+
if (_callback) {
834+
mpcallback_handler(_callback);
833835
}
834836
}
835837

cc3200/mods/pybpin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
typedef struct {
3636
const mp_obj_base_t base;
3737
const qstr name;
38-
mp_obj_t callback;
3938
const uint32_t port;
4039
uint16_t type;
4140
const uint8_t bit;

cc3200/mods/pybrtc.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
DECLARE TYPES
5858
******************************************************************************/
5959
typedef struct {
60-
mp_obj_t callback;
6160
uint32_t alarm_sec;
6261
uint16_t alarm_msec;
6362
uint8_t pwrmode;
@@ -66,7 +65,7 @@ typedef struct {
6665
/******************************************************************************
6766
DECLARE PRIVATE DATA
6867
******************************************************************************/
69-
STATIC pybrtc_data_t pybrtc_data = {.callback = mp_const_none};
68+
STATIC pybrtc_data_t pybrtc_data;
7069
STATIC const mp_cb_methods_t pybrtc_cb_methods;
7170

7271
/******************************************************************************
@@ -159,7 +158,7 @@ mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
159158
return mp_const_none;
160159
}
161160
}
162-
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
161+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime);
163162

164163
/// \method callback(handler, intmode, value, priority, pwrmode)
165164
/// 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
170169
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mpcallback_INIT_NUM_ARGS, mpcallback_init_args, args);
171170

172171
// check if any parameters were passed
173-
if (kw_args->used > 0 || pybrtc_data.callback == mp_const_none) {
172+
mp_obj_t _callback = mpcallback_find((mp_obj_t)&pyb_rtc_obj);
173+
if (kw_args->used > 0 || _callback == mp_const_none) {
174174
uint32_t seconds;
175175
uint16_t mseconds;
176176
// 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
195195
pybrtc_data.alarm_msec = mseconds;
196196
pybrtc_data.pwrmode = args[4].u_int;
197197

198-
// create the callback
199-
pybrtc_data.callback = mpcallback_new ((mp_obj_t)&pyb_rtc_obj, args[1].u_obj, &pybrtc_cb_methods);
198+
// create the new callback
199+
_callback = mpcallback_new ((mp_obj_t)&pyb_rtc_obj, args[1].u_obj, &pybrtc_cb_methods);
200200
}
201-
202-
return pybrtc_data.callback;
201+
return _callback;
203202
}
204203
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_callback_obj, 1, pyb_rtc_callback);
205204

0 commit comments

Comments
 (0)