1 /*
2 * Copyright 2012-2020 NXP
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 /*
18 * OSAL header files related to memory, debug, random, semaphore and mutex
19 * functions.
20 */
21
22 #ifndef PHUWBCOMMON_H
23 #define PHUWBCOMMON_H
24
25 /*
26 ************************* Include Files ****************************************
27 */
28 #include <pthread.h>
29 #include <semaphore.h>
30
31 #include <cctype>
32
33 #include <phOsalUwb_Timer.h>
34 #include <phUwbCompId.h>
35 #include <phUwbStatus.h>
36 /*
37 * Deferred call declaration.
38 * This type of API is called from ClientApplication (main thread) to notify
39 * specific callback.
40 */
41 typedef void (*pphOsalUwb_DeferFuncPointer_t)(void*);
42
43 /*
44 * Deferred message specific info declaration.
45 */
46 typedef struct phOsalUwb_DeferredCallInfo {
47 pphOsalUwb_DeferFuncPointer_t pDeferredCall; /* pointer to Deferred callback */
48 void* pParam; /* contains timer message specific details*/
49 } phOsalUwb_DeferredCallInfo_t;
50
51 /*
52 * States in which a OSAL timer exist.
53 */
54 typedef enum {
55 eTimerIdle = 0, /* Indicates Initial state of timer */
56 eTimerRunning = 1, /* Indicate timer state when started */
57 eTimerStopped = 2 /* Indicates timer state when stopped */
58 } phOsalUwb_TimerStates_t; /* Variable representing State of timer */
59
60 /*
61 **Timer Handle structure containing details of a timer.
62 */
63 typedef struct phOsalUwb_TimerHandle {
64 uint32_t TimerId; /* ID of the timer */
65 timer_t hTimerHandle; /* Handle of the timer */
66 /* Timer callback function to be invoked */
67 pphOsalUwb_TimerCallbck_t Application_callback;
68 void* pContext; /* Parameter to be passed to the callback function */
69 phOsalUwb_TimerStates_t eState; /* Timer states */
70 /* Deferred Call structure to Invoke Callback function */
71 phOsalUwb_DeferredCallInfo_t tDeferredCallInfo;
72 /* Variables for Structure Instance and Structure Ptr */
73 } phOsalUwb_TimerHandle_t, *pphOsalUwb_TimerHandle_t;
74
is_valid_country_code(const char country_code[2])75 static inline bool is_valid_country_code(const char country_code[2])
76 {
77 return std::isalnum(country_code[0]) && std::isalnum(country_code[1]) &&
78 !(country_code[0] == '0' && country_code[1] == '0');
79 }
80
81 #endif /* PHOSALUWB_H */
82