ast.c File Reference


Detailed Description

AST driver for AVR32 UC3.

AVR32 Asynchronous Timer (AST) driver module.

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

Definition in file ast.c.

#include <avr32/io.h>
#include "compiler.h"
#include "scif_uc3c.h"
#include "ast.h"

Go to the source code of this file.

Functions

void ast_disable_alarm0 (volatile avr32_ast_t *ast)
 This function Disable the AST alarm0.
void ast_disable_alarm1 (volatile avr32_ast_t *ast)
 This function Disable the AST alarm1.
void ast_disable_periodic0 (volatile avr32_ast_t *ast)
 This function Disable the AST periodic0.
void ast_disable_periodic1 (volatile avr32_ast_t *ast)
 This function Disable the AST periodic1.
void ast_enable (volatile avr32_ast_t *ast)
 Enable the AST.
void ast_enable_alarm0 (volatile avr32_ast_t *ast)
 This function Enable the AST alarm0.
void ast_enable_alarm1 (volatile avr32_ast_t *ast)
 This function Enable the AST alarm1.
void ast_enable_periodic0 (volatile avr32_ast_t *ast)
 This function Enable the AST periodic0.
void ast_enable_periodic1 (volatile avr32_ast_t *ast)
 This function Enable the AST periodic1.
ast_calendar_t ast_get_calendar_value (volatile avr32_ast_t *ast)
 This function returns the AST current calendar value.
unsigned long ast_get_counter_value (volatile avr32_ast_t *ast)
 This function returns the AST current counter value.
int ast_init_calendar (volatile avr32_ast_t *ast, unsigned char osc_type, unsigned char psel, ast_calendar_t ast_calendar)
 This function will initialise the AST module in calendar Mode. If you use the 32 KHz oscillator, it will enable this module.
int ast_init_counter (volatile avr32_ast_t *ast, unsigned char osc_type, unsigned char psel, unsigned long ast_counter)
 This function will initialise the AST module in counter Mode. If you use the 32 KHz oscillator, it will enable this module.
int ast_is_busy (volatile avr32_ast_t *ast)
int ast_is_clkbusy (volatile avr32_ast_t *ast)
void ast_set_alarm0_value (volatile avr32_ast_t *ast, ast_calendar_t ast_alarm)
 This function Set the AST alarm0 value.
void ast_set_alarm1_value (volatile avr32_ast_t *ast, ast_calendar_t ast_alarm)
 This function Set the AST alarm1 value.
void ast_set_calendar_value (volatile avr32_ast_t *ast, ast_calendar_t ast_calendar)
 This function sets the AST current calendar value.
void ast_set_counter_value (volatile avr32_ast_t *ast, unsigned long ast_counter)
 This function sets the AST current counter value.
void ast_set_periodic0_value (volatile avr32_ast_t *ast, avr32_ast_pir0_t pir)
 This function Set the AST periodic0 value.
void ast_set_periodic1_value (volatile avr32_ast_t *ast, avr32_ast_pir1_t pir)
 This function Set the AST periodic1 value.


Function Documentation

void ast_disable_alarm0 ( volatile avr32_ast_t *  ast  ) 

This function Disable the AST alarm0.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 196 of file ast.c.

References ast_is_busy().

00197 {
00198   // Wait until the ast CTRL register is up-to-date
00199   while (ast_is_busy(ast));
00200   // Enable the RTC
00201   ast->evd |= AVR32_AST_EVE_ALARM0_MASK;
00202   // Wait until write is done
00203   while (ast_is_busy(ast));
00204 }

void ast_disable_alarm1 ( volatile avr32_ast_t *  ast  ) 

This function Disable the AST alarm1.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 216 of file ast.c.

References ast_is_busy().

00217 {
00218   // Wait until the ast CTRL register is up-to-date
00219   while (ast_is_busy(ast));
00220   // Enable the RTC
00221   ast->evd |= AVR32_AST_EVE_ALARM1_MASK;
00222   // Wait until write is done
00223   while (ast_is_busy(ast));
00224 }

void ast_disable_periodic0 ( volatile avr32_ast_t *  ast  ) 

This function Disable the AST periodic0.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 250 of file ast.c.

References ast_is_busy().

00251 {
00252   // Wait until the ast CTRL register is up-to-date
00253   while (ast_is_busy(ast));
00254   // Enable the RTC
00255   ast->evd |= AVR32_AST_EVE_PER0_MASK;
00256   // Wait until write is done
00257   while (ast_is_busy(ast));
00258 }

void ast_disable_periodic1 ( volatile avr32_ast_t *  ast  ) 

This function Disable the AST periodic1.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 270 of file ast.c.

References ast_is_busy().

00271 {
00272   // Wait until the ast CTRL register is up-to-date
00273   while (ast_is_busy(ast));
00274   // Enable the RTC
00275   ast->evd |= AVR32_AST_EVE_PER0_MASK;
00276   // Wait until write is done
00277   while (ast_is_busy(ast));
00278 }

void ast_enable ( volatile avr32_ast_t *  ast  ) 

Enable the AST.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 127 of file ast.c.

