This file provides an example for the AST on AVR32 UC3 devices.
Definition in file ast_example2.c.
#include <avr32/io.h>
#include "intc.h"
#include "board.h"
#include "compiler.h"
#include "ast.h"
#include "usart.h"
#include "gpio.h"
#include "power_clocks_lib.h"
Go to the source code of this file.
Defines | |
USART Settings | |
#define | EXAMPLE_USART (&AVR32_USART2) |
#define | EXAMPLE_USART_RX_FUNCTION AVR32_USART2_RXD_0_1_FUNCTION |
#define | EXAMPLE_USART_RX_PIN AVR32_USART2_RXD_0_1_PIN |
#define | EXAMPLE_USART_TX_FUNCTION AVR32_USART2_TXD_0_1_FUNCTION |
#define | EXAMPLE_USART_TX_PIN AVR32_USART2_TXD_0_1_PIN |
Functions | |
int | main (void) |
main function : do init and loop (poll if configured so) | |
char * | print_i (char *str, int n) |
print_i function : convert the given number to an ASCII decimal representation. |
#define EXAMPLE_USART (&AVR32_USART2) |
Definition at line 103 of file ast_example2.c.
#define EXAMPLE_USART_RX_FUNCTION AVR32_USART2_RXD_0_1_FUNCTION |
Definition at line 105 of file ast_example2.c.
#define EXAMPLE_USART_RX_PIN AVR32_USART2_RXD_0_1_PIN |
Definition at line 104 of file ast_example2.c.
#define EXAMPLE_USART_TX_FUNCTION AVR32_USART2_TXD_0_1_FUNCTION |
Definition at line 107 of file ast_example2.c.
#define EXAMPLE_USART_TX_PIN AVR32_USART2_TXD_0_1_PIN |
Definition at line 106 of file ast_example2.c.
int main | ( | void | ) |
main function : do init and loop (poll if configured so)
Definition at line 139 of file ast_example2.c.
References ast_disable_alarm0(), ast_enable(), ast_enable_alarm0(), ast_get_counter_value(), ast_init_counter(), AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_set_alarm0_value(), EXAMPLE_USART, EXAMPLE_USART_RX_FUNCTION, EXAMPLE_USART_RX_PIN, EXAMPLE_USART_TX_FUNCTION, EXAMPLE_USART_TX_PIN, ast_calendar_t::FIELD, and print_i().
00140 { 00141 char temp[20]; 00142 char *ptemp; 00143 ast_calendar_t ast_alarm; 00144 00145 static const gpio_map_t USART_GPIO_MAP = 00146 { 00147 {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION}, 00148 {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION} 00149 }; 00150 00151 // USART options 00152 static const usart_options_t USART_OPTIONS = 00153 { 00154 .baudrate = 57600, 00155 .charlength = 8, 00156 .paritytype = USART_NO_PARITY, 00157 .stopbits = USART_1_STOPBIT, 00158 .channelmode = 0 00159 }; 00160 00161 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP); 00162 00163 // Assign GPIO pins to USART0. 00164 gpio_enable_module(USART_GPIO_MAP, 00165 sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0])); 00166 00167 // Initialize USART in RS232 mode 00168 usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, FOSC0); 00169 00170 // Welcome sentence 00171 usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n"); 00172 usart_write_line(EXAMPLE_USART, "AVR32 UC3 - AST example 2\r\n"); 00173 usart_write_line(EXAMPLE_USART, "AST 32 KHz oscillator counter example.\r\n"); 00174 usart_write_line(EXAMPLE_USART, "Alarm0 wakeup from static sleep mode every second.\r\n"); 00175 00176 // Unsing counter mode and set it to 0 00177 unsigned long ast_counter = 0; 00178 00179 // Initialize the AST 00180 if (!ast_init_counter(&AVR32_AST, AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_counter)) 00181 { 00182 usart_write_line(EXAMPLE_USART, "Error initializing the AST\r\n"); 00183 while(1); 00184 } 00185 00186 // Alarm 0 sends a wakeup signal to the Power manager 00187 AVR32_AST.WER.alarm0=1; 00188 00189 // Enable the AST 00190 ast_enable(&AVR32_AST); 00191 00192 while(1) 00193 { 00194 // disable alarm 0 00195 ast_disable_alarm0(&AVR32_AST); 00196 00197 //ast_init_counter Set Alarm to current time+30 seconds 00198 ast_alarm.FIELD.sec = ast_alarm.FIELD.sec+1; 00199 ast_set_alarm0_value(&AVR32_AST,ast_alarm); 00200 00201 // Enable alarm 0 00202 ast_enable_alarm0(&AVR32_AST); 00203 00204 // Go into static sleep mode 00205 SLEEP(AVR32_PM_SMODE_STATIC); 00206 00207 // After wake up, clear the Alarm0 00208 AVR32_AST.SCR.alarm0=1; 00209 00210 // Toggle Led0 00211 gpio_tgl_gpio_pin(LED0_GPIO); 00212 00213 // Set cursor to the position (1; 6) 00214 usart_write_line(EXAMPLE_USART, "\x1B[6;1H"); 00215 ast_counter = ast_get_counter_value(&AVR32_AST); 00216 usart_write_line(EXAMPLE_USART, "Timer: "); 00217 ptemp = print_i(temp, ast_counter); 00218 usart_write_line(EXAMPLE_USART, ptemp); 00219 usart_write_line(EXAMPLE_USART, " sec "); 00220 } 00221 }
char* print_i | ( | char * | str, | |
int | n | |||
) |
print_i function : convert the given number to an ASCII decimal representation.
Definition at line 122 of file ast_example2.c.
00123 { 00124 int i = 10; 00125 00126 str[i] = '\0'; 00127 do 00128 { 00129 str[--i] = '0' + n%10; 00130 n /= 10; 00131 }while(n); 00132 00133 return &str[i]; 00134 }