Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM Timer Counter for Control Applications (TCC) Driver

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:

Prerequisites

There are no prerequisites for this module.

Module Overview

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.

overview.svg
Overview of the TCC Module

Functional Description

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.

Note
The connection of events between modules requires the use of the SAM Event System Driver (EVENTS) to route output event of one module to the the input event of another. For more information on event routing, refer to the event driver documentation.

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.

Base Timer/Counter

Timer/Counter Size

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.

Timer Counter Sizes and Their Maximum Count Values
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.

Timer/Counter Clock and Prescaler

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.

Timer/Counter Control Inputs (Events)

The TCC can take several actions on the occurrence of an input event. The event actions are listed in events action settings.

TCC Module Event Actions
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

Timer/Counter Reloading

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.

TCC Module Reload Actions
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.

One-shot Mode

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.

Capture Operations

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.

Capture Operations - Event

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.

Capture Operations - Pulse Width

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.

Compare Match Operation

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.

Basic Timer

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

Waveform generation enables the TCC module to generate square waves, or, if combined with an external passive low-pass filter, analog waveforms.

Waveform Generation - PWM

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.

pwm_single_ex.svg
Example Of PWM In Single-Slope Mode, and Different Counter Operations

Several PWM modes are supported by the TCC module, refer to datasheet for the details on PWM waveform generation.

Waveform Generation - Frequency

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.

Waveform Extended Controls

Pattern Generation

Pattern insertion allows the TCC module to change the actual pin output level without modifying the compare/match settings.

TCC Module Output Pattern Generation
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)

Recoverable Faults

The recoverable faults can trigger one or several of following fault actions:

  1. Halt action: The recoverable faults can halt the TCC timer/counter, so that the final output wave is kept at a defined state. When the fault state is removed it is possible to recover the counter and waveform generation. The halt action is defined as:
    TCC Module Recoverable Fault Halt 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
  2. Restart action: When enabled, the recoverable faults can restart the TCC timer/counter.
  3. Keep action: When enabled, the recoverable faults can keep the corresponding channel output to zero when the fault condition is present.
  4. Capture action: When the recoverable fault occurs, the capture action can time stamps the corresponding fault. The following capture mode is supported:
    TCC Module Recoverable Fault Capture Actions
    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.

Non-Recoverable Faults

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.

Double and Circular Buffering

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().

Sleep Mode

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.

Special Considerations

Driver Feature Macro Definition

The table below shows some specific features of the TCC Module.

TCC Module Specific Features
Driver Feature Macro Supported devices
FEATURE_TCC_GENERATE_DMA_TRIGGER SAM L21/L22/R30/R34/R35
Note
The specific features are only available in the driver when the selected device supports those features.

Module Features

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.

SAM TCC Feature List

For SAM D21/R21/L21/L22/DA1/C21/R30, the TCC features are:

TCC module features for SAM D21/R21/L21/L22/DA1/C21/R30
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

SAM D10/D11 TCC Feature List

For SAM D10/D11, the TCC features are:

TCC Module Features For SAM D10/D11
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

Channels vs. Pinouts

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.

Extra Information

For extra information, see Extra Information for TCC Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for TCC Driver.

