Skip to content

Commit 0475de1

Browse files
committed
cc3200: Make WDT and HeartBeat constant objects on their own right.
1 parent 55278dc commit 0475de1

8 files changed

Lines changed: 140 additions & 118 deletions

File tree

cc3200/bootmgr/bootloader.mk

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ BOOT_MISC_SRC_C = $(addprefix misc/,\
4444
mperror.c \
4545
)
4646

47-
BOOT_MODS_SRC_C = $(addprefix mods/,\
48-
pybwdt.c \
49-
)
50-
5147
BOOT_SL_SRC_C = $(addprefix simplelink/,\
5248
cc_pal.c \
5349
)
@@ -72,8 +68,8 @@ BOOT_STM_SRC_C = $(addprefix stmhal/,\
7268
string0.c \
7369
)
7470

75-
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))
76-
OBJ += $(addprefix $(BUILD)/, $(BOOT_MISC_SRC_C:.c=.o) $(BOOT_MAIN_SRC_C:.c=.o) $(BOOT_MAIN_SRC_S:.s=.o) $(BOOT_PY_SRC_C:.c=.o) $(BOOT_STM_SRC_C:.c=.o))
71+
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_MISC_SRC_C:.c=.o))
72+
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))
7773

7874
# Add the linker script
7975
LINKER_SCRIPT = bootmgr/bootmgr.lds

cc3200/bootmgr/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include "utils.h"
5252
#include "cc3200_hal.h"
5353
#include "debug.h"
54-
#include "pybwdt.h"
5554
#include "mperror.h"
5655

5756

@@ -149,7 +148,7 @@ static void bootmgr_board_init(void) {
149148
// Mandatory MCU Initialization
150149
PRCMCC3200MCUInit();
151150

152-
pybwdt_check_reset_cause();
151+
mperror_check_reset_cause();
153152

154153
// Enable the Data Hashing Engine
155154
HASH_Init();

cc3200/misc/mperror.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@ void mperror_init0 (void) {
8686
#endif
8787
}
8888

89+
void mperror_check_reset_cause (void) {
90+
// if we are recovering from a WDT reset, trigger
91+
// a hibernate cycle for a clean boot
92+
if (MAP_PRCMSysResetCauseGet() == PRCM_WDT_RESET) {
93+
HWREG(0x400F70B8) = 1;
94+
UtilsDelay(800000/5);
95+
HWREG(0x400F70B0) = 1;
96+
UtilsDelay(800000/5);
97+
98+
HWREG(0x4402E16C) |= 0x2;
99+
UtilsDelay(800);
100+
HWREG(0x4402F024) &= 0xF7FFFFFF;
101+
102+
MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR);
103+
// set the sleep interval to 10ms
104+
MAP_PRCMHibernateIntervalSet(330);
105+
MAP_PRCMHibernateEnter();
106+
}
107+
}
108+
89109
void mperror_deinit_sfe_pin (void) {
90110
// disable the pull-down
91111
MAP_PinConfigSet(MICROPY_SAFE_BOOT_PIN_NUM, PIN_STRENGTH_4MA, PIN_TYPE_STD);
@@ -179,3 +199,38 @@ void nlr_jump_fail(void *val) {
179199
__fatal_error(NULL);
180200
#endif
181201
}
202+
203+
#ifndef BOOTLOADER
204+
/******************************************************************************/
205+
// Micro Python bindings
206+
207+
/// \function enable()
208+
/// Enables the heartbeat signal
209+
STATIC mp_obj_t pyb_enable_heartbeat(mp_obj_t self) {
210+
mperror_enable_heartbeat ();
211+
return mp_const_none;
212+
}
213+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_heartbeat_obj, pyb_enable_heartbeat);
214+
215+
/// \function disable()
216+
/// Disables the heartbeat signal
217+
STATIC mp_obj_t pyb_disable_heartbeat(mp_obj_t self) {
218+
mperror_disable_heartbeat ();
219+
return mp_const_none;
220+
}
221+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_disable_heartbeat_obj, pyb_disable_heartbeat);
222+
223+
STATIC const mp_map_elem_t pyb_heartbeat_locals_dict_table[] = {
224+
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pyb_enable_heartbeat_obj },
225+
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&pyb_disable_heartbeat_obj },
226+
};
227+
STATIC MP_DEFINE_CONST_DICT(pyb_heartbeat_locals_dict, pyb_heartbeat_locals_dict_table);
228+
229+
static const mp_obj_type_t pyb_heartbeat_type = {
230+
{ &mp_type_type },
231+
.name = MP_QSTR_HeartBeat,
232+
.locals_dict = (mp_obj_t)&pyb_heartbeat_locals_dict,
233+
};
234+
235+
const mp_obj_base_t pyb_heartbeat_obj = {&pyb_heartbeat_type};
236+
#endif

