From 6cfd3f133c4ae7476f5c7da9b3c3973d731ae26b Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Thu, 1 Feb 2018 22:07:34 +0100 Subject: [PATCH] Improve code snippets. Re-work linker stuff. Add new 8-bit target. --- .../chapter05_05-002_template_point.cpp | 1 + .../chapter05_05-003_template_point.cpp | 2 + .../chapter05_06-002_template_point.cpp | 3 + examples/chapter02_02/crt0.s | 6 +- readme.txt | 1 + ref_app/ref_app.sln | 11 +- ref_app/ref_app.vcxproj | 417 +++++++++++++++++- ref_app/ref_app.vcxproj.filters | 69 +++ ref_app/src/mcal/atmega2560/mcal_benchmark.h | 26 ++ ref_app/src/mcal/atmega2560/mcal_cpu.cpp | 18 + ref_app/src/mcal/atmega2560/mcal_cpu.h | 81 ++++ ref_app/src/mcal/atmega2560/mcal_gpt.cpp | 80 ++++ ref_app/src/mcal/atmega2560/mcal_gpt.h | 44 ++ ref_app/src/mcal/atmega2560/mcal_irq.cpp | 13 + ref_app/src/mcal/atmega2560/mcal_irq.h | 24 + ref_app/src/mcal/atmega2560/mcal_led.cpp | 16 + ref_app/src/mcal/atmega2560/mcal_led.h | 57 +++ ref_app/src/mcal/atmega2560/mcal_osc.cpp | 12 + ref_app/src/mcal/atmega2560/mcal_osc.h | 21 + ref_app/src/mcal/atmega2560/mcal_port.cpp | 12 + ref_app/src/mcal/atmega2560/mcal_port.h | 71 +++ ref_app/src/mcal/atmega2560/mcal_pwm.cpp | 11 + ref_app/src/mcal/atmega2560/mcal_pwm.h | 21 + ref_app/src/mcal/atmega2560/mcal_reg.h | 79 ++++ ref_app/src/mcal/atmega2560/mcal_reg_access.h | 15 + ref_app/src/mcal/atmega2560/mcal_ser.h | 21 + ref_app/src/mcal/atmega2560/mcal_spi.cpp | 221 ++++++++++ ref_app/src/mcal/atmega2560/mcal_spi.h | 60 +++ ref_app/src/mcal/atmega2560/mcal_wdg.cpp | 78 ++++ ref_app/src/mcal/atmega2560/mcal_wdg.h | 34 ++ ref_app/src/mcal/avr/mcal_gpt.cpp | 3 +- ref_app/target.vcxproj | 52 +++ ref_app/target.vcxproj.filters | 30 ++ .../micros/atmega2560/make/atmega2560.ld | 123 ++++++ .../atmega2560/make/atmega2560_files.gmk | 18 + .../atmega2560/make/atmega2560_flags.gmk | 27 ++ .../target/micros/atmega2560/startup/crt0.cpp | 63 +++ .../atmega2560/startup/crt0_init_ram.cpp | 59 +++ .../target/micros/atmega2560/startup/crt1.cpp | 46 ++ .../micros/atmega2560/startup/int_vect.cpp | 101 +++++ ref_app/target/micros/avr/make/avr.ld | 5 +- .../target/micros/avr/startup/int_vect.cpp | 65 +-- .../target/micros/stm32f100/make/stm32f100.ld | 4 +- 43 files changed, 2078 insertions(+), 43 deletions(-) create mode 100644 ref_app/src/mcal/atmega2560/mcal_benchmark.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_cpu.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_cpu.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_gpt.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_gpt.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_irq.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_irq.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_led.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_led.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_osc.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_osc.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_port.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_port.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_pwm.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_pwm.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_reg.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_reg_access.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_ser.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_spi.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_spi.h create mode 100644 ref_app/src/mcal/atmega2560/mcal_wdg.cpp create mode 100644 ref_app/src/mcal/atmega2560/mcal_wdg.h create mode 100644 ref_app/target/micros/atmega2560/make/atmega2560.ld create mode 100644 ref_app/target/micros/atmega2560/make/atmega2560_files.gmk create mode 100644 ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk create mode 100644 ref_app/target/micros/atmega2560/startup/crt0.cpp create mode 100644 ref_app/target/micros/atmega2560/startup/crt0_init_ram.cpp create mode 100644 ref_app/target/micros/atmega2560/startup/crt1.cpp create mode 100644 ref_app/target/micros/atmega2560/startup/int_vect.cpp diff --git a/code_snippets/chapter05/chapter05_05-002_template_point.cpp b/code_snippets/chapter05/chapter05_05-002_template_point.cpp index e03df5953..5147fe255 100644 --- a/code_snippets/chapter05/chapter05_05-002_template_point.cpp +++ b/code_snippets/chapter05/chapter05_05-002_template_point.cpp @@ -10,6 +10,7 @@ #include #include +// Both template parameters have default types. template // OK class point diff --git a/code_snippets/chapter05/chapter05_05-003_template_point.cpp b/code_snippets/chapter05/chapter05_05-003_template_point.cpp index 92462c158..4db7c5dad 100644 --- a/code_snippets/chapter05/chapter05_05-003_template_point.cpp +++ b/code_snippets/chapter05/chapter05_05-003_template_point.cpp @@ -10,6 +10,8 @@ #include #include +// Only the second template parameter +// has a default types. template // OK class point diff --git a/code_snippets/chapter05/chapter05_06-002_template_point.cpp b/code_snippets/chapter05/chapter05_06-002_template_point.cpp index 38ba044e1..8bf8fdfb8 100644 --- a/code_snippets/chapter05/chapter05_06-002_template_point.cpp +++ b/code_snippets/chapter05/chapter05_06-002_template_point.cpp @@ -23,6 +23,9 @@ class point my_y(y) { } }; +// A partial specialization of the point +// class with x-axis having type std::uint8_t. + template class point { diff --git a/examples/chapter02_02/crt0.s b/examples/chapter02_02/crt0.s index a672b4384..195bdd41d 100644 --- a/examples/chapter02_02/crt0.s +++ b/examples/chapter02_02/crt0.s @@ -24,11 +24,11 @@ isr_vectors: __my_startup: eor r1, r1 - out 0x3f, r1 ; SREG + out 0x3f, r1 ; sreg ldi r28,lo8(__initial_stack_pointer) ldi r29,hi8(__initial_stack_pointer) - out 0x3E, r29 ; SPH - out 0x3D, r28 ; SPL + out 0x3e, r29 ; sph + out 0x3d, r28 ; spl ; Initialize the rom-to-ram data call __do_copy_data diff --git a/readme.txt b/readme.txt index 62fee08d0..60d5691bd 100644 --- a/readme.txt +++ b/readme.txt @@ -24,6 +24,7 @@ Supported Targets in the Reference Application The reference application supports the following targets: * Win32 in both Release and Debug modes * ATMEL(R) AVR(R) Atmega328P + * ATMEL(R) AVR(R) Atmega2560 * ST Microelectronics(R) STM32F100 ARM(R) Cortex(TM)-M3 * ST Microelectronics(R) STM32L152 ARM(R) Cortex(TM)-M3 * ST Microelectronics(R) STM32F407 ARM(R) Cortex(TM)-M4 diff --git a/ref_app/ref_app.sln b/ref_app/ref_app.sln index c7e1cb9e4..abd7e8422 100644 --- a/ref_app/ref_app.sln +++ b/ref_app/ref_app.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2026 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ref_app", "ref_app.vcxproj", "{C8B59726-9319-45C3-8F11-F9F388FB6A2C}" EndProject @@ -12,6 +12,7 @@ Global Debug|Win32 = Debug|Win32 Release|Win32 = Release|Win32 target am335x|Win32 = target am335x|Win32 + target atmega2560|Win32 = target atmega2560|Win32 target avr|Win32 = target avr|Win32 target bcm2835_raspi_b|Win32 = target bcm2835_raspi_b|Win32 target pic32mx795fx|Win32 = target pic32mx795fx|Win32 @@ -28,6 +29,7 @@ Global {C8B59726-9319-45C3-8F11-F9F388FB6A2C}.Release|Win32.ActiveCfg = Release|Win32 {C8B59726-9319-45C3-8F11-F9F388FB6A2C}.Release|Win32.Build.0 = Release|Win32 {C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target am335x|Win32.ActiveCfg = Release|Win32 + {C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target atmega2560|Win32.ActiveCfg = target atmega2560|Win32 {C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target avr|Win32.ActiveCfg = Release|Win32 {C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target bcm2835_raspi_b|Win32.ActiveCfg = Release|Win32 {C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target pic32mx795fx|Win32.ActiveCfg = Release|Win32 @@ -41,6 +43,8 @@ Global {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.Release|Win32.ActiveCfg = target avr|Win32 {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target am335x|Win32.ActiveCfg = target am335x|Win32 {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target am335x|Win32.Build.0 = target am335x|Win32 + {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target atmega2560|Win32.ActiveCfg = target atmega2560|Win32 + {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target atmega2560|Win32.Build.0 = target atmega2560|Win32 {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target avr|Win32.ActiveCfg = target avr|Win32 {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target avr|Win32.Build.0 = target avr|Win32 {30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target bcm2835_raspi_b|Win32.ActiveCfg = target bcm2835_raspi_b|Win32 @@ -63,4 +67,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B366D59E-C623-4FD4-BF1E-302144448A9E} + EndGlobalSection EndGlobal diff --git a/ref_app/ref_app.vcxproj b/ref_app/ref_app.vcxproj index 66fad433f..0bde3666e 100644 --- a/ref_app/ref_app.vcxproj +++ b/ref_app/ref_app.vcxproj @@ -9,6 +9,10 @@ Release Win32 + + target atmega2560 + Win32 + {C8B59726-9319-45C3-8F11-F9F388FB6A2C} @@ -30,12 +34,17 @@ Application NotSet - v120 + v141 + + + Application + NotSet + v141 Application NotSet - v120 + v141 @@ -43,6 +52,9 @@ + + + @@ -53,14 +65,20 @@ $(SolutionDir)tmp\$(Configuration)\ true $(SolutionDir)tmp\$(Configuration)\ + $(SolutionDir)tmp\$(Configuration)\ $(SolutionDir)tmp\$(Configuration)\ + $(SolutionDir)tmp\$(Configuration)\ false + false AllRules.ruleset AllRules.ruleset + AllRules.ruleset + + $(SolutionDir)/src;$(SolutionDir)/src/mcal/win32;$(SolutionDir)/src/util/STL_C++XX_stdfloat;$(IncludePath) @@ -68,6 +86,9 @@ $(SolutionDir)/src;$(SolutionDir)/src/mcal/win32;$(SolutionDir)/src/util/STL_C++XX_stdfloat;$(IncludePath) + + $(SolutionDir)/src;$(SolutionDir)/src/mcal/win32;$(SolutionDir)/src/util/STL_C++XX_stdfloat;$(IncludePath) + Disabled @@ -115,38 +136,70 @@ MachineX86 + + + MaxSpeed + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;_SECURE_SCL=0;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level3 + ProgramDatabase + 4351;4996 + stdcpp17 + + + $(SolutionDir)Tmp\$(Configuration)\$(ProjectName).exe + true + Console + true + true + MachineX86 + + true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true @@ -162,26 +215,31 @@ Document true true + true Document true true + true Document true true + true Document true true + true Document true true + true @@ -190,383 +248,487 @@ true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true + + + + + + + + + true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true @@ -581,26 +743,32 @@ true true + true true true + true true true + true false false + false false false + false true true + true @@ -618,417 +786,533 @@ true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true - + true + + + + + + + + + + + + + + true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true @@ -1036,373 +1320,471 @@ true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true @@ -1434,6 +1816,7 @@ true true + true @@ -1441,6 +1824,7 @@ true true + true @@ -1465,110 +1849,137 @@ true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true true true + true diff --git a/ref_app/ref_app.vcxproj.filters b/ref_app/ref_app.vcxproj.filters index 0cf4d005c..62b7506f9 100644 --- a/ref_app/ref_app.vcxproj.filters +++ b/ref_app/ref_app.vcxproj.filters @@ -149,6 +149,9 @@ {62976de0-9569-4a72-af6f-e6c489a1dfb0} + + {8fef6100-47d4-49d0-9a34-3e060e206eea} + @@ -493,6 +496,33 @@ src\mcal\stm32l152 + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + @@ -1302,6 +1332,45 @@ src\math\functions + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + + + src\mcal\atmega2560 + diff --git a/ref_app/src/mcal/atmega2560/mcal_benchmark.h b/ref_app/src/mcal/atmega2560/mcal_benchmark.h new file mode 100644 index 000000000..e573589de --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_benchmark.h @@ -0,0 +1,26 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2014. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_BENCHMARK_2014_04_16_H_ + #define MCAL_BENCHMARK_2014_04_16_H_ + + #include + #include + #include + + namespace mcal + { + namespace benchmark + { + typedef mcal::port::port_pin benchmark_port_type; + } + } + +#endif // MCAL_BENCHMARK_2014_04_16_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_cpu.cpp b/ref_app/src/mcal/atmega2560/mcal_cpu.cpp new file mode 100644 index 000000000..563fa3ca9 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_cpu.cpp @@ -0,0 +1,18 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include +#include +#include + +void mcal::cpu::init() +{ + mcal::wdg::init(nullptr); + mcal::port::init(nullptr); + mcal::osc::init(nullptr); +} diff --git a/ref_app/src/mcal/atmega2560/mcal_cpu.h b/ref_app/src/mcal/atmega2560/mcal_cpu.h new file mode 100644 index 000000000..3e86b4894 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_cpu.h @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_CPU_2009_02_14_H_ + #define MCAL_CPU_2009_02_14_H_ + + #if defined(__cplusplus) + #include + #else + #include + #endif + + #include + + #if defined(__cplusplus) + namespace mcal + { + namespace cpu + { + void init(); + + inline void post_init() { } + + inline void nop() { asm volatile("nop"); } + } + } + #endif + + #if defined(__cplusplus) + extern "C" + { + #endif + + inline uint8_t mcal_cpu_read_program_memory_byte(const uint8_t* pointer_to_program_memory) + { + const uint16_t memory_address = (uint16_t) pointer_to_program_memory; + + return pgm_read_byte(memory_address); + } + + inline uint16_t mcal_cpu_read_program_memory_word (const uint8_t* pointer_to_program_memory) + { + const uint16_t memory_address = (uint16_t) pointer_to_program_memory; + + return pgm_read_word(memory_address); + } + + inline uint32_t mcal_cpu_read_program_memory_dword(const uint8_t* pointer_to_program_memory) + { + const uint16_t memory_address = (uint16_t) pointer_to_program_memory; + + return pgm_read_dword(memory_address); + } + + inline uint64_t mcal_cpu_read_program_memory_qword(const uint8_t* pointer_to_program_memory) + { + const uint16_t memory_address = (uint16_t) pointer_to_program_memory; + + uint64_t result_of_read; + + *(((uint8_t*) &result_of_read) + 0U) = pgm_read_byte(memory_address + 0U); + *(((uint8_t*) &result_of_read) + 1U) = pgm_read_byte(memory_address + 1U); + *(((uint8_t*) &result_of_read) + 2U) = pgm_read_byte(memory_address + 2U); + *(((uint8_t*) &result_of_read) + 3U) = pgm_read_byte(memory_address + 3U); + *(((uint8_t*) &result_of_read) + 4U) = pgm_read_byte(memory_address + 4U); + *(((uint8_t*) &result_of_read) + 5U) = pgm_read_byte(memory_address + 5U); + *(((uint8_t*) &result_of_read) + 6U) = pgm_read_byte(memory_address + 6U); + *(((uint8_t*) &result_of_read) + 7U) = pgm_read_byte(memory_address + 7U); + + return result_of_read; + } + + #if defined(__cplusplus) + } + #endif + +#endif // MCAL_CPU_2009_02_14_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_gpt.cpp b/ref_app/src/mcal/atmega2560/mcal_gpt.cpp new file mode 100644 index 000000000..058feb184 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_gpt.cpp @@ -0,0 +1,80 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2015. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include + +namespace +{ + // The one (and only one) system tick. + volatile mcal::gpt::value_type system_tick; + + bool& gpt_is_initialized() __attribute__((used, noinline)); + + bool& gpt_is_initialized() + { + static bool is_init = bool(); + + return is_init; + } +} + +extern "C" +void __vector_23() __attribute__((section(".isr_handlers"),signal, used, externally_visible)); + +void __vector_23() +{ + // Increment the 32-bit system tick with 0x80, representing 128 microseconds. + system_tick += static_cast(0x80U); +} + +void mcal::gpt::init(const config_type*) +{ + if(gpt_is_initialized() == false) + { + // Clear the timer0 overflow flag. + mcal::reg::access::reg_set(); + + // Enable the timer0 overflow interrupt. + mcal::reg::access::reg_set(); + + // Set the timer0 clock source to f_osc/8 = 2MHz and begin counting. + mcal::reg::access::reg_set(); + + // Set the is-initialized indication flag. + gpt_is_initialized() = true; + } +} + +mcal::gpt::value_type mcal::gpt::secure::get_time_elapsed() +{ + if(gpt_is_initialized()) + { + // Return the system tick using a multiple read to ensure data consistency. + + typedef std::uint8_t timer_address_type; + typedef std::uint8_t timer_register_type; + + // Do the first read of the timer0 counter and the system tick. + const timer_register_type tim0_cnt_1 = mcal::reg::access::reg_get(); + const mcal::gpt::value_type sys_tick_1 = system_tick; + + // Do the second read of the timer0 counter. + const timer_register_type tim0_cnt_2 = mcal::reg::access::reg_get(); + + // Perform the consistency check. + const mcal::gpt::value_type consistent_microsecond_tick + = ((tim0_cnt_2 >= tim0_cnt_1) ? mcal::gpt::value_type(sys_tick_1 | std::uint8_t(tim0_cnt_1 >> 1U)) + : mcal::gpt::value_type(system_tick | std::uint8_t(tim0_cnt_2 >> 1U))); + + return consistent_microsecond_tick; + } + else + { + return mcal::gpt::value_type(0U); + } +} diff --git a/ref_app/src/mcal/atmega2560/mcal_gpt.h b/ref_app/src/mcal/atmega2560/mcal_gpt.h new file mode 100644 index 000000000..7ac3c2eb2 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_gpt.h @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_GPT_2011_10_20_H_ + #define MCAL_GPT_2011_10_20_H_ + + #include + #include + + #include + + // Forward declaration of the util::timer template class. + namespace util + { + template + class timer; + } + + namespace mcal + { + namespace gpt + { + typedef void config_type; + typedef std::uint32_t value_type; + + void init(const config_type*); + + class secure final + { + static value_type get_time_elapsed(); + + friend std::chrono::high_resolution_clock::time_point std::chrono::high_resolution_clock::now() UTIL_NOEXCEPT; + + template + friend class util::timer; + }; + } + } + +#endif // MCAL_GPT_2011_10_20_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_irq.cpp b/ref_app/src/mcal/atmega2560/mcal_irq.cpp new file mode 100644 index 000000000..f9f983c47 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_irq.cpp @@ -0,0 +1,13 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +void mcal::irq::init(const config_type*) +{ + mcal::irq::enable_all(); +} diff --git a/ref_app/src/mcal/atmega2560/mcal_irq.h b/ref_app/src/mcal/atmega2560/mcal_irq.h new file mode 100644 index 000000000..4f650ed54 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_irq.h @@ -0,0 +1,24 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_IRQ_2010_04_10_H_ + #define MCAL_IRQ_2010_04_10_H_ + + namespace mcal + { + namespace irq + { + typedef void config_type; + + void init(const config_type*); + + inline void enable_all () { asm volatile("sei"); } + inline void disable_all() { asm volatile("cli"); } + } + } + +#endif // MCAL_IRQ_2010_04_10_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_led.cpp b/ref_app/src/mcal/atmega2560/mcal_led.cpp new file mode 100644 index 000000000..3600a46db --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_led.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +namespace mcal +{ + namespace led + { + const led_type led0; + } +} diff --git a/ref_app/src/mcal/atmega2560/mcal_led.h b/ref_app/src/mcal/atmega2560/mcal_led.h new file mode 100644 index 000000000..b5927e5ea --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_led.h @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_LED_2010_09_14_H_ + #define MCAL_LED_2010_09_14_H_ + + #include + #include + #include + + namespace mcal + { + namespace led + { + template + class led final : private util::noncopyable + { + public: + led() + { + // Set the port pin value to low. + port_pin_type::set_pin_low(); + + // Set the port pin direction to output. + port_pin_type::set_direction_output(); + } + + static void toggle() + { + // Toggle the LED. + port_pin_type::toggle_pin(); + } + + private: + typedef mcal::port::port_pin port_pin_type; + }; + + typedef led led_type; + + extern const led_type led0; + } + } + +#endif // MCAL_LED_2010_09_14_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_osc.cpp b/ref_app/src/mcal/atmega2560/mcal_osc.cpp new file mode 100644 index 000000000..14787d20a --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_osc.cpp @@ -0,0 +1,12 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +void mcal::osc::init(const config_type*) +{ +} diff --git a/ref_app/src/mcal/atmega2560/mcal_osc.h b/ref_app/src/mcal/atmega2560/mcal_osc.h new file mode 100644 index 000000000..59b729640 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_osc.h @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_OSC_2011_10_20_H_ + #define MCAL_OSC_2011_10_20_H_ + + namespace mcal + { + namespace osc + { + typedef void config_type; + + void init(const config_type*); + } + } + +#endif // MCAL_OSC_2011_10_20_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_port.cpp b/ref_app/src/mcal/atmega2560/mcal_port.cpp new file mode 100644 index 000000000..4486c3fe8 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_port.cpp @@ -0,0 +1,12 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +void mcal::port::init(const config_type*) +{ +} diff --git a/ref_app/src/mcal/atmega2560/mcal_port.h b/ref_app/src/mcal/atmega2560/mcal_port.h new file mode 100644 index 000000000..221b55543 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_port.h @@ -0,0 +1,71 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_PORT_2012_06_27_H_ + #define MCAL_PORT_2012_06_27_H_ + + #include + + namespace mcal + { + namespace port + { + typedef void config_type; + + void init(const config_type*); + + template + class port_pin + { + public: + static void set_direction_output() + { + // Set the port pin's direction to output. + mcal::reg::access::bit_set(); + } + + static void set_direction_input() + { + // Set the port pin's direction to input. + mcal::reg::access::bit_clr(); + } + + static void set_pin_high() + { + // Set the port output value to high. + mcal::reg::access::bit_set(); + } + + static void set_pin_low() + { + // Set the port output value to low. + mcal::reg::access::bit_clr(); + } + + static bool read_input_value() + { + // Read the port input value. + return mcal::reg::access::bit_get(); + } + + static void toggle_pin() + { + // Toggle the port output value. + mcal::reg::access::bit_not(); + } + + private: + static constexpr addr_type pdir = port - 1U; + static constexpr addr_type pinp = port - 2U; + }; + } + } + +#endif // MCAL_PORT_2012_06_27_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_pwm.cpp b/ref_app/src/mcal/atmega2560/mcal_pwm.cpp new file mode 100644 index 000000000..82f2c8b36 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_pwm.cpp @@ -0,0 +1,11 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +//mcal::pwm::pwm_type pwm0; +//mcal::pwm::pwm_type pwm1; diff --git a/ref_app/src/mcal/atmega2560/mcal_pwm.h b/ref_app/src/mcal/atmega2560/mcal_pwm.h new file mode 100644 index 000000000..4d6b57cb0 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_pwm.h @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2017. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_PWM_2010_09_14_H_ + #define MCAL_PWM_2010_09_14_H_ + + namespace mcal + { + namespace pwm + { + typedef void config_type; + + inline void init(const config_type*) { } + } + } + +#endif // MCAL_PWM_2010_09_14_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_reg.h b/ref_app/src/mcal/atmega2560/mcal_reg.h new file mode 100644 index 000000000..71381c112 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_reg.h @@ -0,0 +1,79 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_REG_2010_04_10_H_ + #define MCAL_REG_2010_04_10_H_ + + #include + + namespace mcal + { + namespace reg + { + constexpr std::uint8_t sfr_offset = 0x20U; + + // Bit-position values. + constexpr std::uint8_t bval0 = 1U; + constexpr std::uint8_t bval1 = 1U << 1U; + constexpr std::uint8_t bval2 = 1U << 2U; + constexpr std::uint8_t bval3 = 1U << 3U; + constexpr std::uint8_t bval4 = 1U << 4U; + constexpr std::uint8_t bval5 = 1U << 5U; + constexpr std::uint8_t bval6 = 1U << 6U; + constexpr std::uint8_t bval7 = 1U << 7U; + + // System registers. + constexpr std::uint8_t mcusr = 0x14U + sfr_offset; + constexpr std::uint8_t prr = 0x64U; + + // Port registers. + constexpr std::uint8_t pinb = 0x03U + sfr_offset; + constexpr std::uint8_t ddrb = 0x04U + sfr_offset; + constexpr std::uint8_t portb = 0x05U + sfr_offset; + constexpr std::uint8_t pinc = 0x06U + sfr_offset; + constexpr std::uint8_t ddrc = 0x07U + sfr_offset; + constexpr std::uint8_t portc = 0x08U + sfr_offset; + constexpr std::uint8_t pind = 0x09U + sfr_offset; + constexpr std::uint8_t ddrd = 0x0AU + sfr_offset; + constexpr std::uint8_t portd = 0x0BU + sfr_offset; + constexpr std::uint8_t pine = 0x0CU + sfr_offset; + constexpr std::uint8_t ddre = 0x0DU + sfr_offset; + constexpr std::uint8_t porte = 0x0EU + sfr_offset; + + // Timer registers + constexpr std::uint8_t tifr0 = 0x15U + sfr_offset; + constexpr std::uint8_t tccr0a = 0x24U + sfr_offset; + constexpr std::uint8_t tccr0b = 0x25U + sfr_offset; + constexpr std::uint8_t tcnt0 = 0x26U + sfr_offset; + constexpr std::uint8_t ocr0a = 0x27U + sfr_offset; + constexpr std::uint8_t timsk0 = 0x6EU; + + constexpr std::uint8_t tifr1 = 0x16U + sfr_offset; + constexpr std::uint8_t tccr1a = 0x80U; + constexpr std::uint8_t tccr1b = 0x81U; + constexpr std::uint8_t tcnt1l = 0x84U; + constexpr std::uint8_t tcnt1h = 0x85U; + constexpr std::uint8_t ocr1a = 0x88U; + constexpr std::uint8_t timsk1 = 0x6FU; + + constexpr std::uint8_t tifr2 = 0x17U + sfr_offset; + constexpr std::uint8_t tccr2a = 0xB0U; + constexpr std::uint8_t tccr2b = 0xB1U; + constexpr std::uint8_t tcnt2 = 0xB2U; + constexpr std::uint8_t ocr2a = 0xB3U; + constexpr std::uint8_t timsk2 = 0x70U; + + // SPI(TM) registers. + constexpr std::uint8_t spcr = 0x2CU + sfr_offset; + constexpr std::uint8_t spsr = 0x2DU + sfr_offset; + constexpr std::uint8_t spdr = 0x2EU + sfr_offset; + + // Watchdog registers + constexpr std::uint8_t wdtcsr = 0x60U; + } + } +#endif // MCAL_REG_2010_04_10_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_reg_access.h b/ref_app/src/mcal/atmega2560/mcal_reg_access.h new file mode 100644 index 000000000..ccce06b72 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_reg_access.h @@ -0,0 +1,15 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_REG_ACCESS_2010_04_10_H_ + #define MCAL_REG_ACCESS_2010_04_10_H_ + + #include + #include + #include + +#endif // MCAL_REG_ACCESS_2010_04_10_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_ser.h b/ref_app/src/mcal/atmega2560/mcal_ser.h new file mode 100644 index 000000000..c139e8ae0 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_ser.h @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_SER_2011_10_20_H_ + #define MCAL_SER_2011_10_20_H_ + + namespace mcal + { + namespace ser + { + typedef void config_type; + + inline void init(const config_type*) { } + } + } + +#endif // MCAL_SER_2011_10_20_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_spi.cpp b/ref_app/src/mcal/atmega2560/mcal_spi.cpp new file mode 100644 index 000000000..dbde55c43 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_spi.cpp @@ -0,0 +1,221 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2012 - 2015. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +/* +#include +#include +#include +#include +#include + +mcal::spi::spi_communication mcal::spi::the_spi; + +namespace +{ + typedef mcal::port::port_pin portd0_type; + + typedef mcal::port::port_pin portd1_type; + + void enable_rx_tx_interrupt() + { + // Enable the spi end-of-transmission interrupt + // by setting the spie bit in the spcr register. + mcal::reg::access::bit_set(); + } + + void disable_rx_tx_interrupt() + { + // Disable the spi end-of-transmission interrupt + // by clearing the spie bit in the spcr register. + mcal::reg::access::bit_clr(); + } +} + +mcal::spi::spi_communication::spi_communication() : send_is_active(false), + channel(0U) +{ + // Set the special port pins ss, mosi and sck to output. + // Do this even though the ss pin will not be used. + constexpr std::uint8_t pdir_mask = mcal::reg::bval2 + | mcal::reg::bval3 + | mcal::reg::bval5; + + mcal::reg::access::reg_or(); + + // Enable spi as master mode, clock idle to high, etc. + // Set the spi clock to f_osc/64 = (1/4)MHz. + constexpr std::uint8_t spcr_mask = mcal::reg::bval1 + | mcal::reg::bval2 + | mcal::reg::bval3 + | mcal::reg::bval4 + | mcal::reg::bval6; + + mcal::reg::access::reg_set(); + + // Set the chip-select-not ports to output high. + portd0_type::set_pin_high(); + portd0_type::set_direction_output(); + + portd1_type::set_pin_high(); + portd1_type::set_direction_output(); +} + +mcal::spi::spi_communication::~spi_communication() +{ +} + +bool mcal::spi::spi_communication::send(const std::uint8_t byte_to_send) +{ + mcal::irq::disable_all(); + + // If the spi is idle, begin transmission. + if(send_is_active == false) + { + // Set the send-active flag. + send_is_active = true; + + // Set the chip-select-not for the appropriate channel to low. + if(channel == static_cast(1U)) + { + portd1_type::set_pin_low(); + } + else + { + portd0_type::set_pin_low(); + } + + // Send the first byte over spi. + mcal::reg::dynamic_access::reg_set(mcal::reg::spdr, byte_to_send); + + // Enable the spi rx/tx interrupt. + enable_rx_tx_interrupt(); + + mcal::irq::enable_all(); + } + else + { + // A transmission is already in progress. + // Pack the next byte-to-send into the send-buffer. + send_buffer.in(byte_to_send); + + mcal::irq::enable_all(); + } + + return true; +} + +bool mcal::spi::spi_communication::recv(std::uint8_t& byte_to_recv) +{ + disable_rx_tx_interrupt(); + + byte_to_recv = recv_buffer.out(); + + enable_rx_tx_interrupt(); + + return true; +} + +mcal::spi::spi_communication::size_type mcal::spi::spi_communication::recv_ready() const +{ + disable_rx_tx_interrupt(); + + // Get the count of bytes in the receive buffer. + const size_type count = recv_buffer.size(); + + enable_rx_tx_interrupt(); + + return count; +} + +bool mcal::spi::spi_communication::idle() const +{ + disable_rx_tx_interrupt(); + + const bool is_active = send_is_active; + + enable_rx_tx_interrupt(); + + return (is_active == false); +} + +bool mcal::spi::spi_communication::select_channel(const std::uint8_t ch) +{ + // Support for two channels 0 and 1. + if(ch <= static_cast(2U)) + { + channel = ch; + + return true; + } + else + { + return false; + } +} + +void __vector_17() +{ + // The spi interrupt is on end-of-transmission. + + // Receive the byte from the previous transmission. + const std::uint8_t byte_to_recv = mcal::reg::access::reg_get(); + + mcal::spi::the_spi.recv_buffer.in(byte_to_recv); + + const bool send_buffer_is_empty = mcal::spi::the_spi.send_buffer.empty(); + + if(send_buffer_is_empty) + { + // The send-buffer is empty and reception from + // the previous (final) transmission is done. + // Deactivate the send-active flag. + mcal::spi::the_spi.send_is_active = false; + + // Reset the chip-select-not on the channel to high. + if(mcal::spi::the_spi.channel == static_cast(1U)) + { + portd1_type::set_pin_high(); + } + else + { + portd0_type::set_pin_high(); + } + + // Disable the spi rx/tx interrupt. + disable_rx_tx_interrupt(); + } + else + { + // Send the next byte if there is at least one in the send queue. + const std::uint8_t byte_to_send = mcal::spi::the_spi.send_buffer.out(); + + mcal::reg::dynamic_access::reg_set(mcal::reg::spdr, byte_to_send); + } +} +*/ diff --git a/ref_app/src/mcal/atmega2560/mcal_spi.h b/ref_app/src/mcal/atmega2560/mcal_spi.h new file mode 100644 index 000000000..94a27ae38 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_spi.h @@ -0,0 +1,60 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2012 - 2015. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_SPI_2012_05_24_H_ + #define MCAL_SPI_2012_05_24_H_ + + namespace mcal + { + namespace spi + { + typedef void config_type; + + inline void init(const config_type*) { } + } + } + + /* + #include + #include + + extern "C" void __vector_17() __attribute__((signal, used, externally_visible)); + + namespace mcal + { + namespace spi + { + typedef void config_type; + + inline void init(const config_type*) { } + + class spi_communication : public util::communication<16U> + { + public: + spi_communication(); + virtual ~spi_communication(); + + virtual bool send (const std::uint8_t byte_to_send); + virtual bool recv (std::uint8_t& byte_to_recv); + virtual size_type recv_ready() const; + virtual bool idle () const; + + bool select_channel(const std::uint8_t ch); + + private: + volatile bool send_is_active; + std::uint8_t channel; + + friend void ::__vector_17(); + }; + + extern spi_communication the_spi; + } + } + */ + +#endif // MCAL_SPI_2012_05_24_H_ diff --git a/ref_app/src/mcal/atmega2560/mcal_wdg.cpp b/ref_app/src/mcal/atmega2560/mcal_wdg.cpp new file mode 100644 index 000000000..ee0b0d390 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_wdg.cpp @@ -0,0 +1,78 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2013. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include + +void mcal::wdg::init(const config_type*) +{ + // Read the MCU status register. + volatile const std::uint8_t mcu_status_register = + mcal::reg::access::reg_get(); + + // At the moment, we do not make use of the MCU status register. + // In the future, for example, we could query the reset reason. + static_cast(mcu_status_register); + + // Clear the MCU status register. + mcal::reg::access::reg_set(); + + // Reset the watchdog timer. + asm volatile("wdr"); + + // Set the watchdog timer period and activate the watchdog timer. + mcal::reg::access::reg_set(); + + // See Chapter 11.9.2, Table 11-2: Watchdog Timer Prescale Select. + // Select WDP3:WDP0 in WDTCSR to binary 0011, resulting in a watchdog + // period of approximately 125ms. + mcal::reg::access::reg_set(); +} + +void mcal::wdg::secure::trigger() +{ + asm volatile("wdr"); +} + +// This following function is not used. +// It is, however, kept as an example of *turning off* +// the wdt if wdton is set in the fuse bits. +void mcal_wdg_turn_off_wdt_if_wdton_is_set(); + +void mcal_wdg_turn_off_wdt_if_wdton_is_set() +{ + asm volatile("wdr"); + + // Clear WDRF in the MCU status register. + mcal::reg::access::bit_clr(); + + // Set WDCE and WDE. + mcal::reg::access::reg_or(); + + // Turn off the WDT. + mcal::reg::access::reg_set(); +} diff --git a/ref_app/src/mcal/atmega2560/mcal_wdg.h b/ref_app/src/mcal/atmega2560/mcal_wdg.h new file mode 100644 index 000000000..97527bb64 --- /dev/null +++ b/ref_app/src/mcal/atmega2560/mcal_wdg.h @@ -0,0 +1,34 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_WDT_2010_04_10_H_ + #define MCAL_WDT_2010_04_10_H_ + + extern "C" void __my_startup() __attribute__((section(".startup"), used, noinline)); + + namespace sys { namespace idle { void task_func(); } } + + namespace mcal + { + namespace wdg + { + typedef void config_type; + + void init(const config_type*); + + struct secure final + { + private: + static void trigger(); + + friend void ::sys::idle::task_func(); + friend void ::__my_startup(); + }; + } + } + +#endif // MCAL_WDT_2010_04_10_H_ diff --git a/ref_app/src/mcal/avr/mcal_gpt.cpp b/ref_app/src/mcal/avr/mcal_gpt.cpp index ff6dfe9ca..9c2ae02d8 100644 --- a/ref_app/src/mcal/avr/mcal_gpt.cpp +++ b/ref_app/src/mcal/avr/mcal_gpt.cpp @@ -23,7 +23,8 @@ namespace } } -extern "C" void __vector_16() __attribute__((signal, used, externally_visible)); +extern "C" +void __vector_16() __attribute__((signal, used, externally_visible)); void __vector_16() { diff --git a/ref_app/target.vcxproj b/ref_app/target.vcxproj index 7612f158f..231262575 100644 --- a/ref_app/target.vcxproj +++ b/ref_app/target.vcxproj @@ -1,6 +1,10 @@  + + target atmega2560 + Win32 + target bcm2835_raspi_b Win32 @@ -55,6 +59,11 @@ Unicode true + + Makefile + Unicode + true + Makefile Unicode @@ -116,6 +125,10 @@ Makefile v141 + + Makefile + v141 + Makefile v141 @@ -135,6 +148,9 @@ + + + @@ -166,6 +182,7 @@ <_ProjectFileVersion>10.0.30319.1 $(SolutionDir)bin\ + $(SolutionDir)bin\ $(SolutionDir)bin\ $(SolutionDir)bin\ $(SolutionDir)bin\ @@ -176,6 +193,7 @@ $(SolutionDir)bin\ $(SolutionDir)bin\ $(OutDir) + $(OutDir) $(OutDir) $(OutDir) $(OutDir) @@ -186,6 +204,7 @@ $(OutDir) $(OutDir) Build\Build.bat AVR + Build\Build.bat AVR Build\Build.bat AVR Build\Build.bat AVR target\build\build.bat stm32f100 @@ -196,6 +215,7 @@ target\build\build.bat bcm2835_raspi_b target\build\build.bat pic32mx795fx Build\Build.bat AVR rebuild + Build\Build.bat AVR rebuild Build\Build.bat AVR rebuild Build\Build.bat AVR rebuild target\build\build.bat stm32f100 rebuild @@ -207,6 +227,7 @@ target\build\build.bat bcm2835_raspi_b rebuild target\build\build.bat pic32mx795fx rebuild Target\Build\Build.bat avr clean_all + Target\Build\Build.bat atmega2560 clean_all Target\Build\Build.bat rl78 clean_all Target\Build\Build.bat rx63n clean_all target\build\build.bat stm32f100 clean_all @@ -218,6 +239,7 @@ target\build\build.bat bcm2835_raspi_b clean_all target\build\build.bat pic32mx795fx clean_all ref_app.hex + ref_app.hex ref_app.hex ref_app.hex ref_app.hex @@ -228,6 +250,7 @@ ref_app.hex ref_app.hex $(NMakePreprocessorDefinitions) + $(NMakePreprocessorDefinitions) $(NMakePreprocessorDefinitions) $(NMakePreprocessorDefinitions) @@ -239,6 +262,7 @@ $(ProjectDir)/Cpp; $(ProjectDir)/Cpp/Hal/AVR;$(NMakeIncludeSearchPath) + $(ProjectDir)/Cpp; $(ProjectDir)/Cpp/Hal/AVR;$(NMakeIncludeSearchPath) $(ProjectDir)/Cpp; $(ProjectDir)/Cpp/Hal/AVR;$(NMakeIncludeSearchPath) $(ProjectDir)/Cpp; $(ProjectDir)/Cpp/Hal/AVR;$(NMakeIncludeSearchPath) $(SolutionDir)/src;$(SolutionDir)/src/mcal/stm32f100 @@ -249,6 +273,7 @@ $(SolutionDir)/src;$(SolutionDir)/src/mcal/bcm2835_raspi_b $(SolutionDir)/src;$(SolutionDir)/src/mcal/pic32mx795fx $(NMakeForcedIncludes) + $(NMakeForcedIncludes) $(NMakeForcedIncludes) $(NMakeForcedIncludes) @@ -260,6 +285,7 @@ $(NMakeAssemblySearchPath) + $(NMakeAssemblySearchPath) $(NMakeAssemblySearchPath) $(NMakeAssemblySearchPath) @@ -271,6 +297,7 @@ $(NMakeForcedUsingAssemblies) + $(NMakeForcedUsingAssemblies) $(NMakeForcedUsingAssemblies) $(NMakeForcedUsingAssemblies) @@ -290,28 +317,35 @@ $(NMakeAssemblySearchPath) $(NMakeForcedUsingAssemblies) Target\Build\Build.bat avr + Target\Build\Build.bat atmega2560 Target\Build\Build.bat rl78 Target\Build\Build.bat rx63n Target\Build\Build.bat avr rebuild + Target\Build\Build.bat atmega2560 rebuild Target\Build\Build.bat rl78 rebuild Target\Build\Build.bat rx63n rebuild + $(SolutionDir)src\util\STL $(SolutionDir)src\util\STL_C++XX_stdfloat $(SolutionDir)src $(SolutionDir)src\mcal\avr + $(SolutionDir)src\util\STL $(SolutionDir)src\util\STL_C++XX_stdfloat $(SolutionDir)src $(SolutionDir)src\mcal\avr $(SolutionDir)/src;$(SolutionDir)/src/mcal/rl78 $(SolutionDir)/src;$(SolutionDir)/src/mcal/rx63n + + + Build\Build.bat AVR @@ -323,22 +357,28 @@ $(NMakeAssemblySearchPath) $(NMakeForcedUsingAssemblies) + + + + + + @@ -352,6 +392,11 @@ $(SolutionDir)tmp\log\ref_app.log + + + $(SolutionDir)tmp\log\ref_app.log + + $(SolutionDir)tmp\log\ref_app.log @@ -412,6 +457,9 @@ + + + @@ -449,6 +497,10 @@ + + + + diff --git a/ref_app/target.vcxproj.filters b/ref_app/target.vcxproj.filters index 4a788fcec..d9d7bab44 100644 --- a/ref_app/target.vcxproj.filters +++ b/ref_app/target.vcxproj.filters @@ -103,6 +103,15 @@ {8390d2aa-8970-46fb-a030-12003da78359} + + {981e5c20-1cb2-47d6-8987-7a6ee473efff} + + + {5811fa00-3254-48e2-ad7c-1f0f728a9b7f} + + + {655b96de-d2f6-4ab9-9e37-a70ae26780a0} + @@ -225,6 +234,15 @@ micros\stm32l152\make + + micros\atmega2560\make + + + micros\atmega2560\make + + + micros\atmega2560\make + @@ -344,5 +362,17 @@ micros\stm32l152\startup + + micros\atmega2560\startup + + + micros\atmega2560\startup + + + micros\atmega2560\startup + + + micros\atmega2560\startup + \ No newline at end of file diff --git a/ref_app/target/micros/atmega2560/make/atmega2560.ld b/ref_app/target/micros/atmega2560/make/atmega2560.ld new file mode 100644 index 000000000..a803ae09c --- /dev/null +++ b/ref_app/target/micros/atmega2560/make/atmega2560.ld @@ -0,0 +1,123 @@ + +/* + Copyright Christopher Kormanyos 2007 - 2018. + Distributed under the Boost Software License, + Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) +*/ + +/* Linker script for ATMEL(R) AVR(R) ATmega2560. */ + +INPUT(libc.a libm.a libgcc.a) + +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:6) + +/* The beginning and end of the program ROM area. */ +_rom_begin = 0x00000000; +_rom_end = 0x00007FFC; + +/* The beginning and end (i.e., top) of the stack */ +/* Set up a stack with a size of 1K */ +_stack_begin = 0x801C00; +_stack_end = 0x802000; + +/* The initial stack pointer (top of stack) is at the top of the 8K RAM */ +__initial_stack_pointer = 0x802000; + +MEMORY +{ + ROM(rx) : ORIGIN = 0, LENGTH = 32K - 4 + RAM(rw!x) : ORIGIN = 0x800100, LENGTH = 0x1B00 +} + +SECTIONS +{ + . = 0x0; + . = ALIGN(2); + + /* ISR vectors */ + .isr_vector : + { + *(.isr_vector) + . = ALIGN(0x80); + KEEP(*(.isr_vector)) + } > ROM = 0xAAAA + + /* Startup code */ + .startup : + { + *(.startup) + . = ALIGN(0x10); + KEEP(*(.startup)) + } > ROM = 0xAAAA + + /* ISR handlers */ + .isr_handlers : + { + *(.isr_handlers) + . = ALIGN(0x10); + KEEP(*(.isr_handlers)) + } > ROM = 0xAAAA + + /* Program code (text), read-only data and static ctors */ + .text : + { + _ctors_begin = .; + *(.ctors) + . = ALIGN(2); + KEEP (*(SORT(.ctors))) + _ctors_end = .; + . = ALIGN(2); + *(.progmem*) + . = ALIGN(2); + *(.trampolines*) + . = ALIGN(2); + *(.text) + . = ALIGN(2); + *(.text*) + . = ALIGN(2); + } > ROM + + .text : + { + . = ALIGN(0x10); + } > ROM = 0xAAAA + + .= 0x800100; + . = ALIGN(2); + + /* The ROM-to-RAM initialized data section */ + .data : + { + _data_begin = .; + *(.data) + . = ALIGN(2); + KEEP (*(.data)) + *(.data*) + . = ALIGN(2); + KEEP (*(.data*)) + *(.rodata) /* Do *NOT* move this! Include .rodata here if gcc is used with -fdata-sections. */ + . = ALIGN(2); + KEEP (*(.rodata)) + *(.rodata*) + . = ALIGN(2); + KEEP (*(.rodata*)) + _data_end = .; + } > RAM AT > ROM + + /* The uninitialized (zero-cleared) data section */ + .bss : + { + _bss_begin = .; + *(.bss) + . = ALIGN(2); + KEEP (*(.bss)) + *(.bss*) + . = ALIGN(2); + KEEP (*(.bss*)) + _bss_end = .; + } > RAM + + _rom_data_begin = LOADADDR(.data); +} diff --git a/ref_app/target/micros/atmega2560/make/atmega2560_files.gmk b/ref_app/target/micros/atmega2560/make/atmega2560_files.gmk new file mode 100644 index 000000000..cb9c0a232 --- /dev/null +++ b/ref_app/target/micros/atmega2560/make/atmega2560_files.gmk @@ -0,0 +1,18 @@ +# +# Copyright Christopher Kormanyos 2007 - 2018. +# Distributed under the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt +# or copy at http://www.boost.org/LICENSE_1_0.txt) +# + +# ------------------------------------------------------------------------------ +# File list of the avr files in the project +# ------------------------------------------------------------------------------ + +FILES_TGT = $(PATH_APP)/util/STL/impl/avr/avr_float_limits \ + $(PATH_APP)/util/STL/impl/cmath_impl_gamma \ + $(PATH_APP)/util/STL/impl/cmath_impl_hyperbolic \ + $(PATH_TGT)/startup/crt0 \ + $(PATH_TGT)/startup/crt0_init_ram \ + $(PATH_TGT)/startup/crt1 \ + $(PATH_TGT)/startup/int_vect diff --git a/ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk b/ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk new file mode 100644 index 000000000..558995070 --- /dev/null +++ b/ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk @@ -0,0 +1,27 @@ +# +# Copyright Christopher Kormanyos 2007 - 2018. +# Distributed under the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt +# or copy at http://www.boost.org/LICENSE_1_0.txt) +# + +# ------------------------------------------------------------------------------ +# compiler flags for the target architecture +# ------------------------------------------------------------------------------ + +GCC_VERSION = 7.2.0 +GCC_TARGET = avr + +TGT_CFLAGS = -O2 \ + -mmcu=atmega2560 \ + -fsigned-char \ + -mrelax + +TGT_CPPFLAGS = -std=c++17 + +TGT_INCLUDES = -I$(PATH_APP)/util/STL \ + -I$(PATH_APP)/util/STL_C++XX_stdfloat + +TGT_AFLAGS = + +TGT_LDFLAGS = diff --git a/ref_app/target/micros/atmega2560/startup/crt0.cpp b/ref_app/target/micros/atmega2560/startup/crt0.cpp new file mode 100644 index 000000000..c91e62630 --- /dev/null +++ b/ref_app/target/micros/atmega2560/startup/crt0.cpp @@ -0,0 +1,63 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +// ATMEL(R) AVR(R) startup code. +// Expressed with C++ for Atmega328P by Chris. + +#include + +asm volatile(".extern __initial_stack_pointer"); + +namespace crt +{ + void init_ram () __attribute__((section(".startup"), used, noinline)); + void init_ctors() __attribute__((section(".startup"), used, noinline)); +} + +extern "C" void __my_startup() __attribute__((section(".startup"), used, noinline)); + +void __my_startup() +{ + // Load the sreg register. + asm volatile("eor r1, r1"); + asm volatile("out 0x3f, r1"); + + // Set the stack pointer. + asm volatile + ("ldi r28, lo8(__initial_stack_pointer)"); + asm volatile + ("ldi r29, hi8(__initial_stack_pointer)"); + + // Load the sph register (stack pointer high). + asm volatile("out 0x3e, r29"); + + // Load the spl register (stack pointer low). + asm volatile("out 0x3d, r28"); + + // CPU Initialization, including watchdog, + // port, oscillators (i.e. clocks). + mcal::cpu::init(); + + // Initialize statics from ROM to RAM. + // Zero-clear default-initialized static RAM. + crt::init_ram(); + mcal::wdg::secure::trigger(); + + // Call all ctor initializations. + crt::init_ctors(); + mcal::wdg::secure::trigger(); + + // Call main (and never return). + asm volatile("rcall main"); + + // Catch an unexpected return from main. + for(;;) + { + // Replace with a loud error if desired. + mcal::wdg::secure::trigger(); + } +} diff --git a/ref_app/target/micros/atmega2560/startup/crt0_init_ram.cpp b/ref_app/target/micros/atmega2560/startup/crt0_init_ram.cpp new file mode 100644 index 000000000..348c0819f --- /dev/null +++ b/ref_app/target/micros/atmega2560/startup/crt0_init_ram.cpp @@ -0,0 +1,59 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include +#include + +#include + +extern "C" +{ + extern std::uintptr_t _rom_data_begin; // Start address for the initialization values of the rom-to-ram section. + extern std::uintptr_t _data_begin; // Start address for the .data section. + extern std::uintptr_t _data_end; // End address for the .data section. + extern std::uintptr_t _bss_begin; // Start address for the .bss section. + extern std::uintptr_t _bss_end; // End address for the .bss section. +} + +namespace crt +{ + void init_ram() __attribute__((section(".startup"), used, noinline)); +} + +void crt::init_ram() +{ + typedef std::uint16_t memory_aligned_type; + + // Copy the data segment initializers from rom-to-ram. + // Note that all data segments are aligned by 2. + const std::size_t size = std::size_t( static_cast(static_cast(&_data_end)) + - static_cast(static_cast(&_data_begin))); + + + std::uint8_t* rom_source = static_cast(static_cast(&_rom_data_begin)); + + std::for_each(static_cast(static_cast(&_data_begin)), + static_cast(static_cast(&_data_begin)) + size, + [&rom_source](memory_aligned_type& ram_destination) + { + // Note that particular care needs to be taken to read program + // memory with the function mcal_cpu_read_program_memory_word(). + + // Copy the data from the rom-source to the ram-destination. + ram_destination = mcal_cpu_read_program_memory_word(rom_source); + + // Acquire the next 16-bit address of the rom-source. + rom_source += 2U; + }); + + // Clear the bss segment. + // Note that the bss segment is aligned by 2. + std::fill(static_cast(static_cast(&_bss_begin)), + static_cast(static_cast(&_bss_end)), + static_cast(0U)); +} diff --git a/ref_app/target/micros/atmega2560/startup/crt1.cpp b/ref_app/target/micros/atmega2560/startup/crt1.cpp new file mode 100644 index 000000000..dfe17df97 --- /dev/null +++ b/ref_app/target/micros/atmega2560/startup/crt1.cpp @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +#include + +extern "C" +{ + struct ctor_type + { + typedef void(*function_type)(); + }; + + extern ctor_type::function_type _ctors_end[]; + extern ctor_type::function_type _ctors_begin[]; +} + +namespace crt +{ + void init_ctors() __attribute__((section(".startup"), used, noinline)); +} + +void crt::init_ctors() +{ + typedef std::uint16_t function_aligned_type; + + for(std::uint8_t* rom_source = static_cast(static_cast(_ctors_end)); + rom_source != static_cast(static_cast(_ctors_begin)); + rom_source -= sizeof(function_aligned_type)) + { + // Note that particular care needs to be taken to read program + // memory with the function mcal_cpu_read_program_memory_word(). + + // Acquire the next 16-bit ctor function address. + const ctor_type::function_type ctor_function_address = + reinterpret_cast(mcal_cpu_read_program_memory_word(rom_source - 2U)); + + // Call the ctor function. + ctor_function_address(); + } +} diff --git a/ref_app/target/micros/atmega2560/startup/int_vect.cpp b/ref_app/target/micros/atmega2560/startup/int_vect.cpp new file mode 100644 index 000000000..45c1dd31f --- /dev/null +++ b/ref_app/target/micros/atmega2560/startup/int_vect.cpp @@ -0,0 +1,101 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2018. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include +#include + +extern "C" void __my_startup () __attribute__((section(".startup"), used, noinline)); +extern "C" void __vector_unused_irq() __attribute__((signal, used, externally_visible)); +extern "C" void __vector_23 () __attribute__((signal, used, externally_visible)); + +extern "C" +void __vector_unused_irq() +{ + for(;;) + { + mcal::cpu::nop(); + } +} + +namespace +{ + typedef struct struct_isr_type + { + typedef void(*function_type)(); + + const std::uint8_t jmp[2]; // JMP instruction (0x940C): 0x0C = low byte, 0x94 = high byte. + const function_type func; // The interrupt service routine. + } + isr_type; +} + +extern "C" +const volatile std::array __isr_vector __attribute__((section(".isr_vector"))); + +extern "C" +const volatile std::array __isr_vector = +{{ + // addr. nr. interrupt source + { { 0x0C, 0x94 }, __my_startup }, // 0x00, 0 reset + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x02, 1 external interrupt0 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x04, 2 external interrupt1 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x06, 3 external interrupt2 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x08, 4 external interrupt3 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x0A, 5 external interrupt4 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x0C, 6 external interrupt5 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x0E, 7 external interrupt6 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x10, 8 external interrupt7 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x12, 9 pin change int request0 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x14, 10 pin change int request1 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x16, 11 pin change int request2 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x18, 12 Watchdog Timer Interrupt + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x1A, 13 timer/counter2 compare A + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x1C, 14 timer/counter2 compare B + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x1E, 15 timer/counter2 overflow + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x20, 16 timer/counter1 capture + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x22, 17 timer/counter1 compare A + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x24, 18 timer/counter1 compare B + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x26, 19 timer/counter1 compare C + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x28, 20 timer/counter1 overflow + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x2A, 21 timer/counter0 compare A + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x2C, 22 timer/counter0 compare B + { { 0x0C, 0x94 }, __vector_23 }, // 0x2E, 23 timer/counter0 overflow + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x30, 24 spi serial transfer cComplete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x32, 25 uart0 rx complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x34, 26 uart0 data register empty + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x36, 27 uart0 tx complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x38, 28 analog comparator + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x3A, 29 adc conversion complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x3C, 30 eeprom ready + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x3E, 31 timer/counter3 capture event + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x40, 32 timer/counter3 compare match a + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x42, 33 timer/counter3 compare match b + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x44, 34 timer/counter3 compare match c + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x46, 35 timer/counter3 overflow + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x48, 36 uart1 rx complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x4A, 37 uart1 data register empty + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x4C, 38 uart1 tx complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x4E, 39 2 wire serial interface + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x50, 40 store program memory ready + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x52, 41 timer/counter4 captureevent + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x54, 42 timer/counter4 compare a + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x56, 43 timer/counter4 compare b + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x58, 44 timer/counter4 compare c + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x5A, 45 timer/counter4 overflow + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x5C, 46 timer/counter5 capture event + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x5E, 47 timer/counter5 compare a + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x60, 48 timer/counter5 compare b + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x62, 49 timer/counter5 compare c + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x64, 50 timer/counter5 overflow + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x66, 51 uart2 rx complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x68, 52 uart2 data register empty + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x6A, 53 uart2 tx complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x6C, 54 uart3 rx complete + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x6E, 55 uart3 data register empty + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x70, 56 uart3 tx complete +}}; diff --git a/ref_app/target/micros/avr/make/avr.ld b/ref_app/target/micros/avr/make/avr.ld index 8f4ea8c6d..dca765879 100644 --- a/ref_app/target/micros/avr/make/avr.ld +++ b/ref_app/target/micros/avr/make/avr.ld @@ -14,9 +14,8 @@ OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") OUTPUT_ARCH(avr:5) /* The beginning and end of the program ROM area. */ -/* Leave 4 bytes for the 32-bit checksum plus 0x10 extra bytes free. */ _rom_begin = 0x00000000; -_rom_end = 0x00007FEC; +_rom_end = 0x00007FFC; /* The beginning and end (i.e., top) of the stack */ /* Set up a stack with a size of (3/4)K */ @@ -28,7 +27,7 @@ __initial_stack_pointer = 0x800800; MEMORY { - ROM(rx) : ORIGIN = 0, LENGTH = 32K - 0x14 + ROM(rx) : ORIGIN = 0, LENGTH = 32K - 4 RAM(rw!x) : ORIGIN = 0x800100, LENGTH = 0x0400 } diff --git a/ref_app/target/micros/avr/startup/int_vect.cpp b/ref_app/target/micros/avr/startup/int_vect.cpp index 8268324ac..30e12b22a 100644 --- a/ref_app/target/micros/avr/startup/int_vect.cpp +++ b/ref_app/target/micros/avr/startup/int_vect.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2013. +// Copyright Christopher Kormanyos 2007 - 2018. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -13,7 +13,14 @@ extern "C" void __my_startup () __attribute__((section(".startup"), used, extern "C" void __vector_unused_irq() __attribute__((signal, used, externally_visible)); extern "C" void __vector_16 () __attribute__((signal, used, externally_visible)); -void __vector_unused_irq() { for(;;) { mcal::cpu::nop(); } } +extern "C" +void __vector_unused_irq() +{ + for(;;) + { + mcal::cpu::nop(); + } +} namespace { @@ -33,31 +40,31 @@ const volatile std::array __isr_vector __attribute__((section(".i extern "C" const volatile std::array __isr_vector = {{ - // Nr. interrupt source - { { 0x0C, 0x94 }, __my_startup }, // 0, reset - { { 0x0C, 0x94 }, __vector_unused_irq }, // 1, ext0 - { { 0x0C, 0x94 }, __vector_unused_irq }, // 2, ext1 - { { 0x0C, 0x94 }, __vector_unused_irq }, // 3, pin0 - { { 0x0C, 0x94 }, __vector_unused_irq }, // 4, pin1 - { { 0x0C, 0x94 }, __vector_unused_irq }, // 5, pin2 - { { 0x0C, 0x94 }, __vector_unused_irq }, // 6, watchdog - { { 0x0C, 0x94 }, __vector_unused_irq }, // 7, timer2 cmp a - { { 0x0C, 0x94 }, __vector_unused_irq }, // 8, timer2 cmp b - { { 0x0C, 0x94 }, __vector_unused_irq }, // 9, timer2 ovf - { { 0x0C, 0x94 }, __vector_unused_irq }, // 10, timer1 cap - { { 0x0C, 0x94 }, __vector_unused_irq }, // 11, timer1 cmp a - { { 0x0C, 0x94 }, __vector_unused_irq }, // 12, timer1 cmp b - { { 0x0C, 0x94 }, __vector_unused_irq }, // 13, timer1 ovf - { { 0x0C, 0x94 }, __vector_unused_irq }, // 14, timer0 cmp a - { { 0x0C, 0x94 }, __vector_unused_irq }, // 15, timer0 cmp b - { { 0x0C, 0x94 }, __vector_16 }, // 16, timer0 ovf - { { 0x0C, 0x94 }, __vector_unused_irq }, // 17, spi(TM) - { { 0x0C, 0x94 }, __vector_unused_irq }, // 18, usart rx - { { 0x0C, 0x94 }, __vector_unused_irq }, // 19, usart err - { { 0x0C, 0x94 }, __vector_unused_irq }, // 20, usart tx - { { 0x0C, 0x94 }, __vector_unused_irq }, // 21, adc - { { 0x0C, 0x94 }, __vector_unused_irq }, // 22, eep Ready - { { 0x0C, 0x94 }, __vector_unused_irq }, // 23, comparator - { { 0x0C, 0x94 }, __vector_unused_irq }, // 24, two-wire - { { 0x0C, 0x94 }, __vector_unused_irq } // 25, spm + // addr. nr. interrupt source + { { 0x0C, 0x94 }, __my_startup }, // 0x00, 0, reset + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x02, 1, ext0 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x04, 2, ext1 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x06, 3, pin0 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x08, 4, pin1 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x0A, 5, pin2 + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x0C, 6, watchdog + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x0E, 7, timer2 cmp a + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x10, 8, timer2 cmp b + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x12, 9, timer2 ovf + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x14, 10, timer1 cap + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x16, 11, timer1 cmp a + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x18, 12, timer1 cmp b + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x1A, 13, timer1 ovf + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x1C, 14, timer0 cmp a + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x1E, 15, timer0 cmp b + { { 0x0C, 0x94 }, __vector_16 }, // 0x2E, 16, timer0 ovf + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x20, 17, spi(TM) + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x22, 18, usart rx + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x24, 19, usart err + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x26, 20, usart tx + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x28, 21, adc + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x2A, 22, eep ready + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x2C, 23, comparator + { { 0x0C, 0x94 }, __vector_unused_irq }, // 0x2E, 24, two-wire + { { 0x0C, 0x94 }, __vector_unused_irq } // 0x30, 25, spm }}; diff --git a/ref_app/target/micros/stm32f100/make/stm32f100.ld b/ref_app/target/micros/stm32f100/make/stm32f100.ld index 4688da76e..27eada330 100644 --- a/ref_app/target/micros/stm32f100/make/stm32f100.ld +++ b/ref_app/target/micros/stm32f100/make/stm32f100.ld @@ -1,6 +1,6 @@ /* - Copyright Christopher Kormanyos 2007 - 2014. + Copyright Christopher Kormanyos 2007 - 2018. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -39,7 +39,7 @@ SECTIONS .isr_vector : { *(.isr_vector) - . = ALIGN(0x10); + . = ALIGN(0x100); KEEP(*(.isr_vector)) } > ROM = 0xAAAA