Skip to content

Commit 11aa6ba

Browse files
committed
cc3200: Add WDT functionality as part of the pyb module.
Also improve pybsd, and make it save it's pin configuration. This is a necessary step towards supporting the CC3200 low power deep sleep (LPDS) mode.
1 parent fe2eb5f commit 11aa6ba

File tree

17 files changed

+361
-150
lines changed

17 files changed

+361
-150
lines changed

cc3200/application.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
9696
pybsd.c \
9797
pybsystick.c \
9898
pybuart.c \
99+
pybwdt.c \
99100
)
100101

101102
APP_CC3100_SRC_C = $(addprefix drivers/cc3100/src/,\

cc3200/bootmgr/bootloader.mk

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ BOOT_INC += -Ibootmgr/sl
55
BOOT_INC += -Ihal
66
BOOT_INC += -Ihal/inc
77
BOOT_INC += -I../drivers/cc3100/inc
8+
BOOT_INC += -Imods
89
BOOT_INC += -Isimplelink
910
BOOT_INC += -Isimplelink/oslib
1011
BOOT_INC += -Iutil
@@ -38,6 +39,10 @@ BOOT_CC3100_SRC_C = $(addprefix drivers/cc3100/,\
3839
src/wlan.c \
3940
)
4041

42+
BOOT_MODS_SRC_C = $(addprefix mods/,\
43+
pybwdt.c \
44+
)
45+
4146
BOOT_SL_SRC_C = $(addprefix simplelink/,\
4247
cc_pal.c \
4348
)
@@ -62,8 +67,8 @@ BOOT_STM_SRC_C = $(addprefix stmhal/,\
6267
string0.c \
6368
)
6469

65-
OBJ = $(addprefix $(BUILD)/, $(BOOT_HAL_SRC_C:.c=.o) $(BOOT_SL_SRC_C:.c=.o) $(BOOT_CC3100_SRC_C:.c=.o) $(BOOT_UTIL_SRC_C:.c=.o) $(BOOT_MAIN_SRC_C:.c=.o))
66-
OBJ += $(addprefix $(BUILD)/, $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o))
70+
OBJ = $(addprefix $(BUILD)/, $(BOOT_HAL_SRC_C:.c=.o) $(BOOT_MODS_SRC_C:.c=.o) $(BOOT_SL_SRC_C:.c=.o) $(BOOT_CC3100_SRC_C:.c=.o) $(BOOT_UTIL_SRC_C:.c=.o))
71+
OBJ += $(addprefix $(BUILD)/, $(BOOT_MAIN_SRC_C:.c=.o) $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o))
6772

6873
# Add the linker script
6974
LINKER_SCRIPT = bootmgr/bootmgr.lds
@@ -72,9 +77,6 @@ LDFLAGS += -T $(LINKER_SCRIPT)
7277
# Add the bootloader specific CFLAGS
7378
CFLAGS += $(BOOT_CPPDEFINES) $(BOOT_INC)
7479

75-
# Optimize for size all sources except for main
76-
77-
7880
# Disable strict aliasing for the simplelink driver
7981
$(BUILD)/drivers/cc3100/src/driver.o: CFLAGS += -fno-strict-aliasing
8082

cc3200/bootmgr/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "utils.h"
5050
#include "cc3200_hal.h"
5151
#include "debug.h"
52+
#include "pybwdt.h"
5253

5354

