1 /* 2 * Copyright 2024 Microchip Technology Inc. and its subsidiaries. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef _MEC_VBAT_H 7 #define _MEC_VBAT_H 8 9 #include <stdbool.h> 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include "mec_retval.h" 14 15 /* Interfaces to any C modules */ 16 #ifdef __cplusplus 17 extern "C" 18 { 19 #endif 20 21 /* VBAT Power-Fail and Status */ 22 enum mec_vbat_pfrs { 23 MEC_VBAT_PFRS_RSVD_BIT_0 = 0, 24 MEC_VBAT_PFRS_RSVD_BIT_1, 25 MEC_VBAT_PFRS_PCR_SOFT_RESET_POS, 26 MEC_VBAT_PFRS_JTAG_RESET_POS, 27 MEC_VBAT_PFRS_RESET_IN_PIN_POS, 28 MEC_VBAT_PFRS_WDT_RST_POS, 29 MEC_VBAT_PFRS_ARM_SYSRSTREQ_POS, 30 MEC_VBAT_PFRS_VBAT_RST_POS 31 }; 32 33 uint32_t mec_hal_vbat_pfrs(void); 34 void mec_hal_vbat_pfrs_clear(uint32_t clrmsk); 35 36 /* Lower word of 64-bit monotonic counter is read-only. 37 * A read causes it to increment by 1. 38 */ 39 uint32_t mec_hal_read_monotonic_counter32(void); 40 41 /* Obtain full 64-bit monotonic counter value 42 * Read causes lower 32-bits to increment by 1. 43 */ 44 uint64_t mec_hal_read_monotonic_counter64(void); 45 46 /* Upper word of 64-bit monotonic counter is read/write. 47 * Read/write does not cause it to increment. 48 */ 49 void mec_hal_set_monotonic_counter_msw(uint32_t msw); 50 51 /* Battery backed memory size in bytes */ 52 uint32_t mec_hal_bbram_size(void); 53 /* Battery backed memory base address */ 54 uintptr_t mec_hal_bbram_base_address(void); 55 56 /* Access battery backed memory */ 57 int mec_hal_bbram_rd8(uint16_t byte_ofs, uint8_t *val); 58 int mec_hal_bbram_wr8(uint16_t byte_ofs, uint8_t val); 59 60 int mec_hal_bbram_rd32(uint16_t byte_ofs, uint32_t *val); 61 int mec_hal_bbram_wr32(uint16_t byte_ofs, uint32_t val); 62 63 int mec_hal_bbram_rd(uint16_t byte_ofs, uint8_t *data, size_t datasz, size_t *nread); 64 int mec_hal_bbram_wr(uint16_t byte_ofs, uint8_t *data, size_t datasz, size_t *nwritten); 65 66 #ifdef __cplusplus 67 } 68 #endif 69 70 #endif /* #ifndef _MEC_VBAT_H */ 71