From 84fd89b8cfb1c4f4bedd94d8f50ab402f878267a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 22 Aug 2019 12:12:21 -0400 Subject: [PATCH] ctr: Add support for multiple integers in DECL_CTR_INT Signed-off-by: Kevin O'Connor --- src/command.h | 10 +++++----- src/ctr.h | 30 +++++++++++++++++------------- src/generic/armcm_boot.h | 4 ++-- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/command.h b/src/command.h index 6cf2ca6b..1edf7c5a 100644 --- a/src/command.h +++ b/src/command.h @@ -16,17 +16,17 @@ #define HF_IN_SHUTDOWN 0x01 // Handler can run even when in emergency stop // Declare a constant exported to the host -#define DECL_CONSTANT(NAME, VALUE) \ - DECL_CTR_INT("_DECL_CONSTANT " NAME, (VALUE)) +#define DECL_CONSTANT(NAME, VALUE) \ + DECL_CTR_INT("_DECL_CONSTANT " NAME, 1, CTR_INT(VALUE)) #define DECL_CONSTANT_STR(NAME, VALUE) \ DECL_CTR("_DECL_CONSTANT_STR " NAME " " VALUE) // Declare an enumeration -#define DECL_ENUMERATION(ENUM, NAME, VALUE) \ - DECL_CTR_INT("_DECL_ENUMERATION " ENUM " " NAME, (VALUE)) +#define DECL_ENUMERATION(ENUM, NAME, VALUE) \ + DECL_CTR_INT("_DECL_ENUMERATION " ENUM " " NAME, 1, CTR_INT(VALUE)) #define DECL_ENUMERATION_RANGE(ENUM, NAME, VALUE, COUNT) \ DECL_CTR_INT("_DECL_ENUMERATION_RANGE " ENUM " " NAME \ - " " __stringify(COUNT), (VALUE)) + " " __stringify(COUNT), 1, CTR_INT(VALUE)) // Send an output message (and declare a static message type for it) #define output(FMT, args...) \ diff --git a/src/ctr.h b/src/ctr.h index 36a7334c..b5b56ee2 100644 --- a/src/ctr.h +++ b/src/ctr.h @@ -14,20 +14,24 @@ static char __PASTE(_DECLS_, __LINE__)[] __attribute__((used)) \ __section(".compile_time_request") = (REQUEST) -// Helper macros for encoding an integer -#define CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0') -#define CTR_INT(V, S) CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f) +// Macro to encode an integer for use with DECL_CTR_INT() +#define _CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0') +#define _CTR_INT(V, S) _CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f) +#define CTR_INT(VALUE) { \ + ' ', (VALUE) < 0 ? '-' : '+', '0', 'x', \ + _CTR_INT((VALUE),28), _CTR_INT((VALUE),24), \ + _CTR_INT((VALUE),20), _CTR_INT((VALUE),16), \ + _CTR_INT((VALUE),12), _CTR_INT((VALUE),8), \ + _CTR_INT((VALUE),4), _CTR_INT((VALUE),0) } // Declare a compile time request with an integer expression -#define DECL_CTR_INT(REQUEST, VALUE) \ - static struct { char _r[sizeof(REQUEST)]; char _v[12]; } \ - __PASTE(_DECLI_, __LINE__) __attribute__((used)) \ - __section(".compile_time_request") = { \ - REQUEST " ", { \ - (VALUE) < 0 ? '-' : '+', '0', 'x', \ - CTR_INT((VALUE),28), CTR_INT((VALUE),24), \ - CTR_INT((VALUE),20), CTR_INT((VALUE),16), \ - CTR_INT((VALUE),12), CTR_INT((VALUE),8), \ - CTR_INT((VALUE),4), CTR_INT((VALUE),0), 0 } } +#define DECL_CTR_INT(REQUEST, PARAM_COUNT, args...) \ + static struct { \ + char _request[sizeof(REQUEST)-1]; \ + char _values[(PARAM_COUNT)][12]; \ + char _end_of_line; \ + } __PASTE(_DECLI_, __LINE__) __attribute__((used)) \ + __section(".compile_time_request") = { \ + (REQUEST), { args }, 0 } #endif // ctr.h diff --git a/src/generic/armcm_boot.h b/src/generic/armcm_boot.h index 10b17e18..a0bfd3f4 100644 --- a/src/generic/armcm_boot.h +++ b/src/generic/armcm_boot.h @@ -4,8 +4,8 @@ #include "ctr.h" // DECL_CTR_INT // Declare an IRQ handler -#define DECL_ARMCM_IRQ(FUNC, NUM) \ - DECL_CTR_INT("DECL_ARMCM_IRQ " __stringify(FUNC), (NUM)) +#define DECL_ARMCM_IRQ(FUNC, NUM) \ + DECL_CTR_INT("DECL_ARMCM_IRQ " __stringify(FUNC), 1, CTR_INT(NUM)) // Statically declare an IRQ handler and run-time enable it #define armcm_enable_irq(FUNC, NUM, PRIORITY) do { \