hpm_pmon_drv.h 1.8 KB

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