From 4d7fba83a6192df95f8728e87d5923b11c29ece6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 22 Jan 2017 10:18:25 +1100 Subject: cc3200: Convert to use builtin help function. --- cc3200/misc/help.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'cc3200/misc') diff --git a/cc3200/misc/help.c b/cc3200/misc/help.c index 4601818bd..cce515898 100644 --- a/cc3200/misc/help.c +++ b/cc3200/misc/help.c @@ -25,23 +25,8 @@ * THE SOFTWARE. */ -#include +#include "py/builtin.h" -#include "lib/utils/pyhelp.h" - -STATIC const char help_text[] = "Welcome to MicroPython!\n" +const char *cc3200_help_text = "Welcome to MicroPython!\n" "For online help please visit http://micropython.org/help/.\n" "For further help on a specific object, type help(obj)\n"; - -STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) { - if (n_args == 0) { - // print a general help message - printf("%s", help_text); - } - else { - // try to print something sensible about the given object - pyhelp_print_obj(args[0]); - } - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, pyb_help); -- cgit v1.2.3 From b7d27e31e8c5d34aaba7e2a7070bb3b6fb082d28 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 6 Feb 2017 11:14:16 +1100 Subject: cc3200: Refactor "ticks" functions to use common extmod implementation. The port now uses the common mp_utime_ticks_{ms,us,cpu,add,diff} functions from extmod/utime_mphal.c. The mp_utime_sleep_XXX functions are still cc3200-specific because they handle the GIL differently to the ones in extmod. The files misc/mpsystick.[ch] have been removed because they contain 2 unused functions, and the other remaining function is renamed to mp_hal_ticks_us and moved to hal/cc3200_hal.c. --- cc3200/application.mk | 1 - cc3200/hal/cc3200_hal.c | 14 +++++++++- cc3200/hal/cc3200_hal.h | 6 +++++ cc3200/misc/mpsystick.c | 71 ------------------------------------------------- cc3200/misc/mpsystick.h | 35 ------------------------ cc3200/mods/modutime.c | 39 +++++---------------------- cc3200/mpconfigport.h | 1 + 7 files changed, 27 insertions(+), 140 deletions(-) delete mode 100644 cc3200/misc/mpsystick.c delete mode 100644 cc3200/misc/mpsystick.h (limited to 'cc3200/misc') diff --git a/cc3200/application.mk b/cc3200/application.mk index 5ee909144..b15dbde7f 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -77,7 +77,6 @@ APP_MISC_SRC_C = $(addprefix misc/,\ mpirq.c \ mperror.c \ mpexception.c \ - mpsystick.c \ ) APP_MODS_SRC_C = $(addprefix mods/,\ diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index 37026db14..5c0e9c30f 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -108,6 +108,19 @@ mp_uint_t mp_hal_ticks_ms(void) { return HAL_tickCount; } +// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge +// to grab a microsecond counter. +mp_uint_t mp_hal_ticks_us(void) { + mp_uint_t irq_state = disable_irq(); + uint32_t counter = SysTickValueGet(); + uint32_t milliseconds = mp_hal_ticks_ms(); + enable_irq(irq_state); + + uint32_t load = SysTickPeriodGet(); + counter = load - counter; // Convert from decrementing to incrementing + return (milliseconds * 1000) + ((counter * 1000) / load); +} + void mp_hal_delay_ms(mp_uint_t delay) { // only if we are not within interrupt context and interrupts are enabled if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0 && query_irq() == IRQ_STATE_ENABLED) { @@ -211,4 +224,3 @@ static void hal_TickInit (void) { MAP_SysTickEnable(); } #endif - diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h index 9715096b6..fcb85b292 100644 --- a/cc3200/hal/cc3200_hal.h +++ b/cc3200/hal/cc3200_hal.h @@ -30,6 +30,9 @@ #include #include +#include "hal/utils.h" +#include "hal/systick.h" + /****************************************************************************** DEFINE CONSTANTS ******************************************************************************/ @@ -64,4 +67,7 @@ extern void HAL_SystemDeInit (void); extern void HAL_IncrementTick(void); extern void mp_hal_set_interrupt_char (int c); +#define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec)) +#define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet()) + #endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */ diff --git a/cc3200/misc/mpsystick.c b/cc3200/misc/mpsystick.c deleted file mode 100644 index 7c35354e1..000000000 --- a/cc3200/misc/mpsystick.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * Copyright (c) 2015 Daniel Campora - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/mpconfig.h" -#include "py/obj.h" -#include "py/mphal.h" -#include "mpsystick.h" -#include "systick.h" -#include "inc/hw_types.h" -#include "inc/hw_nvic.h" - -#ifdef USE_FREERTOS -#include "FreeRTOS.h" -#include "task.h" -#endif - - -bool sys_tick_has_passed(uint32_t start_tick, uint32_t delay_ms) { - return mp_hal_ticks_ms() - start_tick >= delay_ms; -} - -// waits until at least delay_ms milliseconds have passed from the sampling of -// startTick. Handles overflow properly. Assumes stc was taken from -// mp_hal_ticks_ms() some time before calling this function. -void sys_tick_wait_at_least(uint32_t start_tick, uint32_t delay_ms) { -#ifdef USE_FREERTOS - vTaskDelay (delay_ms / portTICK_PERIOD_MS); -#else - while (!sys_tick_has_passed(start_tick, delay_ms)) { - __WFI(); // enter sleep mode, waiting for interrupt - } -#endif -} - -// The SysTick timer counts down at HAL_FCPU_HZ, so we can use that knowledge -// to grab a microsecond counter. -// We assume that mp_hal_ticks_ms returns milliseconds. -uint32_t sys_tick_get_microseconds(void) { - mp_uint_t irq_state = disable_irq(); - uint32_t counter = SysTickValueGet(); - uint32_t milliseconds = mp_hal_ticks_ms(); - enable_irq(irq_state); - - uint32_t load = SysTickPeriodGet(); - counter = load - counter; // Convert from decrementing to incrementing - return (milliseconds * 1000) + ((counter * 1000) / load); -} diff --git a/cc3200/misc/mpsystick.h b/cc3200/misc/mpsystick.h deleted file mode 100644 index d7ad59461..000000000 --- a/cc3200/misc/mpsystick.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * Copyright (c) 2015 Daniel Campora - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MPSYSTICK_H -#define MPSYSTICK_H - -void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms); -bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms); -uint32_t sys_tick_get_microseconds(void); - -#endif // MPSYSTICK_H diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c index 7ea8df1ef..de1f75012 100644 --- a/cc3200/mods/modutime.c +++ b/cc3200/mods/modutime.c @@ -33,6 +33,7 @@ #include "py/obj.h" #include "py/smallint.h" #include "py/mphal.h" +#include "extmod/utime_mphal.h" #include "timeutils.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" @@ -41,7 +42,6 @@ #include "prcm.h" #include "systick.h" #include "pybrtc.h" -#include "mpsystick.h" #include "mpexception.h" #include "utils.h" @@ -143,38 +143,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_ms_obj, time_sleep_ms); STATIC mp_obj_t time_sleep_us (mp_obj_t usec_in) { mp_int_t usec = mp_obj_get_int(usec_in); if (usec > 0) { - UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec)); + mp_hal_delay_us(usec); } return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_us_obj, time_sleep_us); -STATIC mp_obj_t time_ticks_ms(void) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_ms_obj, time_ticks_ms); - -STATIC mp_obj_t time_ticks_us(void) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - return MP_OBJ_NEW_SMALL_INT(sys_tick_get_microseconds() & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_us_obj, time_ticks_us); - -STATIC mp_obj_t time_ticks_cpu(void) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - return MP_OBJ_NEW_SMALL_INT((SysTickPeriodGet() - SysTickValueGet()) & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(time_ticks_cpu_obj, time_ticks_cpu); - -STATIC mp_obj_t time_ticks_diff(mp_obj_t t0, mp_obj_t t1) { - // We want to "cast" the 32 bit unsigned into a 30-bit small-int - uint32_t start = mp_obj_get_int(t0); - uint32_t end = mp_obj_get_int(t1); - return MP_OBJ_NEW_SMALL_INT((end - start) & MP_SMALL_INT_POSITIVE_MASK); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(time_ticks_diff_obj, time_ticks_diff); - STATIC const mp_map_elem_t time_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) }, @@ -186,10 +160,11 @@ STATIC const mp_map_elem_t time_module_globals_table[] = { // MicroPython additions { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_ms), (mp_obj_t)&time_sleep_ms_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_us), (mp_obj_t)&time_sleep_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&time_ticks_ms_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&time_ticks_us_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&time_ticks_cpu_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&time_ticks_diff_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_ms), (mp_obj_t)&mp_utime_ticks_ms_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_us), (mp_obj_t)&mp_utime_ticks_us_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_cpu), (mp_obj_t)&mp_utime_ticks_cpu_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_add), (mp_obj_t)&mp_utime_ticks_add_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ticks_diff), (mp_obj_t)&mp_utime_ticks_diff_obj }, }; STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 49ea64403..944a6c071 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -116,6 +116,7 @@ #define MICROPY_PY_UHEAPQ (0) #define MICROPY_PY_UHASHLIB (0) #define MICROPY_PY_USELECT (1) +#define MICROPY_PY_UTIME_MP_HAL (1) #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) -- cgit v1.2.3 From 1c35270667dbdafa7a8e16a7b8546add07cc7e00 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 21 Feb 2017 17:26:21 +1100 Subject: cc3200: Remove util/std.h, can just use stdio.h instead. --- cc3200/fatfs/src/drivers/sflash_diskio.c | 2 +- cc3200/ftp/ftp.c | 3 +-- cc3200/misc/mpirq.c | 2 +- cc3200/mods/modwlan.c | 2 +- cc3200/util/std.h | 33 -------------------------------- 5 files changed, 4 insertions(+), 38 deletions(-) delete mode 100644 cc3200/util/std.h (limited to 'cc3200/misc') diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/cc3200/fatfs/src/drivers/sflash_diskio.c index 1cfd41fb7..6a1fc4068 100644 --- a/cc3200/fatfs/src/drivers/sflash_diskio.c +++ b/cc3200/fatfs/src/drivers/sflash_diskio.c @@ -1,6 +1,6 @@ #include #include -#include "std.h" +#include #include "py/mpconfig.h" #include "py/obj.h" diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index 9dbc7ca33..22035d6b3 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -25,8 +25,7 @@ */ #include -#include -#include "std.h" +#include #include "py/mpstate.h" #include "py/obj.h" diff --git a/cc3200/misc/mpirq.c b/cc3200/misc/mpirq.c index be5746759..37149089f 100644 --- a/cc3200/misc/mpirq.c +++ b/cc3200/misc/mpirq.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "std.h" +#include #include "py/mpconfig.h" #include "py/obj.h" diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 3a2b869b1..0235502cf 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -26,7 +26,7 @@ #include #include -#include "std.h" +#include #include "simplelink.h" #include "py/mpconfig.h" diff --git a/cc3200/util/std.h b/cc3200/util/std.h deleted file mode 100644 index 6adcb9463..000000000 --- a/cc3200/util/std.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -// This file is needed because in some cases we can't include stdio.h, -// because the CC3100 socket driver has name clashes with it. - -typedef unsigned int size_t; - -int printf(const char *fmt, ...); -int snprintf(char *str, size_t size, const char *fmt, ...); -- cgit v1.2.3 From 22a6344ebe032e9e66024614ecbe7d9608fa9288 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Feb 2017 12:36:23 +1100 Subject: cc3200: When raising OSError's use MP_Exxx as arg instead of a string. --- cc3200/misc/mpexception.c | 3 --- cc3200/misc/mpexception.h | 3 --- cc3200/mods/modnetwork.c | 3 ++- cc3200/mods/moduhashlib.c | 4 ++-- cc3200/mods/modwlan.c | 14 +++++++------- cc3200/mods/pybadc.c | 9 +++++---- cc3200/mods/pybi2c.c | 13 +++++++------ cc3200/mods/pybrtc.c | 9 +++++---- cc3200/mods/pybsd.c | 5 +++-- cc3200/mods/pybspi.c | 5 +++-- cc3200/mods/pybtimer.c | 5 +++-- cc3200/mods/pybuart.c | 6 +++--- cc3200/mods/pybwdt.c | 5 +++-- 13 files changed, 43 insertions(+), 41 deletions(-) (limited to 'cc3200/misc') diff --git a/cc3200/misc/mpexception.c b/cc3200/misc/mpexception.c index c45f0244b..068adb70b 100644 --- a/cc3200/misc/mpexception.c +++ b/cc3200/misc/mpexception.c @@ -40,9 +40,6 @@ STATIC void mpexception_set_user_interrupt (int chr, void *data); /****************************************************************************** DECLARE EXPORTED DATA ******************************************************************************/ -const char mpexception_os_resource_not_avaliable[] = "resource not available"; -const char mpexception_os_operation_failed[] = "the requested operation failed"; -const char mpexception_os_request_not_possible[] = "the requested operation is not possible"; const char mpexception_value_invalid_arguments[] = "invalid argument(s) value"; const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type"; const char mpexception_uncaught[] = "uncaught exception"; diff --git a/cc3200/misc/mpexception.h b/cc3200/misc/mpexception.h index f55aa739e..2f9d1877c 100644 --- a/cc3200/misc/mpexception.h +++ b/cc3200/misc/mpexception.h @@ -28,9 +28,6 @@ #ifndef MPEXCEPTION_H_ #define MPEXCEPTION_H_ -extern const char mpexception_os_resource_not_avaliable[]; -extern const char mpexception_os_operation_failed[]; -extern const char mpexception_os_request_not_possible[]; extern const char mpexception_value_invalid_arguments[]; extern const char mpexception_num_type_invalid_arguments[]; extern const char mpexception_uncaught[]; diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index c592eced2..d44f75aca 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -29,6 +29,7 @@ #include "py/obj.h" #include "py/nlr.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "modnetwork.h" #include "mpexception.h" @@ -99,7 +100,7 @@ STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args // check the server id if (args[0].u_obj != MP_OBJ_NULL) { if (mp_obj_get_int(args[0].u_obj) != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } } diff --git a/cc3200/mods/moduhashlib.c b/cc3200/mods/moduhashlib.c index c22cc8a06..e1145e4d8 100644 --- a/cc3200/mods/moduhashlib.c +++ b/cc3200/mods/moduhashlib.c @@ -93,7 +93,7 @@ STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) { self->digested = false; } } else { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -106,7 +106,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) { } } else if (self->c_size < self->b_size) { // it's a fixed len block which is still incomplete - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } if (!self->digested) { diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index bec8480d6..2a0d3bf63 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -836,7 +836,7 @@ STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n if (n_args > 1 || n_kw > 0) { // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // start the peripheral wlan_init_helper(self, &args[1]); @@ -860,7 +860,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) { // check for correct wlan mode if (wlan_obj.mode == ROLE_AP) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } Sl_WlanNetworkEntry_t wlanEntry; @@ -914,7 +914,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ // check for the correct wlan mode if (wlan_obj.mode == ROLE_AP) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // parse args @@ -962,7 +962,7 @@ STATIC mp_obj_t wlan_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ modwlan_Status_t status; status = wlan_do_connect (ssid, ssid_len, bssid, auth, key, key_len, timeout); if (status == MODWLAN_ERROR_TIMEOUT) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_ETIMEDOUT); } else if (status == MODWLAN_ERROR_INVALID_PARAMS) { mp_raise_ValueError(mpexception_value_invalid_arguments); } @@ -993,7 +993,7 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma // check the interface id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_EPERM); } // get the configuration @@ -1224,13 +1224,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq); // strcpy(urn, p); // // if (sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, len, (unsigned char *)urn) < 0) { -// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); +// mp_raise_OSError(MP_EIO); // } // } // else { // // get the URN // if (sl_NetAppGet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, &len, (uint8_t *)urn) < 0) { -// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); +// mp_raise_OSError(MP_EIO); // } // return mp_obj_new_str(urn, (len - 1), false); // } diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c index e63bebbd0..696e7650b 100644 --- a/cc3200/mods/pybadc.c +++ b/cc3200/mods/pybadc.c @@ -33,6 +33,7 @@ #include "py/runtime.h" #include "py/binary.h" #include "py/gc.h" +#include "py/mperrno.h" #include "bufhelper.h" #include "inc/hw_types.h" #include "inc/hw_adc.h" @@ -104,7 +105,7 @@ STATIC void pyb_adc_init (pyb_adc_obj_t *self) { STATIC void pyb_adc_check_init(void) { // not initialized if (!pyb_adc_obj.enabled) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -149,7 +150,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // check the number of bits @@ -206,7 +207,7 @@ STATIC mp_obj_t adc_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t if (args[0].u_obj != MP_OBJ_NULL) { ch_id = mp_obj_get_int(args[0].u_obj); if (ch_id >= PYB_ADC_NUM_CHANNELS) { - mp_raise_ValueError(mpexception_os_resource_not_avaliable); + mp_raise_ValueError(mpexception_value_invalid_arguments); } else if (args[1].u_obj != mp_const_none) { uint pin_ch_id = pin_find_peripheral_type (args[1].u_obj, PIN_FN_ADC, 0); if (ch_id != pin_ch_id) { @@ -277,7 +278,7 @@ STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) { // the channel must be enabled if (!self->enabled) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // wait until a new value is available diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index 32451802d..658b2bfcd 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -30,6 +30,7 @@ #include "py/mpstate.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "bufhelper.h" #include "inc/hw_types.h" @@ -144,7 +145,7 @@ STATIC bool pyb_i2c_transaction(uint cmd) { STATIC void pyb_i2c_check_init(pyb_i2c_obj_t *self) { // not initialized if (!self->baudrate) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -256,7 +257,7 @@ STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) { // receive the data if (!pyb_i2c_read(args[0].u_int, (byte *)vstr->buf, vstr->len)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } } @@ -275,7 +276,7 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { if (pyb_i2c_mem_addr_write (i2c_addr, (byte *)&mem_addr, mem_addr_size)) { // Read the specified length of data if (!pyb_i2c_read (i2c_addr, (byte *)vstr->buf, vstr->len)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } } } @@ -341,7 +342,7 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup the object @@ -445,7 +446,7 @@ STATIC mp_obj_t pyb_i2c_writeto(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m // send the data if (!pyb_i2c_write(args[0].u_int, bufinfo.buf, bufinfo.len, args[2].u_bool)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } // return the number of bytes written @@ -514,7 +515,7 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(mp_uint_t n_args, const mp_obj_t *pos_args, return mp_obj_new_int(bufinfo.len); } - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem); diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index 510a9050d..ddc26faf9 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -28,6 +28,7 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" @@ -292,7 +293,7 @@ STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup the object @@ -360,7 +361,7 @@ STATIC mp_obj_t pyb_rtc_alarm (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma // check the alarm id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } uint32_t f_seconds; @@ -395,7 +396,7 @@ STATIC mp_obj_t pyb_rtc_alarm_left (mp_uint_t n_args, const mp_obj_t *args) { // only alarm id 0 is available if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // get the current time @@ -413,7 +414,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc STATIC mp_obj_t pyb_rtc_alarm_cancel (mp_uint_t n_args, const mp_obj_t *args) { // only alarm id 0 is available if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // disable the alarm pyb_rtc_disable_alarm(); diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index 937b8599d..306baea8b 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -27,6 +27,7 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" #include "extmod/vfs_fat.h" @@ -108,7 +109,7 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) pyb_sd_hw_init (self); if (sd_disk_init() != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } // register it with the sleep module @@ -133,7 +134,7 @@ STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup and initialize the object diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index 6fc7ee62d..3cd384266 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -30,6 +30,7 @@ #include "py/mpstate.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "bufhelper.h" #include "inc/hw_types.h" #include "inc/hw_mcspi.h" @@ -131,7 +132,7 @@ STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) { STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) { if (!self->baudrate) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // send and receive the data MAP_SPICSEnable(GSPI_BASE); @@ -234,7 +235,7 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_ // check the peripheral id if (args[0].u_int != 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // setup the object diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c index 0eeb6eefd..d25ac6c2b 100644 --- a/cc3200/mods/pybtimer.c +++ b/cc3200/mods/pybtimer.c @@ -34,6 +34,7 @@ #include "py/nlr.h" #include "py/runtime.h" #include "py/gc.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" @@ -329,7 +330,7 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz // create a new Timer object int32_t timer_idx = mp_obj_get_int(args[0]); if (timer_idx < 0 || timer_idx > (PYBTIMER_NUM_TIMERS - 1)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } pyb_timer_obj_t *tim = &pyb_timer_obj[timer_idx]; @@ -370,7 +371,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp // verify that the timer has been already initialized if (!tim->config) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } if (channel_n != TIMER_A && channel_n != TIMER_B && channel_n != (TIMER_A | TIMER_B)) { // invalid channel diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index f28af9063..bab2b3d22 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -279,7 +279,7 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) { STATIC void uart_check_init(pyb_uart_obj_t *self) { // not initialized if (!self->baudrate) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } } @@ -471,7 +471,7 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size } if (uart_id > PYB_UART_1) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } // get the correct uart instance @@ -619,7 +619,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t // write the data if (!uart_tx_strn(self, buf, size)) { - mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed); + mp_raise_OSError(MP_EIO); } return size; } diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c index b4c847268..76c701ca0 100644 --- a/cc3200/mods/pybwdt.c +++ b/cc3200/mods/pybwdt.c @@ -29,6 +29,7 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" +#include "py/mperrno.h" #include "py/mphal.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" @@ -100,14 +101,14 @@ STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_ mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_wdt_init_args, args); if (args[0].u_obj != mp_const_none && mp_obj_get_int(args[0].u_obj) > 0) { - mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable); + mp_raise_OSError(MP_ENODEV); } uint timeout_ms = args[1].u_int; if (timeout_ms < PYBWDT_MIN_TIMEOUT_MS) { mp_raise_ValueError(mpexception_value_invalid_arguments); } if (pyb_wdt_obj.running) { - mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible); + mp_raise_OSError(MP_EPERM); } // Enable the WDT peripheral clock -- cgit v1.2.3