cc3200/misc/mperror.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@
2828
#ifndef MPERROR_H_
2929
#define MPERROR_H_
3030

31+
#ifndef BOOTLOADER
32+
extern const mp_obj_base_t pyb_heartbeat_obj;
33+
#endif
34+
3135
extern void NORETURN __fatal_error(const char *msg);
3236

3337
void mperror_init0 (void);
38+
void mperror_check_reset_cause (void);
3439
void mperror_deinit_sfe_pin (void);
3540
void mperror_signal_error (void);
3641
void mperror_request_safe_boot (void);

cc3200/mods/modpyb.c

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -271,46 +271,6 @@ STATIC mp_obj_t pyb_mkdisk(mp_obj_t path_o) {
271271
}
272272
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_mkdisk_obj, pyb_mkdisk);
273273

274-
/// \function wdt_enable('msec')
275-
/// Enabled the watchdog timer with msec timeout value
276-
STATIC mp_obj_t pyb_enable_wdt(mp_obj_t msec_in) {
277-
mp_int_t msec = mp_obj_get_int(msec_in);
278-
pybwdt_ret_code_t ret;
279-
ret = pybwdt_enable (msec);
280-
if (ret == E_PYBWDT_IS_RUNNING) {
281-
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));
282-
}
283-
else if (ret == E_PYBWDT_INVALID_TIMEOUT) {
284-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
285-
}
286-
return mp_const_none;
287-
}
288-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_wdt_obj, pyb_enable_wdt);
289-
290-
/// \function wdt_kick()
291-
/// Kicks the watchdog timer
292-
STATIC mp_obj_t pyb_kick_wdt(void) {
293-
pybwdt_kick ();
294-
return mp_const_none;
295-
}
296-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_kick_wdt_obj, pyb_kick_wdt);
297-
298-
/// \function enable_heartbeat()
299-
/// Enables the heartbeat signal
300-
STATIC mp_obj_t pyb_enable_heartbeat(void) {
301-
mperror_enable_heartbeat ();
302-
return mp_const_none;
303-
}
304-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_enable_heartbeat_obj, pyb_enable_heartbeat);
305-
306-
/// \function disable_heartbeat()
307-
/// Disables the heartbeat signal
308-
STATIC mp_obj_t pyb_disable_heartbeat(void) {
309-
mperror_disable_heartbeat ();
310-
return mp_const_none;
311-
}
312-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_heartbeat_obj, pyb_disable_heartbeat);
313-
314274
MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c
315275

316276
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
@@ -342,10 +302,6 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
342302
{ MP_OBJ_NEW_QSTR(MP_QSTR_udelay), (mp_obj_t)&pyb_udelay_obj },
343303
{ MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj },
344304
{ MP_OBJ_NEW_QSTR(MP_QSTR_mkdisk), (mp_obj_t)&pyb_mkdisk_obj },
345-
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_wdt), (mp_obj_t)&pyb_enable_wdt_obj },
346-
{ MP_OBJ_NEW_QSTR(MP_QSTR_kick_wdt), (mp_obj_t)&pyb_kick_wdt_obj },
347-
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_heartbeat), (mp_obj_t)&pyb_enable_heartbeat_obj },
348-
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_heartbeat), (mp_obj_t)&pyb_disable_heartbeat_obj },
349305

