1 /*
2 * Copyright (c) 2021 HPMicro
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #ifndef HPM_PMON_DRV_H
9 #define HPM_PMON_DRV_H
10 #include "hpm_common.h"
11 #include "hpm_pmon_regs.h"
12
13 #define PMON_EVENT_GLITCH0 (1U << 0)
14 #define PMON_EVENT_GLITCH1 (1U << 1)
15 #define PMON_EVENT_CLOCK0 (1U << 2)
16 #define PMON_EVENT_CLOCK1 (1U << 3)
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
pmon_enable(PMON_Type * ptr,uint8_t monitor_index,bool enable)22 static inline void pmon_enable(PMON_Type *ptr,
23 uint8_t monitor_index,
24 bool enable)
25 {
26 ptr->MONITOR[monitor_index].CONTROL = (ptr->MONITOR[monitor_index].CONTROL
27 & ~PMON_MONITOR_CONTROL_ENABLE_MASK)
28 | PMON_MONITOR_CONTROL_ENABLE_SET(enable);
29 }
30
pmon_select_glitch_mode(PMON_Type * ptr,uint8_t monitor_index,bool active_mode)31 static inline void pmon_select_glitch_mode(PMON_Type *ptr,
32 uint8_t monitor_index,
33 bool active_mode)
34 {
35 ptr->MONITOR[monitor_index].CONTROL = (ptr->MONITOR[monitor_index].CONTROL
36 & ~PMON_MONITOR_CONTROL_ACTIVE_MASK)
37 | PMON_MONITOR_CONTROL_ACTIVE_SET(active_mode);
38 }
39
pmon_glich_detected(PMON_Type * ptr,uint8_t monitor_index)40 static inline bool pmon_glich_detected(PMON_Type *ptr, uint8_t monitor_index)
41 {
42 return ptr->MONITOR[monitor_index].STATUS;
43 }
44
pmon_test_mode_enable(PMON_Type * ptr,bool enable)45 static inline void pmon_test_mode_enable(PMON_Type *ptr, bool enable)
46 {
47 ptr->TEST_MODE = (ptr->TEST_MODE & ~PMON_TEST_MODE_DISABLE_MASK)
48 | PMON_TEST_MODE_DISABLE_SET(!enable);
49 }
50
pmon_irq_enable(PMON_Type * ptr,uint32_t mask,bool enable)51 static inline void pmon_irq_enable(PMON_Type *ptr, uint32_t mask, bool enable)
52 {
53 ptr->IRQ_ENABLE = (ptr->IRQ_ENABLE & ~mask) | (enable ? mask : 0);
54 }
55
pmon_irq_get_status(PMON_Type * ptr)56 static inline uint32_t pmon_irq_get_status(PMON_Type *ptr)
57 {
58 return ptr->IRQ_FLAG;
59 }
60
61 #ifdef __cplusplus
62 }
63 #endif
64
65 #endif /* HPM_PMON_DRV_H */
66