Definition in file rtc_example.c.
#include <avr32/io.h>
#include "intc.h"
#include "board.h"
#include "compiler.h"
#include "rtc.h"
#include "usart.h"
#include "gpio.h"
#include "pm.h"
Go to the source code of this file.
Defines | |
USART Settings | |
#define | EXAMPLE_USART (&AVR32_USART1) |
#define | EXAMPLE_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION |
#define | EXAMPLE_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN |
#define | EXAMPLE_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION |
#define | EXAMPLE_USART_TX_PIN AVR32_USART1_TXD_0_0_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. | |
void | rtc_irq (void) |
Variables | |
static volatile int | print_sec = 1 |
static int | sec = 0 |
#define EXAMPLE_USART (&AVR32_USART1) |
#define EXAMPLE_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION |
#define EXAMPLE_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN |
#define EXAMPLE_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION |
#define EXAMPLE_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN |
int main | ( | void | ) |
main function : do init and loop (poll if configured so)
Definition at line 184 of file rtc_example.c.
References EXAMPLE_USART, EXAMPLE_USART_RX_FUNCTION, EXAMPLE_USART_RX_PIN, EXAMPLE_USART_TX_FUNCTION, EXAMPLE_USART_TX_PIN, print_i(), print_sec, rtc_enable(), rtc_enable_interrupt(), rtc_init(), rtc_irq(), RTC_OSC_32KHZ, RTC_PSEL_32KHZ_1HZ, rtc_set_top_value(), and sec.
00185 { 00186 char temp[20]; 00187 char *ptemp; 00188 00189 static const gpio_map_t USART_GPIO_MAP = 00190 { 00191 {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION}, 00192 {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION} 00193 }; 00194 00195 // USART options 00196 static const usart_options_t USART_OPTIONS = 00197 { 00198 .baudrate = 57600, 00199 .charlength = 8, 00200 .paritytype = USART_NO_PARITY, 00201 .stopbits = USART_1_STOPBIT, 00202 .channelmode = 0 00203 }; 00204 00205 pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 00206 00207 // Assign GPIO pins to USART0. 00208 gpio_enable_module(USART_GPIO_MAP, 00209 sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0])); 00210 00211 // Initialize USART in RS232 mode at 12MHz. 00212 usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, 12000000); 00213 00214 // Welcome sentence 00215 usart_write_line(EXAMPLE_USART, "\x1B[2J\x1B[H\r\nATMEL\r\n"); 00216 usart_write_line(EXAMPLE_USART, "AVR32 UC3 - RTC example\r\n"); 00217 00218 usart_write_line(EXAMPLE_USART, "RTC 32 KHz oscillator program test.\r\n"); 00219 00220 // Disable all interrupts. */ 00221 Disable_global_interrupt(); 00222 00223 // The INTC driver has to be used only for GNU GCC for AVR32. 00224 #if __GNUC__ 00225 // Initialize interrupt vectors. 00226 INTC_init_interrupts(); 00227 00228 // Register the RTC interrupt handler to the interrupt controller. 00229 INTC_register_interrupt(&rtc_irq, AVR32_RTC_IRQ, AVR32_INTC_INT0); 00230 #endif 00231 00232 // Initialize the RTC 00233 if (!rtc_init(&AVR32_RTC, RTC_OSC_32KHZ, RTC_PSEL_32KHZ_1HZ)) 00234 { 00235 usart_write_line(&AVR32_USART0, "Error initializing the RTC\r\n"); 00236 while(1); 00237 } 00238 // Set top value to 0 to generate an interrupt every seconds */ 00239 rtc_set_top_value(&AVR32_RTC, 0); 00240 // Enable the interrupts 00241 rtc_enable_interrupt(&AVR32_RTC); 00242 // Enable the RTC 00243 rtc_enable(&AVR32_RTC); 00244 00245 // Enable global interrupts 00246 Enable_global_interrupt(); 00247 00248 while(1) 00249 { 00250 if (print_sec) 00251 { 00252 // Set cursor to the position (1; 5) 00253 usart_write_line(EXAMPLE_USART, "\x1B[5;1H"); 00254 ptemp = print_i(temp, sec); 00255 usart_write_line(EXAMPLE_USART, "Timer: "); 00256 usart_write_line(EXAMPLE_USART, ptemp); 00257 usart_write_line(EXAMPLE_USART, "s"); 00258 print_sec = 0; 00259 } 00260 } 00261 }
char* print_i | ( | char * | str, | |
int | n | |||
) |
print_i function : convert the given number to an ASCII decimal representation.
Definition at line 167 of file rtc_example.c.
Referenced by main().
00168 { 00169 int i = 10; 00170 00171 str[i] = '\0'; 00172 do 00173 { 00174 str[--i] = '0' + n%10; 00175 n /= 10; 00176 }while(n); 00177 00178 return &str[i]; 00179 }
void rtc_irq | ( | void | ) |
Definition at line 152 of file rtc_example.c.
References print_sec, rtc_clear_interrupt(), and sec.
Referenced by main().
00153 { 00154 // Increment the minutes counter 00155 sec++; 00156 00157 // clear the interrupt flag 00158 rtc_clear_interrupt(&AVR32_RTC); 00159 00160 // specify that an interrupt has been raised 00161 print_sec = 1; 00162 }
volatile int print_sec = 1 [static] |
int sec = 0 [static] |