Microchip® Advanced Software Framework

rtc_tamper.h File Reference

SAM RTC Driver (Tamper)

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

Data Structures

struct  rtc_tamper_config
 RTC Tamper configuration structure. More...
 
struct  rtc_tamper_input_config
 RTC tamper input configuration structure. More...
 

Functions

RTC Tamper Detection
static void rtc_tamper_get_config_defaults (struct rtc_tamper_config *const config)
 Gets the RTC tamper default configurations. More...
 
enum status_code rtc_tamper_set_config (struct rtc_module *const module, struct rtc_tamper_config *const tamper_cfg)
 
static uint32_t rtc_tamper_get_detect_flag (struct rtc_module *const module)
 Retrieves the RTC tamper detection status. More...
 
static void rtc_tamper_clear_detect_flag (struct rtc_module *const module, const uint32_t detect_flags)
 Clears RTC tamper detection flag. More...
 
#define RTC_TAMPER_DETECT_ID0   (1UL << 0)
 RTC tamper ID0 detection bitmask. More...
 
#define RTC_TAMPER_DETECT_ID1   (1UL << 1)
 RTC tamper ID1 detection bitmask. More...
 
#define RTC_TAMPER_DETECT_ID2   (1UL << 2)
 RTC tamper ID2 detection bitmask. More...
 
#define RTC_TAMPER_DETECT_ID3   (1UL << 3)
 RTC tamper ID3 detection bitmask. More...
 
#define RTC_TAMPER_DETECT_ID4   (1UL << 4)
 RTC tamper ID4 detection bitmask. More...
 
#define RTC_TAMPER_DETECT_EVT   (1UL << 5)
 RTC tamper input event detection bitmask. More...
 
enum  rtc_tamper_active_layer_freq_divider {
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_2 = RTC_MODE0_CTRLB_ACTF_DIV2,
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_4 = RTC_MODE0_CTRLB_ACTF_DIV4,
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_8 = RTC_MODE0_CTRLB_ACTF_DIV8,
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_16 = RTC_MODE0_CTRLB_ACTF_DIV16,
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_32 = RTC_MODE0_CTRLB_ACTF_DIV32,
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_64 = RTC_MODE0_CTRLB_ACTF_DIV64,
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_128 = RTC_MODE0_CTRLB_ACTF_DIV128,
  RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_256 = RTC_MODE0_CTRLB_ACTF_DIV256
}
 RTC tamper active layer frequency divider. More...
 
enum  rtc_tamper_debounce_freq_divider {
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_2 = RTC_MODE0_CTRLB_DEBF_DIV2,
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_4 = RTC_MODE0_CTRLB_DEBF_DIV4,
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_8 = RTC_MODE0_CTRLB_DEBF_DIV8,
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_16 = RTC_MODE0_CTRLB_DEBF_DIV16,
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_32 = RTC_MODE0_CTRLB_DEBF_DIV32,
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_64 = RTC_MODE0_CTRLB_DEBF_DIV64,
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_128 = RTC_MODE0_CTRLB_DEBF_DIV128,
  RTC_TAMPER_DEBOUNCE_FREQ_DIV_256 = RTC_MODE0_CTRLB_DEBF_DIV256
}
 RTC tamper debounce frequency divider. More...
 
enum  rtc_tamper_input_action {
  RTC_TAMPER_INPUT_ACTION_OFF = RTC_TAMPCTRL_IN0ACT_OFF,
  RTC_TAMPER_INPUT_ACTION_WAKE = RTC_TAMPCTRL_IN0ACT_WAKE,
  RTC_TAMPER_INPUT_ACTION_CAPTURE = RTC_TAMPCTRL_IN0ACT_CAPTURE,
  RTC_TAMPER_INPUT_ACTION_ACTL = RTC_TAMPCTRL_IN0ACT_ACTL
}
 RTC tamper input action. More...
 
enum  rtc_tamper_level_sel {
  RTC_TAMPER_LEVEL_FALLING = (0),
  RTC_TAMPER_LEVEL_RISING = (1)
}
 RTC tamper input level select. More...
 
enum  rtc_tamper_debounce_seq {
  RTC_TAMPER_DEBOUNCE_SYNC,
  RTC_TAMPER_DEBOUNCE_ASYNC,
  RTC_TAMPER_DEBOUNCE_MAJORITY
}
 RTC tamper debounce sequential. More...
 

