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
wink
firmware
Commits
cce8a4cf
Verified
Commit
cce8a4cf
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
feat(genapi): Autogenerate IRQ stubs
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
4427d8ac
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/api/genapi.py
+84
-2
84 additions, 2 deletions
epicardium/api/genapi.py
with
84 additions
and
2 deletions
epicardium/api/genapi.py
+
84
−
2
View file @
cce8a4cf
...
...
@@ -5,11 +5,16 @@ import subprocess
import
sys
MATCH_EXPANSION
=
re
.
compile
(
MATCH_
API_
EXPANSION
=
re
.
compile
(
r
"
__GENERATE_API \$ __GEN_ID_(?P<id>\w+) \$ (?P<decl>.*?) \$
"
,
re
.
DOTALL
|
re
.
MULTILINE
,
)
MATCH_ISR_EXPANSION
=
re
.
compile
(
r
"
__GENERATE_API_ISR \$ __GEN_ID_(?P<id>\w+) \$ (?P<isr>.*?) \$
"
,
re
.
DOTALL
|
re
.
MULTILINE
,
)
MATCH_DECLARATION
=
re
.
compile
(
r
"
^(?P<typename>.*?)\s*\((?P<args>.*)\)$
"
,
re
.
DOTALL
,
...
...
@@ -34,7 +39,7 @@ def bailout(message, *args, **kwargs):
def
parse_declarations
(
source
):
"""
Parse all declarations in the given source.
"""
declarations
=
[]
for
exp
in
MATCH_EXPANSION
.
finditer
(
source
):
for
exp
in
MATCH_
API_
EXPANSION
.
finditer
(
source
):
id
=
exp
.
group
(
"
id
"
)
decl
=
MATCH_DECLARATION
.
match
(
exp
.
group
(
"
decl
"
))
...
...
@@ -76,6 +81,21 @@ def parse_declarations(source):
return
declarations
def
parse_interrupts
(
source
):
"""
Parse all isr declarations in the given source.
"""
interrupts
=
[]
for
exp
in
MATCH_ISR_EXPANSION
.
finditer
(
source
):
id
=
exp
.
group
(
"
id
"
)
isr
=
exp
.
group
(
"
isr
"
)
interrupts
.
append
({
"
id
"
:
id
,
"
isr
"
:
isr
,
})
return
interrupts
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
"
Generate the API stubs from a header file.
"
...
...
@@ -98,6 +118,7 @@ def main():
# a way we can find later on.
api_src
=
"""
\
#define API(id, def) __GENERATE_API $ __GEN_ID_##id $ def $
#define API_ISR(id, isr) __GENERATE_API_ISR $ __GEN_ID_##id $ isr $
#include
"
{header}
"
"""
.
format
(
header
=
os
.
path
.
relpath
(
args
.
header
)
...
...
@@ -109,6 +130,8 @@ def main():
).
decode
()
declarations
=
parse_declarations
(
source
)
interrupts
=
parse_interrupts
(
source
)
fmt_header
=
{
"
header
"
:
os
.
path
.
basename
(
args
.
header
)
}
...
...
@@ -118,6 +141,7 @@ def main():
tmp
=
"""
\
#include <stdio.h>
#define API_ISR(id, isr)
#include
"
{header}
"
#include
"
api/caller.h
"
"""
...
...
@@ -160,6 +184,64 @@ def main():
}}
"""
f_client
.
write
(
tmp
.
format
(
**
decl
))
tmp
=
"""
\
/* Weakly linked stubs for ISRs */
"""
f_client
.
write
(
tmp
)
for
isr
in
interrupts
:
tmp
=
"""
\
void {isr}(api_int_id_t id)
__attribute__((weak, alias(
"
__epic_isr_default_handler
"
)));
"""
f_client
.
write
(
tmp
.
format
(
**
isr
))
tmp
=
"""
\
/* Default handler stub */
__attribute__((weak)) void epic_isr_default_handler(api_int_id_t id)
{
;
}
/*
* This function is needed because aliasing the weak default handler will
* lead to issues.
*/
void __epic_isr_default_handler(api_int_id_t id)
{
epic_isr_default_handler(id);
}
/*
* __dispatch_isr() will be called from the actual isr which was triggered
* by core 0. It will then call the appropriate isr.
*/
void __dispatch_isr(api_int_id_t id)
{
switch (id) {
"""
f_client
.
write
(
tmp
)
for
isr
in
interrupts
:
tmp
=
"""
\
case {id}:
{isr}(id);
break;
"""
f_client
.
write
(
tmp
.
format
(
**
isr
))
tmp
=
"""
\
default:
epic_isr_default_handler(id);
break;
}
}
"""
f_client
.
write
(
tmp
)
# END: Generate Client }}}
# Generate Dispatcher {{{
...
...
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