mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-28 05:34:11 -04:00
os: refactor/rewrite entire namespace.
This commit is contained in:
parent
6193283f03
commit
065485b971
181 changed files with 5353 additions and 1929 deletions
|
@ -56,6 +56,10 @@ namespace ams::boot {
|
|||
constexpr size_t ApbMiscSize = os::MemoryPageSize;
|
||||
constexpr size_t MipiCalSize = os::MemoryPageSize;
|
||||
|
||||
constexpr s32 DsiWaitForCommandMilliSecondsMax = 250;
|
||||
constexpr s32 DsiWaitForCommandCompletionMilliSeconds = 5;
|
||||
constexpr s32 DsiWaitForHostControlMilliSecondsMax = 150;
|
||||
|
||||
/* Types. */
|
||||
|
||||
/* Globals. */
|
||||
|
@ -151,10 +155,10 @@ namespace ams::boot {
|
|||
}
|
||||
|
||||
void WaitDsiTrigger() {
|
||||
os::TimeoutHelper timeout_helper(250'000'000ul);
|
||||
os::Tick timeout = os::GetSystemTick() + os::ConvertToTick(TimeSpan::FromMilliSeconds(DsiWaitForCommandMilliSecondsMax));
|
||||
|
||||
while (true) {
|
||||
if (timeout_helper.TimedOut()) {
|
||||
if (os::GetSystemTick() >= timeout) {
|
||||
break;
|
||||
}
|
||||
if (reg::Read(g_dsi_regs + sizeof(u32) * DSI_TRIGGER) == 0) {
|
||||
|
@ -162,14 +166,14 @@ namespace ams::boot {
|
|||
}
|
||||
}
|
||||
|
||||
svcSleepThread(5'000'000ul);
|
||||
os::SleepThread(TimeSpan::FromMilliSeconds(DsiWaitForCommandCompletionMilliSeconds));
|
||||
}
|
||||
|
||||
void WaitDsiHostControl() {
|
||||
os::TimeoutHelper timeout_helper(150'000'000ul);
|
||||
os::Tick timeout = os::GetSystemTick() + os::ConvertToTick(TimeSpan::FromMilliSeconds(DsiWaitForHostControlMilliSecondsMax));
|
||||
|
||||
while (true) {
|
||||
if (timeout_helper.TimedOut()) {
|
||||
if (os::GetSystemTick() >= timeout) {
|
||||
break;
|
||||
}
|
||||
if ((reg::Read(g_dsi_regs + sizeof(u32) * DSI_HOST_CONTROL) & DSI_HOST_CONTROL_IMM_BTA) == 0) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue