adcifb.c File Reference


Detailed Description

ADCIFB driver for AVR32 UC3.

This file defines a useful set of functions for ADC on AVR32 devices.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file adcifb.c.

#include <avr32/io.h>
#include "compiler.h"
#include "adcifb.h"

Go to the source code of this file.

Functions

void adcifb_channels_enable (volatile avr32_adcifb_t *adcifb, unsigned long int channels_mask)
 Enable one or several channels.
long int adcifb_configure (volatile avr32_adcifb_t *adcifb, adcifb_opt_t *p_adcifb_opt)
 Initialize the ADCIFB module (enable and configure). Mandatory to call.
long int adcifb_configure_trigger (volatile avr32_adcifb_t *adcifb, unsigned char trgmod, unsigned short int trgper)
 Configure the ADCIFB trigger mode.
unsigned long adcifb_get_last_data (volatile avr32_adcifb_t *adcifb)
 Get Last Converted data.
bool adcifb_is_drdy (volatile avr32_adcifb_t *adcifb)
 Check if one or more data has been converted since the start of conversion and is available.
bool adcifb_is_ovre (volatile avr32_adcifb_t *adcifb)
 Check if one or more Overrun Error has occurred since the start of conversion.
bool adcifb_is_ready (volatile avr32_adcifb_t *adcifb)
 Check if the ADCIFB is ready to perform a conversion sequence.
long int adcifb_sr_statushigh_wait (volatile avr32_adcifb_t *adcifb, unsigned long statusMask)
 Wait for a status high in the ADCIFB SR status register.
void adcifb_start_conversion_sequence (volatile avr32_adcifb_t *adcifb)
 Start an ADC conversion sequence (Software trigger).


Function Documentation

void adcifb_channels_enable ( volatile avr32_adcifb_t *  adcifb,
unsigned long int  channels_mask 
)

Enable one or several channels.

Parameters:
*adcifb Base address of the ADCIFB module
channels_mask Bitmask of channels to enable

Definition at line 92 of file adcifb.c.

Referenced by main().

00094 {
00095   adcifb->cher |= channels_mask;
00096 }

long int adcifb_configure ( volatile avr32_adcifb_t *  adcifb,
adcifb_opt_t p_adcifb_opt 
)

Initialize the ADCIFB module (enable and configure). Mandatory to call.

Parameters:
*adcifb Base address of the ADCIFB module
p_adcifb_opt Structure for the ADCIFB module configuration
Note:
To avoid an infinite loop, this function checks the ADCIFB READY status bit but no longer than ADCIFB_POLL_TIMEOUT times.
Returns:
Status.
Return values:
0 ADCIFB successfully enabled and configured
<0 ADCIFB initialization failed.

Definition at line 53 of file adcifb.c.

References adcifb_sr_statushigh_wait(), adcifb_opt_t::ratio_clkadcifb_clkadc, adcifb_opt_t::resolution, adcifb_opt_t::shtim, adcifb_opt_t::sleep_mode_enable, and adcifb_opt_t::startup.

Referenced by main().

00055 {
00056   unsigned long int prescal_tempo;
00057 
00058 
00059     // Enable the ADCIFB module.
00060   adcifb->cr = AVR32_ADCIFB_CR_EN_MASK;
00061   
00062   // Compute the PRESCAL field according to the ratio Fclk_adcifb/Fclk_adc.
00063   // PRESCAL = ((Fclk_adcifb/Fclk_adc)/2)-1
00064   prescal_tempo = (p_adcifb_opt->ratio_clkadcifb_clkadc >> 1) -1;
00065 
00066   // Set the ADC configuration
00067   adcifb->acr  = (p_adcifb_opt->sleep_mode_enable << AVR32_ADCIFB_ACR_SLEEP_OFFSET)
00068                | (p_adcifb_opt->resolution << AVR32_ADCIFB_ACR_RES_OFFSET)
00069                | (prescal_tempo << AVR32_ADCIFB_ACR_PRESCAL_OFFSET)
00070                | (p_adcifb_opt->startup << AVR32_ADCIFB_ACR_STARTUP_OFFSET)
00071                | (p_adcifb_opt->shtim << AVR32_ADCIFB_ACR_SHTIM_OFFSET);
00072 
00073   // Wait Startup Time, with a timeout.
00074   return(adcifb_sr_statushigh_wait(adcifb, AVR32_ADCIFB_SR_READY_MASK));
00075 }

long int adcifb_configure_trigger ( volatile avr32_adcifb_t *  adcifb,
unsigned char  trgmod,
unsigned short int  trgper 
)

Configure the ADCIFB trigger mode.

