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
a2f55fe1
Commit
a2f55fe1
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Add polling ability to UART object.
parent
6c9c7bc7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
stmhal/modselect.c
+4
-10
4 additions, 10 deletions
stmhal/modselect.c
stmhal/pybioctl.h
+6
-0
6 additions, 0 deletions
stmhal/pybioctl.h
stmhal/uart.c
+33
-0
33 additions, 0 deletions
stmhal/uart.c
with
43 additions
and
10 deletions
stmhal/modselect.c
+
4
−
10
View file @
a2f55fe1
...
...
@@ -35,16 +35,10 @@
#include
"qstr.h"
#include
"obj.h"
#include
"objlist.h"
#include
"pybioctl.h"
/// \moduleref select
#define MP_IOCTL_POLL (0x100 | 1)
#define MP_IOCTL_POLL_RD (0x0001)
#define MP_IOCTL_POLL_WR (0x0002)
#define MP_IOCTL_POLL_HUP (0x0004)
#define MP_IOCTL_POLL_ERR (0x0008)
typedef
struct
_poll_obj_t
{
mp_uint_t
(
*
ioctl
)(
mp_obj_t
obj
,
mp_uint_t
request
,
int
*
errcode
,
...);
mp_uint_t
flags
;
...
...
@@ -85,13 +79,13 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, mp_uint_t *rwx_num) {
}
poll_obj_t
*
poll_obj
=
(
poll_obj_t
*
)
poll_map
->
table
[
i
].
value
;
int
err
no
;
mp_int_t
ret
=
poll_obj
->
ioctl
(
poll_map
->
table
[
i
].
key
,
MP_IOCTL_POLL
,
&
err
no
,
poll_obj
->
flags
);
int
err
code
;
mp_int_t
ret
=
poll_obj
->
ioctl
(
poll_map
->
table
[
i
].
key
,
MP_IOCTL_POLL
,
&
err
code
,
poll_obj
->
flags
);
poll_obj
->
flags_ret
=
ret
;
if
(
ret
==
-
1
)
{
// error doing ioctl
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
err
no
)));
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
err
code
)));
}
if
(
ret
!=
0
)
{
...
...
This diff is collapsed.
Click to expand it.
stmhal/pybioctl.h
0 → 100644
+
6
−
0
View file @
a2f55fe1
#define MP_IOCTL_POLL (0x100 | 1)
#define MP_IOCTL_POLL_RD (0x0001)
#define MP_IOCTL_POLL_WR (0x0002)
#define MP_IOCTL_POLL_HUP (0x0004)
#define MP_IOCTL_POLL_ERR (0x0008)
This diff is collapsed.
Click to expand it.
stmhal/uart.c
+
33
−
0
View file @
a2f55fe1
...
...
@@ -26,6 +26,7 @@
#include
<stdio.h>
#include
<string.h>
#include
<stdarg.h>
#include
"stm32f4xx_hal.h"
...
...
@@ -37,6 +38,7 @@
#include
"runtime.h"
#include
"bufhelper.h"
#include
"uart.h"
#include
"pybioctl.h"
/// \moduleref pyb
/// \class UART - duplex serial communication bus
...
...
@@ -475,10 +477,41 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
STATIC
MP_DEFINE_CONST_DICT
(
pyb_uart_locals_dict
,
pyb_uart_locals_dict_table
);
mp_uint_t
uart_ioctl
(
mp_obj_t
self_in
,
mp_uint_t
request
,
int
*
errcode
,
...)
{
pyb_uart_obj_t
*
self
=
self_in
;
va_list
vargs
;
va_start
(
vargs
,
errcode
);
mp_uint_t
ret
;
if
(
request
==
MP_IOCTL_POLL
)
{
mp_uint_t
flags
=
va_arg
(
vargs
,
mp_uint_t
);
ret
=
0
;
if
(
flags
&
MP_IOCTL_POLL_RD
&&
uart_rx_any
(
self
))
{
ret
|=
MP_IOCTL_POLL_RD
;
}
if
(
flags
&
MP_IOCTL_POLL_WR
)
{
// TODO can we always write?
ret
|=
MP_IOCTL_POLL_WR
;
}
}
else
{
*
errcode
=
1
;
// EPERM, operation not permitted
ret
=
-
1
;
}
va_end
(
vargs
);
return
ret
;
}
STATIC
const
mp_stream_p_t
uart_stream_p
=
{
//.read = uart_read, // TODO
//.write = uart_write, // TODO
.
ioctl
=
uart_ioctl
,
.
is_text
=
false
,
};
const
mp_obj_type_t
pyb_uart_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_UART
,
.
print
=
pyb_uart_print
,
.
make_new
=
pyb_uart_make_new
,
.
stream_p
=
&
uart_stream_p
,
.
locals_dict
=
(
mp_obj_t
)
&
pyb_uart_locals_dict
,
};
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