PF1550 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
pf1550_sequencer.hpp
Go to the documentation of this file.
1
21#ifndef PF1550_SEQUENCER_HPP
22#define PF1550_SEQUENCER_HPP
23
24#include <array>
25#include <cstddef>
26#include <cstdint>
27
28#include "pf1550_detail.hpp"
29#include "pf1550_types.hpp"
30
31namespace pf1550 {
32
40inline constexpr uint32_t kVsnvsTurnOnDelayUs = 600;
42inline constexpr uint32_t kVsnvsRiseUs = 100;
44inline constexpr uint32_t kSlotFastUs = 500;
46inline constexpr uint32_t kSlotSlowUs = 2000;
48inline constexpr uint32_t kPowerDownStepUs = 2000;
50inline constexpr uint8_t kMaxSequenceNumber = 7;
51
55 std::array<uint8_t, kRailCount> order{};
57 uint32_t slot_us{0};
59 bool pwron_edge{false};
62 bool sw1_dvs{false};
64 bool sw2_dvs{false};
65};
66
67namespace detail {
68
71inline constexpr std::array<std::array<uint8_t, kRailCount>, 9> kPowerUpOrder = {{
72 {1, 2, 3, 4, 4, 5, 5}, // A1
73 {5, 5, 1, 1, 1, 1, 5}, // A2
74 {3, 3, 3, 3, 2, 3, 3}, // A3
75 {4, 3, 2, 1, 2, 1, 3}, // A4
76 {3, 3, 3, 3, 2, 3, 3}, // A5
77 {3, 3, 3, 3, 2, 3, 3}, // A6
78 {3, 3, 3, 3, 2, 3, 3}, // A7
79 {3, 3, 3, 3, 2, 3, 3}, // A8
80 {3, 3, 3, 3, 3, 3, 3}, // A9
81}};
82
84inline constexpr std::array<bool, 9> kSw1Dvs = {false, true, true, true, true,
85 true, true, true, false};
87inline constexpr std::array<bool, 9> kSw2Dvs = {true, false, false, true, false,
88 false, false, false, false};
89
90} // namespace detail
91
99 const auto n = static_cast<std::size_t>(detail::ToUnderlying(option));
100 if ((n < 1U) || (n > detail::kPowerUpOrder.size())) {
102 }
103 StartupProfile p{};
104 p.order = detail::kPowerUpOrder[n - 1U];
105 p.slot_us = (option == Option::A1) ? kSlotFastUs : kSlotSlowUs;
106 p.pwron_edge = (option == Option::A8);
107 p.sw1_dvs = detail::kSw1Dvs[n - 1U];
108 p.sw2_dvs = detail::kSw2Dvs[n - 1U];
110}
111
118constexpr uint32_t PowerUpDelayUs(const StartupProfile& profile, Rail rail) noexcept {
119 const uint32_t order =
120 profile.order[static_cast<std::size_t>(detail::ToUnderlying(rail)) % kRailCount];
121 return (order > 1U) ? ((order - 1U) * profile.slot_us) : 0U;
122}
123
129constexpr uint32_t PowerUpDurationUs(const StartupProfile& profile) noexcept {
130 uint32_t longest = 0U;
131 for (const uint8_t order : profile.order) {
132 const uint32_t d = (order > 1U) ? ((static_cast<uint32_t>(order) - 1U) * profile.slot_us) : 0U;
133 longest = (d > longest) ? d : longest;
134 }
135 return longest;
136}
137
143constexpr Result<uint32_t> ResetReleaseDelayMs(uint32_t code) noexcept {
144 constexpr std::array<uint32_t, 8> kMs = {2, 0, 4, 8, 16, 128, 256, 1024};
145 if ((code >= kMs.size()) || (kMs[code] == 0U)) {
147 }
148 return Result<uint32_t>::Success(kMs[code]);
149}
150
160 uint32_t por_dly_code) noexcept {
161 const Result<uint32_t> ms = ResetReleaseDelayMs(por_dly_code);
162 if (!ms.ok()) {
164 }
166 (ms.value * 1000U));
167}
168
174constexpr bool IsPowerDownBypassed(const PowerDownSequence& sequence) noexcept {
175 bool bypassed = true;
176 for (const uint8_t order : sequence.order) {
177 bypassed = bypassed && (order == 0U);
178 }
179 return bypassed;
180}
181
190constexpr uint32_t PowerDownDelayUs(const PowerDownSequence& sequence, Rail rail) noexcept {
191 uint32_t highest = 0U;
192 for (const uint8_t order : sequence.order) {
193 highest = (order > highest) ? order : highest;
194 }
195 const uint32_t own =
196 sequence.order[static_cast<std::size_t>(detail::ToUnderlying(rail)) % kRailCount];
197 return (highest - own) * kPowerDownStepUs;
198}
199
205constexpr uint32_t PowerDownDurationUs(const PowerDownSequence& sequence) noexcept {
206 uint32_t highest = 0U;
207 for (const uint8_t order : sequence.order) {
208 highest = (order > highest) ? order : highest;
209 }
210 return highest * kPowerDownStepUs;
211}
212
219constexpr PowerDownSequence MirrorOf(const StartupProfile& profile) noexcept {
221 s.order = profile.order;
222 return s;
223}
224
225// The checks sit in `detail` for its typed integer literals (MISRA C++:2023 Rule 7.0.6).
226namespace detail {
227
228static_assert((StartupProfileOf(Option::A1).value.slot_us == 500U) &&
229 (StartupProfileOf(Option::A4).value.slot_us == 2000U));
230static_assert(!StartupProfileOf(Option::A0).ok() && !StartupProfileOf(Option::Unknown).ok());
231static_assert((StartupProfileOf(Option::A4).value.order[0] == 4U) &&
232 (StartupProfileOf(Option::A4).value.order[6] == 3U));
233static_assert(StartupProfileOf(Option::A8).value.pwron_edge &&
234 !StartupProfileOf(Option::A9).value.pwron_edge);
235static_assert(StartupProfileOf(Option::A1).value.sw2_dvs &&
236 !StartupProfileOf(Option::A1).value.sw1_dvs &&
237 StartupProfileOf(Option::A5).value.sw1_dvs &&
238 !StartupProfileOf(Option::A9).value.sw1_dvs);
239static_assert(PowerUpDurationUs(StartupProfileOf(Option::A4).value) == 6000U);
240static_assert(PowerUpDurationUs(StartupProfileOf(Option::A1).value) == 2000U);
241static_assert((ResetReleaseDelayMs(0_u32).value == 2U) && !ResetReleaseDelayMs(1_u32).ok() &&
242 (ResetReleaseDelayMs(7_u32).value == 1024U));
243static_assert(ColdStartToResetReleaseUs(StartupProfileOf(Option::A4).value, 0_u32).value == 8600U);
244static_assert(IsPowerDownBypassed(PowerDownSequence{}) &&
245 (PowerDownDurationUs(PowerDownSequence{}) == 0U));
246static_assert(PowerDownDelayUs(MirrorOf(StartupProfileOf(Option::A4).value), Rail::Sw1) == 0U);
247static_assert(PowerDownDelayUs(MirrorOf(StartupProfileOf(Option::A4).value), Rail::Ldo1) == 6000U);
248
249} // namespace detail
250
253} // namespace pf1550
254
255#endif // PF1550_SEQUENCER_HPP
constexpr uint32_t PowerDownDurationUs(const PowerDownSequence &sequence) noexcept
How long the power-down sequence takes: the delay of the last rail.
Definition pf1550_sequencer.hpp:205
constexpr uint32_t PowerUpDelayUs(const StartupProfile &profile, Rail rail) noexcept
When a rail turns on, counted from the start of the first power-up slot.
Definition pf1550_sequencer.hpp:118
constexpr bool IsPowerDownBypassed(const PowerDownSequence &sequence) noexcept
Whether the power-down sequencer is bypassed: every order is 0 (section 10.7).
Definition pf1550_sequencer.hpp:174
constexpr Result< uint32_t > ResetReleaseDelayMs(uint32_t code) noexcept
The delay of RESETBMCU after the last regulator, from POR_DLY[2:0] (Table 135).
Definition pf1550_sequencer.hpp:143
constexpr uint32_t kPowerDownStepUs
Power-down delay between regulators, microseconds (tD5 typical 2.0 ms).
Definition pf1550_sequencer.hpp:48
constexpr PowerDownSequence MirrorOf(const StartupProfile &profile) noexcept
The power-down order that mirrors the power-up order of an option, as the registers hold it after res...
Definition pf1550_sequencer.hpp:219
constexpr Result< uint32_t > ColdStartToResetReleaseUs(const StartupProfile &profile, uint32_t por_dly_code) noexcept
From a cold start to RESETBMCU high, for an option and a POR_DLY code (Table 84).
Definition pf1550_sequencer.hpp:159
constexpr uint32_t kVsnvsTurnOnDelayUs
Turn-on delay of VSNVS after a cold start, microseconds (Table 84, tD1 typical 0.6 ms).
Definition pf1550_sequencer.hpp:40
constexpr uint8_t kMaxSequenceNumber
Largest sequence number a *_PWRUP_SEQ or *_PWRDN_SEQ field holds.
Definition pf1550_sequencer.hpp:50
constexpr uint32_t kSlotFastUs
Power-up slot with OTP_SEQ_CLK_SPEED = 0, microseconds (tD3 typical 0.5 ms).
Definition pf1550_sequencer.hpp:44
constexpr uint32_t kVsnvsRiseUs
Rise time of VSNVS, microseconds (tR1 typical 0.1 ms).
Definition pf1550_sequencer.hpp:42
constexpr Result< StartupProfile > StartupProfileOf(Option option) noexcept
The pre-programmed start-up sequence of an option (Table 85).
Definition pf1550_sequencer.hpp:98
constexpr uint32_t PowerUpDurationUs(const StartupProfile &profile) noexcept
How long the power-up sequencer runs: the start of the last slot used.
Definition pf1550_sequencer.hpp:129
constexpr uint32_t kSlotSlowUs
Power-up slot with OTP_SEQ_CLK_SPEED = 1, microseconds (tD3 typical 2.0 ms).
Definition pf1550_sequencer.hpp:46
constexpr uint32_t PowerDownDelayUs(const PowerDownSequence &sequence, Rail rail) noexcept
When a rail turns off in a power-down, counted from the start of the sequence.
Definition pf1550_sequencer.hpp:190
constexpr std::size_t kRailCount
Number of rails.
Definition pf1550_types.hpp:259
Option
The start-up option of the part (OTP_FLAVOR, Table 87; ordering codes A0 to A9).
Definition pf1550_types.hpp:215
Rail
The power rails the driver configures.
Definition pf1550_types.hpp:249
@ A4
Option A4.
@ A1
Default option.
@ A9
Option A9.
@ Unknown
A flavour byte the data sheet does not list (ambiguity C10).
@ A5
Option A5.
@ A0
Not programmed: internal validation only; nothing is assumed about it.
@ A8
Option A8 (edge-sensitive PWRON).
@ Sw1
Buck 1, 1.0 A, DVS.
@ Ldo1
LDO1, 300 mA, load switch capable.
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,...
Public types of the PF1550 driver: errors, Result<T>, enumerations, units, status and interrupt types...
The registers of the power-down sequence (Tables 139 to 145).
Definition pf1550_types.hpp:582
std::array< uint8_t, kRailCount > order
Definition pf1550_types.hpp:585
The value of a call, or why there is none.
Definition pf1550_types.hpp:123
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition pf1550_types.hpp:149
static constexpr Result Success(T v) noexcept
A successful result.
Definition pf1550_types.hpp:141
T value
The value; T{} when the call failed.
Definition pf1550_types.hpp:124
constexpr bool ok() const noexcept
Definition pf1550_types.hpp:128
The start-up behaviour of one pre-programmed option (Table 85).
Definition pf1550_sequencer.hpp:53
bool sw2_dvs
OTP_SW2_DVS_SEL: true for DVS mode (C57).
Definition pf1550_sequencer.hpp:64
bool pwron_edge
OTP_PWRON_CFG: true when PWRON is edge sensitive (option A8), false for level.
Definition pf1550_sequencer.hpp:59
bool sw1_dvs
Definition pf1550_sequencer.hpp:62
uint32_t slot_us
Length of one power-up slot in microseconds: 500 for OTP_SEQ_CLK_SPEED = 0, 2000 for 1.
Definition pf1550_sequencer.hpp:57
std::array< uint8_t, kRailCount > order
OTP_xxx_PWRUP_SEQ[2:0] per rail, indexed by Rail.
Definition pf1550_sequencer.hpp:55