/** * \brief Initializes the RTC module with given configurations. * * Initializes the module, setting up all given configurations to provide * the desired functionality of the RTC. * * \param[out] module Pointer to the software instance struct * \param[in] hw Pointer to hardware instance * \param[in] config Pointer to the configuration structure * * \return Status of the initialization procedure. * \retval STATUS_OK If the initialization was run stressfully * \retval STATUS_ERR_INVALID_ARG If invalid argument(s) were given */ enum status_code rtc_count_init( struct rtc_module *const module, Rtc *const hw, const struct rtc_count_config *const config) { /* Sanity check arguments */ Assert(module); Assert(hw); Assert(config); /* Initialize device instance */ module->hw = hw; /* Turn on the digital interface clock */ system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBA, MCLK_APBAMASK_RTC); /* Select RTC clock */ OSC32KCTRL->RTCCTRL.reg = RTC_CLOCK_SOURCE; /* Reset module to hardware defaults. */ rtc_count_reset(module); /* Save conf_struct internally for continued use. */ module->mode = config->mode; # if (RTC_INST_NUM == 1) _rtc_instance[0] = module; # else /* Register this instance for callbacks*/ _rtc_instance[_rtc_get_inst_index(hw)] = module; # endif /* Set config and return status. */ return _rtc_count_set_config(module, config); }
/** * \brief Initializes the RTC module with given configurations. * * Initializes the module, setting up all given configurations to provide * the desired functionality of the RTC. * * \param[out] module Pointer to the software instance struct * \param[in] hw Pointer to hardware instance * \param[in] config Pointer to the configuration structure * * \return Status of the initialization procedure. * \retval STATUS_OK If the initialization was run stressfully * \retval STATUS_ERR_INVALID_ARG If invalid argument(s) were given */ enum status_code rtc_count_init( struct rtc_module *const module, Rtc *const hw, const struct rtc_count_config *const config) { /* Sanity check arguments */ Assert(module); Assert(hw); Assert(config); /* Initialize device instance */ module->hw = hw; /* Turn on the digital interface clock */ system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBA, PM_APBAMASK_RTC); /* Set up GCLK */ struct system_gclk_chan_config gclk_chan_conf; system_gclk_chan_get_config_defaults(&gclk_chan_conf); gclk_chan_conf.source_generator = GCLK_GENERATOR_2; system_gclk_chan_set_config(RTC_GCLK_ID, &gclk_chan_conf); system_gclk_chan_enable(RTC_GCLK_ID); /* Reset module to hardware defaults. */ rtc_count_reset(module); /* Save conf_struct internally for continued use. */ module->mode = config->mode; module->continuously_update = config->continuously_update; # if (RTC_INST_NUM == 1) _rtc_instance[0] = module; # else /* Register this instance for callbacks*/ _rtc_instance[_rtc_get_inst_index(hw)] = module; # endif /* Set config and return status. */ return _rtc_count_set_config(module, config); }