~aleteoryx/muditaos

ref: 3cbbeff551230786ae13c23a7bf4fa8c50099896 muditaos/module-bsp/board/rt1051/bsp/lpm/LDO.cpp -rw-r--r-- 1.9 KiB
3cbbeff5 — Lefucjusz [MOS-1011] Fix frequency switching stability 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "LDO.hpp"
#include <fsl_common.h>
#include <critical.hpp>

namespace
{
    constexpr auto ldoStabilizationDelayUs{40};
}

namespace bsp::ldo
{
    void SwitchToRegularMode()
    {
        cpp_freertos::CriticalSection::Enter();

        /* Enable regular 2P5 and disable weak 2P5 LDO */
        PMU->REG_2P5_SET = PMU_REG_2P5_ENABLE_LINREG_MASK;
        PMU->REG_2P5_CLR = PMU_REG_2P5_ENABLE_WEAK_LINREG_MASK;

        /* Wait for regular 2P5 to become stable (documentation Low Power AN12085) */
        while ((PMU->REG_2P5 & PMU_REG_2P5_OK_VDD2P5_MASK) == 0) {}

        /* Enable regular 1P1 and disable weak 1P1 LDO */
        PMU->REG_1P1_SET = PMU_REG_1P1_ENABLE_LINREG_MASK;
        PMU->REG_1P1_CLR = PMU_REG_1P1_ENABLE_WEAK_LINREG_MASK;

        /* Wait for regular 1P1 to become stable (documentation Low Power AN12085) */
        while ((PMU->REG_1P1 & PMU_REG_1P1_OK_VDD1P1_MASK) == 0) {}

        cpp_freertos::CriticalSection::Exit();

#if BOARD_BellHybrid == 1
        NVIC_ClearPendingIRQ(ANATOP_EVENT0_IRQn);
        EnableIRQ(ANATOP_EVENT0_IRQn);
#endif
    }

    void SwitchToLowPowerMode()
    {
#if BOARD_BellHybrid == 1
        DisableIRQ(ANATOP_EVENT0_IRQn);
#endif

        cpp_freertos::CriticalSection::Enter();

        /* Enable weak 2P5 and disable regular 2P5 LDO */
        PMU->REG_2P5_SET = PMU_REG_2P5_ENABLE_WEAK_LINREG_MASK;
        PMU->REG_2P5_CLR = PMU_REG_2P5_ENABLE_LINREG_MASK;

        /* Enable weak 1P1 and disable regular 1P1 LDO */
        PMU->REG_1P1_SET = PMU_REG_1P1_ENABLE_WEAK_LINREG_MASK;
        PMU->REG_1P1_CLR = PMU_REG_1P1_ENABLE_LINREG_MASK;

        /* Wait for weak LDOs to stabilize */
        SDK_DelayAtLeastUs(ldoStabilizationDelayUs, CLOCK_GetCpuClkFreq());

        cpp_freertos::CriticalSection::Exit();
    }
} // namespace bsp::ldo