Parameters:
*adcifb Base address of the ADCIFB module
trgmod Trigger mode, one of AVR32_ADCIFB_TRGR_TRGMOD_* defines (cf adcifb_xxx.h part header file)
trgper defines the Trigger period where Trigger Period = trgper *Tclk_adc (effective only if trigger_mode==AVR32_ADCIFB_TRGMOD_PT)
Returns:
Status.
Return values:
0 ADCIFB trigger mode successfully configured
<0 ADCIFB trigger mode configuration failed.

Definition at line 78 of file adcifb.c.

Referenced by main().

00081 {
00082   // If the trigger mode is not set to "Periodic Trigger", clear the trgper field.
00083   if(AVR32_ADCIFB_TRGMOD_PT != trgmod)
00084     trgper = 0;
00085   // Configure the trigger mode
00086   adcifb->trgr = ((trgmod&AVR32_ADCIFB_TRGMOD_MASK)<<AVR32_ADCIFB_TRGMOD_OFFSET)
00087                | ((trgper&AVR32_ADCIFB_TRGPER_MASK)<<AVR32_ADCIFB_TRGPER_OFFSET);
00088   return PASS;
00089 }

unsigned long adcifb_get_last_data ( volatile avr32_adcifb_t *  adcifb  ) 

Get Last Converted data.

Parameters:
*adcifb Base address of the ADCIFB module
Returns:
The value acquired (unsigned long)
Warning:
the return value contains the converted data in the bits[0-11]; bits[16-23] contain the channel id that was last converted.

Definition at line 105 of file adcifb.c.

Referenced by main().

00106 {
00107   return(adcifb->lcdr);
00108 }

bool adcifb_is_drdy ( volatile avr32_adcifb_t *  adcifb  ) 

Check if one or more data has been converted since the start of conversion and is available.

Parameters:
*adcifb Base address of the ADCIFB module
Returns:
bool TRUE if one or more data has been converted since the start of conversion and is available FALSE if no data has been converted since the start of conversion

Definition at line 131 of file adcifb.c.

Referenced by main().

00132 {
00133   return((adcifb->sr & AVR32_ADCIFB_SR_DRDY_MASK)>>AVR32_ADCIFB_SR_DRDY_OFFSET);
00134 }

bool adcifb_is_ovre ( volatile avr32_adcifb_t *  adcifb  ) 

Check if one or more Overrun Error has occurred since the start of conversion.

Parameters:
*adcifb Base address of the ADCIFB module
Returns:
bool TRUE if an overrun has occured FALSE if no overrun occured

Definition at line 137 of file adcifb.c.

00138 {
00139   return((adcifb->sr & AVR32_ADCIFB_SR_OVRE_MASK)>>AVR32_ADCIFB_SR_OVRE_OFFSET);
00140 }

bool adcifb_is_ready ( volatile avr32_adcifb_t *  adcifb  ) 

Check if the ADCIFB is ready to perform a conversion sequence.

Parameters:
*adcifb Base address of the ADCIFB module
Returns:
bool TRUE if the ADCIFB is ready to perform a conversion sequence. FALSE if the ADCIFB is not ready to perform a conversion sequence.

Definition at line 125 of file adcifb.c.

Referenced by main().

00126 {
00127   return((adcifb->sr & AVR32_ADCIFB_SR_READY_MASK)>>AVR32_ADCIFB_SR_READY_OFFSET);
00128 }

long int adcifb_sr_statushigh_wait ( volatile avr32_adcifb_t *  adcifb,
unsigned long  statusMask 
)

Wait for a status high in the ADCIFB SR status register.

Parameters:
*adcifb Base address of the ADCIFB module
statusMask Mask field of the status to poll
Returns:
Status.
Return values:
0 Status is high.
<0 ADCIFB_POLL_TIMEOUT Timeout expired before the status was high.

Definition at line 111 of file adcifb.c.

References ADCIFB_POLL_TIMEOUT.

Referenced by adcifb_configure().

00113 {
00114   unsigned int timeout = ADCIFB_POLL_TIMEOUT;
00115 
00116   while(!(adcifb->sr & statusMask))
00117   {
00118     if(--timeout == 0)
00119       return -1;
00120   }
00121   return PASS;
00122 }

void adcifb_start_conversion_sequence ( volatile avr32_adcifb_t *  adcifb  ) 

Start an ADC conversion sequence (Software trigger).

Parameters:
*adcifb Base address of the ADCIFB module

Definition at line 99 of file adcifb.c.

Referenced by main().

00100 {
00101   adcifb->cr = AVR32_ADCIFB_CR_START_MASK;
00102 }


Generated on Fri Feb 19 02:24:12 2010 for AVR32 - ADCIFB Driver - Example 1 by  doxygen 1.5.5