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 ******************************************************************************/
18#ifndef GKI_INT_H
19#define GKI_INT_H
20
21#include "gki_common.h"
22#include <pthread.h>
23#include <sys/prctl.h>
24
25/**********************************************************************
26** OS specific definitions
27*/
28/* The base priority used for pthread based GKI task. below value is to keep it retro compatible.
29 * It is recommended to use (GKI_MAX_TASKS+3), this will assign real time priorities GKI_MAX_TASKS-
30 * task_id -2 to the thread */
31#ifndef GKI_LINUX_BASE_PRIORITY
32#define GKI_LINUX_BASE_PRIORITY 30
33#endif
34
35/* The base policy used for pthread based GKI task. the sched defines are defined here to avoid undefined values due
36 * to missing header file, see pthread functions! Overall it is recommend however to use SCHED_NOMRAL */
37#define GKI_SCHED_NORMAL    0
38#define GKI_SCHED_FIFO      1
39#define GKI_SCHED_RR        2
40#ifndef GKI_LINUX_BASE_POLICY
41#define GKI_LINUX_BASE_POLICY GKI_SCHED_NORMAL
42#endif
43
44/* GKI timer bases should use GKI_SCHED_FIFO to ensure the least jitter possible */
45#ifndef GKI_LINUX_TIMER_POLICY
46#define GKI_LINUX_TIMER_POLICY GKI_SCHED_FIFO
47#endif
48
49/* the GKI_timer_update() thread should have the highest real time priority to ensue correct
50 * timer expiry.
51 */
52#ifndef GKI_LINUX_TIMER_TICK_PRIORITY
53#define GKI_LINUX_TIMER_TICK_PRIORITY GKI_LINUX_BASE_PRIORITY+2
54#endif
55
56/* the AV timer should preferably run above the gki timer tick to ensure precise AV timing
57 * If you observe AV jitter under have load you may increase this one */
58#ifndef GKI_LINUX_AV_TIMER_PRIORITY
59#define GKI_LINUX_AV_TIMER_PRIORITY GKI_LINUX_BASE_PRIORITY+3
60#endif
61
62/* defines by how much the nice value of the PROCESS should be changed. Values allowed:
63 * -19 to +19. a negative value give higher priority to btld compared to the default nice value
64 * of 20. in case of SCHED_NORMAL, a level of -5 should give a good btld/bt performance.
65 * In case of real time scheduling, leave default value.
66 */
67#ifndef GKI_LINUX_DEFAULT_NICE_INC
68#define GKI_LINUX_DEFAULT_NICE_INC -7
69#endif
70
71typedef struct
72{
73    pthread_mutex_t     GKI_mutex;
74    pthread_t           thread_id[GKI_MAX_TASKS];
75    pthread_mutex_t     thread_evt_mutex[GKI_MAX_TASKS];
76    pthread_cond_t      thread_evt_cond[GKI_MAX_TASKS];
77    pthread_mutex_t     thread_timeout_mutex[GKI_MAX_TASKS];
78    pthread_cond_t      thread_timeout_cond[GKI_MAX_TASKS];
79    int                 no_timer_suspend;   /* 1: no suspend, 0 stop calling GKI_timer_update() */
80    pthread_mutex_t     gki_timer_mutex;
81    pthread_cond_t      gki_timer_cond;
82#if (GKI_DEBUG == TRUE)
83    pthread_mutex_t     GKI_trace_mutex;
84#endif
85} tGKI_OS;
86
87/* condition to exit or continue GKI_run() timer loop */
88#define GKI_TIMER_TICK_RUN_COND 1
89#define GKI_TIMER_TICK_STOP_COND 0
90
91extern void gki_system_tick_start_stop_cback(BOOLEAN start);
92
93/* Contains common control block as well as OS specific variables */
94typedef struct
95{
96    tGKI_OS     os;
97    tGKI_COM_CB com;
98} tGKI_CB;
99
100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
105#if GKI_DYNAMIC_MEMORY == FALSE
106GKI_API extern tGKI_CB  gki_cb;
107#else
108GKI_API extern tGKI_CB *gki_cb_ptr;
109#define gki_cb (*gki_cb_ptr)
110#endif
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif
117
118