API Overview

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the SAM Timer Counter for Control Applications (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...
 

Enumerations

enum  tcc_callback {
  TCC_CALLBACK_OVERFLOW,
  TCC_CALLBACK_RETRIGGER,
  TCC_CALLBACK_COUNTER_EVENT,
  TCC_CALLBACK_ERROR,
  TCC_CALLBACK_FAULTA,
  TCC_CALLBACK_FAULTB,
  TCC_CALLBACK_FAULT0,
  TCC_CALLBACK_FAULT1,
  TCC_CALLBACK_CHANNEL_n = n
}
 Enum for the possible callback types for the TCC module. More...
 
enum  tcc_channel_function {
  TCC_CHANNEL_FUNCTION_COMPARE,
  TCC_CHANNEL_FUNCTION_CAPTURE
}
 TCC channel operation modes. More...
 
enum  tcc_clock_prescaler {
  TCC_CLOCK_PRESCALER_DIV1,
  TCC_CLOCK_PRESCALER_DIV2,
  TCC_CLOCK_PRESCALER_DIV4,
  TCC_CLOCK_PRESCALER_DIV8,
  TCC_CLOCK_PRESCALER_DIV16,
  TCC_CLOCK_PRESCALER_DIV64,
  TCC_CLOCK_PRESCALER_DIV256,
  TCC_CLOCK_PRESCALER_DIV1024
}
 TCC clock prescaler values. More...
 
enum  tcc_count_direction {
  TCC_COUNT_DIRECTION_UP,
  TCC_COUNT_DIRECTION_DOWN
}
 TCC module count direction. More...
 
enum  tcc_count_overflow_dma_trigger_mode {
  TCC_COUNT_OVERFLOW_DMA_TRIGGER_MODE_CONTINUE,
  TCC_COUNT_OVERFLOW_DMA_TRIGGER_MODE_ONE_SHOT
}
 TCC module counter overflow DMA request mode. More...
 
enum  tcc_event0_action {
  TCC_EVENT0_ACTION_OFF = TCC_EVENT_ACTION_OFF,
  TCC_EVENT0_ACTION_RETRIGGER = TCC_EVENT_ACTION_RETRIGGER,
  TCC_EVENT0_ACTION_COUNT_EVENT = TCC_EVENT_ACTION_COUNT_EVENT,
  TCC_EVENT0_ACTION_START = TCC_EVENT_ACTION_START,
  TCC_EVENT0_ACTION_INCREMENT = TCC_EVENT_ACTION_INCREMENT,
  TCC_EVENT0_ACTION_COUNT_DURING_ACTIVE = TCC_EVENT_ACTION_COUNT_DURING_ACTIVE,
  TCC_EVENT0_ACTION_NON_RECOVERABLE_FAULT = TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT
}
 Action to be performed when the TCC module is triggered by event0. More...
 
enum  tcc_event1_action {
  TCC_EVENT1_ACTION_OFF = TCC_EVENT_ACTION_OFF,
  TCC_EVENT1_ACTION_RETRIGGER = TCC_EVENT_ACTION_RETRIGGER,
  TCC_EVENT1_ACTION_DIR_CONTROL = TCC_EVENT_ACTION_DIR_CONTROL,
  TCC_EVENT1_ACTION_STOP = TCC_EVENT_ACTION_STOP,
  TCC_EVENT1_ACTION_DECREMENT = TCC_EVENT_ACTION_DECREMENT,
  TCC_EVENT1_ACTION_PERIOD_PULSE_WIDTH_CAPTURE = TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE,
  TCC_EVENT1_ACTION_PULSE_WIDTH_PERIOD_CAPTURE = TCC_EVENT_ACTION_PULSE_WIDTH_PERIOD_CAPTURE,
  TCC_EVENT1_ACTION_NON_RECOVERABLE_FAULT = TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT
}
 Action to perform when the TCC module is triggered by event1. More...
 
enum  tcc_event_action {
  TCC_EVENT_ACTION_OFF,
  TCC_EVENT_ACTION_STOP,
  TCC_EVENT_ACTION_RETRIGGER,
  TCC_EVENT_ACTION_START,
  TCC_EVENT_ACTION_COUNT_EVENT,
  TCC_EVENT_ACTION_DIR_CONTROL,
  TCC_EVENT_ACTION_INCREMENT,
  TCC_EVENT_ACTION_DECREMENT,
  TCC_EVENT_ACTION_COUNT_DURING_ACTIVE,
  TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE,
  TCC_EVENT_ACTION_PULSE_WIDTH_PERIOD_CAPTURE,
  TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT
}
 Action to perform when the TCC module is triggered by events. More...
 
enum  tcc_event_generation_selection {
  TCC_EVENT_GENERATION_SELECTION_START,
  TCC_EVENT_GENERATION_SELECTION_END,
  TCC_EVENT_GENERATION_SELECTION_BETWEEN,
  TCC_EVENT_GENERATION_SELECTION_BOUNDARY
}
 On which part of the counter cycle the counter event output is generated. More...
 
enum  tcc_fault_blanking {
  TCC_FAULT_BLANKING_DISABLE,
  TCC_FAULT_BLANKING_RISING_EDGE,
  TCC_FAULT_BLANKING_FALLING_EDGE,
  TCC_FAULT_BLANKING_BOTH_EDGE
}
 TCC (recoverable) fault Input Blanking Start Point. More...
 
enum  tcc_fault_capture_action {
  TCC_FAULT_CAPTURE_DISABLE,
  TCC_FAULT_CAPTURE_EACH,
  TCC_FAULT_CAPTURE_MINIMUM,
  TCC_FAULT_CAPTURE_MAXIMUM,
  TCC_FAULT_CAPTURE_SMALLER,
  TCC_FAULT_CAPTURE_BIGGER,
  TCC_FAULT_CAPTURE_CHANGE
}
 TCC (recoverable) fault Capture action. More...
 
enum  tcc_fault_capture_channel {
  TCC_FAULT_CAPTURE_CHANNEL_0,
  TCC_FAULT_CAPTURE_CHANNEL_1,
  TCC_FAULT_CAPTURE_CHANNEL_2,
  TCC_FAULT_CAPTURE_CHANNEL_3
}
 Capture Channel triggered by TCC (recoverable) fault. More...
 
enum  tcc_fault_halt_action {
  TCC_FAULT_HALT_ACTION_DISABLE,
  TCC_FAULT_HALT_ACTION_HW_HALT,
  TCC_FAULT_HALT_ACTION_SW_HALT,
  TCC_FAULT_HALT_ACTION_NON_RECOVERABLE
}
 TCC (recoverable) fault Halt action. More...
 
enum  tcc_fault_keep {
  TCC_FAULT_KEEP_DISABLE,
  TCC_FAULT_KEEP_TILL_END
}
 TCC (recoverable) fault Output Keep Action. More...
 
enum  tcc_fault_qualification {
  TCC_FAULT_QUALIFICATION_DISABLE,
  TCC_FAULT_QUALIFICATION_BY_OUTPUT
}
 TCC (recoverable) fault Input Qualification Action. More...
 
enum  tcc_fault_restart {
  TCC_FAULT_RESTART_DISABLE,
  TCC_FAULT_RESTART_ENABLE
}
 TCC (recoverable) fault Restart Action. More...
 
enum  tcc_fault_source {
  TCC_FAULT_SOURCE_DISABLE,
  TCC_FAULT_SOURCE_ENABLE,
  TCC_FAULT_SOURCE_INVERT,
  TCC_FAULT_SOURCE_ALTFAULT
}
 TCC (recoverable) fault Input Source. More...
 
enum  tcc_fault_state_output {
  TCC_FAULT_STATE_OUTPUT_OFF,
  TCC_FAULT_STATE_OUTPUT_0,
  TCC_FAULT_STATE_OUTPUT_1
}
 TCC Non-recoverable State Outupt. More...
 
enum  tcc_match_capture_channel { TCC_MATCH_CAPTURE_CHANNEL_n = n }
 Index of the match capture channels. More...
 
enum  tcc_output_invertion {
  TCC_OUTPUT_INVERTION_DISABLE,
  TCC_OUTPUT_INVERTION_ENABLE
}
 TCC output inversion. More...
 
enum  tcc_output_pattern {
  TCC_OUTPUT_PATTERN_DISABLE,
  TCC_OUTPUT_PATTERN_0,
  TCC_OUTPUT_PATTERN_1
}
 TCC pattern generator for outputs. More...
 
enum  tcc_ramp {
  TCC_RAMP_RAMP1 = 0,
  TCC_RAMP_RAMP2A,
  TCC_RAMP_RAMP2
}
 Ramp Operations which are supported in single-slope PWM generation. More...
 
enum  tcc_ramp_index {
  TCC_RAMP_INDEX_DEFAULT,
  TCC_RAMP_INDEX_FORCE_B,
  TCC_RAMP_INDEX_FORCE_A,
  TCC_RAMP_INDEX_FORCE_KEEP
}
 Ramp Index for TCC wave generation. More...
 
enum  tcc_reload_action {
  TCC_RELOAD_ACTION_GCLK,
  TCC_RELOAD_ACTION_PRESC,
  TCC_RELOAD_ACTION_RESYNC
}
 TCC Counter reload action enum. More...
 
enum  tcc_wave_generation {
  TCC_WAVE_GENERATION_NORMAL_FREQ = 0,
  TCC_WAVE_GENERATION_MATCH_FREQ = 1,
  TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM = 2,
  TCC_WAVE_GENERATION_DOUBLE_SLOPE_CRITICAL = 4,
  TCC_WAVE_GENERATION_DOUBLE_SLOPE_BOTTOM = 5,
  TCC_WAVE_GENERATION_DOUBLE_SLOPE_BOTH = 6,
  TCC_WAVE_GENERATION_DOUBLE_SLOPE_TOP = 7
}
 TCC wave generation mode enum. More...
 
enum  tcc_wave_output { TCC_WAVE_OUTPUT_n = n }
 Index of the wave outputs. More...
 
enum  tcc_wave_polarity {
  TCC_WAVE_POLARITY_0,
  TCC_WAVE_POLARITY_1
}
 Polarity of TCC wave generation on channels. 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(), sw_timer_init(), 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 run_callback_test(), 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 eic_callback_to_clear_halt(), run_faultx_test(), 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 run_faultx_test(), and 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 eic_callback_to_clear_halt(), run_faultn_test(), 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 run_faultn_test(), and 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 for the possible callback types for the TCC module.

Enumerator
TCC_CALLBACK_OVERFLOW 

Callback for TCC overflow.

TCC_CALLBACK_RETRIGGER 

Callback for TCC Retrigger.

TCC_CALLBACK_COUNTER_EVENT 

Callback for TCC counter event.

TCC_CALLBACK_ERROR 

Callback for capture overflow error.

TCC_CALLBACK_FAULTA 

Callback for Recoverable Fault A.

TCC_CALLBACK_FAULTB 

Callback for Recoverable Fault B.

TCC_CALLBACK_FAULT0 

Callback for Non-Recoverable Fault 0.

TCC_CALLBACK_FAULT1 

Callback for Non-Recoverable Fault 1.

TCC_CALLBACK_CHANNEL_n 

Channel callback type table for TCC.

Each TCC module may contain several callback types for channels; each channel will have its own callback type in the table, with the channel index number substituted for "n" in the channel callback type (e.g. TCC_MATCH_CAPTURE_CHANNEL_0).

TCC channel operation modes.

To set a timer channel either in compare or in capture mode.

Enumerator
TCC_CHANNEL_FUNCTION_COMPARE 

TCC channel performs compare operation.

TCC_CHANNEL_FUNCTION_CAPTURE 

TCC channel performs capture operation.

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.

Enumerator
TCC_CLOCK_PRESCALER_DIV1 

Divide clock by 1.

TCC_CLOCK_PRESCALER_DIV2 

Divide clock by 2.

TCC_CLOCK_PRESCALER_DIV4 

Divide clock by 4.

TCC_CLOCK_PRESCALER_DIV8 

Divide clock by 8.

TCC_CLOCK_PRESCALER_DIV16 

Divide clock by 16.

TCC_CLOCK_PRESCALER_DIV64 

Divide clock by 64.

TCC_CLOCK_PRESCALER_DIV256 

Divide clock by 256.

TCC_CLOCK_PRESCALER_DIV1024 

Divide clock by 1024.

TCC module count direction.

Used when selecting the Timer/Counter count direction.

Enumerator
TCC_COUNT_DIRECTION_UP 

Timer should count upward.

TCC_COUNT_DIRECTION_DOWN 

Timer should count downward.

TCC module counter overflow DMA request mode.

Used when selecting the Timer/Counter overflow DMA request mode.

Enumerator
TCC_COUNT_OVERFLOW_DMA_TRIGGER_MODE_CONTINUE 

TCC generates a DMA request on each cycle when an update condition is detected.

TCC_COUNT_OVERFLOW_DMA_TRIGGER_MODE_ONE_SHOT 

When an update condition is detected, the TCC generates a DMA trigger on the cycle following the DMA One-Shot Command written to the Control B register.

Action to be performed when the TCC module is triggered by event0.

Event action to perform when the module is triggered by event0.

Enumerator
TCC_EVENT0_ACTION_OFF 

No event action.

TCC_EVENT0_ACTION_RETRIGGER 

Re-trigger Counter on event.

TCC_EVENT0_ACTION_COUNT_EVENT 

Count events (increment or decrement, depending on count direction)

TCC_EVENT0_ACTION_START 

Start counter on event.

TCC_EVENT0_ACTION_INCREMENT 

Increment counter on event.

TCC_EVENT0_ACTION_COUNT_DURING_ACTIVE 

Count during active state of asynchronous event.

TCC_EVENT0_ACTION_NON_RECOVERABLE_FAULT 

Generate Non-Recoverable Fault on event.

Action to perform when the TCC module is triggered by event1.

Event action to perform when the module is triggered by event1.

Enumerator
TCC_EVENT1_ACTION_OFF 

No event action.

TCC_EVENT1_ACTION_RETRIGGER 

Re-trigger Counter on event.

TCC_EVENT1_ACTION_DIR_CONTROL 

The event source must be an asynchronous event, and the input value will override the direction settings.

If TCEINVx is 0 and input event is LOW: counter will count up. If TCEINVx is 0 and input event is HIGH: counter will count down.

TCC_EVENT1_ACTION_STOP 

Stop counter on event.

TCC_EVENT1_ACTION_DECREMENT 

Decrement on event.

TCC_EVENT1_ACTION_PERIOD_PULSE_WIDTH_CAPTURE 

Store period in capture register 0, pulse width in capture register 1.

TCC_EVENT1_ACTION_PULSE_WIDTH_PERIOD_CAPTURE 

Store pulse width in capture register 0, period in capture register 1.

TCC_EVENT1_ACTION_NON_RECOVERABLE_FAULT 

Generate Non-Recoverable Fault on event.

Action to perform when the TCC module is triggered by events.

Event action to perform when the module is triggered by events.

Enumerator
TCC_EVENT_ACTION_OFF 

No event action.

TCC_EVENT_ACTION_STOP 

Stop counting, the counter will maintain its current value, waveforms are set to a defined Non-Recoverable State output (tcc_non_recoverable_state_output).

TCC_EVENT_ACTION_RETRIGGER 

Re-trigger counter on event, may generate an event if the re-trigger event output is enabled.

Note
When re-trigger event action is enabled, enabling the counter will not start until the next incoming event appears.
TCC_EVENT_ACTION_START 

Start counter when previously stopped.

Start counting on the event rising edge. Further events will not restart the counter; the counter keeps on counting using prescaled GCLK_TCCx, until it reaches TOP or Zero depending on the direction.

TCC_EVENT_ACTION_COUNT_EVENT 

Count events; i.e.

Increment or decrement depending on count direction.

TCC_EVENT_ACTION_DIR_CONTROL 

The event source must be an asynchronous event, input value will overrides the direction settings (input low: counting up, input high: counting down).

TCC_EVENT_ACTION_INCREMENT 

Increment the counter on event, irrespective of count direction.

TCC_EVENT_ACTION_DECREMENT 

Decrement the counter on event, irrespective of count direction.

TCC_EVENT_ACTION_COUNT_DURING_ACTIVE 

Count during active state of asynchronous event.

In this case, depending on the count direction, the count will be incremented or decremented on each prescaled GCLK_TCCx, as long as the input event remains active.

TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE 

Store period in capture register 0, pulse width in capture register 1.

TCC_EVENT_ACTION_PULSE_WIDTH_PERIOD_CAPTURE 

Store pulse width in capture register 0, period in capture register 1.

TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT 

Generate Non-Recoverable Fault on event.

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.

Enumerator
TCC_EVENT_GENERATION_SELECTION_START 

Counter Event is generated when a new counter cycle starts.

TCC_EVENT_GENERATION_SELECTION_END 

Counter Event is generated when a counter cycle ends.

TCC_EVENT_GENERATION_SELECTION_BETWEEN 

Counter Event is generated when a counter cycle ends, except for the first and last cycles.

TCC_EVENT_GENERATION_SELECTION_BOUNDARY 

Counter Event is generated when a new counter cycle starts or ends.

TCC (recoverable) fault Input Blanking Start Point.

Enumerator
TCC_FAULT_BLANKING_DISABLE 

No blanking.

TCC_FAULT_BLANKING_RISING_EDGE 

Blanking applied from rising edge of the output waveform.

TCC_FAULT_BLANKING_FALLING_EDGE 

Blanking applied from falling edge of the output waveform.

TCC_FAULT_BLANKING_BOTH_EDGE 

Blanking applied from each toggle of the output waveform.

TCC (recoverable) fault Capture action.

Enumerator
TCC_FAULT_CAPTURE_DISABLE 

Capture disabled.

TCC_FAULT_CAPTURE_EACH 

Capture on Fault, each value is captured.

TCC_FAULT_CAPTURE_MINIMUM 

Capture the minimum detection, but notify on smaller ones.

TCC_FAULT_CAPTURE_MAXIMUM 

Capture the maximum detection, but notify on bigger ones.

TCC_FAULT_CAPTURE_SMALLER 

Capture if the value is smaller than last, notify event or interrupt if previous stamp is confirmed to be "local minimum" (not bigger than current stamp).

TCC_FAULT_CAPTURE_BIGGER 

Capture if the value is bigger than last, notify event or interrupt if previous stamp is confirmed to be "local maximum" (not smaller than current stamp).

TCC_FAULT_CAPTURE_CHANGE 

Capture if the time stamps changes its increment direction.

Capture Channel triggered by TCC (recoverable) fault.

Enumerator
TCC_FAULT_CAPTURE_CHANNEL_0 

Recoverable fault triggers channel 0 capture operation.

TCC_FAULT_CAPTURE_CHANNEL_1 

Recoverable fault triggers channel 1 capture operation.

TCC_FAULT_CAPTURE_CHANNEL_2 

Recoverable fault triggers channel 2 capture operation.

TCC_FAULT_CAPTURE_CHANNEL_3 

Recoverable fault triggers channel 3 capture operation.

TCC (recoverable) fault Halt action.

Enumerator
TCC_FAULT_HALT_ACTION_DISABLE 

Halt action disabled.

TCC_FAULT_HALT_ACTION_HW_HALT 

Hardware halt action, counter is halted until restart.

TCC_FAULT_HALT_ACTION_SW_HALT 

Software halt action, counter is halted until fault bit cleared.

TCC_FAULT_HALT_ACTION_NON_RECOVERABLE 

Non-Recoverable fault, force output to pre-defined level.

TCC (recoverable) fault Output Keep Action.

Enumerator
TCC_FAULT_KEEP_DISABLE 

Disable keeping, wave output released as soon as fault is released.

TCC_FAULT_KEEP_TILL_END 

Keep wave output until end of TCC cycle.

TCC (recoverable) fault Input Qualification Action.

Enumerator
TCC_FAULT_QUALIFICATION_DISABLE 

The input is not disabled on compare condition.

TCC_FAULT_QUALIFICATION_BY_OUTPUT 

The input is disabled when match output signal is at inactive level.

TCC (recoverable) fault Restart Action.

Enumerator
TCC_FAULT_RESTART_DISABLE 

Restart Action disabled.

TCC_FAULT_RESTART_ENABLE 

Restart Action enabled.

TCC (recoverable) fault Input Source.

Enumerator
TCC_FAULT_SOURCE_DISABLE 

Fault input is disabled.

TCC_FAULT_SOURCE_ENABLE 

Match Capture Event x (x=0,1) input.

TCC_FAULT_SOURCE_INVERT 

Inverted MCEx (x=0,1) event input.

TCC_FAULT_SOURCE_ALTFAULT 

Alternate fault (A or B) state at the end of the previous period.

TCC Non-recoverable State Outupt.

Enumerator
TCC_FAULT_STATE_OUTPUT_OFF 

Non-recoverable fault output is tri-stated.

TCC_FAULT_STATE_OUTPUT_0 

Non-recoverable fault force output 0.

TCC_FAULT_STATE_OUTPUT_1 

Non-recoverable fault force output 1.

Index of the match capture channels.

This enum is used to specify which capture/match channel to do operations on.

Enumerator
TCC_MATCH_CAPTURE_CHANNEL_n 

Match capture channel index table for TCC.

Each TCC module may contain several match capture channels; each channel will have its own index in the table, with the index number substituted for "n" in the index name (e.g. TCC_MATCH_CAPTURE_CHANNEL_0).

TCC output inversion.

Used when enabling or disabling output inversion.

Enumerator
TCC_OUTPUT_INVERTION_DISABLE 

Output inversion not to be enabled.

TCC_OUTPUT_INVERTION_ENABLE 

Invert the output from WO[x].

TCC pattern generator for outputs.

Used when disabling output pattern or when selecting a specific pattern.

Enumerator
TCC_OUTPUT_PATTERN_DISABLE 

SWAP output pattern is not used.

TCC_OUTPUT_PATTERN_0 

Pattern 0 is applied to SWAP output.

TCC_OUTPUT_PATTERN_1 

Pattern 1 is applied to SWAP output.

enum tcc_ramp

Ramp Operations which are supported in single-slope PWM generation.

Ramp operations which are supported in single-slope PWM generation.

Enumerator
TCC_RAMP_RAMP1 

Default timer/counter PWM operation.

TCC_RAMP_RAMP2A 

Uses a single channel (CC0) to control both CC0/CC1 compare outputs.

In cycle A, the channel 0 output is disabled, and in cycle B, the channel 1 output is disabled.

TCC_RAMP_RAMP2 

Uses channels CC0 and CC1 to control compare outputs.

In cycle A, the channel 0 output is disabled, and in cycle B, the channel 1 output is disabled.

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.

Enumerator
TCC_RAMP_INDEX_DEFAULT 

Default, cycle index toggles.

TCC_RAMP_INDEX_FORCE_B 

Force next cycle to be cycle B (set to 1)

TCC_RAMP_INDEX_FORCE_A 

Force next cycle to be cycle A (clear to 0)

TCC_RAMP_INDEX_FORCE_KEEP 

Force next cycle keeping the same as current.

TCC Counter reload action enum.

This enum specify how the counter is reloaded and whether the prescaler should be restarted.

Enumerator
TCC_RELOAD_ACTION_GCLK 

The counter is reloaded/reset on the next GCLK and starts counting on the prescaler clock.

TCC_RELOAD_ACTION_PRESC 

The counter is reloaded/reset on the next prescaler clock.

TCC_RELOAD_ACTION_RESYNC 

The counter is reloaded/reset on the next GCLK, and the prescaler is restarted as well.

TCC wave generation mode enum.

This enum is used to specify the waveform generation mode.

Enumerator
TCC_WAVE_GENERATION_NORMAL_FREQ 

Normal Frequency: Top is the PER register, output toggled on each compare match.

TCC_WAVE_GENERATION_MATCH_FREQ 

Match Frequency: Top is CC0 register, output toggles on each update condition.

TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM 

Single-Slope PWM: Top is the PER register, CCx controls duty cycle (output active when count is greater than CCx)

TCC_WAVE_GENERATION_DOUBLE_SLOPE_CRITICAL 

Double-slope (count up and down), non centre-aligned: Top is the PER register, CC[x] controls duty cycle while counting up and CC[x+N/2] controls it while counting down.

TCC_WAVE_GENERATION_DOUBLE_SLOPE_BOTTOM 

Double-slope (count up and down), interrupt/event at Bottom (Top is the PER register, output active when count is greater than CCx)

TCC_WAVE_GENERATION_DOUBLE_SLOPE_BOTH 

Double-slope (count up and down), interrupt/event at Bottom and Top: (Top is the PER register, output active when count is lower than CCx)

TCC_WAVE_GENERATION_DOUBLE_SLOPE_TOP 

Double-slope (count up and down), interrupt/event at Top (Top is the PER register, output active when count is greater than CCx)

Index of the wave outputs.

This enum is used to specify which wave output to do operations on.

Enumerator
TCC_WAVE_OUTPUT_n 

Waveform output index table for TCC.

Each TCC module may contain several wave outputs; each output will have its own index in the table, with the index number substituted for "n" in the index name (e.g. TCC_WAVE_OUTPUT_0).

Polarity of TCC wave generation on channels.

Specifies whether the wave output needs to be inverted or not.

Enumerator
TCC_WAVE_POLARITY_0 

Wave output is not inverted.

TCC_WAVE_POLARITY_1 

Wave output is inverted.

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.

Parameters
[in]module_instPointer to the TCC software instance struct
[in]status_flagsBitmask of TCC_STATUS_* flags to clear

References Assert, tcc_module::hw, i, 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.

Referenced by eic_callback_to_clear_halt(), run_callback_test(), run_faultn_test(), and run_faultx_test().

static void tcc_disable ( const struct tcc_module *const  module_inst)
inlinestatic

Disables the TCC module.

Disables a TCC module and stops the counter.

Parameters
[in]module_instPointer to the software module instance struct

References Assert, and tcc_module::hw.

Referenced by nm_bsp_stop_configurable_timer(), run_callback_test(), sw_timer_disable(), and 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.

Parameters
[in]module_instPointer to the TCC software instance struct
[in]channel_indexIndex of the compare channel to set up to
Return values
STATUS_OKThe module was initialized successfully
STATUS_INVALID_ARGAn invalid channel index is supplied

References _tcc_cc_nums, _tcc_get_inst_index(), Assert, tcc_module::hw, STATUS_ERR_INVALID_ARG, and STATUS_OK.

static void tcc_disable_circular_buffer_top ( struct tcc_module *const  module_inst)
inlinestatic

Disable Circular option for double buffered Top/Period Values.

Stop circularing the double buffered top/period values.

Parameters
[in]module_instPointer to the TCC software instance struct

References Assert, and tcc_module::hw.

static void tcc_disable_double_buffering ( struct tcc_module *const  module_inst)
inlinestatic

Disable TCC double buffering Write.

When double buffering write is disabled, following function will write values to effective registers (not buffered):

Note
This function does not lock double buffer update, which means on next UPDATE condition the last written buffered values will be committed to take effect. Invoke tcc_lock_double_buffer_update() before this function to disable double buffering update, if this change is not expected.
Parameters
[in]module_instPointer 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.

Note
Events cannot be altered while the module is enabled.
Parameters
[in]module_instPointer to the software module instance struct
[in]eventsStruct 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.

static void tcc_dma_trigger_command ( const struct tcc_module *const  module_inst)
inlinestatic

TCC DMA Trigger.

TCC DMA trigger command.

Parameters
[in]module_instPointer to the software module instance struct

References Assert, and tcc_module::hw.

static void tcc_enable ( const struct tcc_module *const  module_inst)
inlinestatic

Enable the TCC module.

Enables a TCC module that has been previously initialized. The counter will start when the counter is enabled.

Note
When the counter is configured to re-trigger on an event, the counter will not start until the next incoming event appears. Then it restarts on any following event.
Parameters
[in]module_instPointer to the software module instance struct

References Assert, and tcc_module::hw.

Referenced by configurable_timer_init(), configure_tcc(), configure_tcc_ramp2a_mode(), configure_tcc_ramp2c_mode(), configure_timer(), run_basic_functionality_test(), run_callback_test(), run_capture_and_compare_test(), run_faultn_test(), run_faultx_test(), run_reset_test(), sw_timer_enable(), and timer0_init().

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.

Parameters
[in]module_instPointer to the TCC software instance struct
[in]channel_indexIndex of the compare channel to set up to
Return values
STATUS_OKThe module was initialized successfully
STATUS_INVALID_ARGAn invalid channel index is supplied

References _tcc_cc_nums, _tcc_get_inst_index(), Assert, tcc_module::hw, STATUS_ERR_INVALID_ARG, and STATUS_OK.

Referenced by configure_tcc(), and configure_tcc_ramp2a_mode().

static void tcc_enable_circular_buffer_top ( struct tcc_module *const  module_inst)
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.

Parameters
[in]module_instPointer to the TCC software instance struct

References Assert, and tcc_module::hw.

Referenced by configure_tcc_ramp2a_mode().

static void tcc_enable_double_buffering ( struct tcc_module *const  module_inst)
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.

Parameters
[in]module_instPointer 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.

Note
Events cannot be altered while the module is enabled.
Parameters
[in]module_instPointer to the software module instance struct
[in]eventsStruct containing flags of events to enable or configure
Returns
Status of the events setup procedure.
Return values
STATUS_OKThe module was initialized successfully
STATUS_INVALID_ARGAn 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.

Referenced by configure_tcc(), configure_tcc_ramp2c_mode(), run_capture_and_compare_test(), run_faultn_test(), and run_faultx_test().

static void tcc_force_double_buffer_update ( struct tcc_module *const  module_inst)
inlinestatic

Force the TCC double buffered registers to update once.

Parameters
[in]module_instPointer 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.

Parameters
[in]module_instPointer to the software module instance struct
[in]channel_indexIndex of the Compare Capture channel to read
Returns
Capture value stored in the specified timer channel.

References _tcc_cc_nums, _tcc_get_inst_index(), Assert, and tcc_module::hw.

Referenced by run_capture_and_compare_test().

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:

  • Don't run in standby
  • When setting top, compare, or pattern by API, do double buffering write
  • The base timer/counter configurations:
    • GCLK generator 0 clock source
    • No prescaler
    • GCLK reload action
    • Count upward
    • Don't perform one-shot operations
    • Counter starts on 0
    • Period/top value set to maximum
  • The match/capture configurations:
    • All Capture compare channel value set to 0
    • No capture enabled (all channels use compare function)
    • Normal frequency wave generation
    • Waveform generation polarity set to 0
    • Don't perform ramp on waveform
  • The waveform extension configurations:
    • No recoverable fault is enabled, fault actions are disabled, filter is set to 0
    • No non-recoverable fault state output is enabled and filter is 0
    • No inversion of waveform output
  • No channel output enabled
  • No PWM pin output enabled
  • Pin and MUX configuration not set
Parameters
[out]configPointer to a TCC module configuration structure to set
[in]hwPointer 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.

Referenced by configurable_timer_init(), configure_tcc(), configure_tcc_ramp2a_mode(), configure_tcc_ramp2c_mode(), configure_timer(), run_basic_functionality_test(), run_callback_test(), run_capture_and_compare_test(), run_faultn_test(), run_faultx_test(), run_init_test(), run_reset_test(), sw_timer_init(), and timer0_init().

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.

Parameters
[in]module_instPointer to the software module instance struct
Returns
Count value of the specified TCC module.

References Assert, and tcc_module::hw.

Referenced by run_basic_functionality_test(), run_faultn_test(), and run_faultx_test().

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.

Parameters
[in]module_instPointer to the TCC software instance struct
Returns
Bitmask of TCC_STATUS_* flags.
Return values
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_READYNone of register is syncing
TCC_STATUS_CAPTURE_OVERFLOWTimer capture data has overflowed
TCC_STATUS_COUNTER_EVENTTimer counter event has occurred
TCC_STATUS_COUNT_OVERFLOWTimer count value has overflowed
TCC_STATUS_COUNTER_RETRIGGEREDTimer counter has been retriggered
TCC_STATUS_STOPTimer counter has been stopped
TCC_STATUS_RAMP_CYCLE_INDEXWave ramp index for cycle

References Assert, tcc_module::hw, i, status, 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.

Referenced by run_callback_test(), run_faultn_test(), and run_faultx_test().

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.

Parameters
[in,out]module_instPointer to the software module instance struct
[in]hwPointer to the TCC hardware module
[in]configPointer to the TCC configuration options struct
Returns
Status of the initialization procedure.
Return values
STATUS_OKThe module was initialized successfully
STATUS_BUSYThe hardware module was busy when the initialization procedure was attempted
STATUS_INVALID_ARGAn invalid configuration option or argument was supplied
STATUS_ERR_DENIEDThe 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, i, tcc_match_wave_config::match, module_inst, 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, 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.

Referenced by configurable_timer_init(), configure_tcc(), configure_tcc_ramp2a_mode(), configure_tcc_ramp2c_mode(), configure_timer(), run_basic_functionality_test(), run_callback_test(), run_capture_and_compare_test(), run_faultn_test(), run_faultx_test(), run_init_test(), run_reset_test(), sw_timer_init(), and timer0_init().

static bool tcc_is_running ( struct tcc_module *const  module_inst)
inlinestatic

Checks if the timer/counter is running.

Parameters
[in]module_instPointer to the TCC software instance struct
Returns
Status which indicates whether the module is running.
Return values
trueThe timer/counter is running
falseThe timer/counter is stopped

References Assert, and tcc_module::hw.

static bool tcc_is_syncing ( const struct tcc_module *const  module_inst)
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.

Parameters
[in]module_instPointer to the software module instance struct
Returns
Synchronization status of the underlying hardware module.
Return values
falseIf the module has completed synchronization
trueIf the module synchronization is ongoing

References Assert, and tcc_module::hw.

Referenced by run_reset_test(), and tcc_reset().

static void tcc_lock_double_buffer_update ( struct tcc_module *const  module_inst)
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.

Parameters
[in]module_instPointer to the TCC software instance struct

References Assert, and tcc_module::hw.

static void tcc_reset ( const struct tcc_module *const  module_inst)
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.

Note
When resetting a 32-bit counter only the master TCC module's instance structure should be passed to the function.
Parameters
[in]module_instPointer to the software module instance struct

References Assert, tcc_module::hw, tcc_disable(), and tcc_is_syncing().

Referenced by main(), run_basic_functionality_test(), run_callback_test(), run_capture_and_compare_test(), run_faultn_test(), run_faultx_test(), and run_reset_test().

static void tcc_restart_counter ( const struct tcc_module *const  module_inst)
inlinestatic

Starts the counter from beginning.

Restarts an initialized TCC module's counter.

Parameters
[in]module_instPointer to the software module instance struct

References Assert, and tcc_module::hw.

Referenced by run_basic_functionality_test().

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.

Parameters
[in]module_instPointer to the software module instance struct
[in]channel_indexIndex of the compare channel to write to
[in]compareNew compare value to set
Returns
Status of the compare update procedure.
Return values
STATUS_OKThe compare value was updated successfully
STATUS_ERR_INVALID_ARGAn invalid channel index was supplied or compare value exceed resolution

References _tcc_set_compare_value(), Assert, and tcc_module::double_buffering_enabled.

Referenced by configure_tcc(), and tcc_callback_to_change_duty_cycle().

static void tcc_set_count_direction ( const struct tcc_module *const  module_inst,
enum tcc_count_direction  dir 
)
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.

Parameters
[in]module_instPointer to the software module instance struct
[in]dirNew 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.

Parameters
[in]module_instPointer to the software module instance struct
[in]countNew timer count value to set
Returns
Status which indicates whether the new value is set.
Return values
STATUS_OKThe timer count was updated successfully
STATUS_ERR_INVALID_ARGAn invalid timer counter size was specified

References _tcc_get_inst_index(), _tcc_maxs, Assert, count, tcc_module::hw, STATUS_ERR_INVALID_ARG, and STATUS_OK.

Referenced by run_basic_functionality_test(), and run_callback_test().

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).

