gki_common.h revision 5738f83aeb59361a0a2eda2460113f6dc9194271
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_COMMON_H 19#define GKI_COMMON_H 20 21#include "gki.h" 22#include "dyn_mem.h" 23 24/* Task States: (For OSRdyTbl) */ 25#define TASK_DEAD 0 /* b0000 */ 26#define TASK_READY 1 /* b0001 */ 27#define TASK_WAIT 2 /* b0010 */ 28#define TASK_DELAY 4 /* b0100 */ 29#define TASK_SUSPEND 8 /* b1000 */ 30 31 32/******************************************************************** 33** Internal Error codes 34*********************************************************************/ 35#define GKI_ERROR_BUF_CORRUPTED 0xFFFF 36#define GKI_ERROR_NOT_BUF_OWNER 0xFFFE 37#define GKI_ERROR_FREEBUF_BAD_QID 0xFFFD 38#define GKI_ERROR_FREEBUF_BUF_LINKED 0xFFFC 39#define GKI_ERROR_SEND_MSG_BAD_DEST 0xFFFB 40#define GKI_ERROR_SEND_MSG_BUF_LINKED 0xFFFA 41#define GKI_ERROR_ENQUEUE_BUF_LINKED 0xFFF9 42#define GKI_ERROR_DELETE_POOL_BAD_QID 0xFFF8 43#define GKI_ERROR_BUF_SIZE_TOOBIG 0xFFF7 44#define GKI_ERROR_BUF_SIZE_ZERO 0xFFF6 45#define GKI_ERROR_ADDR_NOT_IN_BUF 0xFFF5 46 47 48/******************************************************************** 49** Misc constants 50*********************************************************************/ 51 52#define GKI_MAX_INT32 (0x7fffffffL) 53#define GKI_MAX_TIMESTAMP (0xffffffffL) 54 55/******************************************************************** 56** Buffer Management Data Structures 57*********************************************************************/ 58 59typedef struct _buffer_hdr 60{ 61 struct _buffer_hdr *p_next; /* next buffer in the queue */ 62 UINT8 q_id; /* id of the queue */ 63 UINT8 task_id; /* task which allocated the buffer*/ 64 UINT8 status; /* FREE, UNLINKED or QUEUED */ 65 UINT8 Type; 66} BUFFER_HDR_T; 67 68typedef struct _free_queue 69{ 70 BUFFER_HDR_T *p_first; /* first buffer in the queue */ 71 BUFFER_HDR_T *p_last; /* last buffer in the queue */ 72 UINT16 size; /* size of the buffers in the pool */ 73 UINT16 total; /* toatal number of buffers */ 74 UINT16 cur_cnt; /* number of buffers currently allocated */ 75 UINT16 max_cnt; /* maximum number of buffers allocated at any time */ 76} FREE_QUEUE_T; 77 78 79/* Buffer related defines 80*/ 81#define ALIGN_POOL(pl_size) ( (((pl_size) + 3) / sizeof(UINT32)) * sizeof(UINT32)) 82#define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T)) /* Offset past header */ 83#define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(UINT32)) /* Header + Magic Number */ 84#define MAX_USER_BUF_SIZE ((UINT16)0xffff - BUFFER_PADDING_SIZE) /* pool size must allow for header */ 85#define MAGIC_NO 0xDDBADDBA 86 87#define BUF_STATUS_FREE 0 88#define BUF_STATUS_UNLINKED 1 89#define BUF_STATUS_QUEUED 2 90 91// btla-specific ++ 92#define GKI_USE_DEFERED_ALLOC_BUF_POOLS 93// btla-specific -- 94 95/* Exception related structures (Used in debug mode only) 96*/ 97#if (GKI_DEBUG == TRUE) 98typedef struct 99{ 100 UINT16 type; 101 UINT8 taskid; 102 UINT8 msg[GKI_MAX_EXCEPTION_MSGLEN]; 103} EXCEPTION_T; 104#endif 105 106 107/* Put all GKI variables into one control block 108*/ 109typedef struct 110{ 111 /* Task management variables 112 */ 113 /* The stack and stack size are not used on Windows 114 */ 115// btla-specific ++ 116#if (!defined GKI_USE_DEFERED_ALLOC_BUF_POOLS && (GKI_USE_DYNAMIC_BUFFERS == FALSE)) 117// btla-specific -- 118 119#if (GKI_NUM_FIXED_BUF_POOLS > 0) 120 UINT8 bufpool0[(ALIGN_POOL(GKI_BUF0_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF0_MAX]; 121#endif 122 123#if (GKI_NUM_FIXED_BUF_POOLS > 1) 124 UINT8 bufpool1[(ALIGN_POOL(GKI_BUF1_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF1_MAX]; 125#endif 126 127#if (GKI_NUM_FIXED_BUF_POOLS > 2) 128 UINT8 bufpool2[(ALIGN_POOL(GKI_BUF2_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF2_MAX]; 129#endif 130 131#if (GKI_NUM_FIXED_BUF_POOLS > 3) 132 UINT8 bufpool3[(ALIGN_POOL(GKI_BUF3_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF3_MAX]; 133#endif 134 135#if (GKI_NUM_FIXED_BUF_POOLS > 4) 136 UINT8 bufpool4[(ALIGN_POOL(GKI_BUF4_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF4_MAX]; 137#endif 138 139#if (GKI_NUM_FIXED_BUF_POOLS > 5) 140 UINT8 bufpool5[(ALIGN_POOL(GKI_BUF5_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF5_MAX]; 141#endif 142 143#if (GKI_NUM_FIXED_BUF_POOLS > 6) 144 UINT8 bufpool6[(ALIGN_POOL(GKI_BUF6_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF6_MAX]; 145#endif 146 147#if (GKI_NUM_FIXED_BUF_POOLS > 7) 148 UINT8 bufpool7[(ALIGN_POOL(GKI_BUF7_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF7_MAX]; 149#endif 150 151#if (GKI_NUM_FIXED_BUF_POOLS > 8) 152 UINT8 bufpool8[(ALIGN_POOL(GKI_BUF8_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF8_MAX]; 153#endif 154 155#if (GKI_NUM_FIXED_BUF_POOLS > 9) 156 UINT8 bufpool9[(ALIGN_POOL(GKI_BUF9_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF9_MAX]; 157#endif 158 159#if (GKI_NUM_FIXED_BUF_POOLS > 10) 160 UINT8 bufpool10[(ALIGN_POOL(GKI_BUF10_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF10_MAX]; 161#endif 162 163#if (GKI_NUM_FIXED_BUF_POOLS > 11) 164 UINT8 bufpool11[(ALIGN_POOL(GKI_BUF11_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF11_MAX]; 165#endif 166 167#if (GKI_NUM_FIXED_BUF_POOLS > 12) 168 UINT8 bufpool12[(ALIGN_POOL(GKI_BUF12_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF12_MAX]; 169#endif 170 171#if (GKI_NUM_FIXED_BUF_POOLS > 13) 172 UINT8 bufpool13[(ALIGN_POOL(GKI_BUF13_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF13_MAX]; 173#endif 174 175#if (GKI_NUM_FIXED_BUF_POOLS > 14) 176 UINT8 bufpool14[(ALIGN_POOL(GKI_BUF14_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF14_MAX]; 177#endif 178 179#if (GKI_NUM_FIXED_BUF_POOLS > 15) 180 UINT8 bufpool15[(ALIGN_POOL(GKI_BUF15_SIZE) + BUFFER_PADDING_SIZE) * GKI_BUF15_MAX]; 181#endif 182 183#else 184/* Definitions for dynamic buffer use */ 185#if (GKI_NUM_FIXED_BUF_POOLS > 0) 186 UINT8 *bufpool0; 187#endif 188 189#if (GKI_NUM_FIXED_BUF_POOLS > 1) 190 UINT8 *bufpool1; 191#endif 192 193#if (GKI_NUM_FIXED_BUF_POOLS > 2) 194 UINT8 *bufpool2; 195#endif 196 197#if (GKI_NUM_FIXED_BUF_POOLS > 3) 198 UINT8 *bufpool3; 199#endif 200 201#if (GKI_NUM_FIXED_BUF_POOLS > 4) 202 UINT8 *bufpool4; 203#endif 204 205#if (GKI_NUM_FIXED_BUF_POOLS > 5) 206 UINT8 *bufpool5; 207#endif 208 209#if (GKI_NUM_FIXED_BUF_POOLS > 6) 210 UINT8 *bufpool6; 211#endif 212 213#if (GKI_NUM_FIXED_BUF_POOLS > 7) 214 UINT8 *bufpool7; 215#endif 216 217#if (GKI_NUM_FIXED_BUF_POOLS > 8) 218 UINT8 *bufpool8; 219#endif 220 221#if (GKI_NUM_FIXED_BUF_POOLS > 9) 222 UINT8 *bufpool9; 223#endif 224 225#if (GKI_NUM_FIXED_BUF_POOLS > 10) 226 UINT8 *bufpool10; 227#endif 228 229#if (GKI_NUM_FIXED_BUF_POOLS > 11) 230 UINT8 *bufpool11; 231#endif 232 233#if (GKI_NUM_FIXED_BUF_POOLS > 12) 234 UINT8 *bufpool12; 235#endif 236 237#if (GKI_NUM_FIXED_BUF_POOLS > 13) 238 UINT8 *bufpool13; 239#endif 240 241#if (GKI_NUM_FIXED_BUF_POOLS > 14) 242 UINT8 *bufpool14; 243#endif 244 245#if (GKI_NUM_FIXED_BUF_POOLS > 15) 246 UINT8 *bufpool15; 247#endif 248 249#endif 250 251 UINT8 *OSStack[GKI_MAX_TASKS]; /* pointer to beginning of stack */ 252 UINT16 OSStackSize[GKI_MAX_TASKS]; /* stack size available to each task */ 253 254 255 INT8 *OSTName[GKI_MAX_TASKS]; /* name of the task */ 256 257 UINT8 OSRdyTbl[GKI_MAX_TASKS]; /* current state of the task */ 258 UINT16 OSWaitEvt[GKI_MAX_TASKS]; /* events that have to be processed by the task */ 259 UINT16 OSWaitForEvt[GKI_MAX_TASKS]; /* events the task is waiting for*/ 260 261 UINT32 OSTicks; /* system ticks from start */ 262 UINT32 OSIdleCnt; /* idle counter */ 263 INT16 OSDisableNesting; /* counter to keep track of interrupt disable nesting */ 264 INT16 OSLockNesting; /* counter to keep track of sched lock nesting */ 265 INT16 OSIntNesting; /* counter to keep track of interrupt nesting */ 266 267 /* Timer related variables 268 */ 269 INT32 OSTicksTilExp; /* Number of ticks till next timer expires */ 270#if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) 271 UINT32 OSTicksTilStop; /* inactivity delay timer; OS Ticks till stopping system tick */ 272#endif 273 INT32 OSNumOrigTicks; /* Number of ticks between last timer expiration to the next one */ 274 275 INT32 OSWaitTmr [GKI_MAX_TASKS]; /* ticks the task has to wait, for specific events */ 276 277 /* Only take up space timers used in the system (GKI_NUM_TIMERS defined in target.h) */ 278#if (GKI_NUM_TIMERS > 0) 279 INT32 OSTaskTmr0 [GKI_MAX_TASKS]; 280 INT32 OSTaskTmr0R [GKI_MAX_TASKS]; 281#endif 282 283#if (GKI_NUM_TIMERS > 1) 284 INT32 OSTaskTmr1 [GKI_MAX_TASKS]; 285 INT32 OSTaskTmr1R [GKI_MAX_TASKS]; 286#endif 287 288#if (GKI_NUM_TIMERS > 2) 289 INT32 OSTaskTmr2 [GKI_MAX_TASKS]; 290 INT32 OSTaskTmr2R [GKI_MAX_TASKS]; 291#endif 292 293#if (GKI_NUM_TIMERS > 3) 294 INT32 OSTaskTmr3 [GKI_MAX_TASKS]; 295 INT32 OSTaskTmr3R [GKI_MAX_TASKS]; 296#endif 297 298 299 300 /* Buffer related variables 301 */ 302 BUFFER_HDR_T *OSTaskQFirst[GKI_MAX_TASKS][NUM_TASK_MBOX]; /* array of pointers to the first event in the task mailbox */ 303 BUFFER_HDR_T *OSTaskQLast [GKI_MAX_TASKS][NUM_TASK_MBOX]; /* array of pointers to the last event in the task mailbox */ 304 305 /* Define the buffer pool management variables 306 */ 307 FREE_QUEUE_T freeq[GKI_NUM_TOTAL_BUF_POOLS]; 308 309 UINT16 pool_buf_size[GKI_NUM_TOTAL_BUF_POOLS]; 310 UINT16 pool_max_count[GKI_NUM_TOTAL_BUF_POOLS]; 311 UINT16 pool_additions[GKI_NUM_TOTAL_BUF_POOLS]; 312 313 /* Define the buffer pool start addresses 314 */ 315 UINT8 *pool_start[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the start of each buffer pool */ 316 UINT8 *pool_end[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the end of each buffer pool */ 317 UINT16 pool_size[GKI_NUM_TOTAL_BUF_POOLS]; /* actual size of the buffers in a pool */ 318 319 /* Define the buffer pool access control variables */ 320 void *p_user_mempool; /* User O/S memory pool */ 321 UINT16 pool_access_mask; /* Bits are set if the corresponding buffer pool is a restricted pool */ 322 UINT8 pool_list[GKI_NUM_TOTAL_BUF_POOLS]; /* buffer pools arranged in the order of size */ 323 UINT8 curr_total_no_of_pools; /* number of fixed buf pools + current number of dynamic pools */ 324 325 BOOLEAN timer_nesting; /* flag to prevent timer interrupt nesting */ 326 327 /* Time queue arrays */ 328 TIMER_LIST_Q *timer_queues[GKI_MAX_TIMER_QUEUES]; 329 /* System tick callback */ 330 SYSTEM_TICK_CBACK *p_tick_cb; 331 BOOLEAN system_tick_running; /* TRUE if system tick is running. Valid only if p_tick_cb is not NULL */ 332 333#if (GKI_DEBUG == TRUE) 334 UINT16 ExceptionCnt; /* number of GKI exceptions that have happened */ 335 EXCEPTION_T Exception[GKI_MAX_EXCEPTION]; 336#endif 337 338} tGKI_COM_CB; 339 340 341#ifdef __cplusplus 342extern "C" { 343#endif 344 345/* Internal GKI function prototypes 346*/ 347GKI_API extern BOOLEAN gki_chk_buf_damage(void *); 348extern BOOLEAN gki_chk_buf_owner(void *); 349extern void gki_buffer_init (void); 350extern void gki_timers_init(void); 351extern void gki_adjust_timer_count (INT32); 352 353#ifdef GKI_USE_DEFERED_ALLOC_BUF_POOLS 354extern void gki_dealloc_free_queue(void); 355#endif 356 357extern void OSStartRdy(void); 358extern void OSCtxSw(void); 359extern void OSIntCtxSw(void); 360extern void OSSched(void); 361extern void OSIntEnter(void); 362extern void OSIntExit(void); 363 364 365/* Debug aids 366*/ 367typedef void (*FP_PRINT)(char *, ...); 368 369#if (GKI_DEBUG == TRUE) 370 371typedef void (*PKT_PRINT)(UINT8 *, UINT16); 372 373extern void gki_print_task(FP_PRINT); 374extern void gki_print_exception(FP_PRINT); 375extern void gki_print_timer(FP_PRINT); 376extern void gki_print_stack(FP_PRINT); 377extern void gki_print_buffer(FP_PRINT); 378extern void gki_print_buffer_statistics(FP_PRINT, INT16); 379GKI_API extern void gki_print_used_bufs (FP_PRINT, UINT8); 380extern void gki_dump(UINT8 *, UINT16, FP_PRINT); 381extern void gki_dump2(UINT16 *, UINT16, FP_PRINT); 382extern void gki_dump4(UINT32 *, UINT16, FP_PRINT); 383 384#endif 385 386#ifdef __cplusplus 387} 388#endif 389 390#endif 391