# RTC Configuration

The application demonstration is explained as follows. This application demonstrates only three modes of tamper detection in SAM L22 Xplained Pro. The procedure for testing active layer protection is explained in section Active Layer Protection.

Before entering into the application demonstration, the basic condition in which the device SAM L22 is configured is explained as follows. If the user needs variations in the basic configuration files, which are to be changed, this is explained as follows.

1. 1.The RTC is configured in Clock/calendar mode (mode 2) operating at 32.768kHz external oscillator. This mode is selected to keep track of the time and get the timestamp value easily.
2. 2.The application allows user to set time; this includes date also. The application has current time and date set as 12:59:50 and 31/12/2012. The user can configure current time by changing the following macros in the header file example.h
#define YEAR    2012
#define MONTH    12
#define DAY      31
#define HOUR     11
#define MINUTE   59
#define SECOND   50
#define TIME_PM  false
Note: time.pm is not applicable if the RTC is configured for 24-hours clock mode
3. 3.This application is configured in 12-hours clock mode. In order to configure for 24-hours clock mode, assign ‘true’ to the variable ‘config_rtc_calendar.clock_24h’ as shown below.
config_rtc_calendar.clock_24h = true;
Note: For 24-hours clock mode, the macro TIME_PM available in the header file example.h doesn't need to be defined and all the code statements related to the AM/PM settings can be removed.
4. 4.The SAM L22 has five dedicated pins RTC/IN [0, 1…4] for tamper detection. User Switch SW0 available in the Xplained Pro board, connected to RTC/IN [4] pin, is used to provide tamper input. The tamper input pin can be changed as per user’s board requirements. The following macro should be changed corresponding to the tamper input pin:
#define TAMPER_INPUT_PIN   4

While configuring some other tamper input pin, ensure that the pull is enabled and the pin is configured as input.

This application is configured in such a way that the tamper is detected if there occurs a rising edge on the pin RTC/IN [4]. In order to configure for falling edge, change the level as shown below in both the functions, configure_tamper_wake() and configure_tamper_capture().

config_rtc_tamper.in_cfg[4].level = RTC_TAMPER_LEVEL_FALLING;
5. 5.As mentioned earlier, when the tamper is enabled in capture mode, the RTC takes the timestamp of the clock register. The clock register value is converted into time value and it is available in the global structure struct tamper_time.