tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
interrupt.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_HARDWARE_STM32_INTERRUPT_HPP
5#define TETL_HARDWARE_STM32_INTERRUPT_HPP
6
7#include <etl/version.hpp>
8
9#include <etl/array.hpp>
10#include <etl/cstddef.hpp>
11
12namespace etl::experimental::hardware::stm32 {
13// EXAMPLE
14// extern isr::vector_t callbacks;
15
16// static void dummy_handler() {
17// }
18
19// constexpr auto callbacks = isr::vector_t{
20// nullptr,
21// dummy_handler,
22// dummy_handler,
23// };
24
25// void NMI_Handler() { isr::call(callbacks, isr_ids::nmi); }
26// void HardFault_Handler() { isr::call(callbacks, isr_ids::hard_fault); }
27// void SysTick_Handler() { isr::call_checked(callbacks, isr_ids::sys_tick); }
28
29enum struct isr_ids : size_t {
30 nmi,
33 max_id,
34};
35
36struct isr {
37 using callback_t = void (*)();
38 using vector_t = etl::array<callback_t, static_cast<size_t>(isr_ids::max_id)>;
39
40 static auto call(vector_t const& callbacks, isr_ids id) noexcept -> void
41 {
42 callbacks[static_cast<size_t>(id)]();
43 }
44
45 static auto call_checked(vector_t const& callbacks, isr_ids id) noexcept -> void
46 {
47 if (callbacks[static_cast<size_t>(id)] != nullptr) {
48 callbacks[static_cast<size_t>(id)]();
49 }
50 }
51};
52} // namespace etl::experimental::hardware::stm32
53
54#endif // TETL_HARDWARE_STM32_INTERRUPT_HPP
isr_ids
Definition interrupt.hpp:29
Definition adjacent_find.hpp:9
A container that encapsulates fixed size arrays.
Definition array.hpp:49
constexpr auto operator[](size_type const pos) const noexcept -> const_reference
Accesses the specified item with range checking.
Definition array.hpp:74
Definition interrupt.hpp:36
static auto call(vector_t const &callbacks, isr_ids id) noexcept -> void
Definition interrupt.hpp:40
static auto call_checked(vector_t const &callbacks, isr_ids id) noexcept -> void
Definition interrupt.hpp:45