The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [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 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 18 | |
Sharvil Nanavati | 2250944 | 2014-09-06 18:17:55 -0700 | [diff] [blame^] | 19 | #pragma once |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 20 | |
Sharvil Nanavati | 6449e49 | 2014-06-06 01:26:23 -0700 | [diff] [blame] | 21 | #include "bt_target.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 22 | #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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 78 | /* Timer list entry callback type |
| 79 | */ |
| 80 | typedef void (TIMER_CBACK)(void *p_tle); |
| 81 | #ifndef TIMER_PARAM_TYPE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 82 | #define TIMER_PARAM_TYPE UINT32 |
| 83 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 84 | /* Define a timer list entry |
| 85 | */ |
| 86 | typedef struct _tle |
| 87 | { |
| 88 | struct _tle *p_next; |
| 89 | struct _tle *p_prev; |
| 90 | TIMER_CBACK *p_cback; |
| 91 | INT32 ticks; |
Chris Manton | 5ec39bb | 2014-06-09 21:47:16 -0700 | [diff] [blame] | 92 | INT32 ticks_initial; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 93 | TIMER_PARAM_TYPE param; |
Andre Eisenbach | cf32e8d | 2014-08-12 16:46:51 -0700 | [diff] [blame] | 94 | TIMER_PARAM_TYPE data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 95 | UINT16 event; |
| 96 | UINT8 in_use; |
| 97 | } TIMER_LIST_ENT; |
| 98 | |
| 99 | /* Define a timer list queue |
| 100 | */ |
| 101 | typedef struct |
| 102 | { |
| 103 | TIMER_LIST_ENT *p_first; |
| 104 | TIMER_LIST_ENT *p_last; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 105 | } TIMER_LIST_Q; |
| 106 | |
| 107 | |
| 108 | /*********************************************************************** |
| 109 | ** This queue is a general purpose buffer queue, for application use. |
| 110 | */ |
| 111 | typedef struct |
| 112 | { |
Chris Manton | fe7216c | 2014-05-06 10:35:42 -0700 | [diff] [blame] | 113 | void *_p_first; |
| 114 | void *_p_last; |
| 115 | UINT16 _count; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 116 | } BUFFER_Q; |
| 117 | |
Mike Lockwood | d0bc215 | 2014-06-10 16:52:39 -0700 | [diff] [blame] | 118 | #define GKI_IS_QUEUE_EMPTY(p_q) ((p_q)->count == 0) |
| 119 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 120 | /* Task constants |
| 121 | */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 122 | typedef void (*TASKPTR)(UINT32); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 123 | |
| 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | /* Task management |
| 132 | */ |
Sharvil Nanavati | 0d5de78 | 2014-09-06 16:31:37 -0700 | [diff] [blame] | 133 | GKI_API extern UINT8 GKI_create_task(TASKPTR, UINT8, const char *); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 134 | GKI_API extern void GKI_destroy_task(UINT8 task_id); |
| 135 | GKI_API extern void GKI_task_self_cleanup(UINT8 task_id); |
| 136 | GKI_API extern void GKI_exit_task(UINT8); |
| 137 | GKI_API extern UINT8 GKI_get_taskid(void); |
| 138 | GKI_API extern void GKI_init(void); |
| 139 | GKI_API extern void GKI_shutdown(void); |
Sharvil Nanavati | 0d5de78 | 2014-09-06 16:31:37 -0700 | [diff] [blame] | 140 | GKI_API extern const char *GKI_map_taskname(UINT8); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 141 | |
| 142 | /* To send buffers and events between tasks |
| 143 | */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 144 | GKI_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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 149 | GKI_API extern void GKI_freebuf (void *); |
| 150 | GKI_API extern void *GKI_getbuf (UINT16); |
| 151 | GKI_API extern UINT16 GKI_get_buf_size (void *); |
| 152 | GKI_API extern void *GKI_getpoolbuf (UINT8); |
| 153 | GKI_API extern UINT16 GKI_poolcount (UINT8); |
| 154 | GKI_API extern UINT16 GKI_poolfreecount (UINT8); |
| 155 | GKI_API extern UINT16 GKI_poolutilization (UINT8); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 156 | |
| 157 | |
| 158 | /* User buffer queue management |
| 159 | */ |
| 160 | GKI_API extern void *GKI_dequeue (BUFFER_Q *); |
| 161 | GKI_API extern void GKI_enqueue (BUFFER_Q *, void *); |
| 162 | GKI_API extern void GKI_enqueue_head (BUFFER_Q *, void *); |
| 163 | GKI_API extern void *GKI_getfirst (BUFFER_Q *); |
| 164 | GKI_API extern void *GKI_getlast (BUFFER_Q *); |
| 165 | GKI_API extern void *GKI_getnext (void *); |
| 166 | GKI_API extern void GKI_init_q (BUFFER_Q *); |
Chris Manton | fe7216c | 2014-05-06 10:35:42 -0700 | [diff] [blame] | 167 | GKI_API extern UINT16 GKI_queue_length(BUFFER_Q *); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 168 | GKI_API extern BOOLEAN GKI_queue_is_empty(BUFFER_Q *); |
| 169 | GKI_API extern void *GKI_remove_from_queue (BUFFER_Q *, void *); |
| 170 | GKI_API extern UINT16 GKI_get_pool_bufsize (UINT8); |
| 171 | |
| 172 | /* Timer management |
| 173 | */ |
| 174 | GKI_API extern void GKI_add_to_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT *); |
| 175 | GKI_API extern void GKI_delay(UINT32); |
| 176 | GKI_API extern UINT32 GKI_get_tick_count(void); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 177 | GKI_API extern void GKI_init_timer_list (TIMER_LIST_Q *); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 178 | GKI_API extern INT32 GKI_ready_to_sleep (void); |
Andre Eisenbach | e3afaf0 | 2014-08-19 19:10:31 -0700 | [diff] [blame] | 179 | GKI_API extern BOOLEAN GKI_remove_from_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT *); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 180 | GKI_API extern void GKI_start_timer(UINT8, INT32, BOOLEAN); |
| 181 | GKI_API extern void GKI_stop_timer (UINT8); |
| 182 | GKI_API extern void GKI_timer_update(INT32); |
| 183 | GKI_API extern UINT16 GKI_update_timer_list (TIMER_LIST_Q *, INT32); |
| 184 | GKI_API extern UINT32 GKI_get_remaining_ticks (TIMER_LIST_Q *, TIMER_LIST_ENT *); |
| 185 | GKI_API extern UINT16 GKI_wait(UINT16, UINT32); |
Chris Manton | 5ec39bb | 2014-06-09 21:47:16 -0700 | [diff] [blame] | 186 | GKI_API extern BOOLEAN GKI_timer_queue_is_empty(const TIMER_LIST_Q *timer_q); |
| 187 | GKI_API extern TIMER_LIST_ENT *GKI_timer_getfirst(const TIMER_LIST_Q *timer_q); |
Chris Manton | 5ec39bb | 2014-06-09 21:47:16 -0700 | [diff] [blame] | 188 | GKI_API extern INT32 GKI_timer_ticks_getinitial(const TIMER_LIST_ENT *tle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 189 | |
| 190 | /* Disable Interrupts, Enable Interrupts |
| 191 | */ |
| 192 | GKI_API extern void GKI_enable(void); |
| 193 | GKI_API extern void GKI_disable(void); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 194 | |
| 195 | /* Allocate (Free) memory from an OS |
| 196 | */ |
| 197 | GKI_API extern void *GKI_os_malloc (UINT32); |
| 198 | GKI_API extern void GKI_os_free (void *); |
| 199 | |
| 200 | /* os timer operation */ |
| 201 | GKI_API extern UINT32 GKI_get_os_tick_count(void); |
| 202 | |
| 203 | /* Exception handling |
| 204 | */ |
| 205 | GKI_API extern void GKI_exception (UINT16, char *); |
| 206 | |
| 207 | #if GKI_DEBUG == TRUE |
| 208 | GKI_API extern void GKI_PrintBufferUsage(UINT8 *p_num_pools, UINT16 *p_cur_used); |
| 209 | GKI_API extern void GKI_PrintBuffer(void); |
| 210 | GKI_API extern void GKI_print_task(void); |
| 211 | #else |
| 212 | #undef GKI_PrintBufferUsage |
| 213 | #define GKI_PrintBuffer() NULL |
| 214 | #endif |