13 #include "sw/device/lib/base/multibits.h"
16 #include "rstmgr_regs.h"
19 #if !OT_IS_ENGLISH_BREAKFAST
22 #define RSTMGR_RESET_INFO_CHECK(pub_name, priv_name) \
23 static_assert(kDifRstmgrResetInfo##pub_name == \
24 (0x1 << RSTMGR_RESET_##priv_name##_BIT), \
25 "kDifRstmgrResetInfo" #pub_name \
26 " must match the register definition!")
28 RSTMGR_RESET_INFO_CHECK(Por, INFO_POR);
29 RSTMGR_RESET_INFO_CHECK(LowPowerExit, INFO_LOW_POWER_EXIT);
32 << RSTMGR_RESET_INFO_HW_REQ_OFFSET),
33 "kDifRstmgrResetInfoHwReq must match the register definition!");
36 RSTMGR_PARAM_NUM_SW_RESETS == 8,
37 "Number of software resets has changed, please update this file!");
45 RSTMGR_PARAM_NUM_SW_RESETS <= 32,
46 "Reset Enable and Control registers span across multiple registers!");
55 "Alert info dump max size has grown, please update the public define!");
61 static bool alert_capture_is_locked(
mmio_region_t base_addr) {
63 mmio_region_read32(base_addr, RSTMGR_ALERT_REGWEN_REG_OFFSET);
74 mmio_region_read32(base_addr, RSTMGR_CPU_REGWEN_REG_OFFSET);
83 static bool rstmgr_software_reset_is_locked(
85 return !mmio_region_read32(
86 base_addr, RSTMGR_SW_RST_REGWEN_0_REG_OFFSET + 4 * (ptrdiff_t)peripheral);
92 static void rstmgr_software_reset_hold(
mmio_region_t base_addr,
95 bool value = hold ? false :
true;
97 base_addr, RSTMGR_SW_RST_CTRL_N_0_REG_OFFSET + 4 * (ptrdiff_t)peripheral,
106 static void rstmgr_reset_info_clear(
mmio_region_t base_addr) {
107 mmio_region_write32(base_addr, RSTMGR_RESET_INFO_REG_OFFSET, UINT32_MAX);
111 if (handle == NULL) {
117 rstmgr_reset_info_clear(base_addr);
120 for (uint32_t i = 0; i < RSTMGR_PARAM_NUM_SW_RESETS; i++) {
121 mmio_region_write32(base_addr,
122 RSTMGR_SW_RST_CTRL_N_0_REG_OFFSET + (ptrdiff_t)i * 4,
131 if (handle == NULL || peripheral >= RSTMGR_PARAM_NUM_SW_RESETS) {
138 base_addr, RSTMGR_SW_RST_REGWEN_0_REG_OFFSET + 4 * (ptrdiff_t)peripheral,
147 if (handle == NULL || is_locked == NULL ||
148 peripheral >= RSTMGR_PARAM_NUM_SW_RESETS) {
153 *is_locked = rstmgr_software_reset_is_locked(base_addr, peripheral);
160 if (handle == NULL || info == NULL) {
165 *info = mmio_region_read32(base_addr, RSTMGR_RESET_INFO_REG_OFFSET);
171 if (handle == NULL) {
177 rstmgr_reset_info_clear(base_addr);
184 if (handle == NULL) {
190 if (alert_capture_is_locked(base_addr)) {
199 mmio_region_write32(base_addr, RSTMGR_ALERT_INFO_CTRL_REG_OFFSET, enabled);
206 if (handle == NULL || state == NULL) {
213 mmio_region_read32(base_addr, RSTMGR_ALERT_INFO_CTRL_REG_OFFSET);
223 if (handle == NULL || size == NULL) {
228 *size = mmio_region_read32(base_addr, RSTMGR_ALERT_INFO_ATTR_REG_OFFSET);
234 size_t dump_size,
size_t *segments_read) {
235 if (handle == NULL || dump == NULL || segments_read == NULL) {
242 size_t dump_size_actual =
243 mmio_region_read32(base_addr, RSTMGR_ALERT_INFO_ATTR_REG_OFFSET);
246 if (dump_size < dump_size_actual) {
250 uint32_t control_reg =
251 mmio_region_read32(base_addr, RSTMGR_ALERT_INFO_CTRL_REG_OFFSET);
254 for (uint32_t i = 0; i < dump_size_actual; ++i) {
256 RSTMGR_ALERT_INFO_CTRL_INDEX_FIELD, i);
259 mmio_region_write32(base_addr, RSTMGR_ALERT_INFO_CTRL_REG_OFFSET,
263 dump[i] = mmio_region_read32(base_addr, RSTMGR_ALERT_INFO_REG_OFFSET);
266 *segments_read = dump_size_actual;
273 if (handle == NULL) {
279 if (cpu_capture_is_locked(base_addr)) {
288 mmio_region_write32(base_addr, RSTMGR_CPU_INFO_CTRL_REG_OFFSET, enabled);
295 if (handle == NULL || state == NULL) {
301 uint32_t reg = mmio_region_read32(base_addr, RSTMGR_CPU_INFO_CTRL_REG_OFFSET);
311 if (handle == NULL || size == NULL) {
316 *size = mmio_region_read32(base_addr, RSTMGR_CPU_INFO_ATTR_REG_OFFSET);
322 size_t dump_size,
size_t *segments_read) {
323 if (handle == NULL || dump == NULL || segments_read == NULL) {
330 size_t dump_size_actual =
331 mmio_region_read32(base_addr, RSTMGR_CPU_INFO_ATTR_REG_OFFSET);
334 if (dump_size < dump_size_actual) {
338 uint32_t control_reg =
339 mmio_region_read32(base_addr, RSTMGR_CPU_INFO_CTRL_REG_OFFSET);
342 for (uint32_t i = 0; i < dump_size_actual; ++i) {
344 RSTMGR_CPU_INFO_CTRL_INDEX_FIELD, i);
347 mmio_region_write32(base_addr, RSTMGR_CPU_INFO_CTRL_REG_OFFSET,
351 dump[i] = mmio_region_read32(base_addr, RSTMGR_CPU_INFO_REG_OFFSET);
354 *segments_read = dump_size_actual;
362 if (handle == NULL || peripheral >= RSTMGR_PARAM_NUM_SW_RESETS) {
367 if (rstmgr_software_reset_is_locked(base_addr, peripheral)) {
373 rstmgr_software_reset_hold(base_addr, peripheral,
true);
374 rstmgr_software_reset_hold(base_addr, peripheral,
false);
377 rstmgr_software_reset_hold(base_addr, peripheral,
true);
380 rstmgr_software_reset_hold(base_addr, peripheral,
false);
392 if (handle == NULL || asserted == NULL ||
393 peripheral >= RSTMGR_PARAM_NUM_SW_RESETS) {
399 !mmio_region_read32(handle->
base_addr, RSTMGR_SW_RST_CTRL_N_0_REG_OFFSET +
400 4 * (ptrdiff_t)peripheral);
406 if (handle == NULL) {
410 mmio_region_write32(handle->
base_addr, RSTMGR_RESET_REQ_REG_OFFSET,
418 if (rstmgr == NULL || codes == NULL) {
421 *codes = mmio_region_read32(rstmgr->
base_addr, RSTMGR_ERR_CODE_REG_OFFSET);