Skip to content

Commit

Permalink
Restore mistakenly removed files
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Oct 15, 2024
1 parent 81501c8 commit ea68d3b
Show file tree
Hide file tree
Showing 169 changed files with 21,504 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/chapter04_04a/src/app/benchmark/app_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2020.
// 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 <app/led/app_led.h>
#include <mcal_benchmark.h>
#include <mcal_cpu.h>

namespace
{
using port_type = mcal::benchmark::benchmark_port_type;
}

namespace app
{
namespace benchmark
{
void task_init();
void task_func();
}
}

void app::benchmark::task_init()
{
// Set the benchmark port pin to output
port_type::set_direction_output();
}

void app::benchmark::task_func()
{
port_type::set_pin_high();

const bool result_is_ok = app::led::get_state_is_ok();

port_type::set_pin_low();

if(result_is_ok == false)
{
for(;;)
{
mcal::cpu::nop();
}
}
}
99 changes: 99 additions & 0 deletions examples/chapter04_04a/src/app/led/app_led.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2024.
// 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 <array>
#include <cstddef>
#include <cstdint>
#include <functional>

#include <app/led/app_led.h>
#include <mcal/mcal.h>
#include <util/utility/util_time.h>

namespace app
{
namespace led
{
void task_init();
void task_func();
}
}

namespace
{
using timer_type = util::timer<std::uint32_t>;

using app_led_type = mcal::led::led_base;

using app_led_array_type = std::array<std::reference_wrapper<app_led_type>, static_cast<std::size_t>(UINT8_C(5))>;

constexpr auto app_led_one_sec = timer_type::seconds(1U);

timer_type app_led_timer { app_led_one_sec };

app_led_array_type& app_led_base_class_array();

app_led_array_type& app_led_base_class_array()
{
using namespace mcal::led;

static app_led_array_type local_base_class_array
{
led0(), led1(), led2(), led3(), led4()
};

return local_base_class_array;
}

bool app_led_state_is_on { true };
}

bool app::led::get_state_is_ok()
{
const auto& local_base_class_array = app_led_base_class_array();

const auto app_led_state_result_is_ok =
std::all_of
(
local_base_class_array.cbegin(),
local_base_class_array.cend(),
[](app_led_type& led) -> bool
{
return (app_led_state_is_on == led.state_is_on());
});

return app_led_state_result_is_ok;
}

void app::led::task_init()
{
auto& local_base_class_array = app_led_base_class_array();

for(app_led_type& led : local_base_class_array)
{
led.toggle();
}

app_led_state_is_on = true;
}

void app::led::task_func()
{
if(app_led_timer.timeout())
{
app_led_timer.start_interval(app_led_one_sec);

auto& local_base_class_array = app_led_base_class_array();

for(app_led_type& led : local_base_class_array)
{
led.toggle();
}

app_led_state_is_on = (!app_led_state_is_on);
}
}
17 changes: 17 additions & 0 deletions examples/chapter04_04a/src/app/led/app_led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2024.
// 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 APP_LED_2020_04_23_H
#define APP_LED_2020_04_23_H

namespace app { namespace led {

bool get_state_is_ok();

} }

#endif // APP_LED_2020_04_23_H
27 changes: 27 additions & 0 deletions examples/chapter04_04a/src/mcal/avr/mcal_benchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2014 - 2024.
// 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
18 changes: 18 additions & 0 deletions examples/chapter04_04a/src/mcal/avr/mcal_cpu.cpp
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);
}
25 changes: 25 additions & 0 deletions examples/chapter04_04a/src/mcal/avr/mcal_cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2020.
// 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_

#include <cstdint>

namespace mcal
{
namespace cpu
{
void init();

inline void post_init() { }

inline void nop() { asm volatile("nop"); }
}
}

#endif // MCAL_CPU_2009_02_14_H_
96 changes: 96 additions & 0 deletions examples/chapter04_04a/src/mcal/avr/mcal_eep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <mcal_cpu.h>
#include <mcal_eep.h>
#include <mcal_reg.h>

namespace
{
bool mcal_eep_is_busy()
{
return (mcal::reg::reg_access_static<std::uint8_t,
std::uint8_t,
mcal::reg::eecr,
UINT8_C(1)>::bit_get() == true);
}
}

void mcal::eep::init(const config_type*)
{
}

void mcal::eep::write(const address_type addr, const std::uint8_t data)
{
while(mcal_eep_is_busy())
{
mcal::cpu::nop();
}

// Write the address register.
mcal::reg::reg_access_dynamic<std::uint8_t,
address_type>::reg_set(mcal::reg::eear, addr);

// Write the data register.
mcal::reg::reg_access_dynamic<std::uint8_t,
std::uint8_t>::reg_set(mcal::reg::eedr, data);

// Set eecr.eempe (bit 2).
mcal::reg::reg_access_static<std::uint8_t,
std::uint8_t,
mcal::reg::eecr,
UINT8_C(2)>::bit_set();

// Set eecr.eepe (bit 1).
mcal::reg::reg_access_static<std::uint8_t,
std::uint8_t,
mcal::reg::eecr,
UINT8_C(1)>::bit_set();
}

std::uint8_t mcal::eep::read(const address_type addr)
{
while(mcal_eep_is_busy())
{
mcal::cpu::nop();
}

// Write the address register.
mcal::reg::reg_access_dynamic<std::uint8_t,
address_type>::reg_set(mcal::reg::eear, addr);

// Set eecr.eere (bit 0).
mcal::reg::reg_access_static<std::uint8_t,
std::uint8_t,
mcal::reg::eecr,
UINT8_C(0)>::bit_set();

// Read one data byte.
const std::uint8_t data =
mcal::reg::reg_access_static<std::uint8_t,
std::uint8_t,
mcal::reg::eedr>::reg_get();

return data;
}

/*
#define EERE 0
#define EEPE 1
#define EEMPE 2
#define EERIE 3
#define EEPM0 4
#define EEPM1 5
*/

/*
while(EECR & (1 << EEPE));
EEAR = uiAddress;
EEDR = ucData;
EECR |= 1 << EEMPE;
EECR |= 1 << EEPE;
*/

/*
while (EECR & (1 << EEPE));
EEAR = uiAddress;
EECR |= (1 << EERE);
return EEDR;
*/
20 changes: 20 additions & 0 deletions examples/chapter04_04a/src/mcal/avr/mcal_eep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MCAL_EEP_2018_12_15_H_
#define MCAL_EEP_2018_12_15_H_

#include <cstdint>

namespace mcal
{
namespace eep
{
using config_type = void;
using address_type = std::uint_fast16_t;

void init(const config_type*);

void write(const address_type addr, const std::uint8_t data);
std::uint8_t read (const address_type addr);
}
}

#endif // MCAL_EEP_2018_12_15_H_
Loading

0 comments on commit ea68d3b

Please sign in to comment.