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
9b2cff9a
Commit
9b2cff9a
authored
8 years ago
by
Martine Lenders
Browse files
Options
Downloads
Patches
Plain Diff
lwip: port mboxes to core_mbox
parent
9b63d5c2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile.dep
+1
-0
1 addition, 0 deletions
Makefile.dep
pkg/lwip/contrib/sys_arch.c
+45
-72
45 additions, 72 deletions
pkg/lwip/contrib/sys_arch.c
pkg/lwip/include/arch/sys_arch.h
+5
-8
5 additions, 8 deletions
pkg/lwip/include/arch/sys_arch.h
with
51 additions
and
80 deletions
Makefile.dep
+
1
−
0
View file @
9b2cff9a
...
@@ -411,6 +411,7 @@ endif
...
@@ -411,6 +411,7 @@ endif
ifneq
(,$(filter lwip,$(USEMODULE)))
ifneq
(,$(filter lwip,$(USEMODULE)))
USEPKG
+=
lwip
USEPKG
+=
lwip
USEMODULE
+=
core_mbox
USEMODULE
+=
lwip_api
USEMODULE
+=
lwip_api
USEMODULE
+=
lwip_contrib
USEMODULE
+=
lwip_contrib
USEMODULE
+=
lwip_core
USEMODULE
+=
lwip_core
...
...
This diff is collapsed.
Click to expand it.
pkg/lwip/contrib/sys_arch.c
+
45
−
72
View file @
9b2cff9a
...
@@ -28,6 +28,9 @@
...
@@ -28,6 +28,9 @@
#include
"thread.h"
#include
"thread.h"
#include
"xtimer.h"
#include
"xtimer.h"
#define _MSG_SUCCESS (0x5cac)
#define _MSG_TIMEOUT (0x5cad)
void
sys_init
(
void
)
void
sys_init
(
void
)
{
{
return
;
return
;
...
@@ -95,110 +98,80 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t count)
...
@@ -95,110 +98,80 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t count)
err_t
sys_mbox_new
(
sys_mbox_t
*
mbox
,
int
size
)
err_t
sys_mbox_new
(
sys_mbox_t
*
mbox
,
int
size
)
{
{
(
void
)
size
;
(
void
)
size
;
mbox
->
waiting
=
0
;
mbox_init
(
&
mbox
->
mbox
,
mbox
->
msgs
,
SYS_MBOX_SIZE
);
cib_init
(
&
mbox
->
cib
,
SYS_MBOX_SIZE
);
mutex_init
(
&
mbox
->
mutex
);
if
(
sema_create
(
&
mbox
->
not_empty
,
0
)
<
0
)
{
return
ERR_VAL
;
}
if
(
sema_create
(
&
mbox
->
not_full
,
0
)
<
0
)
{
return
ERR_VAL
;
}
return
ERR_OK
;
return
ERR_OK
;
}
}
void
sys_mbox_free
(
sys_mbox_t
*
mbox
)
void
sys_mbox_free
(
sys_mbox_t
*
mbox
)
{
{
sema_destroy
(
&
mbox
->
not_empty
)
;
(
void
)
mbox
;
sema_destroy
(
&
mbox
->
not_full
)
;
return
;
}
}
void
sys_mbox_post
(
sys_mbox_t
*
mbox
,
void
*
msg
)
void
sys_mbox_post
(
sys_mbox_t
*
mbox
,
void
*
msg
)
{
{
int
idx
;
msg_t
m
=
{
.
content
=
{
.
ptr
=
msg
},
.
type
=
_MSG_SUCCESS
}
;
LWIP_ASSERT
(
"invalid mbox"
,
sys_mbox_valid
(
mbox
));
LWIP_ASSERT
(
"invalid mbox"
,
sys_mbox_valid
(
mbox
));
mutex_lock
(
&
mbox
->
mutex
);
mbox_put
(
&
mbox
->
mbox
,
&
m
);
while
((
idx
=
cib_put
(
&
mbox
->
cib
))
<
0
)
{
mbox
->
waiting
++
;
mutex_unlock
(
&
mbox
->
mutex
);
sema_wait_timed
(
&
mbox
->
not_full
,
0
);
mutex_lock
(
&
mbox
->
mutex
);
mbox
->
waiting
--
;
}
mbox
->
msgs
[
idx
]
=
msg
;
if
(
cib_avail
(
&
mbox
->
cib
)
==
1
)
{
sema_post
(
&
mbox
->
not_empty
);
}
mutex_unlock
(
&
mbox
->
mutex
);
}
}
err_t
sys_mbox_trypost
(
sys_mbox_t
*
mbox
,
void
*
msg
)
err_t
sys_mbox_trypost
(
sys_mbox_t
*
mbox
,
void
*
msg
)
{
{
int
idx
;
msg_t
m
=
{
.
content
=
{
.
ptr
=
msg
},
.
type
=
_MSG_SUCCESS
}
;
LWIP_ASSERT
(
"invalid mbox"
,
sys_mbox_valid
(
mbox
));
if
(
mbox_try_put
(
&
mbox
->
mbox
,
&
m
))
{
mutex_lock
(
&
mbox
->
mutex
);
return
ERR_OK
;
if
((
idx
=
cib_put
(
&
mbox
->
cib
))
<
0
)
{
mutex_unlock
(
&
mbox
->
mutex
);
return
ERR_MEM
;
}
}
mbox
->
msgs
[
idx
]
=
msg
;
else
{
if
(
cib_avail
(
&
mbox
->
cib
)
==
1
)
{
return
ERR_MEM
;
sema_post
(
&
mbox
->
not_empty
);
}
}
mutex_unlock
(
&
mbox
->
mutex
);
}
return
ERR_OK
;
static
void
_mbox_timeout
(
void
*
arg
)
{
msg_t
m
=
{
.
type
=
_MSG_TIMEOUT
};
mbox_put
(
arg
,
&
m
);
}
}
u32_t
sys_arch_mbox_fetch
(
sys_mbox_t
*
mbox
,
void
**
msg
,
u32_t
timeout
)
u32_t
sys_arch_mbox_fetch
(
sys_mbox_t
*
mbox
,
void
**
msg
,
u32_t
timeout
)
{
{
u32_t
time_needed
=
0
;
msg_t
m
;
unsigned
int
idx
;
xtimer_t
timer
=
{
.
callback
=
_mbox_timeout
,
.
arg
=
&
mbox
->
mbox
};
uint64_t
start
,
stop
;
LWIP_ASSERT
(
"invalid mbox"
,
sys_mbox_valid
(
mbox
));
start
=
xtimer_now64
();
mutex_lock
(
&
mbox
->
mutex
);
if
(
timeout
>
0
)
{
while
(
cib_avail
(
&
mbox
->
cib
)
==
0
)
{
uint64_t
u_timeout
=
(
timeout
*
MS_IN_USEC
);
sys_sem_t
*
not_empty
=
(
sys_sem_t
*
)(
&
mbox
->
not_empty
);
_xtimer_set64
(
&
timer
,
(
uint32_t
)
u_timeout
,
(
uint32_t
)(
u_timeout
>>
32
));
mutex_unlock
(
&
mbox
->
mutex
);
if
(
timeout
!=
0
)
{
time_needed
=
sys_arch_sem_wait
(
not_empty
,
timeout
);
if
(
time_needed
==
SYS_ARCH_TIMEOUT
)
{
return
SYS_ARCH_TIMEOUT
;
}
}
else
{
sys_arch_sem_wait
(
not_empty
,
0
);
}
mutex_lock
(
&
mbox
->
mutex
);
}
idx
=
cib_get
(
&
mbox
->
cib
);
if
(
msg
!=
NULL
)
{
*
msg
=
mbox
->
msgs
[
idx
];
}
}
if
(
mbox
->
waiting
)
{
mbox_get
(
&
mbox
->
mbox
,
&
m
);
sema_post
(
&
mbox
->
not_full
);
stop
=
xtimer_now64
();
switch
(
m
.
type
)
{
case
_MSG_SUCCESS
:
*
msg
=
m
.
content
.
ptr
;
return
(
u32_t
)((
stop
-
start
)
/
MS_IN_USEC
);
case
_MSG_TIMEOUT
:
break
;
default:
/* should not happen */
LWIP_ASSERT
(
"invalid message received"
,
false
);
break
;
}
}
mutex_unlock
(
&
mbox
->
mutex
);
return
SYS_ARCH_TIMEOUT
;
return
time_needed
;
}
}
u32_t
sys_arch_mbox_tryfetch
(
sys_mbox_t
*
mbox
,
void
**
msg
)
u32_t
sys_arch_mbox_tryfetch
(
sys_mbox_t
*
mbox
,
void
**
msg
)
{
{
int
idx
;
msg_t
m
;
LWIP_ASSERT
(
"invalid mbox"
,
sys_mbox_valid
(
mbox
));
if
(
mbox_try_get
(
&
mbox
->
mbox
,
&
m
))
{
mutex_lock
(
&
mbox
->
mutex
);
LWIP_ASSERT
(
"invalid message received"
,
(
m
.
type
==
_MSG_SUCCESS
));
if
(
cib_avail
(
&
mbox
->
cib
)
==
0
)
{
*
msg
=
m
.
content
.
ptr
;
mutex_unlock
(
&
mbox
->
mutex
);
return
ERR_OK
;
return
SYS_MBOX_EMPTY
;
}
}
idx
=
cib_get
(
&
mbox
->
cib
);
else
{
if
(
msg
!=
NULL
)
{
return
SYS_MBOX_EMPTY
;
*
msg
=
mbox
->
msgs
[
idx
];
}
}
mutex_unlock
(
&
mbox
->
mutex
);
return
0
;
}
}
sys_thread_t
sys_thread_new
(
const
char
*
name
,
lwip_thread_fn
thread
,
void
*
arg
,
sys_thread_t
sys_thread_new
(
const
char
*
name
,
lwip_thread_fn
thread
,
void
*
arg
,
...
...
This diff is collapsed.
Click to expand it.
pkg/lwip/include/arch/sys_arch.h
+
5
−
8
View file @
9b2cff9a
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#include
"cib.h"
#include
"cib.h"
#include
"kernel_types.h"
#include
"kernel_types.h"
#include
"mbox.h"
#include
"mutex.h"
#include
"mutex.h"
#include
"random.h"
#include
"random.h"
#include
"sema.h"
#include
"sema.h"
...
@@ -38,12 +39,8 @@ extern "C" {
...
@@ -38,12 +39,8 @@ extern "C" {
#define SYS_MBOX_SIZE (8)
#define SYS_MBOX_SIZE (8)
typedef
struct
{
typedef
struct
{
cib_t
cib
;
mbox_t
mbox
;
void
*
msgs
[
SYS_MBOX_SIZE
];
msg_t
msgs
[
SYS_MBOX_SIZE
];
mutex_t
mutex
;
sema_t
not_empty
;
sema_t
not_full
;
volatile
int
waiting
;
}
sys_mbox_t
;
}
sys_mbox_t
;
typedef
mutex_t
sys_mutex_t
;
typedef
mutex_t
sys_mutex_t
;
...
@@ -62,13 +59,13 @@ static inline bool sys_sem_valid(sys_sem_t *sem)
...
@@ -62,13 +59,13 @@ static inline bool sys_sem_valid(sys_sem_t *sem)
static
inline
bool
sys_mbox_valid
(
sys_mbox_t
*
mbox
)
static
inline
bool
sys_mbox_valid
(
sys_mbox_t
*
mbox
)
{
{
return
(
mbox
!=
NULL
)
&&
(
mbox
->
cib
.
mask
!=
0
);
return
(
mbox
!=
NULL
)
&&
(
mbox
->
mbox
.
cib
.
mask
!=
0
);
}
}
static
inline
void
sys_mbox_set_invalid
(
sys_mbox_t
*
mbox
)
static
inline
void
sys_mbox_set_invalid
(
sys_mbox_t
*
mbox
)
{
{
if
(
mbox
!=
NULL
)
{
if
(
mbox
!=
NULL
)
{
mbox
->
cib
.
mask
=
0
;
mbox
->
mbox
.
cib
.
mask
=
0
;
}
}
}
}
...
...
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