From 3b3c0fabdf9d797a55b45139ec30587a5a700ff7 Mon Sep 17 00:00:00 2001 From: Thog Date: Sun, 31 Jul 2016 22:42:20 +0200 Subject: [PATCH] Add PTMSYSM_CheckNew3DS, PTMSYSM_ShutdownAsync and PTMSYSM_RebootAsync --- libctru/include/3ds/services/ptmsysm.h | 17 ++++++++++++ libctru/source/services/ptmsysm.c | 37 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libctru/include/3ds/services/ptmsysm.h b/libctru/include/3ds/services/ptmsysm.h index 772b2d4..0978bb6 100644 --- a/libctru/include/3ds/services/ptmsysm.h +++ b/libctru/include/3ds/services/ptmsysm.h @@ -10,9 +10,26 @@ Result ptmSysmInit(void); /// Exits ptm:sysm. void ptmSysmExit(void); + +/** + * @brief return 1 if it's a New 3DS otherwise, return 0 for Old 3DS. + */ +Result PTMSYSM_CheckNew3DS(void); + /** * @brief Configures the New 3DS' CPU clock speed and L2 cache. * @param value Bit0: enable higher clock, Bit1: enable L2 cache. */ Result PTMSYSM_ConfigureNew3DSCPU(u8 value); +/** + * @brief Trigger a hardware system shutdown via the MCU + * @param timeout: timeout passed to PMApp:TerminateNonEssential. + */ +Result PTMSYSM_ShutdownAsync(u64 timeout); + +/** + * @brief Trigger a hardware system reboot via the MCU. + * @param timeout: timeout passed to PMApp:TerminateNonEssential. + */ +Result PTMSYSM_RebootAsync(u64 timeout); diff --git a/libctru/source/services/ptmsysm.c b/libctru/source/services/ptmsysm.c index ecd736f..6ee8da4 100644 --- a/libctru/source/services/ptmsysm.c +++ b/libctru/source/services/ptmsysm.c @@ -24,6 +24,17 @@ void ptmSysmExit(void) svcCloseHandle(ptmSysmHandle); } +Result PTMSYSM_CheckNew3DS(void) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x040A,0,0); // 0x040A0000 + + if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return 0; + + return (Result)cmdbuf[1]; +} + Result PTMSYSM_ConfigureNew3DSCPU(u8 value) { Result ret; @@ -37,3 +48,29 @@ Result PTMSYSM_ConfigureNew3DSCPU(u8 value) return (Result)cmdbuf[1]; } +Result PTMSYSM_ShutdownAsync(u64 timeout) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x407,3,0); // 0x040700C0 + cmdbuf[1] = 0; + cmdbuf[2] = timeout & 0xffffffff; + cmdbuf[3] = (timeout >> 32) & 0xffffffff; + + if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret; + + return (Result)cmdbuf[1]; +} + +Result PTMSYSM_RebootAsync(u64 timeout) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x409,2,0); // 0x04090080 + cmdbuf[1] = timeout & 0xffffffff; + cmdbuf[2] = (timeout >> 32) & 0xffffffff; + + if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret; + + return (Result)cmdbuf[1]; +}