HPM SDK
HPMicro Software Development Kit
hpm_tamp_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_TAMP_DRV_H
9 #define HPM_TAMP_DRV_H
10 
11 #include "hpm_common.h"
12 #include "hpm_tamp_regs.h"
13 
22 typedef enum {
40 
41 typedef enum {
59 
60  typedef struct {
61  bool enable;
67  bool auto_recover; /* used in active mode */
68  uint32_t poly; /* used in active mode */
69  uint32_t lfsr; /* used in active mode */
71 
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
85 void tamp_init_ch_config(TAMP_Type *ptr, uint8_t ch, tamper_ch_config_t *config);
86 
95 
104 static inline void tamp_set_ch_enable(TAMP_Type *ptr, uint8_t ch, bool enable)
105 {
106  ch >>= 1u;
107  if (enable) {
109  } else {
111  }
112 }
113 
122 static inline void tamp_set_ch_config_lock(TAMP_Type *ptr, uint8_t ch, bool lock)
123 {
124  ch >>= 1u;
125  if (lock) {
127  } else {
129  }
130 }
131 
139 static inline uint32_t tamp_get_flags(TAMP_Type *ptr)
140 {
141  return TAMP_TAMP_FLAG_FLAG_GET(ptr->TAMP_FLAG);
142 }
143 
151 static inline void tamp_clear_flags(TAMP_Type *ptr, uint32_t flags)
152 {
153  ptr->TAMP_FLAG = TAMP_TAMP_FLAG_FLAG_SET(flags);
154 }
155 
164 static inline bool tamp_check_ch_flag(TAMP_Type *ptr, uint8_t ch)
165 {
166  return ((TAMP_TAMP_FLAG_FLAG_GET(ptr->TAMP_FLAG) & (1u << ch)) != 0u) ? true : false;
167 }
168 
176 static inline void tamp_clear_ch_flag(TAMP_Type *ptr, uint8_t ch)
177 {
178  ptr->TAMP_FLAG = TAMP_TAMP_FLAG_FLAG_SET(1u << ch);
179 }
180 
189 static inline void tamp_enable_ch_irq(TAMP_Type *ptr, uint8_t ch, bool enable)
190 {
191  if (enable) {
192  ptr->IRQ_EN |= TAMP_IRQ_EN_IRQ_EN_SET(1u << ch);
193  } else {
194  ptr->IRQ_EN &= ~TAMP_IRQ_EN_IRQ_EN_SET(1u << ch);
195  }
196 }
197 
205 static inline void tamp_set_irq_lock(TAMP_Type *ptr, bool lock)
206 {
207  if (lock) {
209  } else {
210  ptr->IRQ_EN &= ~TAMP_IRQ_EN_LOCK_MASK;
211  }
212 }
213 
214 #ifdef __cplusplus
215 }
216 #endif
220 #endif /* HPM_TAMP_DRV_H */
221 
#define TAMP_IRQ_EN_LOCK_MASK
Definition: hpm_tamp_regs.h:165
#define TAMP_TAMP_CONTROL_LOCK_MASK
Definition: hpm_tamp_regs.h:33
#define TAMP_TAMP_FLAG_FLAG_SET(x)
Definition: hpm_tamp_regs.h:154
#define TAMP_TAMP_FLAG_FLAG_GET(x)
Definition: hpm_tamp_regs.h:155
#define TAMP_TAMP_CONTROL_ENABLE_MASK
Definition: hpm_tamp_regs.h:118
#define TAMP_IRQ_EN_IRQ_EN_SET(x)
Definition: hpm_tamp_regs.h:179
static uint32_t tamp_get_flags(TAMP_Type *ptr)
Get tamper all channel flags.
Definition: hpm_tamp_drv.h:139
void tamp_init_ch_config(TAMP_Type *ptr, uint8_t ch, tamper_ch_config_t *config)
Init tamper channel config.
Definition: hpm_tamp_drv.c:10
static void tamp_set_irq_lock(TAMP_Type *ptr, bool lock)
Set tamper irq lock or unlock.
Definition: hpm_tamp_drv.h:205
tamper_filter_len_t
Definition: hpm_tamp_drv.h:41
static void tamp_clear_ch_flag(TAMP_Type *ptr, uint8_t ch)
Clear tamper channel flag.
Definition: hpm_tamp_drv.h:176
static void tamp_set_ch_config_lock(TAMP_Type *ptr, uint8_t ch, bool lock)
Set tamper channel config lock or unlock.
Definition: hpm_tamp_drv.h:122
static void tamp_enable_ch_irq(TAMP_Type *ptr, uint8_t ch, bool enable)
Set tamper channel irq enable or disable.
Definition: hpm_tamp_drv.h:189
void tamp_get_default_ch_config(TAMP_Type *ptr, tamper_ch_config_t *config)
Get tamper default channel config.
Definition: hpm_tamp_drv.c:24
static void tamp_clear_flags(TAMP_Type *ptr, uint32_t flags)
Clear tamper flags.
Definition: hpm_tamp_drv.h:151
tamper_speed_t
Definition: hpm_tamp_drv.h:22
static bool tamp_check_ch_flag(TAMP_Type *ptr, uint8_t ch)
Check tamper channel flag.
Definition: hpm_tamp_drv.h:164
static void tamp_set_ch_enable(TAMP_Type *ptr, uint8_t ch, bool enable)
Set tamper channel enable or disable.
Definition: hpm_tamp_drv.h:104
@ filter_len_16_cycles
Definition: hpm_tamp_drv.h:46
@ filter_len_4096_cycles
Definition: hpm_tamp_drv.h:54
@ filter_len_8192_cycles
Definition: hpm_tamp_drv.h:55
@ filter_len_32768_cycles
Definition: hpm_tamp_drv.h:57
@ filter_len_4_cycles
Definition: hpm_tamp_drv.h:44
@ filter_len_128_cycles
Definition: hpm_tamp_drv.h:49
@ filter_len_2048_cycles
Definition: hpm_tamp_drv.h:53
@ filter_len_8_cycles
Definition: hpm_tamp_drv.h:45
@ filter_len_256_cycles
Definition: hpm_tamp_drv.h:50
@ filter_len_512_cycles
Definition: hpm_tamp_drv.h:51
@ filter_len_1024_cycles
Definition: hpm_tamp_drv.h:52
@ filter_len_64_cycles
Definition: hpm_tamp_drv.h:48
@ filter_len_32_cycles
Definition: hpm_tamp_drv.h:47
@ filter_len_1_cycle
Definition: hpm_tamp_drv.h:42
@ filter_len_16384_cycles
Definition: hpm_tamp_drv.h:56
@ filter_len_2_cycles
Definition: hpm_tamp_drv.h:43
@ spd_1_time_per_sec
Definition: hpm_tamp_drv.h:23
@ spd_128_times_per_sec
Definition: hpm_tamp_drv.h:30
@ spd_8192_times_per_sec
Definition: hpm_tamp_drv.h:36
@ spd_512_times_per_sec
Definition: hpm_tamp_drv.h:32
@ spd_16384_times_per_sec
Definition: hpm_tamp_drv.h:37
@ spd_4096_times_per_sec
Definition: hpm_tamp_drv.h:35
@ spd_4_times_per_sec
Definition: hpm_tamp_drv.h:25
@ spd_1024_times_per_sec
Definition: hpm_tamp_drv.h:33
@ spd_256_times_per_sec
Definition: hpm_tamp_drv.h:31
@ spd_2_times_per_sec
Definition: hpm_tamp_drv.h:24
@ spd_16_times_per_sec
Definition: hpm_tamp_drv.h:27
@ spd_8_times_per_sec
Definition: hpm_tamp_drv.h:26
@ spd_64_times_per_sec
Definition: hpm_tamp_drv.h:29
@ spd_32_times_per_sec
Definition: hpm_tamp_drv.h:28
@ spd_2048_times_per_sec
Definition: hpm_tamp_drv.h:34
@ spd_32768_times_per_sec
Definition: hpm_tamp_drv.h:38
Definition: hpm_tamp_regs.h:12
__RW uint32_t IRQ_EN
Definition: hpm_tamp_regs.h:21
__RW uint32_t CONTROL
Definition: hpm_tamp_regs.h:14
__RW uint32_t TAMP_FLAG
Definition: hpm_tamp_regs.h:20
struct TAMP_Type::@406 TAMP[4]
Definition: hpm_tamp_drv.h:60
uint32_t poly
Definition: hpm_tamp_drv.h:68
uint32_t lfsr
Definition: hpm_tamp_drv.h:69
bool enable
Definition: hpm_tamp_drv.h:61
bool expect_high_level
Definition: hpm_tamp_drv.h:64
bool active_mode
Definition: hpm_tamp_drv.h:62
bool auto_recover
Definition: hpm_tamp_drv.h:67
bool filter_bypass
Definition: hpm_tamp_drv.h:63
tamper_speed_t speed
Definition: hpm_tamp_drv.h:65
tamper_filter_len_t filter_len
Definition: hpm_tamp_drv.h:66