350306
#if MICROPY_HW_ENABLE_RNG
351307
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj },
@@ -360,6 +316,8 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
360316
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
361317
{ MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type },
362318
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
319+
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_obj },
320+
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_obj },
363321

364322
#if MICROPY_HW_HAS_SDCARD
365323
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },

cc3200/mods/pybwdt.c

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "prcm.h"
4040
#include "utils.h"
4141
#include "pybwdt.h"
42+
#include "mpexception.h"
43+
#include "mperror.h"
4244

4345

4446
/******************************************************************************
@@ -65,59 +67,11 @@ static pybwdt_data_t pybwdt_data;
6567
DEFINE PUBLIC FUNCTIONS
6668
******************************************************************************/
6769
// must be called in main.c just after initializing the hal
70+
__attribute__ ((section (".boot")))
6871
void pybwdt_init0 (void) {
6972
pybwdt_data.running = false;
7073
}
7174

72-
void pybwdt_check_reset_cause (void) {
73-
// if we are recovering from a WDT reset, trigger
74-
// a hibernate cycle for a clean boot
75-
if (MAP_PRCMSysResetCauseGet() == PRCM_WDT_RESET) {
76-
HWREG(0x400F70B8) = 1;
77-
UtilsDelay(800000/5);
78-
HWREG(0x400F70B0) = 1;
79-
UtilsDelay(800000/5);
80-
81-
HWREG(0x4402E16C) |= 0x2;
82-
UtilsDelay(800);
83-
HWREG(0x4402F024) &= 0xF7FFFFFF;
84-
85-
MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR);
86-
// set the sleep interval to 10ms
87-
MAP_PRCMHibernateIntervalSet(330);
88-
MAP_PRCMHibernateEnter();
89-
}
90-
}
91-
92-
// minimum timeout value is 500ms
93-
pybwdt_ret_code_t pybwdt_enable (uint32_t timeout) {
94-
if (timeout >= PYBWDT_MIN_TIMEOUT_MS) {
95-
if (!pybwdt_data.running) {
96-
// Enable the WDT peripheral clock
97-
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
98-
99-
// Unlock to be able to configure the registers
100-
MAP_WatchdogUnlock(WDT_BASE);
101-
102-
// Make the WDT stall when the debugger stops on a breakpoint
103-
MAP_WatchdogStallEnable (WDT_BASE);
104-
105-
// Set the watchdog timer reload value
106-
// the WDT trigger a system reset after the second timeout
107-
// so, divide by the 2 timeout value received
108-
MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(timeout / 2));
109-
110-
// Start the timer. Once the timer is started, it cannot be disabled.
111-
MAP_WatchdogEnable(WDT_BASE);
112-
pybwdt_data.running = true;
113-
114-
return E_PYBWDT_OK;
115-
}
116-
return E_PYBWDT_IS_RUNNING;
117-
}
118-
return E_PYBWDT_INVALID_TIMEOUT;
119-
}
120-
12175
void pybwdt_kick (void) {
12276
// check that the servers and simplelink are running fine
12377
if (pybwdt_data.servers && pybwdt_data.simplelink && pybwdt_data.running) {
@@ -134,3 +88,62 @@ void pybwdt_srv_alive (void) {
13488
void pybwdt_sl_alive (void) {
13589
pybwdt_data.simplelink = true;
13690
}
91+
92+
/******************************************************************************/
93+
// Micro Python bindings
94+
95+
/// \function wdt_enable('msec')
96+
/// Enabled the watchdog timer with msec timeout value
97+
STATIC mp_obj_t pyb_enable_wdt(mp_obj_t self, mp_obj_t msec_in) {
98+
mp_int_t msec = mp_obj_get_int(msec_in);
99+
100+
if (msec < PYBWDT_MIN_TIMEOUT_MS) {
101+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
102+
}
103+
if (pybwdt_data.running) {
104+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));
105+
}
106+
107+
// Enable the WDT peripheral clock
108+
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
109+
110+
// Unlock to be able to configure the registers
111+
MAP_WatchdogUnlock(WDT_BASE);
112+
113+
// make the WDT stall when the debugger stops on a breakpoint
114+
MAP_WatchdogStallEnable (WDT_BASE);
115+
116+
// set the watchdog timer reload value
117+
// the WDT trigger a system reset after the second timeout
118+
// so, divide by the 2 timeout value received
119+
MAP_WatchdogReloadSet(WDT_BASE, PYBWDT_MILLISECONDS_TO_TICKS(msec / 2));
120+
121+
// start the timer. Once wdt is started, it cannot be disabled.
122+
MAP_WatchdogEnable(WDT_BASE);
123+
pybwdt_data.running = true;
124+
125+
return mp_const_none;
126+
}
127+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_enable_wdt_obj, pyb_enable_wdt);
128+
129+
/// \function wdt_kick()
130+
/// Kicks the watchdog timer
131+
STATIC mp_obj_t pyb_kick_wdt(mp_obj_t self) {
132+
pybwdt_kick ();
133+
return mp_const_none;
134+
}
135+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_kick_wdt_obj, pyb_kick_wdt);
136+
137+
STATIC const mp_map_elem_t pybwdt_locals_dict_table[] = {
138+
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pyb_enable_wdt_obj },
139+
{ MP_OBJ_NEW_QSTR(MP_QSTR_kick), (mp_obj_t)&pyb_kick_wdt_obj },
140+
};
141+
STATIC MP_DEFINE_CONST_DICT(pybwdt_locals_dict, pybwdt_locals_dict_table);
142+
143+
static const mp_obj_type_t pybwdt_type = {
144+
{ &mp_type_type },
145+
.name = MP_QSTR_WDT,
146+
.locals_dict = (mp_obj_t)&pybwdt_locals_dict,
147+
};
148+
149+
const mp_obj_base_t pyb_wdt_obj = {&pybwdt_type};

