PF1550 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
pf1550_irq.hpp
Go to the documentation of this file.
1
7#ifndef PF1550_IRQ_HPP
8#define PF1550_IRQ_HPP
9
10#include <array>
11#include <cstddef>
12#include <cstdint>
13
14#include "pf1550_detail.hpp"
15#include "pf1550_registers.hpp"
16#include "pf1550_types.hpp"
17
18namespace pf1550 {
19
29 uint8_t bit;
30};
31
33inline constexpr std::array<IrqLocation, kIrqSourceCount> kIrqLocations = {{
34 {.group = IrqGroup::Charger, .bit = 0}, {.group = IrqGroup::Charger, .bit = 1},
35 {.group = IrqGroup::Charger, .bit = 2}, {.group = IrqGroup::Charger, .bit = 3},
36 {.group = IrqGroup::Charger, .bit = 5}, {.group = IrqGroup::Charger, .bit = 6},
37 {.group = IrqGroup::Charger, .bit = 7}, {.group = IrqGroup::SwLowSide, .bit = 0},
38 {.group = IrqGroup::SwLowSide, .bit = 1}, {.group = IrqGroup::SwLowSide, .bit = 2},
39 {.group = IrqGroup::SwHighSide, .bit = 0}, {.group = IrqGroup::SwHighSide, .bit = 1},
40 {.group = IrqGroup::SwHighSide, .bit = 2}, {.group = IrqGroup::SwDvs, .bit = 0},
41 {.group = IrqGroup::SwDvs, .bit = 1}, {.group = IrqGroup::Ldo, .bit = 0},
42 {.group = IrqGroup::Ldo, .bit = 1}, {.group = IrqGroup::Ldo, .bit = 2},
43 {.group = IrqGroup::Temp, .bit = 0}, {.group = IrqGroup::Temp, .bit = 2},
44 {.group = IrqGroup::Onkey, .bit = 0}, {.group = IrqGroup::Onkey, .bit = 1},
45 {.group = IrqGroup::Onkey, .bit = 2}, {.group = IrqGroup::Onkey, .bit = 3},
46 {.group = IrqGroup::Onkey, .bit = 4}, {.group = IrqGroup::Onkey, .bit = 5},
47 {.group = IrqGroup::Misc, .bit = 0}, {.group = IrqGroup::Misc, .bit = 1},
48 {.group = IrqGroup::Misc, .bit = 2}, {.group = IrqGroup::Misc, .bit = 3},
49 {.group = IrqGroup::Misc, .bit = 4},
50}};
51
65inline constexpr std::array<uint8_t, kIrqGroups> kIrqDefinedBits = {0xEF, 0x07, 0x07, 0x03,
66 0x07, 0x05, 0x3F, 0x1F};
67
69inline constexpr uint8_t kCategoryCharger = 1U << 0;
71inline constexpr uint8_t kCategorySw = 0x0E;
73inline constexpr uint8_t kCategoryLdo = 1U << 4;
75inline constexpr uint8_t kCategoryOnkey = 1U << 5;
77inline constexpr uint8_t kCategoryTemp = 1U << 6;
79inline constexpr uint8_t kCategoryMisc = 1U << 7;
80
84constexpr uint8_t CategoryBitsOf(IrqGroup group) noexcept {
85 switch (group) {
87 return kCategoryCharger;
90 return kCategorySw;
91 case IrqGroup::SwDvs:
92 return 0x06;
93 case IrqGroup::Ldo:
94 return kCategoryLdo;
95 case IrqGroup::Temp:
96 return kCategoryTemp;
97 case IrqGroup::Onkey:
98 return kCategoryOnkey;
99 case IrqGroup::Misc:
100 return kCategoryMisc;
101 default:
102 break;
103 }
104 return 0U;
105}
106
110constexpr IrqLocation LocationOf(IrqSource source) noexcept {
111 const auto i = static_cast<std::size_t>(detail::ToUnderlying(source));
112 return (i < kIrqLocations.size()) ? kIrqLocations[i]
113 : IrqLocation{.group = IrqGroup::Charger, .bit = 0};
114}
115
120constexpr bool Has(const InterruptEvents& events, IrqSource source) noexcept {
121 const IrqLocation loc = LocationOf(source);
122 const uint32_t byte =
123 events.status[static_cast<std::size_t>(detail::ToUnderlying(loc.group)) % kIrqGroups];
124 return ((byte >> (loc.bit & 7U)) & 1U) != 0U;
125}
126
131constexpr bool IsFaultSource(IrqSource source) noexcept {
132 // SW1..3 low-side (7..9) and high-side (10..12) limits, LDO faults (15..17), 125 C (19), SYS_OVLO
133 // (30).
134 constexpr uint32_t kFaultSources = (0x3FU << 7) | (0x7U << 15) | (1U << 19) | (1U << 30);
135 const auto i = static_cast<uint32_t>(detail::ToUnderlying(source));
136 return (i < kIrqSourceCount) && (((kFaultSources >> i) & 1U) != 0U);
137}
138
142constexpr bool HasFault(const std::array<uint8_t, kIrqGroups>& status) noexcept {
143 InterruptEvents e{};
144 e.status = status;
145 for (std::size_t i = 0U; i < kIrqSourceCount; ++i) {
146 const auto source = static_cast<IrqSource>(i);
147 if (IsFaultSource(source) && Has(e, source)) {
148 return true;
149 }
150 }
151 return false;
152}
153
158constexpr uint8_t MaskByteFor(const IrqMask& mask, IrqGroup group) noexcept {
159 return mask.masked[static_cast<std::size_t>(detail::ToUnderlying(group)) % kIrqGroups];
160}
161
165template <std::size_t N>
166constexpr IrqMask UnmaskOnly(const std::array<IrqSource, N>& sources) noexcept {
167 IrqMask m{};
168 for (const IrqSource s : sources) {
169 const IrqLocation loc = LocationOf(s);
170 auto& byte = m.masked[static_cast<std::size_t>(detail::ToUnderlying(loc.group)) % kIrqGroups];
171 byte = static_cast<uint8_t>(static_cast<uint32_t>(byte) & ~(1U << (loc.bit & 7U)));
172 }
173 return m;
174}
175
176static_assert((LocationOf(IrqSource::ChgVbus).bit == 5U) &&
181static_assert(UnmaskOnly(std::array<IrqSource, 1>{IrqSource::OnkeyPush}).masked[6] == 0xFEU);
182
185} // namespace pf1550
186
187#endif // PF1550_IRQ_HPP
constexpr bool Has(const InterruptEvents &events, IrqSource source) noexcept
Definition pf1550_irq.hpp:120
constexpr IrqMask UnmaskOnly(const std::array< IrqSource, N > &sources) noexcept
Definition pf1550_irq.hpp:166
constexpr std::array< uint8_t, kIrqGroups > kIrqSenseRegs
The sense register of each group (the charger's is CHG_INT_OK).
Definition pf1550_irq.hpp:61
constexpr uint8_t MaskByteFor(const IrqMask &mask, IrqGroup group) noexcept
Definition pf1550_irq.hpp:158
constexpr std::array< IrqLocation, kIrqSourceCount > kIrqLocations
The location of every source, indexed by IrqSource (Tables 90 to 110 and 150).
Definition pf1550_irq.hpp:33
constexpr uint8_t kCategoryMisc
MISC_INT.
Definition pf1550_irq.hpp:79
constexpr bool IsFaultSource(IrqSource source) noexcept
Definition pf1550_irq.hpp:131
constexpr uint8_t kCategoryTemp
TEMP_INT.
Definition pf1550_irq.hpp:77
constexpr uint8_t kCategorySw
SW1_INT, SW2_INT and SW3_INT.
Definition pf1550_irq.hpp:71
constexpr IrqLocation LocationOf(IrqSource source) noexcept
Definition pf1550_irq.hpp:110
constexpr uint8_t kCategoryOnkey
ONKEY_INT.
Definition pf1550_irq.hpp:75
constexpr std::array< uint8_t, kIrqGroups > kIrqMaskRegs
The mask register of each group.
Definition pf1550_irq.hpp:57
constexpr std::array< uint8_t, kIrqGroups > kIrqDefinedBits
The bits that carry a source in each group; the others are reserved and preserved.
Definition pf1550_irq.hpp:65
constexpr bool HasFault(const std::array< uint8_t, kIrqGroups > &status) noexcept
Definition pf1550_irq.hpp:142
constexpr std::array< uint8_t, kIrqGroups > kIrqStatRegs
The status register of each group, indexed by IrqGroup.
Definition pf1550_irq.hpp:53
constexpr uint8_t kCategoryLdo
LDO_INT.
Definition pf1550_irq.hpp:73
constexpr uint8_t kCategoryCharger
INT_CATEGORY bit of a group's summary (the three SW groups share bits 1 to 3 by rail).
Definition pf1550_irq.hpp:69
constexpr uint8_t CategoryBitsOf(IrqGroup group) noexcept
Definition pf1550_irq.hpp:84
constexpr uint8_t kSwIntStat2
SW_INT_STAT2: SW1 and SW2 DVS done.
Definition pf1550_registers.hpp:46
constexpr uint8_t kSwIntSense0
SW_INT_SENSE0.
Definition pf1550_registers.hpp:42
constexpr uint8_t kSwIntMask2
SW_INT_MASK2.
Definition pf1550_registers.hpp:47
constexpr uint8_t kTempIntMask0
TEMP_INT_MASK0.
Definition pf1550_registers.hpp:53
constexpr uint8_t kMiscIntStat0
MISC_INT_STAT0: power-up/down, PWRON, VSYS.
Definition pf1550_registers.hpp:58
constexpr uint8_t kChgIntMask
CHG_INT_MASK (reset: all masked).
Definition pf1550_registers.hpp:115
constexpr uint8_t kMiscIntSense0
MISC_INT_SENSE0.
Definition pf1550_registers.hpp:60
constexpr uint8_t kTempIntStat0
TEMP_INT_STAT0: die temperature 110 and 125 C.
Definition pf1550_registers.hpp:52
constexpr uint8_t kChgIntOk
CHG_INT_OK (R): live state of the sources.
Definition pf1550_registers.hpp:116
constexpr uint8_t kSwIntSense1
SW_INT_SENSE1.
Definition pf1550_registers.hpp:45
constexpr uint8_t kSwIntSense2
SW_INT_SENSE2.
Definition pf1550_registers.hpp:48
constexpr uint8_t kLdoIntMask0
LDO_INT_MASK0.
Definition pf1550_registers.hpp:50
constexpr uint8_t kSwIntStat0
SW_INT_STAT0: SWx low-side current limit.
Definition pf1550_registers.hpp:40
constexpr uint8_t kMiscIntMask0
MISC_INT_MASK0.
Definition pf1550_registers.hpp:59
constexpr uint8_t kChgInt
CHG_INT: charger interrupt status.
Definition pf1550_registers.hpp:114
constexpr uint8_t kLdoIntStat0
LDO_INT_STAT0: LDOx current-limit faults.
Definition pf1550_registers.hpp:49
constexpr uint8_t kOnkeyIntStat0
ONKEY_INT_STAT0: push and 1, 2, 3, 4, 8 s.
Definition pf1550_registers.hpp:55
constexpr uint8_t kSwIntStat1
SW_INT_STAT1: SWx high-side current limit.
Definition pf1550_registers.hpp:43
constexpr uint8_t kOnkeyIntMask0
ONKEY_INT_MASK0.
Definition pf1550_registers.hpp:56
constexpr uint8_t kLdoIntSense0
LDO_INT_SENSE0.
Definition pf1550_registers.hpp:51
constexpr uint8_t kSwIntMask1
SW_INT_MASK1.
Definition pf1550_registers.hpp:44
constexpr uint8_t kTempIntSense0
TEMP_INT_SENSE0.
Definition pf1550_registers.hpp:54
constexpr uint8_t kOnkeyIntSense0
ONKEY_INT_SENSE0.
Definition pf1550_registers.hpp:57
constexpr uint8_t kSwIntMask0
SW_INT_MASK0.
Definition pf1550_registers.hpp:41
constexpr std::size_t kIrqSourceCount
Number of interrupt sources.
Definition pf1550_types.hpp:550
IrqGroup
Interrupt groups, one status/mask/sense register triple each.
Definition pf1550_types.hpp:504
IrqSource
Every interrupt source of Tables 90 to 110 and 150 (31 sources).
Definition pf1550_types.hpp:516
constexpr std::size_t kIrqGroups
Number of interrupt groups.
Definition pf1550_types.hpp:212
@ Onkey
ONKEY_INT_STAT0.
@ SwLowSide
SW_INT_STAT0.
@ SwHighSide
SW_INT_STAT1.
@ Ldo
LDO_INT_STAT0.
@ Misc
MISC_INT_STAT0.
@ SwDvs
SW_INT_STAT2.
@ Temp
TEMP_INT_STAT0.
@ Charger
CHG_INT (0x80).
@ Ldo2Fault
LDO2_FAULTI.
@ Temp125
THERM125I.
@ SysOvervoltage
SYS_OVLO_I.
The PF1550 driver: everything it declares lives here; internals in detail.
Definition pf1550.hpp:39
Compile-time helpers of the PF1550 driver: typed integer literals, exact hook matching,...
PF1550 register map: addresses, bit fields, reset values and the access table (datasheet section 12).
Public types of the PF1550 driver: errors, Result<T>, enumerations, units, status and interrupt types...
Interrupt events returned by ServiceInterrupts(), one status byte per group.
Definition pf1550_types.hpp:562
std::array< uint8_t, kIrqGroups > status
The status bytes as read, before any clear.
Definition pf1550_types.hpp:563
Where one interrupt source lives.
Definition pf1550_irq.hpp:27
IrqGroup group
The group (one status, mask and sense register).
Definition pf1550_irq.hpp:28
uint8_t bit
Bit number in those registers.
Definition pf1550_irq.hpp:29
Interrupt masks, one byte per group; a set bit masks the source. The default masks every source,...
Definition pf1550_types.hpp:556