This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the timer modules within the device, for waveform generation and timing operations.
The following driver API modes are covered by this manual:
The following peripheral is used by this module:
The following devices can use this module:
The outline of this documentation is as follows:
There are no prerequisites for this module.
The Timer/Counter (TC) module provides a set of timing and counting related functionality, such as the generation of periodic waveforms, the capturing of a periodic waveform's frequency/duty cycle, and software timekeeping for periodic operations. TC modules can be configured to use an 8-, 16-, or 32-bit counter size.
This TC module for the SAM is capable of the following functions:
The diagram below shows the overview of the TC module design.
Driver Feature Macro | Supported devices |
---|---|
FEATURE_TC_DOUBLE_BUFFERED | SAM L21/L22/C20/C21/R30/R34/R35 |
FEATURE_TC_SYNCBUSY_SCHEME_VERSION_2 | SAM L21/L22/C20/C21/R30/R34/R35 |
FEATURE_TC_STAMP_PW_CAPTURE | SAM L21/L22/C20/C21/R30/R34/R35 |
FEATURE_TC_READ_SYNC | SAM L21/L22/C20/C21/R30/R34/R35 |
FEATURE_TC_IO_CAPTURE | SAM L21/L22/C20/C21/R30/R34/R35 |
FEATURE_TC_GENERATE_DMA_TRIGGER | SAM L21/L22/R30/R34/R35 |
Independent of the configured counter size, each TC module can be set up in one of two different modes; capture and compare.
In capture mode, the counter value is stored when a configurable event occurs. This mode can be used to generate timestamps used in event capture, or it can be used for the measurement of a periodic input signal's frequency/duty cycle.
In compare mode, the counter value is compared against one or more of the configured channel compare values. When the counter value coincides with a compare value an action can be taken automatically by the module, such as generating an output event or toggling a pin when used for frequency or Pulse Width Modulation (PWM) signal generation.
Each timer module can be configured in one of three different counter sizes; 8-, 16-, and 32-bit. The size of the counter determines the maximum value it can count to before an overflow occurs and the count is reset back to zero. The table below shows the maximum values for each of the possible counter sizes.
Counter size | Max. (hexadecimal) | Max. (decimal) |
---|---|---|
8-bit | 0xFF | 255 |
16-bit | 0xFFFF | 65,535 |
32-bit | 0xFFFFFFFF | 4,294,967,295 |
When using the counter in 16- or 32-bit count mode, Compare Capture register 0 (CC0) is used to store the period value when running in PWM generation match mode.
When using 32-bit counter size, two 16-bit counters are chained together in a cascade formation. Except in SAM D09/D10/D11. Even numbered TC modules (e.g. TC0, TC2) can be configured as 32-bit counters. The odd numbered counters will act as slaves to the even numbered masters, and will not be reconfigurable until the master timer is disabled. The pairing of timer modules for 32-bit mode is shown in the table below.
Master TC module | Slave TC module |
---|---|
TC0 | TC1 |
TC2 | TC3 |
... | ... |
TCn-1 | TCn |
In SAM D09/D10/D11, odd numbered TC modules (e.g. TC1) can be configured as 32-bit counters. The even numbered (e.g. TC2) counters will act as slaves to the odd numbered masters.
Each TC peripheral is clocked asynchronously to the system clock by a GCLK (Generic Clock) channel. The GCLK channel connects to any of the GCLK generators. The GCLK generators are configured to use one of the available clock sources on the system such as internal oscillator, external crystals, etc. See the Generic Clock driver for more information.
Each TC module in the SAM has its own individual clock prescaler, which can be used to divide the input clock frequency used in the counter. This prescaler only scales the clock used to provide clock pulses for the counter to count, and does not affect the digital register interface portion of the module, thus the timer registers will synchronize to the raw GCLK frequency input to the module.
As a result of this, when selecting a GCLK frequency and timer prescaler value the user application should consider both the timer resolution required and the synchronization frequency, to avoid lengthy synchronization times of the module if a very slow GCLK frequency is fed into the TC module. It is preferable to use a higher module GCLK frequency as the input to the timer, and prescale this down as much as possible to obtain a suitable counter frequency in latency-sensitive applications.
Timer modules also contain a configurable reload action, used when a re-trigger event occurs. Examples of a re-trigger event are the counter reaching the maximum value when counting up, or when an event from the event system tells the counter to re-trigger. The reload action determines if the prescaler should be reset, and when this should happen. The counter will always be reloaded with the value it is set to start counting from. The user can choose between three different reload actions, described in the table below.
Reload action | Description |
---|---|
TC_RELOAD_ACTION_GCLK | Reload TC counter value on next GCLK cycle. Leave prescaler as-is. |
TC_RELOAD_ACTION_PRESC | Reloads TC counter value on next prescaler clock. Leave prescaler as-is. |
TC_RELOAD_ACTION_RESYNC | Reload TC counter value on next GCLK cycle. Clear prescaler to zero. |
The reload action to use will depend on the specific application being implemented. One example is when an external trigger for a reload occurs; if the TC uses the prescaler, the counter in the prescaler should not have a value between zero and the division factor. The TC counter and the counter in the prescaler should both start at zero. When the counter is set to re-trigger when it reaches the maximum value on the other hand, this is not the right option to use. In such a case it would be better if the prescaler is left unaltered when the re-trigger happens, letting the counter reset on the next GCLK cycle.
In compare match operation, Compare/Capture registers are used in comparison with the counter value. When the timer's count value matches the value of a compare channel, a user defined action can be taken.
A Basic Timer is a simple application where compare match operations are used to determine when a specific period has elapsed. In Basic Timer operations, one or more values in the module's Compare/Capture registers are used to specify the time (as a number of prescaled GCLK cycles) when an action should be taken by the microcontroller. This can be an Interrupt Service Routine (ISR), event generator via the event system, or a software flag that is polled via the user application.
Waveform generation enables the TC module to generate square waves, or if combined with an external passive low-pass filter; analog waveforms.
Pulse width modulation is a form of waveform generation and a signalling technique that can be useful in many situations. When PWM mode is used, a digital pulse train with a configurable frequency and duty cycle can be generated by the TC module and output to a GPIO pin of the device.
Often PWM is used to communicate a control or information parameter to an external circuit or component. Differing impedances of the source generator and sink receiver circuits are less of an issue when using PWM compared to using an analog voltage value, as noise will not generally affect the signal's integrity to a meaningful extent.
The figure below illustrates operations and different states of the counter and its output when running the counter in PWM normal mode. As can be seen, the TOP value is unchanged and is set to MAX. The compare match value is changed at several points to illustrate the resulting waveform output changes. The PWM output is set to normal (i.e. non-inverted) output mode.
In the figure below, the counter is set to generate PWM in Match mode. The PWM output is inverted via the appropriate configuration option in the TC driver configuration structure. In this example, the counter value is changed once, but the compare match value is kept unchanged. As can be seen, it is possible to change the TOP value when running in PWM match mode.
Frequency Generation mode is in many ways identical to PWM generation. However, in Frequency Generation a toggle only occurs on the output when a match on a capture channels occurs. When the match is made, the timer value is reset, resulting in a variable frequency square wave with a fixed 50% duty cycle.
In capture operations, any event from the event system or a pin change can trigger a capture of the counter value. This captured counter value can be used as a timestamp for the event, or it can be used in frequency and pulse width capture.
Event capture is a simple use of the capture functionality, designed to create timestamps for specific events. When the TC module's input capture pin is externally toggled, the current timer count value is copied into a buffered register which can then be read out by the user application.
Note that when performing any capture operation, there is a risk that the counter reaches its top value (MAX) when counting up, or the bottom value (zero) when counting down, before the capture event occurs. This can distort the result, making event timestamps to appear shorter than reality; the user application should check for timer overflow when reading a capture result in order to detect this situation and perform an appropriate adjustment.
Before checking for a new capture, TC_STATUS_COUNT_OVERFLOW should be checked. The response to an overflow error is left to the user application, however it may be necessary to clear both the capture overflow flag and the capture flag upon each capture reading.
Pulse Width Capture mode makes it possible to measure the pulse width and period of PWM signals. This mode uses two capture channels of the counter. This means that the counter module used for Pulse Width Capture can not be used for any other purpose. There are two modes for pulse width capture; Pulse Width Period (PWP) and Period Pulse Width (PPW). In PWP mode, capture channel 0 is used for storing the pulse width and capture channel 1 stores the observed period. While in PPW mode, the roles of the two capture channels are reversed.
As in the above example it is necessary to poll on interrupt flags to see if a new capture has happened and check that a capture overflow error has not occurred.
TC modules can be configured into a one-shot mode. When configured in this manner, starting the timer will cause it to count until the next overflow or underflow condition before automatically halting, waiting to be manually triggered by the user application software or an event signal from the event system.
The output of the wave generation can be inverted by hardware if desired, resulting in the logically inverted value being output to the configured device GPIO pin.
The number of capture compare registers in each TC module is dependent on the specific SAM device being used, and in some cases the counter size.
The maximum amount of capture compare registers available in any SAM device is two when running in 32-bit mode and four in 8- and 16-bit modes.
For extra information, see Extra Information for TC Driver. This includes:
For a list of examples related to this driver, see Examples for TC Driver.
Data Structures | |
struct | tc_16bit_config |
Configuration struct for TC module in 16-bit size counter mode. More... | |
struct | tc_32bit_config |
Configuration struct for TC module in 32-bit size counter mode. More... | |
struct | tc_8bit_config |
Configuration struct for TC module in 8-bit size counter mode. More... | |
struct | tc_config |
TC configuration structure. More... | |
struct | tc_events |
TC event enable/disable structure. More... | |
struct | tc_module |
TC software device instance structure. More... | |
struct | tc_pwm_channel |
Configuration struct for TC module in 32-bit size counter mode. More... | |
Enumerations | |
enum | tc_clock_prescaler { TC_CLOCK_PRESCALER_DIV1 = TC_CTRLA_PRESCALER(0), TC_CLOCK_PRESCALER_DIV2 = TC_CTRLA_PRESCALER(1), TC_CLOCK_PRESCALER_DIV4 = TC_CTRLA_PRESCALER(2), TC_CLOCK_PRESCALER_DIV8 = TC_CTRLA_PRESCALER(3), TC_CLOCK_PRESCALER_DIV16 = TC_CTRLA_PRESCALER(4), TC_CLOCK_PRESCALER_DIV64 = TC_CTRLA_PRESCALER(5), TC_CLOCK_PRESCALER_DIV256 = TC_CTRLA_PRESCALER(6), TC_CLOCK_PRESCALER_DIV1024 = TC_CTRLA_PRESCALER(7) } |
TC clock prescaler values. More... | |
enum | tc_compare_capture_channel { TC_COMPARE_CAPTURE_CHANNEL_0, TC_COMPARE_CAPTURE_CHANNEL_1 } |
Index of the compare capture channels. More... | |
enum | tc_count_direction { TC_COUNT_DIRECTION_UP, TC_COUNT_DIRECTION_DOWN } |
TC module count direction. More... | |
enum | tc_counter_size { TC_COUNTER_SIZE_8BIT = TC_CTRLA_MODE_COUNT8, TC_COUNTER_SIZE_16BIT = TC_CTRLA_MODE_COUNT16, TC_COUNTER_SIZE_32BIT = TC_CTRLA_MODE_COUNT32 } |
Specifies if the counter is 8-, 16-, or 32-bit. More... | |
enum | tc_reload_action { TC_RELOAD_ACTION_GCLK = TC_CTRLA_PRESCSYNC_GCLK, TC_RELOAD_ACTION_PRESC = TC_CTRLA_PRESCSYNC_PRESC, TC_RELOAD_ACTION_RESYNC = TC_CTRLA_PRESCSYNC_RESYNC } |
TC Counter reload action enum. More... | |
enum | tc_wave_generation { TC_WAVE_GENERATION_NORMAL_FREQ = TC_WAVE_GENERATION_NORMAL_FREQ_MODE, TC_WAVE_GENERATION_MATCH_FREQ = TC_WAVE_GENERATION_MATCH_FREQ_MODE, TC_WAVE_GENERATION_NORMAL_PWM = TC_WAVE_GENERATION_NORMAL_PWM_MODE, TC_WAVE_GENERATION_MATCH_PWM = TC_WAVE_GENERATION_MATCH_PWM_MODE } |
TC wave generation mode enum. More... | |
#define | FEATURE_TC_DOUBLE_BUFFERED |
Define port features set according to different device family. More... | |
#define | FEATURE_TC_SYNCBUSY_SCHEME_VERSION_2 |
SYNCBUSY scheme version 2. More... | |
#define | FEATURE_TC_STAMP_PW_CAPTURE |
TC time stamp capture and pulse width capture. More... | |
#define | FEATURE_TC_READ_SYNC |
Read synchronization of COUNT. More... | |
#define | FEATURE_TC_IO_CAPTURE |
I/O pin edge capture. More... | |
#define | FEATURE_TC_GENERATE_DMA_TRIGGER |
Generate Direct Memory Access (DMA) triggers. More... | |
Module Status Flags | |
TC status flags, returned by tc_get_status() and cleared by tc_clear_status(). | |
#define | TC_STATUS_CHANNEL_0_MATCH (1UL << 0) |
Timer channel 0 has matched against its compare value, or has captured a new value. More... | |
#define | TC_STATUS_CHANNEL_1_MATCH (1UL << 1) |
Timer channel 1 has matched against its compare value, or has captured a new value. More... | |
#define | TC_STATUS_SYNC_READY (1UL << 2) |
Timer register synchronization has completed, and the synchronized count value may be read. More... | |
#define | TC_STATUS_CAPTURE_OVERFLOW (1UL << 3) |
A new value was captured before the previous value was read, resulting in lost data. More... | |
#define | TC_STATUS_COUNT_OVERFLOW (1UL << 4) |
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 | TC_STATUS_CHN0_BUFFER_VALID (1UL << 5) |
Channel 0 compare or capture buffer valid. More... | |
#define | TC_STATUS_CHN1_BUFFER_VALID (1UL << 6) |
Channel 1 compare or capture buffer valid. More... | |
#define | TC_STATUS_PERIOD_BUFFER_VALID (1UL << 7) |
Period buffer valid. More... | |
TC Wave Generation Mode | |
#define | TC_WAVE_GENERATION_NORMAL_FREQ_MODE TC_WAVE_WAVEGEN_NFRQ |
TC wave generation mode: normal frequency. More... | |
#define | TC_WAVE_GENERATION_MATCH_FREQ_MODE TC_WAVE_WAVEGEN_MFRQ |
TC wave generation mode: match frequency. More... | |
#define | TC_WAVE_GENERATION_NORMAL_PWM_MODE TC_WAVE_WAVEGEN_NPWM |
TC wave generation mode: normal PWM. More... | |
#define | TC_WAVE_GENERATION_MATCH_PWM_MODE TC_WAVE_WAVEGEN_MPWM |
TC wave generation mode: match PWM. More... | |
Waveform Inversion Mode | |
enum | tc_waveform_invert_output { TC_WAVEFORM_INVERT_OUTPUT_NONE = 0, TC_WAVEFORM_INVERT_OUTPUT_CHANNEL_0 = TC_WAVEFORM_INVERT_CC0_MODE, TC_WAVEFORM_INVERT_OUTPUT_CHANNEL_1 = TC_WAVEFORM_INVERT_CC1_MODE } |
Waveform inversion mode. More... | |
enum | tc_event_action { TC_EVENT_ACTION_OFF = TC_EVCTRL_EVACT_OFF, TC_EVENT_ACTION_RETRIGGER = TC_EVCTRL_EVACT_RETRIGGER, TC_EVENT_ACTION_INCREMENT_COUNTER = TC_EVCTRL_EVACT_COUNT, TC_EVENT_ACTION_START = TC_EVCTRL_EVACT_START, TC_EVENT_ACTION_PPW = TC_EVCTRL_EVACT_PPW, TC_EVENT_ACTION_PWP = TC_EVCTRL_EVACT_PWP, TC_EVENT_ACTION_STAMP = TC_EVCTRL_EVACT_STAMP, TC_EVENT_ACTION_PW = TC_EVCTRL_EVACT_PW } |
Action to perform when the TC module is triggered by an event. More... | |
#define | TC_WAVEFORM_INVERT_CC0_MODE TC_DRVCTRL_INVEN(1) |
Waveform inversion CC0 mode. More... | |
#define | TC_WAVEFORM_INVERT_CC1_MODE TC_DRVCTRL_INVEN(2) |
Waveform inversion CC1 mode. More... | |
Driver Initialization and Configuration | |
static bool | tc_is_syncing (const struct tc_module *const module_inst) |
Determines if the hardware module(s) are currently synchronizing to the bus. More... | |
static void | tc_get_config_defaults (struct tc_config *const config) |
Initializes config with predefined default values. More... | |
enum status_code | tc_init (struct tc_module *const module_inst, Tc *const hw, const struct tc_config *const config) |
Initializes a hardware TC module instance. More... | |
Event Management | |
static void | tc_enable_events (struct tc_module *const module_inst, struct tc_events *const events) |
Enables a TC module event input or output. More... | |
static void | tc_disable_events (struct tc_module *const module_inst, struct tc_events *const events) |
Disables a TC module event input or output. More... | |
Enable/Disable/Reset | |
enum status_code | tc_reset (const struct tc_module *const module_inst) |
Resets the TC module. More... | |
static void | tc_enable (const struct tc_module *const module_inst) |
Enable the TC module. More... | |
static void | tc_disable (const struct tc_module *const module_inst) |
Disables the TC module. More... | |
Get/Set Count Value | |
uint32_t | tc_get_count_value (const struct tc_module *const module_inst) |
Get TC module count value. More... | |
enum status_code | tc_set_count_value (const struct tc_module *const module_inst, const uint32_t count) |
Sets TC module count value. More... | |
Start/Stop Counter | |
static void | tc_stop_counter (const struct tc_module *const module_inst) |
Stops the counter. More... | |
static void | tc_start_counter (const struct tc_module *const module_inst) |
Starts the counter. More... | |
Double Buffering | |
static void | tc_update_double_buffer (const struct tc_module *const module_inst) |
Update double buffer. More... | |
Count Read Synchronization | |
static void | tc_sync_read_count (const struct tc_module *const module_inst) |
Read synchronization of COUNT. More... | |
Generate TC DMA Triggers Command | |
static void | tc_dma_trigger_command (const struct tc_module *const module_inst) |
TC DMA Trigger. More... | |
Get Capture Set Compare | |
uint32_t | tc_get_capture_value (const struct tc_module *const module_inst, const enum tc_compare_capture_channel channel_index) |
Gets the TC module capture value. More... | |
enum status_code | tc_set_compare_value (const struct tc_module *const module_inst, const enum tc_compare_capture_channel channel_index, const uint32_t compare_value) |
Sets a TC module compare value. More... | |
Set Top Value | |
enum status_code | tc_set_top_value (const struct tc_module *const module_inst, const uint32_t top_value) |
Set the timer TOP/period value. More... | |
Status Management | |
static uint32_t | tc_get_status (struct tc_module *const module_inst) |
Retrieves the current module status. More... | |
static void | tc_clear_status (struct tc_module *const module_inst, const uint32_t status_flags) |
Clears a module status flag. More... | |
#define FEATURE_TC_DOUBLE_BUFFERED |
Define port features set according to different device family.
TC double buffered.
#define FEATURE_TC_GENERATE_DMA_TRIGGER |
Generate Direct Memory Access (DMA) triggers.
#define FEATURE_TC_IO_CAPTURE |
I/O pin edge capture.
#define FEATURE_TC_READ_SYNC |
Read synchronization of COUNT.
#define FEATURE_TC_STAMP_PW_CAPTURE |
TC time stamp capture and pulse width capture.
#define FEATURE_TC_SYNCBUSY_SCHEME_VERSION_2 |
SYNCBUSY scheme version 2.
#define TC_STATUS_CAPTURE_OVERFLOW (1UL << 3) |
A new value was captured before the previous value was read, resulting in lost data.
Referenced by tc_clear_status(), and tc_get_status().
#define TC_STATUS_CHANNEL_0_MATCH (1UL << 0) |
Timer channel 0 has matched against its compare value, or has captured a new value.
Referenced by tc_clear_status(), and tc_get_status().
#define TC_STATUS_CHANNEL_1_MATCH (1UL << 1) |
Timer channel 1 has matched against its compare value, or has captured a new value.
Referenced by tc_clear_status(), and tc_get_status().
#define TC_STATUS_CHN0_BUFFER_VALID (1UL << 5) |
Channel 0 compare or capture buffer valid.
Referenced by tc_get_status().
#define TC_STATUS_CHN1_BUFFER_VALID (1UL << 6) |
Channel 1 compare or capture buffer valid.
Referenced by tc_get_status().
#define TC_STATUS_COUNT_OVERFLOW (1UL << 4) |
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.
Referenced by tc_clear_status(), and tc_get_status().
#define TC_STATUS_PERIOD_BUFFER_VALID (1UL << 7) |
Period buffer valid.
Referenced by tc_get_status().
#define TC_STATUS_SYNC_READY (1UL << 2) |
Timer register synchronization has completed, and the synchronized count value may be read.
Referenced by tc_clear_status(), and tc_get_status().
#define TC_WAVE_GENERATION_MATCH_FREQ_MODE TC_WAVE_WAVEGEN_MFRQ |
TC wave generation mode: match frequency.
#define TC_WAVE_GENERATION_MATCH_PWM_MODE TC_WAVE_WAVEGEN_MPWM |
TC wave generation mode: match PWM.
#define TC_WAVE_GENERATION_NORMAL_FREQ_MODE TC_WAVE_WAVEGEN_NFRQ |
TC wave generation mode: normal frequency.
#define TC_WAVE_GENERATION_NORMAL_PWM_MODE TC_WAVE_WAVEGEN_NPWM |
TC wave generation mode: normal PWM.
#define TC_WAVEFORM_INVERT_CC0_MODE TC_DRVCTRL_INVEN(1) |
Waveform inversion CC0 mode.
#define TC_WAVEFORM_INVERT_CC1_MODE TC_DRVCTRL_INVEN(2) |
Waveform inversion CC1 mode.
enum tc_clock_prescaler |
TC clock prescaler values.
This enum is used to choose the clock prescaler configuration. The prescaler divides the clock frequency of the TC module to make the counter count slower.
enum tc_count_direction |
enum tc_counter_size |
Specifies if the counter is 8-, 16-, or 32-bit.
This enum specifies the maximum value it is possible to count to.
enum tc_event_action |
Action to perform when the TC module is triggered by an event.
Event action to perform when the module is triggered by an event.
enum tc_reload_action |
TC Counter reload action enum.
This enum specify how the counter and prescaler should reload.
enum tc_wave_generation |
TC wave generation mode enum.
This enum is used to select which mode to run the wave generation in.
|
inlinestatic |
Clears a module status flag.
Clears the given status flag of the module.
[in] | module_inst | Pointer to the TC software instance struct |
[in] | status_flags | Bitmask of TC_STATUS_* flags to clear |
References Assert, TC_STATUS_CAPTURE_OVERFLOW, TC_STATUS_CHANNEL_0_MATCH, TC_STATUS_CHANNEL_1_MATCH, TC_STATUS_COUNT_OVERFLOW, and TC_STATUS_SYNC_READY.
|
inlinestatic |
Disables the TC module.
Disables a TC module and stops the counter.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tc_is_syncing().
Referenced by tc_reset().
|
inlinestatic |
Disables a TC module event input or output.
Disables one or more input or output events to or from the TC module. See tc_events for a list of events this module supports.
[in] | module_inst | Pointer to the software module instance struct |
[in] | events | Struct containing flags of events to disable |
References Assert, tc_events::generate_event_on_compare_channel, tc_events::generate_event_on_overflow, tc_events::invert_event_input, and tc_events::on_event_perform_action.
|
inlinestatic |
TC DMA Trigger.
TC DMA trigger command.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tc_is_syncing().
|
inlinestatic |
Enable the TC module.
Enables a TC module that has been previously initialized. The counter will start when the counter is enabled.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tc_is_syncing().
Referenced by test_event_gen_user_init().
|
inlinestatic |
Enables a TC module event input or output.
Enables one or more input or output events to or from the TC module. See tc_events for a list of events this module supports.
[in] | module_inst | Pointer to the software module instance struct |
[in] | events | Struct containing flags of events to enable |
References Assert, tc_events::event_action, tc_events::generate_event_on_compare_channel, tc_events::generate_event_on_overflow, tc_events::invert_event_input, and tc_events::on_event_perform_action.
Referenced by test_event_gen_user_init().
uint32_t tc_get_capture_value | ( | const struct tc_module *const | module_inst, |
const enum tc_compare_capture_channel | channel_index | ||
) |
Gets the TC module capture value.
Retrieves the capture value in the indicated TC module capture channel.
[in] | module_inst | Pointer to the software module instance struct |
[in] | channel_index | Index of the Compare Capture channel to read |
References Assert, TC_COUNTER_SIZE_16BIT, TC_COUNTER_SIZE_32BIT, TC_COUNTER_SIZE_8BIT, and tc_is_syncing().
|
inlinestatic |
Initializes config with predefined default values.
This function will initialize a given TC 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:
[out] | config | Pointer to a TC module configuration structure to set |
References Assert, tc_config::clock_prescaler, tc_config::clock_source, tc_16bit_config::compare_capture_channel, tc_config::count_direction, tc_config::counter_16_bit, tc_config::counter_size, tc_config::double_buffering_enabled, tc_config::enable_capture_on_channel, tc_config::enable_capture_on_IO, tc_pwm_channel::enabled, GCLK_GENERATOR_0, tc_config::on_demand, tc_config::oneshot, tc_pwm_channel::pin_mux, tc_pwm_channel::pin_out, tc_config::pwm_channel, tc_config::reload_action, tc_config::run_in_standby, TC_CLOCK_PRESCALER_DIV1, TC_COMPARE_CAPTURE_CHANNEL_0, TC_COMPARE_CAPTURE_CHANNEL_1, TC_COUNT_DIRECTION_UP, TC_COUNTER_SIZE_16BIT, TC_RELOAD_ACTION_GCLK, TC_WAVE_GENERATION_NORMAL_FREQ, TC_WAVEFORM_INVERT_OUTPUT_NONE, tc_16bit_config::value, tc_config::wave_generation, and tc_config::waveform_invert_output.
Referenced by test_event_gen_user_init().
uint32_t tc_get_count_value | ( | const struct tc_module *const | module_inst | ) |
Get TC module count value.
Retrieves the current count value of a TC module. The specified TC module may be started or stopped.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, TC_COUNTER_SIZE_16BIT, TC_COUNTER_SIZE_32BIT, TC_COUNTER_SIZE_8BIT, and tc_is_syncing().
Referenced by run_asynchronous_event_test(), run_resynchronous_event_test(), and run_synchronous_event_test().
|
inlinestatic |
Retrieves the current module status.
Retrieves the status of the module, giving overall state information.
[in] | module_inst | Pointer to the TC software instance struct |
TC_STATUS_*
flags.TC_STATUS_CHANNEL_0_MATCH | Timer channel 0 compare/capture match |
TC_STATUS_CHANNEL_1_MATCH | Timer channel 1 compare/capture match |
TC_STATUS_SYNC_READY | Timer read synchronization has completed |
TC_STATUS_CAPTURE_OVERFLOW | Timer capture data has overflowed |
TC_STATUS_COUNT_OVERFLOW | Timer count value has overflowed |
TC_STATUS_CHN0_BUFFER_VALID | Timer count channel 0 compare/capture buffer valid |
TC_STATUS_CHN1_BUFFER_VALID | Timer count channel 1 compare/capture buffer valid |
TC_STATUS_PERIOD_BUFFER_VALID | Timer count period buffer valid |
References Assert, TC_STATUS_CAPTURE_OVERFLOW, TC_STATUS_CHANNEL_0_MATCH, TC_STATUS_CHANNEL_1_MATCH, TC_STATUS_CHN0_BUFFER_VALID, TC_STATUS_CHN1_BUFFER_VALID, TC_STATUS_COUNT_OVERFLOW, TC_STATUS_PERIOD_BUFFER_VALID, and TC_STATUS_SYNC_READY.
enum status_code tc_init | ( | struct tc_module *const | module_inst, |
Tc *const | hw, | ||
const struct tc_config *const | config | ||
) |
Initializes a hardware TC module instance.
Enables the clock and initializes the TC module, based on the given configuration values.
[in,out] | module_inst | Pointer to the software module instance struct |
[in] | hw | Pointer to the TC hardware module |
[in] | config | Pointer to the TC configuration options struct |
STATUS_OK | The module was initialized successfully |
STATUS_BUSY | Hardware module was busy when the initialization procedure was attempted |
STATUS_INVALID_ARG | An invalid configuration option or argument was supplied |
STATUS_ERR_DENIED | Hardware module was already enabled, or the hardware module is configured in 32-bit slave mode |
References _tc_get_inst_index(), Assert, tc_config::clock_prescaler, tc_config::clock_source, tc_8bit_config::compare_capture_channel, tc_16bit_config::compare_capture_channel, tc_32bit_config::compare_capture_channel, tc_config::count_direction, tc_config::counter_16_bit, tc_config::counter_32_bit, tc_config::counter_8_bit, tc_config::counter_size, system_pinmux_config::direction, tc_config::enable_capture_on_channel, tc_pwm_channel::enabled, system_pinmux_config::mux_position, tc_config::oneshot, tc_8bit_config::period, tc_pwm_channel::pin_mux, tc_pwm_channel::pin_out, tc_config::pwm_channel, tc_config::reload_action, tc_config::run_in_standby, system_gclk_chan_config::source_generator, STATUS_BUSY, STATUS_ERR_DENIED, STATUS_ERR_INVALID_ARG, STATUS_OK, system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBC, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), system_gclk_chan_set_config(), system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_OUTPUT, system_pinmux_pin_set_config(), TC_COUNTER_SIZE_16BIT, TC_COUNTER_SIZE_32BIT, TC_COUNTER_SIZE_8BIT, tc_is_syncing(), tc_8bit_config::value, tc_16bit_config::value, tc_32bit_config::value, tc_config::wave_generation, and tc_config::waveform_invert_output.
Referenced by test_event_gen_user_init().
Determines if the hardware module(s) are currently synchronizing to the bus.
Checks to see if the underlying hardware peripheral module(s) are currently synchronizing across multiple clock domains to the hardware bus. This function can be used to delay further operations on a module until such time that it is ready, to prevent blocking delays for synchronization in the user application.
[in] | module_inst | Pointer to the software module instance struct |
false | If the module has completed synchronization |
true | If the module synchronization is ongoing |
References Assert.
Referenced by tc_disable(), tc_dma_trigger_command(), tc_enable(), tc_get_capture_value(), tc_get_count_value(), tc_init(), tc_reset(), tc_set_compare_value(), tc_set_count_value(), tc_set_top_value(), tc_start_counter(), tc_stop_counter(), tc_sync_read_count(), and tc_update_double_buffer().
enum status_code tc_reset | ( | const struct tc_module *const | module_inst | ) |
Resets the TC module.
Resets the TC module, restoring all hardware module registers to their default values and disabling the module. The TC module will not be accessible while the reset is being performed.
[in] | module_inst | Pointer to the software module instance struct |
STATUS_OK | The module was reset successfully |
STATUS_ERR_UNSUPPORTED_DEV | A 32-bit slave TC module was passed to the function. Only use reset on master TC |
References Assert, STATUS_ERR_UNSUPPORTED_DEV, STATUS_OK, tc_disable(), and tc_is_syncing().
enum status_code tc_set_compare_value | ( | const struct tc_module *const | module_inst, |
const enum tc_compare_capture_channel | channel_index, | ||
const uint32_t | compare | ||
) |
Sets a TC module compare value.
Writes a compare value to the given TC module compare/capture channel.
[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 to set |
STATUS_OK | The compare value was updated successfully |
STATUS_ERR_INVALID_ARG | An invalid channel index was supplied |
References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, TC_COUNTER_SIZE_16BIT, TC_COUNTER_SIZE_32BIT, TC_COUNTER_SIZE_8BIT, and tc_is_syncing().
enum status_code tc_set_count_value | ( | const struct tc_module *const | module_inst, |
const uint32_t | count | ||
) |
Sets TC module count value.
Sets the current timer count value of a initialized TC module. The specified TC module may be started or stopped.
[in] | module_inst | Pointer to the software module instance struct |
[in] | count | New timer count value to set |
STATUS_OK | The timer count was updated successfully |
STATUS_ERR_INVALID_ARG | An invalid timer counter size was specified |
References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, TC_COUNTER_SIZE_16BIT, TC_COUNTER_SIZE_32BIT, TC_COUNTER_SIZE_8BIT, and tc_is_syncing().
enum status_code tc_set_top_value | ( | const struct tc_module *const | module_inst, |
const uint32_t | top_value | ||
) |
Set the timer TOP/period value.
For 8-bit counter size this function writes the top value to the period register.
For 16- and 32-bit counter size this function writes the top value to Capture Compare register 0. The value in this register can not be used for any other purpose.
[in] | module_inst | Pointer to the software module instance struct |
[in] | top_value | New timer TOP value to set |
STATUS_OK | The timer TOP value was updated successfully |
STATUS_ERR_INVALID_ARG | The configured TC module counter size in the module instance is invalid |
References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, TC_COUNTER_SIZE_16BIT, TC_COUNTER_SIZE_32BIT, TC_COUNTER_SIZE_8BIT, and tc_is_syncing().
|
inlinestatic |
Starts the counter.
Starts or restarts an initialized TC module's counter.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tc_is_syncing().
|
inlinestatic |
Stops the counter.
This function will stop the counter. When the counter is stopped the value in the count value is set to 0 if the counter was counting up, or maximum if the counter was counting down when stopped.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tc_is_syncing().
Referenced by cleanup_asynchronous_event_test(), cleanup_resynchronous_event_test(), and cleanup_synchronous_event_test().
|
inlinestatic |
Read synchronization of COUNT.
Read synchronization of COUNT.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tc_is_syncing().
|
inlinestatic |
Update double buffer.
Update double buffer.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tc_is_syncing().