qdec.c File Reference


Detailed Description

QDEC driver for AVR32 UC3.

AVR32 QDEC driver module.

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

Definition in file qdec.c.

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

Go to the source code of this file.

Functions

int qdec_configure_interrupts (volatile avr32_qdec_t *qdec, const qdec_interrupt_t *bitfield)
 Enables various QDEC interrupts.
int qdec_get_interrupt_settings (volatile avr32_qdec_t *qdec)
 Get the QDEC current interrupt settings.
int qdec_init_quadrature_decoder_mode (volatile avr32_qdec_t *qdec, const qdec_quadrature_decoder_opt_t *opt)
 Sets options for QDEC quadrature decoder initialization.
int qdec_init_timer_mode (volatile avr32_qdec_t *qdec, const qdec_timer_opt_t *opt)
 Sets options for QDEC Timer mode initialization.
unsigned short int qdec_read_pc (volatile avr32_qdec_t *qdec)
 Read value of the channel's QDEC Position Current Counter register.
unsigned short int qdec_read_pc_cap (volatile avr32_qdec_t *qdec)
 Read value of the channel's QDEC Position Capture Counter register.
unsigned short int qdec_read_rc (volatile avr32_qdec_t *qdec)
 Read value of the channel's QDEC Revolution Current Counter register.
unsigned short int qdec_read_rc_cap (volatile avr32_qdec_t *qdec)
 Read value of the channel's QDEC Revolution Capture register.
int qdec_software_trigger (volatile avr32_qdec_t *qdec)
 Software Trigger Condition to start QDEC service.
int qdec_stop (volatile avr32_qdec_t *qdec)
 Stops a QDEC.
unsigned short int qdec_write_pc_cmp (volatile avr32_qdec_t *qdec, unsigned short int value)
 Writes a value to the channel's QDEC Position Counter Compare register.
unsigned short int qdec_write_pc_cnt (volatile avr32_qdec_t *qdec, unsigned short int value)
 Write value of the channel's QDEC Position Current Counter register.
unsigned short int qdec_write_pc_top (volatile avr32_qdec_t *qdec, unsigned short int value)
 Writes a value to the channel's QDEC Position Counter Top register.
unsigned short int qdec_write_rc_cmp (volatile avr32_qdec_t *qdec, unsigned short int value)
 Writes a value to the channel's QDEC Revolution Counter Compare register.
unsigned short int qdec_write_rc_cnt (volatile avr32_qdec_t *qdec, unsigned short int value)
 Write value of the channel's QDEC Revolution Current Counter register.
unsigned short int qdec_write_rc_top (volatile avr32_qdec_t *qdec, unsigned short int value)
 Writes a value to the channel's QDEC Revolution Counter Top register.


Function Documentation

int qdec_configure_interrupts ( volatile avr32_qdec_t *  qdec,
const qdec_interrupt_t bitfield 
)

Enables various QDEC interrupts.

Parameters:
qdec Pointer to the QDEC instance to access.
bitfield The interrupt enable configuration.
Return values:
0 Success.

Definition at line 59 of file qdec.c.

References qdec_interrupt_t::cap, qdec_interrupt_t::cmp, qdec_interrupt_t::dirinv, qdec_interrupt_t::idexerr, qdec_interrupt_t::ovr, qdec_interrupt_t::pcro, qdec_interrupt_t::qepi, and qdec_interrupt_t::rcro.

Referenced by main().

00060 {
00061 
00062   AVR32_ENTER_CRITICAL_REGION( );
00063   // Enable the appropriate interrupts.
00064   qdec->ier            =     bitfield->ovr << AVR32_QDEC_IER_OVR_OFFSET |
00065                              bitfield->dirinv << AVR32_QDEC_IER_DIRINV_OFFSET |
00066                              bitfield->idexerr << AVR32_QDEC_IER_IDXERR_OFFSET |
00067                              bitfield->rcro << AVR32_QDEC_IER_RCRO_OFFSET |
00068                              bitfield->pcro << AVR32_QDEC_IER_PCRO_OFFSET |
00069                              bitfield->cap << AVR32_QDEC_IER_CAP_OFFSET |
00070                              bitfield->cmp << AVR32_QDEC_IER_CMP_OFFSET |
00071                              bitfield->qepi << AVR32_QDEC_IER_QEPI_OFFSET;
00072 
00073   // Disable the appropriate interrupts.
00074   qdec->idr            =     (~bitfield->ovr & 1) << AVR32_QDEC_IER_OVR_OFFSET |
00075                              (~bitfield->dirinv & 1) << AVR32_QDEC_IER_DIRINV_OFFSET |
00076                              (~bitfield->idexerr & 1) << AVR32_QDEC_IER_IDXERR_OFFSET |
00077                              (~bitfield->rcro & 1) << AVR32_QDEC_IER_RCRO_OFFSET |
00078                              (~bitfield->pcro & 1) << AVR32_QDEC_IER_PCRO_OFFSET |
00079                              (~bitfield->cap & 1) << AVR32_QDEC_IER_CAP_OFFSET |
00080                              (~bitfield->cmp & 1) << AVR32_QDEC_IER_CMP_OFFSET |
00081                              (~bitfield->qepi & 1) << AVR32_QDEC_IER_QEPI_OFFSET;
00082 
00083   AVR32_LEAVE_CRITICAL_REGION( );
00084 
00085   return 0;
00086 }

