Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
641cbef4
Commit
641cbef4
authored
Apr 17, 2020
by
Tomasz Wlostowski
Committed by
Grzegorz Daniluk
Apr 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib: added simple event queue system
parent
f5a242a6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
195 additions
and
1 deletion
+195
-1
wrc-event.h
include/wrc-event.h
+17
-0
wrc.h
include/wrc.h
+1
-0
event.c
lib/event.c
+156
-0
event.h
lib/event.h
+19
-0
lib.mk
lib/lib.mk
+2
-1
No files found.
include/wrc-event.h
0 → 100644
View file @
641cbef4
/*
* This work is part of the White Rabbit project
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef __WRC_EVENT_H__
#define __WRC_EVENT_H__
#include <lib/event.h>
#define WRC_EVENT_LINK_UP 1
#define WRC_EVENT_LINK_DOWN 2
#define WRC_EVENT_TIMING_UP 3
#define WRC_EVENT_TIMING_DOWN 4
#define WRC_EVENT_PTP_MODE_CHANGED 5
#endif
/* __WRC_TASK_H__ */
include/wrc.h
View file @
641cbef4
...
...
@@ -17,6 +17,7 @@
#include <pp-printf.h>
#include <util.h>
#include <trace.h>
#include <wrc-event.h>
#include <wrc-task.h>
#include <wrc-debug.h>
...
...
lib/event.c
0 → 100644
View file @
641cbef4
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <stdint.h>
#include "event.h"
// fixme: make configurable through BSPs/KConfig
#define MAX_EVENTS_PER_QUEUE 8
#define MAX_EVENT_HANDLERS 8
struct
event_queue
{
uint8_t
data
[
MAX_EVENTS_PER_QUEUE
];
uint8_t
head
,
tail
,
count
,
size
;
};
struct
event_handler
{
struct
event_queue
queue
;
int
enabled
;
int
event_mask
;
void
(
*
handler
)(
int
event
);
};
static
struct
event_handler
handlers
[
MAX_EVENT_HANDLERS
];
static
int
event_handler_count
=
0
;
static
inline
void
queue_put
(
struct
event_queue
*
buf
,
uint8_t
c
)
{
if
(
buf
->
count
>=
buf
->
size
)
return
;
buf
->
data
[
buf
->
head
]
=
c
;
buf
->
head
++
;
buf
->
count
++
;
if
(
buf
->
head
>=
buf
->
size
)
buf
->
head
=
0
;
}
static
inline
int
queue_get
(
struct
event_queue
*
buf
)
{
if
(
!
buf
->
count
)
return
-
1
;
int
rv
=
buf
->
data
[
buf
->
tail
];
buf
->
tail
++
;
if
(
buf
->
tail
>=
buf
->
size
)
buf
->
tail
=
0
;
buf
->
count
--
;
return
rv
;
}
static
inline
int
queue_init
(
struct
event_queue
*
buf
)
{
buf
->
head
=
buf
->
tail
=
buf
->
count
=
0
;
buf
->
size
=
MAX_EVENTS_PER_QUEUE
;
return
0
;
}
static
inline
int
queue_full
(
struct
event_queue
*
buf
)
{
return
buf
->
size
==
buf
->
count
;
}
static
inline
int
queue_purge
(
struct
event_queue
*
buf
)
{
buf
->
head
=
buf
->
tail
=
buf
->
count
=
0
;
}
int
event_handler_register
(
int
mask
,
int
enable
,
void
(
*
func
)(
int
)
)
{
if
(
event_handler_count
>=
MAX_EVENT_HANDLERS
)
return
-
1
;
int
rv
=
event_handler_count
;
struct
event_handler
*
eh
=
&
handlers
[
event_handler_count
];
event_handler_count
++
;
eh
->
enabled
=
enable
;
eh
->
event_mask
=
mask
;
eh
->
handler
=
func
;
queue_init
(
&
eh
->
queue
);
return
rv
;
}
int
event_handler_enable
(
int
id
,
int
enable
)
{
struct
event_handler
*
eh
=
&
handlers
[
id
];
eh
->
enabled
=
enable
;
return
0
;
}
int
event_post
(
int
event
)
{
int
i
;
for
(
i
=
0
;
i
<
event_handler_count
;
i
++
)
{
struct
event_handler
*
eh
=
&
handlers
[
i
];
if
(
!
eh
->
enabled
||
(
eh
->
event_mask
&
event
)
==
0
)
continue
;
queue_put
(
&
eh
->
queue
,
event
);
}
return
0
;
}
int
event_poll
(
int
handler
)
{
struct
event_handler
*
eh
=
&
handlers
[
handler
];
if
(
!
eh
->
enabled
)
return
0
;
if
(
eh
->
queue
.
count
==
0
)
return
0
;
return
queue_get
(
&
eh
->
queue
);
}
int
events_init
()
{
int
i
;
event_handler_count
=
0
;
for
(
i
=
0
;
i
<
MAX_EVENT_HANDLERS
;
i
++
)
handlers
[
i
].
enabled
=
0
;
}
int
events_dispatch
()
{
int
i
;
for
(
i
=
0
;
i
<
event_handler_count
;
i
++
)
{
struct
event_handler
*
eh
=
&
handlers
[
i
];
if
(
!
eh
->
enabled
)
continue
;
if
(
eh
->
queue
.
count
==
0
)
continue
;
if
(
eh
->
handler
)
eh
->
handler
(
queue_get
(
&
eh
->
queue
));
}
}
\ No newline at end of file
lib/event.h
0 → 100644
View file @
641cbef4
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#ifndef __EVENT_H
#define __EVENT_H
int
event_handler_register
(
int
mask
,
int
enable
,
void
(
*
func
)(
int
)
);
int
event_handler_enable
(
int
id
,
int
enable
);
int
event_post
(
int
event
);
int
events_init
(
void
);
int
events_dispatch
(
void
);
#endif
\ No newline at end of file
lib/lib.mk
View file @
641cbef4
...
...
@@ -3,7 +3,8 @@ obj-y += lib/util.o lib/wrc-tasks.o
obj-$(CONFIG_LM32) += \
lib/atoi.o \
lib/assert.o \
lib/usleep.o
lib/usleep.o \
lib/event.o
obj-$(CONFIG_WR_NODE) += lib/net.o
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment