SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
SAM3/4S/4L/4E/4N/4CM/4C/G Timer Counter (TC) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Timer Counter functionality. More...

Functions

void tc_disable_interrupt (Tc *p_tc, uint32_t ul_channel, uint32_t ul_sources)
 Disable TC interrupts on the specified channel.
void tc_disable_qdec_interrupt (Tc *p_tc, uint32_t ul_sources)
 Disable TC QDEC interrupts.
void tc_enable_interrupt (Tc *p_tc, uint32_t ul_channel, uint32_t ul_sources)
 Enable the TC interrupts on the specified channel.
void tc_enable_qdec_interrupt (Tc *p_tc, uint32_t ul_sources)
 Enable TC QDEC interrupts.
uint32_t tc_find_mck_divisor (uint32_t ul_freq, uint32_t ul_mck, uint32_t *p_uldiv, uint32_t *ul_tcclks, uint32_t ul_boardmck)
 Find the best PBA/MCK divisor.
uint32_t tc_get_feature (Tc *p_tc)
 Indicate TC features.
uint32_t tc_get_interrupt_mask (Tc *p_tc, uint32_t ul_channel)
 Read the TC interrupt mask for the specified channel.
uint32_t tc_get_qdec_interrupt_mask (Tc *p_tc)
 Read TC QDEC interrupt mask.
uint32_t tc_get_qdec_interrupt_status (Tc *p_tc)
 Get current TC QDEC interrupt status.
uint32_t tc_get_status (Tc *p_tc, uint32_t ul_channel)
 Get the current status for the specified TC channel.
uint32_t tc_get_version (Tc *p_tc)
 Indicate TC version.
void tc_init (Tc *p_tc, uint32_t ul_Channel, uint32_t ul_Mode)
 Configure TC for timer, waveform generation, or capture.
uint32_t tc_init_2bit_gray (Tc *p_tc, uint32_t ul_channel, uint32_t ul_steppermode)
 Configure TC for 2-bit Gray Counter for Stepper Motor.
uint32_t tc_read_cv (Tc *p_tc, uint32_t ul_channel)
 Read the counter value on the specified channel.
uint32_t tc_read_ra (Tc *p_tc, uint32_t ul_channel)
 Read TC Register A (RA) on the specified channel.
uint32_t tc_read_rb (Tc *p_tc, uint32_t ul_channel)
 Read TC Register B (RB) on the specified channel.
uint32_t tc_read_rc (Tc *p_tc, uint32_t ul_channel)
 Read TC Register C (RC) on the specified channel.
void tc_set_block_mode (Tc *p_tc, uint32_t ul_blockmode)
 Configure the TC Block mode.
void tc_set_writeprotect (Tc *p_tc, uint32_t ul_enable)
 Enable or disable write protection of TC registers.
void tc_start (Tc *p_tc, uint32_t ul_channel)
 Start the TC clock on the specified channel.
void tc_stop (Tc *p_tc, uint32_t ul_channel)
 Stop the TC clock on the specified channel.
void tc_sync_trigger (Tc *p_tc)
 Asserts a SYNC signal to generate a software trigger on all channels.
void tc_write_ra (Tc *p_tc, uint32_t ul_channel, uint32_t ul_value)
 Write to TC Register A (RA) on the specified channel.
void tc_write_rb (Tc *p_tc, uint32_t ul_channel, uint32_t ul_value)
 Write to TC Register B (RB) on the specified channel.
void tc_write_rc (Tc *p_tc, uint32_t ul_channel, uint32_t ul_value)
 Write to TC Register C (RC) on the selected channel.

Detailed Description

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Timer Counter functionality.

The Timer Counter (TC) includes several identical 16-bit or 32-bit Timer Counter channels. Each channel can be independently programmed to perform a wide range of functions that includes frequency measurement, event counting, interval measurement, pulse generation, delay timing, and pulse width modulation.

