timer.c File Reference

#include "timer.h"

Include dependency graph for timer.c:

Go to the source code of this file.

Functions

int timer_configure_interrupts (unsigned int instance, unsigned int channel, volatile struct timer_interrupt_t *bitfield)
int timer_external_clock_selection (unsigned int instance, unsigned int channel, unsigned int clock_signal)
volatile avr32_timer_t * timer_getHandle (unsigned int instance)
int timer_init_capture (unsigned int instance, volatile struct timer_capture_opt_t *opt)
int timer_init_waveform (unsigned int instance, volatile struct timer_waveform_opt_t *opt)
char timer_interrupt_settings (unsigned int instance, unsigned int channel)
int timer_read_ra (unsigned int instance, unsigned int channel)
int timer_read_rb (unsigned int instance, unsigned int channel)
int timer_read_rc (unsigned int instance, unsigned int channel)
unsigned long timer_read_sr (unsigned int instance, unsigned int channel)
int timer_read_tc (unsigned int instance, unsigned int channel)
int timer_software_trigger (unsigned int instance, unsigned int channel)
int timer_start (unsigned int instance, unsigned int channel)
int timer_stop (unsigned int instance, unsigned int channel)
void timer_sync_trigger (unsigned int instance)
int timer_write_ra (unsigned int instance, unsigned int channel, unsigned short value)
int timer_write_rb (unsigned int instance, unsigned int channel, unsigned short value)
int timer_write_rc (unsigned int instance, unsigned int channel, unsigned short value)


Function Documentation

int timer_configure_interrupts ( unsigned int  instance,
unsigned int  channel,
volatile struct timer_interrupt_t bitfield 
)

This function will enable or disable interrupt for a given Timer/Counter instance and channel depending on the bitfield mask value

Parameters:
instance,: The Timer/Counter instance
channel,: The Timer/Counter channel
*bitfield,: The mask to use for this instance and channel
Returns:
TIMER_INVALID_ARGUMENT or TIMER_SUCCESS

Definition at line 278 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, and TIMER_SUCCESS.

00279 {
00280         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00281 
00282         if( instance >= AVR32_TIMER_COUNT )
00283                 return TIMER_INVALID_ARGUMENT;
00284 
00285         /* enable the appropriate interrupts */
00286         timer->channel[channel].ier = (bitfield->covfs << AVR32_TIMER_COVFS_OFFSET) |
00287                                                                 (bitfield->lovrs << AVR32_TIMER_LOVRS_OFFSET) |
00288                                                                 (bitfield->cpas << AVR32_TIMER_CPAS_OFFSET) |
00289                                                                 (bitfield->cpbs << AVR32_TIMER_CPBS_OFFSET) |
00290                                                                 (bitfield->cpcs << AVR32_TIMER_CPCS_OFFSET) |
00291                                                                 (bitfield->ldras << AVR32_TIMER_LDRAS_OFFSET) |
00292                                                                 (bitfield->ldrbs << AVR32_TIMER_LDRBS_OFFSET) |
00293                                                                 (bitfield->etrgs << AVR32_TIMER_ETRGS_OFFSET);
00294 
00295         /* disable the appropriate interrupts */
00296         timer->channel[channel].idr = ( ~(bitfield->covfs) << AVR32_TIMER_COVFS_OFFSET) |
00297                                                                 ( ~(bitfield->lovrs) << AVR32_TIMER_LOVRS_OFFSET) |
00298                                                                 ( ~(bitfield->cpas) << AVR32_TIMER_CPAS_OFFSET) |
00299                                                                 ( ~(bitfield->cpbs) << AVR32_TIMER_CPBS_OFFSET) |
00300                                                                 ( ~(bitfield->cpcs) << AVR32_TIMER_CPCS_OFFSET) |
00301                                                                 ( ~(bitfield->ldras) << AVR32_TIMER_LDRAS_OFFSET) |
00302                                                                 ( ~(bitfield->ldrbs) << AVR32_TIMER_LDRBS_OFFSET) |
00303                                                                 ( ~(bitfield->etrgs) << AVR32_TIMER_ETRGS_OFFSET);
00304 
00305         return TIMER_SUCCESS;
00306 }

