[dif/pwrmgr] Integrate autogen'd IRQ DIFs into source tree.
This commit partially addresses #8142. Specifically it:
1. deprecates existing (manually implemented) **Power Manager** IRQ DIFs,
2. integrates the auto-generated **Power Manager** IRQ DIFs into meson build
targets, and
3. refactors all existing source code to make use of the new auto-genenerated
**Power Manager** IRQ DIFs, and supporting shared DIF typedefs and
error codes.
This continues the long-term goal of auto-generating all IRQ DIFs across
all IPs, as described in #8142.
Signed-off-by: Timothy Trippel <ttrippel@google.com>
diff --git a/sw/device/lib/dif/autogen/meson.build b/sw/device/lib/dif/autogen/meson.build
index 59bdfa5..4ca88f4 100644
--- a/sw/device/lib/dif/autogen/meson.build
+++ b/sw/device/lib/dif/autogen/meson.build
@@ -2,13 +2,13 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
-# Autogen OTP Controller DIF library
-sw_lib_dif_autogen_otp_ctrl = declare_dependency(
+# Autogen Power Manager DIF library
+sw_lib_dif_autogen_pwrmgr = declare_dependency(
link_with: static_library(
- 'sw_lib_dif_autogen_otp_ctrl',
+ 'sw_lib_dif_autogen_pwrmgr',
sources: [
- hw_ip_otp_ctrl_reg_h,
- 'dif_otp_ctrl_autogen.c',
+ hw_ip_pwrmgr_reg_h,
+ 'dif_pwrmgr_autogen.c',
],
dependencies: [
sw_lib_mmio,
@@ -184,6 +184,20 @@
)
)
+# Autogen OTP Controller DIF library
+sw_lib_dif_autogen_otp_ctrl = declare_dependency(
+ link_with: static_library(
+ 'sw_lib_dif_autogen_otp_ctrl',
+ sources: [
+ hw_ip_otp_ctrl_reg_h,
+ 'dif_otp_ctrl_autogen.c',
+ ],
+ dependencies: [
+ sw_lib_mmio,
+ ],
+ )
+)
+
# Autogen Reset Manager DIF library
sw_lib_dif_autogen_rstmgr = declare_dependency(
link_with: static_library(
diff --git a/sw/device/lib/dif/dif_pwrmgr.c b/sw/device/lib/dif/dif_pwrmgr.c
index 0bc91e1..f985b1e 100644
--- a/sw/device/lib/dif/dif_pwrmgr.c
+++ b/sw/device/lib/dif/dif_pwrmgr.c
@@ -8,6 +8,7 @@
#include "sw/device/lib/base/bitfield.h"
#include "sw/device/lib/base/mmio.h"
+#include "sw/device/lib/dif/dif_base.h"
#include "pwrmgr_regs.h" // Generated.
@@ -156,15 +157,15 @@
};
/**
- * Checks if a value is a valid `dif_pwrmgr_toggle_t` and converts it to `bool`.
+ * Checks if a value is a valid `dif_toggle_t` and converts it to `bool`.
*/
OT_WARN_UNUSED_RESULT
-static bool toggle_to_bool(dif_pwrmgr_toggle_t val, bool *val_bool) {
+static bool toggle_to_bool(dif_toggle_t val, bool *val_bool) {
switch (val) {
- case kDifPwrmgrToggleEnabled:
+ case kDifToggleEnabled:
*val_bool = true;
break;
- case kDifPwrmgrToggleDisabled:
+ case kDifToggleDisabled:
*val_bool = false;
break;
default:
@@ -174,10 +175,10 @@
}
/**
- * Converts a `bool` to `dif_pwrmgr_toggle_t`.
+ * Converts a `bool` to `dif_toggle_t`.
*/
-static dif_pwrmgr_toggle_t bool_to_toggle(bool val) {
- return val ? kDifPwrmgrToggleEnabled : kDifPwrmgrToggleDisabled;
+static dif_toggle_t bool_to_toggle(bool val) {
+ return val ? kDifToggleEnabled : kDifToggleDisabled;
}
/**
@@ -189,14 +190,6 @@
}
/**
- * Checks if a value is a valid `dif_pwrmgr_irq_t`.
- */
-OT_WARN_UNUSED_RESULT
-static bool is_valid_irq(dif_pwrmgr_irq_t val) {
- return val >= 0 && val <= kDifPwrmgrIrqLast;
-}
-
-/**
* Checks if a value is valid for, i.e. fits in the mask of, a
* `bitfield_field32_t`.
*/
@@ -215,8 +208,7 @@
static bool control_register_is_locked(const dif_pwrmgr_t *pwrmgr) {
// Control register is locked when `PWRMGR_CTRL_CFG_REGWEN_EN_BIT` bit is 0.
return !bitfield_bit32_read(
- mmio_region_read32(pwrmgr->params.base_addr,
- PWRMGR_CTRL_CFG_REGWEN_REG_OFFSET),
+ mmio_region_read32(pwrmgr->base_addr, PWRMGR_CTRL_CFG_REGWEN_REG_OFFSET),
PWRMGR_CTRL_CFG_REGWEN_EN_BIT);
}
@@ -229,11 +221,11 @@
static void sync_slow_clock_domain_polled(const dif_pwrmgr_t *pwrmgr) {
// Start sync and wait for it to finish.
mmio_region_write32(
- pwrmgr->params.base_addr, PWRMGR_CFG_CDC_SYNC_REG_OFFSET,
+ pwrmgr->base_addr, PWRMGR_CFG_CDC_SYNC_REG_OFFSET,
bitfield_bit32_write(0, PWRMGR_CFG_CDC_SYNC_SYNC_BIT, true));
- while (bitfield_bit32_read(mmio_region_read32(pwrmgr->params.base_addr,
- PWRMGR_CFG_CDC_SYNC_REG_OFFSET),
- PWRMGR_CFG_CDC_SYNC_SYNC_BIT)) {
+ while (bitfield_bit32_read(
+ mmio_region_read32(pwrmgr->base_addr, PWRMGR_CFG_CDC_SYNC_REG_OFFSET),
+ PWRMGR_CFG_CDC_SYNC_SYNC_BIT)) {
}
}
@@ -244,193 +236,190 @@
static bool request_sources_is_locked(const dif_pwrmgr_t *pwrmgr,
dif_pwrmgr_req_type_t req_type) {
request_reg_info_t reg_info = request_reg_infos[req_type];
- uint32_t reg_val = mmio_region_read32(pwrmgr->params.base_addr,
- reg_info.write_enable_reg_offset);
+ uint32_t reg_val =
+ mmio_region_read32(pwrmgr->base_addr, reg_info.write_enable_reg_offset);
// Locked if write enable bit is set to 0.
return !bitfield_bit32_read(reg_val, reg_info.write_enable_bit_index);
}
-dif_pwrmgr_result_t dif_pwrmgr_init(dif_pwrmgr_params_t params,
- dif_pwrmgr_t *pwrmgr) {
+dif_result_t dif_pwrmgr_init(mmio_region_t base_addr, dif_pwrmgr_t *pwrmgr) {
if (pwrmgr == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
- *pwrmgr = (dif_pwrmgr_t){.params = params};
+ pwrmgr->base_addr = base_addr;
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_config_result_t dif_pwrmgr_low_power_set_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t new_state) {
+dif_result_t dif_pwrmgr_low_power_set_enabled(const dif_pwrmgr_t *pwrmgr,
+ dif_toggle_t new_state) {
if (pwrmgr == NULL) {
- return kDifPwrmgrConfigBadArg;
+ return kDifBadArg;
}
bool enable = false;
if (!toggle_to_bool(new_state, &enable)) {
- return kDifPwrmgrConfigBadArg;
+ return kDifBadArg;
}
if (control_register_is_locked(pwrmgr)) {
- return kDifPwrMgrConfigLocked;
+ return kDifLocked;
}
uint32_t reg_val =
- mmio_region_read32(pwrmgr->params.base_addr, PWRMGR_CONTROL_REG_OFFSET);
+ mmio_region_read32(pwrmgr->base_addr, PWRMGR_CONTROL_REG_OFFSET);
reg_val =
bitfield_bit32_write(reg_val, PWRMGR_CONTROL_LOW_POWER_HINT_BIT, enable);
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_CONTROL_REG_OFFSET,
- reg_val);
+ mmio_region_write32(pwrmgr->base_addr, PWRMGR_CONTROL_REG_OFFSET, reg_val);
// Slow clock domain must be synced for changes to take effect.
sync_slow_clock_domain_polled(pwrmgr);
- return kDifPwrmgrConfigOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_low_power_get_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t *cur_state) {
+dif_result_t dif_pwrmgr_low_power_get_enabled(const dif_pwrmgr_t *pwrmgr,
+ dif_toggle_t *cur_state) {
if (pwrmgr == NULL || cur_state == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
uint32_t reg_val =
- mmio_region_read32(pwrmgr->params.base_addr, PWRMGR_CONTROL_REG_OFFSET);
+ mmio_region_read32(pwrmgr->base_addr, PWRMGR_CONTROL_REG_OFFSET);
*cur_state = bool_to_toggle(
bitfield_bit32_read(reg_val, PWRMGR_CONTROL_LOW_POWER_HINT_BIT));
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_config_result_t dif_pwrmgr_set_domain_config(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_domain_config_t config) {
+dif_result_t dif_pwrmgr_set_domain_config(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_domain_config_t config) {
if (pwrmgr == NULL || !is_valid_for_bitfield(config, kDomainConfigBitfield)) {
- return kDifPwrmgrConfigBadArg;
+ return kDifBadArg;
}
if (control_register_is_locked(pwrmgr)) {
- return kDifPwrMgrConfigLocked;
+ return kDifLocked;
}
uint32_t reg_val =
- mmio_region_read32(pwrmgr->params.base_addr, PWRMGR_CONTROL_REG_OFFSET);
+ mmio_region_read32(pwrmgr->base_addr, PWRMGR_CONTROL_REG_OFFSET);
reg_val = bitfield_field32_write(reg_val, kDomainConfigBitfield, config);
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_CONTROL_REG_OFFSET,
- reg_val);
+ mmio_region_write32(pwrmgr->base_addr, PWRMGR_CONTROL_REG_OFFSET, reg_val);
// Slow clock domain must be synced for changes to take effect.
sync_slow_clock_domain_polled(pwrmgr);
- return kDifPwrmgrConfigOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_get_domain_config(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_domain_config_t *config) {
+dif_result_t dif_pwrmgr_get_domain_config(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_domain_config_t *config) {
if (pwrmgr == NULL || config == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
uint32_t reg_val =
- mmio_region_read32(pwrmgr->params.base_addr, PWRMGR_CONTROL_REG_OFFSET);
+ mmio_region_read32(pwrmgr->base_addr, PWRMGR_CONTROL_REG_OFFSET);
*config = bitfield_field32_read(reg_val, kDomainConfigBitfield);
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_config_result_t dif_pwrmgr_set_request_sources(
+dif_result_t dif_pwrmgr_set_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t sources) {
if (pwrmgr == NULL || !is_valid_req_type(req_type)) {
- return kDifPwrmgrConfigBadArg;
+ return kDifBadArg;
}
request_reg_info_t reg_info = request_reg_infos[req_type];
if (!is_valid_for_bitfield(sources, reg_info.bitfield)) {
- return kDifPwrmgrConfigBadArg;
+ return kDifBadArg;
}
// Return early if locked.
if (request_sources_is_locked(pwrmgr, req_type)) {
- return kDifPwrMgrConfigLocked;
+ return kDifLocked;
}
// Write new value
uint32_t reg_val = bitfield_field32_write(0, reg_info.bitfield, sources);
- mmio_region_write32(pwrmgr->params.base_addr,
- reg_info.sources_enable_reg_offset, reg_val);
+ mmio_region_write32(pwrmgr->base_addr, reg_info.sources_enable_reg_offset,
+ reg_val);
// Slow clock domain must be synced for changes to take effect.
sync_slow_clock_domain_polled(pwrmgr);
- return kDifPwrmgrConfigOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_get_request_sources(
+dif_result_t dif_pwrmgr_get_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t *sources) {
if (pwrmgr == NULL || !is_valid_req_type(req_type) || sources == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
request_reg_info_t reg_info = request_reg_infos[req_type];
- uint32_t reg_val = mmio_region_read32(pwrmgr->params.base_addr,
- reg_info.sources_enable_reg_offset);
+ uint32_t reg_val =
+ mmio_region_read32(pwrmgr->base_addr, reg_info.sources_enable_reg_offset);
*sources = bitfield_field32_read(reg_val, reg_info.bitfield);
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_get_current_request_sources(
+dif_result_t dif_pwrmgr_get_current_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t *sources) {
if (pwrmgr == NULL || !is_valid_req_type(req_type) || sources == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
request_reg_info_t reg_info = request_reg_infos[req_type];
- uint32_t reg_val = mmio_region_read32(pwrmgr->params.base_addr,
+ uint32_t reg_val = mmio_region_read32(pwrmgr->base_addr,
reg_info.cur_req_sources_reg_offset);
*sources = bitfield_field32_read(reg_val, reg_info.bitfield);
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_request_sources_lock(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type) {
+dif_result_t dif_pwrmgr_request_sources_lock(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_req_type_t req_type) {
if (pwrmgr == NULL || !is_valid_req_type(req_type)) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
// Only a single bit of this register is significant, thus we don't perform a
// read-modify-write. Setting this bit to 0 locks sources.
- mmio_region_write32(pwrmgr->params.base_addr,
+ mmio_region_write32(pwrmgr->base_addr,
request_reg_infos[req_type].write_enable_reg_offset, 0);
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_request_sources_is_locked(
+dif_result_t dif_pwrmgr_request_sources_is_locked(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
bool *is_locked) {
if (pwrmgr == NULL || !is_valid_req_type(req_type) || is_locked == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
*is_locked = request_sources_is_locked(pwrmgr, req_type);
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_request_recording_set_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t new_state) {
+dif_result_t dif_pwrmgr_wakeup_request_recording_set_enabled(
+ const dif_pwrmgr_t *pwrmgr, dif_toggle_t new_state) {
if (pwrmgr == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
bool enable = false;
if (!toggle_to_bool(new_state, &enable)) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
// Only a single bit of this register is significant, thus we don't perform a
@@ -438,35 +427,35 @@
uint32_t reg_val =
bitfield_bit32_write(0, PWRMGR_WAKE_INFO_CAPTURE_DIS_VAL_BIT, !enable);
- mmio_region_write32(pwrmgr->params.base_addr,
+ mmio_region_write32(pwrmgr->base_addr,
PWRMGR_WAKE_INFO_CAPTURE_DIS_REG_OFFSET, reg_val);
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_request_recording_get_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t *cur_state) {
+dif_result_t dif_pwrmgr_wakeup_request_recording_get_enabled(
+ const dif_pwrmgr_t *pwrmgr, dif_toggle_t *cur_state) {
if (pwrmgr == NULL || cur_state == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
uint32_t reg_val = mmio_region_read32(
- pwrmgr->params.base_addr, PWRMGR_WAKE_INFO_CAPTURE_DIS_REG_OFFSET);
+ pwrmgr->base_addr, PWRMGR_WAKE_INFO_CAPTURE_DIS_REG_OFFSET);
// Recording is disabled if this bit is set to 1.
*cur_state = bool_to_toggle(
!bitfield_bit32_read(reg_val, PWRMGR_WAKE_INFO_CAPTURE_DIS_VAL_BIT));
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_reason_get(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_wakeup_reason_t *reason) {
+dif_result_t dif_pwrmgr_wakeup_reason_get(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_wakeup_reason_t *reason) {
if (pwrmgr == NULL || reason == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
uint32_t reg_val =
- mmio_region_read32(pwrmgr->params.base_addr, PWRMGR_WAKE_INFO_REG_OFFSET);
+ mmio_region_read32(pwrmgr->base_addr, PWRMGR_WAKE_INFO_REG_OFFSET);
dif_pwrmgr_wakeup_types_t types = 0;
if (bitfield_bit32_read(reg_val, PWRMGR_WAKE_INFO_FALL_THROUGH_BIT)) {
@@ -487,126 +476,24 @@
.request_sources = request_sources,
};
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_reason_clear(const dif_pwrmgr_t *pwrmgr) {
+dif_result_t dif_pwrmgr_wakeup_reason_clear(const dif_pwrmgr_t *pwrmgr) {
if (pwrmgr == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_WAKE_INFO_REG_OFFSET,
+ mmio_region_write32(pwrmgr->base_addr, PWRMGR_WAKE_INFO_REG_OFFSET,
UINT32_MAX);
- return kDifPwrmgrOk;
+ return kDifOk;
}
-dif_pwrmgr_result_t dif_pwrmgr_irq_is_pending(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq,
- bool *is_pending) {
- if (pwrmgr == NULL || !is_valid_irq(irq) || is_pending == NULL) {
- return kDifPwrmgrBadArg;
- }
-
- uint32_t reg_val = mmio_region_read32(pwrmgr->params.base_addr,
- PWRMGR_INTR_STATE_REG_OFFSET);
- *is_pending = bitfield_bit32_read(reg_val, irq);
-
- return kDifPwrmgrOk;
-}
-
-dif_pwrmgr_result_t dif_pwrmgr_irq_acknowledge(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq) {
- if (pwrmgr == NULL || !is_valid_irq(irq)) {
- return kDifPwrmgrBadArg;
- }
-
- uint32_t reg_val = bitfield_bit32_write(0, irq, true);
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_INTR_STATE_REG_OFFSET,
- reg_val);
-
- return kDifPwrmgrOk;
-}
-
-dif_pwrmgr_result_t dif_pwrmgr_irq_get_enabled(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq,
- dif_pwrmgr_toggle_t *state) {
- if (pwrmgr == NULL || !is_valid_irq(irq) || state == NULL) {
- return kDifPwrmgrBadArg;
- }
-
- uint32_t reg_val = mmio_region_read32(pwrmgr->params.base_addr,
- PWRMGR_INTR_ENABLE_REG_OFFSET);
- *state = bool_to_toggle(bitfield_bit32_read(reg_val, irq));
-
- return kDifPwrmgrOk;
-}
-
-dif_pwrmgr_result_t dif_pwrmgr_irq_set_enabled(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq,
- dif_pwrmgr_toggle_t state) {
- if (pwrmgr == NULL || !is_valid_irq(irq)) {
- return kDifPwrmgrBadArg;
- }
-
- bool enable = false;
- if (!toggle_to_bool(state, &enable)) {
- return kDifPwrmgrBadArg;
- }
-
- uint32_t reg_val = mmio_region_read32(pwrmgr->params.base_addr,
- PWRMGR_INTR_ENABLE_REG_OFFSET);
- reg_val = bitfield_bit32_write(reg_val, irq, enable);
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_INTR_ENABLE_REG_OFFSET,
- reg_val);
-
- return kDifPwrmgrOk;
-}
-
-dif_pwrmgr_result_t dif_pwrmgr_irq_force(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq) {
- if (pwrmgr == NULL || !is_valid_irq(irq)) {
- return kDifPwrmgrBadArg;
- }
-
- uint32_t reg_val = bitfield_bit32_write(0, irq, true);
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_INTR_TEST_REG_OFFSET,
- reg_val);
-
- return kDifPwrmgrOk;
-}
-
-dif_pwrmgr_result_t dif_pwrmgr_irq_disable_all(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_irq_snapshot_t *snapshot) {
+dif_result_t dif_pwrmgr_alert_force(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_alert_t alert) {
if (pwrmgr == NULL) {
- return kDifPwrmgrBadArg;
- }
-
- if (snapshot != NULL) {
- *snapshot = mmio_region_read32(pwrmgr->params.base_addr,
- PWRMGR_INTR_ENABLE_REG_OFFSET);
- }
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_INTR_ENABLE_REG_OFFSET,
- 0);
-
- return kDifPwrmgrOk;
-}
-
-dif_pwrmgr_result_t dif_pwrmgr_irq_restore_all(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_irq_snapshot_t snapshot) {
- if (pwrmgr == NULL) {
- return kDifPwrmgrBadArg;
- }
-
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_INTR_ENABLE_REG_OFFSET,
- snapshot);
- return kDifPwrmgrOk;
-}
-
-dif_pwrmgr_result_t dif_pwrmgr_alert_force(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_alert_t alert) {
- if (pwrmgr == NULL) {
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
bitfield_bit32_index_t index;
@@ -615,12 +502,11 @@
index = PWRMGR_ALERT_TEST_FATAL_FAULT_BIT;
break;
default:
- return kDifPwrmgrBadArg;
+ return kDifBadArg;
}
uint32_t reg = bitfield_bit32_write(0, index, true);
- mmio_region_write32(pwrmgr->params.base_addr, PWRMGR_ALERT_TEST_REG_OFFSET,
- reg);
+ mmio_region_write32(pwrmgr->base_addr, PWRMGR_ALERT_TEST_REG_OFFSET, reg);
- return kDifPwrmgrOk;
+ return kDifOk;
}
diff --git a/sw/device/lib/dif/dif_pwrmgr.h b/sw/device/lib/dif/dif_pwrmgr.h
index b292b7a..8bc0cee 100644
--- a/sw/device/lib/dif/dif_pwrmgr.h
+++ b/sw/device/lib/dif/dif_pwrmgr.h
@@ -15,52 +15,15 @@
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
+#include "sw/device/lib/dif/dif_base.h"
+
+#include "sw/device/lib/dif/autogen/dif_pwrmgr_autogen.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
- * Enumeration for enabling/disabling various functionality.
- */
-typedef enum dif_pwrmgr_toggle {
- /**
- * Enabled state.
- */
- kDifPwrmgrToggleEnabled,
- /**
- * Disabled state.
- */
- kDifPwrmgrToggleDisabled,
-} dif_pwrmgr_toggle_t;
-
-/**
- * Hardware instantiation parameters for power manager.
- *
- * This struct describes information about the underlying hardware that is
- * not determined until the hardware design is used as part of a top-level
- * design.
- */
-typedef struct dif_pwrmgr_params {
- /**
- * Base address of power manager registers.
- */
- mmio_region_t base_addr;
-} dif_pwrmgr_params_t;
-
-/**
- * A handle to power manager.
- *
- * This type should be treated as opaque by users.
- */
-typedef struct dif_pwrmgr {
- /**
- * Hardware instantiation parameters.
- */
- dif_pwrmgr_params_t params;
-} dif_pwrmgr_t;
-
-/**
* A request type, i.e. wakeup or reset.
*/
typedef enum dif_pwrmgr_req_type {
@@ -210,75 +173,6 @@
} dif_pwrmgr_wakeup_reason_t;
/**
- * Result of a power manager operation.
- */
-typedef enum dif_pwrmgr_result {
- /**
- * The call succeeded.
- */
- kDifPwrmgrOk = 0,
- /**
- * A non-specific error occurred and the hardware is in an invalid or
- * irrecoverable state.
- */
- kDifPwrmgrError = 1,
- /**
- * The caller supplied invalid arguments but the call did not cause any
- * side-effects and the hardware is in a valid and recoverable state.
- */
- kDifPwrmgrBadArg = 2,
-} dif_pwrmgr_result_t;
-
-/**
- * Result of a power manager operation that writes to lockable configuration
- * registers.
- */
-typedef enum dif_pwrmgr_config_result {
- /**
- * The call succeeded.
- */
- kDifPwrmgrConfigOk = kDifPwrmgrOk,
- /**
- * A non-specific error occurred and the hardware is in an invalid or
- * irrecoverable state.
- */
- kDifPwrmgrConfigError = kDifPwrmgrError,
- /**
- * The caller supplied invalid arguments but the call did not cause any
- * side-effects and the hardware is in a valid and recoverable state.
- */
- kDifPwrmgrConfigBadArg = kDifPwrmgrBadArg,
- /**
- * The register that needs to be written to is locked.
- */
- kDifPwrMgrConfigLocked,
-} dif_pwrmgr_config_result_t;
-
-/**
- * Power manager interrupts.
- */
-typedef enum dif_pwrmgr_irq {
- /**
- * The device woke up from low power state.
- *
- * Note: This interrupt is not triggered during power-on reset.
- */
- kDifPwrmgrIrqWakeup = 0,
- /**
- * \internal Last power manager interrupt.
- */
- kDifPwrmgrIrqLast = kDifPwrmgrIrqWakeup,
-} dif_pwrmgr_irq_t;
-
-/**
- * A snapshot of the enablement state of power manager interrupts.
- *
- * This is an opaque type, to be used with the `dif_pwrmgr_irq_disable_all()`
- * and `dif_pwrmgr_irq_restore_all()` functions.
- */
-typedef uint32_t dif_pwrmgr_irq_snapshot_t;
-
-/**
* Power manager alerts.
*/
typedef enum dif_pwrmgr_alert {
@@ -294,13 +188,12 @@
*
* This function does not actuate the hardware.
*
- * @param params Hardware instantiation parameters.
+ * @param base_addr Hardware instantiation base address.
* @param[out] pwrmgr Out-param for the initialized handle.
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_init(dif_pwrmgr_params_t params,
- dif_pwrmgr_t *pwrmgr);
+dif_result_t dif_pwrmgr_init(mmio_region_t base_addr, dif_pwrmgr_t *pwrmgr);
/**
* Enables or disables low power state.
@@ -318,8 +211,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_config_result_t dif_pwrmgr_low_power_set_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t new_state);
+dif_result_t dif_pwrmgr_low_power_set_enabled(const dif_pwrmgr_t *pwrmgr,
+ dif_toggle_t new_state);
/**
* Checks whether low power state is enabled.
@@ -329,8 +222,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_low_power_get_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t *cur_state);
+dif_result_t dif_pwrmgr_low_power_get_enabled(const dif_pwrmgr_t *pwrmgr,
+ dif_toggle_t *cur_state);
/**
* Configures power manager to enable/disable various clock and power domains in
@@ -344,8 +237,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_config_result_t dif_pwrmgr_set_domain_config(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_domain_config_t config);
+dif_result_t dif_pwrmgr_set_domain_config(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_domain_config_t config);
/**
* Gets current power manager configuration.
@@ -355,8 +248,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_get_domain_config(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_domain_config_t *config);
+dif_result_t dif_pwrmgr_get_domain_config(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_domain_config_t *config);
/**
* Sets sources enabled for a request type.
@@ -374,7 +267,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_config_result_t dif_pwrmgr_set_request_sources(
+dif_result_t dif_pwrmgr_set_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t sources);
@@ -391,7 +284,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_get_request_sources(
+dif_result_t dif_pwrmgr_get_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t *sources);
@@ -405,7 +298,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_get_current_request_sources(
+dif_result_t dif_pwrmgr_get_current_request_sources(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
dif_pwrmgr_request_sources_t *sources);
@@ -420,8 +313,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_request_sources_lock(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type);
+dif_result_t dif_pwrmgr_request_sources_lock(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_req_type_t req_type);
/**
* Checks whether sources of a request type is locked.
@@ -432,7 +325,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_request_sources_is_locked(
+dif_result_t dif_pwrmgr_request_sources_is_locked(
const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_req_type_t req_type,
bool *is_locked);
@@ -448,8 +341,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_request_recording_set_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t new_state);
+dif_result_t dif_pwrmgr_wakeup_request_recording_set_enabled(
+ const dif_pwrmgr_t *pwrmgr, dif_toggle_t new_state);
/**
* Checks whether wakeup requests are being recorded.
@@ -459,8 +352,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_request_recording_get_enabled(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_toggle_t *cur_state);
+dif_result_t dif_pwrmgr_wakeup_request_recording_get_enabled(
+ const dif_pwrmgr_t *pwrmgr, dif_toggle_t *cur_state);
/**
* Gets wakeup reason and source requests since the last time recording
@@ -477,8 +370,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_reason_get(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_wakeup_reason_t *reason);
+dif_result_t dif_pwrmgr_wakeup_reason_get(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_wakeup_reason_t *reason);
/**
* Clears wakeup reason(s) recorded since the last time recording started.
@@ -487,96 +380,7 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_wakeup_reason_clear(const dif_pwrmgr_t *pwrmgr);
-
-/**
- * Returns whether a particular interrupt is currently pending.
- *
- * @param pwrmgr A power manager handle.
- * @param irq An interrupt type.
- * @param[out] is_pending Out-param for whether the interrupt is pending.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_irq_is_pending(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq,
- bool *is_pending);
-
-/**
- * Acknowledges a particular interrupt, indicating to the hardware that it has
- * been successfully serviced.
- *
- * @param pwrmgr A power manager handle.
- * @param irq An interrupt type.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_irq_acknowledge(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq);
-
-/**
- * Checks whether a particular interrupt is currently enabled or disabled.
- *
- * @param pwrmgr A power manager handle.
- * @param irq An interrupt type.
- * @param[out] state Out-param toggle state of the interrupt.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_irq_get_enabled(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq,
- dif_pwrmgr_toggle_t *state);
-
-/**
- * Sets whether a particular interrupt is currently enabled or disabled.
- *
- * @param pwrmgr A power manager handle.
- * @param irq An interrupt type.
- * @param state The new toggle state for the interrupt.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_irq_set_enabled(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq,
- dif_pwrmgr_toggle_t state);
-
-/**
- * Forces a particular interrupt, causing it to be serviced as if hardware had
- * asserted it.
- *
- * @param pwrmgr A power manager handle.
- * @param irq An interrupt type.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_irq_force(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_irq_t irq);
-
-/**
- * Disables all interrupts, optionally snapshotting all toggle state for later
- * restoration.
- *
- * @param pwrmgr A power manager handle.
- * @param[out] snapshot Out-param for the snapshot; may be `NULL`.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_irq_disable_all(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_irq_snapshot_t *snapshot);
-
-/**
- * Restores interrupts from the given snapshot.
- *
- * This function can be used with `dif_pwrmgr_irq_disable_all()` to temporary
- * interrupt save-and-restore.
- *
- * @param pwrmgr A power manager handle.
- * @param snapshot A snapshot to restore from.
- * @return The result of the operation.
- */
-OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_irq_restore_all(
- const dif_pwrmgr_t *pwrmgr, dif_pwrmgr_irq_snapshot_t snapshot);
+dif_result_t dif_pwrmgr_wakeup_reason_clear(const dif_pwrmgr_t *pwrmgr);
/**
* Forces a particular alert, causing it to be serviced as if hardware had
@@ -587,8 +391,8 @@
* @return The result of the operation.
*/
OT_WARN_UNUSED_RESULT
-dif_pwrmgr_result_t dif_pwrmgr_alert_force(const dif_pwrmgr_t *pwrmgr,
- dif_pwrmgr_alert_t alert);
+dif_result_t dif_pwrmgr_alert_force(const dif_pwrmgr_t *pwrmgr,
+ dif_pwrmgr_alert_t alert);
#ifdef __cplusplus
} // extern "C"
diff --git a/sw/device/lib/dif/dif_pwrmgr_unittest.cc b/sw/device/lib/dif/dif_pwrmgr_unittest.cc
index 01b35e7..b1f4bf2 100644
--- a/sw/device/lib/dif/dif_pwrmgr_unittest.cc
+++ b/sw/device/lib/dif/dif_pwrmgr_unittest.cc
@@ -7,6 +7,7 @@
#include "gtest/gtest.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/base/testing/mock_mmio.h"
+#include "sw/device/lib/dif/dif_base.h"
#include "pwrmgr_regs.h" // Generated
@@ -21,13 +22,12 @@
/**
* Common constants used in tests.
*/
-static constexpr std::array<dif_pwrmgr_toggle_t, 2> kAllToggles = {
- kDifPwrmgrToggleEnabled, kDifPwrmgrToggleDisabled};
+static constexpr std::array<dif_toggle_t, 2> kAllToggles = {
+ kDifToggleDisabled,
+ kDifToggleEnabled,
+};
static constexpr std::array<bool, 2> kAllBools = {true, false};
-static constexpr dif_pwrmgr_toggle_t kBadToggle =
- static_cast<dif_pwrmgr_toggle_t>(kDifPwrmgrToggleDisabled + 1);
-static constexpr dif_pwrmgr_irq_t kBadIrq =
- static_cast<dif_pwrmgr_irq_t>(kDifPwrmgrIrqLast + 1);
+static constexpr dif_toggle_t kBadToggle = static_cast<dif_toggle_t>(2);
static constexpr dif_pwrmgr_req_type_t kBadReqType =
static_cast<dif_pwrmgr_req_type_t>(kDifPwrmgrReqTypeReset + 1);
static constexpr dif_pwrmgr_domain_config_t kBadConfig =
@@ -35,23 +35,17 @@
static constexpr dif_pwrmgr_request_sources_t kBadSources =
std::numeric_limits<uint32_t>::max();
-class DifPwrmgrTest : public testing::Test, public mock_mmio::MmioTest {
- protected:
- /**
- * Parameters for initializing a `dif_pwrmgr_t`.
- */
- const dif_pwrmgr_params_t params_ = {.base_addr = dev().region()};
-};
+class DifPwrmgrTest : public testing::Test, public mock_mmio::MmioTest {};
class InitTest : public DifPwrmgrTest {};
TEST_F(InitTest, BadArgs) {
- EXPECT_EQ(dif_pwrmgr_init(params_, nullptr), kDifPwrmgrBadArg);
+ EXPECT_EQ(dif_pwrmgr_init(dev().region(), nullptr), kDifBadArg);
}
TEST_F(InitTest, Init) {
dif_pwrmgr_t pwrmgr;
- EXPECT_EQ(dif_pwrmgr_init(params_, &pwrmgr), kDifPwrmgrOk);
+ EXPECT_EQ(dif_pwrmgr_init(dev().region(), &pwrmgr), kDifOk);
}
// Base class for the rest of the tests in this file, provides a
@@ -77,18 +71,16 @@
/**
* Initialized `dif_pwrmgr_t` used in tests.
*/
- const dif_pwrmgr_t pwrmgr_ = {.params = params_};
+ const dif_pwrmgr_t pwrmgr_ = {.base_addr = dev().region()};
};
class LowPowerTest : public DifPwrmgrInitialized {};
TEST_F(LowPowerTest, SetBadArgs) {
- EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(nullptr, kDifPwrmgrToggleEnabled),
- kDifPwrmgrConfigBadArg);
- EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(&pwrmgr_, kBadToggle),
- kDifPwrmgrConfigBadArg);
- EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(nullptr, kBadToggle),
- kDifPwrmgrConfigBadArg);
+ EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(nullptr, kDifToggleEnabled),
+ kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(&pwrmgr_, kBadToggle), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(nullptr, kBadToggle), kDifBadArg);
}
TEST_F(LowPowerTest, SetLocked) {
@@ -96,8 +88,7 @@
EXPECT_READ32(PWRMGR_CTRL_CFG_REGWEN_REG_OFFSET,
AllOnesExcept(PWRMGR_CTRL_CFG_REGWEN_EN_BIT));
- EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(&pwrmgr_, toggle),
- kDifPwrMgrConfigLocked);
+ EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(&pwrmgr_, toggle), kDifLocked);
}
}
@@ -112,37 +103,33 @@
{{
.offset = PWRMGR_CONTROL_LOW_POWER_HINT_BIT,
.mask = 1,
- .value = (toggle == kDifPwrmgrToggleEnabled),
+ .value = (toggle == kDifToggleEnabled),
}});
ExpectSync();
- EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(&pwrmgr_, toggle),
- kDifPwrmgrConfigOk);
+ EXPECT_EQ(dif_pwrmgr_low_power_set_enabled(&pwrmgr_, toggle), kDifOk);
}
}
TEST_F(LowPowerTest, GetBadArgs) {
- dif_pwrmgr_toggle_t state;
+ dif_toggle_t state;
- EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(nullptr, &state),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(&pwrmgr_, nullptr),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(nullptr, nullptr),
- kDifPwrmgrBadArg);
+ EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(nullptr, &state), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(&pwrmgr_, nullptr), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(nullptr, nullptr), kDifBadArg);
}
TEST_F(LowPowerTest, Get) {
for (auto toggle : kAllToggles) {
- dif_pwrmgr_toggle_t state;
+ dif_toggle_t state;
EXPECT_READ32(PWRMGR_CONTROL_REG_OFFSET,
{{
.offset = PWRMGR_CONTROL_LOW_POWER_HINT_BIT,
- .value = (toggle == kDifPwrmgrToggleEnabled),
+ .value = (toggle == kDifToggleEnabled),
}});
- EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(&pwrmgr_, &state), kDifPwrmgrOk);
+ EXPECT_EQ(dif_pwrmgr_low_power_get_enabled(&pwrmgr_, &state), kDifOk);
EXPECT_EQ(state, toggle);
}
}
@@ -182,18 +169,16 @@
constexpr std::array<dif_pwrmgr_domain_config_t, 4> DomainConfig::kConfigs;
TEST_F(DomainConfig, SetBadArgs) {
- EXPECT_EQ(dif_pwrmgr_set_domain_config(nullptr, 0), kDifPwrmgrConfigBadArg);
- EXPECT_EQ(dif_pwrmgr_set_domain_config(&pwrmgr_, kBadConfig),
- kDifPwrmgrConfigBadArg);
- EXPECT_EQ(dif_pwrmgr_set_domain_config(nullptr, kBadConfig),
- kDifPwrmgrConfigBadArg);
+ EXPECT_EQ(dif_pwrmgr_set_domain_config(nullptr, 0), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_set_domain_config(&pwrmgr_, kBadConfig), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_set_domain_config(nullptr, kBadConfig), kDifBadArg);
}
TEST_F(DomainConfig, SetLocked) {
EXPECT_READ32(PWRMGR_CTRL_CFG_REGWEN_REG_OFFSET,
AllOnesExcept(PWRMGR_WAKEUP_EN_REGWEN_EN_BIT));
- EXPECT_EQ(dif_pwrmgr_set_domain_config(&pwrmgr_, 0), kDifPwrMgrConfigLocked);
+ EXPECT_EQ(dif_pwrmgr_set_domain_config(&pwrmgr_, 0), kDifLocked);
}
TEST_F(DomainConfig, Set) {
@@ -211,18 +196,15 @@
}});
ExpectSync();
- EXPECT_EQ(dif_pwrmgr_set_domain_config(&pwrmgr_, config), kDifPwrmgrOk);
+ EXPECT_EQ(dif_pwrmgr_set_domain_config(&pwrmgr_, config), kDifOk);
}
}
TEST_F(DomainConfig, GetBadArgs) {
dif_pwrmgr_domain_config_t config;
- EXPECT_EQ(dif_pwrmgr_get_domain_config(nullptr, &config),
- kDifPwrmgrConfigBadArg);
- EXPECT_EQ(dif_pwrmgr_get_domain_config(&pwrmgr_, nullptr),
- kDifPwrmgrConfigBadArg);
- EXPECT_EQ(dif_pwrmgr_get_domain_config(nullptr, nullptr),
- kDifPwrmgrConfigBadArg);
+ EXPECT_EQ(dif_pwrmgr_get_domain_config(nullptr, &config), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_get_domain_config(&pwrmgr_, nullptr), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_get_domain_config(nullptr, nullptr), kDifBadArg);
}
TEST_F(DomainConfig, Get) {
@@ -234,8 +216,7 @@
}});
dif_pwrmgr_domain_config_t act_config;
- EXPECT_EQ(dif_pwrmgr_get_domain_config(&pwrmgr_, &act_config),
- kDifPwrmgrOk);
+ EXPECT_EQ(dif_pwrmgr_get_domain_config(&pwrmgr_, &act_config), kDifOk);
EXPECT_EQ(act_config, exp_config);
}
}
@@ -268,23 +249,23 @@
TEST_F(RequestSources, SetBadArgs) {
EXPECT_EQ(dif_pwrmgr_set_request_sources(nullptr, kDifPwrmgrReqTypeWakeup,
kDifPwrmgrWakeupRequestSourceOne),
- kDifPwrmgrConfigBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_set_request_sources(&pwrmgr_, kBadReqType,
kDifPwrmgrWakeupRequestSourceOne),
- kDifPwrmgrConfigBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_set_request_sources(&pwrmgr_, kDifPwrmgrReqTypeWakeup,
kBadSources),
- kDifPwrmgrConfigBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_set_request_sources(nullptr, kBadReqType,
kDifPwrmgrWakeupRequestSourceOne),
- kDifPwrmgrConfigBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_set_request_sources(nullptr, kDifPwrmgrReqTypeWakeup,
kBadSources),
- kDifPwrmgrConfigBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_set_request_sources(&pwrmgr_, kBadReqType, kBadSources),
- kDifPwrmgrConfigBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_set_request_sources(nullptr, kBadReqType, kBadSources),
- kDifPwrmgrConfigBadArg);
+ kDifBadArg);
}
TEST_F(RequestSources, SetWakeupLocked) {
@@ -293,7 +274,7 @@
EXPECT_EQ(dif_pwrmgr_set_request_sources(&pwrmgr_, kDifPwrmgrReqTypeWakeup,
kDifPwrmgrWakeupRequestSourceOne),
- kDifPwrMgrConfigLocked);
+ kDifLocked);
}
TEST_F(RequestSources, SetResetLocked) {
@@ -302,7 +283,7 @@
EXPECT_EQ(dif_pwrmgr_set_request_sources(&pwrmgr_, kDifPwrmgrReqTypeReset,
kDifPwrmgrResetRequestSourceOne),
- kDifPwrMgrConfigLocked);
+ kDifLocked);
}
TEST_F(RequestSources, SetWakeup) {
@@ -316,7 +297,7 @@
EXPECT_EQ(dif_pwrmgr_set_request_sources(&pwrmgr_, kDifPwrmgrReqTypeWakeup,
kDifPwrmgrWakeupRequestSourceOne),
- kDifPwrmgrConfigOk);
+ kDifOk);
}
TEST_F(RequestSources, SetReset) {
@@ -330,7 +311,7 @@
EXPECT_EQ(dif_pwrmgr_set_request_sources(&pwrmgr_, kDifPwrmgrReqTypeReset,
kDifPwrmgrResetRequestSourceOne),
- kDifPwrmgrConfigOk);
+ kDifOk);
}
TEST_F(RequestSources, GetBadArgs) {
@@ -338,21 +319,21 @@
EXPECT_EQ(dif_pwrmgr_get_request_sources(nullptr, kDifPwrmgrReqTypeWakeup,
&sources),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_get_request_sources(&pwrmgr_, kBadReqType, &sources),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_get_request_sources(&pwrmgr_, kDifPwrmgrReqTypeWakeup,
nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_get_request_sources(nullptr, kBadReqType, &sources),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_get_request_sources(nullptr, kDifPwrmgrReqTypeWakeup, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_get_request_sources(&pwrmgr_, kBadReqType, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_get_request_sources(nullptr, kBadReqType, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
}
TEST_F(RequestSources, GetWakeup) {
@@ -362,7 +343,7 @@
dif_pwrmgr_request_sources_t act_sources = 0;
EXPECT_EQ(dif_pwrmgr_get_request_sources(&pwrmgr_, kDifPwrmgrReqTypeWakeup,
&act_sources),
- kDifPwrmgrOk);
+ kDifOk);
EXPECT_EQ(act_sources, exp_sources);
}
}
@@ -374,7 +355,7 @@
dif_pwrmgr_request_sources_t act_sources = 0;
EXPECT_EQ(dif_pwrmgr_get_request_sources(&pwrmgr_, kDifPwrmgrReqTypeReset,
&act_sources),
- kDifPwrmgrOk);
+ kDifOk);
EXPECT_EQ(act_sources, exp_sources);
}
}
@@ -384,25 +365,25 @@
EXPECT_EQ(dif_pwrmgr_get_current_request_sources(
nullptr, kDifPwrmgrReqTypeWakeup, &sources),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_get_current_request_sources(&pwrmgr_, kBadReqType, &sources),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_get_current_request_sources(
&pwrmgr_, kDifPwrmgrReqTypeWakeup, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_get_current_request_sources(nullptr, kBadReqType, &sources),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_get_current_request_sources(
nullptr, kDifPwrmgrReqTypeWakeup, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_get_current_request_sources(&pwrmgr_, kBadReqType, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_get_current_request_sources(nullptr, kBadReqType, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
}
TEST_F(RequestSources, GetCurrentWakeup) {
@@ -412,7 +393,7 @@
dif_pwrmgr_request_sources_t act_sources = 0;
EXPECT_EQ(dif_pwrmgr_get_current_request_sources(
&pwrmgr_, kDifPwrmgrReqTypeWakeup, &act_sources),
- kDifPwrmgrOk);
+ kDifOk);
EXPECT_EQ(act_sources, exp_sources);
}
}
@@ -424,32 +405,30 @@
dif_pwrmgr_request_sources_t act_sources = 0;
EXPECT_EQ(dif_pwrmgr_get_current_request_sources(
&pwrmgr_, kDifPwrmgrReqTypeReset, &act_sources),
- kDifPwrmgrOk);
+ kDifOk);
EXPECT_EQ(act_sources, exp_sources);
}
}
TEST_F(RequestSources, LockBadArgs) {
EXPECT_EQ(dif_pwrmgr_request_sources_lock(nullptr, kDifPwrmgrReqTypeWakeup),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_request_sources_lock(&pwrmgr_, kBadReqType),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_request_sources_lock(nullptr, kBadReqType),
- kDifPwrmgrBadArg);
+ kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_request_sources_lock(&pwrmgr_, kBadReqType), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_request_sources_lock(nullptr, kBadReqType), kDifBadArg);
}
TEST_F(RequestSources, LockWakeup) {
EXPECT_WRITE32(PWRMGR_WAKEUP_EN_REGWEN_REG_OFFSET, 0);
EXPECT_EQ(dif_pwrmgr_request_sources_lock(&pwrmgr_, kDifPwrmgrReqTypeWakeup),
- kDifPwrmgrOk);
+ kDifOk);
}
TEST_F(RequestSources, LockReset) {
EXPECT_WRITE32(PWRMGR_RESET_EN_REGWEN_REG_OFFSET, 0);
EXPECT_EQ(dif_pwrmgr_request_sources_lock(&pwrmgr_, kDifPwrmgrReqTypeReset),
- kDifPwrmgrOk);
+ kDifOk);
}
TEST_F(RequestSources, IsLockedBadArgs) {
@@ -457,24 +436,24 @@
EXPECT_EQ(dif_pwrmgr_request_sources_is_locked(
nullptr, kDifPwrmgrReqTypeWakeup, &is_locked),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_request_sources_is_locked(&pwrmgr_, kBadReqType, &is_locked),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_request_sources_is_locked(
&pwrmgr_, kDifPwrmgrReqTypeWakeup, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_request_sources_is_locked(nullptr, kBadReqType, &is_locked),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_request_sources_is_locked(
nullptr, kDifPwrmgrReqTypeWakeup, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_request_sources_is_locked(&pwrmgr_, kBadReqType, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_request_sources_is_locked(nullptr, kBadReqType, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
}
TEST_F(RequestSources, IsLockedWakeup) {
@@ -488,7 +467,7 @@
bool is_locked = !exp_val;
EXPECT_EQ(dif_pwrmgr_request_sources_is_locked(
&pwrmgr_, kDifPwrmgrReqTypeWakeup, &is_locked),
- kDifPwrmgrOk);
+ kDifOk);
EXPECT_EQ(is_locked, exp_val);
}
}
@@ -504,7 +483,7 @@
bool is_locked = !exp_val;
EXPECT_EQ(dif_pwrmgr_request_sources_is_locked(
&pwrmgr_, kDifPwrmgrReqTypeReset, &is_locked),
- kDifPwrmgrOk);
+ kDifOk);
EXPECT_EQ(is_locked, exp_val);
}
}
@@ -512,15 +491,15 @@
class WakeupRecording : public DifPwrmgrInitialized {};
TEST_F(WakeupRecording, SetEnabledBadArgs) {
- EXPECT_EQ(dif_pwrmgr_wakeup_request_recording_set_enabled(
- nullptr, kDifPwrmgrToggleEnabled),
- kDifPwrmgrBadArg);
+ EXPECT_EQ(dif_pwrmgr_wakeup_request_recording_set_enabled(nullptr,
+ kDifToggleEnabled),
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_wakeup_request_recording_set_enabled(&pwrmgr_, kBadToggle),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_wakeup_request_recording_set_enabled(nullptr, kBadToggle),
- kDifPwrmgrBadArg);
+ kDifBadArg);
}
TEST_F(WakeupRecording, SetEnabled) {
@@ -528,25 +507,25 @@
EXPECT_WRITE32(PWRMGR_WAKE_INFO_CAPTURE_DIS_REG_OFFSET,
{{
.offset = PWRMGR_WAKE_INFO_CAPTURE_DIS_VAL_BIT,
- .value = (new_state == kDifPwrmgrToggleDisabled),
+ .value = (new_state == kDifToggleDisabled),
}});
EXPECT_EQ(
dif_pwrmgr_wakeup_request_recording_set_enabled(&pwrmgr_, new_state),
- kDifPwrmgrOk);
+ kDifOk);
}
}
TEST_F(WakeupRecording, GetEnabledBadArgs) {
- dif_pwrmgr_toggle_t is_enabled;
+ dif_toggle_t is_enabled;
EXPECT_EQ(
dif_pwrmgr_wakeup_request_recording_get_enabled(nullptr, &is_enabled),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_wakeup_request_recording_get_enabled(&pwrmgr_, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(dif_pwrmgr_wakeup_request_recording_get_enabled(nullptr, nullptr),
- kDifPwrmgrBadArg);
+ kDifBadArg);
}
TEST_F(WakeupRecording, GetEnabled) {
@@ -554,15 +533,14 @@
EXPECT_READ32(PWRMGR_WAKE_INFO_CAPTURE_DIS_REG_OFFSET,
{{
.offset = PWRMGR_WAKE_INFO_CAPTURE_DIS_VAL_BIT,
- .value = (exp_val == kDifPwrmgrToggleDisabled),
+ .value = (exp_val == kDifToggleDisabled),
}});
- dif_pwrmgr_toggle_t is_enabled = (exp_val == kDifPwrmgrToggleEnabled)
- ? kDifPwrmgrToggleDisabled
- : kDifPwrmgrToggleEnabled;
+ dif_toggle_t is_enabled =
+ (exp_val == kDifToggleEnabled) ? kDifToggleDisabled : kDifToggleEnabled;
EXPECT_EQ(
dif_pwrmgr_wakeup_request_recording_get_enabled(&pwrmgr_, &is_enabled),
- kDifPwrmgrOk);
+ kDifOk);
EXPECT_EQ(is_enabled, exp_val);
}
}
@@ -570,10 +548,9 @@
TEST_F(WakeupRecording, GetReasonBadArgs) {
dif_pwrmgr_wakeup_reason_t wakeup_reason;
- EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(nullptr, &wakeup_reason),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(&pwrmgr_, nullptr), kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(nullptr, nullptr), kDifPwrmgrBadArg);
+ EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(nullptr, &wakeup_reason), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(&pwrmgr_, nullptr), kDifBadArg);
+ EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(nullptr, nullptr), kDifBadArg);
}
/**
@@ -754,233 +731,37 @@
EXPECT_READ32(PWRMGR_WAKE_INFO_REG_OFFSET, test_case.read_val);
dif_pwrmgr_wakeup_reason_t wakeup_reason;
- EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(&pwrmgr_, &wakeup_reason),
- kDifPwrmgrOk);
+ EXPECT_EQ(dif_pwrmgr_wakeup_reason_get(&pwrmgr_, &wakeup_reason), kDifOk);
EXPECT_THAT(wakeup_reason, Eq(test_case.exp_output));
}
}
TEST_F(WakeupRecording, ClearReasonBadArgs) {
- EXPECT_EQ(dif_pwrmgr_wakeup_reason_clear(nullptr), kDifPwrmgrBadArg);
+ EXPECT_EQ(dif_pwrmgr_wakeup_reason_clear(nullptr), kDifBadArg);
}
TEST_F(WakeupRecording, ClearReason) {
EXPECT_WRITE32(PWRMGR_WAKE_INFO_REG_OFFSET,
std::numeric_limits<uint32_t>::max());
- EXPECT_EQ(dif_pwrmgr_wakeup_reason_clear(&pwrmgr_), kDifPwrmgrOk);
-}
-
-class IrqTest : public DifPwrmgrInitialized {};
-
-TEST_F(IrqTest, IsPendingBadArgs) {
- bool is_pending;
-
- EXPECT_EQ(
- dif_pwrmgr_irq_is_pending(nullptr, kDifPwrmgrIrqWakeup, &is_pending),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_is_pending(&pwrmgr_, kBadIrq, &is_pending),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_is_pending(&pwrmgr_, kDifPwrmgrIrqWakeup, nullptr),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_is_pending(nullptr, kBadIrq, &is_pending),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_is_pending(nullptr, kDifPwrmgrIrqWakeup, nullptr),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_is_pending(&pwrmgr_, kBadIrq, nullptr),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_is_pending(nullptr, kBadIrq, nullptr),
- kDifPwrmgrBadArg);
-}
-
-TEST_F(IrqTest, IsPending) {
- for (std::underlying_type<dif_pwrmgr_irq_t>::type irq = 0;
- irq <= kDifPwrmgrIrqLast; ++irq) {
- for (auto exp_val : kAllBools) {
- EXPECT_READ32(PWRMGR_INTR_STATE_REG_OFFSET, {{
- .offset = irq,
- .value = exp_val,
- }});
-
- bool is_pending = !exp_val;
- EXPECT_EQ(dif_pwrmgr_irq_is_pending(
- &pwrmgr_, static_cast<dif_pwrmgr_irq_t>(irq), &is_pending),
- kDifPwrmgrOk);
- EXPECT_EQ(is_pending, exp_val);
- }
- }
-}
-
-TEST_F(IrqTest, AckBadArgs) {
- EXPECT_EQ(dif_pwrmgr_irq_acknowledge(nullptr, kDifPwrmgrIrqWakeup),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_acknowledge(&pwrmgr_, kBadIrq), kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_acknowledge(nullptr, kBadIrq), kDifPwrmgrBadArg);
-}
-
-TEST_F(IrqTest, Ack) {
- for (std::underlying_type<dif_pwrmgr_irq_t>::type irq = 0;
- irq <= kDifPwrmgrIrqLast; ++irq) {
- EXPECT_WRITE32(PWRMGR_INTR_STATE_REG_OFFSET, (1u << irq));
-
- EXPECT_EQ(dif_pwrmgr_irq_acknowledge(&pwrmgr_,
- static_cast<dif_pwrmgr_irq_t>(irq)),
- kDifPwrmgrOk);
- }
-}
-
-TEST_F(IrqTest, GetEnabledBadArgs) {
- dif_pwrmgr_toggle_t is_enabled;
-
- EXPECT_EQ(
- dif_pwrmgr_irq_get_enabled(nullptr, kDifPwrmgrIrqWakeup, &is_enabled),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_get_enabled(&pwrmgr_, kBadIrq, &is_enabled),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_get_enabled(&pwrmgr_, kDifPwrmgrIrqWakeup, nullptr),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_get_enabled(nullptr, kBadIrq, &is_enabled),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_get_enabled(nullptr, kDifPwrmgrIrqWakeup, nullptr),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_get_enabled(&pwrmgr_, kBadIrq, nullptr),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_get_enabled(nullptr, kBadIrq, nullptr),
- kDifPwrmgrBadArg);
-}
-
-TEST_F(IrqTest, GetEnabled) {
- for (std::underlying_type<dif_pwrmgr_irq_t>::type irq = 0;
- irq <= kDifPwrmgrIrqLast; ++irq) {
- for (auto exp_val : kAllToggles) {
- EXPECT_READ32(PWRMGR_INTR_ENABLE_REG_OFFSET,
- {{
- .offset = irq,
- .value = (exp_val == kDifPwrmgrToggleEnabled),
- }});
-
- dif_pwrmgr_toggle_t is_enabled = (exp_val == kDifPwrmgrToggleEnabled)
- ? kDifPwrmgrToggleDisabled
- : kDifPwrmgrToggleEnabled;
- EXPECT_EQ(dif_pwrmgr_irq_get_enabled(
- &pwrmgr_, static_cast<dif_pwrmgr_irq_t>(irq), &is_enabled),
- kDifPwrmgrOk);
- EXPECT_EQ(is_enabled, exp_val);
- }
- }
-}
-
-TEST_F(IrqTest, SetEnabledBadArgs) {
- EXPECT_EQ(dif_pwrmgr_irq_set_enabled(nullptr, kDifPwrmgrIrqWakeup,
- kDifPwrmgrToggleEnabled),
- kDifPwrmgrBadArg);
- EXPECT_EQ(
- dif_pwrmgr_irq_set_enabled(&pwrmgr_, kBadIrq, kDifPwrmgrToggleEnabled),
- kDifPwrmgrBadArg);
- EXPECT_EQ(
- dif_pwrmgr_irq_set_enabled(&pwrmgr_, kDifPwrmgrIrqWakeup, kBadToggle),
- kDifPwrmgrBadArg);
- EXPECT_EQ(
- dif_pwrmgr_irq_set_enabled(nullptr, kBadIrq, kDifPwrmgrToggleEnabled),
- kDifPwrmgrBadArg);
- EXPECT_EQ(
- dif_pwrmgr_irq_set_enabled(nullptr, kDifPwrmgrIrqWakeup, kBadToggle),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_set_enabled(&pwrmgr_, kBadIrq, kBadToggle),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_set_enabled(nullptr, kBadIrq, kBadToggle),
- kDifPwrmgrBadArg);
-}
-
-TEST_F(IrqTest, SetEnabled) {
- for (std::underlying_type<dif_pwrmgr_irq_t>::type irq = 0;
- irq <= kDifPwrmgrIrqLast; ++irq) {
- for (auto new_state : kAllToggles) {
- EXPECT_MASK32(PWRMGR_INTR_ENABLE_REG_OFFSET,
- {{
- .offset = irq,
- .mask = 1,
- .value = (new_state == kDifPwrmgrToggleEnabled),
- }});
-
- EXPECT_EQ(dif_pwrmgr_irq_set_enabled(
- &pwrmgr_, static_cast<dif_pwrmgr_irq_t>(irq), new_state),
- kDifPwrmgrOk);
- }
- }
-}
-
-TEST_F(IrqTest, ForceBadArgs) {
- EXPECT_EQ(dif_pwrmgr_irq_force(nullptr, kDifPwrmgrIrqWakeup),
- kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_force(&pwrmgr_, kBadIrq), kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_force(nullptr, kBadIrq), kDifPwrmgrBadArg);
-}
-
-TEST_F(IrqTest, Force) {
- for (std::underlying_type<dif_pwrmgr_irq_t>::type irq = 0;
- irq <= kDifPwrmgrIrqLast; ++irq) {
- EXPECT_WRITE32(PWRMGR_INTR_TEST_REG_OFFSET, {{
- .offset = irq,
- .value = 1,
- }});
-
- EXPECT_EQ(
- dif_pwrmgr_irq_force(&pwrmgr_, static_cast<dif_pwrmgr_irq_t>(irq)),
- kDifPwrmgrOk);
- }
-}
-
-TEST_F(IrqTest, DisableAllBadArgs) {
- dif_pwrmgr_irq_snapshot_t snapshot;
-
- // `snapshot` is optional.
- EXPECT_EQ(dif_pwrmgr_irq_disable_all(nullptr, &snapshot), kDifPwrmgrBadArg);
- EXPECT_EQ(dif_pwrmgr_irq_disable_all(nullptr, nullptr), kDifPwrmgrBadArg);
-}
-TEST_F(IrqTest, DisableAll) {
- uint32_t exp_snapshot = 0xA5A5A5A5;
-
- // With `snapshot`.
- EXPECT_READ32(PWRMGR_INTR_ENABLE_REG_OFFSET, exp_snapshot);
- EXPECT_WRITE32(PWRMGR_INTR_ENABLE_REG_OFFSET, 0);
-
- dif_pwrmgr_irq_snapshot_t act_snapshot = 0;
- EXPECT_EQ(dif_pwrmgr_irq_disable_all(&pwrmgr_, &act_snapshot), kDifPwrmgrOk);
- EXPECT_EQ(act_snapshot, exp_snapshot);
-
- // Without `snapshot`.
- EXPECT_WRITE32(PWRMGR_INTR_ENABLE_REG_OFFSET, 0);
- EXPECT_EQ(dif_pwrmgr_irq_disable_all(&pwrmgr_, nullptr), kDifPwrmgrOk);
-}
-
-TEST_F(IrqTest, RestoreAllBadArgs) {
- EXPECT_EQ(dif_pwrmgr_irq_restore_all(nullptr, 0), kDifPwrmgrBadArg);
-}
-
-TEST_F(IrqTest, RestoreAll) {
- dif_pwrmgr_irq_snapshot_t snapshot = 0xA5A5A5A5;
-
- EXPECT_WRITE32(PWRMGR_INTR_ENABLE_REG_OFFSET, snapshot);
-
- EXPECT_EQ(dif_pwrmgr_irq_restore_all(&pwrmgr_, snapshot), kDifPwrmgrOk);
+ EXPECT_EQ(dif_pwrmgr_wakeup_reason_clear(&pwrmgr_), kDifOk);
}
class AlertTest : public DifPwrmgrInitialized {};
TEST_F(AlertTest, ForceBadArgs) {
EXPECT_EQ(dif_pwrmgr_alert_force(nullptr, kDifPwrmgrAlertFatalFault),
- kDifPwrmgrBadArg);
+ kDifBadArg);
EXPECT_EQ(
dif_pwrmgr_alert_force(&pwrmgr_, static_cast<dif_pwrmgr_alert_t>(1)),
- kDifPwrmgrBadArg);
+ kDifBadArg);
}
TEST_F(AlertTest, Force) {
EXPECT_WRITE32(PWRMGR_ALERT_TEST_REG_OFFSET, {{0, true}});
EXPECT_EQ(dif_pwrmgr_alert_force(&pwrmgr_, kDifPwrmgrAlertFatalFault),
- kDifPwrmgrOk);
+ kDifOk);
}
} // namespace
diff --git a/sw/device/lib/dif/meson.build b/sw/device/lib/dif/meson.build
index 20f6cf8..b21220b 100644
--- a/sw/device/lib/dif/meson.build
+++ b/sw/device/lib/dif/meson.build
@@ -509,6 +509,7 @@
dependencies: [
sw_lib_mmio,
sw_lib_bitfield,
+ sw_lib_dif_autogen_pwrmgr,
],
)
)
@@ -516,9 +517,11 @@
test('dif_pwrmgr_unittest', executable(
'dif_pwrmgr_unittest',
sources: [
- hw_ip_pwrmgr_reg_h,
- meson.source_root() / 'sw/device/lib/dif/dif_pwrmgr.c',
'dif_pwrmgr_unittest.cc',
+ 'autogen/dif_pwrmgr_autogen_unittest.cc',
+ meson.source_root() / 'sw/device/lib/dif/dif_pwrmgr.c',
+ meson.source_root() / 'sw/device/lib/dif/autogen/dif_pwrmgr_autogen.c',
+ hw_ip_pwrmgr_reg_h,
],
dependencies: [
sw_vendor_gtest,
diff --git a/sw/device/silicon_creator/lib/drivers/keymgr_functest.c b/sw/device/silicon_creator/lib/drivers/keymgr_functest.c
index f975713..26c8e97 100644
--- a/sw/device/silicon_creator/lib/drivers/keymgr_functest.c
+++ b/sw/device/silicon_creator/lib/drivers/keymgr_functest.c
@@ -225,12 +225,10 @@
dif_pwrmgr_domain_config_t config;
config = kDifPwrmgrDomainOptionUsbClockInActivePower;
- CHECK(dif_pwrmgr_set_request_sources(pwrmgr, kDifPwrmgrReqTypeWakeup,
- kDifPwrmgrWakeupRequestSourceFive) ==
- kDifPwrmgrConfigOk);
- CHECK(dif_pwrmgr_set_domain_config(pwrmgr, config) == kDifPwrmgrConfigOk);
- CHECK(dif_pwrmgr_low_power_set_enabled(pwrmgr, kDifPwrmgrToggleEnabled) ==
- kDifPwrmgrConfigOk);
+ CHECK_DIF_OK(dif_pwrmgr_set_request_sources(
+ pwrmgr, kDifPwrmgrReqTypeWakeup, kDifPwrmgrWakeupRequestSourceFive));
+ CHECK_DIF_OK(dif_pwrmgr_set_domain_config(pwrmgr, config));
+ CHECK_DIF_OK(dif_pwrmgr_low_power_set_enabled(pwrmgr, kDifToggleEnabled));
// Enter low power mode.
LOG_INFO("Entering low power");
@@ -287,12 +285,8 @@
// Initialize pwrmgr
dif_pwrmgr_t pwrmgr;
- CHECK(dif_pwrmgr_init(
- (dif_pwrmgr_params_t){
- .base_addr =
- mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR),
- },
- &pwrmgr) == kDifPwrmgrOk);
+ CHECK_DIF_OK(dif_pwrmgr_init(
+ mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR), &pwrmgr));
// Initialize aon_timer
dif_aon_timer_t aon_timer;
@@ -303,7 +297,7 @@
// Get wakeup reason
dif_pwrmgr_wakeup_reason_t wakeup_reason;
- CHECK(dif_pwrmgr_wakeup_reason_get(&pwrmgr, &wakeup_reason) == kDifPwrmgrOk);
+ CHECK_DIF_OK(dif_pwrmgr_wakeup_reason_get(&pwrmgr, &wakeup_reason));
if (compare_wakeup_reasons(&wakeup_reason, &kWakeUpReasonPor)) {
LOG_INFO("Powered up for the first time, program flash");
diff --git a/sw/device/tests/pwrmgr_smoketest.c b/sw/device/tests/pwrmgr_smoketest.c
index 958f3ed..648118b 100644
--- a/sw/device/tests/pwrmgr_smoketest.c
+++ b/sw/device/tests/pwrmgr_smoketest.c
@@ -35,12 +35,8 @@
dif_rstmgr_t rstmgr;
// Initialize pwrmgr
- CHECK(dif_pwrmgr_init(
- (dif_pwrmgr_params_t){
- .base_addr =
- mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR),
- },
- &pwrmgr) == kDifPwrmgrOk);
+ CHECK_DIF_OK(dif_pwrmgr_init(
+ mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR), &pwrmgr));
// Initialize rstmgr since this will check some registers.
CHECK_DIF_OK(dif_rstmgr_init(
@@ -50,7 +46,7 @@
// Notice we are clear rstmgr's RESET_INFO, so after the aon wakeup there
// is only one bit set.
dif_pwrmgr_wakeup_reason_t wakeup_reason;
- CHECK(dif_pwrmgr_wakeup_reason_get(&pwrmgr, &wakeup_reason) == kDifPwrmgrOk);
+ CHECK_DIF_OK(dif_pwrmgr_wakeup_reason_get(&pwrmgr, &wakeup_reason));
if (compare_wakeup_reasons(&wakeup_reason, &kWakeUpReasonPor)) {
LOG_INFO("Powered up for the first time, begin test");
@@ -91,12 +87,10 @@
// Issue #6504: USB clock in active power must be left enabled.
config = kDifPwrmgrDomainOptionUsbClockInActivePower;
- CHECK(dif_pwrmgr_set_request_sources(&pwrmgr, kDifPwrmgrReqTypeWakeup,
- kDifPwrmgrWakeupRequestSourceFive) ==
- kDifPwrmgrConfigOk);
- CHECK(dif_pwrmgr_set_domain_config(&pwrmgr, config) == kDifPwrmgrConfigOk);
- CHECK(dif_pwrmgr_low_power_set_enabled(&pwrmgr, kDifPwrmgrToggleEnabled) ==
- kDifPwrmgrConfigOk);
+ CHECK_DIF_OK(dif_pwrmgr_set_request_sources(
+ &pwrmgr, kDifPwrmgrReqTypeWakeup, kDifPwrmgrWakeupRequestSourceFive));
+ CHECK_DIF_OK(dif_pwrmgr_set_domain_config(&pwrmgr, config));
+ CHECK_DIF_OK(dif_pwrmgr_low_power_set_enabled(&pwrmgr, kDifToggleEnabled));
// Enter low power mode.
wait_for_interrupt();
diff --git a/sw/device/tests/sim_dv/pwrmgr_usbdev_smoketest.c b/sw/device/tests/sim_dv/pwrmgr_usbdev_smoketest.c
index 112da6b..e9c8a60 100644
--- a/sw/device/tests/sim_dv/pwrmgr_usbdev_smoketest.c
+++ b/sw/device/tests/sim_dv/pwrmgr_usbdev_smoketest.c
@@ -31,16 +31,12 @@
}
bool test_main(void) {
- CHECK(dif_pwrmgr_init(
- (dif_pwrmgr_params_t){
- .base_addr =
- mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR),
- },
- &pwrmgr) == kDifPwrmgrOk);
+ CHECK_DIF_OK(dif_pwrmgr_init(
+ mmio_region_from_addr(TOP_EARLGREY_PWRMGR_AON_BASE_ADDR), &pwrmgr));
// Assuming the chip hasn't slept yet, wakeup reason should be empty.
dif_pwrmgr_wakeup_reason_t wakeup_reason;
- CHECK(dif_pwrmgr_wakeup_reason_get(&pwrmgr, &wakeup_reason) == kDifPwrmgrOk);
+ CHECK_DIF_OK(dif_pwrmgr_wakeup_reason_get(&pwrmgr, &wakeup_reason));
const dif_pwrmgr_wakeup_reason_t exp_por_wakeup_reason = {
.types = 0,
@@ -73,14 +69,11 @@
usbdev_force_dx_pullup(kDnSel, true);
// Enable low power on the next WFI with default settings.
- CHECK(dif_pwrmgr_set_request_sources(&pwrmgr, kDifPwrmgrReqTypeWakeup,
- kDifPwrmgrWakeupRequestSourceThree) ==
- kDifPwrmgrConfigOk);
- CHECK(dif_pwrmgr_set_domain_config(
- &pwrmgr, kDifPwrmgrDomainOptionUsbClockInActivePower) ==
- kDifPwrmgrConfigOk);
- CHECK(dif_pwrmgr_low_power_set_enabled(&pwrmgr, kDifPwrmgrToggleEnabled) ==
- kDifPwrmgrConfigOk);
+ CHECK_DIF_OK(dif_pwrmgr_set_request_sources(
+ &pwrmgr, kDifPwrmgrReqTypeWakeup, kDifPwrmgrWakeupRequestSourceThree));
+ CHECK_DIF_OK(dif_pwrmgr_set_domain_config(
+ &pwrmgr, kDifPwrmgrDomainOptionUsbClockInActivePower));
+ CHECK_DIF_OK(dif_pwrmgr_low_power_set_enabled(&pwrmgr, kDifToggleEnabled));
// Enter low power mode.
wait_for_interrupt();