1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Port Specific                                                       */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  PORT SPECIFIC C INFORMATION                            RELEASE        */
26 /*                                                                        */
27 /*    ux_port.h                                            Generic        */
28 /*                                                           6.3.0        */
29 /*                                                                        */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Chaoqiong Xiao, Microsoft Corporation                               */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file contains data type definitions that make USBX function    */
37 /*    identically on a variety of different processor architectures.      */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  12-31-2020     Chaoqiong Xiao           Initial Version 6.1.3         */
44 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
45 /*                                            moved tx_api.h include and  */
46 /*                                            typedefs from ux_api.h,     */
47 /*                                            resulting in version 6.1.10 */
48 /*  10-31-2023     Chaoqiong Xiao           Modified comment(s),          */
49 /*                                            added basic types guards,   */
50 /*                                            improved SLONG typedef,     */
51 /*                                            resulting in version 6.3.0  */
52 /*                                                                        */
53 /**************************************************************************/
54 
55 #ifndef UX_PORT_H
56 #define UX_PORT_H
57 
58 
59 /* Determine if the optional USBX user define file should be used.  */
60 
61 #ifdef UX_INCLUDE_USER_DEFINE_FILE
62 
63 
64 /* Yes, include the user defines in ux_user.h. The defines in this file may
65    alternately be defined on the command line.  */
66 
67 #include "ux_user.h"
68 #endif
69 
70 
71 /* Include library header files.  */
72 
73 #include <stdio.h>
74 #include <string.h>
75 
76 
77 #if !defined(UX_STANDALONE)
78 #include "tx_api.h"
79 #else
80 
81 /* VAR types used in UX,
82    if TX still used, expects tx_api.h included before include this.  */
83 #if !defined(TX_API_H) && !defined(TX_PORT_H)
84 
85 #include <stdint.h>
86 
87 #ifndef VOID
88 #define VOID                                      void
89 typedef char                                      CHAR;
90 typedef unsigned char                             UCHAR;
91 typedef int                                       INT;
92 typedef unsigned int                              UINT;
93 typedef long                                      LONG;
94 typedef unsigned long                             ULONG;
95 typedef short                                     SHORT;
96 typedef unsigned short                            USHORT;
97 #endif
98 
99 #ifndef ULONG64_DEFINED
100 typedef uint64_t                                ULONG64;
101 #define ULONG64_DEFINED
102 #endif
103 
104 #ifndef ALIGN_TYPE_DEFINED
105 #define ALIGN_TYPE                              ULONG
106 #define ALIGN_TYPE_DEFINED
107 #endif
108 
109 #endif
110 #endif
111 
112 
113 /* CPU definition for X86 systems without preemptive timer function.
114    This will make USBX uses the controller for the timer. */
115 
116 #undef THREADX_X86_NO_PTIMER
117 
118 
119 /* For X86 systems, the define #define UX_USE_IO_INSTRUCTIONS should be used.  */
120 
121 
122 /* Define additional generic USBX types.  */
123 
124 #ifndef SLONG_DEFINED
125 typedef LONG                        SLONG;
126 #define SLONG_DEFINED
127 #endif
128 
129 
130 /*  Generic USBX Project constants follow.  */
131 
132 #ifndef UX_PERIODIC_RATE
133 #define UX_PERIODIC_RATE                                    100
134 #endif
135 
136 #ifndef UX_MAX_CLASS_DRIVER
137 #define UX_MAX_CLASS_DRIVER                                 2
138 #endif
139 
140 #ifndef UX_MAX_SLAVE_CLASS_DRIVER
141 #define UX_MAX_SLAVE_CLASS_DRIVER                           2
142 #endif
143 
144 #ifndef UX_MAX_HCD
145 #define UX_MAX_HCD                                          1
146 #endif
147 
148 #ifndef UX_MAX_DEVICES
149 #define UX_MAX_DEVICES                                      2
150 #endif
151 
152 #ifndef UX_MAX_ED
153 #define UX_MAX_ED                                           80
154 #endif
155 
156 #ifndef UX_MAX_TD
157 #define UX_MAX_TD                                           32
158 #endif
159 
160 #ifndef UX_MAX_ISO_TD
161 #define UX_MAX_ISO_TD                                       2
162 #endif
163 
164 #ifndef UX_HOST_ENUM_THREAD_STACK_SIZE
165 #define UX_HOST_ENUM_THREAD_STACK_SIZE                      (2*1024)
166 #endif
167 
168 #ifndef UX_THREAD_STACK_SIZE
169 #define UX_THREAD_STACK_SIZE                                (1*1024)
170 #endif
171 
172 #ifndef UX_THREAD_PRIORITY_ENUM
173 #define UX_THREAD_PRIORITY_ENUM                             20
174 #endif
175 
176 #ifndef UX_THREAD_PRIORITY_CLASS
177 #define UX_THREAD_PRIORITY_CLASS                            20
178 #endif
179 
180 #ifndef UX_THREAD_PRIORITY_KEYBOARD
181 #define UX_THREAD_PRIORITY_KEYBOARD                         20
182 #endif
183 
184 #ifndef UX_THREAD_PRIORITY_HCD
185 #define UX_THREAD_PRIORITY_HCD                              2
186 #endif
187 
188 #ifndef UX_THREAD_PRIORITY_DCD
189 #define UX_THREAD_PRIORITY_DCD                              2
190 #endif
191 
192 #ifndef UX_NO_TIME_SLICE
193 #define UX_NO_TIME_SLICE                                    0
194 #endif
195 
196 #ifndef UX_MAX_SLAVE_LUN
197 #define UX_MAX_SLAVE_LUN                                    1
198 #endif
199 
200 #ifndef UX_MAX_HOST_LUN
201 #define UX_MAX_HOST_LUN                                     1
202 #endif
203 
204 #ifndef UX_HOST_CLASS_STORAGE_MAX_MEDIA
205 #define UX_HOST_CLASS_STORAGE_MAX_MEDIA                     1
206 #endif
207 
208 #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH
209 #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH                 256
210 #endif
211 
212 
213 #ifndef UX_SLAVE_REQUEST_DATA_MAX_LENGTH
214 #define UX_SLAVE_REQUEST_DATA_MAX_LENGTH                    2048
215 #endif
216 
217 #ifndef UX_USE_IO_INSTRUCTIONS
218 
219 /* Don't use IO instructions if this define is not set.  Default to memory mapped.  */
220 
221 #define inpb(a)                                            *((UCHAR *)  (a))
222 #define inpw(a)                                            *((USHORT *) (a))
223 #define inpl(a)                                            *((ULONG *)  (a))
224 #define outpb(a, b)                                        *((UCHAR *)  (a)) =  ((UCHAR)  (b))
225 #define outpw(a, b)                                        *((USHORT *) (a)) =  ((USHORT) (b))
226 #define outpl(a, b)                                        *((ULONG *)  (a)) =  ((ULONG)  (b))
227 #else
228 
229 
230 /* Define simple prototypes for non-memory mapped hardware access.  */
231 
232 UCHAR   inpb(ULONG);
233 USHORT  inpw(ULONG);
234 ULONG   inpl(ULONG);
235 
236 VOID    outpb(ULONG,UCHAR);
237 VOID    outpw(ULONG,USHORT);
238 VOID    outpl(ULONG,ULONG);
239 
240 #endif
241 /* Define local delay function for board specific bsps.  */
242 #ifdef TI_AM335
243     #define UX_BSP_SPECIFIC_DELAY_FUNCTION
244 #endif
245 
246 
247 /* Define interrupt lockout constructs to protect the memory allocation/release which could happen
248    under ISR in the device stack.  */
249 
250 #define UX_INT_SAVE_AREA        unsigned int  old_interrupt_posture;
251 #define UX_DISABLE_INTS         old_interrupt_posture =  tx_interrupt_control(TX_INT_DISABLE);
252 #define UX_RESTORE_INTS         tx_interrupt_control(old_interrupt_posture);
253 
254 
255 /* Define the version ID of USBX.  This may be utilized by the application.  */
256 
257 #ifdef  UX_SYSTEM_INIT
258 CHAR                            _ux_version_id[] =
259                                     "Copyright (c) 2024 Microsoft Corporation. * USBX Generic Version 6.4.1 *";
260 #else
261 extern  CHAR                    _ux_version_id[];
262 #endif
263 
264 #endif
265 
266