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 void platPeriodic(void); 40 41 // free all platform-specific resources for TID, and return non-zero status if some cleanup was done 42 uint32_t platFreeResources(uint32_t tid); 43 44 /* Logging */ 45 void *platLogAllocUserData(); 46 void platLogFlush(void *userData); 47 bool platLogPutcharF(void *userData, char ch); 48 void platEarlyLogFlush(void); 49 50 /* fast timer */ 51 uint64_t platGetTicks(void); //in nanoseconds since an arbitrary starting point in the past 52 53 54 /* sleep/wake */ 55 #define PLAT_MAX_SLEEP_DEVS 32 56 57 void platSleep(void); 58 59 //in platSleepClockRequest() code to set next timer of some variety will live 60 //note that maxErrTotalPpm != maxDriftPpm + maxJitterPpm is quite possible since it is possible to have: 61 // timer A allowing 300ppm of jitter and 10pp of drift and timer B allowing 20ppm of jitter and 500ppm of drift 62 // in that case we'd see maxJitterPpm = 200, maxDriftPpm = 500, maxErrTotalPpm = 520 (MAX of all timers' allowable error totals) 63 //return true if timer was set. false if you failed (you will be called right back though. so false is usually reserved for cases 64 // like "it is too soon to set a timer") 65 //a special case is when nextTimer == 0. this indicates no next timer, so configure system for that 66 //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 67 bool platSleepClockRequest(uint64_t wakeupTime, uint32_t maxJitterPpm, uint32_t maxDriftPpm, uint32_t maxErrTotalPpm); //"nextTime == 0" => "no wakeup needed" 68 69 /* 0 for any "max" value means "do not care" */ 70 bool platRequestDevInSleepMode(uint32_t sleepDevID, uint32_t maxWakeupTime); //request that this device remain powered/clocked in sleep mode (device lists are platform specific) 71 bool platAdjustDevInSleepMode(uint32_t sleepDevID, uint32_t maxWakeupTime); //adjust maxWakeupTime for this device 72 bool platReleaseDevInSleepMode(uint32_t sleepDevID); //unrequest that this device remain powered/clocked in sleep mode (device lists are platform specific) 73 74 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif 80 81