forked from ckormanyos/real-time-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve code snippets. Re-work linker stuff. Add new 8-bit target.
- Loading branch information
1 parent
dda0db3
commit 6cfd3f1
Showing
43 changed files
with
2,078 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <cstdint> | ||
#include <mcal_port.h> | ||
#include <mcal_reg.h> | ||
|
||
namespace mcal | ||
{ | ||
namespace benchmark | ||
{ | ||
typedef mcal::port::port_pin<std::uint8_t, | ||
std::uint8_t, | ||
mcal::reg::portd, | ||
UINT8_C(3)> benchmark_port_type; | ||
} | ||
} | ||
|
||
#endif // MCAL_BENCHMARK_2014_04_16_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <mcal_cpu.h> | ||
#include <mcal_osc.h> | ||
#include <mcal_port.h> | ||
#include <mcal_wdg.h> | ||
|
||
void mcal::cpu::init() | ||
{ | ||
mcal::wdg::init(nullptr); | ||
mcal::port::init(nullptr); | ||
mcal::osc::init(nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <cstdint> | ||
#else | ||
#include <stdint.h> | ||
#endif | ||
|
||
#include <avr/pgmspace.h> | ||
|
||
#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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <mcal_gpt.h> | ||
#include <mcal_reg_access.h> | ||
|
||
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<std::uint8_t>(0x80U); | ||
} | ||
|
||
void mcal::gpt::init(const config_type*) | ||
{ | ||
if(gpt_is_initialized() == false) | ||
{ | ||
// Clear the timer0 overflow flag. | ||
mcal::reg::access<std::uint8_t, std::uint8_t, mcal::reg::tifr0, 0x01U>::reg_set(); | ||
|
||
// Enable the timer0 overflow interrupt. | ||
mcal::reg::access<std::uint8_t, std::uint8_t, mcal::reg::timsk0, 0x01U>::reg_set(); | ||
|
||
// Set the timer0 clock source to f_osc/8 = 2MHz and begin counting. | ||
mcal::reg::access<std::uint8_t, std::uint8_t, mcal::reg::tccr0b, 0x02U>::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<timer_address_type, timer_register_type, mcal::reg::tcnt0>::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<timer_address_type, timer_register_type, mcal::reg::tcnt0>::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); | ||
} | ||
} |
Oops, something went wrong.