int qdec_get_interrupt_settings ( volatile avr32_qdec_t *  qdec  ) 

Get the QDEC current interrupt settings.

Parameters:
qdec Pointer to the QDEC instance to access.
Return values:
>=0 The interrupt enable configuration organized according to qdec_interrupt_t.
Interrupt Settings Value.

Definition at line 53 of file qdec.c.

00054 {
00055   return qdec->imr;
00056 }

int qdec_init_quadrature_decoder_mode ( volatile avr32_qdec_t *  qdec,
const qdec_quadrature_decoder_opt_t opt 
)

Sets options for QDEC quadrature decoder initialization.

Parameters:
qdec Pointer to the QDEC instance to access.
opt Options for quadrature decoder mode.
Return values:
0 Success.

Definition at line 88 of file qdec.c.

References qdec_quadrature_decoder_opt_t::evtrge, qdec_quadrature_decoder_opt_t::filten, qdec_quadrature_decoder_opt_t::idxe, qdec_quadrature_decoder_opt_t::idxinv, qdec_quadrature_decoder_opt_t::idxphs, qdec_quadrature_decoder_opt_t::pcce, qdec_quadrature_decoder_opt_t::phsinva, qdec_quadrature_decoder_opt_t::phsinvb, and qdec_quadrature_decoder_opt_t::rcce.

00089 {
00090   qdec->cf = 0;
00091   qdec->cf            =     1 << AVR32_QDEC_CF_QDEC_OFFSET | 
00092                             opt->idxe << AVR32_QDEC_CF_IDXE_OFFSET |
00093                             opt->pcce << AVR32_QDEC_CF_PCCE_OFFSET |
00094                             opt->rcce << AVR32_QDEC_CF_RCCE_OFFSET |
00095                             opt->evtrge << AVR32_QDEC_CF_EVTRGE_OFFSET |    
00096                             opt->phsinva << AVR32_QDEC_CF_PHSINVA_OFFSET |
00097                             opt->phsinvb << AVR32_QDEC_CF_PHSINVB_OFFSET |       
00098                             opt->idxinv << AVR32_QDEC_CF_IDXINV_OFFSET |  
00099                             opt->idxphs << AVR32_QDEC_CF_IDXPHS_OFFSET |
00100                             opt->filten << AVR32_QDEC_CF_FILTEN_OFFSET ;
00101   // Start QDEC Clock by default
00102   qdec->ctrl          |=     1 << AVR32_QDEC_CTRL_CLKEN_OFFSET;
00103   return 0;
00104   
00105 }

int qdec_init_timer_mode ( volatile avr32_qdec_t *  qdec,
const qdec_timer_opt_t opt 
)

Sets options for QDEC Timer mode initialization.

Parameters:
qdec Pointer to the QDEC instance to access.
opt Options for quadrature decoder mode.
Return values:
0 Success.

Definition at line 107 of file qdec.c.

References qdec_timer_opt_t::evtrge, qdec_timer_opt_t::filten, qdec_timer_opt_t::pcce, qdec_timer_opt_t::rcce, qdec_timer_opt_t::tsdir, and qdec_timer_opt_t::upd.

Referenced by main().

00108 {
00109   qdec->cf = 0;
00110   qdec->cf            =     0 << AVR32_QDEC_CF_QDEC_OFFSET | 
00111                             opt->pcce << AVR32_QDEC_CF_PCCE_OFFSET |
00112                             opt->rcce << AVR32_QDEC_CF_RCCE_OFFSET |    
00113                             opt->evtrge << AVR32_QDEC_CF_EVTRGE_OFFSET |    
00114                             opt->filten << AVR32_QDEC_CF_FILTEN_OFFSET |
00115                             opt->tsdir << AVR32_QDEC_CF_TSDIR_OFFSET |                              
00116                             opt->upd << AVR32_QDEC_CF_UPD_OFFSET ; 
00117   // Start QDEC Clock by default
00118   qdec->ctrl          |=     1 << AVR32_QDEC_CTRL_CLKEN_OFFSET;  
00119    return 0;
00120 }

unsigned short int qdec_read_pc ( volatile avr32_qdec_t *  qdec  ) 

Read value of the channel's QDEC Position Current Counter register.

Parameters:
qdec Pointer to the QDEC instance to access.
Return values:
>=0 Status register value.

Definition at line 141 of file qdec.c.

00142 {
00143    return qdec->CNT.pc;
00144 }

unsigned short int qdec_read_pc_cap ( volatile avr32_qdec_t *  qdec  ) 

Read value of the channel's QDEC Position Capture Counter register.

Parameters:
qdec Pointer to the QDEC instance to access.
Return values:
>=0 Status register value.
QDEC_INVALID_ARGUMENT Invalid argument(s).

Definition at line 191 of file qdec.c.

