00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include <avr32/io.h>
00048 #include "compiler.h"
00049 #include "ast.h"
00050
00051 int ast_is_busy(volatile avr32_ast_t *ast)
00052 {
00053 return (ast->sr & AVR32_AST_SR_BUSY_MASK) != 0;
00054 }
00055
00056 int ast_is_clkbusy(volatile avr32_ast_t *ast)
00057 {
00058 return (ast->sr & AVR32_AST_SR_CLKBUSY_MASK) != 0;
00059 }
00060
00061 int ast_init_calendar(volatile avr32_ast_t *ast,
00062 unsigned char osc_type,
00063 unsigned char psel,
00064 ast_calendar_t ast_calendar)
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
00072 ast->cr = AST_MODE_CALENDAR << AVR32_AST_CR_CAL_OFFSET |
00073 psel << AVR32_AST_CR_PSEL_OFFSET ;
00074
00075
00076 while (ast_is_busy(ast));
00077
00078
00079 ast_set_calendar_value(ast, ast_calendar);
00080
00081 return 1;
00082 }
00083
00084 int ast_init_counter(volatile avr32_ast_t *ast,
00085 unsigned char osc_type,
00086 unsigned char psel,
00087 unsigned long ast_counter)
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
00095 ast->cr = AST_MODE_COUNTER << AVR32_AST_CR_CAL_OFFSET |
00096 psel << AVR32_AST_CR_PSEL_OFFSET ;
00097
00098
00099 while (ast_is_busy(ast));
00100
00101
00102 ast_set_counter_value(ast, ast_counter);
00103
00104 return 1;
00105 }
00106
00107
00108 void ast_enable(volatile avr32_ast_t *ast)
00109 {
00110
00111 while (ast_is_busy(ast));
00112
00113 ast->cr |= AVR32_AST_CR_EN_MASK;
00114
00115 while (ast_is_busy(ast));
00116 }
00117
00118 void ast_set_calendar_value(volatile avr32_ast_t *ast,
00119 ast_calendar_t ast_calendar)
00120 {
00121
00122 while (ast_is_busy(ast));
00123
00124 ast->calv = ast_calendar.field;
00125
00126 while (ast_is_busy(ast));
00127 }
00128
00129 void ast_set_counter_value(volatile avr32_ast_t *ast,
00130 unsigned long ast_counter)
00131 {
00132
00133 while (ast_is_busy(ast));
00134
00135 ast->cv = ast_counter;
00136
00137 while (ast_is_busy(ast));
00138 }
00139
00140
00141 ast_calendar_t ast_get_calendar_value(volatile avr32_ast_t *ast)
00142 {
00143 ast_calendar_t ast_calendar;
00144 ast_calendar.field = ast->calv;
00145 return ast_calendar;
00146 }
00147
00148 unsigned long ast_get_counter_value(volatile avr32_ast_t *ast)
00149 {
00150 return ast->cv;
00151 }
00152
00153 void ast_set_alarm0_value(volatile avr32_ast_t *ast,
00154 ast_calendar_t ast_alarm)
00155 {
00156
00157 ast->ar0 = ast_alarm.field;
00158 }
00159
00160 void ast_set_alarm1_value(volatile avr32_ast_t *ast,
00161 ast_calendar_t ast_alarm)
00162 {
00163
00164 ast->ar1 = ast_alarm.field;
00165 }
00166
00167 void ast_enable_alarm0(volatile avr32_ast_t *ast)
00168 {
00169
00170 while (ast_is_busy(ast));
00171
00172 ast->eve |= AVR32_AST_EVE_ALARM0_MASK;
00173
00174 while (ast_is_busy(ast));
00175 }
00176
00177 void ast_disable_alarm0(volatile avr32_ast_t *ast)
00178 {
00179
00180 while (ast_is_busy(ast));
00181
00182 ast->evd |= AVR32_AST_EVE_ALARM0_MASK;
00183
00184 while (ast_is_busy(ast));
00185 }
00186
00187 void ast_enable_alarm1(volatile avr32_ast_t *ast)
00188 {
00189
00190 while (ast_is_busy(ast));
00191
00192 ast->eve |= AVR32_AST_EVE_ALARM1_MASK;
00193
00194 while (ast_is_busy(ast));
00195 }
00196
00197 void ast_disable_alarm1(volatile avr32_ast_t *ast)
00198 {
00199
00200 while (ast_is_busy(ast));
00201
00202 ast->evd |= AVR32_AST_EVE_ALARM1_MASK;
00203
00204 while (ast_is_busy(ast));
00205 }
00206
00207 void ast_set_periodic0_value(volatile avr32_ast_t *ast,
00208 avr32_ast_pir0_t pir)
00209 {
00210
00211 ast->PIR0 = pir;
00212 }
00213
00214 void ast_set_periodic1_value(volatile avr32_ast_t *ast,
00215 avr32_ast_pir1_t pir)
00216 {
00217
00218 ast->PIR1 = pir;
00219 }
00220
00221 void ast_enable_periodic0(volatile avr32_ast_t *ast)
00222 {
00223
00224 while (ast_is_busy(ast));
00225
00226 ast->eve |= AVR32_AST_EVE_PER0_MASK;
00227
00228 while (ast_is_busy(ast));
00229 }
00230
00231 void ast_disable_periodic0(volatile avr32_ast_t *ast)
00232 {
00233
00234 while (ast_is_busy(ast));
00235
00236 ast->evd |= AVR32_AST_EVE_PER0_MASK;
00237
00238 while (ast_is_busy(ast));
00239 }
00240
00241 void ast_enable_periodic1(volatile avr32_ast_t *ast)
00242 {
00243
00244 while (ast_is_busy(ast));
00245
00246 ast->eve |= AVR32_AST_EVE_PER1_MASK;
00247
00248 while (ast_is_busy(ast));
00249 }
00250
00251 void ast_disable_periodic1(volatile avr32_ast_t *ast)
00252 {
00253
00254 while (ast_is_busy(ast));
00255
00256 ast->evd |= AVR32_AST_EVE_PER0_MASK;
00257
00258 while (ast_is_busy(ast));
00259 }
00260