• 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_H
20 #define UWB_GKI_H
21 
22 #include <string>
23 
24 #include "uwb_gki_target.h"
25 #include "uwb_target.h"
26 
27 /* Error codes */
28 #define GKI_SUCCESS 0x00
29 #define GKI_FAILURE 0x01
30 #define GKI_INVALID_TASK 0xF0
31 #define GKI_INVALID_POOL 0xFF
32 
33 /************************************************************************
34 ** Mailbox definitions. Each task has 4 mailboxes that are used to
35 ** send buffers to the task.
36 */
37 #define TASK_MBOX_0 0
38 #define TASK_MBOX_2 2
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 
50 #define TASK_MBOX_0_EVT_MASK 0x0001
51 #define TASK_MBOX_1_EVT_MASK 0x0002
52 #define TASK_MBOX_2_EVT_MASK 0x0004
53 #define TASK_MBOX_3_EVT_MASK 0x0008
54 
55 #define TIMER_0 0
56 #define TIMER_1 1
57 #define TIMER_2 2
58 #define TIMER_3 3
59 
60 #define TIMER_0_EVT_MASK 0x0010
61 #define TIMER_1_EVT_MASK 0x0020
62 #define TIMER_2_EVT_MASK 0x0040
63 #define TIMER_3_EVT_MASK 0x0080
64 
65 #define APPL_EVT_0 8
66 #define APPL_EVT_7 15
67 
68 #define EVENT_MASK(evt) ((uint16_t)(0x0001 << (evt)))
69 
70 /************************************************************************
71 **  Max Time Queue
72 **/
73 #ifndef GKI_MAX_TIMER_QUEUES
74 #define GKI_MAX_TIMER_QUEUES 3
75 #endif
76 
77 /************************************************************************
78 **  Utility macros for timer conversion
79 **/
80 #ifdef TICKS_PER_SEC
81 #define GKI_MS_TO_TICKS(x) ((x) / (1000 / TICKS_PER_SEC))
82 #define GKI_SECS_TO_TICKS(x) ((x) * (TICKS_PER_SEC))
83 #define GKI_TICKS_TO_MS(x) ((x) * (1000 / TICKS_PER_SEC))
84 #define GKI_TICKS_TO_SECS(x) ((x) * (1 / TICKS_PER_SEC))
85 #endif
86 
87 #ifndef GKI_SHUTDOWN_EVT
88 #define GKI_SHUTDOWN_EVT APPL_EVT_7
89 #endif
90 
91 /* Timer list entry callback type
92  */
93 struct TIMER_LIST_ENT;
94 typedef void(TIMER_CBACK)(TIMER_LIST_ENT* p_tle);
95 
96 /* Define a timer list entry
97  */
98 struct TIMER_LIST_ENT {
99   TIMER_LIST_ENT* p_next;
100   TIMER_LIST_ENT* p_prev;
101   TIMER_CBACK* p_cback;
102   int32_t ticks;
103   uintptr_t param;
104   uint16_t event;
105   uint8_t in_use;
106 };
107 
108 /* Define a timer list queue
109  */
110 typedef struct {
111   TIMER_LIST_ENT* p_first;
112   TIMER_LIST_ENT* p_last;
113   int32_t last_ticks;
114 } TIMER_LIST_Q;
115 
116 /***********************************************************************
117 ** This queue is a general purpose buffer queue, for application use.
118 */
119 typedef struct {
120   void* p_first;
121   void* p_last;
122   uint16_t count;
123 } BUFFER_Q;
124 
125 /* Task constants
126  */
127 #ifndef TASKPTR
128 typedef uint32_t (*TASKPTR)(uint32_t);
129 #endif
130 
131 /* General pool accessible to GKI_getbuf() */
132 #define GKI_RESTRICTED_POOL 1 /* Inaccessible pool to GKI_getbuf() */
133 
134 /***********************************************************************
135 ** Function prototypes
136 */
137 
138 /* Task management
139  */
140 extern uint8_t phUwb_GKI_create_task(TASKPTR, uint8_t, int8_t*, uint16_t*,
141                                      uint16_t, void*, void*);
142 extern void phUwb_GKI_exit_task(uint8_t);
143 extern uint8_t phUwb_GKI_get_taskid(void);
144 extern void phUwb_GKI_init(void);
145 extern void phUwb_GKI_run(void*);
146 
147 /* To send buffers and events between tasks
148  */
149 extern uint8_t phUwb_GKI_isend_event(uint8_t, uint16_t);
150 extern void* phUwb_GKI_read_mbox(uint8_t);
151 extern void phUwb_GKI_send_msg(uint8_t, uint8_t, void*);
152 extern uint8_t phUwb_GKI_send_event(uint8_t, uint16_t);
153 
154 /* To get and release buffers, change owner and get size
155  */
156 extern void phUwb_GKI_freebuf(void*);
157 extern void* phUwb_GKI_getbuf(uint16_t);
158 extern uint16_t phUwb_GKI_get_buf_size(void*);
159 extern void* phUwb_GKI_getpoolbuf(uint8_t);
160 
161 /* User buffer queue management
162  */
163 extern void* phUwb_GKI_dequeue(BUFFER_Q*);
164 extern void phUwb_GKI_enqueue(BUFFER_Q*, void*);
165 extern void phUwb_GKI_init_q(BUFFER_Q*);
166 
167 /* Timer management
168  */
169 extern void phUwb_GKI_add_to_timer_list(TIMER_LIST_Q*, TIMER_LIST_ENT*);
170 extern uint32_t phUwb_GKI_get_tick_count(void);
171 extern void phUwb_GKI_init_timer_list(TIMER_LIST_Q*);
172 extern void phUwb_GKI_remove_from_timer_list(TIMER_LIST_Q*, TIMER_LIST_ENT*);
173 extern void phUwb_GKI_start_timer(uint8_t, int32_t, bool);
174 extern void phUwb_GKI_stop_timer(uint8_t, int);
175 extern void phUwb_GKI_timer_update(uint32_t);
176 extern uint16_t phUwb_GKI_update_timer_list(TIMER_LIST_Q*, uint32_t);
177 extern uint32_t phUwb_GKI_get_remaining_ticks(TIMER_LIST_Q*, TIMER_LIST_ENT*);
178 extern uint16_t phUwb_GKI_wait(uint16_t, uint32_t);
179 
180 /* Start and Stop system time tick callback
181  * true for start system tick if time queue is not empty
182  * false to stop system tick if time queue is empty
183  */
184 typedef void(SYSTEM_TICK_CBACK)(bool);
185 
186 /* Time queue management for system ticks
187  */
188 extern void phUwb_GKI_timer_queue_register_callback(SYSTEM_TICK_CBACK*);
189 
190 /* Disable Interrupts, Enable Interrupts
191  */
192 extern void phUwb_GKI_enable(void);
193 extern void phUwb_GKI_disable(void);
194 
195 /* Allocate (Free) memory from an OS
196  */
197 extern void* phUwb_GKI_os_malloc(uint32_t);
198 extern void phUwb_GKI_os_free(void*);
199 
200 /* Exception handling
201  */
202 extern void phUwb_GKI_exception(uint16_t, std::string);
203 
204 #endif
205