1*84e33947SAndroid Build Coastguard Worker /* 2*84e33947SAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project 3*84e33947SAndroid Build Coastguard Worker * 4*84e33947SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*84e33947SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*84e33947SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*84e33947SAndroid Build Coastguard Worker * 8*84e33947SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*84e33947SAndroid Build Coastguard Worker * 10*84e33947SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*84e33947SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*84e33947SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*84e33947SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*84e33947SAndroid Build Coastguard Worker * limitations under the License. 15*84e33947SAndroid Build Coastguard Worker */ 16*84e33947SAndroid Build Coastguard Worker 17*84e33947SAndroid Build Coastguard Worker /* 18*84e33947SAndroid Build Coastguard Worker * Implementation Notes 19*84e33947SAndroid Build Coastguard Worker * Each platform must supply a platform-specific platform_notifier.h to provide 20*84e33947SAndroid Build Coastguard Worker * definitions and a platform-specific notifier.c to provide the implementation 21*84e33947SAndroid Build Coastguard Worker * for the definitions in this file. 22*84e33947SAndroid Build Coastguard Worker */ 23*84e33947SAndroid Build Coastguard Worker 24*84e33947SAndroid Build Coastguard Worker #ifndef CHPP_SYNC_H_ 25*84e33947SAndroid Build Coastguard Worker #define CHPP_SYNC_H_ 26*84e33947SAndroid Build Coastguard Worker 27*84e33947SAndroid Build Coastguard Worker #include <stdint.h> 28*84e33947SAndroid Build Coastguard Worker 29*84e33947SAndroid Build Coastguard Worker #ifdef __cplusplus 30*84e33947SAndroid Build Coastguard Worker extern "C" { 31*84e33947SAndroid Build Coastguard Worker #endif 32*84e33947SAndroid Build Coastguard Worker 33*84e33947SAndroid Build Coastguard Worker /* 34*84e33947SAndroid Build Coastguard Worker * Platform-specific condition variable struct defined in the platform's 35*84e33947SAndroid Build Coastguard Worker * platform_notifier.h that enables the funcions defined here. 36*84e33947SAndroid Build Coastguard Worker */ 37*84e33947SAndroid Build Coastguard Worker struct ChppNotifier; 38*84e33947SAndroid Build Coastguard Worker 39*84e33947SAndroid Build Coastguard Worker /** 40*84e33947SAndroid Build Coastguard Worker * Initializes the platform-specific ChppNotifier. 41*84e33947SAndroid Build Coastguard Worker * Will be called before notifier is used anywhere else. 42*84e33947SAndroid Build Coastguard Worker * 43*84e33947SAndroid Build Coastguard Worker * @param notifier Points to the ChppNotifier being initialized. 44*84e33947SAndroid Build Coastguard Worker */ 45*84e33947SAndroid Build Coastguard Worker static void chppNotifierInit(struct ChppNotifier *notifier); 46*84e33947SAndroid Build Coastguard Worker 47*84e33947SAndroid Build Coastguard Worker /** 48*84e33947SAndroid Build Coastguard Worker * Deinitializes the platform-specific ChppNotifier. 49*84e33947SAndroid Build Coastguard Worker * 50*84e33947SAndroid Build Coastguard Worker * @param notifier Points to the ChppNotifier being deinitialized. 51*84e33947SAndroid Build Coastguard Worker */ 52*84e33947SAndroid Build Coastguard Worker static void chppNotifierDeinit(struct ChppNotifier *notifier); 53*84e33947SAndroid Build Coastguard Worker 54*84e33947SAndroid Build Coastguard Worker /** 55*84e33947SAndroid Build Coastguard Worker * Returns the signal value in chppNotifierSignal(), if any. Resets the signal 56*84e33947SAndroid Build Coastguard Worker * value afterwards. 57*84e33947SAndroid Build Coastguard Worker * 58*84e33947SAndroid Build Coastguard Worker * @param notifier Points to the ChppNotifier being used. 59*84e33947SAndroid Build Coastguard Worker * 60*84e33947SAndroid Build Coastguard Worker * @return The signal value indicated in chppNotifierSignal(). 61*84e33947SAndroid Build Coastguard Worker */ 62*84e33947SAndroid Build Coastguard Worker static uint32_t chppNotifierGetSignal(struct ChppNotifier *notifier); 63*84e33947SAndroid Build Coastguard Worker 64*84e33947SAndroid Build Coastguard Worker /** 65*84e33947SAndroid Build Coastguard Worker * Waits on a platform-specific notifier until it is signaled through 66*84e33947SAndroid Build Coastguard Worker * chppNotifierSignal(). Similar to chppNotifierTimedWait(), but without the 67*84e33947SAndroid Build Coastguard Worker * timeout. 68*84e33947SAndroid Build Coastguard Worker * 69*84e33947SAndroid Build Coastguard Worker * @param notifier Points to the ChppNotifier being used. 70*84e33947SAndroid Build Coastguard Worker * 71*84e33947SAndroid Build Coastguard Worker * @return The signal value indicated in chppNotifierSignal(). 72*84e33947SAndroid Build Coastguard Worker */ 73*84e33947SAndroid Build Coastguard Worker static uint32_t chppNotifierWait(struct ChppNotifier *notifier); 74*84e33947SAndroid Build Coastguard Worker 75*84e33947SAndroid Build Coastguard Worker /** 76*84e33947SAndroid Build Coastguard Worker * Waits on a platform-specific notifier until it is signaled through 77*84e33947SAndroid Build Coastguard Worker * chppNotifierSignal() or until the specified timeout. 78*84e33947SAndroid Build Coastguard Worker * 79*84e33947SAndroid Build Coastguard Worker * Note that while the timeout is specified as a uint64_t, in practice, CHPP 80*84e33947SAndroid Build Coastguard Worker * would only use values up to CHPP_TRANSPORT_TX_TIMEOUT_NS. 81*84e33947SAndroid Build Coastguard Worker * 82*84e33947SAndroid Build Coastguard Worker * @param notifier Points to the ChppNotifier being used. 83*84e33947SAndroid Build Coastguard Worker * @param timeoutNs Timeout in nanoseconds. 84*84e33947SAndroid Build Coastguard Worker * 85*84e33947SAndroid Build Coastguard Worker * @return The signal value indicated in chppNotifierSignal(). 86*84e33947SAndroid Build Coastguard Worker */ 87*84e33947SAndroid Build Coastguard Worker static uint32_t chppNotifierTimedWait(struct ChppNotifier *notifier, 88*84e33947SAndroid Build Coastguard Worker uint64_t timeoutNs); 89*84e33947SAndroid Build Coastguard Worker 90*84e33947SAndroid Build Coastguard Worker /** 91*84e33947SAndroid Build Coastguard Worker * Signals chppNotifierTimedWait() with the specified signal value. 92*84e33947SAndroid Build Coastguard Worker * 93*84e33947SAndroid Build Coastguard Worker * The signal values can be defined by the user of this class. Note that it is 94*84e33947SAndroid Build Coastguard Worker * expected for different signals to be bitwise exclusive, i.e. each bit in the 95*84e33947SAndroid Build Coastguard Worker * uint32_t should indicate a specific type of signal event. This allows for 96*84e33947SAndroid Build Coastguard Worker * multiple events to be handled simultaneously in chppNotifierTimedWait(). 97*84e33947SAndroid Build Coastguard Worker * 98*84e33947SAndroid Build Coastguard Worker * @param notifier Points to the ChppNotifier being used. 99*84e33947SAndroid Build Coastguard Worker * @param signal The value where each bit represents a different event. 100*84e33947SAndroid Build Coastguard Worker * As such the value 0 will not notify any event. 101*84e33947SAndroid Build Coastguard Worker */ 102*84e33947SAndroid Build Coastguard Worker static void chppNotifierSignal(struct ChppNotifier *notifier, uint32_t signal); 103*84e33947SAndroid Build Coastguard Worker 104*84e33947SAndroid Build Coastguard Worker #ifdef __cplusplus 105*84e33947SAndroid Build Coastguard Worker } 106*84e33947SAndroid Build Coastguard Worker #endif 107*84e33947SAndroid Build Coastguard Worker 108*84e33947SAndroid Build Coastguard Worker #include "chpp/platform/platform_notifier.h" 109*84e33947SAndroid Build Coastguard Worker 110*84e33947SAndroid Build Coastguard Worker #endif // CHPP_SYNC_H_ 111