Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
madonius
firmware
Commits
cebdade6
Verified
Commit
cebdade6
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
feat(streams): Add descriptor table lock
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
13386d1a
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
epicardium/modules/stream.c
+32
-0
32 additions, 0 deletions
epicardium/modules/stream.c
epicardium/modules/stream.h
+3
-0
3 additions, 0 deletions
epicardium/modules/stream.h
with
35 additions
and
0 deletions
epicardium/modules/stream.c
+
32
−
0
View file @
cebdade6
#include
<string.h>
#include
"FreeRTOS.h"
#include
"semphr.h"
#include
"epicardium.h"
#include
"stream.h"
/* Internal buffer of registered streams */
static
struct
stream_info
*
stream_table
[
SD_MAX
];
/* Lock for modifying the stream info table */
static
StaticSemaphore_t
stream_table_lock_data
;
static
SemaphoreHandle_t
stream_table_lock
;
int
stream_init
()
{
memset
(
stream_table
,
0x00
,
sizeof
(
stream_table
));
stream_table_lock
=
xSemaphoreCreateMutexStatic
(
&
stream_table_lock_data
);
return
0
;
}
int
stream_register
(
int
sd
,
struct
stream_info
*
stream
)
{
if
(
xSemaphoreTake
(
stream_table_lock
,
STREAM_MUTEX_WAIT
)
!=
pdTRUE
)
{
return
-
EBUSY
;
}
if
(
sd
<
0
||
sd
>=
SD_MAX
)
{
return
-
EINVAL
;
}
...
...
@@ -23,11 +37,17 @@ int stream_register(int sd, struct stream_info *stream)
}
stream_table
[
sd
]
=
stream
;
xSemaphoreGive
(
stream_table_lock
);
return
0
;
}
int
stream_deregister
(
int
sd
,
struct
stream_info
*
stream
)
{
if
(
xSemaphoreTake
(
stream_table_lock
,
STREAM_MUTEX_WAIT
)
!=
pdTRUE
)
{
return
-
EBUSY
;
}
if
(
sd
<
0
||
sd
>=
SD_MAX
)
{
return
-
EINVAL
;
}
...
...
@@ -38,11 +58,22 @@ int stream_deregister(int sd, struct stream_info *stream)
}
stream_table
[
sd
]
=
NULL
;
xSemaphoreGive
(
stream_table_lock
);
return
0
;
}
int
epic_stream_read
(
int
sd
,
void
*
buf
,
size_t
count
)
{
/*
* TODO: In theory, multiple reads on different streams can happen
* simulaneously. I don't know what the most efficient implementation
* of this would look like.
*/
if
(
xSemaphoreTake
(
stream_table_lock
,
STREAM_MUTEX_WAIT
)
!=
pdTRUE
)
{
return
-
EBUSY
;
}
if
(
sd
<
0
||
sd
>=
SD_MAX
)
{
return
-
EBADF
;
}
...
...
@@ -72,5 +103,6 @@ int epic_stream_read(int sd, void *buf, size_t count)
}
}
xSemaphoreGive
(
stream_table_lock
);
return
i
/
stream
->
item_size
;
}
This diff is collapsed.
Click to expand it.
epicardium/modules/stream.h
+
3
−
0
View file @
cebdade6
...
...
@@ -7,6 +7,9 @@
#include
"FreeRTOS.h"
#include
"queue.h"
/* Time to wait for the descriptor table lock to become available */
#define STREAM_MUTEX_WAIT pdMS_TO_TICKS(100)
/**
* **Stream Descriptors**:
*
...
...
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