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