1 /* 2 * Copyright (C) 2013 SAMSUNG S.LSI 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 #ifndef OSI_COMMON_H 19 #define OSI_COMMON_H 20 21 /************************************************************************ 22 ** OS Interface common component 23 *************************************************************************/ 24 #include <pthread.h> 25 #ifdef ANDROID 26 #include <sys/times.h> 27 #endif 28 29 /************************************************************************ 30 ** Common definition and type 31 *************************************************************************/ 32 /* OSI common */ 33 // Maximum count of each obejct 34 #define OSI_MAX_TASK (3) // main task, read task 35 #define OSI_MAX_MEM_POOL (10) 36 #define OSI_MAX_QUEUE (2) // main queue, read queue 37 #define OSI_MAX_TIMER (2) // fw download timer, nci timer 38 39 // Size of each object 40 #define OSI_MEM_POOL_SIZE \ 41 (259) // for NFC (NCI_MAX_CTRL_SIZE + NCI_MSG_HDR_SIZE + NFC_HAL_EVT_SIZE) 42 #define OSI_QUEUE_SIZE (10) 43 44 // State 45 typedef uint8_t OSI_STATE; 46 #define OSI_FAIL 0 47 #define OSI_OK 1 48 #define OSI_FREE 2 49 #define OSI_ALLOCATED 3 50 #define OSI_RUN 4 51 #define OSI_STOP 5 52 53 #define OSI_TIMER_THREAD_FLAG_DETACH 0x01 54 55 /************************************************************************ 56 ** Common definition and type, union 57 *************************************************************************/ 58 /* OSI task */ 59 typedef void (*tOSI_TASK_ENTRY)(void); 60 typedef struct { 61 pthread_t task; 62 const char* name; 63 OSI_STATE state; 64 tOSI_TASK_ENTRY task_entry; 65 } sOSI_TASK; 66 typedef sOSI_TASK*(tOSI_TASK_HANDLER); 67 68 /* OSI memory */ 69 typedef struct { 70 uint8_t buffer[OSI_MEM_POOL_SIZE]; 71 OSI_STATE state; 72 } sOSI_MEM; 73 typedef sOSI_MEM*(tOSI_MEM_HANDLER); 74 75 /* OSI queue */ 76 typedef struct { 77 void* queue[OSI_QUEUE_SIZE]; 78 int head; 79 int tail; 80 const char* name; 81 OSI_STATE state; 82 pthread_cond_t cond; 83 } sOSI_QUEUE; 84 typedef sOSI_QUEUE*(tOSI_QUEUE_HANDLER); 85 86 /* OSI timer */ 87 typedef void (*tOSI_TIMER_CALLBACK)(void* param); 88 typedef struct { 89 int32_t exact_time; 90 int32_t init_timeout; 91 int32_t timeout; 92 const char* name; 93 tOSI_TIMER_CALLBACK callback; 94 void* callback_param; 95 OSI_STATE state; 96 } sOSI_TIMER; 97 typedef sOSI_TIMER*(tOSI_TIMER_HANDLER); 98 99 /* OSI Context */ 100 typedef struct { 101 /* main */ 102 pthread_mutex_t mutex; 103 104 /* task */ 105 sOSI_TASK task[OSI_MAX_TASK]; 106 107 /* memory */ 108 #ifndef OSI_USE_DYNAMIC_BUF 109 sOSI_MEM mem[OSI_MAX_MEM_POOL]; 110 #else 111 sOSI_MEM* mem[OSI_MAX_MEM_POOL]; 112 #endif 113 int32_t mem_max_cnt; /* Maximum number of allocated memory pool */ 114 115 /* queue */ 116 sOSI_QUEUE queue[OSI_MAX_QUEUE]; 117 int32_t queue_max_cnt; /* Maximum number of allocated queue */ 118 119 /* timer */ 120 sOSI_TIMER timer[OSI_MAX_TIMER]; 121 pthread_t timer_thread; 122 int32_t usingTimer; 123 unsigned char timer_thread_flag; 124 125 /* log */ 126 } tOSI_INFO; 127 128 /************************************************************************ 129 ** Global variable 130 *************************************************************************/ 131 extern tOSI_INFO osi_info; 132 133 /************************************************************************ 134 ** Internal functions 135 *************************************************************************/ 136 void osi_lock(); 137 void osi_unlock(); 138 void OSI_timer_update(int32_t tick); 139 int32_t OSI_timer_get_current_time(); 140 #endif 141