Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
aa321eb3
Commit
aa321eb3
authored
9 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys: uart_stdio: use thread-safe ringbuffer
parent
185f63f7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile.dep
+4
-0
4 additions, 0 deletions
Makefile.dep
sys/uart_stdio/uart_stdio.c
+6
-9
6 additions, 9 deletions
sys/uart_stdio/uart_stdio.c
with
10 additions
and
9 deletions
Makefile.dep
+
4
−
0
View file @
aa321eb3
...
...
@@ -287,6 +287,10 @@ ifneq (,$(filter posix_sockets,$(USEMODULE)))
USEMODULE
+=
random
endif
ifneq
(,$(filter uart_stdio,$(USEMODULE)))
USEMODULE
+=
tsrb
endif
ifneq
(,$(filter posix,$(USEMODULE)))
USEMODULE
+=
timex
USEMODULE
+=
vtimer
...
...
This diff is collapsed.
Click to expand it.
sys/uart_stdio/uart_stdio.c
+
6
−
9
View file @
aa321eb3
...
...
@@ -26,7 +26,7 @@
#include
<stdio.h>
#include
"cpu_conf.h"
#include
"
ringbuffer
.h"
#include
"
tsrb
.h"
#include
"thread.h"
#include
"mutex.h"
#include
"irq.h"
...
...
@@ -56,7 +56,7 @@
*/
static
mutex_t
_rx_mutex
=
MUTEX_INIT
;
static
char
_rx_buf_mem
[
STDIO_RX_BUFSIZE
];
static
ringbuffer_t
_rx_buf
;
static
tsrb_t
_rx_buf
=
TSRB_INIT
(
_rx_buf
_mem
)
;
/**
* @brief Receive a new character from the UART and put it into the receive buffer
...
...
@@ -64,25 +64,22 @@ static ringbuffer_t _rx_buf;
void
uart_stdio_rx_cb
(
void
*
arg
,
char
data
)
{
(
void
)
arg
;
ringbuffer
_add_one
(
&
_rx_buf
,
data
);
tsrb
_add_one
(
&
_rx_buf
,
data
);
mutex_unlock
(
&
_rx_mutex
);
}
void
uart_stdio_init
(
void
)
{
mutex_lock
(
&
_rx_mutex
);
ringbuffer_init
(
&
_rx_buf
,
_rx_buf_mem
,
STDIO_RX_BUFSIZE
);
uart_init
(
STDIO
,
STDIO_BAUDRATE
,
uart_stdio_rx_cb
,
0
,
0
);
}
int
uart_stdio_read
(
char
*
buffer
,
int
count
)
{
int
res
;
mutex_lock
(
&
_rx_mutex
);
unsigned
state
=
disableIRQ
();
count
=
(
count
<
_rx_buf
.
avail
)
?
count
:
_rx_buf
.
avail
;
res
=
ringbuffer_get
(
&
_rx_buf
,
(
char
*
)
buffer
,
count
);
restoreIRQ
(
state
);
while
(
!
(
res
=
tsrb_get
(
&
_rx_buf
,
buffer
,
count
)))
{
mutex_lock
(
&
_rx_mutex
);
}
return
res
;
}
...
...
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