1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_Timer.cpp
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 46347 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/os/os_Timer.h>
17 #include <nn/assert.h>
18 #include <nn/config.h>
19 #include <nn/os/os_Result.h>
20 #include <nn/os/os_Synchronization.h>
21 #include <nn/svc/svc_Stub.h>
22 
23 #include "os_Limits.h"
24 
25 //---------------------------------------------------------------------------
26 
27 using namespace nn;
28 using namespace nn::svc;
29 
30 // C Function Definitions
31 
32 #include <new>
33 
34 using namespace nn::os;
35 
36 namespace nn { namespace os {
37 
38 #if NN_PLATFORM_HAS_MMU
GetCurrentCount()39     s32  Timer::GetCurrentCount()
40     {
41         return os::detail::GetLimitCurrentCount(LIMITABLE_RESOURCE_MAX_TIMER);
42     }
43 
GetMaxCount()44     s32  Timer::GetMaxCount()
45     {
46         return os::detail::GetLimitMaxCount(LIMITABLE_RESOURCE_MAX_TIMER);
47     }
48 #endif  // if NN_PLATFORM_HAS_MMU
49 
50 }}
51 
52 extern "C" {
53 
54 NN_UTIL_DETAIL_CLIBIMPL_DECLARE_CONVERSION(nnosTimerToWaitObject, nnosTimer, nnosWaitObject);
55 NN_UTIL_DETAIL_CLIBIMPL_DECLARE_CONVERSION(nnosWaitObjectToTimer, nnosWaitObject, nnosTimer);
56 
nnosTimerInitialize(nnosTimer * p,bool isManualReset)57 void nnosTimerInitialize(nnosTimer* p, bool isManualReset)
58 {
59     new (p) Timer(isManualReset);
60 }
61 
nnosTimerTryInitialize(nnosTimer * p,bool isManualReset)62 bool nnosTimerTryInitialize(nnosTimer* p, bool isManualReset)
63 {
64     new (p) Timer();
65     Timer* pTimer = reinterpret_cast<Timer*>(p);
66     Result result = pTimer->TryInitialize(isManualReset);
67     return result.IsSuccess();
68 }
69 
nnosTimerStartPeriodic(nnosTimer * p,s64 first,s64 interval)70 void nnosTimerStartPeriodic(nnosTimer* p, s64 first, s64 interval)
71 {
72     Timer* pTimer = reinterpret_cast<Timer*>(p);
73     pTimer->StartPeriodic(nn::fnd::TimeSpan::FromNanoSeconds(first), nn::fnd::TimeSpan::FromNanoSeconds(interval));
74 }
75 
nnosTimerStartOneShot(nnosTimer * p,s64 time)76 void nnosTimerStartOneShot(nnosTimer* p, s64 time)
77 {
78     Timer* pTimer = reinterpret_cast<Timer*>(p);
79     pTimer->StartOneShot(nn::fnd::TimeSpan::FromNanoSeconds(time));
80 }
81 
nnosTimerWait(nnosTimer * p)82 void nnosTimerWait(nnosTimer* p)
83 {
84     Timer* pTimer = reinterpret_cast<Timer*>(p);
85     pTimer->Wait();
86 }
87 
nnosTimerStop(nnosTimer * p)88 void nnosTimerStop(nnosTimer* p)
89 {
90     Timer* pTimer = reinterpret_cast<Timer*>(p);
91     pTimer->Stop();
92 }
93 
nnosTimerClearSignal(nnosTimer * p)94 void nnosTimerClearSignal(nnosTimer* p)
95 {
96     Timer* pTimer = reinterpret_cast<Timer*>(p);
97     pTimer->ClearSignal();
98 }
99 
nnosTimerFinalize(nnosTimer * p)100 void nnosTimerFinalize(nnosTimer* p)
101 {
102     Timer* pTimer = reinterpret_cast<Timer*>(p);
103     pTimer->~Timer();
104 }
105 
nnosTimerSignal(nnosTimer * p)106 void nnosTimerSignal(nnosTimer* p)
107 {
108     Timer* pTimer = reinterpret_cast<Timer*>(p);
109     pTimer->Signal();
110 }
111 
112 }
113