#define RTC_TAMPER_DETECT_EVT   (1UL << 5)

RTC tamper input event detection bitmask.

Referenced by rtc_tamper_clear_detect_flag(), and rtc_tamper_get_detect_flag().

#define RTC_TAMPER_DETECT_ID0   (1UL << 0)

RTC tamper ID0 detection bitmask.

RTC Tamper Detect

The RTC provides several selectable polarity external inputs (INn) that can be used for tamper detection. When detect, tamper inputs support the four actions:

  • Off
  • Wake
  • Capture
  • Active layer protection
Note
The Active Layer Protection is a means of detecting broken traces on the PCB provided by RTC. In this mode an RTC output signal is routed over critical components on the board and fed back to one of the RTC inputs. The input and output signals are compared and a tamper condition is detected when they do not match.

Separate debouncers are embedded for each external input. The detection time depends on whether the debouncer operates synchronously or asynchronously, and whether majority detection is enabled or not. For details, refer to the section "Tamper Detection" of datasheet.

Referenced by rtc_tamper_clear_detect_flag(), and rtc_tamper_get_detect_flag().

#define RTC_TAMPER_DETECT_ID1   (1UL << 1)

RTC tamper ID1 detection bitmask.

Referenced by rtc_tamper_clear_detect_flag(), and rtc_tamper_get_detect_flag().

#define RTC_TAMPER_DETECT_ID2   (1UL << 2)

RTC tamper ID2 detection bitmask.

Referenced by rtc_tamper_clear_detect_flag(), and rtc_tamper_get_detect_flag().

#define RTC_TAMPER_DETECT_ID3   (1UL << 3)

RTC tamper ID3 detection bitmask.

Referenced by rtc_tamper_clear_detect_flag(), and rtc_tamper_get_detect_flag().

#define RTC_TAMPER_DETECT_ID4   (1UL << 4)

RTC tamper ID4 detection bitmask.

Referenced by rtc_tamper_clear_detect_flag(), and rtc_tamper_get_detect_flag().

RTC tamper active layer frequency divider.

The available prescaler factor for the RTC clock output used during active layer protection.

Enumerator
RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_2 

RTC active layer frequency is prescaled by a factor of 2.

RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_4 

RTC active layer frequency is prescaled by a factor of 4.

RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_8 

RTC active layer frequency is prescaled by a factor of 8.

RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_16 

RTC active layer frequency is prescaled by a factor of 16.

RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_32 

RTC active layer frequency is prescaled by a factor of 32.

RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_64 

RTC active layer frequency is prescaled by a factor of 64.

RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_128 

RTC active layer frequency is prescaled by a factor of 128.

RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_256 

RTC active layer frequency is prescaled by a factor of 256.

RTC tamper debounce frequency divider.

The available prescaler factor for the input debouncers.

Enumerator
RTC_TAMPER_DEBOUNCE_FREQ_DIV_2 

RTC debounce frequency is prescaled by a factor of 2.

RTC_TAMPER_DEBOUNCE_FREQ_DIV_4 

RTC debounce frequency is prescaled by a factor of 4.

RTC_TAMPER_DEBOUNCE_FREQ_DIV_8 

RTC debounce frequency is prescaled by a factor of 8.

RTC_TAMPER_DEBOUNCE_FREQ_DIV_16 

RTC debounce frequency is prescaled by a factor of 16.

RTC_TAMPER_DEBOUNCE_FREQ_DIV_32 

RTC debounce frequency is prescaled by a factor of 32.

RTC_TAMPER_DEBOUNCE_FREQ_DIV_64 

RTC debounce frequency is prescaled by a factor of 64.

RTC_TAMPER_DEBOUNCE_FREQ_DIV_128 

RTC debounce frequency is prescaled by a factor of 128.

RTC_TAMPER_DEBOUNCE_FREQ_DIV_256 

RTC debounce frequency is prescaled by a factor of 256.

RTC tamper debounce sequential.

The available sequential for tamper debounce.

Enumerator
RTC_TAMPER_DEBOUNCE_SYNC 

Tamper input detect edge with synchronous stability debounce.

RTC_TAMPER_DEBOUNCE_ASYNC 

Tamper input detect edge with asynchronous stability debounce.

