TC_driver.c File Reference


Detailed Description

XMEGA Timer/Counter driver source file.

This file contains the function implementations the XMEGA Timer/Counter driver.

The driver is not intended for size and/or speed critical code, since most functions are just a few lines of code, and the function call overhead would decrease code performance. The driver is intended for rapid prototyping and documentation purposes for getting started with the XMEGA Timer/Counter module.

For size and/or speed critical code, it is recommended to copy the function contents directly into your application instead of making a function call.

Several functions use the following construct: "some_register = ... | (some_parameter ? SOME_BIT_bm : 0) | ..." Although the use of the ternary operator ( if ? then : else ) is discouraged, in some occasions the operator makes it possible to write pretty clean and neat code. In this driver, the construct is used to set or not set a configuration bit based on a boolean input parameter, such as the "some_parameter" in the example above.

Application note:
AVR1306: Using the XMEGA Timer/Counter
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
1569
Date
2008-04-22 13:03:43 +0200 (ti, 22 apr 2008)

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file TC_driver.c.

#include "avr_compiler.h"
#include "TC_driver.h"

Include dependency graph for TC_driver.c:

Go to the source code of this file.

Functions

void TC0_ConfigClockSource (volatile TC0_t *tc, TC_CLKSEL_t clockSelection)
 Configures clock source for the Timer/Counter 0.
void TC0_ConfigInputCapture (volatile TC0_t *tc, TC_EVSEL_t eventSource)
 Configures the Timer/Counter 0 for input capture operation.
void TC0_ConfigWGM (volatile TC0_t *tc, TC_WGMODE_t wgm)
 Configures the Waveform Generation Mode for the Timer/Counter 0.
void TC0_DisableCCChannels (volatile TC0_t *tc, uint8_t disableMask)
 Disables compare/capture channels on Timer/Counter 0.
void TC0_EnableCCChannels (volatile TC0_t *tc, uint8_t enableMask)
 Enables compare/capture channels for Timer/Counter 0.
void TC0_Reset (volatile TC0_t *tc)
 Resets the Timer/Counter 0.
