nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 1999-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 18 | #include <errno.h> |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 19 | #include <malloc.h> |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 20 | #include <pthread.h> /* must be 1st header defined */ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 21 | |
| 22 | #include <android-base/stringprintf.h> |
| 23 | #include <base/logging.h> |
| 24 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 25 | #include "gki_int.h" |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 26 | |
| 27 | using android::base::StringPrintf; |
| 28 | |
| 29 | extern bool nfc_debug_enabled; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 30 | |
| 31 | /* Temp android logging...move to android tgt config file */ |
| 32 | |
| 33 | #ifndef LINUX_NATIVE |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 34 | #else |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 35 | #define LOGV(format, ...) fprintf(stdout, LOG_TAG format, ##__VA_ARGS__) |
| 36 | #define LOGE(format, ...) fprintf(stderr, LOG_TAG format, ##__VA_ARGS__) |
| 37 | #define LOGI(format, ...) fprintf(stdout, LOG_TAG format, ##__VA_ARGS__) |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 38 | |
| 39 | #define SCHED_NORMAL 0 |
| 40 | #define SCHED_FIFO 1 |
| 41 | #define SCHED_RR 2 |
| 42 | #define SCHED_BATCH 3 |
| 43 | |
| 44 | #endif |
| 45 | |
| 46 | /* Define the structure that holds the GKI variables |
| 47 | */ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 48 | tGKI_CB gki_cb; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 49 | |
| 50 | #define NANOSEC_PER_MILLISEC (1000000) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 51 | #define NSEC_PER_SEC (1000 * NANOSEC_PER_MILLISEC) |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 52 | |
| 53 | /* works only for 1ms to 1000ms heart beat ranges */ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 54 | #define LINUX_SEC (1000 / TICKS_PER_SEC) |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 55 | // #define GKI_TICK_TIMER_DEBUG |
| 56 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 57 | /* this kind of mutex go into tGKI_OS control block!!!! */ |
| 58 | /* static pthread_mutex_t GKI_sched_mutex; */ |
| 59 | /*static pthread_mutex_t thread_delay_mutex; |
| 60 | static pthread_cond_t thread_delay_cond; |
| 61 | static pthread_mutex_t gki_timer_update_mutex; |
| 62 | static pthread_cond_t gki_timer_update_cond; |
| 63 | */ |
| 64 | #ifdef NO_GKI_RUN_RETURN |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 65 | static pthread_t timer_thread_id = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 66 | #endif |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 67 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 68 | typedef struct { |
| 69 | uint8_t task_id; /* GKI task id */ |
| 70 | TASKPTR task_entry; /* Task entry function*/ |
| 71 | uintptr_t params; /* Extra params to pass to task entry function */ |
| 72 | pthread_cond_t* pCond; /* for android*/ |
| 73 | pthread_mutex_t* pMutex; /* for android*/ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 74 | } gki_pthread_info_t; |
| 75 | gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS]; |
| 76 | |
| 77 | /******************************************************************************* |
| 78 | ** |
| 79 | ** Function gki_task_entry |
| 80 | ** |
| 81 | ** Description entry point of GKI created tasks |
| 82 | ** |
| 83 | ** Returns void |
| 84 | ** |
| 85 | *******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 86 | void* gki_task_entry(void* params) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 87 | pthread_t thread_id = pthread_self(); |
| 88 | gki_pthread_info_t* p_pthread_info = (gki_pthread_info_t*)params; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 89 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 90 | "gki_task_entry task_id=%i, thread_id=%lx/%lx, pCond/pMutex=%p/%p", |
| 91 | p_pthread_info->task_id, gki_cb.os.thread_id[p_pthread_info->task_id], |
| 92 | pthread_self(), p_pthread_info->pCond, p_pthread_info->pMutex); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 93 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 94 | gki_cb.os.thread_id[p_pthread_info->task_id] = thread_id; |
| 95 | /* Call the actual thread entry point */ |
| 96 | (p_pthread_info->task_entry)(p_pthread_info->params); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 97 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 98 | LOG(ERROR) << StringPrintf("gki_task task_id=%i terminating", |
| 99 | p_pthread_info->task_id); |
nxf24591 | e1fb2f9 | 2018-06-06 14:41:56 +0530 | [diff] [blame] | 100 | #if (NXP_EXTNS == TRUE) |
| 101 | memset(&(gki_cb.os.thread_id[p_pthread_info->task_id]), 0, sizeof(pthread_t)); |
| 102 | #else |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 103 | gki_cb.os.thread_id[p_pthread_info->task_id] = 0; |
nxf24591 | e1fb2f9 | 2018-06-06 14:41:56 +0530 | [diff] [blame] | 104 | #endif |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 105 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 106 | return NULL; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 107 | } |
| 108 | /* end android */ |
| 109 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 110 | /******************************************************************************* |
| 111 | ** |
| 112 | ** Function GKI_init |
| 113 | ** |
| 114 | ** Description This function is called once at startup to initialize |
| 115 | ** all the timer structures. |
| 116 | ** |
| 117 | ** Returns void |
| 118 | ** |
| 119 | *******************************************************************************/ |
| 120 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 121 | void GKI_init(void) { |
| 122 | pthread_mutexattr_t attr; |
| 123 | tGKI_OS* p_os; |
nxpandroid | 6154b73 | 2016-01-14 20:39:23 +0530 | [diff] [blame] | 124 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 125 | memset(&gki_cb, 0, sizeof(gki_cb)); |
| 126 | |
| 127 | gki_buffer_init(); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 128 | gki_timers_init(); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 129 | gki_cb.com.OSTicks = (uint32_t)times(0); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 130 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 131 | pthread_mutexattr_init(&attr); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 132 | |
| 133 | #ifndef __CYGWIN__ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 134 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 135 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 136 | p_os = &gki_cb.os; |
| 137 | pthread_mutex_init(&p_os->GKI_mutex, &attr); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 138 | /* pthread_mutex_init(&GKI_sched_mutex, NULL); */ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 139 | /* pthread_mutex_init(&thread_delay_mutex, NULL); */ /* used in GKI_delay */ |
| 140 | /* pthread_cond_init (&thread_delay_cond, NULL); */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 141 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 142 | /* Initialiase GKI_timer_update suspend variables & mutexes to be in running |
| 143 | * state. |
| 144 | * this works too even if GKI_NO_TICK_STOP is defined in btld.txt */ |
| 145 | p_os->no_timer_suspend = GKI_TIMER_TICK_RUN_COND; |
| 146 | pthread_mutex_init(&p_os->gki_timer_mutex, NULL); |
| 147 | pthread_cond_init(&p_os->gki_timer_cond, NULL); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 148 | } |
| 149 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 150 | /******************************************************************************* |
| 151 | ** |
| 152 | ** Function GKI_get_os_tick_count |
| 153 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 154 | ** Description This function is called to retrieve the native OS system |
| 155 | ** tick. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 156 | ** |
| 157 | ** Returns Tick count of native OS. |
| 158 | ** |
| 159 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 160 | uint32_t GKI_get_os_tick_count(void) { |
| 161 | /* TODO - add any OS specific code here |
| 162 | **/ |
| 163 | return (gki_cb.com.OSTicks); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /******************************************************************************* |
| 167 | ** |
| 168 | ** Function GKI_create_task |
| 169 | ** |
| 170 | ** Description This function is called to create a new OSS task. |
| 171 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 172 | ** Parameters: task_entry - (input) pointer to the entry function of the |
| 173 | ** task |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 174 | ** task_id - (input) Task id is mapped to priority |
| 175 | ** taskname - (input) name given to the task |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 176 | ** stack - (input) pointer to the top of the stack |
| 177 | ** (highest memory location) |
| 178 | ** stacksize - (input) size of the stack allocated for the |
| 179 | ** task |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 180 | ** |
| 181 | ** Returns GKI_SUCCESS if all OK, GKI_FAILURE if any problem |
| 182 | ** |
| 183 | ** NOTE This function take some parameters that may not be needed |
| 184 | ** by your particular OS. They are here for compatability |
| 185 | ** of the function prototype. |
| 186 | ** |
| 187 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 188 | uint8_t GKI_create_task(TASKPTR task_entry, uint8_t task_id, int8_t* taskname, |
| 189 | uint16_t* stack, uint16_t stacksize, void* pCondVar, |
| 190 | void* pMutex) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 191 | struct sched_param param; |
| 192 | int policy, ret = 0; |
| 193 | pthread_condattr_t attr; |
| 194 | pthread_attr_t attr1; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 195 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 196 | pthread_condattr_init(&attr); |
| 197 | pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 198 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 199 | "GKI_create_task func=0x%p id=%d name=%s stack=0x%p stackSize=%d", |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 200 | task_entry, task_id, taskname, stack, stacksize); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 201 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 202 | if (task_id >= GKI_MAX_TASKS) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 203 | DLOG_IF(INFO, nfc_debug_enabled) |
| 204 | << StringPrintf("Error! task ID > max task allowed"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 205 | return (GKI_FAILURE); |
| 206 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 207 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 208 | gki_cb.com.OSRdyTbl[task_id] = TASK_READY; |
| 209 | gki_cb.com.OSTName[task_id] = taskname; |
| 210 | gki_cb.com.OSWaitTmr[task_id] = 0; |
| 211 | gki_cb.com.OSWaitEvt[task_id] = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 212 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 213 | /* Initialize mutex and condition variable objects for events and timeouts */ |
| 214 | pthread_mutex_init(&gki_cb.os.thread_evt_mutex[task_id], NULL); |
| 215 | pthread_cond_init(&gki_cb.os.thread_evt_cond[task_id], &attr); |
| 216 | pthread_mutex_init(&gki_cb.os.thread_timeout_mutex[task_id], NULL); |
| 217 | pthread_cond_init(&gki_cb.os.thread_timeout_cond[task_id], &attr); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 218 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 219 | pthread_attr_init(&attr1); |
| 220 | /* by default, pthread creates a joinable thread */ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 221 | #if (FALSE == GKI_PTHREAD_JOINABLE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 222 | pthread_attr_setdetachstate(&attr1, PTHREAD_CREATE_DETACHED); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 223 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 224 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 225 | "GKI creating task %i, pCond/pMutex=%p/%p", task_id, pCondVar, pMutex); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 226 | #else |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 227 | DLOG_IF(INFO, nfc_debug_enabled) |
| 228 | << StringPrintf("GKI creating JOINABLE task %i", task_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 229 | #endif |
| 230 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 231 | /* On Android, the new tasks starts running before |
| 232 | * 'gki_cb.os.thread_id[task_id]' is initialized */ |
| 233 | /* Pass task_id to new task so it can initialize gki_cb.os.thread_id[task_id] |
| 234 | * for it calls GKI_wait */ |
| 235 | gki_pthread_info[task_id].task_id = task_id; |
| 236 | gki_pthread_info[task_id].task_entry = task_entry; |
| 237 | gki_pthread_info[task_id].params = 0; |
| 238 | gki_pthread_info[task_id].pCond = (pthread_cond_t*)pCondVar; |
| 239 | gki_pthread_info[task_id].pMutex = (pthread_mutex_t*)pMutex; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 240 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 241 | ret = pthread_create(&gki_cb.os.thread_id[task_id], &attr1, gki_task_entry, |
| 242 | &gki_pthread_info[task_id]); |
| 243 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 244 | if (ret != 0) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 245 | DLOG_IF(INFO, nfc_debug_enabled) |
| 246 | << StringPrintf("pthread_create failed(%d), %s!", ret, taskname); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 247 | return GKI_FAILURE; |
| 248 | } |
| 249 | |
| 250 | if (pthread_getschedparam(gki_cb.os.thread_id[task_id], &policy, ¶m) == |
| 251 | 0) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 252 | #if (PBS_SQL_TASK == TRUE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 253 | if (task_id == PBS_SQL_TASK) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 254 | DLOG_IF(INFO, nfc_debug_enabled) |
| 255 | << StringPrintf("PBS SQL lowest priority task"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 256 | policy = SCHED_NORMAL; |
| 257 | } else |
| 258 | #endif |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 259 | { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 260 | policy = SCHED_RR; |
| 261 | param.sched_priority = 30 - task_id - 2; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 262 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 263 | pthread_setschedparam(gki_cb.os.thread_id[task_id], policy, ¶m); |
| 264 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 265 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 266 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 267 | "Leaving GKI_create_task %p %d %lx %s %p %d", task_entry, task_id, |
| 268 | gki_cb.os.thread_id[task_id], taskname, stack, stacksize); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 269 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 270 | return (GKI_SUCCESS); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /******************************************************************************* |
| 274 | ** |
| 275 | ** Function GKI_shutdown |
| 276 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 277 | ** Description shutdowns the GKI tasks/threads in from max task id to 0 and |
| 278 | ** frees pthread resources! |
| 279 | ** IMPORTANT: in case of join method, GKI_shutdown must be |
| 280 | ** called outside a GKI thread context! |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 281 | ** |
| 282 | ** Returns void |
| 283 | ** |
| 284 | *******************************************************************************/ |
| 285 | #define WAKE_LOCK_ID "brcm_nfca" |
| 286 | #define PARTIAL_WAKE_LOCK 1 |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 287 | extern "C" int acquire_wake_lock(int lock, const char* id); |
| 288 | extern "C" int release_wake_lock(const char* id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 289 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 290 | void GKI_shutdown(void) { |
| 291 | uint8_t task_id; |
| 292 | volatile int* p_run_cond = &gki_cb.os.no_timer_suspend; |
| 293 | int oldCOnd = 0; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 294 | #if (FALSE == GKI_PTHREAD_JOINABLE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 295 | int i = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 296 | #else |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 297 | int result; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 298 | #endif |
| 299 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 300 | /* release threads and set as TASK_DEAD. going from low to high priority fixes |
| 301 | * GKI_exception problem due to btu->hci sleep request events */ |
| 302 | for (task_id = GKI_MAX_TASKS; task_id > 0; task_id--) { |
| 303 | if (gki_cb.com.OSRdyTbl[task_id - 1] != TASK_DEAD) { |
| 304 | gki_cb.com.OSRdyTbl[task_id - 1] = TASK_DEAD; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 305 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 306 | /* paranoi settings, make sure that we do not execute any mailbox events |
| 307 | */ |
| 308 | gki_cb.com.OSWaitEvt[task_id - 1] &= |
| 309 | ~(TASK_MBOX_0_EVT_MASK | TASK_MBOX_1_EVT_MASK | TASK_MBOX_2_EVT_MASK | |
| 310 | TASK_MBOX_3_EVT_MASK); |
| 311 | GKI_send_event(task_id - 1, EVENT_MASK(GKI_SHUTDOWN_EVT)); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 312 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 313 | #if (FALSE == GKI_PTHREAD_JOINABLE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 314 | i = 0; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 315 | |
| 316 | while ((gki_cb.com.OSWaitEvt[task_id - 1] != 0) && (++i < 10)) |
| 317 | usleep(100 * 1000); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 318 | #else |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 319 | /* wait for proper Arnold Schwarzenegger task state */ |
| 320 | result = pthread_join(gki_cb.os.thread_id[task_id - 1], NULL); |
| 321 | if (result < 0) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 322 | DLOG_IF(INFO, nfc_debug_enabled) |
| 323 | << StringPrintf("FAILED: result: %d", result); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 324 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 325 | #endif |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 326 | DLOG_IF(INFO, nfc_debug_enabled) |
| 327 | << StringPrintf("task %s dead", gki_cb.com.OSTName[task_id]); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 328 | GKI_exit_task(task_id - 1); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 329 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 330 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 331 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 332 | /* Destroy mutex and condition variable objects */ |
| 333 | pthread_mutex_destroy(&gki_cb.os.GKI_mutex); |
| 334 | /* pthread_mutex_destroy(&GKI_sched_mutex); */ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 335 | /* pthread_mutex_destroy(&thread_delay_mutex); |
| 336 | pthread_cond_destroy (&thread_delay_cond); */ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 337 | #if (FALSE == GKI_PTHREAD_JOINABLE) |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 338 | i = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 339 | #endif |
| 340 | |
| 341 | #ifdef NO_GKI_RUN_RETURN |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 342 | shutdown_timer = 1; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 343 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 344 | if (gki_cb.os.gki_timer_wake_lock_on) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 345 | DLOG_IF(INFO, nfc_debug_enabled) |
| 346 | << StringPrintf("GKI_shutdown : release_wake_lock(brcm_btld)"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 347 | release_wake_lock(WAKE_LOCK_ID); |
| 348 | gki_cb.os.gki_timer_wake_lock_on = 0; |
| 349 | } |
| 350 | oldCOnd = *p_run_cond; |
| 351 | *p_run_cond = GKI_TIMER_TICK_EXIT_COND; |
| 352 | if (oldCOnd == GKI_TIMER_TICK_STOP_COND) |
| 353 | pthread_cond_signal(&gki_cb.os.gki_timer_cond); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /******************************************************************************* |
| 357 | ** |
| 358 | ** Function GKI_run |
| 359 | ** |
| 360 | ** Description This function runs a task |
| 361 | ** |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 362 | ** Parameters: start: TRUE start system tick (again), FALSE stop |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 363 | ** |
| 364 | ** Returns void |
| 365 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 366 | ******************************************************************************/ |
| 367 | void gki_system_tick_start_stop_cback(bool start) { |
| 368 | tGKI_OS* p_os = &gki_cb.os; |
| 369 | volatile int* p_run_cond = &p_os->no_timer_suspend; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 370 | #ifdef GKI_TICK_TIMER_DEBUG |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 371 | static volatile int wake_lock_count; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 372 | #endif |
| 373 | if (start == false) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 374 | /* this can lead to a race condition. however as we only read this variable |
| 375 | * in the timer loop |
| 376 | * we should be fine with this approach. otherwise uncomment below mutexes. |
| 377 | */ |
| 378 | /* GKI_disable(); */ |
| 379 | *p_run_cond = GKI_TIMER_TICK_STOP_COND; |
| 380 | /* GKI_enable(); */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 381 | #ifdef GKI_TICK_TIMER_DEBUG |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 382 | DLOG_IF(INFO, nfc_debug_enabled) |
| 383 | << StringPrintf(">>> STOP wake_lock_count:%d", --wake_lock_count); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 384 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 385 | release_wake_lock(WAKE_LOCK_ID); |
| 386 | gki_cb.os.gki_timer_wake_lock_on = 0; |
| 387 | } else { |
| 388 | /* restart GKI_timer_update() loop */ |
| 389 | acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); |
| 390 | gki_cb.os.gki_timer_wake_lock_on = 1; |
| 391 | *p_run_cond = GKI_TIMER_TICK_RUN_COND; |
| 392 | pthread_mutex_lock(&p_os->gki_timer_mutex); |
| 393 | pthread_cond_signal(&p_os->gki_timer_cond); |
| 394 | pthread_mutex_unlock(&p_os->gki_timer_mutex); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 395 | |
| 396 | #ifdef GKI_TICK_TIMER_DEBUG |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 397 | DLOG_IF(INFO, nfc_debug_enabled) |
| 398 | << StringPrintf(">>> START wake_lock_count:%d", ++wake_lock_count); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 399 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 400 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 401 | } |
| 402 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 403 | /******************************************************************************* |
| 404 | ** |
| 405 | ** Function timer_thread |
| 406 | ** |
| 407 | ** Description Timer thread |
| 408 | ** |
| 409 | ** Parameters: id - (input) timer ID |
| 410 | ** |
| 411 | ** Returns void |
| 412 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 413 | *******************************************************************************/ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 414 | #ifdef NO_GKI_RUN_RETURN |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 415 | void timer_thread(signed long id) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 416 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s enter", __func__); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 417 | struct timespec delay; |
| 418 | int timeout = 1000; /* 10 ms per system tick */ |
| 419 | int err; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 420 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 421 | while (!shutdown_timer) { |
| 422 | delay.tv_sec = timeout / 1000; |
| 423 | delay.tv_nsec = 1000 * 1000 * (timeout % 1000); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 424 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 425 | /* [u]sleep can't be used because it uses SIGALRM */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 426 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 427 | do { |
| 428 | err = nanosleep(&delay, &delay); |
| 429 | } while (err < 0 && errno == EINTR); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 430 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 431 | GKI_timer_update(1); |
| 432 | } |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 433 | LOG(ERROR) << StringPrintf("%s exit", __func__); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 434 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 435 | } |
| 436 | #endif |
| 437 | |
| 438 | /******************************************************************************* |
| 439 | ** |
| 440 | ** Function GKI_run |
| 441 | ** |
| 442 | ** Description This function runs a task |
| 443 | ** |
| 444 | ** Parameters: p_task_id - (input) pointer to task id |
| 445 | ** |
| 446 | ** Returns void |
| 447 | ** |
| 448 | ** NOTE This function is only needed for operating systems where |
| 449 | ** starting a task is a 2-step process. Most OS's do it in |
| 450 | ** one step, If your OS does it in one step, this function |
| 451 | ** should be empty. |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 452 | *******************************************************************************/ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 453 | void GKI_run(__attribute__((unused)) void* p_task_id) { |
| 454 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s enter", __func__); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 455 | struct timespec delay; |
| 456 | int err = 0; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 457 | volatile int* p_run_cond = &gki_cb.os.no_timer_suspend; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 458 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 459 | #ifndef GKI_NO_TICK_STOP |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 460 | /* register start stop function which disable timer loop in GKI_run() when no |
| 461 | * timers are |
| 462 | * in any GKI/BTA/BTU this should save power when BTLD is idle! */ |
| 463 | GKI_timer_queue_register_callback(gki_system_tick_start_stop_cback); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 464 | DLOG_IF(INFO, nfc_debug_enabled) |
| 465 | << StringPrintf("Start/Stop GKI_timer_update_registered!"); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 466 | #endif |
| 467 | |
| 468 | #ifdef NO_GKI_RUN_RETURN |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 469 | DLOG_IF(INFO, nfc_debug_enabled) |
| 470 | << StringPrintf("GKI_run == NO_GKI_RUN_RETURN"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 471 | pthread_attr_t timer_attr; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 472 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 473 | shutdown_timer = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 474 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 475 | pthread_attr_init(&timer_attr); |
| 476 | pthread_attr_setdetachstate(&timer_attr, PTHREAD_CREATE_DETACHED); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 477 | if (pthread_create(&timer_thread_id, &timer_attr, timer_thread, NULL) != 0) { |
| 478 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 479 | "GKI_run: pthread_create failed to create timer_thread!"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 480 | return GKI_FAILURE; |
| 481 | } |
| 482 | #else |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 483 | DLOG_IF(INFO, nfc_debug_enabled) |
| 484 | << StringPrintf("GKI_run, run_cond(%p)=%d ", p_run_cond, *p_run_cond); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 485 | for (; GKI_TIMER_TICK_EXIT_COND != *p_run_cond;) { |
| 486 | do { |
| 487 | /* adjust hear bit tick in btld by changning TICKS_PER_SEC!!!!! this |
| 488 | * formula works only for |
| 489 | * 1-1000ms heart beat units! */ |
| 490 | delay.tv_sec = LINUX_SEC / 1000; |
| 491 | delay.tv_nsec = 1000 * 1000 * (LINUX_SEC % 1000); |
| 492 | |
| 493 | /* [u]sleep can't be used because it uses SIGALRM */ |
| 494 | do { |
| 495 | err = nanosleep(&delay, &delay); |
| 496 | } while (err < 0 && errno == EINTR); |
| 497 | |
| 498 | if (GKI_TIMER_TICK_RUN_COND != *p_run_cond) break; // GKI has shutdown |
| 499 | |
| 500 | /* the unit should be alsways 1 (1 tick). only if you vary for some reason |
| 501 | * heart beat tick |
| 502 | * e.g. power saving you may want to provide more ticks |
| 503 | */ |
| 504 | GKI_timer_update(1); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 505 | } while (GKI_TIMER_TICK_RUN_COND == *p_run_cond); |
| 506 | |
| 507 | /* currently on reason to exit above loop is no_timer_suspend == |
| 508 | * GKI_TIMER_TICK_STOP_COND |
| 509 | * block timer main thread till re-armed by */ |
| 510 | #ifdef GKI_TICK_TIMER_DEBUG |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 511 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(">>> SUSPENDED"); |
nxpandroid | 6154b73 | 2016-01-14 20:39:23 +0530 | [diff] [blame] | 512 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 513 | if (GKI_TIMER_TICK_EXIT_COND != *p_run_cond) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 514 | pthread_mutex_lock(&gki_cb.os.gki_timer_mutex); |
| 515 | pthread_cond_wait(&gki_cb.os.gki_timer_cond, &gki_cb.os.gki_timer_mutex); |
| 516 | pthread_mutex_unlock(&gki_cb.os.gki_timer_mutex); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 517 | } |
| 518 | /* potentially we need to adjust os gki_cb.com.OSTicks */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 519 | |
| 520 | #ifdef GKI_TICK_TIMER_DEBUG |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 521 | DLOG_IF(INFO, nfc_debug_enabled) |
| 522 | << StringPrintf(">>> RESTARTED run_cond: %d", *p_run_cond); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 523 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 524 | } /* for */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 525 | #endif |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 526 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s exit", __func__); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 527 | } |
| 528 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 529 | /******************************************************************************* |
| 530 | ** |
| 531 | ** Function GKI_stop |
| 532 | ** |
| 533 | ** Description This function is called to stop |
| 534 | ** the tasks and timers when the system is being stopped |
| 535 | ** |
| 536 | ** Returns void |
| 537 | ** |
| 538 | ** NOTE This function is NOT called by the Widcomm stack and |
| 539 | ** profiles. If you want to use it in your own implementation, |
| 540 | ** put specific code here. |
| 541 | ** |
| 542 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 543 | void GKI_stop(void) { |
| 544 | uint8_t task_id; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 545 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 546 | /* gki_queue_timer_cback(FALSE); */ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 547 | /* TODO - add code here if needed*/ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 548 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 549 | for (task_id = 0; task_id < GKI_MAX_TASKS; task_id++) { |
| 550 | if (gki_cb.com.OSRdyTbl[task_id] != TASK_DEAD) { |
| 551 | GKI_exit_task(task_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 552 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 553 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 554 | } |
| 555 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 556 | /******************************************************************************* |
| 557 | ** |
| 558 | ** Function GKI_wait |
| 559 | ** |
| 560 | ** Description This function is called by tasks to wait for a specific |
| 561 | ** event or set of events. The task may specify the duration |
| 562 | ** that it wants to wait for, or 0 if infinite. |
| 563 | ** |
| 564 | ** Parameters: flag - (input) the event or set of events to wait for |
| 565 | ** timeout - (input) the duration that the task wants to wait |
| 566 | ** for the specific events (in system ticks) |
| 567 | ** |
| 568 | ** |
| 569 | ** Returns the event mask of received events or zero if timeout |
| 570 | ** |
| 571 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 572 | uint16_t GKI_wait(uint16_t flag, uint32_t timeout) { |
| 573 | uint16_t evt; |
| 574 | uint8_t rtask; |
| 575 | struct timespec abstime = {0, 0}; |
| 576 | int sec; |
| 577 | int nano_sec; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 578 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 579 | rtask = GKI_get_taskid(); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 580 | if (rtask >= GKI_MAX_TASKS) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 581 | LOG(ERROR) << StringPrintf("%s() Exiting thread; rtask %d >= %d", __func__, |
| 582 | rtask, GKI_MAX_TASKS); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 583 | return EVENT_MASK(GKI_SHUTDOWN_EVT); |
| 584 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 585 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 586 | gki_pthread_info_t* p_pthread_info = &gki_pthread_info[rtask]; |
| 587 | if (p_pthread_info->pCond != NULL && p_pthread_info->pMutex != NULL) { |
| 588 | int ret; |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 589 | DLOG_IF(INFO, nfc_debug_enabled) |
| 590 | << StringPrintf("GKI_wait task=%i, pCond/pMutex = %p/%p", rtask, |
| 591 | p_pthread_info->pCond, p_pthread_info->pMutex); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 592 | ret = pthread_mutex_lock(p_pthread_info->pMutex); |
| 593 | ret = pthread_cond_signal(p_pthread_info->pCond); |
| 594 | ret = pthread_mutex_unlock(p_pthread_info->pMutex); |
| 595 | p_pthread_info->pMutex = NULL; |
| 596 | p_pthread_info->pCond = NULL; |
| 597 | } |
| 598 | gki_cb.com.OSWaitForEvt[rtask] = flag; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 599 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 600 | /* protect OSWaitEvt[rtask] from modification from an other thread */ |
| 601 | pthread_mutex_lock(&gki_cb.os.thread_evt_mutex[rtask]); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 602 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 603 | #if 0 /* for clean scheduling we probably should always call \ |
| 604 | pthread_cond_wait() */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 605 | /* Check if anything in any of the mailboxes. There is a potential race condition where OSTaskQFirst[rtask] |
| 606 | has been modified. however this should only result in addtional call to pthread_cond_wait() but as |
| 607 | the cond is met, it will exit immediately (depending on schedulling) */ |
| 608 | if (gki_cb.com.OSTaskQFirst[rtask][0]) |
| 609 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_0_EVT_MASK; |
| 610 | if (gki_cb.com.OSTaskQFirst[rtask][1]) |
| 611 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_1_EVT_MASK; |
| 612 | if (gki_cb.com.OSTaskQFirst[rtask][2]) |
| 613 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_2_EVT_MASK; |
| 614 | if (gki_cb.com.OSTaskQFirst[rtask][3]) |
| 615 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_3_EVT_MASK; |
| 616 | #endif |
| 617 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 618 | if (!(gki_cb.com.OSWaitEvt[rtask] & flag)) { |
| 619 | if (timeout) { |
| 620 | // timeout = GKI_MS_TO_TICKS(timeout); /* convert from |
| 621 | // milliseconds to ticks */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 622 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 623 | /* get current system time */ |
| 624 | // clock_gettime(CLOCK_MONOTONIC, &currSysTime); |
| 625 | // abstime.tv_sec = currSysTime.time; |
| 626 | // abstime.tv_nsec = NANOSEC_PER_MILLISEC * |
| 627 | // currSysTime.millitm; |
| 628 | clock_gettime(CLOCK_MONOTONIC, &abstime); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 629 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 630 | /* add timeout */ |
| 631 | sec = timeout / 1000; |
| 632 | nano_sec = (timeout % 1000) * NANOSEC_PER_MILLISEC; |
| 633 | abstime.tv_nsec += nano_sec; |
| 634 | if (abstime.tv_nsec > NSEC_PER_SEC) { |
| 635 | abstime.tv_sec += (abstime.tv_nsec / NSEC_PER_SEC); |
| 636 | abstime.tv_nsec = abstime.tv_nsec % NSEC_PER_SEC; |
| 637 | } |
| 638 | abstime.tv_sec += sec; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 639 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 640 | pthread_cond_timedwait(&gki_cb.os.thread_evt_cond[rtask], |
| 641 | &gki_cb.os.thread_evt_mutex[rtask], &abstime); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 642 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 643 | } else { |
| 644 | pthread_cond_wait(&gki_cb.os.thread_evt_cond[rtask], |
| 645 | &gki_cb.os.thread_evt_mutex[rtask]); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 646 | } |
| 647 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 648 | /* TODO: check, this is probably neither not needed depending on |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 649 | phtread_cond_wait() implmentation, |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 650 | e.g. it looks like it is implemented as a counter in which case multiple |
| 651 | cond_signal |
| 652 | should NOT be lost! */ |
| 653 | // we are waking up after waiting for some events, so refresh variables |
| 654 | // no need to call GKI_disable() here as we know that we will have some |
| 655 | // events as we've been waking up after condition pending or timeout |
| 656 | if (gki_cb.com.OSTaskQFirst[rtask][0]) |
| 657 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_0_EVT_MASK; |
| 658 | if (gki_cb.com.OSTaskQFirst[rtask][1]) |
| 659 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_1_EVT_MASK; |
| 660 | if (gki_cb.com.OSTaskQFirst[rtask][2]) |
| 661 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_2_EVT_MASK; |
| 662 | if (gki_cb.com.OSTaskQFirst[rtask][3]) |
| 663 | gki_cb.com.OSWaitEvt[rtask] |= TASK_MBOX_3_EVT_MASK; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 664 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 665 | if (gki_cb.com.OSRdyTbl[rtask] == TASK_DEAD) { |
| 666 | gki_cb.com.OSWaitEvt[rtask] = 0; |
| 667 | /* unlock thread_evt_mutex as pthread_cond_wait() does auto lock when cond |
| 668 | * is met */ |
| 669 | pthread_mutex_unlock(&gki_cb.os.thread_evt_mutex[rtask]); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 670 | LOG(ERROR) << StringPrintf("GKI TASK_DEAD received. exit thread %d...", |
| 671 | rtask); |
nxf24591 | e1fb2f9 | 2018-06-06 14:41:56 +0530 | [diff] [blame] | 672 | #if (NXP_EXTNS == TRUE) |
| 673 | memset(&(gki_cb.os.thread_id[rtask]), 0, sizeof(pthread_t)); |
| 674 | #else |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 675 | gki_cb.os.thread_id[rtask] = 0; |
nxf24591 | e1fb2f9 | 2018-06-06 14:41:56 +0530 | [diff] [blame] | 676 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 677 | return (EVENT_MASK(GKI_SHUTDOWN_EVT)); |
| 678 | } |
| 679 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 680 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 681 | /* Clear the wait for event mask */ |
| 682 | gki_cb.com.OSWaitForEvt[rtask] = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 683 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 684 | /* Return only those bits which user wants... */ |
| 685 | evt = gki_cb.com.OSWaitEvt[rtask] & flag; |
| 686 | |
| 687 | /* Clear only those bits which user wants... */ |
| 688 | gki_cb.com.OSWaitEvt[rtask] &= ~flag; |
| 689 | |
| 690 | /* unlock thread_evt_mutex as pthread_cond_wait() does auto lock mutex when |
| 691 | * cond is met */ |
| 692 | pthread_mutex_unlock(&gki_cb.os.thread_evt_mutex[rtask]); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 693 | return (evt); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 694 | } |
| 695 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 696 | /******************************************************************************* |
| 697 | ** |
| 698 | ** Function GKI_delay |
| 699 | ** |
| 700 | ** Description This function is called by tasks to sleep unconditionally |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 701 | ** for a specified amount of time. The duration is in |
| 702 | ** milliseconds |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 703 | ** |
| 704 | ** Parameters: timeout - (input) the duration in milliseconds |
| 705 | ** |
| 706 | ** Returns void |
| 707 | ** |
| 708 | *******************************************************************************/ |
| 709 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 710 | void GKI_delay(uint32_t timeout) { |
| 711 | uint8_t rtask = GKI_get_taskid(); |
| 712 | struct timespec delay; |
| 713 | int err; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 714 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 715 | DLOG_IF(INFO, nfc_debug_enabled) |
| 716 | << StringPrintf("GKI_delay %d %d", rtask, timeout); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 717 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 718 | delay.tv_sec = timeout / 1000; |
| 719 | delay.tv_nsec = 1000 * 1000 * (timeout % 1000); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 720 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 721 | /* [u]sleep can't be used because it uses SIGALRM */ |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 722 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 723 | do { |
| 724 | err = nanosleep(&delay, &delay); |
| 725 | } while (err < 0 && errno == EINTR); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 726 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 727 | /* Check if task was killed while sleeping */ |
| 728 | /* NOTE |
| 729 | ** if you do not implement task killing, you do not |
| 730 | ** need this check. |
| 731 | */ |
| 732 | if (rtask && gki_cb.com.OSRdyTbl[rtask] == TASK_DEAD) { |
| 733 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 734 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 735 | DLOG_IF(INFO, nfc_debug_enabled) |
| 736 | << StringPrintf("GKI_delay %d %d done", rtask, timeout); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 737 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 738 | } |
| 739 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 740 | /******************************************************************************* |
| 741 | ** |
| 742 | ** Function GKI_send_event |
| 743 | ** |
| 744 | ** Description This function is called by tasks to send events to other |
| 745 | ** tasks. Tasks can also send events to themselves. |
| 746 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 747 | ** Parameters: task_id - (input) The id of the task to which the event has |
| 748 | ** to be sent |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 749 | ** event - (input) The event that has to be sent |
| 750 | ** |
| 751 | ** |
| 752 | ** Returns GKI_SUCCESS if all OK, else GKI_FAILURE |
| 753 | ** |
| 754 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 755 | uint8_t GKI_send_event(uint8_t task_id, uint16_t event) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 756 | /* use efficient coding to avoid pipeline stalls */ |
| 757 | if (task_id < GKI_MAX_TASKS) { |
| 758 | /* protect OSWaitEvt[task_id] from manipulation in GKI_wait() */ |
| 759 | pthread_mutex_lock(&gki_cb.os.thread_evt_mutex[task_id]); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 760 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 761 | /* Set the event bit */ |
| 762 | gki_cb.com.OSWaitEvt[task_id] |= event; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 763 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 764 | pthread_cond_signal(&gki_cb.os.thread_evt_cond[task_id]); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 765 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 766 | pthread_mutex_unlock(&gki_cb.os.thread_evt_mutex[task_id]); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 767 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 768 | return (GKI_SUCCESS); |
| 769 | } |
| 770 | return (GKI_FAILURE); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 771 | } |
| 772 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 773 | /******************************************************************************* |
| 774 | ** |
| 775 | ** Function GKI_isend_event |
| 776 | ** |
| 777 | ** Description This function is called from ISRs to send events to other |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 778 | ** tasks. The only difference between this function and |
| 779 | ** GKI_send_event is that this function assumes interrupts are |
| 780 | ** already disabled. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 781 | ** |
| 782 | ** Parameters: task_id - (input) The destination task Id for the event. |
| 783 | ** event - (input) The event flag |
| 784 | ** |
| 785 | ** Returns GKI_SUCCESS if all OK, else GKI_FAILURE |
| 786 | ** |
| 787 | ** NOTE This function is NOT called by the Widcomm stack and |
| 788 | ** profiles. If you want to use it in your own implementation, |
| 789 | ** put your code here, otherwise you can delete the entire |
| 790 | ** body of the function. |
| 791 | ** |
| 792 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 793 | uint8_t GKI_isend_event(uint8_t task_id, uint16_t event) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 794 | DLOG_IF(INFO, nfc_debug_enabled) |
| 795 | << StringPrintf("GKI_isend_event %d %x", task_id, event); |
| 796 | DLOG_IF(INFO, nfc_debug_enabled) |
| 797 | << StringPrintf("GKI_isend_event %d %x done", task_id, event); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 798 | return GKI_send_event(task_id, event); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 799 | } |
| 800 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 801 | /******************************************************************************* |
| 802 | ** |
| 803 | ** Function GKI_get_taskid |
| 804 | ** |
| 805 | ** Description This function gets the currently running task ID. |
| 806 | ** |
| 807 | ** Returns task ID |
| 808 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 809 | ** NOTE The Widcomm upper stack and profiles may run as a single |
| 810 | ** task. If you only have one GKI task, then you can hard-code |
| 811 | ** this function to return a '1'. Otherwise, you should have |
| 812 | ** some OS-specific method to determine the current task. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 813 | ** |
| 814 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 815 | uint8_t GKI_get_taskid(void) { |
| 816 | int i; |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 817 | pthread_t thread_id = pthread_self(); |
| 818 | for (i = 0; i < GKI_MAX_TASKS; i++) { |
nxf24591 | e1fb2f9 | 2018-06-06 14:41:56 +0530 | [diff] [blame] | 819 | #if (NXP_EXTNS == TRUE) |
| 820 | if (0 == memcmp(&(gki_cb.os.thread_id[i]), &thread_id, sizeof(pthread_t))) { |
| 821 | #else |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 822 | if (gki_cb.os.thread_id[i] == thread_id) { |
nxf24591 | e1fb2f9 | 2018-06-06 14:41:56 +0530 | [diff] [blame] | 823 | #endif |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 824 | return (i); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 825 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 826 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 827 | return (-1); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /******************************************************************************* |
| 831 | ** |
| 832 | ** Function GKI_map_taskname |
| 833 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 834 | ** Description This function gets the task name of the taskid passed as |
| 835 | ** arg. If GKI_MAX_TASKS is passed as arg the currently running |
| 836 | ** task name is returned |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 837 | ** |
| 838 | ** Parameters: task_id - (input) The id of the task whose name is being |
| 839 | ** sought. GKI_MAX_TASKS is passed to get the name of the |
| 840 | ** currently running task. |
| 841 | ** |
| 842 | ** Returns pointer to task name |
| 843 | ** |
| 844 | ** NOTE this function needs no customization |
| 845 | ** |
| 846 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 847 | int8_t* GKI_map_taskname(uint8_t task_id) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 848 | DLOG_IF(INFO, nfc_debug_enabled) |
| 849 | << StringPrintf("GKI_map_taskname %d", task_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 850 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 851 | if (task_id < GKI_MAX_TASKS) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 852 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf( |
| 853 | "GKI_map_taskname %d %s done", task_id, gki_cb.com.OSTName[task_id]); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 854 | return (gki_cb.com.OSTName[task_id]); |
| 855 | } else if (task_id == GKI_MAX_TASKS) { |
| 856 | return (gki_cb.com.OSTName[GKI_get_taskid()]); |
| 857 | } else { |
| 858 | return (int8_t*)"BAD"; |
| 859 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 860 | } |
| 861 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 862 | /******************************************************************************* |
| 863 | ** |
| 864 | ** Function GKI_enable |
| 865 | ** |
| 866 | ** Description This function enables interrupts. |
| 867 | ** |
| 868 | ** Returns void |
| 869 | ** |
| 870 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 871 | void GKI_enable(void) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 872 | pthread_mutex_unlock(&gki_cb.os.GKI_mutex); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 873 | /* pthread_mutex_xx is nesting save, no need for this: already_disabled = |
| 874 | * 0; */ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 875 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 876 | } |
| 877 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 878 | /******************************************************************************* |
| 879 | ** |
| 880 | ** Function GKI_disable |
| 881 | ** |
| 882 | ** Description This function disables interrupts. |
| 883 | ** |
| 884 | ** Returns void |
| 885 | ** |
| 886 | *******************************************************************************/ |
| 887 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 888 | void GKI_disable(void) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 889 | // DLOG_IF(INFO, nfc_debug_enabled) << |
| 890 | // StringPrintf("GKI_disable"); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 891 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 892 | /* pthread_mutex_xx is nesting save, no need for this: if |
| 893 | (!already_disabled) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 894 | already_disabled = 1; */ |
| 895 | pthread_mutex_lock(&gki_cb.os.GKI_mutex); |
| 896 | /* } */ |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 897 | // DLOG_IF(INFO, nfc_debug_enabled) << |
| 898 | // StringPrintf("Leaving GKI_disable"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 899 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 900 | } |
| 901 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 902 | /******************************************************************************* |
| 903 | ** |
| 904 | ** Function GKI_exception |
| 905 | ** |
| 906 | ** Description This function throws an exception. |
| 907 | ** This is normally only called for a nonrecoverable error. |
| 908 | ** |
| 909 | ** Parameters: code - (input) The code for the error |
| 910 | ** msg - (input) The message that has to be logged |
| 911 | ** |
| 912 | ** Returns void |
| 913 | ** |
| 914 | *******************************************************************************/ |
| 915 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 916 | void GKI_exception(uint16_t code, std::string msg) { |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 917 | uint8_t task_id; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 918 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 919 | LOG(ERROR) << StringPrintf("Task State Table"); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 920 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 921 | for (task_id = 0; task_id < GKI_MAX_TASKS; task_id++) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 922 | LOG(ERROR) << StringPrintf("TASK ID [%d] task name [%s] state [%d]", |
| 923 | task_id, gki_cb.com.OSTName[task_id], |
| 924 | gki_cb.com.OSRdyTbl[task_id]); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 925 | } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 926 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 927 | LOG(ERROR) << StringPrintf("%d %s", code, msg.c_str()); |
| 928 | LOG(ERROR) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 929 | "********************************************************************"); |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 930 | LOG(ERROR) << StringPrintf("* %d %s", code, msg.c_str()); |
| 931 | LOG(ERROR) << StringPrintf( |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 932 | "********************************************************************"); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 933 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 934 | LOG(ERROR) << StringPrintf("%d %s done", code, msg.c_str()); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 935 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 936 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 937 | } |
| 938 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 939 | /******************************************************************************* |
| 940 | ** |
| 941 | ** Function GKI_get_time_stamp |
| 942 | ** |
| 943 | ** Description This function formats the time into a user area |
| 944 | ** |
| 945 | ** Parameters: tbuf - (output) the address to the memory containing the |
| 946 | ** formatted time |
| 947 | ** |
| 948 | ** Returns the address of the user area containing the formatted time |
| 949 | ** The format of the time is ???? |
| 950 | ** |
| 951 | ** NOTE This function is only called by OBEX. |
| 952 | ** |
| 953 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 954 | int8_t* GKI_get_time_stamp(int8_t* tbuf) { |
| 955 | uint32_t ms_time; |
| 956 | uint32_t s_time; |
| 957 | uint32_t m_time; |
| 958 | uint32_t h_time; |
| 959 | int8_t* p_out = tbuf; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 960 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 961 | gki_cb.com.OSTicks = times(0); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 962 | ms_time = GKI_TICKS_TO_MS(gki_cb.com.OSTicks); |
| 963 | s_time = ms_time / 100; /* 100 Ticks per second */ |
| 964 | m_time = s_time / 60; |
| 965 | h_time = m_time / 60; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 966 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 967 | ms_time -= s_time * 100; |
| 968 | s_time -= m_time * 60; |
| 969 | m_time -= h_time * 60; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 970 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 971 | *p_out++ = (int8_t)((h_time / 10) + '0'); |
| 972 | *p_out++ = (int8_t)((h_time % 10) + '0'); |
| 973 | *p_out++ = ':'; |
| 974 | *p_out++ = (int8_t)((m_time / 10) + '0'); |
| 975 | *p_out++ = (int8_t)((m_time % 10) + '0'); |
| 976 | *p_out++ = ':'; |
| 977 | *p_out++ = (int8_t)((s_time / 10) + '0'); |
| 978 | *p_out++ = (int8_t)((s_time % 10) + '0'); |
| 979 | *p_out++ = ':'; |
| 980 | *p_out++ = (int8_t)((ms_time / 10) + '0'); |
| 981 | *p_out++ = (int8_t)((ms_time % 10) + '0'); |
| 982 | *p_out++ = ':'; |
| 983 | *p_out = 0; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 984 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 985 | return (tbuf); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 986 | } |
| 987 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 988 | /******************************************************************************* |
| 989 | ** |
| 990 | ** Function GKI_register_mempool |
| 991 | ** |
| 992 | ** Description This function registers a specific memory pool. |
| 993 | ** |
| 994 | ** Parameters: p_mem - (input) pointer to the memory pool |
| 995 | ** |
| 996 | ** Returns void |
| 997 | ** |
| 998 | ** NOTE This function is NOT called by the Widcomm stack and |
| 999 | ** profiles. If your OS has different memory pools, you |
| 1000 | ** can tell GKI the pool to use by calling this function. |
| 1001 | ** |
| 1002 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1003 | void GKI_register_mempool(void* p_mem) { |
| 1004 | gki_cb.com.p_user_mempool = p_mem; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1005 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1006 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | /******************************************************************************* |
| 1010 | ** |
| 1011 | ** Function GKI_os_malloc |
| 1012 | ** |
| 1013 | ** Description This function allocates memory |
| 1014 | ** |
| 1015 | ** Parameters: size - (input) The size of the memory that has to be |
| 1016 | ** allocated |
| 1017 | ** |
| 1018 | ** Returns the address of the memory allocated, or NULL if failed |
| 1019 | ** |
| 1020 | ** NOTE This function is called by the Widcomm stack when |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1021 | ** dynamic memory allocation is used. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1022 | ** |
| 1023 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1024 | void* GKI_os_malloc(uint32_t size) { return (malloc(size)); } |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1025 | |
| 1026 | /******************************************************************************* |
| 1027 | ** |
| 1028 | ** Function GKI_os_free |
| 1029 | ** |
| 1030 | ** Description This function frees memory |
| 1031 | ** |
| 1032 | ** Parameters: size - (input) The address of the memory that has to be |
| 1033 | ** freed |
| 1034 | ** |
| 1035 | ** Returns void |
| 1036 | ** |
| 1037 | ** NOTE This function is NOT called by the Widcomm stack and |
| 1038 | ** profiles. It is only called from within GKI if dynamic |
| 1039 | ** |
| 1040 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1041 | void GKI_os_free(void* p_mem) { |
| 1042 | if (p_mem != NULL) free(p_mem); |
| 1043 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1044 | } |
| 1045 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1046 | /******************************************************************************* |
| 1047 | ** |
| 1048 | ** Function GKI_suspend_task() |
| 1049 | ** |
| 1050 | ** Description This function suspends the task specified in the argument. |
| 1051 | ** |
| 1052 | ** Parameters: task_id - (input) the id of the task that has to suspended |
| 1053 | ** |
| 1054 | ** Returns GKI_SUCCESS if all OK, else GKI_FAILURE |
| 1055 | ** |
| 1056 | ** NOTE This function is NOT called by the Widcomm stack and |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1057 | ** profiles. If you want to implement task suspension |
| 1058 | ** capability, put specific code here. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1059 | ** |
| 1060 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1061 | uint8_t GKI_suspend_task(uint8_t task_id) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1062 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1063 | << StringPrintf("GKI_suspend_task %d - NOT implemented", task_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1064 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1065 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1066 | << StringPrintf("GKI_suspend_task %d done", task_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1067 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1068 | return (GKI_SUCCESS); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1069 | } |
| 1070 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1071 | /******************************************************************************* |
| 1072 | ** |
| 1073 | ** Function GKI_resume_task() |
| 1074 | ** |
| 1075 | ** Description This function resumes the task specified in the argument. |
| 1076 | ** |
| 1077 | ** Parameters: task_id - (input) the id of the task that has to resumed |
| 1078 | ** |
| 1079 | ** Returns GKI_SUCCESS if all OK |
| 1080 | ** |
| 1081 | ** NOTE This function is NOT called by the Widcomm stack and |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1082 | ** profiles. If you want to implement task suspension |
| 1083 | ** capability, put specific code here. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1084 | ** |
| 1085 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1086 | uint8_t GKI_resume_task(uint8_t task_id) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1087 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1088 | << StringPrintf("GKI_resume_task %d - NOT implemented", task_id); |
nxpandroid | cdd3044 | 2016-05-27 17:26:18 +0530 | [diff] [blame] | 1089 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1090 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1091 | << StringPrintf("GKI_resume_task %d done", task_id); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1092 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1093 | return (GKI_SUCCESS); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1094 | } |
| 1095 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1096 | /******************************************************************************* |
| 1097 | ** |
| 1098 | ** Function GKI_exit_task |
| 1099 | ** |
| 1100 | ** Description This function is called to stop a GKI task. |
| 1101 | ** |
| 1102 | ** Parameters: task_id - (input) the id of the task that has to be stopped |
| 1103 | ** |
| 1104 | ** Returns void |
| 1105 | ** |
| 1106 | ** NOTE This function is NOT called by the Widcomm stack and |
| 1107 | ** profiles. If you want to use it in your own implementation, |
| 1108 | ** put specific code here to kill a task. |
| 1109 | ** |
| 1110 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1111 | void GKI_exit_task(uint8_t task_id) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1112 | if (task_id >= GKI_MAX_TASKS) { |
| 1113 | return; |
| 1114 | } |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1115 | GKI_disable(); |
| 1116 | gki_cb.com.OSRdyTbl[task_id] = TASK_DEAD; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1117 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1118 | /* Destroy mutex and condition variable objects */ |
| 1119 | pthread_mutex_destroy(&gki_cb.os.thread_evt_mutex[task_id]); |
| 1120 | pthread_cond_destroy(&gki_cb.os.thread_evt_cond[task_id]); |
| 1121 | pthread_mutex_destroy(&gki_cb.os.thread_timeout_mutex[task_id]); |
| 1122 | pthread_cond_destroy(&gki_cb.os.thread_timeout_cond[task_id]); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1123 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1124 | GKI_enable(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1125 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1126 | // GKI_send_event(task_id, EVENT_MASK(GKI_SHUTDOWN_EVT)); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1127 | |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1128 | DLOG_IF(INFO, nfc_debug_enabled) |
| 1129 | << StringPrintf("GKI_exit_task %d done", task_id); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1130 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1131 | } |
| 1132 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1133 | /******************************************************************************* |
| 1134 | ** |
| 1135 | ** Function GKI_sched_lock |
| 1136 | ** |
| 1137 | ** Description This function is called by tasks to disable scheduler |
| 1138 | ** task context switching. |
| 1139 | ** |
| 1140 | ** Returns void |
| 1141 | ** |
| 1142 | ** NOTE This function is NOT called by the Widcomm stack and |
| 1143 | ** profiles. If you want to use it in your own implementation, |
| 1144 | ** put code here to tell the OS to disable context switching. |
| 1145 | ** |
| 1146 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1147 | void GKI_sched_lock(void) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1148 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("GKI_sched_lock"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1149 | GKI_disable(); |
| 1150 | return; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1151 | } |
| 1152 | |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1153 | /******************************************************************************* |
| 1154 | ** |
| 1155 | ** Function GKI_sched_unlock |
| 1156 | ** |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1157 | ** Description This function is called by tasks to enable scheduler |
| 1158 | ** switching. |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1159 | ** |
| 1160 | ** Returns void |
| 1161 | ** |
| 1162 | ** NOTE This function is NOT called by the Widcomm stack and |
| 1163 | ** profiles. If you want to use it in your own implementation, |
| 1164 | ** put code here to tell the OS to re-enable context switching. |
| 1165 | ** |
| 1166 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1167 | void GKI_sched_unlock(void) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1168 | DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("GKI_sched_unlock"); |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1169 | GKI_enable(); |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | /******************************************************************************* |
| 1173 | ** |
| 1174 | ** Function GKI_shiftdown |
| 1175 | ** |
| 1176 | ** Description shift memory down (to make space to insert a record) |
| 1177 | ** |
| 1178 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1179 | void GKI_shiftdown(uint8_t* p_mem, uint32_t len, uint32_t shift_amount) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1180 | uint8_t* ps = p_mem + len - 1; |
| 1181 | uint8_t* pd = ps + shift_amount; |
| 1182 | uint32_t xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1183 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1184 | for (xx = 0; xx < len; xx++) *pd-- = *ps--; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | /******************************************************************************* |
| 1188 | ** |
| 1189 | ** Function GKI_shiftup |
| 1190 | ** |
| 1191 | ** Description shift memory up (to delete a record) |
| 1192 | ** |
| 1193 | *******************************************************************************/ |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1194 | void GKI_shiftup(uint8_t* p_dest, uint8_t* p_src, uint32_t len) { |
nxf24591 | c1cbeab | 2018-02-21 17:32:26 +0530 | [diff] [blame] | 1195 | uint8_t* ps = p_src; |
| 1196 | uint8_t* pd = p_dest; |
| 1197 | uint32_t xx; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1198 | |
nxpandroid | 8f6d053 | 2017-07-12 18:25:30 +0530 | [diff] [blame] | 1199 | for (xx = 0; xx < len; xx++) *pd++ = *ps++; |
nxpandroid | c761165 | 2015-09-23 16:42:05 +0530 | [diff] [blame] | 1200 | } |