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
be50f8b9
Commit
be50f8b9
authored
9 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys: newlib: use double-lock scheme for uart ringbuffer
parent
fecc1050
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sys/newlib/syscalls.c
+11
-12
11 additions, 12 deletions
sys/newlib/syscalls.c
with
11 additions
and
12 deletions
sys/newlib/syscalls.c
+
11
−
12
View file @
be50f8b9
...
@@ -54,7 +54,7 @@ caddr_t heap_top = (caddr_t)&_sheap + 4;
...
@@ -54,7 +54,7 @@ caddr_t heap_top = (caddr_t)&_sheap + 4;
/**
/**
* @brief use mutex for waiting on incoming UART chars
* @brief use mutex for waiting on incoming UART chars
*/
*/
static
mutex_t
uart_rx_mutex
;
static
mutex_t
uart_rx_mutex
=
MUTEX_INIT
;
static
char
rx_buf_mem
[
STDIO_RX_BUFSIZE
];
static
char
rx_buf_mem
[
STDIO_RX_BUFSIZE
];
static
ringbuffer_t
rx_buf
;
static
ringbuffer_t
rx_buf
;
#endif
#endif
...
@@ -65,16 +65,14 @@ static ringbuffer_t rx_buf;
...
@@ -65,16 +65,14 @@ static ringbuffer_t rx_buf;
void
rx_cb
(
void
*
arg
,
char
data
)
void
rx_cb
(
void
*
arg
,
char
data
)
{
{
(
void
)
arg
;
(
void
)
arg
;
#ifndef MODULE_UART0
#ifdef MODULE_UART0
ringbuffer_add_one
(
&
rx_buf
,
data
);
mutex_unlock
(
&
uart_rx_mutex
);
#else
if
(
uart0_handler_pid
)
{
if
(
uart0_handler_pid
)
{
uart0_handle_incoming
(
data
);
uart0_handle_incoming
(
data
);
uart0_notify_thread
();
uart0_notify_thread
();
}
}
#else
ringbuffer_add_one
(
&
rx_buf
,
data
);
mutex_unlock
(
&
uart_rx_mutex
);
#endif
#endif
}
}
...
@@ -84,7 +82,7 @@ void rx_cb(void *arg, char data)
...
@@ -84,7 +82,7 @@ void rx_cb(void *arg, char data)
void
_init
(
void
)
void
_init
(
void
)
{
{
#ifndef MODULE_UART0
#ifndef MODULE_UART0
mutex_
init
(
&
uart_rx_mutex
);
mutex_
lock
(
&
uart_rx_mutex
);
ringbuffer_init
(
&
rx_buf
,
rx_buf_mem
,
STDIO_RX_BUFSIZE
);
ringbuffer_init
(
&
rx_buf
,
rx_buf_mem
,
STDIO_RX_BUFSIZE
);
#endif
#endif
uart_init
(
STDIO
,
STDIO_BAUDRATE
,
rx_cb
,
0
,
0
);
uart_init
(
STDIO
,
STDIO_BAUDRATE
,
rx_cb
,
0
,
0
);
...
@@ -205,10 +203,11 @@ int _open_r(struct _reent *r, const char *name, int mode)
...
@@ -205,10 +203,11 @@ int _open_r(struct _reent *r, const char *name, int mode)
int
_read_r
(
struct
_reent
*
r
,
int
fd
,
void
*
buffer
,
unsigned
int
count
)
int
_read_r
(
struct
_reent
*
r
,
int
fd
,
void
*
buffer
,
unsigned
int
count
)
{
{
#ifndef MODULE_UART0
#ifndef MODULE_UART0
while
(
rx_buf
.
avail
==
0
)
{
mutex_lock
(
&
uart_rx_mutex
);
mutex_lock
(
&
uart_rx_mutex
);
}
count
=
count
<
rx_buf
.
avail
?
count
:
rx_buf
.
avail
;
return
ringbuffer_get
(
&
rx_buf
,
(
char
*
)
buffer
,
rx_buf
.
avail
);
return
ringbuffer_get
(
&
rx_buf
,
(
char
*
)
buffer
,
count
);
#else
#else
char
*
res
=
(
char
*
)
buffer
;
char
*
res
=
(
char
*
)
buffer
;
res
[
0
]
=
(
char
)
uart0_readc
();
res
[
0
]
=
(
char
)
uart0_readc
();
...
...
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