void TC0_SetCCAIntLevel (volatile TC0_t *tc, TC_CCAINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel A interrupt.
void TC0_SetCCBIntLevel (volatile TC0_t *tc, TC_CCBINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel B interrupt.
void TC0_SetCCCIntLevel (volatile TC0_t *tc, TC_CCCINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel C interrupt.
void TC0_SetCCDIntLevel (volatile TC0_t *tc, TC_CCDINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel D interrupt.
void TC0_SetErrorIntLevel (volatile TC0_t *tc, TC_ERRINTLVL_t intLevel)
 Sets the Error interrupt level.
void TC0_SetOverflowIntLevel (volatile TC0_t *tc, TC_OVFINTLVL_t intLevel)
 Sets the overflow interrupt level.
void TC1_ConfigClockSource (volatile TC1_t *tc, TC_CLKSEL_t clockSelection)
 Configures clock source for the Timer/Counter 1.
void TC1_ConfigInputCapture (volatile TC1_t *tc, TC_EVSEL_t eventSource)
 Configures the Timer/Counter 1 for input capture operation.
void TC1_ConfigWGM (volatile TC1_t *tc, TC_WGMODE_t wgm)
 Configures the Waveform Generation Mode for the Timer/Counter 1.
void TC1_DisableCCChannels (volatile TC1_t *tc, uint8_t disableMask)
 Disables compare/capture channels on Timer/Counter 1.
void TC1_EnableCCChannels (volatile TC1_t *tc, uint8_t enableMask)
 Enables compare/capture channels for Timer/Counter 1.
void TC1_Reset (volatile TC1_t *tc)
 Resets the Timer/Counter 1.
void TC1_SetCCAIntLevel (volatile TC1_t *tc, TC_CCAINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel A interrupt.
void TC1_SetCCBIntLevel (volatile TC1_t *tc, TC_CCBINTLVL_t intLevel)
 Sets the interrupt level for compare/capture channel B interrupt.
void TC1_SetErrorIntLevel (volatile TC1_t *tc, TC_ERRINTLVL_t intLevel)
 Sets the Error interrupt level.
void TC1_SetOverflowIntLevel (volatile TC1_t *tc, TC_OVFINTLVL_t intLevel)
 Sets the overflow interrupt level.


Function Documentation

void TC0_ConfigClockSource ( volatile TC0_t *  tc,
TC_CLKSEL_t  clockSelection 
)

Configures clock source for the Timer/Counter 0.

This function clears the old clock source setting of the Timer/Counter and sets a new clock source according to the clockSelection parameter.

Parameters:
tc Timer/Counter module instance.
clockSelection Timer/Counter clock source setting.

Definition at line 79 of file TC_driver.c.

Referenced by tcc0_init().

00080 {
00081         tc->CTRLA = ( tc->CTRLA & ~TC0_CLKSEL_gm ) | clockSelection;
00082 }

void TC0_ConfigInputCapture ( volatile TC0_t *  tc,
TC_EVSEL_t  eventSource 
)

Configures the Timer/Counter 0 for input capture operation.

This function sets the Timer/Counter in input capture mode and selects the event lines that will trigger the individual input capture channels.

Note:
Output compare operation is disabled when input capture operation is enabled.
Parameters:
tc Timer/Counter module instance.
eventSource Event source selection.

Definition at line 137 of file TC_driver.c.

00138 {
00139         tc->CTRLD = ( tc->CTRLD & ~( TC0_EVSEL_gm | TC0_EVACT_gm ) ) |
00140                     eventSource |
00141                     TC_EVACT_CAPT_gc;
00142 }

void TC0_ConfigWGM ( volatile TC0_t *  tc,
TC_WGMODE_t  wgm 
)

Configures the Waveform Generation Mode for the Timer/Counter 0.

This function clears the old WGM setting of the Timer/Counter and sets a new WGM setting according to the wgm parameter.

Parameters:
tc Timer/Counter module instance.
wgm Waveform generation mode.

Definition at line 106 of file TC_driver.c.

Referenced by tcc0_init().

00107 {
00108         tc->CTRLB = ( tc->CTRLB & ~TC0_WGMODE_gm ) | wgm;
00109 }

void TC0_DisableCCChannels ( volatile TC0_t *  tc,
uint8_t  disableMask 
)

Disables compare/capture channels on Timer/Counter 0.

This function disables compare/capture channels according to the supplied disableMask. The disableMask can be obtained by ORing together the symbols

  • TC0_CCAEN_bm
  • TC0_CCBEN_bm
  • TC0_CCCEN_bm
  • TC0_CCDEN_bm

Example: TC0_DisableCCChannels( &TCC0, TC0_CCAEN_bm | TC0_CCCEN_bm ) will disable channels A and C.

Parameters:
tc Timer/Counter module instance.
disableMask Mask of channels to disable.

Definition at line 232 of file TC_driver.c.

00233 {
00234         /* Make sure only CCxEN bits are set in disableMask. */
00235         disableMask &= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
00236 
00237         /* Disable channels. */
00238         tc->CTRLB &= ~disableMask;
00239 }

void TC0_EnableCCChannels ( volatile TC0_t *  tc,
uint8_t  enableMask 
)

Enables compare/capture channels for Timer/Counter 0.

This function enables compare/capture channels according to the supplied enableMask. The enableMask can be obtained by ORing together the symbols

  • TC0_CCAEN_bm
  • TC0_CCBEN_bm
  • TC0_CCCEN_bm
  • TC0_CCDEN_bm

Example: TC0_EnableCCChannels( &TCC0, TC0_CCAEN_bm | TC0_CCCEN_bm ) will enable channels A and C.

Note:
No capture/compare channels are disabled by calling this function. Disabling is done by calling TC0_DisableCCChannels.
Parameters:
tc Timer/Counter module instance.
enableMask Mask of channels to enable.

Definition at line 182 of file TC_driver.c.

Referenced by tcc0_init().

00183 {
00184         /* Make sure only CCxEN bits are set in enableMask. */
00185         enableMask &= ( TC0_CCAEN_bm | TC0_CCBEN_bm | TC0_CCCEN_bm | TC0_CCDEN_bm );
00186 
00187         /* Enable channels. */
00188         tc->CTRLB |= enableMask;
00189 }

void TC0_Reset ( volatile TC0_t *  tc  ) 

Resets the Timer/Counter 0.

This function will reset the Timer/Counter. After calling this function, the Timer/Counter will be in the same state as it would after a full reset of the device.

Parameters:
tc Timer/Counter 0 module instance.

Definition at line 408 of file TC_driver.c.

00409 {
00410         /* TC must be turned off before a Reset command. */
00411         tc->CTRLA = ( tc->CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
00412 
00413         /* Issue Reset command. */
00414         tc->CTRLFSET = TC_CMD_RESET_gc;
00415 }

void TC0_SetCCAIntLevel ( volatile TC0_t *  tc,
TC_CCAINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel A interrupt.

This function sets the interrupt level for compare/capture channel A interrupt in Timer/Counter 0.

Parameters:
tc Timer/Counter module instance.
intLevel New compare/capture channel A interrupt level.

Definition at line 324 of file TC_driver.c.

Referenced by tcc0_init().

00325 {
00326         tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCAINTLVL_gm ) | intLevel;
00327 }

void TC0_SetCCBIntLevel ( volatile TC0_t *  tc,
TC_CCBINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel B interrupt.

This function sets the interrupt level for compare/capture channel B interrupt in Timer/Counter 0.

Parameters:
tc Timer/Counter module instance.
intLevel New compare/capture channel B interrupt level.

Definition at line 352 of file TC_driver.c.

00353 {
00354         tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCBINTLVL_gm ) | intLevel;
00355 }

void TC0_SetCCCIntLevel ( volatile TC0_t *  tc,
TC_CCCINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel C interrupt.

This function sets the interrupt level for compare/capture channel C interrupt in Timer/Counter 0.

Parameters:
tc Timer/Counter module instance.
intLevel New compare/capture channel A interrupt level.

Definition at line 380 of file TC_driver.c.

00381 {
00382         tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCCINTLVL_gm ) | intLevel;
00383 }

void TC0_SetCCDIntLevel ( volatile TC0_t *  tc,
TC_CCDINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel D interrupt.

This function sets the interrupt level for compare/capture channel D interrupt in Timer/Counter 0.

Parameters:
tc Timer/Counter module instance.
intLevel New compare/capture channel A interrupt level.

Definition at line 394 of file TC_driver.c.

00395 {
00396         tc->INTCTRLB = ( tc->INTCTRLB & ~TC0_CCDINTLVL_gm ) | intLevel;
00397 }

void TC0_SetErrorIntLevel ( volatile TC0_t *  tc,
TC_ERRINTLVL_t  intLevel 
)

Sets the Error interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 0.

Parameters:
tc Timer/Counter module instance.
intLevel New error interrupt level.

Definition at line 297 of file TC_driver.c.

00298 {
00299         tc->INTCTRLA = ( tc->INTCTRLA & ~TC0_ERRINTLVL_gm ) | intLevel;
00300 }

void TC0_SetOverflowIntLevel ( volatile TC0_t *  tc,
TC_OVFINTLVL_t  intLevel 
)

Sets the overflow interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 0.

Parameters:
tc Timer/Counter module instance.
intLevel New overflow interrupt level.

Definition at line 271 of file TC_driver.c.

00272 {
00273         tc->INTCTRLA = ( tc->INTCTRLA & ~TC0_OVFINTLVL_gm ) | intLevel;
00274 }

void TC1_ConfigClockSource ( volatile TC1_t *  tc,
TC_CLKSEL_t  clockSelection 
)

Configures clock source for the Timer/Counter 1.

This function clears the old clock source setting of the Timer/Counter and sets a new clock source according to the clockSelection parameter.

Parameters:
tc Timer/Counter module instance.
clockSelection Timer/Counter clock source setting.

Definition at line 92 of file TC_driver.c.

00093 {
00094         tc->CTRLA = ( tc->CTRLA & ~TC1_CLKSEL_gm ) | clockSelection;
00095 }

void TC1_ConfigInputCapture ( volatile TC1_t *  tc,
TC_EVSEL_t  eventSource 
)

Configures the Timer/Counter 1 for input capture operation.

This function sets the Timer/Counter in input capture mode and selects the event lines that will trigger the individual input capture channels.

Note:
Output compare operation is disabled when input capture operation is enabled.
Parameters:
tc Timer/Counter module instance.
eventSource Event source selection.

Definition at line 156 of file TC_driver.c.

00157 {
00158         tc->CTRLD = ( tc->CTRLD & ~( TC1_EVSEL_gm | TC1_EVACT_gm ) ) |
00159                     eventSource |
00160                     TC_EVACT_CAPT_gc;
00161 }

void TC1_ConfigWGM ( volatile TC1_t *  tc,
TC_WGMODE_t  wgm 
)

Configures the Waveform Generation Mode for the Timer/Counter 1.

This function clears the old WGM setting of the Timer/Counter and sets a new WGM setting according to the wgm parameter.

Parameters:
tc Timer/Counter module instance.
wgm Waveform generation mode.

Definition at line 120 of file TC_driver.c.

00121 {
00122         tc->CTRLB = ( tc->CTRLB & ~TC1_WGMODE_gm ) | wgm;
00123 }

void TC1_DisableCCChannels ( volatile TC1_t *  tc,
uint8_t  disableMask 
)

Disables compare/capture channels on Timer/Counter 1.

This function disables compare/capture channels according to the supplied disableMask. The disableMask can be obtained by ORing together the symbols

  • TC1_CCAEN_bm
  • TC1_CCBEN_bm

Example: TC1_DisableCCChannels( &TCC1, TC1_CCAEN_bm | TC1_CCBEN_bm ) will disable channels A and B.

Parameters:
tc Timer/Counter module instance.
disableMask Mask of channels to disable.

Definition at line 255 of file TC_driver.c.

00256 {
00257         /* Make sure only CCxEN bits are set in disableMask. */
00258         disableMask &= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
00259 
00260         /* Disable channels. */
00261         tc->CTRLB &= ~disableMask;
00262 }

void TC1_EnableCCChannels ( volatile TC1_t *  tc,
uint8_t  enableMask 
)

Enables compare/capture channels for Timer/Counter 1.

This function enables compare/capture channels according to the supplied enableMask. The enableMask can be obtained by ORing together the symbols

  • TC1_CCAEN_bm
  • TC1_CCBEN_bm

Example: TC1_EnableCCChannels( &TCC1, TC1_CCAEN_bm | TC1_CCBEN_bm ) will enable channels A and B.

Note:
No capture/compare channels are disabled by calling this function. Disabling is done by calling TC1_DisableCCChannels.
Parameters:
tc Timer/Counter module instance.
enableMask Mask of channels to enable.

Definition at line 207 of file TC_driver.c.

00208 {
00209         /* Make sure only CCxEN bits are set in enableMask. */
00210         enableMask &= ( TC1_CCAEN_bm | TC1_CCBEN_bm );
00211 
00212         /* Enable channels. */
00213         tc->CTRLB |= enableMask;
00214 }

void TC1_Reset ( volatile TC1_t *  tc  ) 

Resets the Timer/Counter 1.

This function will reset the Timer/Counter. After calling this function, the Timer/Counter will be in the same state as it would after a full reset of the device.

Parameters:
tc Timer/Counter 1 module instance.

Definition at line 426 of file TC_driver.c.

00427 {
00428         /* TC must be turned off before a Reset command. */
00429         tc->CTRLA = ( tc->CTRLA & ~TC1_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
00430 
00431         /* Issue Reset command. */
00432         tc->CTRLFSET = TC_CMD_RESET_gc;
00433 }

void TC1_SetCCAIntLevel ( volatile TC1_t *  tc,
TC_CCAINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel A interrupt.

This function sets the interrupt level for compare/capture channel A interrupt in Timer/Counter 1.

Parameters:
tc Timer/Counter module instance.
intLevel New compare/capture channel A interrupt level.

Definition at line 338 of file TC_driver.c.

00339 {
00340         tc->INTCTRLB = ( tc->INTCTRLB & ~TC1_CCAINTLVL_gm ) | intLevel;
00341 }

void TC1_SetCCBIntLevel ( volatile TC1_t *  tc,
TC_CCBINTLVL_t  intLevel 
)

Sets the interrupt level for compare/capture channel B interrupt.

This function sets the interrupt level for compare/capture channel B interrupt in Timer/Counter 1.

Parameters:
tc Timer/Counter module instance.
intLevel New compare/capture channel B interrupt level.

Definition at line 366 of file TC_driver.c.

00367 {
00368         tc->INTCTRLB = ( tc->INTCTRLB & ~TC1_CCBINTLVL_gm ) | intLevel;
00369 }

void TC1_SetErrorIntLevel ( volatile TC1_t *  tc,
TC_ERRINTLVL_t  intLevel 
)

Sets the Error interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 1.

Parameters:
tc Timer/Counter module instance.
intLevel New error interrupt level.

Definition at line 310 of file TC_driver.c.

00311 {
00312         tc->INTCTRLA = ( tc->INTCTRLA & ~TC1_ERRINTLVL_gm ) | intLevel;
00313 }

void TC1_SetOverflowIntLevel ( volatile TC1_t *  tc,
TC_OVFINTLVL_t  intLevel 
)

Sets the overflow interrupt level.

This function sets the overflow interrupt level of this Timer/Counter 1.

Parameters:
tc Timer/Counter module instance.
intLevel New overflow interrupt level.

Definition at line 284 of file TC_driver.c.

00285 {
00286         tc->INTCTRLA = ( tc->INTCTRLA & ~TC1_OVFINTLVL_gm ) | intLevel;
00287 }


Generated on Fri Sep 4 16:08:56 2009 for AVR1606: Calibration of the internal RC oscillator of XMEGA by  doxygen 1.5.6