Here is the call graph for this function:

int timer_external_clock_selection ( unsigned int  instance,
unsigned int  channel,
unsigned int  clock_signal 
)

This function use an external clock for a timer/counter instance

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
clock_signal,: Which external clock to use
Returns:
TIMER_SUCCESS or TIMER_INVALID_ARGUMENT

Definition at line 145 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, TIMER_NUMBER_OF_CHANNELS, and TIMER_SUCCESS.

00146 {
00147         volatile struct avr32_timer_t *timer =timer_getHandle(instance);
00148 
00149         /* Check for valid input */
00150         if( (channel >= TIMER_NUMBER_OF_CHANNELS) | (instance >= AVR32_TIMER_COUNT) | (clock_signal >= 2) )
00151                 return TIMER_INVALID_ARGUMENT;
00152 
00153         //clear bitfield and set the correct behaviour
00154         timer->bmr &= ~( (AVR32_TIMER_BMR_TC2XC2S_SIZE+1) << (2*clock_signal) );
00155         timer->bmr = channel << (2*clock_signal) ;
00156 
00157         return TIMER_SUCCESS;
00158 }

Here is the call graph for this function:

volatile avr32_timer_t* timer_getHandle ( unsigned int  instance  ) 

This function returns the base address for a given Timer/Counter instance

Parameters:
instance,: The Timer/Counter instance
Returns:
The base address for the instance or TIMER_INVALID_ARGUMENT if the instance is invalid

Definition at line 259 of file timer.c.

References TIMER_INVALID_ARGUMENT.

Referenced by timer_configure_interrupts(), timer_external_clock_selection(), timer_init_capture(), timer_init_waveform(), timer_interrupt_settings(), timer_read_ra(), timer_read_rb(), timer_read_rc(), timer_read_sr(), timer_read_tc(), timer_software_trigger(), timer_start(), timer_stop(), timer_sync_trigger(), timer_write_ra(), timer_write_rb(), and timer_write_rc().

00260 {
00261   switch (instance) {
00262 
00263   case 0:
00264     return &AVR32_TIMER0;
00265 
00266   case 1:
00267     return &AVR32_TIMER1;
00268 
00269   default:
00270     break;
00271     
00272   }
00273   return (avr32_timer_t *) TIMER_INVALID_ARGUMENT;
00274 
00275 }

int timer_init_capture ( unsigned int  instance,
volatile struct timer_capture_opt_t opt 
)

This function will initialize the timer/counter instance in capture mode, with the options provided

Parameters:
instance,: The Timer/Counter instance to be initialized
*opt,: The options for the instance.
Returns:
TIMER_SUCCESS or TIMER_INVALID_ARGUMENT

Definition at line 40 of file timer.c.

References TIMER_CAPTURE_OPERATING_MODE, timer_getHandle(), TIMER_INVALID_ARGUMENT, TIMER_NUMBER_OF_CHANNELS, and TIMER_SUCCESS.

Referenced by init_timer_input().

00041 {
00042         volatile struct avr32_timer_t *timer =timer_getHandle(instance);
00043 
00044         if( (opt->channel >= TIMER_NUMBER_OF_CHANNELS) )
00045                 return TIMER_INVALID_ARGUMENT;
00046 
00047         /* MEASURE SIGNALS: Capture operating mode */
00048         timer->channel[opt->channel].cmr =
00049                 (opt->tcclks << AVR32_TIMER_TCCLKS_OFFSET) |
00050                 (opt->clki << AVR32_TIMER_CLKI_OFFSET ) |
00051                 (opt->burst << AVR32_TIMER_BURST_OFFSET ) |
00052                 (opt->ldbstop << AVR32_TIMER_LDBSTOP_OFFSET ) |
00053                 (opt->ldbdis << AVR32_TIMER_LDBDIS_OFFSET ) |
00054                 (opt->etrgedg << AVR32_TIMER_ETRGEDG_OFFSET )|
00055                 (opt->abetrg << AVR32_TIMER_ABETRG_OFFSET ) |
00056                 (opt->cpctrg << AVR32_TIMER_CPCTRG_OFFSET )|
00057                 (TIMER_CAPTURE_OPERATING_MODE << AVR32_TIMER_WAVE_OFFSET ) |
00058                 (opt->ldra << AVR32_TIMER_LDRA_OFFSET ) |
00059                 (opt->ldrb << AVR32_TIMER_LDRB_OFFSET );
00060 
00061         return TIMER_SUCCESS;
00062 } /* end timer_init_capture() */