5455
//*****************************************************************************
@@ -153,6 +154,8 @@ static void bootmgr_board_init(void) {
153154
// Mandatory MCU Initialization
154155
PRCMCC3200MCUInit();
155156

157+
pybwdt_check_reset_cause();
158+
156159
// Enable the Data Hashing Engine
157160
HASH_Init();
158161

cc3200/hal/cc_types.h

Lines changed: 0 additions & 58 deletions
This file was deleted.

cc3200/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include MICROPY_HAL_H
3333
#include "mptask.h"
3434
#include "simplelink.h"
35+
#include "pybwdt.h"
3536
#include "debug.h"
3637

3738
/******************************************************************************
@@ -62,6 +63,9 @@ int main (void) {
6263
// Initialize the clocks and the interrupt system
6364
HAL_SystemInit();
6465

66+
// Start the watchdog
67+
pybwdt_init0();
68+
6569
#ifdef DEBUG
6670
ASSERT (OSI_OK == osi_TaskCreate(TASK_Micropython,
6771
(const signed char *)"MicroPy",

cc3200/misc/FreeRTOSHooks.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "inc/hw_memmap.h"
3535
#include "pybuart.h"
3636
#include "osi.h"
37+
#include "pybwdt.h"
3738

3839

3940
//*****************************************************************************
@@ -45,10 +46,11 @@
4546
//! \return none
4647
//!
4748
//*****************************************************************************
48-
void
49-
vApplicationIdleHook( void)
49+
void vApplicationIdleHook (void)
5050
{
51-
//Handle Idle Hook for Profiling, Power Management etc
51+
// kick the watchdog
52+
pybwdt_kick();
53+
// gate the processor clock to save power
5254
__WFI();
5355
}
5456

@@ -61,7 +63,7 @@ vApplicationIdleHook( void)
6163
//! \return none
6264
//!
6365
//*****************************************************************************
64-
void vApplicationMallocFailedHook()
66+
void vApplicationMallocFailedHook (void)
6567
{
6668
#ifdef DEBUG
6769
// Break into the debugger
@@ -70,9 +72,9 @@ void vApplicationMallocFailedHook()
7072
printf("\nFATAL ERROR: FreeRTOS malloc failed!\n");
7173
#endif
7274

73-
//Handle Memory Allocation Errors
74-
while(1)
75+
for ( ; ; )
7576
{
77+
// TODO: Blink the BLD
7678
}
7779
}
7880

@@ -85,7 +87,7 @@ void vApplicationMallocFailedHook()
8587
//! \return none
8688
//!
8789
//*****************************************************************************
88-
void vApplicationStackOverflowHook( OsiTaskHandle *pxTask, signed char *pcTaskName)
90+
void vApplicationStackOverflowHook (OsiTaskHandle *pxTask, signed char *pcTaskName)
8991
{
9092
#ifdef DEBUG
9193
// Break into the debugger
@@ -94,9 +96,9 @@ void vApplicationStackOverflowHook( OsiTaskHandle *pxTask, signed char *pcTaskNa
9496
printf("\nFATAL ERROR: Application: %s stack overflow!\n", pcTaskName);
9597
#endif
9698

97-
//Handle FreeRTOS Stack Overflow
98-
while(1)
99+
for ( ; ; )
99100
{
101+
// TODO: Blink the BLD
100102
}
101103
}
102104

@@ -109,7 +111,7 @@ void vApplicationStackOverflowHook( OsiTaskHandle *pxTask, signed char *pcTaskNa
109111
//! \return none
110112
//!
111113
//*****************************************************************************
112-
void vApplicationTickHook( void )
114+
void vApplicationTickHook (void)
113115
{
114116
HAL_IncrementTick();
115117
}

cc3200/mods/modpyb.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "pybadc.h"
5959
#include "pybi2c.h"
6060
#include "pybsd.h"
61+
#include "pybwdt.h"
6162
#include "utils.h"
6263
#include "gccollect.h"
6364

@@ -251,7 +252,7 @@ STATIC mp_obj_t pyb_repl_uart(uint n_args, const mp_obj_t *args) {
251252
} else if (mp_obj_get_type(args[0]) == &pyb_uart_type) {
252253
pyb_stdio_uart = args[0];
253254
} else {
254-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_num_type_invalid_arguments));
255+
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, mpexception_num_type_invalid_arguments));
255256
}
256257
return mp_const_none;
257258
}
@@ -269,6 +270,30 @@ STATIC mp_obj_t pyb_mkdisk(mp_obj_t path_o) {
269270
}
270271
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_mkdisk_obj, pyb_mkdisk);
271272

273+
/// \function wdt_enable('msec')
274+
/// Enabled the watchdog timer with msec timeout value
275+
STATIC mp_obj_t pyb_enable_wdt(mp_obj_t msec_in) {
276+
mp_int_t msec = mp_obj_get_int(msec_in);
277+
pybwdt_ret_code_t ret;
278+
ret = pybwdt_enable (msec);
279+
if (ret == E_PYBWDT_IS_RUNNING) {
280+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));
281+
}
282+
else if (ret == E_PYBWDT_INVALID_TIMEOUT) {
283+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
284+
}
285+
return mp_const_none;
286+
}
287+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_wdt_obj, pyb_enable_wdt);
288+
289+
/// \function wdt_kick()
290+
/// Kicks the watchdog timer
291+
STATIC mp_obj_t pyb_kick_wdt(void) {
292+
pybwdt_kick ();
293+
return mp_const_none;
294+
}
295+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_kick_wdt_obj, pyb_kick_wdt);
296+
272297
MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c
273298

274299
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
@@ -300,6 +325,8 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
300325
{ MP_OBJ_NEW_QSTR(MP_QSTR_udelay), (mp_obj_t)&pyb_udelay_obj },
301326
{ MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj },
302327
{ MP_OBJ_NEW_QSTR(MP_QSTR_mkdisk), (mp_obj_t)&pyb_mkdisk_obj },
328+
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_wdt), (mp_obj_t)&pyb_enable_wdt_obj },
329+
{ MP_OBJ_NEW_QSTR(MP_QSTR_kick_wdt), (mp_obj_t)&pyb_kick_wdt_obj },
303330

304331
#if MICROPY_HW_ENABLE_RNG
305332
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj },
@@ -316,7 +343,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
316343
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
317344

318345
#if MICROPY_HW_HAS_SDCARD
319-
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sdcard_obj },
346+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },
320347
#endif
321348
};
322349

cc3200/mods/pybadc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
111111
}
112112

113113
// disable the callback before re-configuring
114-
pyb_obj_adc_t *self = m_new_obj(pyb_obj_adc_t);
114+
pyb_obj_adc_t *self = m_new_obj_with_finaliser(pyb_obj_adc_t);
115115
self->base.type = &pyb_adc_type;
116116
self->channel = channel;
117117
self->num = num;

cc3200/mods/pybi2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
324324
}
325325

326326
// create and setup the object
327-
pyb_i2c_obj_t *self = m_new_obj(pyb_i2c_obj_t);
327+
pyb_i2c_obj_t *self = m_new_obj_with_finaliser(pyb_i2c_obj_t);
328328
self->base.type = &pyb_i2c_type;
329329
self->mode = PYBI2C_MODE_DISABLED;
330330

0 commit comments

Comments
 (0)