|
17 | 17 |
|
18 | 18 | namespace local |
19 | 19 | { |
| 20 | + template<typename UnsignedTickType, const unsigned CoreId> |
| 21 | + struct timer_core_x_backend |
| 22 | + { |
| 23 | + using tick_type = UnsignedTickType; |
| 24 | + |
| 25 | + constexpr static auto get_now() -> tick_type |
| 26 | + { |
| 27 | + return static_cast<tick_type>(mcal::gpt::secure::get_time_elapsed()); |
| 28 | + } |
| 29 | + }; |
| 30 | + |
| 31 | + template<typename UnsignedTickType> |
| 32 | + struct timer_core_x_backend<UnsignedTickType, 1U> |
| 33 | + { |
| 34 | + using tick_type = UnsignedTickType; |
| 35 | + |
| 36 | + constexpr static auto get_now() -> tick_type |
| 37 | + { |
| 38 | + return static_cast<tick_type>(mcal::gpt::secure::get_time_elapsed_core1()); |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + template<typename UnsignedTickType> |
| 43 | + struct timer_core_x_backend<UnsignedTickType, 2U> |
| 44 | + { |
| 45 | + using tick_type = UnsignedTickType; |
| 46 | + |
| 47 | + constexpr static auto get_now() -> tick_type |
| 48 | + { |
| 49 | + return static_cast<tick_type>(mcal::gpt::secure::get_time_elapsed_core2()); |
| 50 | + } |
| 51 | + }; |
| 52 | + |
| 53 | + template<typename UnsignedTickType> |
| 54 | + struct timer_core_x_backend<UnsignedTickType, 3U> |
| 55 | + { |
| 56 | + using tick_type = UnsignedTickType; |
| 57 | + |
| 58 | + constexpr static auto get_now() -> tick_type |
| 59 | + { |
| 60 | + return static_cast<tick_type>(mcal::gpt::secure::get_time_elapsed_core3()); |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | + template<const unsigned CoreId> |
20 | 65 | auto main_worker_core_x(mcal::led::led_base& my_led) -> void; |
| 66 | + |
| 67 | + template<const unsigned CoreId> |
| 68 | + auto main_worker_core_x(mcal::led::led_base& my_led) -> void |
| 69 | + { |
| 70 | + my_led.toggle(); |
| 71 | + |
| 72 | + using local_timer_backend_type = timer_core_x_backend<std::uint64_t, CoreId>; |
| 73 | + using local_tick_type = typename local_timer_backend_type::tick_type; |
| 74 | + using local_timer_type = util::timer<local_tick_type, local_timer_backend_type>; |
| 75 | + |
| 76 | + constexpr local_tick_type led_time_1sec { local_timer_type::seconds(local_tick_type { UINT8_C(1) }) }; |
| 77 | + |
| 78 | + local_timer_type led_timer { led_time_1sec }; |
| 79 | + |
| 80 | + for(;;) |
| 81 | + { |
| 82 | + while(!led_timer.timeout()) |
| 83 | + { |
| 84 | + mcal::cpu::nop(); |
| 85 | + } |
| 86 | + |
| 87 | + my_led.toggle(); |
| 88 | + |
| 89 | + led_timer.start_interval(led_time_1sec); |
| 90 | + } |
| 91 | + } |
21 | 92 | } |
22 | 93 |
|
23 | 94 | extern "C" auto main_core1(void) -> void; |
24 | 95 | extern "C" auto main_core2(void) -> void; |
25 | 96 | extern "C" auto main_core3(void) -> void; |
26 | 97 | extern "C" auto main_core0_init(void) -> void; |
27 | 98 |
|
28 | | -extern "C" auto main_core1(void) -> void { local::main_worker_core_x(mcal::led::led1()); } |
29 | | -extern "C" auto main_core2(void) -> void { local::main_worker_core_x(mcal::led::led2()); } |
30 | | -extern "C" auto main_core3(void) -> void { local::main_worker_core_x(mcal::led::led3()); } |
| 99 | +extern "C" auto main_core1(void) -> void { local::main_worker_core_x<1U>(mcal::led::led1()); } |
| 100 | +extern "C" auto main_core2(void) -> void { local::main_worker_core_x<2U>(mcal::led::led2()); } |
| 101 | +extern "C" auto main_core3(void) -> void { local::main_worker_core_x<3U>(mcal::led::led3()); } |
31 | 102 |
|
32 | 103 | extern "C" auto main_core0_init(void) -> void |
33 | 104 | { |
34 | 105 | mcal::wdg::init (nullptr); |
35 | 106 | mcal::port::init(nullptr); |
36 | 107 | mcal::osc::init (nullptr); |
37 | 108 | } |
38 | | - |
39 | | -auto local::main_worker_core_x(mcal::led::led_base& my_led) -> void |
40 | | -{ |
41 | | - my_led.toggle(); |
42 | | - |
43 | | - for(;;) |
44 | | - { |
45 | | - using local_timer_type = util::timer<std::uint64_t>; |
46 | | - using local_tick_type = typename local_timer_type::tick_type; |
47 | | - |
48 | | - local_timer_type::blocking_delay(local_timer_type::seconds(local_tick_type { UINT8_C(1) })); |
49 | | - |
50 | | - my_led.toggle(); |
51 | | - } |
52 | | -} |
|
0 commit comments