From f2f099f8864ec5da769bd13c79359009feff0508 Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Wed, 5 Oct 2022 07:12:35 +0200 Subject: [PATCH] ComputeGraph improvements. More customization options --- ComputeGraph/README.md | 20 +++++++++++++++++++ ComputeGraph/examples/example1/graph.py | 8 +++++++- cmsisdsp/cg/static/scheduler/config.py | 9 +++++++++ cmsisdsp/cg/static/scheduler/templates/code.h | 4 ++++ .../static/scheduler/templates/codeArray.cpp | 5 +++++ .../cg/static/scheduler/templates/commonc.cpp | 5 +++++ cmsisdsp/version.py | 2 +- 7 files changed, 51 insertions(+), 2 deletions(-) diff --git a/ComputeGraph/README.md b/ComputeGraph/README.md index c3d66744..9f670d12 100644 --- a/ComputeGraph/README.md +++ b/ComputeGraph/README.md @@ -209,6 +209,14 @@ When `debugLimit` is > 0, the number of iterations of the scheduling is limited When true, generate some code to dump the FIFO content at runtime. Only useful for debug. +In C code generation, it is only available when using the mode `codeArray == False`. + +When this mode is enabled, the first line of the scheduler file is : + +`#define DEBUGSCHED 1` + +and it also enable some debug code in `GenericNodes.h` + #### schedName (default = "scheduler") Name of the scheduler function used in the generated code. @@ -247,6 +255,10 @@ Enable the generation of `CMSIS EventRecorder` intrumentation in the code. Name of custom header in generated C code. If you use several scheduler, you may want to use different headers for each one. +##### postCustomCName (default = "") + +Name of custom header in generated C code coming after all of the other includes. + ##### genericNodeCName (default = "GenericNodes.h") Name of GenericNodes header in generated C code. If you use several scheduler, you may want to use different headers for each one. @@ -261,6 +273,14 @@ Name of scheduler cpp and header in generated C code. If you use several schedul If the option is set to `xxx`, the names generated will be `xxx.cpp` and `xxx.h` +##### CAPI (default = True) + +By default, the scheduler function is callable from C. When false, it is a standard C++ API. + +##### CMSISDSP (default = True) + +If you don't use any of the datatypes or functions of the CMSIS-DSP, you don't need to include the `arm_math.h` in the scheduler file. This option can thus be set to `False`. + #### Options for Python code generation only ##### pyOptionalArgs (default = "") diff --git a/ComputeGraph/examples/example1/graph.py b/ComputeGraph/examples/example1/graph.py index 76bbf3e5..29cd45fc 100644 --- a/ComputeGraph/examples/example1/graph.py +++ b/ComputeGraph/examples/example1/graph.py @@ -63,7 +63,13 @@ print("Schedule length = %d" % sched.scheduleLength) print("Memory usage %d bytes" % sched.memory) # -#conf.codeArray=True + +#conf.postCustomCName = "post.h" +#conf.CAPI = True +#conf.prefix="global" +#conf.dumpFIFO = True +#conf.CMSISDSP = False +#conf.switchCase = False sched.ccode("generated",conf) with open("test.dot","w") as f: diff --git a/cmsisdsp/cg/static/scheduler/config.py b/cmsisdsp/cg/static/scheduler/config.py index fea3e427..197e808c 100644 --- a/cmsisdsp/cg/static/scheduler/config.py +++ b/cmsisdsp/cg/static/scheduler/config.py @@ -107,6 +107,9 @@ class Configuration: self.customCName = "custom.h" self.customPythonName = "custom" + # Name of post custom files + self.postCustomCName = "" + # Name of generic nodes headers self.genericNodeCName = "GenericNodes.h" @@ -114,6 +117,12 @@ class Configuration: self.schedulerCFileName = "scheduler" self.schedulerPythonFileName = "sched" + # True is C API for the scheduler + self.CAPI = True + + # By default arm_math.h is included + self.CMSISDSP = True + @property def debug(self): return (self.debugLimit > 0) diff --git a/cmsisdsp/cg/static/scheduler/templates/code.h b/cmsisdsp/cg/static/scheduler/templates/code.h index 461f1865..175cee3e 100644 --- a/cmsisdsp/cg/static/scheduler/templates/code.h +++ b/cmsisdsp/cg/static/scheduler/templates/code.h @@ -14,10 +14,12 @@ The support classes and code is covered by CMSIS-DSP license. {% if config.cOptionalArgs %},{{config.cOptionalArgs}}{% endif %} {% endmacro -%} +{% if config.CAPI -%} #ifdef __cplusplus extern "C" { #endif +{% endif %} {% if config.eventRecorder %} #include "EventRecorder.h" @@ -32,9 +34,11 @@ extern "C" extern uint32_t {{config.schedName}}(int *error{{optionalargs()}}); +{% if config.CAPI -%} #ifdef __cplusplus } #endif +{% endif %} #endif diff --git a/cmsisdsp/cg/static/scheduler/templates/codeArray.cpp b/cmsisdsp/cg/static/scheduler/templates/codeArray.cpp index 2874431b..a7ee0a10 100644 --- a/cmsisdsp/cg/static/scheduler/templates/codeArray.cpp +++ b/cmsisdsp/cg/static/scheduler/templates/codeArray.cpp @@ -11,11 +11,16 @@ The support classes and code is covered by CMSIS-DSP license. #define DEBUGSCHED 1 {% endif %} +{% if config.CMSISDSP -%} #include "arm_math.h" +{% endif %} #include "{{config.customCName}}" #include "{{config.genericNodeCName}}" #include "{{config.appNodesCName}}" #include "{{config.schedulerCFileName}}.h" +{% if config.postCustomCName -%} +#include "{{config.postCustomCName}}" +{% endif %} {% include "defineConfig.h" %} diff --git a/cmsisdsp/cg/static/scheduler/templates/commonc.cpp b/cmsisdsp/cg/static/scheduler/templates/commonc.cpp index 41f9abb9..fcb9480a 100644 --- a/cmsisdsp/cg/static/scheduler/templates/commonc.cpp +++ b/cmsisdsp/cg/static/scheduler/templates/commonc.cpp @@ -11,11 +11,16 @@ The support classes and code is covered by CMSIS-DSP license. #define DEBUGSCHED 1 {% endif %} +{% if config.CMSISDSP -%} #include "arm_math.h" +{% endif %} #include "{{config.customCName}}" #include "{{config.genericNodeCName}}" #include "{{config.appNodesCName}}" #include "{{config.schedulerCFileName}}.h" +{% if config.postCustomCName -%} +#include "{{config.postCustomCName}}" +{% endif %} {% include "defineConfig.h" %} diff --git a/cmsisdsp/version.py b/cmsisdsp/version.py index ee1fe1bf..e551dabb 100755 --- a/cmsisdsp/version.py +++ b/cmsisdsp/version.py @@ -1,2 +1,2 @@ # Python wrapper version -__version__ = "1.9.1" +__version__ = "1.9.2"