os: refactor/rewrite entire namespace.
This commit is contained in:
@@ -52,7 +52,7 @@ namespace ams::i2c::driver::impl {
|
||||
}
|
||||
|
||||
/* Close interrupt event. */
|
||||
this->interrupt_event.Finalize();
|
||||
os::FinalizeInterruptEvent(std::addressof(this->interrupt_event));
|
||||
|
||||
/* Close PCV. */
|
||||
pcv::Finalize();
|
||||
@@ -152,10 +152,10 @@ namespace ams::i2c::driver::impl {
|
||||
break;
|
||||
}
|
||||
|
||||
this->interrupt_event.Reset();
|
||||
if (!this->interrupt_event.TimedWait(InterruptTimeout)) {
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
if (!os::TimedWaitInterruptEvent(std::addressof(this->interrupt_event), InterruptTimeout)) {
|
||||
this->HandleTransactionResult(i2c::ResultBusBusy());
|
||||
this->interrupt_event.Reset();
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
return i2c::ResultTimedOut();
|
||||
}
|
||||
|
||||
@@ -175,10 +175,10 @@ namespace ams::i2c::driver::impl {
|
||||
break;
|
||||
}
|
||||
|
||||
this->interrupt_event.Reset();
|
||||
if (!this->interrupt_event.TimedWait(InterruptTimeout)) {
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
if (!os::TimedWaitInterruptEvent(std::addressof(this->interrupt_event), InterruptTimeout)) {
|
||||
this->HandleTransactionResult(i2c::ResultBusBusy());
|
||||
this->interrupt_event.Reset();
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
return i2c::ResultTimedOut();
|
||||
}
|
||||
}
|
||||
@@ -200,11 +200,11 @@ namespace ams::i2c::driver::impl {
|
||||
|
||||
/* Receive bytes. */
|
||||
while (remaining > 0) {
|
||||
this->interrupt_event.Reset();
|
||||
if (!this->interrupt_event.TimedWait(InterruptTimeout)) {
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
if (!os::TimedWaitInterruptEvent(std::addressof(this->interrupt_event), InterruptTimeout)) {
|
||||
this->HandleTransactionResult(i2c::ResultBusBusy());
|
||||
this->ClearInterruptMask();
|
||||
this->interrupt_event.Reset();
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
return i2c::ResultTimedOut();
|
||||
}
|
||||
|
||||
@@ -241,7 +241,8 @@ namespace ams::i2c::driver::impl {
|
||||
};
|
||||
const auto index = ConvertToIndex(bus);
|
||||
AMS_ABORT_UNLESS(index < util::size(s_interrupts));
|
||||
R_ABORT_UNLESS(this->interrupt_event.Initialize(s_interrupts[index], false));
|
||||
os::InitializeInterruptEvent(std::addressof(this->interrupt_event), s_interrupts[index], os::EventClearMode_ManualClear);
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
}
|
||||
|
||||
void BusAccessor::SetClock(SpeedMode speed_mode) {
|
||||
@@ -423,7 +424,7 @@ namespace ams::i2c::driver::impl {
|
||||
|
||||
this->HandleTransactionResult(transaction_result);
|
||||
this->ClearInterruptMask();
|
||||
this->interrupt_event.Reset();
|
||||
os::ClearInterruptEvent(std::addressof(this->interrupt_event));
|
||||
return transaction_result;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace ams::i2c::driver::impl {
|
||||
Send = 0,
|
||||
Receive = 1,
|
||||
};
|
||||
static constexpr u64 InterruptTimeout = 100'000'000ul;
|
||||
static constexpr TimeSpan InterruptTimeout = TimeSpan::FromMilliSeconds(100);
|
||||
private:
|
||||
os::InterruptEvent interrupt_event;
|
||||
os::InterruptEventType interrupt_event;
|
||||
os::Mutex open_mutex;
|
||||
os::Mutex register_mutex;
|
||||
Registers *i2c_registers = nullptr;
|
||||
@@ -38,7 +38,7 @@ namespace ams::i2c::driver::impl {
|
||||
PcvModule pcv_module = PcvModule_I2C1;
|
||||
bool suspended = false;
|
||||
public:
|
||||
BusAccessor() { /* ... */ }
|
||||
BusAccessor() : open_mutex(false), register_mutex(false) { /* ... */ }
|
||||
private:
|
||||
inline void ClearInterruptMask() const {
|
||||
reg::Write(&i2c_registers->I2C_INTERRUPT_MASK_REGISTER_0, 0);
|
||||
|
||||
@@ -34,10 +34,18 @@ namespace ams::i2c::driver::impl {
|
||||
bool power_bus_suspended = false;
|
||||
Session sessions[MaxDriverSessions];
|
||||
BusAccessor bus_accessors[ConvertToIndex(Bus::Count)];
|
||||
os::Mutex transaction_mutexes[ConvertToIndex(Bus::Count)];
|
||||
TYPED_STORAGE(os::Mutex) transaction_mutexes[ConvertToIndex(Bus::Count)];
|
||||
public:
|
||||
ResourceManager() {
|
||||
/* ... */
|
||||
ResourceManager() : initialize_mutex(false), session_open_mutex(false) {
|
||||
for (size_t i = 0; i < util::size(this->transaction_mutexes); i++) {
|
||||
new (GetPointer(this->transaction_mutexes[i])) os::Mutex(false);
|
||||
}
|
||||
}
|
||||
|
||||
~ResourceManager() {
|
||||
for (size_t i = 0; i < util::size(this->transaction_mutexes); i++) {
|
||||
GetReference(this->transaction_mutexes[i]).~Mutex();
|
||||
}
|
||||
}
|
||||
private:
|
||||
size_t GetFreeSessionId() const;
|
||||
@@ -57,7 +65,7 @@ namespace ams::i2c::driver::impl {
|
||||
}
|
||||
|
||||
os::Mutex& GetTransactionMutex(Bus bus) {
|
||||
return this->transaction_mutexes[ConvertToIndex(bus)];
|
||||
return GetReference(this->transaction_mutexes[ConvertToIndex(bus)]);
|
||||
}
|
||||
|
||||
void Initialize();
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace ams::i2c::driver::impl {
|
||||
u64 retry_wait_time = 0;
|
||||
bool open = false;
|
||||
public:
|
||||
Session() { /* ... */ }
|
||||
Session() : bus_accessor_mutex(false) { /* ... */ }
|
||||
public:
|
||||
void Open(Bus bus, u32 slave_address, AddressingMode addr_mode, SpeedMode speed_mode, BusAccessor *bus_accessor, u32 max_retries, u64 retry_wait_time);
|
||||
void Start();
|
||||
|
||||
Reference in New Issue
Block a user