Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
79a38a7a
Commit
79a38a7a
authored
May 10, 2016
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: For network drivers, convert to use MP_Exxx errno symbols.
parent
83a9a723
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
stmhal/modnwcc3k.c
+9
-8
9 additions, 8 deletions
stmhal/modnwcc3k.c
stmhal/modnwwiznet5k.c
+9
-8
9 additions, 8 deletions
stmhal/modnwwiznet5k.c
with
18 additions
and
16 deletions
stmhal/modnwcc3k.c
+
9
−
8
View file @
79a38a7a
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include
"py/objlist.h"
#include
"py/objlist.h"
#include
"py/stream.h"
#include
"py/stream.h"
#include
"py/runtime.h"
#include
"py/runtime.h"
#include
"py/mperrno.h"
#include
"netutils.h"
#include
"netutils.h"
#include
"modnetwork.h"
#include
"modnetwork.h"
#include
"pin.h"
#include
"pin.h"
...
@@ -125,7 +126,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
...
@@ -125,7 +126,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
if
(
ip
==
0
)
{
if
(
ip
==
0
)
{
// unknown host
// unknown host
return
ENOENT
;
return
MP_
ENOENT
;
}
}
out_ip
[
0
]
=
ip
>>
24
;
out_ip
[
0
]
=
ip
>>
24
;
...
@@ -138,7 +139,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
...
@@ -138,7 +139,7 @@ STATIC int cc3k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uin
STATIC
int
cc3k_socket_socket
(
mod_network_socket_obj_t
*
socket
,
int
*
_errno
)
{
STATIC
int
cc3k_socket_socket
(
mod_network_socket_obj_t
*
socket
,
int
*
_errno
)
{
if
(
socket
->
u_param
.
domain
!=
MOD_NETWORK_AF_INET
)
{
if
(
socket
->
u_param
.
domain
!=
MOD_NETWORK_AF_INET
)
{
*
_errno
=
EAFNOSUPPORT
;
*
_errno
=
MP_
EAFNOSUPPORT
;
return
-
1
;
return
-
1
;
}
}
...
@@ -147,7 +148,7 @@ STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
...
@@ -147,7 +148,7 @@ STATIC int cc3k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
case
MOD_NETWORK_SOCK_STREAM
:
type
=
SOCK_STREAM
;
break
;
case
MOD_NETWORK_SOCK_STREAM
:
type
=
SOCK_STREAM
;
break
;
case
MOD_NETWORK_SOCK_DGRAM
:
type
=
SOCK_DGRAM
;
break
;
case
MOD_NETWORK_SOCK_DGRAM
:
type
=
SOCK_DGRAM
;
break
;
case
MOD_NETWORK_SOCK_RAW
:
type
=
SOCK_RAW
;
break
;
case
MOD_NETWORK_SOCK_RAW
:
type
=
SOCK_RAW
;
break
;
default:
*
_errno
=
EINVAL
;
return
-
1
;
default:
*
_errno
=
MP_
EINVAL
;
return
-
1
;
}
}
// open socket
// open socket
...
@@ -201,7 +202,7 @@ STATIC int cc3k_socket_accept(mod_network_socket_obj_t *socket, mod_network_sock
...
@@ -201,7 +202,7 @@ STATIC int cc3k_socket_accept(mod_network_socket_obj_t *socket, mod_network_sock
socklen_t
addr_len
=
sizeof
(
addr
);
socklen_t
addr_len
=
sizeof
(
addr
);
if
((
fd
=
CC3000_EXPORT
(
accept
)(
socket
->
u_state
,
&
addr
,
&
addr_len
))
<
0
)
{
if
((
fd
=
CC3000_EXPORT
(
accept
)(
socket
->
u_state
,
&
addr
,
&
addr_len
))
<
0
)
{
if
(
fd
==
SOC_IN_PROGRESS
)
{
if
(
fd
==
SOC_IN_PROGRESS
)
{
*
_errno
=
EAGAIN
;
*
_errno
=
MP_
EAGAIN
;
}
else
{
}
else
{
*
_errno
=
-
fd
;
*
_errno
=
-
fd
;
}
}
...
@@ -239,7 +240,7 @@ STATIC int cc3k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_ui
...
@@ -239,7 +240,7 @@ STATIC int cc3k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_ui
STATIC
mp_uint_t
cc3k_socket_send
(
mod_network_socket_obj_t
*
socket
,
const
byte
*
buf
,
mp_uint_t
len
,
int
*
_errno
)
{
STATIC
mp_uint_t
cc3k_socket_send
(
mod_network_socket_obj_t
*
socket
,
const
byte
*
buf
,
mp_uint_t
len
,
int
*
_errno
)
{
if
(
cc3k_get_fd_closed_state
(
socket
->
u_state
))
{
if
(
cc3k_get_fd_closed_state
(
socket
->
u_state
))
{
CC3000_EXPORT
(
closesocket
)(
socket
->
u_state
);
CC3000_EXPORT
(
closesocket
)(
socket
->
u_state
);
*
_errno
=
EPIPE
;
*
_errno
=
MP_
EPIPE
;
return
-
1
;
return
-
1
;
}
}
...
@@ -266,7 +267,7 @@ STATIC mp_uint_t cc3k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, m
...
@@ -266,7 +267,7 @@ STATIC mp_uint_t cc3k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, m
fd_set
rfds
;
fd_set
rfds
;
FD_ZERO
(
&
rfds
);
FD_ZERO
(
&
rfds
);
FD_SET
(
socket
->
u_state
,
&
rfds
);
FD_SET
(
socket
->
u_state
,
&
rfds
);
timeval
tv
;
cc3000_
timeval
tv
;
tv
.
tv_sec
=
0
;
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
1
;
tv
.
tv_usec
=
1
;
int
nfds
=
CC3000_EXPORT
(
select
)(
socket
->
u_state
+
1
,
&
rfds
,
NULL
,
NULL
,
&
tv
);
int
nfds
=
CC3000_EXPORT
(
select
)(
socket
->
u_state
+
1
,
&
rfds
,
NULL
,
NULL
,
&
tv
);
...
@@ -382,7 +383,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request
...
@@ -382,7 +383,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request
}
}
// call cc3000 select with minimum timeout
// call cc3000 select with minimum timeout
timeval
tv
;
cc3000_
timeval
tv
;
tv
.
tv_sec
=
0
;
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
1
;
tv
.
tv_usec
=
1
;
int
nfds
=
CC3000_EXPORT
(
select
)(
fd
+
1
,
&
rfds
,
&
wfds
,
&
xfds
,
&
tv
);
int
nfds
=
CC3000_EXPORT
(
select
)(
fd
+
1
,
&
rfds
,
&
wfds
,
&
xfds
,
&
tv
);
...
@@ -404,7 +405,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request
...
@@ -404,7 +405,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request
ret
|=
MP_IOCTL_POLL_HUP
;
ret
|=
MP_IOCTL_POLL_HUP
;
}
}
}
else
{
}
else
{
*
_errno
=
EINVAL
;
*
_errno
=
MP_
EINVAL
;
ret
=
-
1
;
ret
=
-
1
;
}
}
return
ret
;
return
ret
;
...
...
This diff is collapsed.
Click to expand it.
stmhal/modnwwiznet5k.c
+
9
−
8
View file @
79a38a7a
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include
"py/nlr.h"
#include
"py/nlr.h"
#include
"py/objlist.h"
#include
"py/objlist.h"
#include
"py/runtime.h"
#include
"py/runtime.h"
#include
"py/mperrno.h"
#include
"py/mphal.h"
#include
"py/mphal.h"
#include
"netutils.h"
#include
"netutils.h"
#include
"modnetwork.h"
#include
"modnetwork.h"
...
@@ -92,20 +93,20 @@ STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len,
...
@@ -92,20 +93,20 @@ STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len,
return
0
;
return
0
;
}
else
{
}
else
{
// failure
// failure
return
ENOENT
;
return
MP_
ENOENT
;
}
}
}
}
STATIC
int
wiznet5k_socket_socket
(
mod_network_socket_obj_t
*
socket
,
int
*
_errno
)
{
STATIC
int
wiznet5k_socket_socket
(
mod_network_socket_obj_t
*
socket
,
int
*
_errno
)
{
if
(
socket
->
u_param
.
domain
!=
MOD_NETWORK_AF_INET
)
{
if
(
socket
->
u_param
.
domain
!=
MOD_NETWORK_AF_INET
)
{
*
_errno
=
EAFNOSUPPORT
;
*
_errno
=
MP_
EAFNOSUPPORT
;
return
-
1
;
return
-
1
;
}
}
switch
(
socket
->
u_param
.
type
)
{
switch
(
socket
->
u_param
.
type
)
{
case
MOD_NETWORK_SOCK_STREAM
:
socket
->
u_param
.
type
=
Sn_MR_TCP
;
break
;
case
MOD_NETWORK_SOCK_STREAM
:
socket
->
u_param
.
type
=
Sn_MR_TCP
;
break
;
case
MOD_NETWORK_SOCK_DGRAM
:
socket
->
u_param
.
type
=
Sn_MR_UDP
;
break
;
case
MOD_NETWORK_SOCK_DGRAM
:
socket
->
u_param
.
type
=
Sn_MR_UDP
;
break
;
default:
*
_errno
=
EINVAL
;
return
-
1
;
default:
*
_errno
=
MP_
EINVAL
;
return
-
1
;
}
}
if
(
socket
->
u_param
.
fileno
==
-
1
)
{
if
(
socket
->
u_param
.
fileno
==
-
1
)
{
...
@@ -119,7 +120,7 @@ STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno)
...
@@ -119,7 +120,7 @@ STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno)
}
}
if
(
socket
->
u_param
.
fileno
==
-
1
)
{
if
(
socket
->
u_param
.
fileno
==
-
1
)
{
// too many open sockets
// too many open sockets
*
_errno
=
EMFILE
;
*
_errno
=
MP_
EMFILE
;
return
-
1
;
return
-
1
;
}
}
}
}
...
@@ -198,7 +199,7 @@ STATIC int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_
...
@@ -198,7 +199,7 @@ STATIC int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_
}
}
if
(
sr
==
SOCK_CLOSED
||
sr
==
SOCK_CLOSE_WAIT
)
{
if
(
sr
==
SOCK_CLOSED
||
sr
==
SOCK_CLOSE_WAIT
)
{
wiznet5k_socket_close
(
socket
);
wiznet5k_socket_close
(
socket
);
*
_errno
=
ENOTCONN
;
// ??
*
_errno
=
MP_
ENOTCONN
;
// ??
return
-
1
;
return
-
1
;
}
}
HAL_Delay
(
1
);
HAL_Delay
(
1
);
...
@@ -276,13 +277,13 @@ STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte
...
@@ -276,13 +277,13 @@ STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte
STATIC
int
wiznet5k_socket_setsockopt
(
mod_network_socket_obj_t
*
socket
,
mp_uint_t
level
,
mp_uint_t
opt
,
const
void
*
optval
,
mp_uint_t
optlen
,
int
*
_errno
)
{
STATIC
int
wiznet5k_socket_setsockopt
(
mod_network_socket_obj_t
*
socket
,
mp_uint_t
level
,
mp_uint_t
opt
,
const
void
*
optval
,
mp_uint_t
optlen
,
int
*
_errno
)
{
// TODO
// TODO
*
_errno
=
EINVAL
;
*
_errno
=
MP_
EINVAL
;
return
-
1
;
return
-
1
;
}
}
STATIC
int
wiznet5k_socket_settimeout
(
mod_network_socket_obj_t
*
socket
,
mp_uint_t
timeout_ms
,
int
*
_errno
)
{
STATIC
int
wiznet5k_socket_settimeout
(
mod_network_socket_obj_t
*
socket
,
mp_uint_t
timeout_ms
,
int
*
_errno
)
{
// TODO
// TODO
*
_errno
=
EINVAL
;
*
_errno
=
MP_
EINVAL
;
return
-
1
;
return
-
1
;
/*
/*
...
@@ -296,7 +297,7 @@ STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_
...
@@ -296,7 +297,7 @@ STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_
STATIC
int
wiznet5k_socket_ioctl
(
mod_network_socket_obj_t
*
socket
,
mp_uint_t
request
,
mp_uint_t
arg
,
int
*
_errno
)
{
STATIC
int
wiznet5k_socket_ioctl
(
mod_network_socket_obj_t
*
socket
,
mp_uint_t
request
,
mp_uint_t
arg
,
int
*
_errno
)
{
// TODO
// TODO
*
_errno
=
EINVAL
;
*
_errno
=
MP_
EINVAL
;
return
-
1
;
return
-
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment