Skip to content

Commit 22a6344

Browse files
committed
cc3200: When raising OSError's use MP_Exxx as arg instead of a string.
1 parent 8bb8e97 commit 22a6344

File tree

13 files changed

+43
-41
lines changed

13 files changed

+43
-41
lines changed

cc3200/misc/mpexception.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ STATIC void mpexception_set_user_interrupt (int chr, void *data);
4040
/******************************************************************************
4141
DECLARE EXPORTED DATA
4242
******************************************************************************/
43-
const char mpexception_os_resource_not_avaliable[] = "resource not available";
44-
const char mpexception_os_operation_failed[] = "the requested operation failed";
45-
const char mpexception_os_request_not_possible[] = "the requested operation is not possible";
4643
const char mpexception_value_invalid_arguments[] = "invalid argument(s) value";
4744
const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type";
4845
const char mpexception_uncaught[] = "uncaught exception";

cc3200/misc/mpexception.h

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

31-
extern const char mpexception_os_resource_not_avaliable[];
32-
extern const char mpexception_os_operation_failed[];
33-
extern const char mpexception_os_request_not_possible[];
3431
extern const char mpexception_value_invalid_arguments[];
3532
extern const char mpexception_num_type_invalid_arguments[];
3633
extern const char mpexception_uncaught[];

cc3200/mods/modnetwork.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "py/obj.h"
3030
#include "py/nlr.h"
3131
#include "py/runtime.h"
32+
#include "py/mperrno.h"
3233
#include "py/mphal.h"
3334
#include "modnetwork.h"
3435
#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
99100
// check the server id
100101
if (args[0].u_obj != MP_OBJ_NULL) {
101102
if (mp_obj_get_int(args[0].u_obj) != 0) {
102-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
103+
mp_raise_OSError(MP_ENODEV);
103104
}
104105
}
105106

cc3200/mods/moduhashlib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) {
9393
self->digested = false;
9494
}
9595
} else {
96-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
96+
mp_raise_OSError(MP_EPERM);
9797
}
9898
}
9999

@@ -106,7 +106,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) {
106106
}
107107
} else if (self->c_size < self->b_size) {
108108
// it's a fixed len block which is still incomplete
109-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
109+
mp_raise_OSError(MP_EPERM);
110110
}
111111