Parameters
[in]module_instPointer to the software module instance struct
[in]channel_indexIndex of the compare channel to write to
[in]compareNew compare value to set
[in]compare_bufferNew compare buffer value to set
Returns
Status of the compare update procedure.
Return values
STATUS_OKThe compare value was updated successfully
STATUS_ERR_INVALID_ARGAn invalid channel index was supplied or compare value exceed resolution

References _tcc_set_compare_value(), Assert, status, and STATUS_OK.

Referenced by configure_tcc_ramp2a_mode().

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.

Parameters
[in]module_instPointer to the software module instance struct
[in]top_valueNew value to be loaded into the PER register
[in]top_buffer_valueNew value to be loaded into the PERB register
Returns
Status of the TOP set procedure.
Return values
STATUS_OKThe timer TOP value was updated successfully
STATUS_ERR_INVALID_ARGAn invalid channel index was supplied or top/period value exceed resolution

References _tcc_set_top_value(), Assert, status, and STATUS_OK.

Referenced by configure_tcc_ramp2a_mode().

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.

Parameters
[in]module_instPointer to the software module instance struct
[in]line_indexOutput line index
[in]patternOutput pattern to use (tcc_output_pattern)
Returns
Status of the pattern set procedure.
Return values
STATUS_OKThe PATT register is updated successfully
STATUS_ERR_INVALID_ARGAn 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.

static void tcc_set_ramp_index ( const struct tcc_module *const  module_inst,
const enum tcc_ramp_index  ramp_index 
)
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.

Parameters
[in]module_instPointer to the software module instance struct
[in]ramp_indexRamp 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.

Parameters
[in]module_instPointer to the software module instance struct
[in]top_valueNew value to be loaded into the PER/PERB register
Returns
Status of the TOP set procedure.
Return values
STATUS_OKThe timer TOP value was updated successfully
STATUS_ERR_INVALID_ARGAn invalid channel index was supplied or top/period value exceed resolution

References _tcc_set_top_value(), Assert, and tcc_module::double_buffering_enabled.

static void tcc_stop_counter ( const struct tcc_module *const  module_inst)
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.

Parameters
[in]module_instPointer to the software module instance struct

References Assert, and tcc_module::hw.

Referenced by run_basic_functionality_test().

static void tcc_toggle_count_direction ( const struct tcc_module *const  module_inst)
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.

Parameters
[in]module_instPointer to the software module instance struct

References Assert, and tcc_module::hw.

static void tcc_unlock_double_buffer_update ( struct tcc_module *const  module_inst)
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.

Parameters
[in]module_instPointer to the TCC software instance struct

References Assert, and tcc_module::hw.