예제 #1
0
파일: acifc.c 프로젝트: 70year/MICO
/**
 * \brief Initialize the ACIFC module.
 *
 * \note Enables the ACIFC module's source clock.
 *
 * \param[out] dev_inst Driver structure pointer
 * \param[in] ac        Module hardware register base address pointer
 * \param[in] cfg       Module configuration structure pointer
 *
 * \return Status of initialization.
 * \retval STATUS_OK         Module initiated correctly
 * \retval STATUS_ERR_DENIED Module has already been enabled
 * \retval STATUS_ERR_BUSY   Module is busy performing a comparison
 */
enum status_code ac_init(
		struct ac_dev_inst *const dev_inst,
		Acifc *const ac,
		struct ac_config *const cfg)
{
	/* Sanity check arguments. */
	Assert(dev_inst);
	Assert(ac);
	Assert(cfg);

	uint32_t ac_ctrl = ac->ACIFC_CTRL;
	/* Check if module is enabled. */
	if (ac_ctrl & ACIFC_CTRL_EN) {
		return STATUS_ERR_DENIED;
	}

	/* Check if comparison is in progress. */
	if (ac_ctrl & ACIFC_CTRL_USTART) {
		return STATUS_ERR_BUSY;
	}

	/* Enable and configure device instance */
	dev_inst->hw_dev = ac;
	sysclk_enable_peripheral_clock(ac);
	_ac_set_config(dev_inst, cfg);

	_ac_instance = (struct ac_dev_inst *)dev_inst;

	return STATUS_OK;
}
예제 #2
0
파일: ac.c 프로젝트: Gussy/sam0
/** \brief Initializes and configures the Analog Comparator driver.
 *
 *  Initializes the Analog Comparator driver, configuring it to the user
 *  supplied configuration parameters, ready for use. This function should be
 *  called before enabling the Analog Comparator.
 *
 *  \note Once called the Analog Comparator will not be running; to start the
 *        Analog Comparator call \ref ac_enable() after configuring the module.
 *
 * \param[out] module_inst  Pointer to the AC software instance struct
 * \param[in]  hw           Pointer to the AC module instance
 * \param[in]  config       Pointer to the config struct, created by the user
 *                          application
 */
enum status_code ac_init(
    struct ac_module *const module_inst,
    Ac *const hw,
    struct ac_config *const config)
{
    /* Sanity check arguments */
    Assert(module_inst);
    Assert(hw);
    Assert(config);

    /* Initialize device instance */
    module_inst->hw = hw;

#if (SAML21)
    /* Turn on the digital interface clock */
    system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBD, MCLK_APBDMASK_AC);
#else
    /* Turn on the digital interface clock */
    system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, MCLK_APBCMASK_AC);
#endif

#if AC_CALLBACK_MODE == true
    /* Initialize parameters */
    for (uint8_t i = 0; i < AC_CALLBACK_N; i++) {
        module_inst->callback[i]        = NULL;
    }

    /* Initialize software flags*/
    module_inst->register_callback_mask = 0x00;
    module_inst->enable_callback_mask   = 0x00;

#  if (AC_INST_NUM == 1)
    _ac_instance[0] = module_inst;
#  else
    /* Register this instance for callbacks*/
    _ac_instance[_ac_get_inst_index(hw)] = module_inst;
#  endif
#endif

    /* Write configuration to module */
    return _ac_set_config(module_inst, config);
}