This file provides an example for the AST on AVR32 UC3 devices.
Definition in file ast_example1.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) |
#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 |
int main | ( | void | ) |
main function : do init and loop (poll if configured so)
Definition at line 139 of file ast_example1.c.
References ast_enable(), ast_get_calendar_value(), ast_init_calendar(), AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, 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 00144 static const gpio_map_t USART_GPIO_MAP = 00145 { 00146 {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION}, 00147 {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION} 00148 }; 00149 00150 // USART options 00151 static const usart_options_t USART_OPTIONS = 00152 { 00153 .baudrate = 57600, 00154 .charlength = 8, 00155 .paritytype = USART_NO_PARITY, 00156 .stopbits = USART_1_STOPBIT, 00157 .channelmode = 0 00158 }; 00159 00160 // switch main clock to external oscillator 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 message 00171 usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n"); 00172 usart_write_line(EXAMPLE_USART, "AVR32 UC3 - AST example\r\n"); 00173 00174 usart_write_line(EXAMPLE_USART, "AST 32 KHz oscillator program test.\r\n"); 00175 00176 ast_calendar_t ast_calendar; 00177 ast_calendar.FIELD.sec = 0; 00178 ast_calendar.FIELD.min = 15; 00179 ast_calendar.FIELD.hour = 12; 00180 ast_calendar.FIELD.day = 5; 00181 ast_calendar.FIELD.month= 6; 00182 ast_calendar.FIELD.year = 9; 00183 00184 // Initialize the AST 00185 if (!ast_init_calendar(&AVR32_AST, AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_calendar)) 00186 { 00187 usart_write_line(EXAMPLE_USART, "Error initializing the AST\r\n"); 00188 while(1); 00189 } 00190 // Enable the AST 00191 ast_enable(&AVR32_AST); 00192 00193 volatile int i; 00194 while(1) 00195 { 00196 // slow down operations 00197 for ( i=0 ; i < 10000 ; i++); 00198 gpio_tgl_gpio_pin(LED0_GPIO); 00199 00200 // Set cursor to the position (1; 5) 00201 usart_write_line(EXAMPLE_USART, "\x1B[5;1H"); 00202 ast_calendar = ast_get_calendar_value(&AVR32_AST); 00203 usart_write_line(EXAMPLE_USART, "Timer: "); 00204 ptemp = print_i(temp, ast_calendar.FIELD.sec); 00205 usart_write_line(EXAMPLE_USART, ptemp); 00206 usart_write_line(EXAMPLE_USART, " sec "); 00207 } 00208 }
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_example1.c.
Referenced by main().
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 }