Atmel Software Framework

interrupt_usart_example.c File Reference

Example of an interrupt-driven USART communication.

Copyright (c) 2009-2011 Atmel Corporation. All rights reserved.

#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "print_funcs.h"
#include "intc.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"
#include "conf_example.h"




int main (void)
 The main function. More...
static void usart_int_handler (void)
 The USART interrupt handler. More...


Referenced by main().


Referenced by main(), and usart_int_handler().


Referenced by main().


Referenced by main().


Referenced by main().


Referenced by main().


Referenced by main().


Referenced by main().

int main ( void  )

The main function.

It sets up the USART module on EXAMPLE_USART. The terminal settings are 57600 8N1. Then it sets up the interrupt handler and waits for a USART interrupt to trigger.

We have nothing left to do in the main, so we may switch to a device sleep mode: we just need to be sure that the USART module will be still be active in the chosen sleep mode. The sleep mode to use is the FROZEN sleep mode: in this mode the PB clocks are still active (so the USART module which is on the Peripheral Bus will still be

active while the CPU and HSB will be stopped).

Modules communicating with external circuits should normally be disabled before entering a sleep mode that will stop the module

operation: this is not the case for the FROZEN sleep mode.

When the USART interrupt occurs, this will wake the CPU up which will then execute the interrupt handler code then come back to the while(1) loop below to execute the sleep instruction again.

References usart_options_t::baudrate, Disable_global_interrupt, Enable_global_interrupt, EXAMPLE_TARGET_PBACLK_FREQ_HZ, EXAMPLE_USART, EXAMPLE_USART_BAUDRATE, EXAMPLE_USART_IRQ, EXAMPLE_USART_RX_FUNCTION, EXAMPLE_USART_RX_PIN, EXAMPLE_USART_TX_FUNCTION, EXAMPLE_USART_TX_PIN, FOSC0, gpio_enable_module(), INTC_init_interrupts(), INTC_register_interrupt(), pcl_configure_clocks(), pcl_dfll_freq_param, PCL_OSC0, pcl_switch_to_osc(), print(), SLEEP, USART_1_STOPBIT, USART_GPIO_MAP, usart_init_rs232(), usart_int_handler(), USART_NO_PARITY, USART_NORMAL_CHMODE, and USART_OPTIONS.

static void usart_int_handler ( void  )

The USART interrupt handler.

The `__attribute__((interrupt))' (under GNU GCC for AVR32) and `__interrupt' (under IAR Embedded Workbench for Atmel AVR32) C function attributes are used to manage the `rete' instruction.

References c, EXAMPLE_USART, usart_read_char(), and usart_write_char().

Referenced by main().