/** * \brief Initializes config with predefined default values. * * This function will initialize a given TCC configuration structure to * a set of known default values. This function should be called on * any new instance of the configuration structures before being * modified by the user application. * * The default configuration is as follows: * \li Don't run in standby * \li The base timer/counter configurations: * \li GCLK generator 0 (GCLK main) clock source * \li No prescaler * \li GCLK reload action * \li Count upward * \li Don't perform one-shot operations * \li Counter starts on 0 * \li Period/top value set to maximum of counting * \li The match/capture configurations: * \li All Capture compare channel value set to 0 * \li No capture enabled (all channels use compare function) * \li Normal frequency wave generation * \li Waveform generation polarity set to 0 * \li Don't perform ramp on waveform * \li The waveform extension configurations: * \li No inversion of waveform output * \li No channel output enabled * \li No PWM pin output enabled * \li Pin and Mux configuration not set * * \param[out] config Pointer to a TCC module configuration structure to set * \param[in] hw Pointer to the TCC hardware module * */ void tcc_get_config_defaults( struct tcc_config *const config, Tcc *const hw) { /* TCC instance index */ uint8_t module_index = _tcc_get_inst_index(hw); /* Base counter defaults */ config->counter.count = 0; config->counter.period = _tcc_maxs[module_index]; config->counter.clock_source = GCLK_GENERATOR_0; config->counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1; config->counter.reload_action = TCC_RELOAD_ACTION_GCLK; config->counter.direction = TCC_COUNT_DIRECTION_UP; config->counter.oneshot = false; /* Match/Capture defaults */ # define _TCC_CHANNEL_MATCH_VALUE_INIT(n, value) \ config->compare.match[n] = value; MREPEAT(TCC_NUM_CHANNELS, _TCC_CHANNEL_MATCH_VALUE_INIT, 0) # undef _TCC_CHANNEL_MATCH_VALUE_INIT # define _TCC_CHANNEL_WAVE_POLARITY_INIT(n, value) \ config->compare.wave_polarity[n] = value; MREPEAT(TCC_NUM_CHANNELS, _TCC_CHANNEL_WAVE_POLARITY_INIT, TCC_WAVE_POLARITY_0) # undef _TCC_CHANNEL_WAVE_POLARITY_INIT config->compare.wave_generation = TCC_WAVE_GENERATION_NORMAL_FREQ; config->compare.wave_ramp = TCC_RAMP_RAMP1; # define _TCC_CHANNEL_FUNCTION_INIT(n, value) \ config->compare.channel_function[n] = value; MREPEAT(TCC_NUM_CHANNELS, _TCC_CHANNEL_FUNCTION_INIT, TCC_CHANNEL_FUNCTION_COMPARE) # undef _TCC_CHANNEL_FUNCTION_INIT # define _TCC_OUT_INVERT_INIT(n, value) \ config->wave_ext.invert[n] = value; MREPEAT(TCC_NUM_WAVE_OUTPUTS, _TCC_OUT_INVERT_INIT, false) # undef _TCC_OUT_INVERT_INIT #define _TCC_CHANNEL_OUT_PIN_INIT(n, dummy) \ config->pins.enable_wave_out_pin[n] = false;\ config->pins.wave_out_pin[TCC_WAVE_OUTPUT_##n] = 0; \ config->pins.wave_out_pin_mux[TCC_WAVE_OUTPUT_##n] = 0; MREPEAT(TCC_NUM_WAVE_OUTPUTS, _TCC_CHANNEL_OUT_PIN_INIT, 0) #undef _TCC_CHANNEL_OUT_PIN_INIT config->run_in_standby = false; }
/** * \internal Get the interrupt vector for the given device instance * * \param[in] The TCC module instance number * * \return Interrupt vector for of the given TCC module instance. */ static enum system_interrupt_vector _tcc_interrupt_get_interrupt_vector( uint32_t inst_num) { static uint8_t tcc_interrupt_vectors[TCC_INST_NUM] = { MREPEAT(TCC_INST_NUM, _TCC_INTERRUPT_VECT_NUM, 0) }; return (enum system_interrupt_vector)tcc_interrupt_vectors[inst_num]; }
/** * \brief Initializes config with predefined default values. * * This function will initialize a given TCC configuration structure to * a set of known default values. This function should be called on * any new instance of the configuration structures before being * modified by the user application. * * The default configuration is as follows: * \li Don't run in standby * \li When setting top,compare or pattern by API, do double buffering write * \li The base timer/counter configurations: * - GCLK generator 0 clock source * - No prescaler * - GCLK reload action * - Count upward * - Don't perform one-shot operations * - Counter starts on 0 * - Period/top value set to maximum * \li The match/capture configurations: * - All Capture compare channel value set to 0 * - No capture enabled (all channels use compare function) * - Normal frequency wave generation * - Waveform generation polarity set to 0 * - Don't perform ramp on waveform * \li The waveform extension configurations: * - No recoverable fault is enabled, fault actions are disabled, filter * is set to 0 * - No non-recoverable fault state output is enabled and filter is 0 * - No inversion of waveform output * \li No channel output enabled * \li No PWM pin output enabled * \li Pin and MUX configuration not set * * \param[out] config Pointer to a TCC module configuration structure to set * \param[in] hw Pointer to the TCC hardware module * */ void tcc_get_config_defaults( struct tcc_config *const config, Tcc *const hw) { /* TCC instance index */ uint8_t module_index = _tcc_get_inst_index(hw); /* Base counter defaults */ config->counter.count = 0; config->counter.period = _tcc_maxs[module_index]; config->counter.clock_source = GCLK_GENERATOR_0; config->counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1; config->counter.reload_action = TCC_RELOAD_ACTION_GCLK; config->counter.direction = TCC_COUNT_DIRECTION_UP; config->counter.oneshot = false; /* Match/Capture defaults */ # define _TCC_CHANNEL_MATCH_VALUE_INIT(n, value) \ config->compare.match[n] = value; MREPEAT(TCC_NUM_CHANNELS, _TCC_CHANNEL_MATCH_VALUE_INIT, 0) # undef _TCC_CHANNEL_MATCH_VALUE_INIT /* Wave polarity defaults */ # define _TCC_CHANNEL_WAVE_POLARITY_INIT(n, value) \ config->compare.wave_polarity[n] = value; MREPEAT(TCC_NUM_CHANNELS, _TCC_CHANNEL_WAVE_POLARITY_INIT, TCC_WAVE_POLARITY_0) # undef _TCC_CHANNEL_WAVE_POLARITY_INIT config->compare.wave_generation = TCC_WAVE_GENERATION_NORMAL_FREQ; config->compare.wave_ramp = TCC_RAMP_RAMP1; # define _TCC_CHANNEL_FUNCTION_INIT(n, value) \ config->compare.channel_function[n] = value; MREPEAT(TCC_NUM_CHANNELS, _TCC_CHANNEL_FUNCTION_INIT, TCC_CHANNEL_FUNCTION_COMPARE) # undef _TCC_CHANNEL_FUNCTION_INIT /* Recoverable fault defaults */ # define _TCC_FAULT_FUNCTION_INIT(n, dummy) \ config->wave_ext.recoverable_fault[n].filter_value = 0; \ config->wave_ext.recoverable_fault[n].blanking_cycles = 0; \ config->wave_ext.recoverable_fault[n].restart = false; \ config->wave_ext.recoverable_fault[n].keep = false; \ config->wave_ext.recoverable_fault[n].qualification = false; \ config->wave_ext.recoverable_fault[n].source = TCC_FAULT_SOURCE_DISABLE; \ config->wave_ext.recoverable_fault[n].blanking = TCC_FAULT_BLANKING_DISABLE; \ config->wave_ext.recoverable_fault[n].halt_action = TCC_FAULT_HALT_ACTION_DISABLE; \ config->wave_ext.recoverable_fault[n].capture_action = TCC_FAULT_CAPTURE_DISABLE; \ config->wave_ext.recoverable_fault[n].capture_channel = TCC_FAULT_CAPTURE_CHANNEL_0; MREPEAT(TCC_NUM_FAULTS, _TCC_FAULT_FUNCTION_INIT, 0) # undef _TCC_FAULT_FUNCTION_INIT /* Non-recoverable fault defaults */ # define _TCC_NRF_FUNCTION_INIT(n, dummy) \ config->wave_ext.non_recoverable_fault[n].filter_value = 0; \ config->wave_ext.non_recoverable_fault[n].output = TCC_FAULT_STATE_OUTPUT_OFF; MREPEAT(TCC_NUM_WAVE_OUTPUTS, _TCC_NRF_FUNCTION_INIT, 0) # undef _TCC_NRF_FUNCTION_INIT /* Output inversion defaults */ # define _TCC_OUT_INVERT_INIT(n, value) \ config->wave_ext.invert[n] = value; MREPEAT(TCC_NUM_WAVE_OUTPUTS, _TCC_OUT_INVERT_INIT, false) # undef _TCC_OUT_INVERT_INIT # define _TCC_CHANNEL_OUT_PIN_INIT(n, dummy) \ config->pins.enable_wave_out_pin[n] = false;\ config->pins.wave_out_pin[TCC_WAVE_OUTPUT_##n] = 0; \ config->pins.wave_out_pin_mux[TCC_WAVE_OUTPUT_##n] = 0; MREPEAT(TCC_NUM_WAVE_OUTPUTS, _TCC_CHANNEL_OUT_PIN_INIT, 0) # undef _TCC_CHANNEL_OUT_PIN_INIT config->double_buffering_enabled = true; config->run_in_standby = false; }
void *_tcc_instances[TCC_INST_NUM]; void _tcc_interrupt_handler(uint8_t module_index); const uint32_t _tcc_intflag[TCC_CALLBACK_N] = { TCC_INTFLAG_OVF, TCC_INTFLAG_TRG, TCC_INTFLAG_CNT, TCC_INTFLAG_ERR, TCC_INTFLAG_FAULTA, TCC_INTFLAG_FAULTB, TCC_INTFLAG_FAULT0, TCC_INTFLAG_FAULT1, #define _TCC_INTFLAG_MC(n,dummy) TCC_INTFLAG_MC##n, /* TCC_INTFLAG_MC0 ~ ... */ MREPEAT(TCC_NUM_CHANNELS, _TCC_INTFLAG_MC, 0) #undef _TCC_INTFLAG_MC }; # define _TCC_INTERRUPT_VECT_NUM(n, unused) \ SYSTEM_INTERRUPT_MODULE_TCC##n, /** * \internal Get the interrupt vector for the given device instance * * \param[in] The TCC module instance number * * \return Interrupt vector for of the given TCC module instance. */ static enum system_interrupt_vector _tcc_interrupt_get_interrupt_vector( uint32_t inst_num) {