This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the TCC module within the device, for waveform generation and timing operations.
It also provides extended options for control applications.
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 for Control Applications (TCC) 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, software timekeeping for periodic operations, waveform extension control, fault detection etc.
The counter size of the TCC modules can be 16- or 24-bit depending on the TCC instance. Refer SAM TCC Feature List and SAM D10/D11 TCC Feature List for details on TCC instances.
The TCC module for the SAM includes the following functions:
The diagram below shows the overview of the TCC Module.
The TCC module consists of following sections:
The base counter can be configured to either count a prescaled generic clock or events from the event system.(TCEx, with event action configured to counting). The counter value can be used by compare/capture channels which can be set up either in compare mode or capture mode.
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 channels' 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 PWM signal generation.
In compare mode, when output signal is generated, extended waveform controls are available, to arrange the compare outputs into specific formats. The Output matrix can change the channel output routing. Pattern generation unit can overwrite the output signal line to specific state. The Fault protection feature of the TCC supports recoverable and non-recoverable faults.
Each TCC has a counter size of either 16- or 24-bits. The size of the counter determines the maximum value it can count to before an overflow occurs. The table below shows the maximum values for each of the possible counter sizes.
Counter size | Max. (hexadecimal) | Max. (decimal) |
---|---|---|
16-bit | 0xFFFF | 65,535 |
24-bit | 0xFFFFFF | 16,777,215 |
The period/top value of the counter can be set, to define counting period. This will allow the counter to overflow when the counter value reaches the period/top value.
TCC is clocked asynchronously to the system clock by a GCLK (Generic Clock) channel. The GCLK channel can be connected to any of the GCLK generators. The GCLK generators are configured to use one of the available clock sources in the system such as internal oscillator, external crystals, etc. See the Generic Clock driver for more information.
Each TCC module in the SAM has its own individual clock prescaler, which can be used to divide the input clock frequency used by 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 be synchronized 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 TCC 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.
The TCC can take several actions on the occurrence of an input event. The event actions are listed in events action settings.
Event action | Description | Applied event |
---|---|---|
TCC_EVENT_ACTION_OFF | No action on the event input | All |
TCC_EVENT_ACTION_RETRIGGER | Re-trigger Counter on event | All |
TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT | Generate Non-Recoverable Fault on event | All |
TCC_EVENT_ACTION_START | Counter start on event | EV0 |
TCC_EVENT_ACTION_DIR_CONTROL | Counter direction control | EV0 |
TCC_EVENT_ACTION_DECREMENT | Counter decrement on event | EV0 |
TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE | Capture pulse period and pulse width | EV0 |
TCC_EVENT_ACTION_PULSE_WIDTH_PERIOD_CAPTURE | Capture pulse width and pulse period | EV0 |
TCC_EVENT_ACTION_STOP | Counter stop on event | EV1 |
TCC_EVENT_ACTION_COUNT_EVENT | Counter count on event | EV1 |
TCC_EVENT_ACTION_INCREMENT | Counter increment on event | EV1 |
TCC_EVENT_ACTION_COUNT_DURING_ACTIVE | Counter count during active state of asynchronous event | EV1 |
The TCC also has a configurable reload action, used when a re-trigger event occurs. Examples of a re-trigger event could be the counter reaching the maximum value when counting up, or when an event from the event system makes the counter to re-trigger. The reload action determines if the prescaler should be reset, and on which clock. The counter will always be reloaded with the value it is set to start counting. The user can choose between three different reload actions, described in the table below.
Reload action | Description |
---|---|
TCC_RELOAD_ACTION_GCLK | Reload TCC counter value on next GCLK cycle. Leave prescaler as-is. |
TCC_RELOAD_ACTION_PRESC | Reloads TCC counter value on next prescaler clock. Leave prescaler as-is. |
TCC_RELOAD_ACTION_RESYNC | Reload TCC 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 TCC uses the prescaler, the counter in the prescaler should not have a value between zero and the division factor. The counter in the TCC module and the counter in the prescaler should both start at zero. If the counter is set to re-trigger when it reaches the maximum value, 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.
The TCC module can be configured in 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 from the event system.
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 timestamps for the events, 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 input event appears, the current counter value is copied into the corresponding compare/capture register, which can then be read 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 they really are. In this case, 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, TCC_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 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. 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.
Refer to Timer/Counter Control Inputs (Events) to set up the input event to perform pulse width capture.
In compare match operation, Compare/Capture registers are compared 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 operation is 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 (in terms of the number of prescaled GCLK cycles, or input events) at which an action should be taken by the microcontroller. This can be an Interrupt Service Routine (ISR), event generation via the event system, or a software flag that is polled from the user application.
Waveform generation enables the TCC 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 applications. When PWM mode is used, a digital pulse train with a configurable frequency and duty cycle can be generated by the TCC 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 is 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 using the timer in Normal PWM mode (Single Slope). As can be seen, the TOP/PERIOD 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.
Several PWM modes are supported by the TCC module, refer to datasheet for the details on PWM waveform generation.
Normal Frequency Generation is in many ways identical to PWM generation. However, only in Frequency Generation, a toggle occurs on the output when a match on a compare channels occurs.
When the Match Frequency Generation is used, the timer value is reset on match condition, resulting in a variable frequency square wave with a fixed 50% duty cycle.
Pattern insertion allows the TCC module to change the actual pin output level without modifying the compare/match settings.
Pattern | Description |
---|---|
TCC_OUTPUT_PATTERN_DISABLE | Pattern disabled, generate output as is |
TCC_OUTPUT_PATTERN_0 | Generate pattern 0 on output (keep the output LOW) |
TCC_OUTPUT_PATTERN_1 | Generate pattern 1 on output (keep the output HIGH) |
The recoverable faults can trigger one or several of following fault actions:
Action | Description |
---|---|
TCC_FAULT_HALT_ACTION_DISABLE | Halt action is disabled |
TCC_FAULT_HALT_ACTION_HW_HALT | The timer/counter is halted as long as the corresponding fault is present |
TCC_FAULT_HALT_ACTION_SW_HALT | The timer/counter is halted until the corresponding fault is removed and fault state cleared by software |
TCC_FAULT_HALT_ACTION_NON_RECOVERABLE | Force all the TCC output pins to a pre-defined level, as what Non-Recoverable Fault do |
Action | Description |
---|---|
TCC_FAULT_CAPTURE_DISABLE | Capture action is disabled |
TCC_FAULT_CAPTURE_EACH | Equivalent to standard capture operation, on each fault occurrence the time stamp is captured |
TCC_FAULT_CAPTURE_MINIMUM | Get the minimum time stamped value in all time stamps |
TCC_FAULT_CAPTURE_MAXIMUM | Get the maximum time stamped value in all time stamps |
TCC_FAULT_CAPTURE_SMALLER | Time stamp the fault input if the value is smaller than last one |
TCC_FAULT_CAPTURE_BIGGER | Time stamp the fault input if the value is bigger than last one |
TCC_FAULT_CAPTURE_CHANGE | Time stamp the fault input if the time stamps changes its increment direction |
In TCC module, only the first two compare channels (CC0 and CC1) can work with recoverable fault inputs. The corresponding event inputs (TCCx MC0 and TCCx MC1) are then used as fault inputs respectively. The faults are called Fault A and Fault B.
The recoverable fault can be filtered or effected by corresponding channel output. On fault condition there are many other settings that can be chosen. Refer to data sheet for more details about the recoverable fault operations.
The non-recoverable faults force all the TCC output pins to a pre-defined level (can be forced to 0 or 1). The input control signal of non-recoverable fault is from timer/counter event (TCCx EV0 and TCCx EV1). To enable non-recoverable fault, corresponding TCEx event action must be set to non-recoverable fault action (TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT). Refer to Timer/Counter Control Inputs (Events) to see the available event input action.
The pattern, period, and the compare channels registers are double buffered. For these options there are effective registers (PATT, PER, and CCx) and buffer registers (PATTB, PERB, and CCx). When writing to the buffer registers, the values are buffered and will be committed to effective registers on UPDATE condition.
Usually the buffered value is cleared after it is committed, but there is also an option to circular the register buffers. The period (PER) and four lowest compare channels register (CCx, x is 0 ~ 3) support this function. When circular buffer is used, on UPDATE the previous period or compare values are copied back into the corresponding period buffer and compare buffers. This way, the register value and its buffer register value is actually switched on UPDATE condition, and will be switched back on next UPDATE condition.
For input capture, the buffer register (CCBx) and the corresponding capture channel register (CCx) act like a FIFO. When regular register (CCx) is empty or read, any content in the buffer register is passed to regular one.
In TCC module driver, when the double buffering write is enabled, any write through tcc_set_top_value(), tcc_set_compare_value(), and tcc_set_pattern() will be done to the corresponding buffer register. Then the value in the buffer register will be transferred to the regular register on the next UPDATE condition or by a force UPDATE using tcc_force_double_buffer_update().
TCC modules can be configured to operate in any sleep mode, with its "run in standby" function enabled. It can wake up the device using interrupts or perform internal actions with the help of the Event System.
The table below shows some specific features of the TCC Module.
Driver Feature Macro | Supported devices |
---|---|
FEATURE_TCC_GENERATE_DMA_TRIGGER | SAM L21/L22/R30/R34/R35 |
The features of TCC, such as timer/counter size, number of compare capture channels, and number of outputs, are dependent on the TCC module instance being used.
For SAM D21/R21/L21/L22/DA1/C21/R30, the TCC features are:
TCC# | Match/Capture channels | Wave outputs | Counter size [bits] | Fault | Dithering | Output matrix | Dead-Time insertion | SWAP | Pattern |
---|---|---|---|---|---|---|---|---|---|
0 | 4 | 8 | 24 | Y | Y | Y | Y | Y | Y |
1 | 2 | 4 | 24 | Y | Y | Y | |||
2 | 2 | 2 | 16 | Y |
For SAM D10/D11, the TCC features are:
TCC# | Match/Capture channels | Wave outputs | Counter size [bits] | Fault | Dithering | Output matrix | Dead-Time insertion | SWAP | Pattern |
---|---|---|---|---|---|---|---|---|---|
0 | 4 | 8 | 24 | Y | Y | Y | Y | Y | Y |
As the TCC module may have more waveform output pins than the number of compare/capture channels, the free pins (with number higher than number of channels) will reuse the waveform generated by channels subsequently. E.g., if the number of channels is four and the number of wave output pins is eight, channel 0 output will be available on out pin 0 and 4, channel 1 output on wave out pin 1 and 5, and so on.
For extra information, see Extra Information for TCC Driver. This includes:
For a list of examples related to this driver, see Examples for TCC Driver.
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... | |
Typedefs | |
typedef void(* | tcc_callback_t )(struct tcc_module *const module) |
Type definition for the TCC callback function. 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... | |
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... | |
#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.
#define _TCC_ENUM | ( | n, | |
type | |||
) | TCC_##type##_##n, |
Generates a table enum list entry for a given type and index (e.g.
"TCC_CALLBACK_MC_CHANNEL_0,").
#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.
#define FEATURE_TCC_GENERATE_DMA_TRIGGER |
Generate DMA triggers.
#define TCC_NUM_CHANNELS 4 |
Maximum number of channels supported by the driver (Channel index from 0 to TCC_NUM_CHANNELS
- 1).
Referenced by _tcc_build_ctrla(), _tcc_build_waves(), tcc_clear_status(), tcc_disable_events(), tcc_enable_events(), tcc_get_config_defaults(), tcc_get_status(), and tcc_init().
#define TCC_NUM_FAULTS 2 |
Maximum number of (recoverable) faults supported by the driver.
Referenced by _tcc_build_faults(), tcc_get_config_defaults(), and tcc_init().
#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).
Referenced by _tcc_build_drvctrl(), tcc_get_config_defaults(), and tcc_init().
#define TCC_STATUS_CAPTURE_OVERFLOW (1UL << 24) |
A new value was captured before the previous value was read, resulting in lost data.
Referenced by tcc_clear_status(), and tcc_get_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.
Referenced by tcc_clear_status(), and tcc_get_status().
#define TCC_STATUS_CHANNEL_OUTPUT | ( | ch | ) | (1UL << ((ch)+8)) |
Timer channel ch
(0 ~ 3) match/compare output state.
Referenced by tcc_get_status().
#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.
Referenced by tcc_clear_status(), and tcc_get_status().
#define TCC_STATUS_COUNTER_EVENT (1UL << 25) |
A counter event occurred.
Referenced by tcc_clear_status(), and tcc_get_status().
#define TCC_STATUS_COUNTER_RETRIGGERED (1UL << 26) |
A counter retrigger occurred.
Referenced by tcc_clear_status(), and tcc_get_status().
#define TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR | ( | x | ) | (1UL << ((x)+16)) |
A Non-Recoverable Fault x
(0 ~ 1) has occurred.
Referenced by tcc_clear_status(), and tcc_get_status().
#define TCC_STATUS_NON_RECOVERABLE_FAULT_PRESENT | ( | x | ) | (1UL << ((x)+20)) |
The Non-Recoverable Fault x
(0 ~ 1) input is present.
Referenced by tcc_get_status().
#define TCC_STATUS_RAMP_CYCLE_INDEX (1UL << 28) |
Ramp period cycle index.
In ramp operation, each two period cycles are marked as cycle A and B, the index 0 represents cycle A and 1 represents cycle B.
Referenced by tcc_get_status().
#define TCC_STATUS_RECOVERABLE_FAULT_OCCUR | ( | n | ) | (1UL << ((n)+18)) |
A Recoverable Fault n
(0 ~ 1 representing A ~ B) has occured.
Referenced by tcc_clear_status(), and tcc_get_status().
#define TCC_STATUS_RECOVERABLE_FAULT_PRESENT | ( | n | ) | (1UL << ((n)+22)) |
A Recoverable Fault n
(0 ~ 1 representing A ~ B) is present.
Referenced by tcc_get_status().
#define TCC_STATUS_STOPPED (1UL << 29) |
The counter has been stopped (due to disable, stop command, or one-shot).
Referenced by tcc_get_status().
#define TCC_STATUS_SYNC_READY (1UL << 23) |
Timer registers synchronization has completed, and the synchronized count value may be read.
Referenced by tcc_get_status().
typedef void(* tcc_callback_t)(struct tcc_module *const module) |
Type definition for the TCC callback function.
enum tcc_callback |
Enum for the possible callback types for the TCC module.
enum tcc_channel_function |
enum tcc_clock_prescaler |
TCC clock prescaler values.
This enum is used to choose the clock prescaler configuration. The prescaler divides the clock frequency of the TCC module to operate TCC at a slower clock rate.
enum tcc_count_direction |
TCC module counter overflow DMA request mode.
Used when selecting the Timer/Counter overflow DMA request mode.
enum tcc_event0_action |
Action to be performed when the TCC module is triggered by event0.
Event action to perform when the module is triggered by event0.
enum tcc_event1_action |
Action to perform when the TCC module is triggered by event1.
Event action to perform when the module is triggered by event1.
enum tcc_event_action |
Action to perform when the TCC module is triggered by events.
Event action to perform when the module is triggered by events.
On which part of the counter cycle the counter event output is generated.
This enum is used to define the point at which the counter event is generated.
enum tcc_fault_blanking |
TCC (recoverable) fault Input Blanking Start Point.
TCC (recoverable) fault Capture action.
Capture Channel triggered by TCC (recoverable) fault.
TCC (recoverable) fault Halt action.
enum tcc_fault_keep |
enum tcc_fault_restart |
enum tcc_fault_source |
TCC (recoverable) fault Input Source.
Index of the match capture channels.
This enum is used to specify which capture/match channel to do operations on.
enum tcc_output_invertion |
enum tcc_output_pattern |
enum tcc_ramp |
Ramp Operations which are supported in single-slope PWM generation.
Ramp operations which are supported in single-slope PWM generation.
enum tcc_ramp_index |
Ramp Index for TCC wave generation.
In ramp operation, each two period cycles are marked as cycle A and B, the index 0 represents cycle A and 1 represents cycle B.
enum tcc_reload_action |
TCC Counter reload action enum.
This enum specify how the counter is reloaded and whether the prescaler should be restarted.
enum tcc_wave_generation |
TCC wave generation mode enum.
This enum is used to specify the waveform generation mode.
enum tcc_wave_output |
Index of the wave outputs.
This enum is used to specify which wave output to do operations on.
enum tcc_wave_polarity |
void tcc_clear_status | ( | struct tcc_module *const | module_inst, |
const uint32_t | status_flags | ||
) |
Clears a module status flag.
Clears the given status flag of the module.
[in] | module_inst | Pointer to the TCC software instance struct |
[in] | status_flags | Bitmask of TCC_STATUS_* flags to clear |
References Assert, tcc_module::hw, TCC_NUM_CHANNELS, TCC_STATUS_CAPTURE_OVERFLOW, TCC_STATUS_CHANNEL_MATCH_CAPTURE, TCC_STATUS_COUNT_OVERFLOW, TCC_STATUS_COUNTER_EVENT, TCC_STATUS_COUNTER_RETRIGGERED, TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR, and TCC_STATUS_RECOVERABLE_FAULT_OCCUR.
|
inlinestatic |
Disables the TCC module.
Disables a TCC module and stops the counter.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tcc_module::hw.
Referenced by tcc_reset().
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.
Stop circularing the double buffered compare values.
[in] | module_inst | Pointer to the TCC software instance struct |
[in] | channel_index | Index of the compare channel to set up to |
STATUS_OK | The module was initialized successfully |
STATUS_INVALID_ARG | An invalid channel index is supplied |
References _tcc_cc_nums, _tcc_get_inst_index(), Assert, tcc_module::hw, STATUS_ERR_INVALID_ARG, and STATUS_OK.
|
inlinestatic |
Disable Circular option for double buffered Top/Period Values.
Stop circularing the double buffered top/period values.
[in] | module_inst | Pointer to the TCC software instance struct |
References Assert, and tcc_module::hw.
|
inlinestatic |
Disable TCC double buffering Write.
When double buffering write is disabled, following function will write values to effective registers (not buffered):
[in] | module_inst | Pointer to the TCC software instance struct |
References Assert, tcc_module::double_buffering_enabled, and tcc_module::hw.
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.
Disables one or more input or output events for the given TCC module. See tcc_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, tcc_events::generate_event_on_channel, tcc_events::generate_event_on_counter_event, tcc_events::generate_event_on_counter_overflow, tcc_events::generate_event_on_counter_retrigger, tcc_module::hw, tcc_events::input_config, tcc_input_event_config::invert, tcc_events::on_event_perform_channel_action, tcc_events::on_input_event_perform_action, and TCC_NUM_CHANNELS.
|
inlinestatic |
TCC DMA Trigger.
TCC DMA trigger command.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tcc_module::hw.
|
inlinestatic |
Enable the TCC module.
Enables a TCC 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 tcc_module::hw.
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.
Enable circular option for the double buffered channel compare values. On each UPDATE condition, the contents of CCBx and CCx are switched, meaning that the contents of CCBx are transferred to CCx and the contents of CCx are transferred to CCBx.
[in] | module_inst | Pointer to the TCC software instance struct |
[in] | channel_index | Index of the compare channel to set up to |
STATUS_OK | The module was initialized successfully |
STATUS_INVALID_ARG | An invalid channel index is supplied |
References _tcc_cc_nums, _tcc_get_inst_index(), Assert, tcc_module::hw, STATUS_ERR_INVALID_ARG, and STATUS_OK.
|
inlinestatic |
Enable Circular option for double buffered Top/Period Values.
Enable circular option for the double buffered top/period values. On each UPDATE condition, the contents of PERB and PER are switched, meaning that the contents of PERB are transferred to PER and the contents of PER are transferred to PERB.
[in] | module_inst | Pointer to the TCC software instance struct |
References Assert, and tcc_module::hw.
|
inlinestatic |
Enable TCC double buffering write.
When double buffering write is enabled, the following function will write values to buffered registers instead of effective ones (buffered):
Then, on UPDATE condition the buffered registers are committed to regular ones to take effect.
[in] | module_inst | Pointer to the TCC software instance struct |
References Assert, and tcc_module::double_buffering_enabled.
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.
Enables one or more input or output events to or from the TCC module. See tcc_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 or configure |
STATUS_OK | The module was initialized successfully |
STATUS_INVALID_ARG | An invalid configuration option or argument was supplied |
References tcc_input_event_config::action, Assert, tcc_events::generate_event_on_channel, tcc_events::generate_event_on_counter_event, tcc_events::generate_event_on_counter_overflow, tcc_events::generate_event_on_counter_retrigger, tcc_output_event_config::generation_selection, tcc_module::hw, tcc_events::input_config, tcc_input_event_config::invert, tcc_input_event_config::modify_action, tcc_output_event_config::modify_generation_selection, tcc_events::on_event_perform_channel_action, tcc_events::on_input_event_perform_action, tcc_events::output_config, STATUS_ERR_DENIED, STATUS_ERR_INVALID_ARG, STATUS_OK, TCC_EVENT0_ACTION_COUNT_DURING_ACTIVE, TCC_EVENT0_ACTION_COUNT_EVENT, TCC_EVENT0_ACTION_INCREMENT, TCC_EVENT0_ACTION_NON_RECOVERABLE_FAULT, TCC_EVENT0_ACTION_OFF, TCC_EVENT0_ACTION_RETRIGGER, TCC_EVENT0_ACTION_START, TCC_EVENT1_ACTION_DECREMENT, TCC_EVENT1_ACTION_DIR_CONTROL, TCC_EVENT1_ACTION_NON_RECOVERABLE_FAULT, TCC_EVENT1_ACTION_OFF, TCC_EVENT1_ACTION_PERIOD_PULSE_WIDTH_CAPTURE, TCC_EVENT1_ACTION_PULSE_WIDTH_PERIOD_CAPTURE, TCC_EVENT1_ACTION_RETRIGGER, TCC_EVENT1_ACTION_STOP, TCC_EVENT_GENERATION_SELECTION_BETWEEN, TCC_EVENT_GENERATION_SELECTION_BOUNDARY, TCC_EVENT_GENERATION_SELECTION_END, TCC_EVENT_GENERATION_SELECTION_START, and TCC_NUM_CHANNELS.
|
inlinestatic |
Force the TCC double buffered registers to update once.
[in] | module_inst | Pointer to the TCC software instance struct |
References Assert, and tcc_module::hw.
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.
Retrieves the capture value in the indicated TCC 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 _tcc_cc_nums, _tcc_get_inst_index(), Assert, and tcc_module::hw.
void tcc_get_config_defaults | ( | struct tcc_config *const | config, |
Tcc *const | hw | ||
) |
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:
[out] | config | Pointer to a TCC module configuration structure to set |
[in] | hw | Pointer to the TCC hardware module |
References _TCC_CHANNEL_FUNCTION_INIT, _TCC_CHANNEL_MATCH_VALUE_INIT, _TCC_CHANNEL_OUT_PIN_INIT, _TCC_CHANNEL_WAVE_POLARITY_INIT, _TCC_FAULT_FUNCTION_INIT, _tcc_get_inst_index(), _tcc_maxs, _TCC_NRF_FUNCTION_INIT, _TCC_OUT_INVERT_INIT, tcc_counter_config::clock_prescaler, tcc_counter_config::clock_source, tcc_config::compare, tcc_counter_config::count, tcc_config::counter, tcc_counter_config::direction, tcc_counter_config::dma_trigger_mode, tcc_config::double_buffering_enabled, GCLK_GENERATOR_0, MREPEAT, tcc_counter_config::oneshot, tcc_counter_config::period, tcc_counter_config::reload_action, tcc_config::run_in_standby, TCC_CHANNEL_FUNCTION_COMPARE, TCC_CLOCK_PRESCALER_DIV1, TCC_COUNT_DIRECTION_UP, TCC_COUNT_OVERFLOW_DMA_TRIGGER_MODE_CONTINUE, TCC_NUM_CHANNELS, TCC_NUM_FAULTS, TCC_NUM_WAVE_OUTPUTS, TCC_RAMP_RAMP1, TCC_RELOAD_ACTION_GCLK, TCC_WAVE_GENERATION_NORMAL_FREQ, TCC_WAVE_POLARITY_0, tcc_match_wave_config::wave_generation, and tcc_match_wave_config::wave_ramp.
uint32_t tcc_get_count_value | ( | const struct tcc_module *const | module_inst | ) |
Get count value of the given TCC module.
Retrieves the current count value of a TCC module. The specified TCC module can remain running or stopped.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tcc_module::hw.
uint32_t tcc_get_status | ( | struct tcc_module *const | module_inst | ) |
Retrieves the current module status.
Retrieves the status of the module, giving overall state information.
[in] | module_inst | Pointer to the TCC software instance struct |
TCC_STATUS_*
flags.TCC_STATUS_CHANNEL_MATCH_CAPTURE(n) | Channel n match/capture has occured |
TCC_STATUS_CHANNEL_OUTPUT(n) | Channel n match/capture output state |
TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR(x) | Non-recoverable fault x has occured |
TCC_STATUS_RECOVERABLE_FAULT_OCCUR(n) | Recoverable fault n has occured |
TCC_STATUS_NON_RECOVERABLE_FAULT_PRESENT(x) | Non-recoverable fault x input present |
TCC_STATUS_RECOVERABLE_FAULT_PRESENT(n) | Recoverable fault n input present |
TCC_STATUS_SYNC_READY | None of register is syncing |
TCC_STATUS_CAPTURE_OVERFLOW | Timer capture data has overflowed |
TCC_STATUS_COUNTER_EVENT | Timer counter event has occurred |
TCC_STATUS_COUNT_OVERFLOW | Timer count value has overflowed |
TCC_STATUS_COUNTER_RETRIGGERED | Timer counter has been retriggered |
TCC_STATUS_STOP | Timer counter has been stopped |
TCC_STATUS_RAMP_CYCLE_INDEX | Wave ramp index for cycle |
References Assert, tcc_module::hw, TCC_NUM_CHANNELS, TCC_STATUS_CAPTURE_OVERFLOW, TCC_STATUS_CHANNEL_MATCH_CAPTURE, TCC_STATUS_CHANNEL_OUTPUT, TCC_STATUS_COUNT_OVERFLOW, TCC_STATUS_COUNTER_EVENT, TCC_STATUS_COUNTER_RETRIGGERED, TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR, TCC_STATUS_NON_RECOVERABLE_FAULT_PRESENT, TCC_STATUS_RAMP_CYCLE_INDEX, TCC_STATUS_RECOVERABLE_FAULT_OCCUR, TCC_STATUS_RECOVERABLE_FAULT_PRESENT, TCC_STATUS_STOPPED, and TCC_STATUS_SYNC_READY.
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.
Enables the clock and initializes the given TCC module, based on the given configuration values.
[in,out] | module_inst | Pointer to the software module instance struct |
[in] | hw | Pointer to the TCC hardware module |
[in] | config | Pointer to the TCC configuration options struct |
STATUS_OK | The module was initialized successfully |
STATUS_BUSY | The hardware module was busy when the initialization procedure was attempted |
STATUS_INVALID_ARG | An invalid configuration option or argument was supplied |
STATUS_ERR_DENIED | The hardware module was already enabled |
References _tcc_apbcmasks, _tcc_build_ctrla(), _tcc_build_ctrlb(), _tcc_build_drvctrl(), _tcc_build_faults(), _tcc_build_waves(), _tcc_cc_nums, _tcc_gclk_ids, _tcc_get_inst_index(), _tcc_instances, _tcc_maxs, _tcc_ow_nums, Assert, tcc_module::callback, tcc_counter_config::clock_source, tcc_config::compare, tcc_counter_config::count, tcc_config::counter, system_pinmux_config::direction, tcc_config::double_buffering_enabled, tcc_module::double_buffering_enabled, tcc_module::enable_callback_mask, tcc_pins_config::enable_wave_out_pin, tcc_module::hw, tcc_match_wave_config::match, system_pinmux_config::mux_position, NULL, tcc_counter_config::period, tcc_config::pins, tcc_module::register_callback_mask, system_gclk_chan_config::source_generator, 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(), TCC_NUM_CHANNELS, TCC_NUM_FAULTS, TCC_NUM_WAVE_OUTPUTS, tcc_pins_config::wave_out_pin, and tcc_pins_config::wave_out_pin_mux.
|
inlinestatic |
Checks if the timer/counter is running.
[in] | module_inst | Pointer to the TCC software instance struct |
true | The timer/counter is running |
false | The timer/counter is stopped |
References Assert, and tcc_module::hw.
|
inlinestatic |
Determines if the hardware module is currently synchronizing to the bus.
Checks to see if the underlying hardware peripheral module is 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, and tcc_module::hw.
Referenced by tcc_reset().
|
inlinestatic |
Lock the TCC double buffered registers updates.
Locks the double buffered registers so they will not be updated through their buffered values on UPDATE conditions.
[in] | module_inst | Pointer to the TCC software instance struct |
References Assert, and tcc_module::hw.
|
inlinestatic |
Resets the TCC module.
Resets the TCC module, restoring all hardware module registers to their default values and disabling the module. The TCC module will not be accessible while the reset is being performed.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, tcc_module::hw, tcc_disable(), and tcc_is_syncing().
|
inlinestatic |
Starts the counter from beginning.
Restarts an initialized TCC module's counter.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tcc_module::hw.
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.
Writes a compare value to the given TCC module compare/capture channel.
If double buffering is enabled it always write to the buffer register. The value will then be updated immediately by calling tcc_force_double_buffer_update(), or be updated when the lock update bit is cleared and the UPDATE condition happen.
[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 or compare value exceed resolution |
References _tcc_set_compare_value(), Assert, and tcc_module::double_buffering_enabled.
|
inlinestatic |
Sets the TCC module count direction.
Sets the count direction of an initialized TCC module. The specified TCC module can remain running or stopped.
[in] | module_inst | Pointer to the software module instance struct |
[in] | dir | New timer count direction to set |
References Assert, tcc_module::hw, and TCC_COUNT_DIRECTION_DOWN.
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.
Sets the timer count value of an initialized TCC module. The specified TCC module can remain running 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 _tcc_get_inst_index(), _tcc_maxs, Assert, tcc_module::hw, STATUS_ERR_INVALID_ARG, and STATUS_OK.
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.
Writes compare value and buffer to the given TCC module compare/capture channel. Usually as preparation for double buffer or circulared double buffer (circular buffer).
[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 |
[in] | compare_buffer | New compare buffer value to set |
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_set_compare_value(), Assert, and STATUS_OK.
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.
This function writes the given value to the PER and PERB register. Usually as preparation for double buffer or circulared double buffer (circular buffer).
When using MFRQ, the top values are defined by the CC0 and CCB0, the PER and PERB values are ignored, so tcc_set_double_buffer_compare_values (module,channel_0,value,buffer) must be used instead of this function to change the actual top values in that case. For all other waveforms operation the top values are defined by PER and PERB registers values.
[in] | module_inst | Pointer to the software module instance struct |
[in] | top_value | New value to be loaded into the PER register |
[in] | top_buffer_value | New value to be loaded into the PERB register |
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_set_top_value(), Assert, and STATUS_OK.
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.
Force waveform output line to generate specific pattern (0, 1, or as is).
If double buffering is enabled it always write to the buffer register. The value will then be updated immediately by calling tcc_force_double_buffer_update(), or be updated when the lock update bit is cleared and the UPDATE condition happen.
[in] | module_inst | Pointer to the software module instance struct |
[in] | line_index | Output line index |
[in] | pattern | Output pattern to use (tcc_output_pattern) |
STATUS_OK | The PATT register is updated successfully |
STATUS_ERR_INVALID_ARG | An invalid line index was supplied |
References _tcc_get_inst_index(), _tcc_ow_nums, Assert, tcc_module::double_buffering_enabled, tcc_module::hw, STATUS_ERR_INVALID_ARG, STATUS_OK, TCC_OUTPUT_PATTERN_0, and TCC_OUTPUT_PATTERN_DISABLE.
|
inlinestatic |
Sets the TCC module ramp index on next cycle.
In RAMP2 and RAMP2A operation, we can force either cycle A or cycle B at the output, on the next clock cycle. When ramp index command is disabled, cycle A and cycle B will appear at the output, on alternate clock cycles. See tcc_ramp.
[in] | module_inst | Pointer to the software module instance struct |
[in] | ramp_index | Ramp index (tcc_ramp_index) of the next cycle |
References Assert, tcc_module::hw, and TCC_RAMP_INDEX_DEFAULT.
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.
This function writes the given value to the PER/PERB register.
If double buffering is enabled it always write to the buffer register (PERB). The value will then be updated immediately by calling tcc_force_double_buffer_update(), or be updated when the lock update bit is cleared and the UPDATE condition happen.
When using MFRQ, the top value is defined by the CC0 register value and the PER value is ignored, so tcc_set_compare_value (module,channel_0,value) must be used instead of this function to change the actual top value in that case. For all other waveforms operation the top value is defined by PER register value.
[in] | module_inst | Pointer to the software module instance struct |
[in] | top_value | New value to be loaded into the PER/PERB register |
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_set_top_value(), Assert, and tcc_module::double_buffering_enabled.
|
inlinestatic |
Stops the counter.
This function will stop the counter. When the counter is stopped the value in the count register is set to 0 if the counter was counting up, or maximum or the top value if the counter was counting down.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tcc_module::hw.
|
inlinestatic |
Toggles the TCC module count direction.
Toggles the count direction of an initialized TCC module. The specified TCC module can remain running or stopped.
[in] | module_inst | Pointer to the software module instance struct |
References Assert, and tcc_module::hw.
|
inlinestatic |
Unlock the TCC double buffered registers updates.
Unlock the double buffered registers so they will be updated through their buffered values on UPDATE conditions.
[in] | module_inst | Pointer to the TCC software instance struct |
References Assert, and tcc_module::hw.