1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _PLATFORM_H_
18 #define _PLATFORM_H_
19 
20 //
21 //  platform.h
22 //  seos
23 //
24 //  Created by Simon Wilson on 10/2/14.
25 //
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <stdbool.h>
32 #include <stdint.h>
33 #include <seos.h>
34 
35 /* plat life cycle */
36 void platInitialize(void);
37 void platUninitialize(void);
38 void platReset(void);
39 
40 // free all platform-specific resources for TID, and return non-zero status if some cleanup was done
41 uint32_t platFreeResources(uint32_t tid);
42 
43 /* Logging */
44 void *platLogAllocUserData();
45 void platLogFlush(void *userData);
46 bool platLogPutcharF(void *userData, char ch);
47 void platEarlyLogFlush(void);
48 
49 /* fast timer */
50 uint64_t platGetTicks(void); //in nanoseconds since an arbitrary starting point in the past
51 
52 
53 /* sleep/wake */
54 #define PLAT_MAX_SLEEP_DEVS    32
55 
56 void platSleep(void);
57 
58 //in platSleepClockRequest() code to set next timer of some variety will live
59 //note that maxErrTotalPpm != maxDriftPpm + maxJitterPpm is quite possible since it is possible to have:
60 // timer A allowing 300ppm of jitter and 10pp of drift and timer B allowing 20ppm of jitter and 500ppm of drift
61 // in that case we'd see maxJitterPpm = 200, maxDriftPpm = 500, maxErrTotalPpm = 520  (MAX of all timers' allowable error totals)
62 //return true if timer was set. false if you failed (you will be called right back though. so false is usually reserved for cases
63 // like "it is too soon to set a timer")
64 //a special case is when nextTimer == 0. this indicates no next timer, so configure system for that
65 //do not call this func if timer is already due - it will be delayed (potentially by a whole sleep-wke cycle), though this is unlikely
66 bool platSleepClockRequest(uint64_t wakeupTime, uint32_t maxJitterPpm, uint32_t maxDriftPpm, uint32_t maxErrTotalPpm); //"nextTime == 0" => "no wakeup needed"
67 
68 /* 0 for any "max" value means "do not care" */
69 bool platRequestDevInSleepMode(uint32_t sleepDevID, uint32_t maxWakeupTime); //request that this device remain powered/clocked in sleep mode   (device lists are platform specific)
70 bool platReleaseDevInSleepMode(uint32_t sleepDevID); //unrequest that this device remain powered/clocked in sleep mode (device lists are platform specific)
71 
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif
78 
79