AVR32 Asynchronous Timer (AST) driver module.
Definition in file ast.h.
#include "compiler.h"
#include <avr32/io.h>
Go to the source code of this file.
Data Structures | |
struct | ast_calendar_t |
Input when initializing AST in calendar mode. More... | |
Defines | |
AST Mode | |
#define | AST_MODE_CALENDAR 1 |
#define | AST_MODE_COUNTER 0 |
Oscillator Types | |
#define | AST_OSC_1KHZ 4 |
#define | AST_OSC_32KHZ 1 |
#define | AST_OSC_GCLK 3 |
#define | AST_OSC_PB 2 |
#define | AST_OSC_RC 0 |
Predefined PSEL Values | |
#define | AST_PSEL_32KHZ_1HZ 14 |
#define | AST_PSEL_RC_1_76HZ 15 |
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. | |
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. |
#define AST_MODE_CALENDAR 1 |
#define AST_MODE_COUNTER 0 |
#define AST_PSEL_32KHZ_1HZ 14 |
#define AST_PSEL_RC_1_76HZ 15 |
void ast_disable_alarm0 | ( | volatile avr32_ast_t * | ast | ) |
This function Disable the AST alarm0.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 177 of file ast.c.
References ast_is_busy().
Referenced by main().
00178 { 00179 // Wait until the ast CTRL register is up-to-date 00180 while (ast_is_busy(ast)); 00181 // Enable the RTC 00182 ast->evd |= AVR32_AST_EVE_ALARM0_MASK; 00183 // Wait until write is done 00184 while (ast_is_busy(ast)); 00185 }
void ast_disable_alarm1 | ( | volatile avr32_ast_t * | ast | ) |
This function Disable the AST alarm1.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 197 of file ast.c.
References ast_is_busy().
00198 { 00199 // Wait until the ast CTRL register is up-to-date 00200 while (ast_is_busy(ast)); 00201 // Enable the RTC 00202 ast->evd |= AVR32_AST_EVE_ALARM1_MASK; 00203 // Wait until write is done 00204 while (ast_is_busy(ast)); 00205 }
void ast_disable_periodic0 | ( | volatile avr32_ast_t * | ast | ) |
This function Disable the AST periodic0.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 231 of file ast.c.
References ast_is_busy().
00232 { 00233 // Wait until the ast CTRL register is up-to-date 00234 while (ast_is_busy(ast)); 00235 // Enable the RTC 00236 ast->evd |= AVR32_AST_EVE_PER0_MASK; 00237 // Wait until write is done 00238 while (ast_is_busy(ast)); 00239 }
void ast_disable_periodic1 | ( | volatile avr32_ast_t * | ast | ) |
This function Disable the AST periodic1.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 251 of file ast.c.
References ast_is_busy().
00252 { 00253 // Wait until the ast CTRL register is up-to-date 00254 while (ast_is_busy(ast)); 00255 // Enable the RTC 00256 ast->evd |= AVR32_AST_EVE_PER0_MASK; 00257 // Wait until write is done 00258 while (ast_is_busy(ast)); 00259 }
void ast_enable | ( | volatile avr32_ast_t * | ast | ) |
Enable the AST.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 108 of file ast.c.
References ast_is_busy().
Referenced by main().
00109 { 00110 // Wait until the ast CTRL register is up-to-date 00111 while (ast_is_busy(ast)); 00112 // Enable the RTC 00113 ast->cr |= AVR32_AST_CR_EN_MASK; 00114 // Wait until write is done 00115 while (ast_is_busy(ast)); 00116 }
void ast_enable_alarm0 | ( | volatile avr32_ast_t * | ast | ) |
This function Enable the AST alarm0.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 167 of file ast.c.
References ast_is_busy().
Referenced by main().
00168 { 00169 // Wait until the ast CTRL register is up-to-date 00170 while (ast_is_busy(ast)); 00171 // Enable the RTC 00172 ast->eve |= AVR32_AST_EVE_ALARM0_MASK; 00173 // Wait until write is done 00174 while (ast_is_busy(ast)); 00175 }
void ast_enable_alarm1 | ( | volatile avr32_ast_t * | ast | ) |
This function Enable the AST alarm1.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 187 of file ast.c.
References ast_is_busy().
00188 { 00189 // Wait until the ast CTRL register is up-to-date 00190 while (ast_is_busy(ast)); 00191 // Enable the RTC 00192 ast->eve |= AVR32_AST_EVE_ALARM1_MASK; 00193 // Wait until write is done 00194 while (ast_is_busy(ast)); 00195 }
void ast_enable_periodic0 | ( | volatile avr32_ast_t * | ast | ) |
This function Enable the AST periodic0.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 221 of file ast.c.
References ast_is_busy().
00222 { 00223 // Wait until the ast CTRL register is up-to-date 00224 while (ast_is_busy(ast)); 00225 // Enable the RTC 00226 ast->eve |= AVR32_AST_EVE_PER0_MASK; 00227 // Wait until write is done 00228 while (ast_is_busy(ast)); 00229 }
void ast_enable_periodic1 | ( | volatile avr32_ast_t * | ast | ) |
This function Enable the AST periodic1.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 241 of file ast.c.
References ast_is_busy().
00242 { 00243 // Wait until the ast CTRL register is up-to-date 00244 while (ast_is_busy(ast)); 00245 // Enable the RTC 00246 ast->eve |= AVR32_AST_EVE_PER1_MASK; 00247 // Wait until write is done 00248 while (ast_is_busy(ast)); 00249 }
ast_calendar_t ast_get_calendar_value | ( | volatile avr32_ast_t * | ast | ) |
This function returns the AST current calendar value.
ast | Base address of the AST (i.e. &AVR32_AST). |
Definition at line 141 of file ast.c.
References ast_calendar_t::field.
00142 { 00143 ast_calendar_t ast_calendar; 00144 ast_calendar.field = ast->calv; 00145 return ast_calendar; 00146 }
unsigned long ast_get_counter_value | ( | volatile avr32_ast_t * | ast | ) |
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.
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 |
Definition at line 61 of file ast.c.
References ast_is_busy(), ast_is_clkbusy(), AST_MODE_CALENDAR, and ast_set_calendar_value().
00065 { 00066 00067 while (ast_is_clkbusy(ast)); 00068 ast->clock = AVR32_AST_CLOCK_CEN_MASK | 00069 osc_type << AVR32_AST_CLOCK_CSSEL_OFFSET; 00070 00071 // Set the new AST configuration 00072 ast->cr = AST_MODE_CALENDAR << AVR32_AST_CR_CAL_OFFSET | 00073 psel << AVR32_AST_CR_PSEL_OFFSET ; 00074 00075 // Wait until the ast CTRL register is up-to-date 00076 while (ast_is_busy(ast)); 00077 00078 // Set the calendar 00079 ast_set_calendar_value(ast, ast_calendar); 00080 00081 return 1; 00082 }
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.
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 |
Definition at line 84 of file ast.c.
References ast_is_busy(), ast_is_clkbusy(), AST_MODE_COUNTER, and ast_set_counter_value().
Referenced by main().
00088 { 00089 00090 while (ast_is_clkbusy(ast)); 00091 ast->clock = AVR32_AST_CLOCK_CEN_MASK | 00092 osc_type << AVR32_AST_CLOCK_CSSEL_OFFSET; 00093 00094 // Set the new AST configuration 00095 ast->cr = AST_MODE_COUNTER << AVR32_AST_CR_CAL_OFFSET | 00096 psel << AVR32_AST_CR_PSEL_OFFSET ; 00097 00098 // Wait until the ast CTRL register is up-to-date 00099 while (ast_is_busy(ast)); 00100 00101 // Set the calendar 00102 ast_set_counter_value(ast, ast_counter); 00103 00104 return 1; 00105 }
void ast_set_alarm0_value | ( | volatile avr32_ast_t * | ast, | |
ast_calendar_t | ast_alarm | |||
) |
This function Set the AST alarm0 value.
ast | Base address of the AST (i.e. &AVR32_AST). | |
ast_alarm | AST alram0. |
Definition at line 153 of file ast.c.
References ast_calendar_t::field.
Referenced by main().
00155 { 00156 // Set the new val value 00157 ast->ar0 = ast_alarm.field; 00158 }
void ast_set_alarm1_value | ( | volatile avr32_ast_t * | ast, | |
ast_calendar_t | ast_alarm | |||
) |
This function Set the AST alarm1 value.
ast | Base address of the AST (i.e. &AVR32_AST). | |
ast_alarm | AST alram1. |
Definition at line 160 of file ast.c.
References ast_calendar_t::field.
00162 { 00163 // Set the new val value 00164 ast->ar1 = ast_alarm.field; 00165 }
void ast_set_calendar_value | ( | volatile avr32_ast_t * | ast, | |
ast_calendar_t | ast_calendar | |||
) |
This function sets the AST current calendar value.
ast | Base address of the AST (i.e. &AVR32_AST). | |
ast_calendar | Startup date |
Definition at line 118 of file ast.c.
References ast_is_busy(), and ast_calendar_t::field.
Referenced by ast_init_calendar().
00120 { 00121 // Wait until we can write into the VAL register 00122 while (ast_is_busy(ast)); 00123 // Set the new val value 00124 ast->calv = ast_calendar.field; 00125 // Wait until write is done 00126 while (ast_is_busy(ast)); 00127 }
void ast_set_counter_value | ( | volatile avr32_ast_t * | ast, | |
unsigned long | ast_counter | |||
) |
This function sets the AST current counter value.
ast | Base address of the AST (i.e. &AVR32_AST). | |
ast_counter | Startup counter value |
Definition at line 129 of file ast.c.
References ast_is_busy().
Referenced by ast_init_counter().
00131 { 00132 // Wait until we can write into the VAL register 00133 while (ast_is_busy(ast)); 00134 // Set the new val value 00135 ast->cv = ast_counter; 00136 // Wait until write is done 00137 while (ast_is_busy(ast)); 00138 }
void ast_set_periodic0_value | ( | volatile avr32_ast_t * | ast, | |
avr32_ast_pir0_t | pir | |||
) |
void ast_set_periodic1_value | ( | volatile avr32_ast_t * | ast, | |
avr32_ast_pir1_t | pir | |||
) |