blob: c4f6be55a29ccbb9fc428c2f63edb45f7a2bb974 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
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 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080018
Sharvil Nanavati22509442014-09-06 18:17:55 -070019#pragma once
The Android Open Source Project5738f832012-12-12 16:00:35 -080020
Sharvil Nanavati6449e492014-06-06 01:26:23 -070021#include "bt_target.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080022#include "bt_types.h"
23
24/* Error codes */
25#define GKI_SUCCESS 0x00
26#define GKI_FAILURE 0x01
27#define GKI_INVALID_TASK 0xF0
28#define GKI_INVALID_POOL 0xFF
29
30
31/************************************************************************
32** Mailbox definitions. Each task has 4 mailboxes that are used to
33** send buffers to the task.
34*/
35#define TASK_MBOX_0 0
36#define TASK_MBOX_1 1
37#define TASK_MBOX_2 2
38#define TASK_MBOX_3 3
39
40#define NUM_TASK_MBOX 4
41
42/************************************************************************
43** Event definitions.
44**
45** There are 4 reserved events used to signal messages rcvd in task mailboxes.
46** There are 4 reserved events used to signal timeout events.
47** There are 8 general purpose events available for applications.
48*/
49#define MAX_EVENTS 16
50
51#define TASK_MBOX_0_EVT_MASK 0x0001
52#define TASK_MBOX_1_EVT_MASK 0x0002
53#define TASK_MBOX_2_EVT_MASK 0x0004
54#define TASK_MBOX_3_EVT_MASK 0x0008
55
56
57#define TIMER_0 0
58#define TIMER_1 1
59#define TIMER_2 2
60#define TIMER_3 3
61
62#define TIMER_0_EVT_MASK 0x0010
63#define TIMER_1_EVT_MASK 0x0020
64#define TIMER_2_EVT_MASK 0x0040
65#define TIMER_3_EVT_MASK 0x0080
66
67#define APPL_EVT_0 8
68#define APPL_EVT_1 9
69#define APPL_EVT_2 10
70#define APPL_EVT_3 11
71#define APPL_EVT_4 12
72#define APPL_EVT_5 13
73#define APPL_EVT_6 14
74#define APPL_EVT_7 15
75
76#define EVENT_MASK(evt) ((UINT16)(0x0001 << (evt)))
77
The Android Open Source Project5738f832012-12-12 16:00:35 -080078/* Timer list entry callback type
79*/
80typedef void (TIMER_CBACK)(void *p_tle);
81#ifndef TIMER_PARAM_TYPE
The Android Open Source Project5738f832012-12-12 16:00:35 -080082#define TIMER_PARAM_TYPE UINT32
83#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -080084/* Define a timer list entry
85*/
86typedef struct _tle
87{
88 struct _tle *p_next;
89 struct _tle *p_prev;
90 TIMER_CBACK *p_cback;
91 INT32 ticks;
Chris Manton5ec39bb2014-06-09 21:47:16 -070092 INT32 ticks_initial;
The Android Open Source Project5738f832012-12-12 16:00:35 -080093 TIMER_PARAM_TYPE param;
Andre Eisenbachcf32e8d2014-08-12 16:46:51 -070094 TIMER_PARAM_TYPE data;
The Android Open Source Project5738f832012-12-12 16:00:35 -080095 UINT16 event;
96 UINT8 in_use;
97} TIMER_LIST_ENT;
98
99/* Define a timer list queue
100*/
101typedef struct
102{
103 TIMER_LIST_ENT *p_first;
104 TIMER_LIST_ENT *p_last;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800105} TIMER_LIST_Q;
106
107
108/***********************************************************************
109** This queue is a general purpose buffer queue, for application use.
110*/
111typedef struct
112{
Chris Mantonfe7216c2014-05-06 10:35:42 -0700113 void *_p_first;
114 void *_p_last;
115 UINT16 _count;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800116} BUFFER_Q;
117
Mike Lockwoodd0bc2152014-06-10 16:52:39 -0700118#define GKI_IS_QUEUE_EMPTY(p_q) ((p_q)->count == 0)
119
The Android Open Source Project5738f832012-12-12 16:00:35 -0800120/* Task constants
121*/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122typedef void (*TASKPTR)(UINT32);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800123
124#define GKI_PUBLIC_POOL 0 /* General pool accessible to GKI_getbuf() */
125#define GKI_RESTRICTED_POOL 1 /* Inaccessible pool to GKI_getbuf() */
126
127/***********************************************************************
128** Function prototypes
129*/
130
The Android Open Source Project5738f832012-12-12 16:00:35 -0800131/* Task management
132*/
Sharvil Nanavati0d5de782014-09-06 16:31:37 -0700133GKI_API extern UINT8 GKI_create_task(TASKPTR, UINT8, const char *);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800134GKI_API extern void GKI_destroy_task(UINT8 task_id);
135GKI_API extern void GKI_task_self_cleanup(UINT8 task_id);
136GKI_API extern void GKI_exit_task(UINT8);
137GKI_API extern UINT8 GKI_get_taskid(void);
138GKI_API extern void GKI_init(void);
139GKI_API extern void GKI_shutdown(void);
Sharvil Nanavati0d5de782014-09-06 16:31:37 -0700140GKI_API extern const char *GKI_map_taskname(UINT8);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800141
142/* To send buffers and events between tasks
143*/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800144GKI_API extern UINT8 GKI_send_event (UINT8, UINT16);
145
146
147/* To get and release buffers, change owner and get size
148*/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800149GKI_API extern void GKI_freebuf (void *);
150GKI_API extern void *GKI_getbuf (UINT16);
151GKI_API extern UINT16 GKI_get_buf_size (void *);
152GKI_API extern void *GKI_getpoolbuf (UINT8);
153GKI_API extern UINT16 GKI_poolcount (UINT8);
154GKI_API extern UINT16 GKI_poolfreecount (UINT8);
155GKI_API extern UINT16 GKI_poolutilization (UINT8);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800156
157
158/* User buffer queue management
159*/
160GKI_API extern void *GKI_dequeue (BUFFER_Q *);
161GKI_API extern void GKI_enqueue (BUFFER_Q *, void *);
162GKI_API extern void GKI_enqueue_head (BUFFER_Q *, void *);
163GKI_API extern void *GKI_getfirst (BUFFER_Q *);
164GKI_API extern void *GKI_getlast (BUFFER_Q *);
165GKI_API extern void *GKI_getnext (void *);
166GKI_API extern void GKI_init_q (BUFFER_Q *);
Chris Mantonfe7216c2014-05-06 10:35:42 -0700167GKI_API extern UINT16 GKI_queue_length(BUFFER_Q *);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800168GKI_API extern BOOLEAN GKI_queue_is_empty(BUFFER_Q *);
169GKI_API extern void *GKI_remove_from_queue (BUFFER_Q *, void *);
170GKI_API extern UINT16 GKI_get_pool_bufsize (UINT8);
171
172/* Timer management
173*/
174GKI_API extern void GKI_add_to_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT *);
175GKI_API extern void GKI_delay(UINT32);
176GKI_API extern UINT32 GKI_get_tick_count(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800177GKI_API extern void GKI_init_timer_list (TIMER_LIST_Q *);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800178GKI_API extern INT32 GKI_ready_to_sleep (void);
Andre Eisenbache3afaf02014-08-19 19:10:31 -0700179GKI_API extern BOOLEAN GKI_remove_from_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT *);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800180GKI_API extern void GKI_start_timer(UINT8, INT32, BOOLEAN);
181GKI_API extern void GKI_stop_timer (UINT8);
182GKI_API extern void GKI_timer_update(INT32);
183GKI_API extern UINT16 GKI_update_timer_list (TIMER_LIST_Q *, INT32);
184GKI_API extern UINT32 GKI_get_remaining_ticks (TIMER_LIST_Q *, TIMER_LIST_ENT *);
185GKI_API extern UINT16 GKI_wait(UINT16, UINT32);
Chris Manton5ec39bb2014-06-09 21:47:16 -0700186GKI_API extern BOOLEAN GKI_timer_queue_is_empty(const TIMER_LIST_Q *timer_q);
187GKI_API extern TIMER_LIST_ENT *GKI_timer_getfirst(const TIMER_LIST_Q *timer_q);
Chris Manton5ec39bb2014-06-09 21:47:16 -0700188GKI_API extern INT32 GKI_timer_ticks_getinitial(const TIMER_LIST_ENT *tle);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800189
190/* Disable Interrupts, Enable Interrupts
191*/
192GKI_API extern void GKI_enable(void);
193GKI_API extern void GKI_disable(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800194
195/* Allocate (Free) memory from an OS
196*/
197GKI_API extern void *GKI_os_malloc (UINT32);
198GKI_API extern void GKI_os_free (void *);
199
200/* os timer operation */
201GKI_API extern UINT32 GKI_get_os_tick_count(void);
202
203/* Exception handling
204*/
205GKI_API extern void GKI_exception (UINT16, char *);
206
207#if GKI_DEBUG == TRUE
208GKI_API extern void GKI_PrintBufferUsage(UINT8 *p_num_pools, UINT16 *p_cur_used);
209GKI_API extern void GKI_PrintBuffer(void);
210GKI_API extern void GKI_print_task(void);
211#else
212#undef GKI_PrintBufferUsage
213#define GKI_PrintBuffer() NULL
214#endif