diff --git a/libraries/libstratosphere/include/stratosphere/htclow/impl/htclow_internal_types.hpp b/libraries/libstratosphere/include/stratosphere/htclow/impl/htclow_internal_types.hpp index 30bcb5860..bee584a85 100644 --- a/libraries/libstratosphere/include/stratosphere/htclow/impl/htclow_internal_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/htclow/impl/htclow_internal_types.hpp @@ -26,7 +26,7 @@ namespace ams::htclow::impl { }; static_assert(sizeof(ChannelInternalType) == 4); - ALWAYS_INLINE ChannelInternalType ConvertChannelType(ChannelType channel) { + constexpr ALWAYS_INLINE ChannelInternalType ConvertChannelType(ChannelType channel) { return { .channel_id = channel._channel_id, .reserved = 0, @@ -34,27 +34,27 @@ namespace ams::htclow::impl { }; } - ALWAYS_INLINE bool operator==(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { + constexpr ALWAYS_INLINE bool operator==(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { return lhs.module_id == rhs.module_id && lhs.reserved == rhs.reserved && lhs.channel_id == rhs.channel_id; } - ALWAYS_INLINE bool operator!=(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { + constexpr ALWAYS_INLINE bool operator!=(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { return !(lhs == rhs); } - ALWAYS_INLINE bool operator<(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { + constexpr ALWAYS_INLINE bool operator<(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { return lhs.module_id < rhs.module_id || lhs.reserved < rhs.reserved || lhs.channel_id < rhs.channel_id; } - ALWAYS_INLINE bool operator>(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { + constexpr ALWAYS_INLINE bool operator>(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { return rhs < lhs; } - ALWAYS_INLINE bool operator<=(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { + constexpr ALWAYS_INLINE bool operator<=(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { return !(lhs > rhs); } - ALWAYS_INLINE bool operator>=(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { + constexpr ALWAYS_INLINE bool operator>=(const ChannelInternalType &lhs, const ChannelInternalType &rhs) { return !(lhs < rhs); } diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet.hpp index 630b8ede1..574dcf845 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet_factory.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet_factory.hpp index d370ee39c..8670672d7 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet_factory.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_packet_factory.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_send_buffer.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_send_buffer.hpp index 5bf7ff413..abe1cf239 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_send_buffer.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_send_buffer.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp index df0988614..9c42fd258 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp index 762f57808..df956e832 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state.hpp index 0df654f61..9d739758a 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -19,7 +19,7 @@ namespace ams::htclow::ctrl { enum HtcctrlState : u32 { - /* ... */ + HtcctrlState_Eleven = 11, }; } diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.cpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.cpp new file mode 100644 index 000000000..655a1f8c1 --- /dev/null +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "htclow_ctrl_state_machine.hpp" + +namespace ams::htclow::ctrl { + + namespace { + + constexpr const impl::ChannelInternalType ServiceChannels[] = { + { + .channel_id = 0, + .module_id = static_cast(1), + }, + { + .channel_id = 1, + .module_id = static_cast(3), + }, + { + .channel_id = 2, + .module_id = static_cast(3), + }, + { + .channel_id = 0, + .module_id = static_cast(4), + }, + }; + + } + + HtcctrlStateMachine::HtcctrlStateMachine() : m_map(), m_state(HtcctrlState_Eleven), m_prev_state(HtcctrlState_Eleven), m_mutex() { + /* Lock ourselves. */ + std::scoped_lock lk(m_mutex); + + /* Initialize our map. */ + m_map.Initialize(MaxChannelCount, m_map_buffer, sizeof(m_map_buffer)); + + /* Insert each service channel the map. */ + for (const auto &channel : ServiceChannels) { + m_map.insert(std::make_pair(impl::ChannelInternalType{channel}, ServiceChannelState{})); + } + } + +} diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.hpp index a662950ea..10053e793 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.hpp b/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.hpp index caf909ee9..5eb99553e 100644 --- a/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.hpp +++ b/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/driver/htclow_i_driver.hpp b/libraries/libstratosphere/source/htclow/driver/htclow_i_driver.hpp index 7ed703854..ef13c635e 100644 --- a/libraries/libstratosphere/source/htclow/driver/htclow_i_driver.hpp +++ b/libraries/libstratosphere/source/htclow/driver/htclow_i_driver.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_listener.hpp b/libraries/libstratosphere/source/htclow/htclow_listener.hpp index 0526aea50..b6771cf87 100644 --- a/libraries/libstratosphere/source/htclow/htclow_listener.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_listener.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_manager.cpp b/libraries/libstratosphere/source/htclow/htclow_manager.cpp index 527e4d50d..44c670d29 100644 --- a/libraries/libstratosphere/source/htclow/htclow_manager.cpp +++ b/libraries/libstratosphere/source/htclow/htclow_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_manager.hpp b/libraries/libstratosphere/source/htclow/htclow_manager.hpp index c4160426b..727422a25 100644 --- a/libraries/libstratosphere/source/htclow/htclow_manager.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_manager.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_manager_holder.cpp b/libraries/libstratosphere/source/htclow/htclow_manager_holder.cpp index d97854b94..b33bc3600 100644 --- a/libraries/libstratosphere/source/htclow/htclow_manager_holder.cpp +++ b/libraries/libstratosphere/source/htclow/htclow_manager_holder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp b/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp index e65f5c538..2bf71ffa0 100644 --- a/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp +++ b/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_manager_impl.hpp b/libraries/libstratosphere/source/htclow/htclow_manager_impl.hpp index 8bdac84b1..8a6f05d11 100644 --- a/libraries/libstratosphere/source/htclow/htclow_manager_impl.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_manager_impl.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_packet.hpp b/libraries/libstratosphere/source/htclow/htclow_packet.hpp index 89241c4be..11a53b4bd 100644 --- a/libraries/libstratosphere/source/htclow/htclow_packet.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_packet.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_packet_factory.hpp b/libraries/libstratosphere/source/htclow/htclow_packet_factory.hpp index 2a4f44093..5c0f85dd3 100644 --- a/libraries/libstratosphere/source/htclow/htclow_packet_factory.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_packet_factory.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/htclow_worker.hpp b/libraries/libstratosphere/source/htclow/htclow_worker.hpp index cc7b5fd8e..d4b046e76 100644 --- a/libraries/libstratosphere/source/htclow/htclow_worker.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_worker.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp new file mode 100644 index 000000000..d5a7a3e46 --- /dev/null +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "htclow_mux.hpp" + +namespace ams::htclow::mux { + + Mux::Mux(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm) + : m_packet_factory(pf), m_state_machine(sm), m_task_manager(), m_wake_event(os::EventClearMode_ManualClear), + m_channel_impl_map(pf, sm, std::addressof(m_task_manager), std::addressof(m_wake_event)), m_global_send_buffer(pf), + m_mutex(), m_is_sleeping(false), m_version(5) + { + /* ... */ + } + +} diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp index 03e4c0152..dbe9b856b 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -26,7 +26,7 @@ namespace ams::htclow::mux { PacketFactory *m_packet_factory; ctrl::HtcctrlStateMachine *m_state_machine; TaskManager m_task_manager; - os::EventType m_wake_event; + os::Event m_wake_event; ChannelImplMap m_channel_impl_map; GlobalSendBuffer m_global_send_buffer; os::SdkMutex m_mutex; diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.cpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.cpp new file mode 100644 index 000000000..3e5e23119 --- /dev/null +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "htclow_mux_channel_impl_map.hpp" + +namespace ams::htclow::mux { + + ChannelImplMap::ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev) + : m_packet_factory(pf), m_state_machine(sm), m_task_manager(tm), m_event(ev), m_map() + { + /* Initialize the map. */ + m_map.Initialize(MaxChannelCount, m_map_buffer, sizeof(m_map_buffer)); + + /* Set all storages as invalid. */ + for (auto i = 0; i < MaxChannelCount; ++i) { + m_storage_valid[i] = false; + } + } + +} diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp index e5acfdcc2..1dcdc36c4 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -44,13 +44,13 @@ namespace ams::htclow::mux { PacketFactory *m_packet_factory; ctrl::HtcctrlStateMachine *m_state_machine; TaskManager *m_task_manager; - os::EventType *m_event; + os::Event *m_event; u8 m_map_buffer[MapRequiredMemorySize]; MapType m_map; u8 m_storage[0x5200]; /* TODO */ bool m_storage_valid[MaxChannelCount]; public: - ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::EventType *ev); + ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev); }; } diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_global_send_buffer.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_global_send_buffer.hpp index c9273c4fd..ce32dca3c 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux_global_send_buffer.hpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_global_send_buffer.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_task_manager.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_task_manager.hpp index 6e9033c30..b0f7d30a8 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux_task_manager.hpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_task_manager.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Adubbz, Atmosphère-NX + * Copyright (c) 2018-2020 Atmosphère-NX * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,