ams: revamp assertion system
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user