mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-03 08:08:39 -04:00
ams: revamp assertion system
This commit is contained in:
parent
9572fb2ce3
commit
40400aee1f
168 changed files with 1014 additions and 696 deletions
|
@ -72,16 +72,16 @@ namespace ams::boot {
|
|||
/* Get values from PMIC. */
|
||||
{
|
||||
PmicDriver pmic_driver;
|
||||
R_ASSERT(pmic_driver.GetPowerIntr(&power_intr));
|
||||
R_ASSERT(pmic_driver.GetNvErc(&nv_erc));
|
||||
R_ASSERT(pmic_driver.GetAcOk(&ac_ok));
|
||||
R_ABORT_UNLESS(pmic_driver.GetPowerIntr(&power_intr));
|
||||
R_ABORT_UNLESS(pmic_driver.GetNvErc(&nv_erc));
|
||||
R_ABORT_UNLESS(pmic_driver.GetAcOk(&ac_ok));
|
||||
}
|
||||
|
||||
/* Get values from RTC. */
|
||||
{
|
||||
RtcDriver rtc_driver;
|
||||
R_ASSERT(rtc_driver.GetRtcIntr(&rtc_intr));
|
||||
R_ASSERT(rtc_driver.GetRtcIntrM(&rtc_intr_m));
|
||||
R_ABORT_UNLESS(rtc_driver.GetRtcIntr(&rtc_intr));
|
||||
R_ABORT_UNLESS(rtc_driver.GetRtcIntrM(&rtc_intr_m));
|
||||
}
|
||||
|
||||
/* Set global derived boot reason. */
|
||||
|
@ -94,14 +94,14 @@ namespace ams::boot {
|
|||
boot_reason_value.rtc_intr = rtc_intr & ~rtc_intr_m;
|
||||
boot_reason_value.nv_erc = nv_erc;
|
||||
boot_reason_value.boot_reason = g_boot_reason;
|
||||
R_ASSERT(splSetBootReason(boot_reason_value.value));
|
||||
R_ABORT_UNLESS(splSetBootReason(boot_reason_value.value));
|
||||
}
|
||||
|
||||
g_detected_boot_reason = true;
|
||||
}
|
||||
|
||||
u32 GetBootReason() {
|
||||
AMS_ASSERT(g_detected_boot_reason);
|
||||
AMS_ABORT_UNLESS(g_detected_boot_reason);
|
||||
return g_boot_reason;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@ namespace ams::boot::bq24193 {
|
|||
constexpr u32 ChargeVoltageLimitMax = 4208;
|
||||
|
||||
inline u8 EncodeChargeVoltageLimit(u32 voltage) {
|
||||
AMS_ASSERT(voltage >= ChargeVoltageLimitMin);
|
||||
AMS_ASSERT(voltage <= ChargeVoltageLimitMax);
|
||||
AMS_ABORT_UNLESS(voltage >= ChargeVoltageLimitMin);
|
||||
AMS_ABORT_UNLESS(voltage <= ChargeVoltageLimitMax);
|
||||
|
||||
voltage -= ChargeVoltageLimitMin;
|
||||
voltage >>= 4;
|
||||
|
@ -56,8 +56,8 @@ namespace ams::boot::bq24193 {
|
|||
constexpr u32 FastChargeCurrentLimitMax = 4544;
|
||||
|
||||
inline u8 EncodeFastChargeCurrentLimit(u32 current) {
|
||||
AMS_ASSERT(current >= FastChargeCurrentLimitMin);
|
||||
AMS_ASSERT(current <= FastChargeCurrentLimitMax);
|
||||
AMS_ABORT_UNLESS(current >= FastChargeCurrentLimitMin);
|
||||
AMS_ABORT_UNLESS(current <= FastChargeCurrentLimitMax);
|
||||
|
||||
current -= FastChargeCurrentLimitMin;
|
||||
current >>= 6;
|
||||
|
@ -83,8 +83,8 @@ namespace ams::boot::bq24193 {
|
|||
constexpr u32 PreChargeCurrentLimitMax = 2048;
|
||||
|
||||
inline u8 EncodePreChargeCurrentLimit(u32 current) {
|
||||
AMS_ASSERT(current >= PreChargeCurrentLimitMin);
|
||||
AMS_ASSERT(current <= PreChargeCurrentLimitMax);
|
||||
AMS_ABORT_UNLESS(current >= PreChargeCurrentLimitMin);
|
||||
AMS_ABORT_UNLESS(current <= PreChargeCurrentLimitMax);
|
||||
|
||||
current -= PreChargeCurrentLimitMin;
|
||||
current >>= 7;
|
||||
|
@ -99,8 +99,8 @@ namespace ams::boot::bq24193 {
|
|||
constexpr u32 TerminationCurrentLimitMax = 2048;
|
||||
|
||||
inline u8 EncodeTerminationCurrentLimit(u32 current) {
|
||||
AMS_ASSERT(current >= TerminationCurrentLimitMin);
|
||||
AMS_ASSERT(current <= TerminationCurrentLimitMax);
|
||||
AMS_ABORT_UNLESS(current >= TerminationCurrentLimitMin);
|
||||
AMS_ABORT_UNLESS(current <= TerminationCurrentLimitMax);
|
||||
|
||||
current -= TerminationCurrentLimitMin;
|
||||
current >>= 7;
|
||||
|
@ -115,8 +115,8 @@ namespace ams::boot::bq24193 {
|
|||
constexpr u32 MinimumSystemVoltageLimitMax = 3700;
|
||||
|
||||
inline u8 EncodeMinimumSystemVoltageLimit(u32 voltage) {
|
||||
AMS_ASSERT(voltage >= MinimumSystemVoltageLimitMin);
|
||||
AMS_ASSERT(voltage <= MinimumSystemVoltageLimitMax);
|
||||
AMS_ABORT_UNLESS(voltage >= MinimumSystemVoltageLimitMin);
|
||||
AMS_ABORT_UNLESS(voltage <= MinimumSystemVoltageLimitMax);
|
||||
|
||||
voltage -= MinimumSystemVoltageLimitMin;
|
||||
voltage /= 100;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace ams::boot {
|
|||
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
||||
};
|
||||
|
||||
AMS_ASSERT(data != nullptr);
|
||||
AMS_ABORT_UNLESS(data != nullptr);
|
||||
|
||||
u16 crc16 = 0x55AA;
|
||||
const u8 *data_u8 = reinterpret_cast<const u8 *>(data);
|
||||
|
|
|
@ -126,12 +126,12 @@ namespace ams::boot {
|
|||
armDCacheFlush(g_frame_buffer, FrameBufferSize);
|
||||
|
||||
/* Create Address Space. */
|
||||
R_ASSERT(svcCreateDeviceAddressSpace(&g_dc_das_hnd, 0, (1ul << 32)));
|
||||
R_ABORT_UNLESS(svcCreateDeviceAddressSpace(&g_dc_das_hnd, 0, (1ul << 32)));
|
||||
/* Attach it to the DC. */
|
||||
R_ASSERT(svcAttachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
|
||||
R_ABORT_UNLESS(svcAttachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
|
||||
|
||||
/* Map the framebuffer for the DC as read-only. */
|
||||
R_ASSERT(svcMapDeviceAddressSpaceAligned(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr, 1));
|
||||
R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,11 +140,11 @@ namespace ams::boot {
|
|||
const uintptr_t frame_buffer_aligned = reinterpret_cast<uintptr_t>(g_frame_buffer);
|
||||
|
||||
/* Unmap the framebuffer from the DC. */
|
||||
R_ASSERT(svcUnmapDeviceAddressSpace(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr));
|
||||
R_ABORT_UNLESS(svcUnmapDeviceAddressSpace(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr));
|
||||
/* Detach address space from the DC. */
|
||||
R_ASSERT(svcDetachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
|
||||
R_ABORT_UNLESS(svcDetachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
|
||||
/* Close the address space. */
|
||||
R_ASSERT(svcCloseHandle(g_dc_das_hnd));
|
||||
R_ABORT_UNLESS(svcCloseHandle(g_dc_das_hnd));
|
||||
g_dc_das_hnd = INVALID_HANDLE;
|
||||
g_frame_buffer = nullptr;
|
||||
}
|
||||
|
|
|
@ -42,21 +42,21 @@ namespace ams::boot {
|
|||
}
|
||||
|
||||
Result ReadI2cRegister(i2c::driver::Session &session, u8 *dst, size_t dst_size, const u8 *cmd, size_t cmd_size) {
|
||||
AMS_ASSERT(dst != nullptr && dst_size > 0);
|
||||
AMS_ASSERT(cmd != nullptr && cmd_size > 0);
|
||||
AMS_ABORT_UNLESS(dst != nullptr && dst_size > 0);
|
||||
AMS_ABORT_UNLESS(cmd != nullptr && cmd_size > 0);
|
||||
|
||||
u8 cmd_list[i2c::CommandListFormatter::MaxCommandListSize];
|
||||
|
||||
i2c::CommandListFormatter formatter(cmd_list, sizeof(cmd_list));
|
||||
R_ASSERT(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size));
|
||||
R_ASSERT(formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size));
|
||||
R_ABORT_UNLESS(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size));
|
||||
R_ABORT_UNLESS(formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size));
|
||||
|
||||
return RetryUntilSuccess([&]() { return i2c::driver::ExecuteCommandList(session, dst, dst_size, cmd_list, formatter.GetCurrentSize()); });
|
||||
}
|
||||
|
||||
Result WriteI2cRegister(i2c::driver::Session &session, const u8 *src, size_t src_size, const u8 *cmd, size_t cmd_size) {
|
||||
AMS_ASSERT(src != nullptr && src_size > 0);
|
||||
AMS_ASSERT(cmd != nullptr && cmd_size > 0);
|
||||
AMS_ABORT_UNLESS(src != nullptr && src_size > 0);
|
||||
AMS_ABORT_UNLESS(cmd != nullptr && cmd_size > 0);
|
||||
|
||||
u8 cmd_list[0x20];
|
||||
|
||||
|
|
|
@ -90,9 +90,9 @@ void __appInit(void) {
|
|||
|
||||
/* Initialize services we need (TODO: NCM) */
|
||||
sm::DoWithSession([&]() {
|
||||
R_ASSERT(fsInitialize());
|
||||
R_ASSERT(splInitialize());
|
||||
R_ASSERT(pmshellInitialize());
|
||||
R_ABORT_UNLESS(fsInitialize());
|
||||
R_ABORT_UNLESS(splInitialize());
|
||||
R_ABORT_UNLESS(pmshellInitialize());
|
||||
});
|
||||
|
||||
ams::CheckApiVersion();
|
||||
|
@ -147,7 +147,7 @@ int main(int argc, char **argv)
|
|||
boot::CheckAndRepairBootImages();
|
||||
|
||||
/* Tell PM to start boot2. */
|
||||
R_ASSERT(pmshellNotifyBootFinished());
|
||||
R_ABORT_UNLESS(pmshellNotifyBootFinished());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -32,19 +32,19 @@ namespace ams::boot {
|
|||
|
||||
inline u32 ReadWriteRegisterImpl(uintptr_t phys_addr, u32 value, u32 mask) {
|
||||
u32 out_value;
|
||||
R_ASSERT(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value)));
|
||||
R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value)));
|
||||
return out_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u32 ReadPmcRegister(u32 phys_addr) {
|
||||
AMS_ASSERT(IsValidPmcAddress(phys_addr));
|
||||
AMS_ABORT_UNLESS(IsValidPmcAddress(phys_addr));
|
||||
return ReadWriteRegisterImpl(phys_addr, 0, 0);
|
||||
}
|
||||
|
||||
void WritePmcRegister(u32 phys_addr, u32 value, u32 mask) {
|
||||
AMS_ASSERT(IsValidPmcAddress(phys_addr));
|
||||
AMS_ABORT_UNLESS(IsValidPmcAddress(phys_addr));
|
||||
ReadWriteRegisterImpl(phys_addr, value, mask);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
namespace ams::boot {
|
||||
|
||||
void PmicDriver::ShutdownSystem() {
|
||||
R_ASSERT(this->ShutdownSystem(false));
|
||||
R_ABORT_UNLESS(this->ShutdownSystem(false));
|
||||
}
|
||||
|
||||
void PmicDriver::RebootSystem() {
|
||||
R_ASSERT(this->ShutdownSystem(true));
|
||||
R_ABORT_UNLESS(this->ShutdownSystem(true));
|
||||
}
|
||||
|
||||
Result PmicDriver::GetAcOk(bool *out) {
|
||||
|
@ -61,17 +61,17 @@ namespace ams::boot {
|
|||
|
||||
/* Get value, set or clear software reset mask. */
|
||||
u8 on_off_2_val = 0;
|
||||
R_ASSERT(ReadI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
|
||||
R_ABORT_UNLESS(ReadI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
|
||||
if (reboot) {
|
||||
on_off_2_val |= 0x80;
|
||||
} else {
|
||||
on_off_2_val &= ~0x80;
|
||||
}
|
||||
R_ASSERT(WriteI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
|
||||
R_ABORT_UNLESS(WriteI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
|
||||
|
||||
/* Get value, set software reset mask. */
|
||||
u8 on_off_1_val = 0;
|
||||
R_ASSERT(ReadI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
|
||||
R_ABORT_UNLESS(ReadI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
|
||||
on_off_1_val |= 0x80;
|
||||
|
||||
/* Finalize the battery. */
|
||||
|
@ -81,11 +81,11 @@ namespace ams::boot {
|
|||
}
|
||||
|
||||
/* Actually write the value to trigger shutdown/reset. */
|
||||
R_ASSERT(WriteI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
|
||||
R_ABORT_UNLESS(WriteI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
|
||||
|
||||
/* Allow up to 5 seconds for shutdown/reboot to take place. */
|
||||
svcSleepThread(5'000'000'000ul);
|
||||
AMS_ASSERT(false);
|
||||
AMS_ABORT_UNLESS(false);
|
||||
}
|
||||
|
||||
void PmicDriver::FinalizeBattery(BatteryDriver *battery_driver) {
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace ams::gpio {
|
|||
}
|
||||
|
||||
/* Ensure we found an appropriate config. */
|
||||
AMS_ASSERT(configs != nullptr);
|
||||
AMS_ABORT_UNLESS(configs != nullptr);
|
||||
|
||||
for (size_t i = 0; i < num_configs; i++) {
|
||||
/* Configure the GPIO. */
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace ams::gpio {
|
|||
|
||||
/* Helpers. */
|
||||
inline u32 GetPadDescriptor(u32 gpio_pad_name) {
|
||||
AMS_ASSERT(gpio_pad_name < PadNameMax);
|
||||
AMS_ABORT_UNLESS(gpio_pad_name < PadNameMax);
|
||||
return Map[gpio_pad_name];
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace ams::i2c::driver {
|
|||
}
|
||||
|
||||
inline void CheckInitialized() {
|
||||
AMS_ASSERT(GetResourceManager().IsInitialized());
|
||||
AMS_ABORT_UNLESS(GetResourceManager().IsInitialized());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ namespace ams::i2c::driver {
|
|||
/* Session management. */
|
||||
void OpenSession(Session *out_session, I2cDevice device) {
|
||||
CheckInitialized();
|
||||
AMS_ASSERT(impl::IsDeviceSupported(device));
|
||||
AMS_ABORT_UNLESS(impl::IsDeviceSupported(device));
|
||||
|
||||
const auto bus = impl::GetDeviceBus(device);
|
||||
const auto slave_address = impl::GetDeviceSlaveAddress(device);
|
||||
|
@ -119,8 +119,8 @@ namespace ams::i2c::driver {
|
|||
/* Communication. */
|
||||
Result Send(Session &session, const void *src, size_t size, I2cTransactionOption option) {
|
||||
CheckInitialized();
|
||||
AMS_ASSERT(src != nullptr);
|
||||
AMS_ASSERT(size > 0);
|
||||
AMS_ABORT_UNLESS(src != nullptr);
|
||||
AMS_ABORT_UNLESS(size > 0);
|
||||
|
||||
std::scoped_lock<os::Mutex &> lk(GetResourceManager().GetTransactionMutex(impl::ConvertFromIndex(session.bus_idx)));
|
||||
return GetResourceManager().GetSession(session.session_id).DoTransactionWithRetry(nullptr, src, size, option, impl::Command::Send);
|
||||
|
@ -128,8 +128,8 @@ namespace ams::i2c::driver {
|
|||
|
||||
Result Receive(Session &session, void *dst, size_t size, I2cTransactionOption option) {
|
||||
CheckInitialized();
|
||||
AMS_ASSERT(dst != nullptr);
|
||||
AMS_ASSERT(size > 0);
|
||||
AMS_ABORT_UNLESS(dst != nullptr);
|
||||
AMS_ABORT_UNLESS(size > 0);
|
||||
|
||||
std::scoped_lock<os::Mutex &> lk(GetResourceManager().GetTransactionMutex(impl::ConvertFromIndex(session.bus_idx)));
|
||||
return GetResourceManager().GetSession(session.session_id).DoTransactionWithRetry(dst, nullptr, size, option, impl::Command::Receive);
|
||||
|
@ -137,8 +137,8 @@ namespace ams::i2c::driver {
|
|||
|
||||
Result ExecuteCommandList(Session &session, void *dst, size_t size, const void *cmd_list, size_t cmd_list_size) {
|
||||
CheckInitialized();
|
||||
AMS_ASSERT(dst != nullptr && size > 0);
|
||||
AMS_ASSERT(cmd_list != nullptr && cmd_list_size > 0);
|
||||
AMS_ABORT_UNLESS(dst != nullptr && size > 0);
|
||||
AMS_ABORT_UNLESS(cmd_list != nullptr && cmd_list_size > 0);
|
||||
|
||||
u8 *cur_dst = static_cast<u8 *>(dst);
|
||||
const u8 *cur_cmd = static_cast<const u8 *>(cmd_list);
|
||||
|
@ -146,7 +146,7 @@ namespace ams::i2c::driver {
|
|||
|
||||
while (cur_cmd < cmd_list_end) {
|
||||
Command cmd = static_cast<Command>((*cur_cmd) & 3);
|
||||
AMS_ASSERT(cmd < Command::Count);
|
||||
AMS_ABORT_UNLESS(cmd < Command::Count);
|
||||
|
||||
R_TRY(g_cmd_handlers[static_cast<size_t>(cmd)](&cur_cmd, &cur_dst, session));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::i2c::driver::impl {
|
|||
|
||||
/* Ensure we're good if this isn't our first session. */
|
||||
if (this->open_sessions > 1) {
|
||||
AMS_ASSERT(this->speed_mode == speed_mode);
|
||||
AMS_ABORT_UNLESS(this->speed_mode == speed_mode);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -240,8 +240,8 @@ namespace ams::i2c::driver::impl {
|
|||
0x46, 0x74, 0x7C, 0x98, 0x55, 0x5F
|
||||
};
|
||||
const auto index = ConvertToIndex(bus);
|
||||
AMS_ASSERT(index < util::size(s_interrupts));
|
||||
R_ASSERT(this->interrupt_event.Initialize(s_interrupts[index], false));
|
||||
AMS_ABORT_UNLESS(index < util::size(s_interrupts));
|
||||
R_ABORT_UNLESS(this->interrupt_event.Initialize(s_interrupts[index], false));
|
||||
}
|
||||
|
||||
void BusAccessor::SetClock(SpeedMode speed_mode) {
|
||||
|
@ -293,17 +293,17 @@ namespace ams::i2c::driver::impl {
|
|||
reg::Read(&this->i2c_registers->I2C_I2C_CNFG_0);
|
||||
|
||||
if (this->pcv_module != PcvModule_I2C5) {
|
||||
R_ASSERT(pcv::SetReset(this->pcv_module, true));
|
||||
R_ASSERT(pcv::SetClockRate(this->pcv_module, (408'000'000) / (src_div + 1)));
|
||||
R_ASSERT(pcv::SetReset(this->pcv_module, false));
|
||||
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, true));
|
||||
R_ABORT_UNLESS(pcv::SetClockRate(this->pcv_module, (408'000'000) / (src_div + 1)));
|
||||
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, false));
|
||||
}
|
||||
}
|
||||
|
||||
void BusAccessor::ResetController() const {
|
||||
if (this->pcv_module != PcvModule_I2C5) {
|
||||
R_ASSERT(pcv::SetReset(this->pcv_module, true));
|
||||
R_ASSERT(pcv::SetClockRate(this->pcv_module, 81'600'000));
|
||||
R_ASSERT(pcv::SetReset(this->pcv_module, false));
|
||||
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, true));
|
||||
R_ABORT_UNLESS(pcv::SetClockRate(this->pcv_module, 81'600'000));
|
||||
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ namespace ams::i2c::driver::impl {
|
|||
}
|
||||
|
||||
void BusAccessor::DisableClock() {
|
||||
R_ASSERT(pcv::SetClockEnabled(this->pcv_module, false));
|
||||
R_ABORT_UNLESS(pcv::SetClockEnabled(this->pcv_module, false));
|
||||
}
|
||||
|
||||
void BusAccessor::SetPacketMode() {
|
||||
|
|
|
@ -84,37 +84,37 @@ namespace ams::i2c::driver::impl {
|
|||
|
||||
Bus GetDeviceBus(I2cDevice dev) {
|
||||
const size_t dev_idx = GetDeviceIndex(dev);
|
||||
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
|
||||
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
|
||||
return g_device_configs[dev_idx].bus;
|
||||
}
|
||||
|
||||
u32 GetDeviceSlaveAddress(I2cDevice dev) {
|
||||
const size_t dev_idx = GetDeviceIndex(dev);
|
||||
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
|
||||
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
|
||||
return g_device_configs[dev_idx].slave_address;
|
||||
}
|
||||
|
||||
AddressingMode GetDeviceAddressingMode(I2cDevice dev) {
|
||||
const size_t dev_idx = GetDeviceIndex(dev);
|
||||
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
|
||||
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
|
||||
return g_device_configs[dev_idx].addressing_mode;
|
||||
}
|
||||
|
||||
SpeedMode GetDeviceSpeedMode(I2cDevice dev) {
|
||||
const size_t dev_idx = GetDeviceIndex(dev);
|
||||
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
|
||||
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
|
||||
return g_device_configs[dev_idx].speed_mode;
|
||||
}
|
||||
|
||||
u32 GetDeviceMaxRetries(I2cDevice dev) {
|
||||
const size_t dev_idx = GetDeviceIndex(dev);
|
||||
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
|
||||
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
|
||||
return g_device_configs[dev_idx].max_retries;
|
||||
}
|
||||
|
||||
u64 GetDeviceRetryWaitTime(I2cDevice dev) {
|
||||
const size_t dev_idx = GetDeviceIndex(dev);
|
||||
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
|
||||
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
|
||||
return g_device_configs[dev_idx].retry_wait_time;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace ams::i2c::driver::impl {
|
|||
}
|
||||
|
||||
constexpr inline Bus ConvertFromIndex(size_t idx) {
|
||||
AMS_ASSERT(idx < static_cast<size_t>(Bus::Count));
|
||||
AMS_ABORT_UNLESS(idx < static_cast<size_t>(Bus::Count));
|
||||
return static_cast<Bus>(idx);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::i2c::driver::impl {
|
|||
|
||||
void ResourceManager::Finalize() {
|
||||
std::scoped_lock lk(this->initialize_mutex);
|
||||
AMS_ASSERT(this->ref_cnt > 0);
|
||||
AMS_ABORT_UNLESS(this->ref_cnt > 0);
|
||||
this->ref_cnt--;
|
||||
if (this->ref_cnt > 0) {
|
||||
return;
|
||||
|
@ -55,11 +55,11 @@ namespace ams::i2c::driver::impl {
|
|||
/* Get, open session. */
|
||||
{
|
||||
std::scoped_lock lk(this->session_open_mutex);
|
||||
AMS_ASSERT(out_session != nullptr);
|
||||
AMS_ASSERT(bus < Bus::Count);
|
||||
AMS_ABORT_UNLESS(out_session != nullptr);
|
||||
AMS_ABORT_UNLESS(bus < Bus::Count);
|
||||
|
||||
session_id = GetFreeSessionId();
|
||||
AMS_ASSERT(session_id != InvalidSessionId);
|
||||
AMS_ABORT_UNLESS(session_id != InvalidSessionId);
|
||||
|
||||
|
||||
if ((bus == Bus::I2C2 || bus == Bus::I2C3) && (this->bus_accessors[ConvertToIndex(Bus::I2C2)].GetOpenSessions() == 0 && this->bus_accessors[ConvertToIndex(Bus::I2C3)].GetOpenSessions() == 0)) {
|
||||
|
@ -74,8 +74,8 @@ namespace ams::i2c::driver::impl {
|
|||
this->sessions[session_id].Start();
|
||||
if (need_enable_ldo6) {
|
||||
pcv::Initialize();
|
||||
R_ASSERT(pcv::SetVoltageValue(10, 2'900'000));
|
||||
R_ASSERT(pcv::SetVoltageEnabled(10, true));
|
||||
R_ABORT_UNLESS(pcv::SetVoltageValue(10, 2'900'000));
|
||||
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, true));
|
||||
pcv::Finalize();
|
||||
svcSleepThread(560'000ul);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ namespace ams::i2c::driver::impl {
|
|||
/* Get, open session. */
|
||||
{
|
||||
std::scoped_lock lk(this->session_open_mutex);
|
||||
AMS_ASSERT(this->sessions[session.session_id].IsOpen());
|
||||
AMS_ABORT_UNLESS(this->sessions[session.session_id].IsOpen());
|
||||
|
||||
this->sessions[session.session_id].Close();
|
||||
|
||||
|
@ -98,14 +98,14 @@ namespace ams::i2c::driver::impl {
|
|||
|
||||
if (need_disable_ldo6) {
|
||||
pcv::Initialize();
|
||||
R_ASSERT(pcv::SetVoltageEnabled(10, false));
|
||||
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, false));
|
||||
pcv::Finalize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ResourceManager::SuspendBuses() {
|
||||
AMS_ASSERT(this->ref_cnt > 0);
|
||||
AMS_ABORT_UNLESS(this->ref_cnt > 0);
|
||||
|
||||
if (!this->suspended) {
|
||||
{
|
||||
|
@ -118,19 +118,19 @@ namespace ams::i2c::driver::impl {
|
|||
}
|
||||
}
|
||||
pcv::Initialize();
|
||||
R_ASSERT(pcv::SetVoltageEnabled(10, false));
|
||||
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, false));
|
||||
pcv::Finalize();
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::ResumeBuses() {
|
||||
AMS_ASSERT(this->ref_cnt > 0);
|
||||
AMS_ABORT_UNLESS(this->ref_cnt > 0);
|
||||
|
||||
if (this->suspended) {
|
||||
if (this->bus_accessors[ConvertToIndex(Bus::I2C2)].GetOpenSessions() > 0 || this->bus_accessors[ConvertToIndex(Bus::I2C3)].GetOpenSessions() > 0) {
|
||||
pcv::Initialize();
|
||||
R_ASSERT(pcv::SetVoltageValue(10, 2'900'000));
|
||||
R_ASSERT(pcv::SetVoltageEnabled(10, true));
|
||||
R_ABORT_UNLESS(pcv::SetVoltageValue(10, 2'900'000));
|
||||
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, true));
|
||||
pcv::Finalize();
|
||||
svcSleepThread(1'560'000ul);
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ namespace ams::i2c::driver::impl {
|
|||
}
|
||||
|
||||
void ResourceManager::SuspendPowerBus() {
|
||||
AMS_ASSERT(this->ref_cnt > 0);
|
||||
AMS_ABORT_UNLESS(this->ref_cnt > 0);
|
||||
std::scoped_lock lk(this->session_open_mutex);
|
||||
|
||||
if (!this->power_bus_suspended) {
|
||||
|
@ -159,7 +159,7 @@ namespace ams::i2c::driver::impl {
|
|||
}
|
||||
|
||||
void ResourceManager::ResumePowerBus() {
|
||||
AMS_ASSERT(this->ref_cnt > 0);
|
||||
AMS_ABORT_UNLESS(this->ref_cnt > 0);
|
||||
std::scoped_lock lk(this->session_open_mutex);
|
||||
|
||||
if (this->power_bus_suspended) {
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace ams::i2c {
|
|||
size_t cur_index = 0;
|
||||
public:
|
||||
CommandListFormatter(void *cmd_list, size_t cmd_list_size) : cmd_list(static_cast<u8 *>(cmd_list)), cmd_list_size(cmd_list_size) {
|
||||
AMS_ASSERT(cmd_list_size <= MaxCommandListSize);
|
||||
AMS_ABORT_UNLESS(cmd_list_size <= MaxCommandListSize);
|
||||
}
|
||||
~CommandListFormatter() {
|
||||
this->cmd_list = nullptr;
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace ams::pinmux {
|
|||
}
|
||||
|
||||
/* Ensure we found an appropriate config. */
|
||||
AMS_ASSERT(configs != nullptr);
|
||||
AMS_ABORT_UNLESS(configs != nullptr);
|
||||
|
||||
for (size_t i = 0; i < num_configs; i++) {
|
||||
UpdatePad(configs[i].name, configs[i].val, configs[i].mask);
|
||||
|
|
|
@ -30,12 +30,12 @@ namespace ams::pinmux {
|
|||
|
||||
/* Helpers. */
|
||||
inline const Definition *GetDefinition(u32 pinmux_name) {
|
||||
AMS_ASSERT(pinmux_name < PadNameMax);
|
||||
AMS_ABORT_UNLESS(pinmux_name < PadNameMax);
|
||||
return &Map[pinmux_name];
|
||||
}
|
||||
|
||||
inline const DrivePadDefinition *GetDrivePadDefinition(u32 drivepad_name) {
|
||||
AMS_ASSERT(drivepad_name < DrivePadNameMax);
|
||||
AMS_ABORT_UNLESS(drivepad_name < DrivePadNameMax);
|
||||
return &DrivePadMap[drivepad_name];
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ namespace ams::pinmux {
|
|||
u32 pinmux_val = reg::Read(pinmux_reg);
|
||||
|
||||
/* This PINMUX register is locked */
|
||||
AMS_ASSERT((pinmux_val & 0x80) == 0);
|
||||
AMS_ABORT_UNLESS((pinmux_val & 0x80) == 0);
|
||||
|
||||
u32 pm_val = (pinmux_config_val & 0x07);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue