diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-12-22 23:47:46 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-12-23 17:06:10 -0500 |
commit | fe95ea221b2b88e9cb52a6378ff2018ee752094b (patch) | |
tree | 2223d604cc7d5bdf2c771b05e15834dd418b3823 /src | |
parent | 4e8674d5df46841e68b72b83911b28ec71079bf1 (diff) | |
download | kutter-fe95ea221b2b88e9cb52a6378ff2018ee752094b.tar.gz kutter-fe95ea221b2b88e9cb52a6378ff2018ee752094b.tar.xz kutter-fe95ea221b2b88e9cb52a6378ff2018ee752094b.zip |
build: Define DECL_CONSTANT mechanism for defining exported constants
Add a DECL_CONSTANT macro to allow the firmware to define constants
that are to be exported to the host during the "identify" phase. This
replaces the existing hardcoded mechanism of scanning the Kconfig
header file for certain constants.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/avr/serial.c | 3 | ||||
-rw-r--r-- | src/avr/timer.c | 3 | ||||
-rw-r--r-- | src/command.h | 9 | ||||
-rw-r--r-- | src/sam3x8e/Kconfig | 4 | ||||
-rw-r--r-- | src/sam3x8e/serial.c | 3 | ||||
-rw-r--r-- | src/sam3x8e/timer.c | 3 |
6 files changed, 21 insertions, 4 deletions
diff --git a/src/avr/serial.c b/src/avr/serial.c index bd92f048..6bd88598 100644 --- a/src/avr/serial.c +++ b/src/avr/serial.c @@ -9,6 +9,7 @@ #include "autoconf.h" // CONFIG_SERIAL_BAUD #include "board/io.h" // readb #include "board/misc.h" // console_get_input +#include "command.h" // DECL_CONSTANT #include "sched.h" // DECL_INIT #include "irq.h" // irq_save @@ -22,6 +23,8 @@ static uint8_t transmit_pos, transmit_max; * Serial hardware ****************************************************************/ +DECL_CONSTANT(SERIAL_BAUD, CONFIG_SERIAL_BAUD); + static void serial_init(void) { diff --git a/src/avr/timer.c b/src/avr/timer.c index a7e832bc..3744351d 100644 --- a/src/avr/timer.c +++ b/src/avr/timer.c @@ -16,6 +16,9 @@ * Low level timer code ****************************************************************/ +DECL_CONSTANT(CLOCK_FREQ, F_CPU); +DECL_CONSTANT(MCU, CONFIG_MCU); + // Return the number of clock ticks for a given number of microseconds uint32_t timer_from_us(uint32_t us) diff --git a/src/command.h b/src/command.h index 2bbe37f8..c6d8a69c 100644 --- a/src/command.h +++ b/src/command.h @@ -15,6 +15,10 @@ // Flags for command handler declarations. #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_CONSTANT(NAME, VALUE) + // Send an output message (and declare a static message type for it) #define output(FMT, args...) \ _sendf(_DECL_OUTPUT(FMT) , ##args ) @@ -59,6 +63,11 @@ extern const uint32_t command_identify_size; = "_DECL_COMMAND " __stringify(FUNC) " " __stringify(FLAGS) " " MSG; \ void __visible FUNC(uint32_t*) +#define _DECL_CONSTANT(NAME, VALUE) \ + char __PASTE(_DECLC_ ## NAME ## _, __LINE__) [] \ + __visible __section(".compile_time_request") \ + = "_DECL_CONSTANT " __stringify(NAME) " " __stringify(VALUE) + // Create a compile time request and return a unique (incrementing id) // for that request. #define _DECL_REQUEST_ID(REQUEST, ID_SECTION) ({ \ diff --git a/src/sam3x8e/Kconfig b/src/sam3x8e/Kconfig index 2edc8f7c..00e1f06e 100644 --- a/src/sam3x8e/Kconfig +++ b/src/sam3x8e/Kconfig @@ -6,10 +6,6 @@ config BOARD_DIRECTORY string default "sam3x8e" -config MCU - string - default "sam3x8e" - config CLOCK_FREQ int default 42000000 # 84000000/2 diff --git a/src/sam3x8e/serial.c b/src/sam3x8e/serial.c index 42b92efe..d07fc734 100644 --- a/src/sam3x8e/serial.c +++ b/src/sam3x8e/serial.c @@ -9,6 +9,7 @@ #include "board/gpio.h" // gpio_peripheral #include "board/io.h" // readb #include "board/misc.h" // console_get_input +#include "command.h" // DECL_CONSTANT #include "sam3x8e.h" // UART #include "sched.h" // DECL_INIT #include "irq.h" // irq_save @@ -24,6 +25,8 @@ static uint32_t transmit_pos, transmit_max; * Serial hardware ****************************************************************/ +DECL_CONSTANT(SERIAL_BAUD, CONFIG_SERIAL_BAUD); + static void serial_init(void) { diff --git a/src/sam3x8e/timer.c b/src/sam3x8e/timer.c index ead9c90f..0d3728ed 100644 --- a/src/sam3x8e/timer.c +++ b/src/sam3x8e/timer.c @@ -16,6 +16,9 @@ * Low level timer code ****************************************************************/ +DECL_CONSTANT(CLOCK_FREQ, CONFIG_CLOCK_FREQ); +DECL_CONSTANT(MCU, "sam3x8e"); + // Return the number of clock ticks for a given number of microseconds uint32_t timer_from_us(uint32_t us) |