This file defines a useful set of functions to interface with the ADCIFB module on AVR32 devices.
Definition in file adcifb.h.
#include <avr32/io.h>
#include "compiler.h"
Go to the source code of this file.
Data Structures | |
struct | adcifb_opt_t |
Parameters for initialization of the ADCIFB module. More... | |
Defines | |
#define | ADCIFB_POLL_TIMEOUT 10000 |
The timeguard used for polling. | |
Functions | |
void | adcifb_channels_disable (volatile avr32_adcifb_t *adcifb, unsigned long int channels_mask) |
Disable one or several channels. | |
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). |
#define ADCIFB_POLL_TIMEOUT 10000 |
The timeguard used for polling.
Definition at line 56 of file adcifb.h.
Referenced by adcifb_sr_statushigh_wait().
void adcifb_channels_disable | ( | volatile avr32_adcifb_t * | adcifb, | |
unsigned long int | channels_mask | |||
) |
Disable one or several channels.
*adcifb | Base address of the ADCIFB module | |
channels_mask | Bitmask of channels to disable |
void adcifb_channels_enable | ( | volatile avr32_adcifb_t * | adcifb, | |
unsigned long int | channels_mask | |||
) |
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.
*adcifb | Base address of the ADCIFB module | |
p_adcifb_opt | Structure for the ADCIFB module configuration |
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.
*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) |
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.
*adcifb | Base address of the ADCIFB module |
Definition at line 105 of file adcifb.c.
Referenced by main().
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.
*adcifb | Base address of the ADCIFB module |
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.
*adcifb | Base address of the ADCIFB module |
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.
*adcifb | Base address of the ADCIFB module |
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.
*adcifb | Base address of the ADCIFB module | |
statusMask | Mask field of the status to poll |
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 | ) |