• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_H
19 #define GKI_H
20 
21 
22 #include "bt_target.h"
23 #include "bt_types.h"
24 
25 /* Error codes */
26 #define GKI_SUCCESS         0x00
27 #define GKI_FAILURE         0x01
28 #define GKI_INVALID_TASK    0xF0
29 #define GKI_INVALID_POOL    0xFF
30 
31 
32 /************************************************************************
33 ** Mailbox definitions. Each task has 4 mailboxes that are used to
34 ** send buffers to the task.
35 */
36 #define TASK_MBOX_0    0
37 #define TASK_MBOX_1    1
38 #define TASK_MBOX_2    2
39 #define TASK_MBOX_3    3
40 
41 #define NUM_TASK_MBOX  4
42 
43 /************************************************************************
44 ** Event definitions.
45 **
46 ** There are 4 reserved events used to signal messages rcvd in task mailboxes.
47 ** There are 4 reserved events used to signal timeout events.
48 ** There are 8 general purpose events available for applications.
49 */
50 #define MAX_EVENTS              16
51 
52 #define TASK_MBOX_0_EVT_MASK   0x0001
53 #define TASK_MBOX_1_EVT_MASK   0x0002
54 #define TASK_MBOX_2_EVT_MASK   0x0004
55 #define TASK_MBOX_3_EVT_MASK   0x0008
56 
57 
58 #define TIMER_0             0
59 #define TIMER_1             1
60 #define TIMER_2             2
61 #define TIMER_3             3
62 
63 #define TIMER_0_EVT_MASK    0x0010
64 #define TIMER_1_EVT_MASK    0x0020
65 #define TIMER_2_EVT_MASK    0x0040
66 #define TIMER_3_EVT_MASK    0x0080
67 
68 #define APPL_EVT_0          8
69 #define APPL_EVT_1          9
70 #define APPL_EVT_2          10
71 #define APPL_EVT_3          11
72 #define APPL_EVT_4          12
73 #define APPL_EVT_5          13
74 #define APPL_EVT_6          14
75 #define APPL_EVT_7          15
76 
77 #define EVENT_MASK(evt)       ((UINT16)(0x0001 << (evt)))
78 
79 /* Timer list entry callback type
80 */
81 typedef void (TIMER_CBACK)(void *p_tle);
82 #ifndef TIMER_PARAM_TYPE
83 #define TIMER_PARAM_TYPE    UINT32
84 #endif
85 /* Define a timer list entry
86 */
87 typedef struct _tle
88 {
89     struct _tle  *p_next;
90     struct _tle  *p_prev;
91     TIMER_CBACK  *p_cback;
92     INT32         ticks;
93     INT32         ticks_initial;
94     TIMER_PARAM_TYPE   param;
95     TIMER_PARAM_TYPE   data;
96     UINT16        event;
97     UINT8         in_use;
98 } TIMER_LIST_ENT;
99 
100 /* Define a timer list queue
101 */
102 typedef struct
103 {
104     TIMER_LIST_ENT   *p_first;
105     TIMER_LIST_ENT   *p_last;
106 } TIMER_LIST_Q;
107 
108 
109 /***********************************************************************
110 ** This queue is a general purpose buffer queue, for application use.
111 */
112 typedef struct
113 {
114     void    *p_first;
115     void    *p_last;
116     UINT16   count;
117 } BUFFER_Q;
118 
119 #define GKI_IS_QUEUE_EMPTY(p_q) ((p_q)->count == 0)
120 
121 /* Task constants
122 */
123 #ifndef TASKPTR
124 typedef void (*TASKPTR)(UINT32);
125 #endif
126 
127 
128 #define GKI_PUBLIC_POOL         0       /* General pool accessible to GKI_getbuf() */
129 #define GKI_RESTRICTED_POOL     1       /* Inaccessible pool to GKI_getbuf() */
130 
131 /***********************************************************************
132 ** Function prototypes
133 */
134 
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138 
139 /* Task management
140 */
141 GKI_API extern UINT8   GKI_create_task (TASKPTR, UINT8, INT8 *, UINT16 *, UINT16);
142 GKI_API extern void    GKI_destroy_task(UINT8 task_id);
143 GKI_API extern void    GKI_task_self_cleanup(UINT8 task_id);
144 GKI_API extern void    GKI_exit_task(UINT8);
145 GKI_API extern UINT8   GKI_get_taskid(void);
146 GKI_API extern void    GKI_init(void);
147 GKI_API extern void    GKI_shutdown(void);
148 GKI_API extern INT8   *GKI_map_taskname(UINT8);
149 GKI_API extern void    GKI_run(void);
150 GKI_API extern void    GKI_stop(void);
151 
152 /* To send buffers and events between tasks
153 */
154 GKI_API extern void   *GKI_read_mbox  (UINT8);
155 GKI_API extern void    GKI_send_msg   (UINT8, UINT8, void *);
156 GKI_API extern UINT8   GKI_send_event (UINT8, UINT16);
157 
158 
159 /* To get and release buffers, change owner and get size
160 */
161 GKI_API extern void    GKI_freebuf (void *);
162 GKI_API extern void   *GKI_getbuf (UINT16);
163 GKI_API extern UINT16  GKI_get_buf_size (void *);
164 GKI_API extern void   *GKI_getpoolbuf (UINT8);
165 GKI_API extern UINT16  GKI_poolcount (UINT8);
166 GKI_API extern UINT16  GKI_poolfreecount (UINT8);
167 GKI_API extern UINT16  GKI_poolutilization (UINT8);
168 
169 
170 /* User buffer queue management
171 */
172 GKI_API extern void   *GKI_dequeue  (BUFFER_Q *);
173 GKI_API extern void    GKI_enqueue (BUFFER_Q *, void *);
174 GKI_API extern void    GKI_enqueue_head (BUFFER_Q *, void *);
175 GKI_API extern void   *GKI_getfirst (BUFFER_Q *);
176 GKI_API extern void   *GKI_getlast (BUFFER_Q *);
177 GKI_API extern void   *GKI_getnext (void *);
178 GKI_API extern void    GKI_init_q (BUFFER_Q *);
179 GKI_API extern BOOLEAN GKI_queue_is_empty(BUFFER_Q *);
180 GKI_API extern void   *GKI_remove_from_queue (BUFFER_Q *, void *);
181 GKI_API extern UINT16  GKI_get_pool_bufsize (UINT8);
182 
183 /* Timer management
184 */
185 GKI_API extern void    GKI_add_to_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT  *);
186 GKI_API extern void    GKI_delay(UINT32);
187 GKI_API extern UINT32  GKI_get_tick_count(void);
188 GKI_API extern void    GKI_init_timer_list (TIMER_LIST_Q *);
189 GKI_API extern INT32   GKI_ready_to_sleep (void);
190 GKI_API extern BOOLEAN GKI_remove_from_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT  *);
191 GKI_API extern void    GKI_start_timer(UINT8, INT32, BOOLEAN);
192 GKI_API extern void    GKI_stop_timer (UINT8);
193 GKI_API extern void    GKI_timer_update(INT32);
194 GKI_API extern UINT16  GKI_update_timer_list (TIMER_LIST_Q *, INT32);
195 GKI_API extern UINT32  GKI_get_remaining_ticks (TIMER_LIST_Q *, TIMER_LIST_ENT  *);
196 GKI_API extern UINT16  GKI_wait(UINT16, UINT32);
197 GKI_API extern BOOLEAN GKI_timer_queue_is_empty(const TIMER_LIST_Q *timer_q);
198 GKI_API extern TIMER_LIST_ENT *GKI_timer_getfirst(const TIMER_LIST_Q *timer_q);
199 GKI_API extern INT32 GKI_timer_ticks_getinitial(const TIMER_LIST_ENT *tle);
200 
201 /* Disable Interrupts, Enable Interrupts
202 */
203 GKI_API extern void    GKI_enable(void);
204 GKI_API extern void    GKI_disable(void);
205 
206 /* Allocate (Free) memory from an OS
207 */
208 GKI_API extern void     *GKI_os_malloc (UINT32);
209 GKI_API extern void      GKI_os_free (void *);
210 
211 /* os timer operation */
212 GKI_API extern UINT32 GKI_get_os_tick_count(void);
213 
214 /* Exception handling
215 */
216 GKI_API extern void    GKI_exception (UINT16, char *);
217 
218 #if GKI_DEBUG == TRUE
219 GKI_API extern void    GKI_PrintBufferUsage(UINT8 *p_num_pools, UINT16 *p_cur_used);
220 GKI_API extern void    GKI_PrintBuffer(void);
221 GKI_API extern void    GKI_print_task(void);
222 #else
223 #undef GKI_PrintBufferUsage
224 #define GKI_PrintBuffer() NULL
225 #endif
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 
232 #endif
233