Here is the call graph for this function:

int timer_init_waveform ( unsigned int  instance,
volatile struct timer_waveform_opt_t opt 
)

This function will initialize the timer/counter instance in waveform mode, with the options provided

Parameters:
instance,: The Timer/Counter instance to be initialized
*opt,: The options for the instance.
Returns:
TIMER_SUCCESS or TIMER_INVALID_ARGUMENT

Definition at line 65 of file timer.c.

References timer_getHandle(), TIMER_INVALID_ARGUMENT, TIMER_NUMBER_OF_CHANNELS, TIMER_SUCCESS, and TIMER_WAVEFORM_OPERATING_MODE.

Referenced by init_timer_output(), and timer_delay().

00066 {
00067         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00068 
00069         if( (opt->channel >=TIMER_NUMBER_OF_CHANNELS) | (opt->channel < TIMER_SUCCESS) )
00070                 return TIMER_INVALID_ARGUMENT;
00071 
00072         /* GENERATE SIGNALS: Waveform operating mode */
00073         timer->channel[opt->channel].cmr =
00074                 (opt->tcclks << AVR32_TIMER_TCCLKS_OFFSET) |
00075                 (opt->clki << AVR32_TIMER_CLKI_OFFSET ) |
00076                 (opt->burst << AVR32_TIMER_BURST_OFFSET ) |
00077                 (opt->cpcstop << AVR32_TIMER_CPCSTOP_OFFSET ) |
00078                 (opt->cpcdis << AVR32_TIMER_CPCDIS_OFFSET ) |
00079                 (opt->eevtedg << AVR32_TIMER_EEVTEDG_OFFSET )|
00080                 (opt->eevt << AVR32_TIMER_EEVT_OFFSET )|
00081                 (opt->enetrg << AVR32_TIMER_ENETRG_OFFSET )|
00082                 (opt->wavsel << AVR32_TIMER_WAVSEL )|
00083                 (TIMER_WAVEFORM_OPERATING_MODE << AVR32_TIMER_WAVE_OFFSET )|
00084                 (opt->acpa << AVR32_TIMER_ACPA_OFFSET )|
00085                 (opt->acpc << AVR32_TIMER_ACPC_OFFSET )|
00086                 (opt->aeevt << AVR32_TIMER_AEEVT_OFFSET )|
00087                 (opt->aswtrg << AVR32_TIMER_ASWTRG_OFFSET )|
00088                 (opt->bcpb << AVR32_TIMER_BCPB_OFFSET )|
00089                 (opt->bcpc << AVR32_TIMER_BCPC_OFFSET )|
00090                 (opt->beevt << AVR32_TIMER_BEEVT_OFFSET )|
00091                 (opt->bswtrg << AVR32_TIMER_BSWTRG_OFFSET );
00092 
00093         return TIMER_SUCCESS;
00094 } /* end timer_init_waveform() */

Here is the call graph for this function:

char timer_interrupt_settings ( unsigned int  instance,
unsigned int  channel 
)

This function returns the interrupt settings for the given instance and channel

Parameters:
instance,: The Timer/Counter instance
channel,: The Timer/Counter channel
Returns:
The interrupt mask settings

Definition at line 309 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, and TIMER_NUMBER_OF_CHANNELS.

00310 {
00311         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00312 
00313         if( (instance >= AVR32_TIMER_COUNT) | (channel >= TIMER_NUMBER_OF_CHANNELS) )
00314                 return TIMER_INVALID_ARGUMENT;
00315 
00316         return timer->channel[channel].imr;
00317 
00318 }

Here is the call graph for this function:

int timer_read_ra ( unsigned int  instance,
unsigned int  channel 
)

This function returns the RA value for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
TIMER_INVALID_ARGUMENT or the RA value

