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
fdd129db
Commit
fdd129db
authored
8 years ago
by
Joakim Nohlgård
Browse files
Options
Downloads
Patches
Plain Diff
uart_stdio: Bind uart_stdio to vfs fds for stdin/out/err
parent
a1faeb9c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sys/uart_stdio/uart_stdio.c
+57
-1
57 additions, 1 deletion
sys/uart_stdio/uart_stdio.c
with
57 additions
and
1 deletion
sys/uart_stdio/uart_stdio.c
+
57
−
1
View file @
fdd129db
/*
/*
* Copyright (C) 2013 INRIA
* Copyright (C) 2013 INRIA
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2016 Eistec AB
*
*
* This file is subject to the terms and conditions of the GNU Lesser
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* General Public License v2.1. See the file LICENSE in the top level
...
@@ -19,12 +20,17 @@
...
@@ -19,12 +20,17 @@
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*
*
* @}
* @}
*/
*/
#include
<stdio.h>
#include
<stdio.h>
#if MODULE_VFS
#include
<unistd.h>
#include
<errno.h>
#include
<fcntl.h>
#endif
#include
"uart_stdio.h"
#include
"uart_stdio.h"
#include
"board.h"
#include
"board.h"
...
@@ -36,12 +42,47 @@
...
@@ -36,12 +42,47 @@
extern
ethos_t
ethos
;
extern
ethos_t
ethos
;
#endif
#endif
#if MODULE_VFS
#include
"vfs.h"
#endif
#define ENABLE_DEBUG 0
#define ENABLE_DEBUG 0
#include
"debug.h"
#include
"debug.h"
static
char
_rx_buf_mem
[
UART_STDIO_RX_BUFSIZE
];
static
char
_rx_buf_mem
[
UART_STDIO_RX_BUFSIZE
];
isrpipe_t
uart_stdio_isrpipe
=
ISRPIPE_INIT
(
_rx_buf_mem
);
isrpipe_t
uart_stdio_isrpipe
=
ISRPIPE_INIT
(
_rx_buf_mem
);
#if MODULE_VFS
static
ssize_t
uart_stdio_vfs_read
(
vfs_file_t
*
filp
,
void
*
dest
,
size_t
nbytes
);
static
ssize_t
uart_stdio_vfs_write
(
vfs_file_t
*
filp
,
const
void
*
src
,
size_t
nbytes
);
/**
* @brief VFS file operation table for stdin/stdout/stderr
*/
static
vfs_file_ops_t
uart_stdio_vfs_ops
=
{
.
read
=
uart_stdio_vfs_read
,
.
write
=
uart_stdio_vfs_write
,
};
static
ssize_t
uart_stdio_vfs_read
(
vfs_file_t
*
filp
,
void
*
dest
,
size_t
nbytes
)
{
int
fd
=
filp
->
private_data
.
value
;
if
(
fd
!=
STDIN_FILENO
)
{
return
-
EBADF
;
}
return
uart_stdio_read
(
dest
,
nbytes
);
}
static
ssize_t
uart_stdio_vfs_write
(
vfs_file_t
*
filp
,
const
void
*
src
,
size_t
nbytes
)
{
int
fd
=
filp
->
private_data
.
value
;
if
(
fd
==
STDIN_FILENO
)
{
return
-
EBADF
;
}
return
uart_stdio_write
(
src
,
nbytes
);
}
#endif
void
uart_stdio_init
(
void
)
void
uart_stdio_init
(
void
)
{
{
#ifndef USE_ETHOS_FOR_STDIO
#ifndef USE_ETHOS_FOR_STDIO
...
@@ -49,6 +90,21 @@ void uart_stdio_init(void)
...
@@ -49,6 +90,21 @@ void uart_stdio_init(void)
#else
#else
uart_init
(
ETHOS_UART
,
ETHOS_BAUDRATE
,
(
uart_rx_cb_t
)
isrpipe_write_one
,
&
uart_stdio_isrpipe
);
uart_init
(
ETHOS_UART
,
ETHOS_BAUDRATE
,
(
uart_rx_cb_t
)
isrpipe_write_one
,
&
uart_stdio_isrpipe
);
#endif
#endif
#if MODULE_VFS
int
fd
;
fd
=
vfs_bind
(
STDIN_FILENO
,
O_RDONLY
,
&
uart_stdio_vfs_ops
,
(
void
*
)
STDIN_FILENO
);
if
(
fd
<
0
)
{
/* How to handle errors on init? */
}
fd
=
vfs_bind
(
STDOUT_FILENO
,
O_WRONLY
,
&
uart_stdio_vfs_ops
,
(
void
*
)
STDOUT_FILENO
);
if
(
fd
<
0
)
{
/* How to handle errors on init? */
}
fd
=
vfs_bind
(
STDERR_FILENO
,
O_WRONLY
,
&
uart_stdio_vfs_ops
,
(
void
*
)
STDERR_FILENO
);
if
(
fd
<
0
)
{
/* How to handle errors on init? */
}
#endif
}
}
int
uart_stdio_read
(
char
*
buffer
,
int
count
)
int
uart_stdio_read
(
char
*
buffer
,
int
count
)
...
...
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