• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 1999-2012 Broadcom Corporation
4  *  Copyright 2019 NXP
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 #ifndef UWB_GKI_COMMON_H
20 #define UWB_GKI_COMMON_H
21 
22 #include "uwb_gki.h"
23 
24 /* Task States: (For OSRdyTbl) */
25 #define TASK_DEAD 0  /* b0000 */
26 #define TASK_READY 1 /* b0001 */
27 
28 /********************************************************************
29 **  Internal Error codes
30 *********************************************************************/
31 #define GKI_ERROR_BUF_CORRUPTED 0xFFFF
32 #define GKI_ERROR_NOT_BUF_OWNER 0xFFFE
33 #define GKI_ERROR_FREEBUF_BAD_QID 0xFFFD
34 #define GKI_ERROR_FREEBUF_BUF_LINKED 0xFFFC
35 #define GKI_ERROR_SEND_MSG_BAD_DEST 0xFFFB
36 #define GKI_ERROR_SEND_MSG_BUF_LINKED 0xFFFA
37 #define GKI_ERROR_ENQUEUE_BUF_LINKED 0xFFF9
38 #define GKI_ERROR_DELETE_POOL_BAD_QID 0xFFF8
39 #define GKI_ERROR_BUF_SIZE_TOOBIG 0xFFF7
40 #define GKI_ERROR_BUF_SIZE_ZERO 0xFFF6
41 
42 /********************************************************************
43 **  Misc constants
44 *********************************************************************/
45 
46 #define GKI_MAX_INT32 (0x7fffffffL)
47 
48 /********************************************************************
49 **  Buffer Management Data Structures
50 *********************************************************************/
51 
52 typedef struct _buffer_hdr {
53   struct _buffer_hdr* p_next; /* next buffer in the queue */
54   uint8_t q_id;               /* id of the queue */
55   uint8_t task_id;            /* task which allocated the buffer*/
56   uint8_t status;             /* FREE, UNLINKED or QUEUED */
57   uint8_t Type;
58 } BUFFER_HDR_T;
59 
60 typedef struct _free_queue {
61   BUFFER_HDR_T* p_first; /* first buffer in the queue */
62   BUFFER_HDR_T* p_last;  /* last buffer in the queue */
63   uint16_t size;         /* size of the buffers in the pool */
64   uint16_t total;        /* toatal number of buffers */
65   uint16_t cur_cnt;      /* number of  buffers currently allocated */
66   uint16_t max_cnt;      /* maximum number of buffers allocated at any time */
67 } FREE_QUEUE_T;
68 
69 /* Buffer related defines
70  */
71 #define ALIGN_POOL(pl_size) \
72   ((((pl_size) + 3) / sizeof(uint32_t)) * sizeof(uint32_t))
73 /* Offset past header */
74 #define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T))
75 /* Header + Magic Number */
76 #define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(uint32_t))
77 /* pool size must allow for header */
78 #define MAX_USER_BUF_SIZE ((uint16_t)0xffff - BUFFER_PADDING_SIZE)
79 #define MAGIC_NO 0xDDBADDBA
80 
81 #define BUF_STATUS_FREE 0
82 #define BUF_STATUS_UNLINKED 1
83 #define BUF_STATUS_QUEUED 2
84 
85 /* Put all GKI variables into one control block
86  */
87 typedef struct {
88   /* Task management variables
89    */
90   /* The stack and stack size are not used on Windows
91    */
92 
93 #if (GKI_NUM_FIXED_BUF_POOLS > 0)
94   uint8_t bufpool0[(ALIGN_POOL(GKI_BUF0_SIZE) + BUFFER_PADDING_SIZE) *
95                    GKI_BUF0_MAX];
96 #endif
97 
98 #if (GKI_NUM_FIXED_BUF_POOLS > 1)
99   uint8_t bufpool1[(ALIGN_POOL(GKI_BUF1_SIZE) + BUFFER_PADDING_SIZE) *
100                    GKI_BUF1_MAX];
101 #endif
102 
103 #if (GKI_NUM_FIXED_BUF_POOLS > 2)
104   uint8_t bufpool2[(ALIGN_POOL(GKI_BUF2_SIZE) + BUFFER_PADDING_SIZE) *
105                    GKI_BUF2_MAX];
106 #endif
107 
108 #if (GKI_NUM_FIXED_BUF_POOLS > 3)
109   uint8_t bufpool3[(ALIGN_POOL(GKI_BUF3_SIZE) + BUFFER_PADDING_SIZE) *
110                    GKI_BUF3_MAX];
111 #endif
112 
113   uint8_t* OSStack[GKI_MAX_TASKS];     /* pointer to beginning of stack */
114   uint16_t OSStackSize[GKI_MAX_TASKS]; /* stack size available to each task */
115 
116   int8_t* OSTName[GKI_MAX_TASKS]; /* name of the task */
117 
118   uint8_t OSRdyTbl[GKI_MAX_TASKS];   /* current state of the task */
119   uint16_t OSWaitEvt[GKI_MAX_TASKS]; /* events that have to be processed by the
120                                         task */
121   uint16_t OSWaitForEvt[GKI_MAX_TASKS]; /* events the task is waiting for*/
122 
123   uint32_t OSTicks;   /* system ticks from start */
124   uint32_t OSIdleCnt; /* idle counter */
125   int16_t
126       OSDisableNesting; /* counter to keep track of interrupt disable nesting */
127   int16_t OSLockNesting; /* counter to keep track of sched lock nesting */
128   int16_t OSIntNesting;  /* counter to keep track of interrupt nesting */
129 
130   /* Timer related variables
131    */
132   int32_t OSTicksTilExp; /* Number of ticks till next timer expires */
133 #if (GKI_DELAY_STOP_SYS_TICK > 0)
134   uint32_t OSTicksTilStop; /* inactivity delay timer; OS Ticks till stopping
135                               system tick */
136 #endif
137   int32_t OSNumOrigTicks; /* Number of ticks between last timer expiration to
138                              the next one */
139 
140   int32_t OSWaitTmr[GKI_MAX_TASKS]; /* ticks the task has to wait, for specific
141                                        events */
142 
143 /* Only take up space timers used in the system (GKI_NUM_TIMERS defined in
144  * target.h) */
145 #if (GKI_NUM_TIMERS > 0)
146   int32_t OSTaskTmr0[GKI_MAX_TASKS];
147   int32_t OSTaskTmr0R[GKI_MAX_TASKS];
148 #endif
149 
150 #if (GKI_NUM_TIMERS > 1)
151   int32_t OSTaskTmr1[GKI_MAX_TASKS];
152   int32_t OSTaskTmr1R[GKI_MAX_TASKS];
153 #endif
154 
155 #if (GKI_NUM_TIMERS > 2)
156   int32_t OSTaskTmr2[GKI_MAX_TASKS];
157   int32_t OSTaskTmr2R[GKI_MAX_TASKS];
158 #endif
159 
160 #if (GKI_NUM_TIMERS > 3)
161   int32_t OSTaskTmr3[GKI_MAX_TASKS];
162   int32_t OSTaskTmr3R[GKI_MAX_TASKS];
163 #endif
164 
165   /* Buffer related variables
166    */
167   BUFFER_HDR_T* OSTaskQFirst[GKI_MAX_TASKS]
168                             [NUM_TASK_MBOX]; /* array of pointers to the first
169                                                 event in the task mailbox */
170   BUFFER_HDR_T* OSTaskQLast[GKI_MAX_TASKS]
171                            [NUM_TASK_MBOX]; /* array of pointers to the last
172                                                event in the task mailbox */
173 
174   /* Define the buffer pool management variables
175    */
176   FREE_QUEUE_T freeq[GKI_NUM_TOTAL_BUF_POOLS];
177 
178   uint16_t pool_buf_size[GKI_NUM_TOTAL_BUF_POOLS];
179   uint16_t pool_max_count[GKI_NUM_TOTAL_BUF_POOLS];
180   uint16_t pool_additions[GKI_NUM_TOTAL_BUF_POOLS];
181 
182   /* Define the buffer pool start addresses
183    */
184   uint8_t* pool_start[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the
185                                                    start of each buffer pool */
186   uint8_t* pool_end[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the end of
187                                                  each buffer pool */
188   uint16_t pool_size[GKI_NUM_TOTAL_BUF_POOLS]; /* actual size of the buffers in
189                                                   a pool */
190 
191   /* Define the buffer pool access control variables */
192   void* p_user_mempool;      /* User O/S memory pool */
193   uint16_t pool_access_mask; /* Bits are set if the corresponding buffer pool is
194                                 a restricted pool */
195   uint8_t pool_list[GKI_NUM_TOTAL_BUF_POOLS]; /* buffer pools arranged in the
196                                                  order of size */
197   uint8_t curr_total_no_of_pools; /* number of fixed buf pools + current number
198                                      of dynamic pools */
199 
200   bool timer_nesting; /* flag to prevent timer interrupt nesting */
201 
202   /* Time queue arrays */
203   TIMER_LIST_Q* timer_queues[GKI_MAX_TIMER_QUEUES];
204   /* System tick callback */
205   SYSTEM_TICK_CBACK* p_tick_cb;
206   bool system_tick_running; /* TRUE if system tick is running. Valid only if
207                                p_tick_cb is not NULL */
208 
209 } tGKI_COM_CB;
210 
211 /* Internal GKI function prototypes
212  */
213 extern bool phUwb_gki_chk_buf_damage(void*);
214 extern void phUwb_gki_buffer_init(void);
215 extern void phUwb_gki_timers_init(void);
216 extern void phUwb_gki_adjust_timer_count(int32_t);
217 
218 #endif
219