Skip to content

Commit d813717

Browse files
author
danicampora
committed
cc3200: Create wipy module, remove HeartBeat class.
The heartbeat is now controllable via a single function within the wipy module.
1 parent 39a380b commit d813717

File tree

9 files changed

+79
-55
lines changed

9 files changed

+79
-55
lines changed

cc3200/application.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
9292
modusocket.c \
9393
modussl.c \
9494
modutime.c \
95+
modwipy.c \
9596
modwlan.c \
9697
pybadc.c \
9798
pybpin.c \

cc3200/misc/mperror.c

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,13 @@ void mperror_heartbeat_switch_off (void) {
149149
void mperror_heartbeat_signal (void) {
150150
if (mperror_heart_beat.do_disable) {
151151
mperror_heart_beat.do_disable = false;
152-
mperror_heartbeat_switch_off();
153-
mperror_heart_beat.enabled = false;
154-
}
155-
else if (mperror_heart_beat.enabled) {
152+
} else if (mperror_heart_beat.enabled) {
156153
if (!mperror_heart_beat.beating) {
157154
if ((mperror_heart_beat.on_time = HAL_GetTick()) - mperror_heart_beat.off_time > MPERROR_HEARTBEAT_OFF_MS) {
158155
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, MICROPY_SYS_LED_PORT_PIN);
159156
mperror_heart_beat.beating = true;
160157
}
161-
}
162-
else {
158+
} else {
163159
if ((mperror_heart_beat.off_time = HAL_GetTick()) - mperror_heart_beat.on_time > MPERROR_HEARTBEAT_ON_MS) {
164160
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0);
165161
mperror_heart_beat.beating = false;
@@ -199,48 +195,17 @@ void nlr_jump_fail(void *val) {
199195
#endif
200196
}
201197

202-
#ifndef BOOTLOADER
203-
/******************************************************************************/
204-
// Micro Python bindings
205-
206-
/// \classmethod \constructor()
207-
///
208-
/// Return the heart beat object
209-
STATIC mp_obj_t pyb_heartbeat_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
210-
// check arguments
211-
mp_arg_check_num(n_args, n_kw, 0, 0, false);
212-
213-
// return constant object
214-
return (mp_obj_t)&pyb_heartbeat_obj;
215-
}
216-
217-
/// \function enable()
218-
/// Enables the heartbeat signal
219-
STATIC mp_obj_t pyb_enable_heartbeat(mp_obj_t self) {
220-
mperror_heart_beat.enabled = true;
221-
return mp_const_none;
198+
void mperror_enable_heartbeat (bool enable) {
199+
if (enable) {
200+
mperror_heart_beat.enabled = true;
201+
mperror_heart_beat.do_disable = false;
202+
mperror_heartbeat_switch_off();
203+
} else {
204+
mperror_heart_beat.do_disable = true;
205+
mperror_heart_beat.enabled = false;
206+
}
222207
}
223-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_heartbeat_obj, pyb_enable_heartbeat);
224208

225-
/// \function disable()
226-
/// Disables the heartbeat signal
227-
STATIC mp_obj_t pyb_disable_heartbeat(mp_obj_t self) {
228-
mperror_heart_beat.do_disable = true;
229-
return mp_const_none;
209+
bool mperror_is_heartbeat_enabled (void) {
210+
return mperror_heart_beat.enabled;
230211
}
231-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_disable_heartbeat_obj, pyb_disable_heartbeat);
232-
233-
STATIC const mp_map_elem_t pyb_heartbeat_locals_dict_table[] = {
234-
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pyb_enable_heartbeat_obj },
235-
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&pyb_disable_heartbeat_obj },
236-
};
237-
STATIC MP_DEFINE_CONST_DICT(pyb_heartbeat_locals_dict, pyb_heartbeat_locals_dict_table);
238-
239-
const mp_obj_type_t pyb_heartbeat_type = {
240-
{ &mp_type_type },
241-
.name = MP_QSTR_HeartBeat,
242-
.make_new = pyb_heartbeat_make_new,
243-
.locals_dict = (mp_obj_t)&pyb_heartbeat_locals_dict,
244-
};
245-
246-
#endif

cc3200/misc/mperror.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ void mperror_deinit_sfe_pin (void);
4040
void mperror_signal_error (void);
4141
void mperror_heartbeat_switch_off (void);
4242
void mperror_heartbeat_signal (void);
43+
void mperror_enable_heartbeat (bool enable);
44+
bool mperror_is_heartbeat_enabled (void);
4345