References ast_is_busy().

Referenced by main().

00128 {
00129   // Wait until the ast CTRL register is up-to-date
00130   while (ast_is_busy(ast));
00131   // Enable the RTC
00132   ast->cr |= AVR32_AST_CR_EN_MASK;
00133   // Wait until write is done
00134   while (ast_is_busy(ast));
00135 }

void ast_enable_alarm0 ( volatile avr32_ast_t *  ast  ) 

This function Enable the AST alarm0.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 186 of file ast.c.

References ast_is_busy().

00187 {
00188   // Wait until the ast CTRL register is up-to-date
00189   while (ast_is_busy(ast));
00190   // Enable the RTC
00191   ast->eve |= AVR32_AST_EVE_ALARM0_MASK;
00192   // Wait until write is done
00193   while (ast_is_busy(ast));
00194 }

void ast_enable_alarm1 ( volatile avr32_ast_t *  ast  ) 

This function Enable the AST alarm1.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 206 of file ast.c.

References ast_is_busy().

00207 {
00208   // Wait until the ast CTRL register is up-to-date
00209   while (ast_is_busy(ast));
00210   // Enable the RTC
00211   ast->eve |= AVR32_AST_EVE_ALARM1_MASK;
00212   // Wait until write is done
00213   while (ast_is_busy(ast));
00214 }

void ast_enable_periodic0 ( volatile avr32_ast_t *  ast  ) 

This function Enable the AST periodic0.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 240 of file ast.c.

References ast_is_busy().

00241 {
00242   // Wait until the ast CTRL register is up-to-date
00243   while (ast_is_busy(ast));
00244   // Enable the RTC
00245   ast->eve |= AVR32_AST_EVE_PER0_MASK;
00246   // Wait until write is done
00247   while (ast_is_busy(ast));
00248 }

void ast_enable_periodic1 ( volatile avr32_ast_t *  ast  ) 

This function Enable the AST periodic1.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).

Definition at line 260 of file ast.c.

References ast_is_busy().

00261 {
00262   // Wait until the ast CTRL register is up-to-date
00263   while (ast_is_busy(ast));
00264   // Enable the RTC
00265   ast->eve |= AVR32_AST_EVE_PER1_MASK;
00266   // Wait until write is done
00267   while (ast_is_busy(ast));
00268 }

ast_calendar_t ast_get_calendar_value ( volatile avr32_ast_t *  ast  ) 

This function returns the AST current calendar value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
Returns:
The AST current calendar value.

Definition at line 160 of file ast.c.

References ast_calendar_t::field.

Referenced by main().

00161 {
00162   ast_calendar_t ast_calendar;
00163   ast_calendar.field = ast->calv;
00164   return ast_calendar;
00165 }

unsigned long ast_get_counter_value ( volatile avr32_ast_t *  ast  ) 

This function returns the AST current counter value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
Returns:
The AST current counter value.

Definition at line 167 of file ast.c.

00168 {
00169   return ast->cv;
00170 }

int ast_init_calendar ( volatile avr32_ast_t *  ast,
unsigned char  osc_type,
unsigned char  psel,
ast_calendar_t  ast_calendar 
)

This function will initialise the AST module in calendar Mode. If you use the 32 KHz oscillator, it will enable this module.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
osc_type The oscillator you want to use. If you need a better accuracy, use the 32 KHz oscillator (i.e. AST_OSC_32KHZ).
psel The preselector value for the corresponding oscillator (4-bits). To obtain this value, you can use this formula: psel = log(Fosc/Fast)/log(2)-1, where Fosc is the frequency of the oscillator you are using (32 KHz or 115 KHz) and Fast the frequency desired.
ast_calendar Startup date
Returns:
1 if the initialisation succeds otherwize it will return 0.

Definition at line 62 of file ast.c.

References ast_is_busy(), ast_is_clkbusy(), AST_MODE_CALENDAR, AST_OSC_32KHZ, and ast_set_calendar_value().

Referenced by main().

00066 {
00067   scif_osc32_opt_t opt;
00068   opt.mode = SCIF_OSC_MODE_2PIN_CRYSTAL;
00069   opt.startup = AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC;
00070   
00071   // If we use the 32-kHz oscillator, we have to enable it first
00072   if (osc_type == AST_OSC_32KHZ)
00073   {
00074     scif_start_osc32(&opt,true);
00075   }
00076 
00077   while (ast_is_clkbusy(ast));
00078   ast->clock = AVR32_AST_CLOCK_CEN_MASK | 
00079                osc_type << AVR32_AST_CLOCK_CSSEL_OFFSET;
00080                
00081   // Set the new AST configuration
00082   ast->cr =   AST_MODE_CALENDAR << AVR32_AST_CR_CAL_OFFSET |
00083               psel << AVR32_AST_CR_PSEL_OFFSET ;
00084 
00085   // Wait until the ast CTRL register is up-to-date
00086   while (ast_is_busy(ast));
00087   
00088   // Set the calendar
00089   ast_set_calendar_value(ast, ast_calendar);
00090  
00091   return 1; 
00092 }

