Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
5ab98d5c
Commit
5ab98d5c
authored
May 10, 2016
by
Damien George
Browse files
stmhal: Convert to use internal errno symbols; enable uerrno module.
parent
088127d9
Changes
12
Hide whitespace changes
Inline
Side-by-side
stmhal/can.c
View file @
5ab98d5c
...
...
@@ -27,12 +27,12 @@
#include
<stdio.h>
#include
<string.h>
#include
<stdarg.h>
#include
<errno.h>
#include
"py/nlr.h"
#include
"py/objtuple.h"
#include
"py/runtime.h"
#include
"py/gc.h"
#include
"py/mperrno.h"
#include
"py/mphal.h"
#include
"bufhelper.h"
#include
"can.h"
...
...
@@ -817,7 +817,7 @@ mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *err
ret
|=
MP_IOCTL_POLL_WR
;
}
}
else
{
*
errcode
=
EINVAL
;
*
errcode
=
MP_
EINVAL
;
ret
=
-
1
;
}
return
ret
;
...
...
stmhal/modnetwork.c
View file @
5ab98d5c
...
...
@@ -27,7 +27,6 @@
#include
<stdio.h>
#include
<stdint.h>
#include
<string.h>
#include
<errno.h>
#include
"py/nlr.h"
#include
"py/objlist.h"
...
...
stmhal/modnwcc3k.c
View file @
5ab98d5c
...
...
@@ -26,7 +26,6 @@
#include
<string.h>
#include
<stdarg.h>
#include
<errno.h>
// CC3000 defines its own ENOBUFS (different to standard one!)
#undef ENOBUFS
...
...
stmhal/modnwwiznet5k.c
View file @
5ab98d5c
...
...
@@ -27,7 +27,6 @@
#include
<stdio.h>
#include
<stdint.h>
#include
<string.h>
#include
<errno.h>
#include
"py/nlr.h"
#include
"py/objlist.h"
...
...
stmhal/moduselect.c
View file @
5ab98d5c
...
...
@@ -25,11 +25,11 @@
*/
#include
<stdio.h>
#include
<errno.h>
#include
"py/nlr.h"
#include
"py/obj.h"
#include
"py/objlist.h"
#include
"py/mperrno.h"
#include
"py/mphal.h"
#include
"pybioctl.h"
...
...
@@ -212,7 +212,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas
mp_obj_poll_t
*
self
=
self_in
;
mp_map_elem_t
*
elem
=
mp_map_lookup
(
&
self
->
poll_map
,
mp_obj_id
(
obj_in
),
MP_MAP_LOOKUP
);
if
(
elem
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
ENOENT
)));
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_
ENOENT
)));
}
((
poll_obj_t
*
)
elem
->
value
)
->
flags
=
mp_obj_get_int
(
eventmask_in
);
return
mp_const_none
;
...
...
stmhal/modusocket.c
View file @
5ab98d5c
...
...
@@ -26,12 +26,12 @@
#include
<stdio.h>
#include
<string.h>
#include
<errno.h>
#include
"py/nlr.h"
#include
"py/objtuple.h"
#include
"py/objlist.h"
#include
"py/runtime.h"
#include
"py/mperrno.h"
#include
"netutils.h"
#include
"modnetwork.h"
...
...
@@ -116,7 +116,7 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
// TODO I think we can listen even if not bound...
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
ENOTCONN
)));
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_
ENOTCONN
)));
}
int
_errno
;
...
...
@@ -186,7 +186,7 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
EPIPE
)));
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_
EPIPE
)));
}
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
buf_in
,
&
bufinfo
,
MP_BUFFER_READ
);
...
...
@@ -204,7 +204,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
ENOTCONN
)));
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_
ENOTCONN
)));
}
mp_int_t
len
=
mp_obj_get_int
(
len_in
);
vstr_t
vstr
;
...
...
@@ -253,7 +253,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
ENOTCONN
)));
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_
ENOTCONN
)));
}
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
mp_obj_get_int
(
len_in
));
...
...
@@ -314,7 +314,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
ENOTCONN
)));
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_
ENOTCONN
)));
}
mp_uint_t
timeout
;
if
(
timeout_in
==
mp_const_none
)
{
...
...
stmhal/mpconfigport.h
View file @
5ab98d5c
...
...
@@ -61,6 +61,7 @@
#define MICROPY_STREAMS_NON_BLOCK (1)
#define MICROPY_MODULE_WEAK_LINKS (1)
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
...
...
@@ -80,6 +81,7 @@
#define MICROPY_PY_CMATH (1)
#define MICROPY_PY_IO (1)
#define MICROPY_PY_IO_FILEIO (1)
#define MICROPY_PY_UERRNO (1)
#define MICROPY_PY_UBINASCII (1)
#define MICROPY_PY_URANDOM (1)
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
...
...
@@ -141,6 +143,7 @@ extern const struct _mp_obj_module_t mp_module_network;
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
// extra constants
#define MICROPY_PORT_CONSTANTS \
...
...
stmhal/mphalport.c
View file @
5ab98d5c
#include
<errno.h>
#include
<string.h>
#include
"py/mpstate.h"
#include
"py/mperrno.h"
#include
"py/mphal.h"
#include
"usb.h"
#include
"uart.h"
...
...
@@ -9,9 +9,9 @@
// this table converts from HAL_StatusTypeDef to POSIX errno
const
byte
mp_hal_status_to_errno_table
[
4
]
=
{
[
HAL_OK
]
=
0
,
[
HAL_ERROR
]
=
EIO
,
[
HAL_BUSY
]
=
EBUSY
,
[
HAL_TIMEOUT
]
=
ETIMEDOUT
,
[
HAL_ERROR
]
=
MP_
EIO
,
[
HAL_BUSY
]
=
MP_
EBUSY
,
[
HAL_TIMEOUT
]
=
MP_
ETIMEDOUT
,
};
NORETURN
void
mp_hal_raise
(
HAL_StatusTypeDef
status
)
{
...
...
stmhal/pybstdio.c
View file @
5ab98d5c
...
...
@@ -26,10 +26,10 @@
#include
<stdio.h>
#include
<string.h>
#include
<errno.h>
#include
"py/obj.h"
#include
"py/stream.h"
#include
"py/mperrno.h"
#include
"py/mphal.h"
// TODO make stdin, stdout and stderr writable objects so they can
...
...
@@ -69,7 +69,7 @@ STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *er
}
return
size
;
}
else
{
*
errcode
=
EPERM
;
*
errcode
=
MP_
EPERM
;
return
MP_STREAM_ERROR
;
}
}
...
...
@@ -80,7 +80,7 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
mp_hal_stdout_tx_strn_cooked
(
buf
,
size
);
return
size
;
}
else
{
*
errcode
=
EPERM
;
*
errcode
=
MP_
EPERM
;
return
MP_STREAM_ERROR
;
}
}
...
...
stmhal/uart.c
View file @
5ab98d5c
...
...
@@ -27,11 +27,11 @@
#include
<stdio.h>
#include
<string.h>
#include
<stdarg.h>
#include
<errno.h>
#include
"py/nlr.h"
#include
"py/runtime.h"
#include
"py/stream.h"
#include
"py/mperrno.h"
#include
"py/mphal.h"
#include
"uart.h"
#include
"pybioctl.h"
...
...
@@ -829,7 +829,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
// check that size is a multiple of character width
if
(
size
&
self
->
char_width
)
{
*
errcode
=
EIO
;
*
errcode
=
MP_
EIO
;
return
MP_STREAM_ERROR
;
}
...
...
@@ -844,7 +844,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
// wait for first char to become available
if
(
!
uart_rx_wait
(
self
,
self
->
timeout
))
{
// return EAGAIN error to indicate non-blocking (then read() method returns None)
*
errcode
=
EAGAIN
;
*
errcode
=
MP_
EAGAIN
;
return
MP_STREAM_ERROR
;
}
...
...
@@ -871,13 +871,13 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
// check that size is a multiple of character width
if
(
size
&
self
->
char_width
)
{
*
errcode
=
EIO
;
*
errcode
=
MP_
EIO
;
return
MP_STREAM_ERROR
;
}
// wait to be able to write the first character. EAGAIN causes write to return None
if
(
!
uart_tx_wait
(
self
,
self
->
timeout
))
{
*
errcode
=
EAGAIN
;
*
errcode
=
MP_
EAGAIN
;
return
MP_STREAM_ERROR
;
}
...
...
@@ -917,7 +917,7 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a
ret
|=
MP_IOCTL_POLL_WR
;
}
}
else
{
*
errcode
=
EINVAL
;
*
errcode
=
MP_
EINVAL
;
ret
=
MP_STREAM_ERROR
;
}
return
ret
;
...
...
stmhal/usb.c
View file @
5ab98d5c
...
...
@@ -26,7 +26,6 @@
#include
<stdarg.h>
#include
<string.h>
#include
<errno.h>
#include
"usbd_core.h"
#include
"usbd_desc.h"
...
...
@@ -37,6 +36,7 @@
#include
"py/objstr.h"
#include
"py/runtime.h"
#include
"py/stream.h"
#include
"py/mperrno.h"
#include
"bufhelper.h"
#include
"usb.h"
#include
"pybioctl.h"
...
...
@@ -483,7 +483,7 @@ STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, i
int
ret
=
USBD_CDC_Rx
((
byte
*
)
buf
,
size
,
0
);
if
(
ret
==
0
)
{
// return EAGAIN error to indicate non-blocking
*
errcode
=
EAGAIN
;
*
errcode
=
MP_
EAGAIN
;
return
MP_STREAM_ERROR
;
}
return
ret
;
...
...
@@ -493,7 +493,7 @@ STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t
int
ret
=
USBD_CDC_Tx
((
const
byte
*
)
buf
,
size
,
0
);
if
(
ret
==
0
)
{
// return EAGAIN error to indicate non-blocking
*
errcode
=
EAGAIN
;
*
errcode
=
MP_
EAGAIN
;
return
MP_STREAM_ERROR
;
}
return
ret
;
...
...
@@ -511,7 +511,7 @@ STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_
ret
|=
MP_IOCTL_POLL_WR
;
}
}
else
{
*
errcode
=
EINVAL
;
*
errcode
=
MP_
EINVAL
;
ret
=
MP_STREAM_ERROR
;
}
return
ret
;
...
...
@@ -600,7 +600,7 @@ STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_
ret
|=
MP_IOCTL_POLL_WR
;
}
}
else
{
*
errcode
=
EINVAL
;
*
errcode
=
MP_
EINVAL
;
ret
=
MP_STREAM_ERROR
;
}
return
ret
;
...
...
tests/pyb/halerror.py.exp
View file @
5ab98d5c
OSError(5,)
OSError(11
6
,)
OSError(11
0
,)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment