Xmega IEC60730 Class B Library  1.0
 All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
interrupts/UserApplication.c File Reference

Detailed Description

This in an demo application for the interrupt monitor.

This application sets up a periodic interrupt: a timer/counter (TC) overflow interrupt. Further, the application configures the interrupt monitor in order to check that the frequency of the interrupt is correct. Two switch interrupts are configured. The first one changes the frequency of the TC interrupt. The second one deactivates the interrupt in the monitor.

Application note:
AVR1610: Guide to IEC60730 Class B compliance with XMEGA
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@a.nosp@m.tmel.nosp@m..com

Copyright (C) 2012 Atmel Corporation. All rights reserved.

Definition in file interrupts/UserApplication.c.

+ Include dependency graph for interrupts/UserApplication.c:

Go to the source code of this file.

Macros

Configuration parameters
#define F_TC_INT   30
 Frequency in Hz of the T/C interrupt.
#define TC_INT_TOL   15
 Tolerance for number of T/C interrupts (%).
#define TC_PRESCALER   8
 TC prescaler.
#define PER_CHANGE   4
 This multiplies the TC period in SW0 interrupt.
Internal parameters
#define TC_INT_COUNT_REF   (uint32_t) ( ( (1e0L * F_TC_INT) * CLASSB_RTC_INT_PERIOD) / CLASSB_RTC_FREQ )
 Reference for number of TC interrupts.
#define TC_PRESCALER_gc   LABEL(TC_CLKSEL_DIV, TC_PRESCALER, _gc)
 Label for the TC prescaler group configuration.
#define TC_FREQ   (uint32_t) (F_CPU/TC_PRESCALER)
 TC frequency.
#define TC_PER   (uint32_t) (TC_FREQ / F_TC_INT)
 TC period.
Board configuration
#define LEDPORT   PORTR
#define SWITCHPORT0   PORTE
#define SWITCHPORT1   PORTF
#define SWITCH0_INT0_vect   PORTE_INT0_vect
#define SWITCH1_INT0_vect   PORTF_INT0_vect
#define XPLAIN_PULLUP   0x00

Functions

void setup_led_switches_pmic ()
 Setup LEDs and buttons.
void setup_example_tc_interrupt ()
 Setup TC interrupt ! ! This sets up the TC so that it generates an overflow interrupt periodically. ! This interrupt will be checked with the interrupt monitor.
 ISR (SWITCH0_INT0_vect)
 Interrupt for SW0 press: change TC period.
 ISR (SWITCH1_INT0_vect)
 Interrupt for SW1 press: disable TC interrupt monitoring.
 ISR (TCD0_OVF_vect)
 TC overflow interrupt.

Variables

Global variables
NO_INIT volatile uint8_t classb_error
 Global error flag.

Macro Definition Documentation

#define F_TC_INT   30

Frequency in Hz of the T/C interrupt.

This is used to compute the value written to the PER register.

Definition at line 68 of file interrupts/UserApplication.c.

#define TC_PRESCALER   8

TC prescaler.

The TC runs on the system clock scaled down by this parameter. Possible values are 1, 2, 4, 8, 64, 256 or 1024.

Definition at line 78 of file interrupts/UserApplication.c.

#define TC_FREQ   (uint32_t) (F_CPU/TC_PRESCALER)

TC frequency.

The frequency of the TC is F_CPU divided by the prescaling factor.

Definition at line 99 of file interrupts/UserApplication.c.

#define TC_PER   (uint32_t) (TC_FREQ / F_TC_INT)

TC period.

The 16-bit TC will generate an interrupt when the count reaches this value.

Definition at line 104 of file interrupts/UserApplication.c.

Referenced by ISR(), and setup_example_tc_interrupt().


Function Documentation

ISR ( SWITCH0_INT0_vect  )

Interrupt for SW0 press: change TC period.

This interrupt can be used to test the interrupt monitor. After pressing SW0 the period of the TC is changed, which means that the frequency of the TC interrupt is modified. This should be detected by the interrupt monitor, which should then set the global error flag classb_error.

Definition at line 208 of file interrupts/UserApplication.c.

References PER_CHANGE, and TC_PER.

ISR ( SWITCH1_INT0_vect  )

Interrupt for SW1 press: disable TC interrupt monitoring.

If the TC interrupt does not need to be monitored anymore the state of the interrupt can be changed to DISABLE.

Note:
This interrupt could be executed more than once because of button bouncing. If CLASSB_STRICT is defined the monitor would then set classb_error.

Definition at line 219 of file interrupts/UserApplication.c.

References classb_intmon_set_state(), DISABLE, and MY_INTERRUPT.

+ Here is the call graph for this function:

ISR ( TCD0_OVF_vect  )

TC overflow interrupt.

The interrupt counter is incremented by calling classb_intmon_increase(). After that an LED is toggled.

Definition at line 229 of file interrupts/UserApplication.c.

References classb_intmon_increase(), and MY_INTERRUPT.

+ Here is the call graph for this function: