Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Real Time Counter Driver

This is a basic driver for the Real Time Counter (RTC).

The RTC is used to generate interrupts periodically for both the CPU frequency and the interrupt self-diagnostic routines. Depending on the specific device, an RTC or an RTC32 will be used. In both cases the RTC is clocked independently from the CPU with a 32.768 kHz oscillator scaled down to 1024 Hz.

The interrupt period can be configured in the driver through CLASSB_RTC_INT_PERIOD. Further, the RTC module is setup with classb_rtc_setup(). Note that interrupts should be enabled in the main application with sei().

Note that it is possible to use a different RTC driver. The only requirement is that it defines the constants for the interrupt period CLASSB_RTC_INT_PERIOD and the RTC frequency CLASSB_RTC_FREQ.

Functions

void classb_rtc_callback (uint32_t time)
 This is the RTC compare interrupt. More...
 

RTC Settings and Class B Interface.

These two constants give information about the RTC to the Class B tests.

Therefore, they need to be defined with correct values. As long as these are defined, any RTC driver can be used.

#define CLASSB_RTC_INT_PERIOD   2048UL
 RTC interrupt period. More...
 
#define CLASSB_RTC_FREQ   1024UL
 RTC frequency. More...
 

Test declarations.

These symbols set which Class B tests are included in the RTC interrupt, and can be defined at the compiler level or in this file.

#define CLASSB_FREQ_TEST
 Test for the CPU frequency. More...
 
#define CLASSB_INT_MON
 Interrupt monitor. More...
 

Compatibility macros for RTC and RTC32.

Depending on the XMEGA device there will be a 16- or 32-bits RTC.

To make this transparent we define the following constants.

#define RTC_TEST   RTC32
 Name of the RTC module. More...
 
#define RTC_TEST_START_bm   RTC32_ENABLE_bm
 Bit mask used to start RTC. More...
 
#define RTC_TEST_COMPINTLVL_LO_gc   RTC32_COMPINTLVL_LO_gc
 Compare interrupt level group configuration. More...
 
#define RTC_TEST_COMPINTLVL_OFF_gc   RTC32_COMPINTLVL_OFF_gc
 Compare interrupt disable group configuration. More...
 
#define RTC_TEST_COMPIF_bm   RTC32_COMPIF_bm
 Compare interrupt flag bit mask. More...
 
#define RTC_TEST_COMP_vect   RTC32_COMP_vect
 Compare interrupt vector. More...
 
#define RTC_TEST_OVFIF_bm   RTC32_OVFIF_bm
 Overflow Interrupt Flag bit mask. More...
 

#define CLASSB_FREQ_TEST

Test for the CPU frequency.

#define CLASSB_INT_MON

Interrupt monitor.

#define CLASSB_RTC_FREQ   1024UL

RTC frequency.

This gives information to the Class B tests. However, the RTC frequency is hard coded in this driver to 1024 Hz. More details in classb_rtc_setup().

#define CLASSB_RTC_INT_PERIOD   2048UL

RTC interrupt period.

This constant is used to configure the period of the RTC compare interrupt. In addition, it is used in the Class B tests. An example value is 2048UL.

Note
This is a 16- or 32-bit value depending on the RTC hardware module.

Referenced by classb_rtc_callback(), and oven_classb_init_tests().

#define RTC_TEST   RTC32

Name of the RTC module.

Referenced by classb_wdt_test().

#define RTC_TEST_COMP_vect   RTC32_COMP_vect

Compare interrupt vector.

#define RTC_TEST_COMPIF_bm   RTC32_COMPIF_bm

Compare interrupt flag bit mask.

#define RTC_TEST_COMPINTLVL_LO_gc   RTC32_COMPINTLVL_LO_gc

Compare interrupt level group configuration.

#define RTC_TEST_COMPINTLVL_OFF_gc   RTC32_COMPINTLVL_OFF_gc

Compare interrupt disable group configuration.

#define RTC_TEST_OVFIF_bm   RTC32_OVFIF_bm

Overflow Interrupt Flag bit mask.

Referenced by classb_wdt_test().

#define RTC_TEST_START_bm   RTC32_ENABLE_bm

Bit mask used to start RTC.

Referenced by classb_wdt_test().

void classb_rtc_callback ( uint32_t  time)

This is the RTC compare interrupt.

Actions required in Class B tests are implemented as callbacks. Note that this requires a number of symbols to be defined, either in a header file or at the compiler level.

It is possible to add user-defined code to the RTC interrupt through CLASSB_ACTIONS_RTC().

Parameters
timeTime parameter passed by RTC driver. Unused here.

References CLASSB_ACTIONS_RTC, classb_freq_callback(), classb_intmon_callback(), CLASSB_RTC_INT_PERIOD, and rtc_set_alarm_relative().

Referenced by oven_classb_init_tests().