Devices from the following series can use this module:

  • Atmel | SMART SAM3
  • Atmel | SMART SAM4S
  • Atmel | SMART SAM4L
  • Atmel | SMART SAM4E
  • Atmel | SMART SAM4N
  • Atmel | SMART SAM4CM
  • Atmel | SMART SAM4C
  • Atmel | SMART SAMG

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

The Timer Counter (TC) includes several identical 16-bit or 32-bit Timer Counter channels. The number of TC channels is device specific, refer to the device-specific datasheet for more information.

Each channel can be independently programmed to perform a wide range of functions that includes frequency measurement, event counting, interval measurement, pulse generation, delay timing, and pulse width modulation.

Each channel has three external clock inputs, five internal clock inputs, and two multi-purpose input/output signals which can be configured by the user. Each channel drives an internal interrupt signal which can be programmed to generate processor interrupts.

The Timer Counter (TC) embeds a quadrature decoder logic connected in front of the timers. When enabled, the quadrature decoder performs the input line filtering, decoding of quadrature signals and connects to the timers/counters in order to read the position and speed of the motor.

Special Considerations

External Clock

In all cases, if an external clock is used, the duration of each of its levels must be longer than the master clock (MCLK) period. The external clock frequency must be at least 2.5 times lower than the master clock.

External Trigger

If an external trigger is used, the duration of its pulses must be longer than the master clock (MCLK) period in order to be detected.

Extra Information

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

Examples

For a list of examples related to this driver, see Examples for Timer Counter.

API Overview

Function Documentation

◆ tc_disable_interrupt()

void tc_disable_interrupt ( Tc * p_tc,
uint32_t ul_channel,
uint32_t ul_sources )

Disable TC interrupts on the specified channel.

Parameters
[in,out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to configure
[in]ul_sourcesA bitmask of Interrupt sources

Where the input parameter ul_sources can be one or more of the following:

Parameter ValueDescription
TC_IDR_COVFSDisables the Counter Overflow Interrupt
TC_IDR_LOVRSDisables the Load Overrun Interrupt
TC_IDR_CPASDisables the RA Compare Interrupt
TC_IDR_CPBSDisables the RB Compare Interrupt
TC_IDR_CPCSDisables the RC Compare Interrupt
TC_IDR_LDRASDisables the RA Load Interrupt
TC_IDR_LDRBSDisables the RB Load Interrupt
TC_IDR_ETRGSDisables the External Trigger Interrupt

Definition at line 400 of file tc.c.

404{
405 TcChannel *tc_channel;
406
407 /* Validate inputs. */
408 Assert(p_tc);
409 Assert(ul_channel <
410 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
411 tc_channel = p_tc->TC_CHANNEL + ul_channel;
412 tc_channel->TC_IDR = ul_sources;
413}
TcChannel hardware registers.
__O uint32_t TC_IDR
(TcChannel Offset: 0x28) Interrupt Disable Register
TcChannel TC_CHANNEL[TCCHANNEL_NUMBER]
(Tc Offset: 0x0) channel = 0 .

References Tc::TC_CHANNEL, and TcChannel::TC_IDR.

◆ tc_disable_qdec_interrupt()

void tc_disable_qdec_interrupt ( Tc * p_tc,
uint32_t ul_sources )

Disable TC QDEC interrupts.

Note
This function is not available on SAM4L or SAMG devices.
Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_sourcesA bitmask of QDEC interrupts to be disabled

Where the input parameter ul_sources can be one or more of the following:

Parameter ValueDescription
TC_QIDR_IDXDisable the rising edge detected on IDX input interrupt
TC_QIDR_DIRCHGDisable the change in rotation direction detected interrupt
TC_QIDR_QERRDisable the quadrature error detected on PHA/PHB interrupt

Definition at line 646 of file tc.c.

649{
650 /* Validate inputs. */
651 Assert(p_tc);
652
653 p_tc->TC_QIDR = ul_sources;
654}
__O uint32_t TC_QIDR
(Tc Offset: 0xCC) QDEC Interrupt Disable Register

References Tc::TC_QIDR.

◆ tc_enable_interrupt()

void tc_enable_interrupt ( Tc * p_tc,
uint32_t ul_channel,
uint32_t ul_sources )

Enable the TC interrupts on the specified channel.

Parameters
[in,out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to configure
[in]ul_sourcesBitmask of interrupt sources

Where the input parameter ul_sources can be one or more of the following:

Parameter ValueDescription
TC_IER_COVFSEnables the Counter Overflow Interrupt
TC_IER_LOVRSEnables the Load Overrun Interrupt
TC_IER_CPASEnables the RA Compare Interrupt
TC_IER_CPBSEnables the RB Compare Interrupt
TC_IER_CPCSEnables the RC Compare Interrupt
TC_IER_LDRASEnables the RA Load Interrupt
TC_IER_LDRBSEnables the RB Load Interrupt
TC_IER_ETRGSEnables the External Trigger Interrupt

Definition at line 362 of file tc.c.

366{
367 TcChannel *tc_channel;
368
369 /* Validate inputs. */
370 Assert(p_tc);
371 Assert(ul_channel <
372 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
373 tc_channel = p_tc->TC_CHANNEL + ul_channel;
374 tc_channel->TC_IER = ul_sources;
375}
__O uint32_t TC_IER
(TcChannel Offset: 0x24) Interrupt Enable Register

References Tc::TC_CHANNEL, and TcChannel::TC_IER.

◆ tc_enable_qdec_interrupt()

void tc_enable_qdec_interrupt ( Tc * p_tc,
uint32_t ul_sources )

Enable TC QDEC interrupts.

Note
This function is not available on SAM4L or SAMG devices.
Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_sourcesA bitmask of QDEC interrupts to be enabled

Where the input parameter ul_sources can be one or more of the following:

Parameter ValueDescription
TC_QIER_IDXEnable the rising edge detected on IDX input interrupt
TC_QIER_DIRCHGEnable the change in rotation direction detected interrupt
TC_QIER_QERREnable the quadrature error detected on PHA/PHB interrupt

Definition at line 617 of file tc.c.

620{
621 /* Validate inputs. */
622 Assert(p_tc);
623
624 p_tc->TC_QIER = ul_sources;
625}
__O uint32_t TC_QIER
(Tc Offset: 0xC8) QDEC Interrupt Enable Register

References Tc::TC_QIER.

◆ tc_find_mck_divisor()

uint32_t tc_find_mck_divisor ( uint32_t ul_freq,
uint32_t ul_mck,
uint32_t * p_uldiv,
uint32_t * p_ultcclks,
uint32_t ul_boardmck )

Find the best PBA/MCK divisor.

For SAM4L devices: Finds the best PBA divisor given the timer frequency and PBA clock. The result is guaranteed to satisfy the following equation:

(ul_pbaclk / (2* DIV * 65536)) <= freq <= (ul_pbaclk / (2* DIV))

with DIV being the lowest possible value, to maximize timing adjust resolution.

For non SAM4L devices: Finds the best MCK divisor given the timer frequency and MCK. The result is guaranteed to satisfy the following equation:

(MCK / (DIV * 65536)) <= freq <= (MCK / DIV)

with DIV being the lowest possible value, to maximize timing adjust resolution.

Parameters
[in]ul_freqDesired timer frequency
[in]ul_mckPBA clock frequency
[out]p_uldivDivisor value
[out]p_ultcclksTCCLKS field value for divisor
[in]ul_boardmckBoard clock frequency (set to 0 for SAM4L devices)
Returns
The divisor found status.
Return values
0No suitable divisor was found
1A divisor was found

Definition at line 553 of file tc.c.

559{
560 const uint32_t divisors[5] = { 0, 2, 8, 32, 128};
561 uint32_t ul_index;
562 uint32_t ul_high, ul_low;
563
564 UNUSED(ul_boardmck);
565
566 /* Satisfy frequency bound. */
567 for (ul_index = 1;
568 ul_index < (sizeof(divisors) / sizeof(divisors[0]));
569 ul_index++) {
570 ul_high = ul_mck / divisors[ul_index];
571 ul_low = ul_high / TC_DIV_FACTOR;
572 if (ul_freq > ul_high) {
573 return 0;
574 } else if (ul_freq >= ul_low) {
575 break;
576 }
577 }
578 if (ul_index >= (sizeof(divisors) / sizeof(divisors[0]))) {
579 return 0;
580 }
581
582 /* Store results. */
583 if (p_uldiv) {
584 *p_uldiv = divisors[ul_index];
585 }
586
587 if (p_ultcclks) {
588 *p_ultcclks = ul_index;
589 }
590
591 return 1;
592}
#define TC_DIV_FACTOR
Definition tc.c:461

References TC_DIV_FACTOR.

◆ tc_get_feature()

uint32_t tc_get_feature ( Tc * p_tc)

Indicate TC features.

Note
This function is only available on SAM4L devices.
Parameters
[in]p_tcModule hardware register base address pointer
Returns
The TC FEATURES register contents.

Definition at line 731 of file tc.c.

733{
734 /* Validate inputs. */
735 Assert(p_tc);
736
737 return p_tc->TC_FEATURES;
738}

◆ tc_get_interrupt_mask()

uint32_t tc_get_interrupt_mask ( Tc * p_tc,
uint32_t ul_channel )

Read the TC interrupt mask for the specified channel.

Parameters
[in]p_tcModule hardware register base address pointer
[in]ul_channelChannel to read
Returns
The TC interrupt mask value.

Definition at line 423 of file tc.c.

426{
427 TcChannel *tc_channel;
428
429 /* Validate inputs. */
430 Assert(p_tc);
431 Assert(ul_channel <
432 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
433 tc_channel = p_tc->TC_CHANNEL + ul_channel;
434 return tc_channel->TC_IMR;
435}
__I uint32_t TC_IMR
(TcChannel Offset: 0x2C) Interrupt Mask Register

References Tc::TC_CHANNEL, and TcChannel::TC_IMR.

◆ tc_get_qdec_interrupt_mask()

uint32_t tc_get_qdec_interrupt_mask ( Tc * p_tc)

Read TC QDEC interrupt mask.

Note
This function is not available on SAM4L or SAMG devices.
Parameters
[in]p_tcModule hardware register base address pointer
Returns
The QDEC interrupt mask value.

Definition at line 665 of file tc.c.

667{
668 /* Validate inputs. */
669 Assert(p_tc);
670
671 return p_tc->TC_QIMR;
672}
__I uint32_t TC_QIMR
(Tc Offset: 0xD0) QDEC Interrupt Mask Register

References Tc::TC_QIMR.

◆ tc_get_qdec_interrupt_status()

uint32_t tc_get_qdec_interrupt_status ( Tc * p_tc)

Get current TC QDEC interrupt status.

Note
This function is not available on SAM4L or SAMG devices.
Parameters
[in]p_tcModule hardware register base address pointer
Returns
The TC QDEC interrupt status.

Definition at line 683 of file tc.c.

685{
686 /* Validate inputs. */
687 Assert(p_tc);
688
689 return p_tc->TC_QISR;
690}
__I uint32_t TC_QISR
(Tc Offset: 0xD4) QDEC Interrupt Status Register

References Tc::TC_QISR.

◆ tc_get_status()

uint32_t tc_get_status ( Tc * p_tc,
uint32_t ul_channel )

Get the current status for the specified TC channel.

Parameters
[in]p_tcModule hardware register base address pointer
[in]ul_channelChannel number
Returns
The current TC status.

Definition at line 445 of file tc.c.

448{
449 TcChannel *tc_channel;
450
451 /* Validate inputs. */
452 Assert(p_tc);
453 Assert(ul_channel <
454 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
455
456 tc_channel = p_tc->TC_CHANNEL + ul_channel;
457 return tc_channel->TC_SR;
458}
__I uint32_t TC_SR
(TcChannel Offset: 0x20) Status Register

References Tc::TC_CHANNEL, and TcChannel::TC_SR.

◆ tc_get_version()

uint32_t tc_get_version ( Tc * p_tc)

Indicate TC version.

Note
This function is only available on SAM4L devices.
Parameters
[in]p_tcModule hardware register base address pointer
Returns
The TC VERSION register contents.

Definition at line 749 of file tc.c.

751{
752 /* Validate inputs. */
753 Assert(p_tc);
754
755 return p_tc->TC_VERSION;
756}

◆ tc_init()

void tc_init ( Tc * p_tc,
uint32_t ul_channel,
uint32_t ul_mode )

Configure TC for timer, waveform generation, or capture.

Parameters
[in,out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to configure
[in]ul_modeControl mode register bitmask value to set
Note
For more information regarding ul_mode configuration refer to the section entitled "Channel Mode Register: Capture Mode" and/or section "Waveform Operating Mode" in the device-specific datasheet.
If the TC is configured for waveform generation then the external event selection (EEVT) should only be set to TC_CMR_EEVT_TIOB, or the equivalent value of 0, if it really is the intention to use TIOB as an external event trigger. This is because this setting forces TIOB to be an input, even if the external event trigger has not been enabled with TC_CMR_ENETRG, and thus prevents normal operation of TIOB.

Definition at line 70 of file tc.c.

74{
75 TcChannel *tc_channel;
76
77 /* Validate inputs. */
78 Assert(p_tc);
79 Assert(ul_channel <
80 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
81 tc_channel = p_tc->TC_CHANNEL + ul_channel;
82
83 /* Disable TC clock. */
84 tc_channel->TC_CCR = TC_CCR_CLKDIS;
85
86 /* Disable interrupts. */
87 tc_channel->TC_IDR = 0xFFFFFFFF;
88
89 /* Clear status register. */
90 tc_channel->TC_SR;
91
92 /* Set mode. */
93 tc_channel->TC_CMR = ul_mode;
94}
#define TC_CCR_CLKDIS
(TC_CCR) Counter Clock Disable Command
__O uint32_t TC_CCR
(TcChannel Offset: 0x0) Channel Control Register
__IO uint32_t TC_CMR
(TcChannel Offset: 0x4) Channel Mode Register

References TcChannel::TC_CCR, TC_CCR_CLKDIS, Tc::TC_CHANNEL, TcChannel::TC_CMR, TcChannel::TC_IDR, and TcChannel::TC_SR.

◆ tc_init_2bit_gray()

uint32_t tc_init_2bit_gray ( Tc * p_tc,
uint32_t ul_channel,
uint32_t ul_steppermode )

Configure TC for 2-bit Gray Counter for Stepper Motor.

Note
The function tc_init() must be called prior to this one.
This function is not available on SAM3U devices.
Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to configure
[in]ul_steppermodeStepper motor mode register value to set
Returns
0 for OK.

Definition at line 147 of file tc.c.

151{
152 /* Validate inputs. */
153 Assert(p_tc);
154 Assert(ul_channel <
155 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
156
157 p_tc->TC_CHANNEL[ul_channel].TC_SMMR = ul_steppermode;
158 return 0;
159}
__IO uint32_t TC_SMMR
(TcChannel Offset: 0x8) Stepper Motor Mode Register

References Tc::TC_CHANNEL, and TcChannel::TC_SMMR.

◆ tc_read_cv()

uint32_t tc_read_cv ( Tc * p_tc,
uint32_t ul_channel )

Read the counter value on the specified channel.

Parameters
[in]p_tcModule hardware register base address pointer
[in]ul_channelChannel to read
Returns
The counter value.

Definition at line 207 of file tc.c.

210{
211 /* Validate inputs. */
212 Assert(p_tc);
213 Assert(ul_channel <
214 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
215
216 return p_tc->TC_CHANNEL[ul_channel].TC_CV;
217}
__I uint32_t TC_CV
(TcChannel Offset: 0x10) Counter Value

References Tc::TC_CHANNEL, and TcChannel::TC_CV.

◆ tc_read_ra()

uint32_t tc_read_ra ( Tc * p_tc,
uint32_t ul_channel )

Read TC Register A (RA) on the specified channel.

Parameters
[in]p_tcModule hardware register base address pointer
[in]ul_channelChannel to read
Returns
The TC Register A (RA) value.

Definition at line 227 of file tc.c.

230{
231 /* Validate inputs. */
232 Assert(p_tc);
233 Assert(ul_channel <
234 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
235
236 return p_tc->TC_CHANNEL[ul_channel].TC_RA;
237}
__IO uint32_t TC_RA
(TcChannel Offset: 0x14) Register A

References Tc::TC_CHANNEL, and TcChannel::TC_RA.

◆ tc_read_rb()

uint32_t tc_read_rb ( Tc * p_tc,
uint32_t ul_channel )

Read TC Register B (RB) on the specified channel.

Parameters
[in]p_tcModule hardware register base address pointer
[in]ul_channelChannel to read
Returns
The TC Register B (RB) value.

Definition at line 247 of file tc.c.

250{
251 /* Validate inputs. */
252 Assert(p_tc);
253 Assert(ul_channel <
254 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
255
256 return p_tc->TC_CHANNEL[ul_channel].TC_RB;
257}
__IO uint32_t TC_RB
(TcChannel Offset: 0x18) Register B

References Tc::TC_CHANNEL, and TcChannel::TC_RB.

◆ tc_read_rc()

uint32_t tc_read_rc ( Tc * p_tc,
uint32_t ul_channel )

Read TC Register C (RC) on the specified channel.

Parameters
[in]p_tcModule hardware register base address pointer
[in]ul_channelChannel to read
Returns
The Register C (RC) value.

Definition at line 267 of file tc.c.

270{
271 /* Validate inputs. */
272 Assert(p_tc);
273 Assert(ul_channel <
274 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
275
276 return p_tc->TC_CHANNEL[ul_channel].TC_RC;
277}
__IO uint32_t TC_RC
(TcChannel Offset: 0x1C) Register C

References Tc::TC_CHANNEL, and TcChannel::TC_RC.

◆ tc_set_block_mode()

void tc_set_block_mode ( Tc * p_tc,
uint32_t ul_blockmode )

Configure the TC Block mode.

Note
The function tc_init() must be called prior to this one.
Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_blockmodeBlock mode register value to set
Note
For more information regarding ul_blockmode configuration refer to the section entitled "TC Block Mode Register" in the device-specific datasheet.

Definition at line 123 of file tc.c.

126{
127 /* Validate inputs. */
128 Assert(p_tc);
129
130 p_tc->TC_BMR = ul_blockmode;
131}
__IO uint32_t TC_BMR
(Tc Offset: 0xC4) Block Mode Register

References Tc::TC_BMR.

◆ tc_set_writeprotect()

void tc_set_writeprotect ( Tc * p_tc,
uint32_t ul_enable )

Enable or disable write protection of TC registers.

Note
This function is not available on SAM3U devices.
Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_enable1 to enable, 0 to disable

Definition at line 704 of file tc.c.

707{
708 /* Validate inputs. */
709 Assert(p_tc);
710
711 if (ul_enable) {
713 } else {
715 }
716}
#define TC_WPMR_WPEN
(TC_WPMR) Write Protect Enable
__IO uint32_t TC_WPMR
(Tc Offset: 0xE4) Write Protect Mode Register
#define TC_WPMR_WPKEY_PASSWD
Definition tc.c:49

References Tc::TC_WPMR, TC_WPMR_WPEN, and TC_WPMR_WPKEY_PASSWD.

◆ tc_start()

void tc_start ( Tc * p_tc,
uint32_t ul_channel )

Start the TC clock on the specified channel.

Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to configure

Definition at line 169 of file tc.c.

172{
173 /* Validate inputs. */
174 Assert(p_tc);
175 Assert(ul_channel <
176 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
177
178 p_tc->TC_CHANNEL[ul_channel].TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG;
179}
#define TC_CCR_SWTRG
(TC_CCR) Software Trigger Command
#define TC_CCR_CLKEN
(TC_CCR) Counter Clock Enable Command

References TcChannel::TC_CCR, TC_CCR_CLKEN, TC_CCR_SWTRG, and Tc::TC_CHANNEL.

◆ tc_stop()

void tc_stop ( Tc * p_tc,
uint32_t ul_channel )

Stop the TC clock on the specified channel.

Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to configure

Definition at line 187 of file tc.c.

190{
191 /* Validate inputs. */
192 Assert(p_tc);
193 Assert(ul_channel <
194 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
195
196 p_tc->TC_CHANNEL[ul_channel].TC_CCR = TC_CCR_CLKDIS;
197}

References TcChannel::TC_CCR, TC_CCR_CLKDIS, and Tc::TC_CHANNEL.

◆ tc_sync_trigger()

void tc_sync_trigger ( Tc * p_tc)

Asserts a SYNC signal to generate a software trigger on all channels.

Parameters
[out]p_tcModule hardware register base address pointer

Definition at line 103 of file tc.c.

105{
106 /* Validate inputs. */
107 Assert(p_tc);
108
109 p_tc->TC_BCR = TC_BCR_SYNC;
110}
#define TC_BCR_SYNC
(TC_BCR) Synchro Command
__O uint32_t TC_BCR
(Tc Offset: 0xC0) Block Control Register

References Tc::TC_BCR, and TC_BCR_SYNC.

◆ tc_write_ra()

void tc_write_ra ( Tc * p_tc,
uint32_t ul_channel,
uint32_t ul_value )

Write to TC Register A (RA) on the specified channel.

Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to write
[in]ul_valueValue to write

Definition at line 286 of file tc.c.

290{
291 /* Validate inputs. */
292 Assert(p_tc);
293 Assert(ul_channel <
294 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
295
296 p_tc->TC_CHANNEL[ul_channel].TC_RA = ul_value;
297}

References Tc::TC_CHANNEL, and TcChannel::TC_RA.

◆ tc_write_rb()

void tc_write_rb ( Tc * p_tc,
uint32_t ul_channel,
uint32_t ul_value )

Write to TC Register B (RB) on the specified channel.

Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to write
[in]ul_valueValue to write

Definition at line 306 of file tc.c.

310{
311 /* Validate inputs. */
312 Assert(p_tc);
313 Assert(ul_channel <
314 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
315
316 p_tc->TC_CHANNEL[ul_channel].TC_RB = ul_value;
317}

References Tc::TC_CHANNEL, and TcChannel::TC_RB.

◆ tc_write_rc()

void tc_write_rc ( Tc * p_tc,
uint32_t ul_channel,
uint32_t ul_value )

Write to TC Register C (RC) on the selected channel.

Parameters
[out]p_tcModule hardware register base address pointer
[in]ul_channelChannel to write
[in]ul_valueValue to write

Definition at line 326 of file tc.c.

330{
331 /* Validate inputs. */
332 Assert(p_tc);
333 Assert(ul_channel <
334 (sizeof(p_tc->TC_CHANNEL) / sizeof(p_tc->TC_CHANNEL[0])));
335
336 p_tc->TC_CHANNEL[ul_channel].TC_RC = ul_value;
337}

References Tc::TC_CHANNEL, and TcChannel::TC_RC.