4446
#endif // MPERROR_H_

cc3200/mods/modmachine.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
#include "pybtimer.h"
6262
#include "utils.h"
6363
#include "gccollect.h"
64-
#include "mperror.h"
6564

6665

6766
#ifdef DEBUG
@@ -194,7 +193,6 @@ STATIC const mp_map_elem_t machine_module_globals_table[] = {
194193
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
195194
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
196195
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },
197-
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_type },
198196
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },
199197

200198
// class constants

cc3200/mods/modwipy.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "py/mpconfig.h"
2+
#include MICROPY_HAL_H
3+
#include "py/obj.h"
4+
#include "py/runtime.h"
5+
#include "mperror.h"
6+
7+
8+
/******************************************************************************/
9+
// Micro Python bindings
10+
11+
STATIC mp_obj_t mod_wipy_heartbeat (mp_uint_t n_args, const mp_obj_t *args) {
12+
if (n_args) {
13+
mperror_enable_heartbeat (mp_obj_is_true(args[0]));
14+
return mp_const_none;
15+
} else {
16+
return mp_obj_new_bool(mperror_is_heartbeat_enabled());
17+
}
18+
}
19+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_wipy_heartbeat_obj, 0, 1, mod_wipy_heartbeat);
20+
21+
STATIC const mp_map_elem_t wipy_module_globals_table[] = {
22+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_wipy) },
23+
{ MP_OBJ_NEW_QSTR(MP_QSTR_heartbeat), (mp_obj_t)&mod_wipy_heartbeat_obj },
24+
};
25+
26+
STATIC MP_DEFINE_CONST_DICT(wipy_module_globals, wipy_module_globals_table);
27+
28+
const mp_obj_module_t wipy_module = {
29+
.base = { &mp_type_module },
30+
.name = MP_QSTR_wipy,
31+
.globals = (mp_obj_dict_t*)&wipy_module_globals,
32+
};

cc3200/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
113113

114114
// extra built in modules to add to the list of known ones
115115
extern const struct _mp_obj_module_t machine_module;
116+
extern const struct _mp_obj_module_t wipy_module;
116117
extern const struct _mp_obj_module_t mp_module_ure;
117118
extern const struct _mp_obj_module_t mp_module_ujson;
118119
extern const struct _mp_obj_module_t mp_module_uos;
@@ -125,6 +126,7 @@ extern const struct _mp_obj_module_t mp_module_ussl;
125126

126127
#define MICROPY_PORT_BUILTIN_MODULES \
127128
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
129+
{ MP_OBJ_NEW_QSTR(MP_QSTR_wipy), (mp_obj_t)&wipy_module }, \
128130
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \
129131
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
130132
{ MP_OBJ_NEW_QSTR(MP_QSTR_uselect), (mp_obj_t)&mp_module_uselect }, \

cc3200/qstrdefsport.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Q(WLAN_WAKE)
5555
Q(PIN_WAKE)
5656
Q(RTC_WAKE)
5757

58+
// for wipy module
59+
Q(wipy)
60+
Q(heartbeat)
61+
5862
// entries for sys.path
5963
Q(/flash)
6064
Q(/flash/lib)
@@ -315,11 +319,6 @@ Q(WDT)
315319
Q(feed)
316320
Q(timeout)
317321

318-
// for HeartBeat class
319-
Q(HeartBeat)
320-
Q(enable)
321-
Q(disable)
322-
323322
// for irq class
324323
Q(irq)
325324
Q(init)

tests/wipy/modwipy.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
wipy module test for the CC3200 based boards
3+
'''
4+
5+
import os
6+
import wipy
7+
8+
mch = os.uname().machine
9+
if not 'LaunchPad' in mch and not'WiPy' in mch:
10+
raise Exception('Board not supported!')
11+
12+
print(wipy.heartbeat() == True)
13+
wipy.heartbeat(False)
14+
print(wipy.heartbeat() == False)
15+
wipy.heartbeat(True)
16+
print(wipy.heartbeat() == True)
17+
18+
try:
19+
wipy.heartbeat(True, 1)
20+
except:
21+
print('Exception')

tests/wipy/modwipy.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
True
2+
True
3+
True
4+
Exception

0 commit comments

Comments
 (0)