From: Jakob Gruber Date: Mon, 10 Sep 2012 10:22:57 +0000 (+0200) Subject: misc: Move avr_mcu_section.h to sim/avr X-Git-Tag: v1.0~3 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=099905d65703d7ed3a1ae97cf5fd9eae28e03aa8;p=sx%2Fsimavr.git misc: Move avr_mcu_section.h to sim/avr Since sim_elf.h includes avr_mcu_section.h, it needs to reference a path which works both during simavr builds, and compilation of external programs including sim_elf.h. Adding the avr/ subdirectory to pkg-config cflags is not desired, to make sure it's clear that header is shared between the sim and the firmware. --- diff --git a/Makefile.common b/Makefile.common index e019689..178c3c9 100644 --- a/Makefile.common +++ b/Makefile.common @@ -106,7 +106,7 @@ endif -ffunction-sections -fdata-sections \ -Wl,--relax,--gc-sections \ -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \ - -I../include -I../../include \ + -I../simavr/sim/avr -I../../simavr/sim/avr \ ${^} -o ${@} @${AVR}size ${@}|sed '1d' diff --git a/include/avr_mcu_section.h b/include/avr_mcu_section.h deleted file mode 100644 index fca11c6..0000000 --- a/include/avr_mcu_section.h +++ /dev/null @@ -1,200 +0,0 @@ -/* - avr_mcu_section.h - - Copyright 2008, 2009 Michel Pollet - - This file is part of simavr. - - simavr is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - simavr is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with simavr. If not, see . - */ - -#ifndef __AVR_MCU_SECTION_H__ -#define __AVR_MCU_SECTION_H__ - -/* - * This header is used to pass "parameters" to the programmer or the simulator, - * it tags the ELF file with a section that contains parameters about the physical - * AVR this was compiled for, including the speed, model, and signature bytes. - * - * A programmer software can read this and verify fuses values for example, and a - * simulator can instanciate the proper "model" of AVR, the speed and so on without - * command line parameters. - * - * Exemple of use: - * - * #include "avr_mcu_section.h" - * AVR_MCU(F_CPU, "atmega88"); - * - */ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - AVR_MMCU_TAG = 0, - AVR_MMCU_TAG_NAME, - AVR_MMCU_TAG_FREQUENCY, - AVR_MMCU_TAG_VCC, - AVR_MMCU_TAG_AVCC, - AVR_MMCU_TAG_AREF, - AVR_MMCU_TAG_LFUSE, - AVR_MMCU_TAG_HFUSE, - AVR_MMCU_TAG_EFUSE, - AVR_MMCU_TAG_SIGNATURE, - AVR_MMCU_TAG_SIMAVR_COMMAND, - AVR_MMCU_TAG_SIMAVR_CONSOLE, - AVR_MMCU_TAG_VCD_FILENAME, - AVR_MMCU_TAG_VCD_PERIOD, - AVR_MMCU_TAG_VCD_TRACE, -}; - -enum { - SIMAVR_CMD_NONE = 0, - SIMAVR_CMD_VCD_START_TRACE, - SIMAVR_CMD_VCD_STOP_TRACE, - SIMAVR_CMD_UART_LOOPBACK, -}; - -#if __AVR__ - -#define _MMCU_ __attribute__((section(".mmcu"))) -struct avr_mmcu_long_t { - uint8_t tag; - uint8_t len; - uint32_t val; -} __attribute__((__packed__)); - -struct avr_mmcu_string_t { - uint8_t tag; - uint8_t len; - char string[]; -} __attribute__((__packed__)); - -struct avr_mmcu_addr_t { - uint8_t tag; - uint8_t len; - void * what; -} __attribute__((__packed__)); - -struct avr_mmcu_vcd_trace_t { - uint8_t tag; - uint8_t len; - uint8_t mask; - void * what; - char name[]; -} __attribute__((__packed__)); - -#define AVR_MCU_STRING(_tag, _str) \ - const struct avr_mmcu_string_t _##_tag _MMCU_ = {\ - .tag = _tag,\ - .len = sizeof(_str),\ - .string = _str,\ - } - -#define AVR_MCU_LONG(_tag, _val) \ - const struct avr_mmcu_long_t _##_tag _MMCU_ = {\ - .tag = _tag,\ - .len = sizeof(uint32_t),\ - .val = _val,\ - } - -#define AVR_MCU_BYTE(_tag, _val) \ - const uint8_t _##_tag _MMCU_ = { _tag, 1, _val } - -/*! - * This Macro allows you to specify traces for the VCD file output - * engine. This specifies a default header, and let you fill in the - * relevant bits. - * Example: - * const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = { - * { AVR_MCU_VCD_SYMBOL("UDR0"), .what = (void*)&UDR0, }, - * { AVR_MCU_VCD_SYMBOL("UDRE0"), .mask = (1 << UDRE0), .what = (void*)&UCSR0A, }, - * }; - * This structure will automatically tell simavr to add a VCD trace - * for the UART register, and the UDRE0 bit, so you can trace exactly - * the timing of the changed using gtkwave. - */ -#define AVR_MCU_VCD_SYMBOL(_name) \ - .tag = AVR_MMCU_TAG_VCD_TRACE, \ - .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2 + sizeof(_name),\ - .name = _name - -/*! - * Specifies the name and wanted period (in usec) for a VCD file - * this is not mandatory for the VCD output to work, if this tag - * is not used, a VCD file will still be created with default values - */ -#define AVR_MCU_VCD_FILE(_name, _period) \ - AVR_MCU_STRING(AVR_MMCU_TAG_VCD_FILENAME, _name);\ - AVR_MCU_LONG(AVR_MMCU_TAG_VCD_PERIOD, _period) - -/*! - * It is possible to send "commands" to simavr from the - * firmware itself. For this to work you need to specify - * an IO register that is to be used for a write-only - * bridge. A favourite is one of the usual "GPIO register" - * that most (all ?) AVR have. - * See definition of SIMAVR_CMD_* to see what commands can - * be used from your firmware. - */ -#define AVR_MCU_SIMAVR_COMMAND(_register) \ - const struct avr_mmcu_addr_t _simavr_command_register _MMCU_ = {\ - .tag = AVR_MMCU_TAG_SIMAVR_COMMAND,\ - .len = sizeof(void *),\ - .what = (void*)_register, \ - } -/*! - * Similar to AVR_MCU_SIMAVR_COMMAND, The CONSOLE allows the AVR code - * to declare a register (typically a GPIO register, but any unused - * register can work...) that will allow printing on the host's console - * without using a UART to do debug. - */ -#define AVR_MCU_SIMAVR_CONSOLE(_register) \ - const struct avr_mmcu_addr_t _simavr_command_register _MMCU_ = {\ - .tag = AVR_MMCU_TAG_SIMAVR_CONSOLE,\ - .len = sizeof(void *),\ - .what = (void*)_register, \ - } - -/*! - * This tag allows you to specify the voltages used by your board - * It is optional in most cases, but you will need it if you use - * ADC module's IRQs. Not specifying it in this case might lead - * to a divide-by-zero crash. - * The units are Volts*1000 (millivolts) - */ -#define AVR_MCU_VOLTAGES(_vcc, _avcc, _aref) \ - AVR_MCU_LONG(AVR_MMCU_TAG_VCC, (_vcc));\ - AVR_MCU_LONG(AVR_MMCU_TAG_AVCC, (_avcc));\ - AVR_MCU_LONG(AVR_MMCU_TAG_AREF, (_aref)); - -/*! - * This the has to be used if you want to add other tags to the .mmcu section - * the _mmcu symbol is used as an anchor to make sure it stays linked in. - */ -#define AVR_MCU(_speed, _name) \ - const uint8_t _mmcu[2] _MMCU_ = { AVR_MMCU_TAG, 0 }; \ - AVR_MCU_STRING(AVR_MMCU_TAG_NAME, _name);\ - AVR_MCU_LONG(AVR_MMCU_TAG_FREQUENCY, _speed) - -#endif /* __AVR__ */ - -#ifdef __cplusplus -}; -#endif - -#endif diff --git a/simavr/Makefile b/simavr/Makefile index 5382e4d..4ade137 100644 --- a/simavr/Makefile +++ b/simavr/Makefile @@ -40,7 +40,6 @@ VPATH += sim IPATH = sim IPATH += . IPATH += ../../shared -IPATH += ../include # # Static library @@ -88,7 +87,7 @@ install : all $(MKDIR) $(DESTDIR)/include/simavr/avr $(INSTALL) -m644 sim/*.h $(DESTDIR)/include/simavr/ $(INSTALL) -m644 sim_core_*.h $(DESTDIR)/include/simavr/ - $(INSTALL) -m644 ../include/*.h $(DESTDIR)/include/simavr/avr/ + $(INSTALL) -m644 sim/avr/*.h $(DESTDIR)/include/simavr/avr/ $(MKDIR) $(DESTDIR)/lib $(INSTALL) ${OBJ}/libsimavr.a $(DESTDIR)/lib/ $(MKDIR) $(DESTDIR)/lib/pkgconfig/ diff --git a/simavr/sim/avr/avr_mcu_section.h b/simavr/sim/avr/avr_mcu_section.h new file mode 100644 index 0000000..fca11c6 --- /dev/null +++ b/simavr/sim/avr/avr_mcu_section.h @@ -0,0 +1,200 @@ +/* + avr_mcu_section.h + + Copyright 2008, 2009 Michel Pollet + + This file is part of simavr. + + simavr is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + simavr is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with simavr. If not, see . + */ + +#ifndef __AVR_MCU_SECTION_H__ +#define __AVR_MCU_SECTION_H__ + +/* + * This header is used to pass "parameters" to the programmer or the simulator, + * it tags the ELF file with a section that contains parameters about the physical + * AVR this was compiled for, including the speed, model, and signature bytes. + * + * A programmer software can read this and verify fuses values for example, and a + * simulator can instanciate the proper "model" of AVR, the speed and so on without + * command line parameters. + * + * Exemple of use: + * + * #include "avr_mcu_section.h" + * AVR_MCU(F_CPU, "atmega88"); + * + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + AVR_MMCU_TAG = 0, + AVR_MMCU_TAG_NAME, + AVR_MMCU_TAG_FREQUENCY, + AVR_MMCU_TAG_VCC, + AVR_MMCU_TAG_AVCC, + AVR_MMCU_TAG_AREF, + AVR_MMCU_TAG_LFUSE, + AVR_MMCU_TAG_HFUSE, + AVR_MMCU_TAG_EFUSE, + AVR_MMCU_TAG_SIGNATURE, + AVR_MMCU_TAG_SIMAVR_COMMAND, + AVR_MMCU_TAG_SIMAVR_CONSOLE, + AVR_MMCU_TAG_VCD_FILENAME, + AVR_MMCU_TAG_VCD_PERIOD, + AVR_MMCU_TAG_VCD_TRACE, +}; + +enum { + SIMAVR_CMD_NONE = 0, + SIMAVR_CMD_VCD_START_TRACE, + SIMAVR_CMD_VCD_STOP_TRACE, + SIMAVR_CMD_UART_LOOPBACK, +}; + +#if __AVR__ + +#define _MMCU_ __attribute__((section(".mmcu"))) +struct avr_mmcu_long_t { + uint8_t tag; + uint8_t len; + uint32_t val; +} __attribute__((__packed__)); + +struct avr_mmcu_string_t { + uint8_t tag; + uint8_t len; + char string[]; +} __attribute__((__packed__)); + +struct avr_mmcu_addr_t { + uint8_t tag; + uint8_t len; + void * what; +} __attribute__((__packed__)); + +struct avr_mmcu_vcd_trace_t { + uint8_t tag; + uint8_t len; + uint8_t mask; + void * what; + char name[]; +} __attribute__((__packed__)); + +#define AVR_MCU_STRING(_tag, _str) \ + const struct avr_mmcu_string_t _##_tag _MMCU_ = {\ + .tag = _tag,\ + .len = sizeof(_str),\ + .string = _str,\ + } + +#define AVR_MCU_LONG(_tag, _val) \ + const struct avr_mmcu_long_t _##_tag _MMCU_ = {\ + .tag = _tag,\ + .len = sizeof(uint32_t),\ + .val = _val,\ + } + +#define AVR_MCU_BYTE(_tag, _val) \ + const uint8_t _##_tag _MMCU_ = { _tag, 1, _val } + +/*! + * This Macro allows you to specify traces for the VCD file output + * engine. This specifies a default header, and let you fill in the + * relevant bits. + * Example: + * const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = { + * { AVR_MCU_VCD_SYMBOL("UDR0"), .what = (void*)&UDR0, }, + * { AVR_MCU_VCD_SYMBOL("UDRE0"), .mask = (1 << UDRE0), .what = (void*)&UCSR0A, }, + * }; + * This structure will automatically tell simavr to add a VCD trace + * for the UART register, and the UDRE0 bit, so you can trace exactly + * the timing of the changed using gtkwave. + */ +#define AVR_MCU_VCD_SYMBOL(_name) \ + .tag = AVR_MMCU_TAG_VCD_TRACE, \ + .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2 + sizeof(_name),\ + .name = _name + +/*! + * Specifies the name and wanted period (in usec) for a VCD file + * this is not mandatory for the VCD output to work, if this tag + * is not used, a VCD file will still be created with default values + */ +#define AVR_MCU_VCD_FILE(_name, _period) \ + AVR_MCU_STRING(AVR_MMCU_TAG_VCD_FILENAME, _name);\ + AVR_MCU_LONG(AVR_MMCU_TAG_VCD_PERIOD, _period) + +/*! + * It is possible to send "commands" to simavr from the + * firmware itself. For this to work you need to specify + * an IO register that is to be used for a write-only + * bridge. A favourite is one of the usual "GPIO register" + * that most (all ?) AVR have. + * See definition of SIMAVR_CMD_* to see what commands can + * be used from your firmware. + */ +#define AVR_MCU_SIMAVR_COMMAND(_register) \ + const struct avr_mmcu_addr_t _simavr_command_register _MMCU_ = {\ + .tag = AVR_MMCU_TAG_SIMAVR_COMMAND,\ + .len = sizeof(void *),\ + .what = (void*)_register, \ + } +/*! + * Similar to AVR_MCU_SIMAVR_COMMAND, The CONSOLE allows the AVR code + * to declare a register (typically a GPIO register, but any unused + * register can work...) that will allow printing on the host's console + * without using a UART to do debug. + */ +#define AVR_MCU_SIMAVR_CONSOLE(_register) \ + const struct avr_mmcu_addr_t _simavr_command_register _MMCU_ = {\ + .tag = AVR_MMCU_TAG_SIMAVR_CONSOLE,\ + .len = sizeof(void *),\ + .what = (void*)_register, \ + } + +/*! + * This tag allows you to specify the voltages used by your board + * It is optional in most cases, but you will need it if you use + * ADC module's IRQs. Not specifying it in this case might lead + * to a divide-by-zero crash. + * The units are Volts*1000 (millivolts) + */ +#define AVR_MCU_VOLTAGES(_vcc, _avcc, _aref) \ + AVR_MCU_LONG(AVR_MMCU_TAG_VCC, (_vcc));\ + AVR_MCU_LONG(AVR_MMCU_TAG_AVCC, (_avcc));\ + AVR_MCU_LONG(AVR_MMCU_TAG_AREF, (_aref)); + +/*! + * This the has to be used if you want to add other tags to the .mmcu section + * the _mmcu symbol is used as an anchor to make sure it stays linked in. + */ +#define AVR_MCU(_speed, _name) \ + const uint8_t _mmcu[2] _MMCU_ = { AVR_MMCU_TAG, 0 }; \ + AVR_MCU_STRING(AVR_MMCU_TAG_NAME, _name);\ + AVR_MCU_LONG(AVR_MMCU_TAG_FREQUENCY, _speed) + +#endif /* __AVR__ */ + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index d3e6706..1bc169d 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -29,7 +29,7 @@ #include "sim_gdb.h" #include "avr_uart.h" #include "sim_vcd_file.h" -#include "avr_mcu_section.h" +#include "avr/avr_mcu_section.h" #define AVR_KIND_DECL #include "sim_core_decl.h" diff --git a/simavr/sim/sim_elf.h b/simavr/sim/sim_elf.h index 8084873..ed760d5 100644 --- a/simavr/sim/sim_elf.h +++ b/simavr/sim/sim_elf.h @@ -22,7 +22,7 @@ #ifndef __SIM_ELF_H__ #define __SIM_ELF_H__ -#include "avr_mcu_section.h" +#include "avr/avr_mcu_section.h" #ifdef __cplusplus extern "C" {