Definition at line 161 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), and TIMER_INVALID_ARGUMENT.

Referenced by main().

00162 {
00163         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00164 
00165         if (channel>=AVR32_TIMER_COUNT)
00166                 return TIMER_INVALID_ARGUMENT;
00167 
00168         return (timer->channel[channel].ra);
00169 }

Here is the call graph for this function:

int timer_read_rb ( unsigned int  instance,
unsigned int  channel 
)

This function returns the RB value for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
TIMER_INVALID_ARGUMENT or the RB value

Definition at line 172 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), and TIMER_INVALID_ARGUMENT.

00173 {
00174         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00175 
00176         if (channel>=AVR32_TIMER_COUNT)
00177                 return TIMER_INVALID_ARGUMENT;
00178 
00179         return (timer->channel[channel].rb);
00180 }

Here is the call graph for this function:

int timer_read_rc ( unsigned int  instance,
unsigned int  channel 
)

This function returns the RC value for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
TIMER_INVALID_ARGUMENT or the RC value

Definition at line 183 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), and TIMER_INVALID_ARGUMENT.

00184 {
00185         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00186 
00187         if (channel>=AVR32_TIMER_COUNT)
00188                 return TIMER_INVALID_ARGUMENT;
00189 
00190         return (timer->channel[channel].rc);
00191 }

Here is the call graph for this function:

unsigned long timer_read_sr ( unsigned int  instance,
unsigned int  channel 
)

This function returns the status register for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
The value of the status register for the given channel and instance

Definition at line 250 of file timer.c.

References timer_getHandle().

00251 {
00252         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00253 
00254         return timer->channel[channel].sr;
00255 
00256 }

Here is the call graph for this function:

int timer_read_tc ( unsigned int  instance,
unsigned int  channel 
)

This function returns the counter value for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
TIMER_INVALID_ARGUMENT or the counter value

Definition at line 194 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), and TIMER_INVALID_ARGUMENT.

Referenced by timer_delay().

00195 {
00196         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00197 
00198         if (channel>=AVR32_TIMER_COUNT)
00199                 return TIMER_INVALID_ARGUMENT;
00200 
00201         return (timer->channel[channel].cv);
00202 }

Here is the call graph for this function:

int timer_software_trigger ( unsigned int  instance,
unsigned int  channel 
)

This function will enable a software trigger for a channel for the timer/counter instance

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
TIMER_SUCCESS or TIMER_INVALID_ARGUMENT

Definition at line 124 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, and TIMER_SUCCESS.

00125 {
00126         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00127 
00128         if( (channel >= AVR32_TIMER_COUNT) | (channel < 0) )
00129                 return TIMER_INVALID_ARGUMENT;
00130 
00131         /* Disable the current timer */
00132         timer->channel[channel].ccr = (1<<AVR32_TIMER_SWTRG_OFFSET);
00133         return TIMER_SUCCESS;
00134 }

Here is the call graph for this function:

int timer_start ( unsigned int  instance,
unsigned int  channel 
)

This function will start a channel for a timer/counter instance

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
TIMER_SUCCESS or TIMER_INVALID_ARGUMENT

Definition at line 97 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, and TIMER_SUCCESS.

Referenced by main(), and timer_delay().

00098 {
00099         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00100 
00101         if( (channel >= AVR32_TIMER_COUNT) | (channel < 0) )
00102                 return TIMER_INVALID_ARGUMENT;
00103 
00104         /* Disable the current timer */
00105         timer->channel[channel].ccr = (1<<AVR32_TIMER_CLKEN_OFFSET) | (1<<AVR32_TIMER_SWTRG_OFFSET);
00106         return TIMER_SUCCESS;
00107 }

Here is the call graph for this function:

int timer_stop ( unsigned int  instance,
unsigned int  channel 
)

This function will stop a channel for a timer/counter instance

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
Returns:
TIMER_SUCCESS or TIMER_INVALID_ARGUMENT

Definition at line 110 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, and TIMER_SUCCESS.