00192 {
00193    return qdec->CAP.pccap;
00194 }

unsigned short int qdec_read_rc ( volatile avr32_qdec_t *  qdec  ) 

Read value of the channel's QDEC Revolution Current Counter register.

Parameters:
qdec Pointer to the QDEC instance to access.
Return values:
>=0 Status register value.

Definition at line 136 of file qdec.c.

00137 {
00138    return qdec->CNT.rc;
00139 }

unsigned short int qdec_read_rc_cap ( volatile avr32_qdec_t *  qdec  ) 

Read value of the channel's QDEC Revolution Capture register.

Parameters:
qdec Pointer to the QDEC instance to access.
Return values:
>=0 Status register value.
QDEC_INVALID_ARGUMENT Invalid argument(s).

Definition at line 186 of file qdec.c.

00187 {
00188    return qdec->CAP.rccap;
00189 }

int qdec_software_trigger ( volatile avr32_qdec_t *  qdec  ) 

Software Trigger Condition to start QDEC service.

Parameters:
qdec Pointer to the QDEC instance to access.
Return values:
0 Success.

Definition at line 122 of file qdec.c.

Referenced by main().

00123 {
00124   
00125   qdec->ctrl           |= 1 << AVR32_QDEC_CTRL_SWTRG_OFFSET ;  
00126   return 0;
00127 }

int qdec_stop ( volatile avr32_qdec_t *  qdec  ) 

Stops a QDEC.

Parameters:
qdec Pointer to the QDEC instance to access.
Return values:
0 Success.

Definition at line 129 of file qdec.c.

00130 {
00131   // Stop QDEC Clock by default
00132   qdec->ctrl          &=     ~(1 << AVR32_QDEC_CTRL_CLKEN_OFFSET);
00133   return 0;
00134 }

unsigned short int qdec_write_pc_cmp ( volatile avr32_qdec_t *  qdec,
unsigned short int  value 
)

Writes a value to the channel's QDEC Position Counter Compare register.

Parameters:
qdec Pointer to the QDEC instance to access.
value Value to write to the RC register.
Return values:
>=0 Written value.
QDEC_INVALID_ARGUMENT Invalid argument(s).

Definition at line 179 of file qdec.c.

Referenced by main().

00180 {
00181   qdec->CMP.pccmp = value;
00182 
00183   return qdec->CMP.pccmp;  
00184 }

unsigned short int qdec_write_pc_cnt ( volatile avr32_qdec_t *  qdec,
unsigned short int  value 
)

Write value of the channel's QDEC Position Current Counter register.

Parameters:
qdec Pointer to the QDEC instance to access.
value Value to write to the PC register.
Return values:
>=0 Status register value.

Definition at line 152 of file qdec.c.

Referenced by main(), and qdec_int_handler().

00153 {
00154   qdec->CNT.pc = value;
00155   return qdec->CNT.pc;
00156 }

unsigned short int qdec_write_pc_top ( volatile avr32_qdec_t *  qdec,
unsigned short int  value 
)

Writes a value to the channel's QDEC Position Counter Top register.

Parameters:
qdec Pointer to the QDEC instance to access.
value Value to write to the RC register.
Return values:
>=0 Written value.
QDEC_INVALID_ARGUMENT Invalid argument(s).

Definition at line 165 of file qdec.c.

00166 {
00167   qdec->TOP.pctop = value;
00168 
00169   return qdec->TOP.pctop;  
00170 }

unsigned short int qdec_write_rc_cmp ( volatile avr32_qdec_t *  qdec,
unsigned short int  value 
)

Writes a value to the channel's QDEC Revolution Counter Compare register.

Parameters:
qdec Pointer to the QDEC instance to access.
value Value to write to the RC register.
Return values:
>=0 Written value.
QDEC_INVALID_ARGUMENT Invalid argument(s).

Definition at line 172 of file qdec.c.

Referenced by main().

00173 {
00174   qdec->CMP.rccmp = value;
00175 
00176   return qdec->CMP.rccmp;  
00177 }

unsigned short int qdec_write_rc_cnt ( volatile avr32_qdec_t *  qdec,
unsigned short int  value 
)

Write value of the channel's QDEC Revolution Current Counter register.

Parameters:
qdec Pointer to the QDEC instance to access.
value Value to write to the RC register.
Return values:
>=0 Status register value.

Definition at line 146 of file qdec.c.

Referenced by main(), and qdec_int_handler().

00147 {
00148   qdec->CNT.rc = value; 
00149   return 0;
00150 }

unsigned short int qdec_write_rc_top ( volatile avr32_qdec_t *  qdec,
unsigned short int  value 
)

Writes a value to the channel's QDEC Revolution Counter Top register.

Parameters:
qdec Pointer to the QDEC instance to access.
value Value to write to the RC register.
Return values:
>=0 Written value.

Definition at line 158 of file qdec.c.

00159 {
00160   qdec->TOP.rctop = value;
00161   
00162   return qdec->TOP.rctop;  
00163 }


Generated on Fri Feb 19 02:26:13 2010 for AVR32 - QDEC Driver by  doxygen 1.5.5