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
b89d81fd
Commit
b89d81fd
authored
8 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys: add isrpipe
parent
96ef13dc
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile.dep
+4
-0
4 additions, 0 deletions
Makefile.dep
sys/include/isrpipe.h
+113
-0
113 additions, 0 deletions
sys/include/isrpipe.h
sys/isrpipe/Makefile
+1
-0
1 addition, 0 deletions
sys/isrpipe/Makefile
sys/isrpipe/isrpipe.c
+104
-0
104 additions, 0 deletions
sys/isrpipe/isrpipe.c
with
222 additions
and
0 deletions
Makefile.dep
+
4
−
0
View file @
b89d81fd
...
@@ -376,6 +376,10 @@ ifneq (,$(filter uart_stdio,$(USEMODULE)))
...
@@ -376,6 +376,10 @@ ifneq (,$(filter uart_stdio,$(USEMODULE)))
USEMODULE
+=
tsrb
USEMODULE
+=
tsrb
endif
endif
ifneq
(,$(filter isrpipe,$(USEMODULE)))
USEMODULE
+=
tsrb
endif
ifneq
(,$(filter posix,$(USEMODULE)))
ifneq
(,$(filter posix,$(USEMODULE)))
USEMODULE
+=
xtimer
USEMODULE
+=
xtimer
endif
endif
...
...
This diff is collapsed.
Click to expand it.
sys/include/isrpipe.h
0 → 100644
+
113
−
0
View file @
b89d81fd
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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
* directory for more details.
*/
/**
* @ingroup sys
* @{
* @file
* @brief ISR -> userspace pipe interface
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
*/
#ifndef ISRPIPE_H
#define ISRPIPE_H
#include
<stdint.h>
#include
"mutex.h"
#include
"tsrb.h"
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @brief Context structure for isrpipe
*/
typedef
struct
{
mutex_t
mutex
;
/**< isrpipe mutex */
tsrb_t
tsrb
;
/**< isrpipe thread safe ringbuffer */
}
isrpipe_t
;
/**
* @brief Static initializer for irspipe
*/
#define ISRPIPE_INIT(tsrb_buf) { .mutex = MUTEX_INIT, .tsrb = TSRB_INIT(tsrb_buf) }
/**
* @brief Initialisation function for isrpipe
*
* @param[in] isrpipe isrpipe object to initialize
* @param[in] buf buffer to use as ringbuffer (must be power of two sized!)
* @param[in] bufsize size of @p buf
*/
void
isrpipe_init
(
isrpipe_t
*
isrpipe
,
char
*
buf
,
size_t
bufsize
);
/**
* @brief Put one character into the isrpipe's buffer
*
* @param[in] isrpipe isrpipe object to initialize
* @param[in] c character to add to isrpipe buffer
*
* @returns 0 if character could be added
* @returns -1 if buffer was full
*/
int
isrpipe_write_one
(
isrpipe_t
*
isrpipe
,
char
c
);
/**
* @brief Read data from isrpipe (blocking)
*
* @param[in] isrpipe isrpipe object to operate on
* @param[in] buf buffer to write to
* @param[in] count number of bytes to read
*
* @returns number of bytes read
*/
int
isrpipe_read
(
isrpipe_t
*
isrpipe
,
char
*
buf
,
size_t
count
);
/**
* @brief Read data from isrpipe (with timeout, blocking)
*
* Currently, the timeout parameter is applied on every underlying read, which
* might be *per single byte*.
*
* @note This function might return less than @p count bytes
*
* @param[in] isrpipe isrpipe object to operate on
* @param[in] buf buffer to write to
* @param[in] count number of bytes to read
* @param[in] timeout timeout in ms
*
* @returns number of bytes read
* @returns -ETIMEDOUT on timeout
*/
int
isrpipe_read_timeout
(
isrpipe_t
*
isrpipe
,
char
*
buf
,
size_t
count
,
uint32_t
timeout
);
/**
* @brief Read data from isrpipe (with timeout, blocking, wait until all read)
*
* This function is like @ref isrpipe_read_timeout, but will only return on
* timeout or when @p count bytes have been received.
*
* @param[in] isrpipe isrpipe object to operate on
* @param[in] buf buffer to write to
* @param[in] count number of bytes to read
* @param[in] timeout timeout in ms
*
* @returns number of bytes read
* @returns -ETIMEDOUT on timeout
*/
int
isrpipe_read_all_timeout
(
isrpipe_t
*
isrpipe
,
char
*
buf
,
size_t
count
,
uint32_t
timeout
);
#ifdef __cplusplus
}
#endif
/** @} */
#endif
/* ISRPIPE_H */
This diff is collapsed.
Click to expand it.
sys/isrpipe/Makefile
0 → 100644
+
1
−
0
View file @
b89d81fd
include
$(RIOTBASE)/Makefile.base
This diff is collapsed.
Click to expand it.
sys/isrpipe/isrpipe.c
0 → 100644
+
104
−
0
View file @
b89d81fd
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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
* directory for more details.
*/
/**
* @ingroup sys
* @{
* @file
* @brief ISR -> userspace pipe implementation
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include
<errno.h>
#include
"isrpipe.h"
#include
"xtimer.h"
void
isrpipe_init
(
isrpipe_t
*
isrpipe
,
char
*
buf
,
size_t
bufsize
)
{
mutex_init
(
&
isrpipe
->
mutex
);
tsrb_init
(
&
isrpipe
->
tsrb
,
buf
,
bufsize
);
}
int
isrpipe_write_one
(
isrpipe_t
*
isrpipe
,
char
c
)
{
int
res
=
tsrb_add_one
(
&
isrpipe
->
tsrb
,
c
);
/* `res` is either 0 on success or -1 when the buffer is full. Either way,
* unlocking the mutex is fine.
*/
mutex_unlock
(
&
isrpipe
->
mutex
);
return
res
;
}
int
isrpipe_read
(
isrpipe_t
*
isrpipe
,
char
*
buffer
,
size_t
count
)
{
int
res
;
while
(
!
(
res
=
tsrb_get
(
&
isrpipe
->
tsrb
,
buffer
,
count
)))
{
mutex_lock
(
&
isrpipe
->
mutex
);
}
return
res
;
}
typedef
struct
{
mutex_t
*
mutex
;
int
flag
;
}
_isrpipe_timeout_t
;
static
void
_cb
(
void
*
arg
)
{
_isrpipe_timeout_t
*
_timeout
=
(
_isrpipe_timeout_t
*
)
arg
;
_timeout
->
flag
=
1
;
mutex_unlock
(
_timeout
->
mutex
);
}
int
isrpipe_read_timeout
(
isrpipe_t
*
isrpipe
,
char
*
buffer
,
size_t
count
,
uint32_t
timeout
)
{
int
res
;
_isrpipe_timeout_t
_timeout
=
{
.
mutex
=
&
isrpipe
->
mutex
,
.
flag
=
0
};
xtimer_t
timer
=
{
.
callback
=
_cb
,
.
arg
=
&
_timeout
};
xtimer_set
(
&
timer
,
timeout
);
while
(
!
(
res
=
tsrb_get
(
&
isrpipe
->
tsrb
,
buffer
,
count
)))
{
mutex_lock
(
&
isrpipe
->
mutex
);
if
(
_timeout
.
flag
)
{
res
=
-
ETIMEDOUT
;
break
;
}
}
xtimer_remove
(
&
timer
);
return
res
;
}
int
isrpipe_read_all_timeout
(
isrpipe_t
*
isrpipe
,
char
*
buffer
,
size_t
count
,
uint32_t
timeout
)
{
char
*
pos
=
buffer
;
while
(
count
)
{
int
res
=
isrpipe_read_timeout
(
isrpipe
,
pos
,
count
,
timeout
);
if
(
res
>=
0
)
{
count
-=
res
;
pos
+=
res
;
}
else
{
return
res
;
}
}
return
pos
-
buffer
;
}
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