split irq.yaml output in nvic.h and vector_nvic.h

the weak pragmas need to be used in the very compilation unit where
their target is defined, requiring another dispatch
This commit is contained in:
chrysn 2012-10-18 17:30:18 +02:00
parent 5ceb377a37
commit ae832b4ee8
3 changed files with 25 additions and 7 deletions

View File

@ -15,6 +15,5 @@
# warning"no chipset defined; user interrupts are disabled"
#define NVIC_IRQ_COUNT 0
#define IRQ_HANDLERS
#endif

View File

@ -22,6 +22,8 @@
/* load optional platform dependent initialization routines */
#include "../dispatch/vector.c"
/* load the weak symbols for IRQ_HANDLERS */
#include <libopencm3/dispatch/vector_nvic.h>
#define WEAK __attribute__ ((weak))

View File

@ -29,7 +29,7 @@ method to achive the same thing with C preprocessor is known to the author.
import sys
import yaml
template = '''\
template_nvic_h = '''\
/* This file is part of the libopencm3 project.
*
* It was generated by the irq2nvic_h script.
@ -38,6 +38,8 @@ template = '''\
#ifndef {includeguard}
#define {includeguard}
#include <libopencm3/cm3/nvic.h>
/** @defgroup CM3_nvic_defines_{partname_doxygen} User interrupts for {partname_humanreadable}
@ingroup CM3_nvic_defines
@ -60,6 +62,19 @@ template = '''\
/**@}}*/
#endif /* {includeguard} */
'''
template_vector_nvic_h = '''\
/* This file is part of the libopencm3 project.
*
* It was generated by the irq2nvic_h script.
*
* This part needs to get included in the compilation unit where
* blocking_handler gets defined due to the way #pragma works.
*/
/** @defgroup CM3_nvic_isrpragmas_{partname_doxygen} User interrupt service routines (ISR) defaults for {partname_humanreadable}
@ingroup CM3_nvic_isrpragmas
@ -76,11 +91,9 @@ template = '''\
#define IRQ_HANDLERS \\
{vectortableinitialization}
#endif /* {includeguard} */
'''
def convert(infile, outfile):
def convert(infile, outfile_nvic, outfile_vectornvic):
data = yaml.load(infile)
irq2name = list(enumerate(data['irqs']) if isinstance(data['irqs'], list) else data['irqs'].items())
@ -96,10 +109,14 @@ def convert(infile, outfile):
data['isrpragmas'] = "\n".join('#pragma weak %s_isr = blocking_handler'%name.lower() for name in irqnames)
data['vectortableinitialization'] = ', \\\n '.join('[NVIC_%s_IRQ] = %s_isr'%(name.upper(), name.lower()) for name in irqnames)
outfile.write(template.format(**data))
outfile_nvic.write(template_nvic_h.format(**data))
# FIXME: the vector_nvic.h file could just as well be a vector_nvic.c file
# in lib/, but that'd spread this mechanism over the whole library; just
# needs some thingking over
outfile_vectornvic.write(template_vector_nvic_h.format(**data))
def main():
convert(open('irq.yaml'), open('nvic.h', 'w'))
convert(open('irq.yaml'), open('nvic.h', 'w'), open('vector_nvic.h', 'w'))
if __name__ == "__main__":
main()