RTC_TAMPER_DEBOUNCE_MAJORITY 

Tamper input detect edge with majority debounce.

RTC tamper input action.

The available action taken by the tamper input.

Enumerator
RTC_TAMPER_INPUT_ACTION_OFF 

RTC tamper input action is disabled.

RTC_TAMPER_INPUT_ACTION_WAKE 

RTC tamper input action is wake and set tamper flag.

RTC_TAMPER_INPUT_ACTION_CAPTURE 

RTC tamper input action is capture timestamp and set tamper flag.

RTC_TAMPER_INPUT_ACTION_ACTL 

RTC tamper input action is compare IN to OUT, when a mismatch occurs, capture timestamp and set tamper flag.

RTC tamper input level select.

The available edge condition for tamper INn level select.

Enumerator
RTC_TAMPER_LEVEL_FALLING 

A falling edge condition will be detected on Tamper input.

RTC_TAMPER_LEVEL_RISING 

A rising edge condition will be detected on Tamper input.

static void rtc_tamper_clear_detect_flag ( struct rtc_module *const  module,
const uint32_t  detect_flags 
)
inlinestatic

Clears RTC tamper detection flag.

Clears the given detection flag of the module.

Parameters
[in]modulePointer to the TC software instance struct
[in]detect_flagsBitmask of detection flags

References Assert, RTC_TAMPER_DETECT_EVT, RTC_TAMPER_DETECT_ID0, RTC_TAMPER_DETECT_ID1, RTC_TAMPER_DETECT_ID2, RTC_TAMPER_DETECT_ID3, and RTC_TAMPER_DETECT_ID4.

static void rtc_tamper_get_config_defaults ( struct rtc_tamper_config *const  config)
inlinestatic

Gets the RTC tamper default configurations.

Initializes the configuration structure to default values.

The default configuration is as follows:

  • Disable backup register reset on tamper
  • Disable GP register reset on tamper
  • Active layer clock divided by a factor of 8
  • Debounce clock divided by a factor of 8
  • Detect edge on INn with synchronous stability debouncing
  • Disable DMA on tamper
  • Enable GP register
  • Disable debouce, detect on falling edge and no action on INn
Parameters
[out]configConfiguration structure to be initialized to default values.

References rtc_tamper_input_config::action, rtc_tamper_config::actl_freq_div, Assert, rtc_tamper_config::bkup_reset_on_tamper, rtc_tamper_config::deb_freq_div, rtc_tamper_config::deb_seq, rtc_tamper_input_config::debounce_enable, rtc_tamper_config::dma_tamper_enable, rtc_tamper_config::gp0_enable, rtc_tamper_config::gp_reset_on_tamper, rtc_tamper_config::in_cfg, rtc_tamper_input_config::level, RTC_TAMPER_ACTIVE_LAYER_FREQ_DIV_8, RTC_TAMPER_DEBOUNCE_FREQ_DIV_8, RTC_TAMPER_DEBOUNCE_SYNC, RTC_TAMPER_INPUT_ACTION_OFF, and RTC_TAMPER_LEVEL_FALLING.

static uint32_t rtc_tamper_get_detect_flag ( struct rtc_module *const  module)
inlinestatic

Retrieves the RTC tamper detection status.

Retrieves the detection status of each input pin and the input event.

Parameters
[in]modulePointer to the RTC software instance struct
Returns
Bitmask of detection flags.
Return values
RTC_TAMPER_DETECT_ID0Tamper condition on IN0 has been detected
RTC_TAMPER_DETECT_ID1Tamper condition on IN1 has been detected
RTC_TAMPER_DETECT_ID2Tamper condition on IN2 has been detected
RTC_TAMPER_DETECT_ID3Tamper condition on IN3 has been detected
RTC_TAMPER_DETECT_ID4Tamper condition on IN4 has been detected
RTC_TAMPER_DETECT_EVTTamper input event has been detected

References Assert, RTC_TAMPER_DETECT_EVT, RTC_TAMPER_DETECT_ID0, RTC_TAMPER_DETECT_ID1, RTC_TAMPER_DETECT_ID2, RTC_TAMPER_DETECT_ID3, and RTC_TAMPER_DETECT_ID4.

enum status_code rtc_tamper_set_config ( struct rtc_module *const  module,
struct rtc_tamper_config *const  tamper_cfg 
)