cc3200/mods/pybwdt.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@
2727
#ifndef PYBWDT_H_
2828
#define PYBWDT_H_
2929

30-
typedef enum {
31-
E_PYBWDT_OK = 0,
32-
E_PYBWDT_IS_RUNNING = -1,
33-
E_PYBWDT_INVALID_TIMEOUT = -2
34-
}pybwdt_ret_code_t;
30+
#include "py/obj.h"
31+
32+
extern const mp_obj_base_t pyb_wdt_obj;
3533

3634
void pybwdt_init0 (void);
37-
void pybwdt_check_reset_cause (void);
38-
pybwdt_ret_code_t pybwdt_enable (uint32_t timeout);
3935
void pybwdt_kick (void);
4036
void pybwdt_srv_alive (void);
4137
void pybwdt_sl_alive (void);

cc3200/qstrdefsport.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ Q(udelay)
3636
Q(flush)
3737
Q(FileIO)
3838
Q(mkdisk)
39-
Q(enable_wdt)
40-
Q(kick_wdt)
41-
Q(enable_heartbeat)
42-
Q(disable_heartbeat)
39+
Q(enable)
40+
Q(disable)
4341
// Entries for sys.path
4442
Q(/SFLASH)
4543
Q(/SFLASH/LIB)
@@ -105,8 +103,6 @@ Q(pin)
105103
Q(mode)
106104
Q(pull)
107105
Q(callback)
108-
Q(enable)
109-
Q(disable)
110106
Q(swint)
111107
Q(IRQ_RISING)
112108
Q(IRQ_FALLING)
@@ -159,13 +155,9 @@ Q(SLAVE)
159155
// for ADC class
160156
Q(ADC)
161157
Q(read)
162-
Q(enable)
163-
Q(disable)
164158

165159
// for SD class
166160
Q(SD)
167-
Q(enable)
168-
Q(disable)
169161

170162
// for RTC class
171163
Q(RTC)
@@ -250,3 +242,11 @@ Q(LOW_LATENCY_PM)
250242
Q(LOW_POWER_PM)
251243
Q(ALWAYS_ON_PM)
252244
Q(LONG_SLEEP_PM)
245+
246+
// for WDT class
247+
Q(WDT)
248+
Q(kick)
249+
250+
// for HeartBeat class
251+
Q(HeartBeat)
252+

0 commit comments

Comments
 (0)