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*/ 81typedef 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*/ 87typedef 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*/ 102typedef 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*/ 112typedef 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 124typedef 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 136extern "C" { 137#endif 138 139/* Task management 140*/ 141GKI_API extern UINT8 GKI_create_task (TASKPTR, UINT8, INT8 *, UINT16 *, UINT16); 142GKI_API extern void GKI_destroy_task(UINT8 task_id); 143GKI_API extern void GKI_task_self_cleanup(UINT8 task_id); 144GKI_API extern void GKI_exit_task(UINT8); 145GKI_API extern UINT8 GKI_get_taskid(void); 146GKI_API extern void GKI_init(void); 147GKI_API extern void GKI_shutdown(void); 148GKI_API extern INT8 *GKI_map_taskname(UINT8); 149GKI_API extern void GKI_run(void); 150GKI_API extern void GKI_stop(void); 151 152/* To send buffers and events between tasks 153*/ 154GKI_API extern void *GKI_read_mbox (UINT8); 155GKI_API extern void GKI_send_msg (UINT8, UINT8, void *); 156GKI_API extern UINT8 GKI_send_event (UINT8, UINT16); 157 158 159/* To get and release buffers, change owner and get size 160*/ 161GKI_API extern void GKI_freebuf (void *); 162GKI_API extern void *GKI_getbuf (UINT16); 163GKI_API extern UINT16 GKI_get_buf_size (void *); 164GKI_API extern void *GKI_getpoolbuf (UINT8); 165GKI_API extern UINT16 GKI_poolcount (UINT8); 166GKI_API extern UINT16 GKI_poolfreecount (UINT8); 167GKI_API extern UINT16 GKI_poolutilization (UINT8); 168 169 170/* User buffer queue management 171*/ 172GKI_API extern void *GKI_dequeue (BUFFER_Q *); 173GKI_API extern void GKI_enqueue (BUFFER_Q *, void *); 174GKI_API extern void GKI_enqueue_head (BUFFER_Q *, void *); 175GKI_API extern void *GKI_getfirst (BUFFER_Q *); 176GKI_API extern void *GKI_getlast (BUFFER_Q *); 177GKI_API extern void *GKI_getnext (void *); 178GKI_API extern void GKI_init_q (BUFFER_Q *); 179GKI_API extern BOOLEAN GKI_queue_is_empty(BUFFER_Q *); 180GKI_API extern void *GKI_remove_from_queue (BUFFER_Q *, void *); 181GKI_API extern UINT16 GKI_get_pool_bufsize (UINT8); 182 183/* Timer management 184*/ 185GKI_API extern void GKI_add_to_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT *); 186GKI_API extern void GKI_delay(UINT32); 187GKI_API extern UINT32 GKI_get_tick_count(void); 188GKI_API extern void GKI_init_timer_list (TIMER_LIST_Q *); 189GKI_API extern INT32 GKI_ready_to_sleep (void); 190GKI_API extern BOOLEAN GKI_remove_from_timer_list (TIMER_LIST_Q *, TIMER_LIST_ENT *); 191GKI_API extern void GKI_start_timer(UINT8, INT32, BOOLEAN); 192GKI_API extern void GKI_stop_timer (UINT8); 193GKI_API extern void GKI_timer_update(INT32); 194GKI_API extern UINT16 GKI_update_timer_list (TIMER_LIST_Q *, INT32); 195GKI_API extern UINT32 GKI_get_remaining_ticks (TIMER_LIST_Q *, TIMER_LIST_ENT *); 196GKI_API extern UINT16 GKI_wait(UINT16, UINT32); 197GKI_API extern BOOLEAN GKI_timer_queue_is_empty(const TIMER_LIST_Q *timer_q); 198GKI_API extern TIMER_LIST_ENT *GKI_timer_getfirst(const TIMER_LIST_Q *timer_q); 199GKI_API extern INT32 GKI_timer_ticks_getinitial(const TIMER_LIST_ENT *tle); 200 201/* Disable Interrupts, Enable Interrupts 202*/ 203GKI_API extern void GKI_enable(void); 204GKI_API extern void GKI_disable(void); 205 206/* Allocate (Free) memory from an OS 207*/ 208GKI_API extern void *GKI_os_malloc (UINT32); 209GKI_API extern void GKI_os_free (void *); 210 211/* os timer operation */ 212GKI_API extern UINT32 GKI_get_os_tick_count(void); 213 214/* Exception handling 215*/ 216GKI_API extern void GKI_exception (UINT16, char *); 217 218#if GKI_DEBUG == TRUE 219GKI_API extern void GKI_PrintBufferUsage(UINT8 *p_num_pools, UINT16 *p_cur_used); 220GKI_API extern void GKI_PrintBuffer(void); 221GKI_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