112112
if (!self->digested) {

cc3200/mods/modwlan.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
836836
if (n_args > 1 || n_kw > 0) {
837837
// check the peripheral id
838838
if (args[0].u_int != 0) {
839-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
839+
mp_raise_OSError(MP_ENODEV);
840840
}
841841
// start the peripheral
842842
wlan_init_helper(self, &args[1]);
@@ -860,7 +860,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
860860

861861
// check for correct wlan mode
862862
if (wlan_obj.mode == ROLE_AP) {
863-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
863+
mp_raise_OSError(MP_EPERM);
864864
}
865865

866866
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_
914914

915915
// check for the correct wlan mode
916916
if (wlan_obj.mode == ROLE_AP) {
917-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
917+
mp_raise_OSError(MP_EPERM);
918918
}
919919

920920
// 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_
962962
modwlan_Status_t status;
963963
status = wlan_do_connect (ssid, ssid_len, bssid, auth, key, key_len, timeout);
964964
if (status == MODWLAN_ERROR_TIMEOUT) {
965-
mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
965+
mp_raise_OSError(MP_ETIMEDOUT);
966966
} else if (status == MODWLAN_ERROR_INVALID_PARAMS) {
967967
mp_raise_ValueError(mpexception_value_invalid_arguments);
968968
}
@@ -993,7 +993,7 @@ STATIC mp_obj_t wlan_ifconfig (mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma
993993

994994
// check the interface id
995995
if (args[0].u_int != 0) {
996-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
996+
mp_raise_OSError(MP_EPERM);
997997
}
998998

999999
// get the configuration
@@ -1224,13 +1224,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
12241224
// strcpy(urn, p);
12251225
//
12261226
// if (sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, len, (unsigned char *)urn) < 0) {
1227-
// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
1227+
// mp_raise_OSError(MP_EIO);
12281228
// }
12291229
// }
12301230
// else {
12311231
// // get the URN
12321232
// if (sl_NetAppGet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, &len, (uint8_t *)urn) < 0) {
1233-
// mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
1233+
// mp_raise_OSError(MP_EIO);
12341234
// }
12351235
// return mp_obj_new_str(urn, (len - 1), false);
12361236
// }

cc3200/mods/pybadc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "py/runtime.h"
3434
#include "py/binary.h"
3535
#include "py/gc.h"
36+
#include "py/mperrno.h"
3637
#include "bufhelper.h"
3738
#include "inc/hw_types.h"
3839
#include "inc/hw_adc.h"
@@ -104,7 +105,7 @@ STATIC void pyb_adc_init (pyb_adc_obj_t *self) {
104105
STATIC void pyb_adc_check_init(void) {
105106
// not initialized
106107
if (!pyb_adc_obj.enabled) {
107-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
108+
mp_raise_OSError(MP_EPERM);
108109
}
109110
}
110111

@@ -149,7 +150,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
149150

150151
// check the peripheral id
151152
if (args[0].u_int != 0) {
152-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
153+
mp_raise_OSError(MP_ENODEV);
153154
}
154155

155156
// 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
206207
if (args[0].u_obj != MP_OBJ_NULL) {
207208
ch_id = mp_obj_get_int(args[0].u_obj);
208209
if (ch_id >= PYB_ADC_NUM_CHANNELS) {
209-
mp_raise_ValueError(mpexception_os_resource_not_avaliable);
210+
mp_raise_ValueError(mpexception_value_invalid_arguments);
210211
} else if (args[1].u_obj != mp_const_none) {
211212
uint pin_ch_id = pin_find_peripheral_type (args[1].u_obj, PIN_FN_ADC, 0);
212213
if (ch_id != pin_ch_id) {
@@ -277,7 +278,7 @@ STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) {
277278

278279
// the channel must be enabled
279280
if (!self->enabled) {
280-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
281+
mp_raise_OSError(MP_EPERM);
281282
}
282283

283284
// wait until a new value is available

cc3200/mods/pybi2c.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "py/mpstate.h"
3232
#include "py/runtime.h"
33+
#include "py/mperrno.h"
3334
#include "py/mphal.h"
3435
#include "bufhelper.h"
3536
#include "inc/hw_types.h"
@@ -144,7 +145,7 @@ STATIC bool pyb_i2c_transaction(uint cmd) {
144145
STATIC void pyb_i2c_check_init(pyb_i2c_obj_t *self) {
145146
// not initialized
146147
if (!self->baudrate) {
147-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
148+
mp_raise_OSError(MP_EPERM);
148149
}
149150
}
150151

@@ -256,7 +257,7 @@ STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) {
256257

257258
// receive the data
258259
if (!pyb_i2c_read(args[0].u_int, (byte *)vstr->buf, vstr->len)) {
259-
mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
260+
mp_raise_OSError(MP_EIO);
260261
}
261262
}
262263

@@ -275,7 +276,7 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) {
275276
if (pyb_i2c_mem_addr_write (i2c_addr, (byte *)&mem_addr, mem_addr_size)) {
276277
// Read the specified length of data
277278
if (!pyb_i2c_read (i2c_addr, (byte *)vstr->buf, vstr->len)) {
278-
mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
279+
mp_raise_OSError(MP_EIO);
279280
}
280281
}
281282
}
@@ -341,7 +342,7 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
341342

342343
// check the peripheral id
343344
if (args[0].u_int != 0) {
344-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
345+
mp_raise_OSError(MP_ENODEV);
345346
}
346347

347348
// 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
445446

446447
// send the data
447448
if (!pyb_i2c_write(args[0].u_int, bufinfo.buf, bufinfo.len, args[2].u_bool)) {
448-
mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
449+
mp_raise_OSError(MP_EIO);
449450
}
450451

451452
// 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,
514515
return mp_obj_new_int(bufinfo.len);
515516
}
516517

517-
mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
518+
mp_raise_OSError(MP_EIO);
518519
}
519520
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem);
520521

cc3200/mods/pybrtc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "py/mpconfig.h"
2929
#include "py/obj.h"
3030
#include "py/runtime.h"
31+
#include "py/mperrno.h"
3132
#include "inc/hw_types.h"
3233
#include "inc/hw_ints.h"
3334
#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_
292293

293294
// check the peripheral id
294295
if (args[0].u_int != 0) {
295-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
296+
mp_raise_OSError(MP_ENODEV);
296297
}
297298

298299
// 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
360361

361362
// check the alarm id
362363
if (args[0].u_int != 0) {
363-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
364+
mp_raise_OSError(MP_ENODEV);
364365
}
365366

366367
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) {
395396

396397
// only alarm id 0 is available
397398
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
398-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
399+
mp_raise_OSError(MP_ENODEV);
399400
}
400401

401402
// 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
413414
STATIC mp_obj_t pyb_rtc_alarm_cancel (mp_uint_t n_args, const mp_obj_t *args) {
414415
// only alarm id 0 is available
415416
if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
416-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
417+
mp_raise_OSError(MP_ENODEV);
417418
}
418419
// disable the alarm
419420
pyb_rtc_disable_alarm();

cc3200/mods/pybsd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "py/mpconfig.h"
2828
#include "py/obj.h"
2929
#include "py/runtime.h"
30+
#include "py/mperrno.h"
3031
#include "lib/oofatfs/ff.h"
3132
#include "lib/oofatfs/diskio.h"
3233
#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)
108109

109110
pyb_sd_hw_init (self);
110111
if (sd_disk_init() != 0) {
111-
mp_raise_msg(&mp_type_OSError, mpexception_os_operation_failed);
112+
mp_raise_OSError(MP_EIO);
112113
}
113114

114115
// 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
133134

134135
// check the peripheral id
135136
if (args[0].u_int != 0) {
136-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
137+
mp_raise_OSError(MP_ENODEV);
137138
}
138139

139140
// setup and initialize the object

cc3200/mods/pybspi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "py/mpstate.h"
3232
#include "py/runtime.h"
33+
#include "py/mperrno.h"
3334
#include "bufhelper.h"
3435
#include "inc/hw_types.h"
3536
#include "inc/hw_mcspi.h"
@@ -131,7 +132,7 @@ STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) {
131132

132133
STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) {
133134
if (!self->baudrate) {
134-
mp_raise_msg(&mp_type_OSError, mpexception_os_request_not_possible);
135+
mp_raise_OSError(MP_EPERM);
135136
}
136137
// send and receive the data
137138
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_
234235

235236
// check the peripheral id
236237
if (args[0].u_int != 0) {
237-
mp_raise_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable);
238+
mp_raise_OSError(MP_ENODEV);
238239
}
239240

240241
// setup the object

0 commit comments

Comments
 (0)