ald_rmu.c 2.7 KB
Newer Older
W
wangyq2018 已提交
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
/**
  *********************************************************************************
  *
  * @file    ald_rmu.c
  * @brief   RMU module driver.
  *
  * @version V1.0
  * @date    04 Dec 2017
  * @author  AE Team
  * @note
  *
  * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  *
  *********************************************************************************
  */

#include "ald_rmu.h"
#include "ald_syscfg.h"

/** @addtogroup ES32FXXX_ALD
  * @{
  */

/** @defgroup RMU RMU
  * @brief RMU module driver
  * @{
  */
#ifdef ALD_RMU

/** @defgroup RMU_Public_Functions RMU Public Functions
  * @{
  */

/**
  * @brief  Configure BOR parameters.
  * @param  flt: filter time.
  * @param  vol: The voltage.
  * @param  state: The new status: ENABLE/DISABLE.
  * @retval None
  */
41
void ald_rmu_bor_config(rmu_bor_filter_t flt, rmu_bor_vol_t vol, type_func_t state)
W
wangyq2018 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
{
    assert_param(IS_FUNC_STATE(state));

    SYSCFG_UNLOCK();

    if (state)
    {
        assert_param(IS_RMU_BORFLT(flt));
        assert_param(IS_RMU_BORVOL(vol));

        MODIFY_REG(RMU->CR, RMU_CR_BORFLT_MSK, flt << RMU_CR_BORFLT_POSS);
        MODIFY_REG(RMU->CR, RMU_CR_BORVS_MSK, vol << RMU_CR_BORVS_POSS);
        SET_BIT(RMU->CR, RMU_CR_BOREN_MSK);
    }
    else
    {
        CLEAR_BIT(RMU->CR, RMU_CR_BOREN_MSK);
    }

    SYSCFG_LOCK();
    return;
}

/**
  * @brief  Get specified reset status
  * @param  state: Speicifies the type of the reset,
  * @retval The status: SET/RESET.
  */
70
flag_status_t ald_rmu_get_reset_status(rmu_state_t state)
W
wangyq2018 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84
{
    assert_param(IS_RMU_STATE(state));

    if (READ_BIT(RMU->RSTSR, state))
        return SET;

    return RESET;
}

/**
  * @brief  Clear the specified reset status
  * @param  state: Specifies the type of the reset,
  * @retval None
  */
85
void ald_rmu_clear_reset_status(rmu_state_t state)
W
wangyq2018 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99
{
    assert_param(IS_RMU_STATE_CLEAR(state));

    SYSCFG_UNLOCK();
    WRITE_REG(RMU->CRSTSR, state);
    SYSCFG_LOCK();

    return;
}
/**
  * @brief  Reset peripheral device
  * @param  perh: The peripheral device,
  * @retval None
  */
100
void ald_rmu_reset_periperal(rmu_peripheral_t perh)
W
wangyq2018 已提交
101 102 103 104 105 106 107 108 109 110 111
{
    uint32_t idx, pos;

    assert_param(IS_RMU_PERH(perh));

    idx = (perh >> 27) & 0x7;
    pos = perh & ~(0x7 << 27);
    SYSCFG_UNLOCK();

    switch (idx)
    {
112 113 114
        case 0:
            WRITE_REG(RMU->AHB1RSTR, pos);
            break;
W
wangyq2018 已提交
115

116 117 118
        case 1:
            WRITE_REG(RMU->AHB2RSTR, pos);
            break;
W
wangyq2018 已提交
119

120 121 122
        case 2:
            WRITE_REG(RMU->APB1RSTR, pos);
            break;
W
wangyq2018 已提交
123

124 125 126
        case 4:
            WRITE_REG(RMU->APB2RSTR, pos);
            break;
W
wangyq2018 已提交
127

128 129
        default:
            break;
W
wangyq2018 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    }

    SYSCFG_LOCK();
    return;
}

/**
  * @}
  */
#endif /* ALD_RMU */
/**
  * @}
  */

/**
  * @}
  */