cc3200: Create wipy module, remove HeartBeat class.

The heartbeat is now controllable via a single function within the
wipy module.
pull/1521/head
danicampora 2015-10-14 09:46:18 +02:00
rodzic 39a380b621
commit d8137178bb
9 zmienionych plików z 79 dodań i 55 usunięć

Wyświetl plik

@ -92,6 +92,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
modusocket.c \
modussl.c \
modutime.c \
modwipy.c \
modwlan.c \
pybadc.c \
pybpin.c \

Wyświetl plik

@ -149,17 +149,13 @@ void mperror_heartbeat_switch_off (void) {
void mperror_heartbeat_signal (void) {
if (mperror_heart_beat.do_disable) {
mperror_heart_beat.do_disable = false;
mperror_heartbeat_switch_off();
mperror_heart_beat.enabled = false;
}
else if (mperror_heart_beat.enabled) {
} else if (mperror_heart_beat.enabled) {
if (!mperror_heart_beat.beating) {
if ((mperror_heart_beat.on_time = HAL_GetTick()) - mperror_heart_beat.off_time > MPERROR_HEARTBEAT_OFF_MS) {
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, MICROPY_SYS_LED_PORT_PIN);
mperror_heart_beat.beating = true;
}
}
else {
} else {
if ((mperror_heart_beat.off_time = HAL_GetTick()) - mperror_heart_beat.on_time > MPERROR_HEARTBEAT_ON_MS) {
MAP_GPIOPinWrite(MICROPY_SYS_LED_PORT, MICROPY_SYS_LED_PORT_PIN, 0);
mperror_heart_beat.beating = false;
@ -199,48 +195,17 @@ void nlr_jump_fail(void *val) {
#endif
}
#ifndef BOOTLOADER
/******************************************************************************/
// Micro Python bindings
/// \classmethod \constructor()
///
/// Return the heart beat object
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) {
// check arguments
mp_arg_check_num(n_args, n_kw, 0, 0, false);
// return constant object
return (mp_obj_t)&pyb_heartbeat_obj;
void mperror_enable_heartbeat (bool enable) {
if (enable) {
mperror_heart_beat.enabled = true;
mperror_heart_beat.do_disable = false;
mperror_heartbeat_switch_off();
} else {
mperror_heart_beat.do_disable = true;
mperror_heart_beat.enabled = false;
}
}
/// \function enable()
/// Enables the heartbeat signal
STATIC mp_obj_t pyb_enable_heartbeat(mp_obj_t self) {
mperror_heart_beat.enabled = true;
return mp_const_none;
bool mperror_is_heartbeat_enabled (void) {
return mperror_heart_beat.enabled;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_enable_heartbeat_obj, pyb_enable_heartbeat);
/// \function disable()
/// Disables the heartbeat signal
STATIC mp_obj_t pyb_disable_heartbeat(mp_obj_t self) {
mperror_heart_beat.do_disable = true;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_disable_heartbeat_obj, pyb_disable_heartbeat);
STATIC const mp_map_elem_t pyb_heartbeat_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pyb_enable_heartbeat_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&pyb_disable_heartbeat_obj },
};
STATIC MP_DEFINE_CONST_DICT(pyb_heartbeat_locals_dict, pyb_heartbeat_locals_dict_table);
const mp_obj_type_t pyb_heartbeat_type = {
{ &mp_type_type },
.name = MP_QSTR_HeartBeat,
.make_new = pyb_heartbeat_make_new,
.locals_dict = (mp_obj_t)&pyb_heartbeat_locals_dict,
};
#endif

Wyświetl plik

@ -40,5 +40,7 @@ void mperror_deinit_sfe_pin (void);
void mperror_signal_error (void);
void mperror_heartbeat_switch_off (void);
void mperror_heartbeat_signal (void);
void mperror_enable_heartbeat (bool enable);
bool mperror_is_heartbeat_enabled (void);
#endif // MPERROR_H_

Wyświetl plik

@ -61,7 +61,6 @@
#include "pybtimer.h"
#include "utils.h"
#include "gccollect.h"
#include "mperror.h"
#ifdef DEBUG
@ -194,7 +193,6 @@ STATIC const mp_map_elem_t machine_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },
// class constants

Wyświetl plik

@ -0,0 +1,32 @@
#include "py/mpconfig.h"
#include MICROPY_HAL_H
#include "py/obj.h"
#include "py/runtime.h"
#include "mperror.h"
/******************************************************************************/
// Micro Python bindings
STATIC mp_obj_t mod_wipy_heartbeat (mp_uint_t n_args, const mp_obj_t *args) {
if (n_args) {
mperror_enable_heartbeat (mp_obj_is_true(args[0]));
return mp_const_none;
} else {
return mp_obj_new_bool(mperror_is_heartbeat_enabled());
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_wipy_heartbeat_obj, 0, 1, mod_wipy_heartbeat);
STATIC const mp_map_elem_t wipy_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_wipy) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_heartbeat), (mp_obj_t)&mod_wipy_heartbeat_obj },
};
STATIC MP_DEFINE_CONST_DICT(wipy_module_globals, wipy_module_globals_table);
const mp_obj_module_t wipy_module = {
.base = { &mp_type_module },
.name = MP_QSTR_wipy,
.globals = (mp_obj_dict_t*)&wipy_module_globals,
};

Wyświetl plik

@ -113,6 +113,7 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t machine_module;
extern const struct _mp_obj_module_t wipy_module;
extern const struct _mp_obj_module_t mp_module_ure;
extern const struct _mp_obj_module_t mp_module_ujson;
extern const struct _mp_obj_module_t mp_module_uos;
@ -125,6 +126,7 @@ extern const struct _mp_obj_module_t mp_module_ussl;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_wipy), (mp_obj_t)&wipy_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_uselect), (mp_obj_t)&mp_module_uselect }, \

Wyświetl plik

@ -55,6 +55,10 @@ Q(WLAN_WAKE)
Q(PIN_WAKE)
Q(RTC_WAKE)
// for wipy module
Q(wipy)
Q(heartbeat)
// entries for sys.path
Q(/flash)
Q(/flash/lib)
@ -315,11 +319,6 @@ Q(WDT)
Q(feed)
Q(timeout)
// for HeartBeat class
Q(HeartBeat)
Q(enable)
Q(disable)
// for irq class
Q(irq)
Q(init)

Wyświetl plik

@ -0,0 +1,21 @@
'''
wipy module test for the CC3200 based boards
'''
import os
import wipy
mch = os.uname().machine
if not 'LaunchPad' in mch and not'WiPy' in mch:
raise Exception('Board not supported!')
print(wipy.heartbeat() == True)
wipy.heartbeat(False)
print(wipy.heartbeat() == False)
wipy.heartbeat(True)
print(wipy.heartbeat() == True)
try:
wipy.heartbeat(True, 1)
except:
print('Exception')

Wyświetl plik

@ -0,0 +1,4 @@
True
True
True
Exception