Skip to content

Commit 4be4401

Browse files
author
Daniel Campora
committed
cc3200: Reenable active interrupts when waking from suspended mode.
1 parent 0090c71 commit 4be4401

8 files changed

Lines changed: 37 additions & 20 deletions

File tree

cc3200/boards/cc3200_prefix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@
5050
.af = PIN_MODE_0, \
5151
.strength = PIN_STRENGTH_4MA, \
5252
.mode = GPIO_DIR_MODE_IN, \
53-
.used = false \
53+
.isused = false, \
5454
}

cc3200/misc/mpcallback.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_
6262
self->handler = handler;
6363
self->parent = parent;
6464
self->methods = (mp_cb_methods_t *)methods;
65+
self->isenabled = true;
6566
// remove any old callback if present
6667
mpcallback_remove(self->parent);
6768
mp_obj_list_append(&MP_STATE_PORT(mpcallback_obj_list), self);
@@ -79,6 +80,16 @@ mpcallback_obj_t *mpcallback_find (mp_obj_t parent) {
7980
return NULL;
8081
}
8182

83+
void mpcallback_wake_all (void) {
84+
// re-enable all active callback objects one by one
85+
for (mp_uint_t i = 0; i < MP_STATE_PORT(mpcallback_obj_list).len; i++) {
86+
mpcallback_obj_t *callback_obj = ((mpcallback_obj_t *)(MP_STATE_PORT(mpcallback_obj_list).items[i]));
87+
if (callback_obj->isenabled) {
88+
callback_obj->methods->enable(callback_obj->parent);
89+
}
90+
}
91+
}
92+
8293
void mpcallback_remove (const mp_obj_t parent) {
8394
mpcallback_obj_t *callback_obj;
8495
if ((callback_obj = mpcallback_find(parent))) {
@@ -158,6 +169,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(callback_init_obj, 1, callback_init);
158169
STATIC mp_obj_t callback_enable (mp_obj_t self_in) {
159170
mpcallback_obj_t *self = self_in;
160171
self->methods->enable(self->parent);
172+
self->isenabled = true;
161173
return mp_const_none;
162174
}
163175
STATIC MP_DEFINE_CONST_FUN_OBJ_1(callback_enable_obj, callback_enable);
@@ -167,6 +179,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(callback_enable_obj, callback_enable);
167179
STATIC mp_obj_t callback_disable (mp_obj_t self_in) {
168180
mpcallback_obj_t *self = self_in;
169181
self->methods->disable(self->parent);
182+
self->isenabled = false;
170183
return mp_const_none;
171184
}
172185
STATIC MP_DEFINE_CONST_FUN_OBJ_1(callback_disable_obj, callback_disable);

cc3200/misc/mpcallback.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef struct {
4949
mp_obj_t parent;
5050
mp_obj_t handler;
5151
mp_cb_methods_t *methods;
52+
bool isenabled;
5253
} mpcallback_obj_t;
5354

5455
/******************************************************************************
@@ -63,6 +64,7 @@ extern const mp_obj_type_t pyb_callback_type;
6364
void mpcallback_init0 (void);
6465
mp_obj_t mpcallback_new (mp_obj_t parent, mp_obj_t handler, const mp_cb_methods_t *methods);
6566
mpcallback_obj_t *mpcallback_find (mp_obj_t parent);
67+
void mpcallback_wake_all (void);
6668
void mpcallback_remove (const mp_obj_t parent);
6769
void mpcallback_handler (mp_obj_t self_in);
6870
uint mpcallback_translate_priority (uint priority);

cc3200/mods/pybpin.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,10 @@ void pin_verify_af (uint af) {
199199

200200
void pin_config (pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
201201
// configure the pin in analog mode
202-
self->af = af;
203-
self->mode = mode;
204-
self->type = type;
205-
self->strength = strength;
202+
self->af = af, self->mode = mode, self->type = type, self->strength = strength;
206203
pin_obj_configure ((const pin_obj_t *)self);
207204
// mark the pin as used
208-
self->used = true;
205+
self->isused = true;
209206
// register it with the sleep module
210207
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
211208
}

cc3200/mods/pybpin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef struct {
4242
uint8_t af;
4343
uint8_t strength;
4444
uint8_t mode;
45-
bool used;
45+
bool isused;
4646
} pin_obj_t;
4747

4848
extern const mp_obj_type_t pin_type;

cc3200/mods/pybsleep.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@ STATIC NORETURN void pybsleep_suspend_enter (void) {
322322
nvic_reg_store->int_priority[i] = base_reg_addr[i];
323323
}
324324

325+
// switch off the heartbeat led (this makes sure it will blink as soon as we wake up)
326+
mperror_heartbeat_switch_off();
327+
325328
// park the gpio pins
326329
pybsleep_iopark();
327330

328-
// turn-off the heartbeat led
329-
mperror_heartbeat_switch_off();
330-
331331
// store the cpu registers
332332
sleep_store();
333333

@@ -384,12 +384,15 @@ void pybsleep_suspend_exit (void) {
384384
// ungate the clock to the shared spi bus
385385
MAP_PRCMPeripheralClkEnable(PRCM_SSPI, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
386386

387-
// reinitialize simplelink's bus
387+
// reinitialize simplelink's interface
388388
sl_IfOpen (NULL, 0);
389389

390390
// restore the configuration of all active peripherals
391391
pybsleep_obj_wakeup();
392392

393+
// reconfigure all the previously enabled interrupts
394+
mpcallback_wake_all();
395+
393396
// trigger a sw interrupt
394397
MAP_IntPendSet(INT_PRCM);
395398

@@ -450,11 +453,11 @@ STATIC void pybsleep_iopark (void) {
450453
#endif
451454
break;
452455
default:
453-
if (!pin->used) {
454-
// enable the pull-down in unused pins
456+
// enable a weak pull-down if the pin is unused
457+
if (!pin->isused) {
455458
MAP_PinConfigSet(pin->pin_num, pin->strength, PIN_TYPE_STD_PD);
456459
}
457-
// make the pin an input
460+
// make it an input
458461
MAP_PinDirModeSet(pin->pin_num, PIN_DIR_MODE_IN);
459462
break;
460463
}
@@ -610,8 +613,9 @@ STATIC mp_obj_t pyb_sleep_hibernate (mp_obj_t self_in) {
610613
}
611614
}
612615
wlan_stop(SL_STOP_TIMEOUT);
613-
mperror_heartbeat_switch_off();
614616
pybsleep_flash_powerdown();
617+
// must be done just before entering hibernate mode
618+
pybsleep_iopark();
615619
MAP_PRCMHibernateEnter();
616620
return mp_const_none;
617621
}

cc3200/mods/pybuart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ STATIC void pyb_uart_print(void (*print)(void *env, const char *fmt, ...), void
346346
}
347347
}
348348

349-
/// \method init(baudrate, bits=8, parity=None, stop=1, *, timeout=1000, timeout_char=0, read_buf_len=128)
349+
/// \method init(baudrate, bits=8, parity=None, stop=1, *, timeout=1000, timeout_char=0)
350350
///
351351
/// Initialise the UART bus with the given parameters:
352352
///

cc3200/telnet/telnet.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static telnet_data_t telnet_data;
110110
static const char* telnet_welcome_msg = "Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n";
111111
static const char* telnet_request_user = "Login as:";
112112
static const char* telnet_request_password = "Password:";
113-
static const char* telnet_invalid_loggin = "\r\nInvalid credentials, try again\r\n";
113+
static const char* telnet_invalid_loggin = "\r\nInvalid credentials, try again.\r\n";
114114
static const char* telnet_loggin_success = "\r\nLogin succeeded!\r\nType \"help()\" for more information.\r\n";
115115
static const uint8_t telnet_options_user[] = // IAC WONT ECHO IAC WONT SUPPRESS_GO_AHEAD IAC WILL LINEMODE
116116
{ 255, 252, 1, 255, 252, 3, 255, 251, 34 };
@@ -217,10 +217,8 @@ void telnet_run (void) {
217217
break;
218218
case E_TELNET_STE_SUB_LOGGIN_SUCCESS:
219219
if (E_TELNET_RESULT_OK == telnet_send_non_blocking((void *)telnet_loggin_success, strlen(telnet_loggin_success))) {
220-
// clear the current line
220+
// clear the current line and force the prompt
221221
telnet_reset_buffer();
222-
// fake an "enter" key pressed to display the prompt
223-
telnet_data.rxBuffer[telnet_data.rxWindex++] = '\r';
224222
telnet_data.state= E_TELNET_STE_LOGGED_IN;
225223
}
226224
default:
@@ -478,7 +476,10 @@ static void telnet_reset (void) {
478476
}
479477

480478
static void telnet_reset_buffer (void) {
479+
// erase any characters present in the current line
481480
memset (telnet_data.rxBuffer, '\b', TELNET_RX_BUFFER_SIZE / 2);
482481
telnet_data.rxWindex = TELNET_RX_BUFFER_SIZE / 2;
482+
// fake an "enter" key pressed to display the prompt
483+
telnet_data.rxBuffer[telnet_data.rxWindex++] = '\r';
483484
}
484485

0 commit comments

Comments
 (0)