00111 {
00112         volatile struct avr32_timer_t *timer =timer_getHandle(instance);
00113 
00114         if( (channel >= AVR32_TIMER_COUNT) | (channel < 0) )
00115                 return TIMER_INVALID_ARGUMENT;
00116 
00117         /* Disable the current timer */
00118         timer->channel[channel].ccr = (1<<AVR32_TIMER_CLKDIS_OFFSET);
00119 
00120         return TIMER_SUCCESS;
00121 }

Here is the call graph for this function:

void timer_sync_trigger ( unsigned int  instance  ) 

This function will assert a sync singnal for the timer/counter instance

Parameters:
instance,: The Timer/Counter instance
Returns:
nothing

Definition at line 137 of file timer.c.

References timer_getHandle().

00138 {
00139         volatile struct avr32_timer_t *timer =timer_getHandle(instance);
00140 
00141         timer->bcr = (1<<AVR32_TIMER_BCR_SYNC_OFFSET);
00142 }

Here is the call graph for this function:

int timer_write_ra ( unsigned int  instance,
unsigned int  channel,
unsigned short  value 
)

This function sets the RA value for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
value,: The value to write to the register
Returns:
TIMER_INVALID_ARGUMENT or TIMER_SUCCESS

Definition at line 205 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, TIMER_NUMBER_OF_CHANNELS, and TIMER_SUCCESS.

Referenced by main(), and timer_delay().

00206 {
00207         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00208 
00209         if( (channel>=AVR32_TIMER_COUNT) | (channel>=TIMER_NUMBER_OF_CHANNELS) )
00210                 return TIMER_INVALID_ARGUMENT;
00211 
00212         /* This function is only available in WAVEFORM mode */
00213         if(timer->channel[channel].cmr & AVR32_TIMER_CMR0_WAVE_MASK)
00214                 timer->channel[channel].ra = value;
00215 
00216         return TIMER_SUCCESS;
00217 }

Here is the call graph for this function:

int timer_write_rb ( unsigned int  instance,
unsigned int  channel,
unsigned short  value 
)

This function sets the RB value for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
value,: The value to write to the register
Returns:
TIMER_INVALID_ARGUMENT or TIMER_SUCCESS

Definition at line 220 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, TIMER_NUMBER_OF_CHANNELS, and TIMER_SUCCESS.

Referenced by timer_delay().

00221 {
00222         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00223 
00224         if( (channel>=AVR32_TIMER_COUNT) | ( channel >= TIMER_NUMBER_OF_CHANNELS ) )
00225                 return TIMER_INVALID_ARGUMENT;
00226 
00227         /* This function is only available in WAVEFORM mode */
00228         if(timer->channel[channel].cmr & AVR32_TIMER_CMR0_WAVE_MASK)
00229                 timer->channel[channel].rb = value;
00230 
00231         return TIMER_SUCCESS;
00232 }

Here is the call graph for this function:

int timer_write_rc ( unsigned int  instance,
unsigned int  channel,
unsigned short  value 
)

This function sets the RC value for a timer/counter instance and a given channel

Parameters:
instance,: The Timer/Counter instance
channel,: The channel for the selected instance
value,: The value to write to the register
Returns:
TIMER_INVALID_ARGUMENT or TIMER_SUCCESS

Definition at line 235 of file timer.c.

References AVR32_TIMER_COUNT, timer_getHandle(), TIMER_INVALID_ARGUMENT, TIMER_NUMBER_OF_CHANNELS, and TIMER_SUCCESS.

Referenced by timer_delay().

00236 {
00237         volatile struct avr32_timer_t *timer = timer_getHandle(instance);
00238 
00239         if( (channel >= AVR32_TIMER_COUNT) | (channel >= TIMER_NUMBER_OF_CHANNELS) )
00240                 return TIMER_INVALID_ARGUMENT;
00241 
00242         /* This function is only available in WAVEFORM mode */
00243         if(timer->channel[channel].cmr & AVR32_TIMER_CMR0_WAVE_MASK)
00244                 timer->channel[channel].rc = value;
00245 
00246         return TIMER_SUCCESS;
00247 }

Here is the call graph for this function:


Generated on Fri Oct 13 09:41:15 2006 for AVR32110 Using the AVR32 Timer/Counter by  doxygen 1.4.7