SAM TCC - Timer Counter for Control Applications Driver.
Copyright (c) 2013-2020 Microchip Technology Inc. and its subsidiaries.
#include <compiler.h>
#include <clock.h>
#include <gclk.h>
#include <pinmux.h>
#include <system_interrupt.h>
Data Structures | |
struct | tcc_capture_config |
Configuration struct for the TCC module capture. More... | |
struct | tcc_config |
TCC configuration structure. More... | |
struct | tcc_counter_config |
Configuration struct for the TCC module base counter. More... | |
struct | tcc_events |
TCC event enable/disable structure. More... | |
struct | tcc_input_event_config |
TCC input event enable/disable/configure structure. More... | |
struct | tcc_match_wave_config |
Configuration struct for the TCC module match/wave generation. More... | |
struct | tcc_module |
TCC software device instance structure. More... | |
struct | tcc_non_recoverable_fault_config |
Configuration struct for TCC module non-recoverable fault. More... | |
struct | tcc_output_event_config |
TCC output event enable/disable/configure structure. More... | |
struct | tcc_pins_config |
Configuration struct for the TCC module output pins. More... | |
struct | tcc_recoverable_fault_config |
Configuration struct for TCC module recoverable fault. More... | |
struct | tcc_wave_extension_config |
Configuration struct for the TCC module waveform extension. More... | |
Macros | |
#define | _TCC_CHANNEL_ENUM_LIST(type) MREPEAT(TCC_NUM_CHANNELS, _TCC_ENUM, type##_CHANNEL) |
Generates table enum list entries for all channels of a given type and channel number on TCC module. More... | |
#define | _TCC_ENUM(n, type) TCC_##type##_##n, |
Generates a table enum list entry for a given type and index (e.g. More... | |
#define | _TCC_WO_ENUM_LIST(type) MREPEAT(TCC_NUM_WAVE_OUTPUTS, _TCC_ENUM, type) |
Generates table enum list entries for all output of a given type and waveform output number on TCC module. More... | |
#define | TCC_NUM_CHANNELS 4 |
Maximum number of channels supported by the driver (Channel index from 0 to TCC_NUM_CHANNELS - 1). More... | |
#define | TCC_NUM_FAULTS 2 |
Maximum number of (recoverable) faults supported by the driver. More... | |
#define | TCC_NUM_WAVE_OUTPUTS 8 |
Maximum number of wave outputs lines supported by the driver (Output line index from 0 to TCC_NUM_WAVE_OUTPUTS - 1). More... | |
Driver Feature Definition | |
Define port features set according to different device family. | |
#define | FEATURE_TCC_GENERATE_DMA_TRIGGER |
Generate DMA triggers. More... | |
Module Status Flags | |
TCC status flags, returned by tcc_get_status() and cleared by tcc_clear_status(). | |
#define | TCC_STATUS_CHANNEL_MATCH_CAPTURE(ch) (1UL << (ch)) |
Timer channel ch (0 ~ 3) has matched against its compare value, or has captured a new value. More... | |
#define | TCC_STATUS_CHANNEL_OUTPUT(ch) (1UL << ((ch)+8)) |
Timer channel ch (0 ~ 3) match/compare output state. More... | |
#define | TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR(x) (1UL << ((x)+16)) |
A Non-Recoverable Fault x (0 ~ 1) has occurred. More... | |
#define | TCC_STATUS_RECOVERABLE_FAULT_OCCUR(n) (1UL << ((n)+18)) |
A Recoverable Fault n (0 ~ 1 representing A ~ B) has occured. More... | |
#define | TCC_STATUS_NON_RECOVERABLE_FAULT_PRESENT(x) (1UL << ((x)+20)) |
The Non-Recoverable Fault x (0 ~ 1) input is present. More... | |
#define | TCC_STATUS_RECOVERABLE_FAULT_PRESENT(n) (1UL << ((n)+22)) |
A Recoverable Fault n (0 ~ 1 representing A ~ B) is present. More... | |
#define | TCC_STATUS_SYNC_READY (1UL << 23) |
Timer registers synchronization has completed, and the synchronized count value may be read. More... | |
#define | TCC_STATUS_CAPTURE_OVERFLOW (1UL << 24) |
A new value was captured before the previous value was read, resulting in lost data. More... | |
#define | TCC_STATUS_COUNTER_EVENT (1UL << 25) |
A counter event occurred. More... | |
#define | TCC_STATUS_COUNTER_RETRIGGERED (1UL << 26) |
A counter retrigger occurred. More... | |
#define | TCC_STATUS_COUNT_OVERFLOW (1UL << 27) |
The timer count value has overflowed from its maximum value to its minimum when counting upward, or from its minimum value to its maximum when counting downward. More... | |
#define | TCC_STATUS_RAMP_CYCLE_INDEX (1UL << 28) |
Ramp period cycle index. More... | |
#define | TCC_STATUS_STOPPED (1UL << 29) |
The counter has been stopped (due to disable, stop command, or one-shot). More... | |
Typedefs | |
typedef void(* | tcc_callback_t )(struct tcc_module *const module) |
Type definition for the TCC callback function. More... | |
Functions | |
Driver Initialization and Configuration | |
static bool | tcc_is_syncing (const struct tcc_module *const module_inst) |
Determines if the hardware module is currently synchronizing to the bus. More... | |
void | tcc_get_config_defaults (struct tcc_config *const config, Tcc *const hw) |
Initializes config with predefined default values. 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... | |
Event Management | |
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... | |
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... | |
Enable/Disable/Reset | |
static void | tcc_enable (const struct tcc_module *const module_inst) |
Enable the TCC module. More... | |
static void | tcc_disable (const struct tcc_module *const module_inst) |
Disables the TCC module. More... | |
static void | tcc_reset (const struct tcc_module *const module_inst) |
Resets the TCC module. More... | |
Set/Toggle Count Direction | |
static void | tcc_set_count_direction (const struct tcc_module *const module_inst, enum tcc_count_direction dir) |
Sets the TCC module count direction. More... | |
static void | tcc_toggle_count_direction (const struct tcc_module *const module_inst) |
Toggles the TCC module count direction. More... | |
Get/Set Count Value | |
uint32_t | tcc_get_count_value (const struct tcc_module *const module_inst) |
Get count value of the given TCC module. 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... | |
Stop/Restart Counter | |
static void | tcc_stop_counter (const struct tcc_module *const module_inst) |
Stops the counter. More... | |
static void | tcc_restart_counter (const struct tcc_module *const module_inst) |
Starts the counter from beginning. More... | |
Generate TCC DMA Triggers Command | |
static void | tcc_dma_trigger_command (const struct tcc_module *const module_inst) |
TCC DMA Trigger. More... | |
Get/Set Compare/Capture Register | |
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... | |
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... | |
Set Top Value | |
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... | |
Set Output Pattern | |
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... | |
Set Ramp Index | |
static void | tcc_set_ramp_index (const struct tcc_module *const module_inst, const enum tcc_ramp_index ramp_index) |
Sets the TCC module ramp index on next cycle. More... | |
Status Management | |
static bool | tcc_is_running (struct tcc_module *const module_inst) |
Checks if the timer/counter is running. More... | |
uint32_t | tcc_get_status (struct tcc_module *const module_inst) |
Retrieves the current module status. More... | |
void | tcc_clear_status (struct tcc_module *const module_inst, const uint32_t status_flags) |
Clears a module status flag. More... | |
Double Buffering Management | |
static void | tcc_enable_double_buffering (struct tcc_module *const module_inst) |
Enable TCC double buffering write. More... | |
static void | tcc_disable_double_buffering (struct tcc_module *const module_inst) |
Disable TCC double buffering Write. More... | |
static void | tcc_lock_double_buffer_update (struct tcc_module *const module_inst) |
Lock the TCC double buffered registers updates. More... | |
static void | tcc_unlock_double_buffer_update (struct tcc_module *const module_inst) |
Unlock the TCC double buffered registers updates. More... | |
static void | tcc_force_double_buffer_update (struct tcc_module *const module_inst) |
Force the TCC double buffered registers to update once. More... | |
static void | tcc_enable_circular_buffer_top (struct tcc_module *const module_inst) |
Enable Circular option for double buffered Top/Period Values. More... | |
static void | tcc_disable_circular_buffer_top (struct tcc_module *const module_inst) |
Disable Circular option for double buffered Top/Period Values. 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_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_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... | |
enum status_code | tcc_set_double_buffer_compare_values (struct tcc_module *const module_inst, 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... | |