static void init_freqm(void) { FREQM->FREQM_MODE = 0; while((FREQM->FREQM_STATUS & FREQM_STATUS_RCLKBUSY)>0); FREQM->FREQM_MODE = FREQM_MODE_REFSEL(FREQM_REF_RCOSC); while((FREQM->FREQM_STATUS & FREQM_STATUS_RCLKBUSY)>0); FREQM->FREQM_MODE = FREQM_MODE_REFSEL(FREQM_REF_RCOSC)|FREQM_MODE_REFCEN; while((FREQM->FREQM_STATUS & FREQM_STATUS_RCLKBUSY)>0); FREQM->FREQM_MODE = FREQM_MODE_REFSEL(FREQM_REF_RCOSC)|FREQM_MODE_REFCEN| FREQM_MODE_REFNUM(115)|FREQM_MODE_CLKSEL(FREQM_OSC0); }
/** * \brief Configure FREQM with specified value. * * \param dev_inst Device structure pointer. * \param freqm Base address of the FREQM instance. * \param cfg Pointer to FREQM configuration * * \return Status code */ enum status_code freqm_init( struct freqm_dev_inst *const dev_inst, Freqm *const freqm, struct freqm_config *const cfg) { uint32_t timeout = FREQM_NUM_OF_ATTEMPTS; /* Sanity check arguments */ Assert(dev_inst); Assert(freqm); Assert(cfg); dev_inst->hw_dev = freqm; dev_inst->freqm_cfg = cfg; sysclk_enable_peripheral_clock(freqm); freqm->FREQM_MODE = 0; freqm_disable_refclk(dev_inst); while (freqm_get_status(dev_inst) & FREQM_STATUS_RCLKBUSY) { if (!timeout--) { return ERR_TIMEOUT; } } freqm->FREQM_MODE |= FREQM_MODE_REFSEL(cfg->ref_clk); freqm_enable_refclk(dev_inst); while (freqm_get_status(dev_inst) & FREQM_STATUS_RCLKBUSY) { if (!timeout--) { return ERR_TIMEOUT; } } freqm->FREQM_MODE |= FREQM_MODE_REFNUM(cfg->duration); freqm->FREQM_MODE |= FREQM_MODE_CLKSEL(cfg->msr_clk); _freqm_instance = dev_inst; return STATUS_OK; }