int ast_init_counter ( volatile avr32_ast_t *  ast,
unsigned char  osc_type,
unsigned char  psel,
unsigned long  ast_counter 
)

This function will initialise the AST module in counter Mode. If you use the 32 KHz oscillator, it will enable this module.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
osc_type The oscillator you want to use. If you need a better accuracy, use the 32 KHz oscillator (i.e. AST_OSC_32KHZ).
psel The preselector value for the corresponding oscillator (4-bits). To obtain this value, you can use this formula: psel = log(Fosc/Fast)/log(2)-1, where Fosc is the frequency of the oscillator you are using (32 KHz or 115 KHz) and Fast the frequency desired.
ast_counter Startup counter value
Returns:
1 if the initialisation succeds otherwize it will return 0.

Definition at line 94 of file ast.c.

References ast_is_busy(), ast_is_clkbusy(), AST_MODE_COUNTER, AST_OSC_32KHZ, and ast_set_counter_value().

00098 {
00099   scif_osc32_opt_t opt;
00100   opt.mode = SCIF_OSC_MODE_2PIN_CRYSTAL;
00101   opt.startup = AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC;
00102   
00103   // If we use the 32-kHz oscillator, we have to enable it first
00104   if (osc_type == AST_OSC_32KHZ)
00105   {
00106     scif_start_osc32(&opt,true);
00107   }
00108 
00109   while (ast_is_clkbusy(ast));
00110   ast->clock = AVR32_AST_CLOCK_CEN_MASK | 
00111                osc_type << AVR32_AST_CLOCK_CSSEL_OFFSET;
00112                
00113   // Set the new AST configuration
00114   ast->cr =   AST_MODE_COUNTER << AVR32_AST_CR_CAL_OFFSET |
00115               psel << AVR32_AST_CR_PSEL_OFFSET ;
00116 
00117   // Wait until the ast CTRL register is up-to-date
00118   while (ast_is_busy(ast));
00119   
00120   // Set the calendar
00121   ast_set_counter_value(ast, ast_counter);
00122  
00123   return 1; 
00124 }

int ast_is_busy ( volatile avr32_ast_t *  ast  ) 

int ast_is_clkbusy ( volatile avr32_ast_t *  ast  ) 

Definition at line 57 of file ast.c.

Referenced by ast_init_calendar(), and ast_init_counter().

00058 {
00059   return (ast->sr & AVR32_AST_SR_CLKBUSY_MASK) != 0;
00060 }

void ast_set_alarm0_value ( volatile avr32_ast_t *  ast,
ast_calendar_t  ast_alarm 
)

This function Set the AST alarm0 value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
ast_alarm AST alram0.

Definition at line 172 of file ast.c.

References ast_calendar_t::field.

00174 {
00175   // Set the new val value
00176   ast->ar0 = ast_alarm.field;
00177 }

void ast_set_alarm1_value ( volatile avr32_ast_t *  ast,
ast_calendar_t  ast_alarm 
)

This function Set the AST alarm1 value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
ast_alarm AST alram1.

Definition at line 179 of file ast.c.

References ast_calendar_t::field.

00181 {
00182   // Set the new val value
00183   ast->ar1 = ast_alarm.field;
00184 }

void ast_set_calendar_value ( volatile avr32_ast_t *  ast,
ast_calendar_t  ast_calendar 
)

This function sets the AST current calendar value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
ast_calendar Startup date

Definition at line 137 of file ast.c.

References ast_is_busy(), and ast_calendar_t::field.

Referenced by ast_init_calendar().

00139 {
00140   // Wait until we can write into the VAL register
00141   while (ast_is_busy(ast));
00142   // Set the new val value
00143   ast->calv = ast_calendar.field;
00144   // Wait until write is done
00145   while (ast_is_busy(ast));
00146 }

void ast_set_counter_value ( volatile avr32_ast_t *  ast,
unsigned long  ast_counter 
)

This function sets the AST current counter value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
ast_counter Startup counter value

Definition at line 148 of file ast.c.

References ast_is_busy().

Referenced by ast_init_counter().

00150 {
00151   // Wait until we can write into the VAL register
00152   while (ast_is_busy(ast));
00153   // Set the new val value
00154   ast->cv = ast_counter;
00155   // Wait until write is done
00156   while (ast_is_busy(ast));
00157 }

void ast_set_periodic0_value ( volatile avr32_ast_t *  ast,
avr32_ast_pir0_t  pir 
)

This function Set the AST periodic0 value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
pir AST periodic0.

Definition at line 226 of file ast.c.

00228 {
00229   // Set the new val value
00230   ast->PIR0 = pir;
00231 }

void ast_set_periodic1_value ( volatile avr32_ast_t *  ast,
avr32_ast_pir1_t  pir 
)

This function Set the AST periodic1 value.

Parameters:
ast Base address of the AST (i.e. &AVR32_AST).
pir AST periodic1.

Definition at line 233 of file ast.c.

00235 {
00236   // Set the new val value
00237   ast->PIR1 = pir;
00238 }


Generated on Thu Dec 17 19:57:58 2009 for AVR32 - AST Driver by  doxygen 1.5.5