SAM TCC - Timer Counter for Control Applications Driver.
Copyright (c) 2013-2020 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | _SIZE_MAX(size) |
#define | _SIZE_MAX_WITH_DITHER 0x03FFFFFF |
#define | _TCC_CHANNEL_FUNCTION_INIT(n, value) config->compare.channel_function[n] = value; |
#define | _TCC_CHANNEL_MATCH_VALUE_INIT(n, value) config->compare.match[n] = value; |
#define | _TCC_CHANNEL_OUT_PIN_INIT(n, dummy) |
#define | _TCC_CHANNEL_WAVE_POLARITY_INIT(n, value) config->compare.wave_polarity[n] = value; |
#define | _TCC_DITHERING_B 16u |
#define | _TCC_DTI_B 2u |
#define | _TCC_FAULT_FUNCTION_INIT(n, dummy) |
#define | _TCC_INTERRUPT_VECT_NUM(n, unused) SYSTEM_INTERRUPT_MODULE_TCC##n, |
#define | _TCC_NRF_FUNCTION_INIT(n, dummy) |
#define | _TCC_OTMX_B 1u |
#define | _TCC_OUT_INVERT_INIT(n, value) config->wave_ext.invert[n] = value; |
#define | _TCC_PG_B 8u |
#define | _TCC_SWAP_B 4u |
Functions | |
static enum status_code | _tcc_build_ctrla (const uint8_t module_index, const struct tcc_config *const config, uint32_t *value_buffer) |
Build CTRLA register value from configuration. More... | |
static void | _tcc_build_ctrlb (const uint8_t module_index, const struct tcc_config *const config, uint8_t *value_buffer) |
Build CTRLB register value from configuration. More... | |
static enum status_code | _tcc_build_drvctrl (const uint8_t module_index, const struct tcc_config *const config, uint32_t *value_buffer) |
Build DRVCTRL register values from configuration. More... | |
static enum status_code | _tcc_build_faults (const uint8_t module_index, const struct tcc_config *const config, uint32_t *value_buffer) |
Build FAULTs register values from configuration. More... | |
static enum status_code | _tcc_build_waves (const uint8_t module_index, const struct tcc_config *const config, uint32_t *value_buffer) |
Build WAVE & WAVEB register values from configuration. More... | |
uint8_t | _tcc_get_inst_index (Tcc *const hw) |
static enum status_code | _tcc_set_compare_value (const struct tcc_module *const module_inst, const enum tcc_match_capture_channel channel_index, const uint32_t compare, const bool double_buffering_enabled) |
Sets a TCC module compare value/buffer. More... | |
static enum status_code | _tcc_set_top_value (const struct tcc_module *const module_inst, const uint32_t top_value, const bool double_buffering_enabled) |
Set the timer TOP/PERIOD buffer/value. More... | |
void | tcc_clear_status (struct tcc_module *const module_inst, const uint32_t status_flags) |
Clears a module status flag. More... | |
enum status_code | tcc_disable_circular_buffer_compare (struct tcc_module *const module_inst, enum tcc_match_capture_channel channel_index) |
Disable circular option for double buffered compare values. More... | |
void | tcc_disable_events (struct tcc_module *const module_inst, struct tcc_events *const events) |
Disables the event input or output of a TCC instance. More... | |
enum status_code | tcc_enable_circular_buffer_compare (struct tcc_module *const module_inst, enum tcc_match_capture_channel channel_index) |
Enable circular option for double buffered compare values. More... | |
enum status_code | tcc_enable_events (struct tcc_module *const module_inst, struct tcc_events *const events) |
Enables the TCC module event input or output. More... | |
uint32_t | tcc_get_capture_value (const struct tcc_module *const module_inst, const enum tcc_match_capture_channel channel_index) |
Gets the TCC module capture value. More... | |
void | tcc_get_config_defaults (struct tcc_config *const config, Tcc *const hw) |
Initializes config with predefined default values. More... | |
uint32_t | tcc_get_count_value (const struct tcc_module *const module_inst) |
Get count value of the given TCC module. More... | |
uint32_t | tcc_get_status (struct tcc_module *const module_inst) |
Retrieves the current module status. More... | |
enum status_code | tcc_init (struct tcc_module *const module_inst, Tcc *const hw, const struct tcc_config *const config) |
Initializes a hardware TCC module instance. More... | |
enum status_code | tcc_set_compare_value (const struct tcc_module *const module_inst, const enum tcc_match_capture_channel channel_index, const uint32_t compare) |
Sets a TCC module compare value. More... | |
enum status_code | tcc_set_count_value (const struct tcc_module *const module_inst, const uint32_t count) |
Sets count value for the given TCC module. More... | |
enum status_code | tcc_set_double_buffer_compare_values (struct tcc_module *const module_inst, const enum tcc_match_capture_channel channel_index, const uint32_t compare, const uint32_t compare_buffer) |
Sets a TCC module compare value and buffer value. More... | |
enum status_code | tcc_set_double_buffer_top_values (const struct tcc_module *const module_inst, const uint32_t top_value, const uint32_t top_buffer_value) |
Set the timer TOP/PERIOD value and buffer value. More... | |
enum status_code | tcc_set_pattern (const struct tcc_module *const module_inst, const uint32_t line_index, const enum tcc_output_pattern pattern) |
Sets the TCC module waveform output pattern. More... | |
enum status_code | tcc_set_top_value (const struct tcc_module *const module_inst, const uint32_t top_value) |
Set the timer TOP/PERIOD value. More... | |
Variables | |
const uint32_t | _tcc_apbcmasks [TCC_INST_NUM] = TCC_APBCMASKS |
const uint8_t | _tcc_cc_nums [TCC_INST_NUM] = TCC_CC_NUMS |
const uint8_t | _tcc_exts [TCC_INST_NUM] = TCC_EXTS |
const uint8_t | _tcc_gclk_ids [TCC_INST_NUM] = TCC_GCLK_IDS |
const uint32_t | _tcc_maxs [TCC_INST_NUM] = TCC_MAXS |
const uint8_t | _tcc_ow_nums [TCC_INST_NUM] = TCC_OW_NUMS |
const uint8_t | _tcc_sizes [TCC_INST_NUM] = TCC_SIZES |
const Tcc *const | tcc_modules [TCC_INST_NUM] = TCC_INSTS |
#define _SIZE_MAX | ( | size | ) |
#define _SIZE_MAX_WITH_DITHER 0x03FFFFFF |
#define _TCC_CHANNEL_FUNCTION_INIT | ( | n, | |
value | |||
) | config->compare.channel_function[n] = value; |
Referenced by tcc_get_config_defaults().
#define _TCC_CHANNEL_MATCH_VALUE_INIT | ( | n, | |
value | |||
) | config->compare.match[n] = value; |
Referenced by tcc_get_config_defaults().
#define _TCC_CHANNEL_OUT_PIN_INIT | ( | n, | |
dummy | |||
) |
Referenced by tcc_get_config_defaults().
#define _TCC_CHANNEL_WAVE_POLARITY_INIT | ( | n, | |
value | |||
) | config->compare.wave_polarity[n] = value; |
Referenced by tcc_get_config_defaults().
#define _TCC_DITHERING_B 16u |
#define _TCC_DTI_B 2u |
#define _TCC_FAULT_FUNCTION_INIT | ( | n, | |
dummy | |||
) |
Referenced by tcc_get_config_defaults().
#define _TCC_INTERRUPT_VECT_NUM | ( | n, | |
unused | |||
) | SYSTEM_INTERRUPT_MODULE_TCC##n, |
Converts a given TCC index to its interrupt vector index.
#define _TCC_NRF_FUNCTION_INIT | ( | n, | |
dummy | |||
) |
Referenced by tcc_get_config_defaults().
#define _TCC_OTMX_B 1u |
#define _TCC_OUT_INVERT_INIT | ( | n, | |
value | |||
) | config->wave_ext.invert[n] = value; |
Referenced by tcc_get_config_defaults().
#define _TCC_PG_B 8u |
#define _TCC_SWAP_B 4u |
|
inlinestatic |
Build CTRLA register value from configuration.
[in] | module_index | The software module instance index |
[in] | config | Pointer to the TCC configuration options struct |
[out] | value_buffer | Pointer to the buffer to fill with built value |
STATUS_OK | Configuration values are good and register value built and save to buffer |
STATUS_ERR_INVALID_ARG | Invalid parameter found: assigned dither mode is invalid for module; used capture channel is invalid for module |
References _tcc_cc_nums, tcc_config::capture, tcc_capture_config::channel_function, tcc_counter_config::clock_prescaler, tcc_config::counter, i, tcc_counter_config::reload_action, tcc_config::run_in_standby, STATUS_ERR_INVALID_ARG, STATUS_OK, TCC_CHANNEL_FUNCTION_CAPTURE, and TCC_NUM_CHANNELS.
Referenced by tcc_init().
|
inlinestatic |
Build CTRLB register value from configuration.
[in] | module_index | The software module instance index |
[in] | config | Pointer to the TCC configuration options struct |
[out] | value_buffer | Pointer to the buffer to fill with built value |
References tcc_config::counter, tcc_counter_config::direction, tcc_counter_config::oneshot, and TCC_COUNT_DIRECTION_DOWN.
Referenced by tcc_init().
|
inlinestatic |
Build DRVCTRL register values from configuration.
[in] | module_index | The software module instance index |
[in] | config | Pointer to the TCC configuration options struct |
[out] | value_buffer | Pointer to the buffer to fill with built value |
STATUS_OK | Configuration values are good and register value built and save to buffer |
STATUS_ERR_INVALID_ARG | Invalid parameter found: assigned output line is invalid; filter value is invalid |
References _tcc_ow_nums, i, tcc_wave_extension_config::invert, tcc_wave_extension_config::non_recoverable_fault, tcc_non_recoverable_fault_config::output, STATUS_ERR_INVALID_ARG, STATUS_OK, TCC_FAULT_STATE_OUTPUT_1, TCC_FAULT_STATE_OUTPUT_OFF, TCC_NUM_WAVE_OUTPUTS, and tcc_config::wave_ext.
Referenced by tcc_init().
|
inlinestatic |
Build FAULTs register values from configuration.
[in] | module_index | The software module instance index |
[in] | config | Pointer to the TCC configuration options struct |
[out] | value_buffer | Pointer to the buffer to fill with built values |
STATUS_OK | Configuration values are good and register value built and save to buffer |
STATUS_ERR_INVALID_ARG | Invalid parameter found: assigned fault capture channel is invalid; assigned filter value is invalid |
References _tcc_cc_nums, tcc_recoverable_fault_config::blanking, tcc_recoverable_fault_config::blanking_cycles, tcc_recoverable_fault_config::capture_action, tcc_recoverable_fault_config::capture_channel, tcc_recoverable_fault_config::filter_value, tcc_recoverable_fault_config::halt_action, i, if(), tcc_recoverable_fault_config::keep, tcc_recoverable_fault_config::qualification, tcc_wave_extension_config::recoverable_fault, tcc_recoverable_fault_config::restart, tcc_recoverable_fault_config::source, STATUS_ERR_INVALID_ARG, STATUS_OK, TCC_NUM_FAULTS, and tcc_config::wave_ext.
Referenced by tcc_init().
|
inlinestatic |
Build WAVE & WAVEB register values from configuration.
[in] | module_index | The software module instance index |
[in] | config | Pointer to the TCC configuration options struct |
[out] | value_buffer | Pointer to the buffer to fill with built value |
STATUS_OK | Configuration values are good and register value built and save to buffer |
STATUS_ERR_INVALID_ARG | Invalid parameter found: assigned output line is invalid; circular and double buffering conflict; assigned function not supported by module |
References _tcc_cc_nums, tcc_config::compare, STATUS_ERR_INVALID_ARG, STATUS_OK, TCC_NUM_CHANNELS, tcc_match_wave_config::wave_generation, tcc_match_wave_config::wave_polarity, and tcc_match_wave_config::wave_ramp.
Referenced by tcc_init().
uint8_t _tcc_get_inst_index | ( | Tcc *const | hw | ) |
Find the index of the given TCC module instance.
[in] | The | TCC module instance pointer |
References Assert, i, and tcc_modules.
Referenced by _tcc_set_compare_value(), _tcc_set_top_value(), tcc_disable_callback(), tcc_disable_circular_buffer_compare(), tcc_enable_callback(), tcc_enable_circular_buffer_compare(), tcc_get_capture_value(), tcc_get_config_defaults(), tcc_init(), tcc_set_count_value(), and tcc_set_pattern().
|
static |
Sets a TCC module compare value/buffer.
Writes a compare value to the given TCC module compare/capture channel or buffer one.
[in] | module_inst | Pointer to the software module instance struct |
[in] | channel_index | Index of the compare channel to write to |
[in] | compare | New compare value/buffer value to set |
[in] | double_buffering_enabled | Set to true to write to CCBx |
STATUS_OK | The compare value was updated successfully |
STATUS_ERR_INVALID_ARG | An invalid channel index was supplied or compare value exceed resolution |
References _tcc_cc_nums, _tcc_get_inst_index(), _tcc_maxs, Assert, tcc_module::hw, max_count, STATUS_ERR_INVALID_ARG, and STATUS_OK.
Referenced by tcc_set_compare_value(), and tcc_set_double_buffer_compare_values().
|
static |
Set the timer TOP/PERIOD buffer/value.
This function writes the given value to the PER/PERB register.
[in] | module_inst | Pointer to the software module instance struct |
[in] | top_value | New value to be loaded into the PER/PERB register |
[in] | double_buffering_enabled | Set to true to write to PERB |
STATUS_OK | The timer TOP value was updated successfully |
STATUS_ERR_INVALID_ARG | An invalid channel index was supplied or top/period value exceed resolution |
References _tcc_get_inst_index(), _tcc_maxs, Assert, tcc_module::hw, max_count, STATUS_ERR_INVALID_ARG, and STATUS_OK.
Referenced by tcc_set_double_buffer_top_values(), and tcc_set_top_value().
const uint32_t _tcc_apbcmasks[TCC_INST_NUM] = TCC_APBCMASKS |
Referenced by tcc_init().
const uint8_t _tcc_cc_nums[TCC_INST_NUM] = TCC_CC_NUMS |
const uint8_t _tcc_exts[TCC_INST_NUM] = TCC_EXTS |
const uint8_t _tcc_gclk_ids[TCC_INST_NUM] = TCC_GCLK_IDS |
Referenced by tcc_init().
const uint32_t _tcc_maxs[TCC_INST_NUM] = TCC_MAXS |
Referenced by _tcc_set_compare_value(), _tcc_set_top_value(), tcc_get_config_defaults(), tcc_init(), and tcc_set_count_value().
const uint8_t _tcc_ow_nums[TCC_INST_NUM] = TCC_OW_NUMS |
Referenced by _tcc_build_drvctrl(), tcc_init(), and tcc_set_pattern().
const uint8_t _tcc_sizes[TCC_INST_NUM] = TCC_SIZES |
const Tcc* const tcc_modules[TCC_INST_NUM] = TCC_INSTS |
Referenced by _tcc_get_inst_index().