/** * @brief Changes the clock mode of a peripheral. * * @param[in] n index of the @p PCTL register * @param[in] pctl new value for the @p PCTL register * * @notapi */ void halSPCSetPeripheralClockMode(uint32_t n, uint32_t pctl) { uint32_t mode; ME.PCTL[n].R = pctl; mode = ME.MCTL.B.TARGET_MODE; ME.MCTL.R = SPC5_ME_MCTL_MODE(mode) | SPC5_ME_MCTL_KEY; ME.MCTL.R = SPC5_ME_MCTL_MODE(mode) | SPC5_ME_MCTL_KEY_INV; }
/** * @brief Switches the system to the specified run mode. * * @param[in] mode one of the possible run modes * * @return The operation status. * @retval OSAL_SUCCESS if the switch operation has been completed. * @retval OSAL_FAILED if the switch operation failed. */ bool halSPCSetRunMode(spc5_runmode_t mode) { /* Clearing status register bits I_IMODE(4) and I_IMTC(1).*/ ME.IS.R = 5; /* Starts a transition process.*/ ME.MCTL.R = SPC5_ME_MCTL_MODE(mode) | SPC5_ME_MCTL_KEY; ME.MCTL.R = SPC5_ME_MCTL_MODE(mode) | SPC5_ME_MCTL_KEY_INV; /* Waits for the mode switch or an error condition.*/ while (TRUE) { uint32_t r = ME.IS.R; if (r & 1) return OSAL_SUCCESS; if (r & 4) return OSAL_FAILED; } }
/** * @brief Switches the system to the specified run mode. * * @param[in] mode one of the possible run modes * * @return The operation status. * @retval CH_SUCCESS if the switch operation has been completed. * @retval CH_FAILED if the switch operation failed. */ bool_t halSPCSetRunMode(spc5_runmode_t mode) { /* Starts a transition process.*/ ME.MCTL.R = SPC5_ME_MCTL_MODE(mode) | SPC5_ME_MCTL_KEY; ME.MCTL.R = SPC5_ME_MCTL_MODE(mode) | SPC5_ME_MCTL_KEY_INV; /* Waits the transition process to start.*/ while (!ME.GS.B.S_MTRANS) ; /* Waits the transition process to end.*/ while (ME.GS.B.S_MTRANS) ; /* Verifies that the mode has been effectively switched.*/ if (ME.GS.B.S_CURRENTMODE != mode) return CH_FAILED; return CH_SUCCESS; }