1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 00:12:03 +00:00

htc: ObserverThread (mostly), system now boots + works with htc in bg

This commit is contained in:
Michael Scire 2021-02-10 04:22:19 -08:00 committed by SciresM
parent 79a3f442d6
commit 4d86863f2c
6 changed files with 83 additions and 7 deletions

View file

@ -34,7 +34,7 @@ namespace ams::boot2 {
constexpr size_t NumPreSdCardLaunchPrograms = util::size(PreSdCardLaunchPrograms);
constexpr ncm::SystemProgramId AdditionalLaunchPrograms[] = {
ncm::SystemProgramId::Tma, /* tma */
ncm::SystemProgramId::Htc, /* htc */ /* TODO: should we do boot!use_htc_gen2, with default to on in custom settings? */
ncm::SystemProgramId::Am, /* am */
ncm::SystemProgramId::NvServices, /* nvservices */
ncm::SystemProgramId::NvnFlinger, /* nvnflinger */
@ -80,7 +80,7 @@ namespace ams::boot2 {
constexpr size_t NumAdditionalLaunchPrograms = util::size(AdditionalLaunchPrograms);
constexpr ncm::SystemProgramId AdditionalMaintenanceLaunchPrograms[] = {
ncm::SystemProgramId::Tma, /* tma */
ncm::SystemProgramId::Htc, /* htc */
ncm::SystemProgramId::Am, /* am */
ncm::SystemProgramId::NvServices, /* nvservices */
ncm::SystemProgramId::NvnFlinger, /* nvnflinger */

View file

@ -195,4 +195,15 @@ namespace ams::htc::server {
}
}
os::EventType *HtcmiscImpl::GetConnectionEvent() const {
return m_connection_event.GetBase();
}
bool HtcmiscImpl::IsConnected() const {
/* Lock ourselves. */
std::scoped_lock lk(m_connection_mutex);
return m_connected;
}
}

View file

@ -33,11 +33,11 @@ namespace ams::htc::server {
os::ThreadType m_server_thread;
os::Event m_cancel_event;
bool m_cancelled;
os::Event m_connection_event;
mutable os::Event m_connection_event;
bool m_client_connected;
bool m_server_connected;
bool m_connected;
os::SdkMutex m_connection_mutex;
mutable os::SdkMutex m_connection_mutex;
private:
static void ClientThreadEntry(void *arg) { static_cast<HtcmiscImpl *>(arg)->ClientThread(); }
static void ServerThreadEntry(void *arg) { static_cast<HtcmiscImpl *>(arg)->ServerThread(); }
@ -47,6 +47,9 @@ namespace ams::htc::server {
public:
HtcmiscImpl(htclow::HtclowManager *htclow_manager);
~HtcmiscImpl();
os::EventType *GetConnectionEvent() const;
bool IsConnected() const;
private:
void SetClientConnectionEvent(bool en);
void SetServerConnectionEvent(bool en);

View file

@ -29,7 +29,7 @@ namespace ams::htc::server {
m_is_service_available(false)
{
/* Initialize htcs library. */
AMS_ABORT("htcs::impl::HtcsManagerHolder::AddReference();");
/* TODO: AMS_ABORT("htcs::impl::HtcsManagerHolder::AddReference();"); */
/* Update our event state. */
this->UpdateEvent();
@ -69,7 +69,48 @@ namespace ams::htc::server {
}
void Observer::ObserverThreadBody() {
AMS_ABORT("Observer::ObserverThreadBody");
/* When we're done observing, clear our state. */
ON_SCOPE_EXIT {
m_connected = false;
m_is_service_available = false;
this->UpdateEvent();
};
/* Get the events we're waiting on. */
os::EventType * const stop_event = m_stop_event.GetBase();
os::EventType * const conn_event = m_misc_impl.GetConnectionEvent();
os::EventType * const htcs_event = nullptr /* TODO: htcs::impl::HtcsManagerHolder::GetHtcsManager()->GetServiceAvailabilityEvent() */;
/* Loop until we're asked to stop. */
while (!m_stopped) {
/* Wait for an event to be signaled. */
const auto index = os::WaitAny(stop_event, conn_event /*, htcs_event */);
switch (index) {
case 0:
/* Stop event, just break out of the loop. */
os::ClearEvent(stop_event);
break;
case 1:
/* Connection event, update our connection status. */
os::ClearEvent(conn_event);
m_connected = m_misc_impl.IsConnected();
break;
case 2:
/* Htcs event, update our service status. */
os::ClearEvent(htcs_event);
m_is_service_available = false /* TODO: htcs::impl::HtcsManagerHolder::GetHtcsManager()->IsServiceAvailable() */;
break;
AMS_UNREACHABLE_DEFAULT_CASE();
}
/* If the event was our stop event, break. */
if (index == 0) {
break;
}
/* Update event status. */
this->UpdateEvent();
}
}
}

View file

@ -274,7 +274,7 @@ namespace ams::usb {
Result DsInterface::Finalize() {
/* Validate that we have a service. */
R_ABORT_UNLESS(m_interface != nullptr);
AMS_ABORT_UNLESS(m_interface != nullptr);
/* We must be disabled. */
R_UNLESS(!m_client->m_is_enabled, usb::ResultResourceBusy());

View file

@ -42,6 +42,25 @@ namespace ams {
using namespace ams;
#define AMS_HTC_USE_FATAL_ERROR 1
#if AMS_HTC_USE_FATAL_ERROR
extern "C" {
/* Exception handling. */
alignas(16) u8 __nx_exception_stack[ams::os::MemoryPageSize];
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
void __libnx_exception_handler(ThreadExceptionDump *ctx);
}
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
ams::CrashHandler(ctx);
}
#endif
namespace ams::htc {
namespace {
@ -87,6 +106,8 @@ void __appInit(void) {
sm::DoWithSession([&]() {
R_ABORT_UNLESS(setsysInitialize());
R_ABORT_UNLESS(setcalInitialize());
R_ABORT_UNLESS(pscmInitialize());
R_ABORT_UNLESS(fsInitialize());
});