1 /* =========================================================================
2  * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
3  * $Revision: #14 $
4  * $Date: 2010/11/04 $
5  * $Change: 1621695 $
6  *
7  * Synopsys Portability Library Software and documentation
8  * (hereinafter, "Software") is an Unsupported proprietary work of
9  * Synopsys, Inc. unless otherwise expressly agreed to in writing
10  * between Synopsys and you.
11  *
12  * The Software IS NOT an item of Licensed Software or Licensed Product
13  * under any End User Software License Agreement or Agreement for
14  * Licensed Product with Synopsys or any supplement thereto. You are
15  * permitted to use and redistribute this Software in source and binary
16  * forms, with or without modification, provided that redistributions
17  * of source code must retain this notice. You may not view, use,
18  * disclose, copy or distribute this file or any information contained
19  * herein except pursuant to this license grant from Synopsys. If you
20  * do not agree with this notice, including the disclaimer below, then
21  * you are not authorized to use the Software.
22  *
23  * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
24  * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
27  * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
33  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
34  * DAMAGE.
35  * ========================================================================= */
36 #ifndef _DWC_OS_H_
37 #define _DWC_OS_H_
38 
39 #include "basic_types.h"
40 //#include "va_list.h"
41 #include <stdarg.h>
42 
43 #include "diag.h"
44 #include "dwc_otg_dbg.h"
45 #include "freertos_service.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 extern
51 _LONG_CALL_ u32
52 DiagPrintf(
53     IN  const char *fmt, ...
54 );
55 
56 #define DBG_8195A_OTG(...)  do{\
57 	if (ConfigDebug[LEVEL_INFO] & BIT(MODULE_USB_OTG)) \
58 		DiagPrintf("\r" __VA_ARGS__);\
59 	}while(0)
60 
61 #define DBG_8195A_OTG_INFO(...)  do{\
62 	if (ConfigDebug[LEVEL_INFO] & BIT(MODULE_USB_OTG)) \
63 		DiagPrintf("\r" __VA_ARGS__);\
64 	}while(0)
65 
66 #define DBG_8195A_OTG_WARN(...)  do{\
67 	if (ConfigDebug[LEVEL_WARN] & BIT(MODULE_USB_OTG)) \
68 		DiagPrintf("\r" __VA_ARGS__);\
69 	}while(0)
70 
71 #define DBG_8195A_OTG_ERR(...)  do{\
72 	if (ConfigDebug[LEVEL_ERROR] & BIT(MODULE_USB_OTG)) \
73 		DiagPrintf("\r" __VA_ARGS__);\
74 	}while(0)
75 
76 #define DBG_8195A_OTG_LVL(LVL,...)  do{\
77     if (ConfigDebug[LEVEL_INFO] & BIT(MODULE_USB_OTG)){ \
78 	DiagPrintf("\rRTL8195A[OTG_LVL_%2x]: ",LVL);\
79 	DiagPrintf(__VA_ARGS__);\
80     }\
81 }while(0)
82 
83 /** @file
84  *
85  * DWC portability library, low level os-wrapper functions
86  *
87  */
88 
89 /* These basic types need to be defined by some OS header file or custom header
90  * file for your specific target architecture.
91  *
92  * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
93  *
94  * Any custom or alternate header file must be added and enabled here.
95  */
96 #if 0//8195A_PORTING
97 #else
98 #define DWC_OS_PORTING   1
99 #endif
100 
101 #include "usb_errno.h"
102 
103 /** @name Primitive Types and Values */
104 
105 /** We define a boolean type for consistency.  Can be either YES or NO */
106 typedef uint8_t dwc_bool_t;
107 #define YES  1
108 #define NO   0
109 
110 /** Compile Flag Definition */
111 #define __OTG_LITTLE_ENDIAN
112 #undef  DWC_CRYPTOLIB
113 #undef  DWC_DEBUG_REGS
114 #undef  DWC_DEBUG_MEMORY
115 #undef  DWC_UTFLIB
116 #undef  CONFIG_DEBUG_MUTEXES
117 #define DWC_WITH_WLAN_OSDEP 1
118 
119 
120 #ifdef DWC_OS_PORTING
121 
122 /** @name Error Codes */
123 #define DWC_E_INVALID		EINVAL
124 #define DWC_E_NO_MEMORY		ENOMEM
125 #define DWC_E_NO_DEVICE		ENODEV
126 #define DWC_E_NOT_SUPPORTED	EOPNOTSUPP
127 #define DWC_E_TIMEOUT		ETIMEDOUT
128 #define DWC_E_BUSY		EBUSY
129 #define DWC_E_AGAIN		EAGAIN
130 #define DWC_E_RESTART		ERESTART
131 #define DWC_E_ABORT		ECONNABORTED
132 #define DWC_E_SHUTDOWN		ESHUTDOWN
133 #define DWC_E_NO_DATA		ENODATA
134 #define DWC_E_DISCONNECT	ECONNRESET
135 #define DWC_E_UNKNOWN		EINVAL
136 #define DWC_E_NO_STREAM_RES	ENOSR
137 #define DWC_E_COMMUNICATION	ECOMM
138 #define DWC_E_OVERFLOW		EOVERFLOW
139 #define DWC_E_PROTOCOL		EPROTO
140 #define DWC_E_IN_PROGRESS	EINPROGRESS
141 #define DWC_E_PIPE		EPIPE
142 #define DWC_E_IO		EIO
143 #define DWC_E_NO_SPACE		ENOSPC
144 
145 #else
146 
147 /** @name Error Codes */
148 #define DWC_E_INVALID		1001
149 #define DWC_E_NO_MEMORY		1002
150 #define DWC_E_NO_DEVICE		1003
151 #define DWC_E_NOT_SUPPORTED	1004
152 #define DWC_E_TIMEOUT		1005
153 #define DWC_E_BUSY		1006
154 #define DWC_E_AGAIN		1007
155 #define DWC_E_RESTART		1008
156 #define DWC_E_ABORT		1009
157 #define DWC_E_SHUTDOWN		1010
158 #define DWC_E_NO_DATA		1011
159 #define DWC_E_DISCONNECT	2000
160 #define DWC_E_UNKNOWN		3000
161 #define DWC_E_NO_STREAM_RES	4001
162 #define DWC_E_COMMUNICATION	4002
163 #define DWC_E_OVERFLOW		4003
164 #define DWC_E_PROTOCOL		4004
165 #define DWC_E_IN_PROGRESS	4005
166 #define DWC_E_PIPE		4006
167 #define DWC_E_IO		4007
168 #define DWC_E_NO_SPACE		4008
169 
170 #endif
171 
172 
173 /** @name Tracing/Logging Functions
174  *
175  * These function provide the capability to add tracing, debugging, and error
176  * messages, as well exceptions as assertions.  The WUDEV uses these
177  * extensively.  These could be logged to the main console, the serial port, an
178  * internal buffer, etc.  These functions could also be no-op if they are too
179  * expensive on your system.  By default undefining the DEBUG macro already
180  * no-ops some of these functions. */
181 
182 /** Returns non-zero if in interrupt context. */
183 extern _LONG_CALL_ dwc_bool_t DWC_IN_IRQ(void);
184 #define dwc_in_irq DWC_IN_IRQ
185 
186 /** Returns "IRQ" if DWC_IN_IRQ is true. */
187 extern _LONG_CALL_ char *dwc_irq(void);
188 
189 /** Returns non-zero if in bottom-half context. */
190 extern _LONG_CALL_ dwc_bool_t DWC_IN_BH(void);
191 #define dwc_in_bh DWC_IN_BH
192 
193 /** Returns "BH" if DWC_IN_BH is true. */
194 extern _LONG_CALL_ char *dwc_bh(void);
195 
196 /**
197  * A vprintf() clone.  Just call vprintf if you've got it.
198  */
199 #if 0
200 extern void DWC_VPRINTF(char *format, va_list args);
201 #define dwc_vprintf DWC_VPRINTF
202 #endif
203 /**
204  * A vsnprintf() clone.  Just call vprintf if you've got it.
205  */
206 extern _LONG_CALL_ int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
207 #define dwc_vsnprintf DWC_VSNPRINTF
208 
209 /**
210  * printf() clone.  Just call printf if you've go it.
211  */
212 #ifdef OTGDEBUG
213 #define DWC_PRINTF(format...) do{ DBG_8195A_OTG(format); }while(0)
214 #else
215 #define DWC_PRINTF(format...)
216 #endif
217 
218 //extern void DWC_PRINTF(char *format, ...)
219 /* This provides compiler level static checking of the parameters if you're
220  * using GCC. */
221 #if 0
222 #ifdef __GNUC__
223 	__attribute__ ((format(printf, 1, 2)));
224 #else
225 	;
226 #endif
227 #endif
228 #define dwc_printf DWC_PRINTF
229 
230 /**
231  * sprintf() clone.  Just call sprintf if you've got it.
232  */
233 extern _LONG_CALL_ int DWC_SPRINTF(char *string, char *format, ...)
234 #if 0//def __GNUC__
235 	__attribute__ ((format(prvDiagPrintf, 2, 3)));
236 #else
237 	;
238 #endif
239 #define dwc_sprintf DWC_SPRINTF
240 
241 /**
242  * snprintf() clone.  Just call snprintf if you've got it.
243  */
244 extern _LONG_CALL_ int DWC_SNPRINTF(char *string, int size, char *format, ...)
245 #if 0//def __GNUC__
246 	__attribute__ ((format(prvDiagPrintf, 3, 4)));
247 #else
248 	;
249 #endif
250 #define dwc_snprintf DWC_SNPRINTF
251 
252 /**
253  * Prints a WARNING message.  On systems that don't differentiate between
254  * warnings and regular log messages, just print it.  Indicates that something
255  * may be wrong with the driver.  Works like printf().
256  *
257  * Use the DWC_WARN macro to call this function.
258  */
259 extern _LONG_CALL_ void __DWC_WARN(char *format, ...)
260 #if 0//def __GNUC__
261 	__attribute__ ((format(prvDiagPrintf, 1, 2)));
262 #else
263 	;
264 #endif
265 
266 /**
267  * Prints an error message.  On systems that don't differentiate between errors
268  * and regular log messages, just print it.  Indicates that something went wrong
269  * with the driver.  Works like printf().
270  *
271  * Use the DWC_ERROR macro to call this function.
272  */
273 extern _LONG_CALL_ void __DWC_ERROR(char *format, ...)
274 #if 0//def __GNUC__
275 	__attribute__ ((format(prvDiagPrintf, 1, 2)));
276 #else
277 	;
278 #endif
279 
280 /**
281  * Prints an exception error message and takes some user-defined action such as
282  * print out a backtrace or trigger a breakpoint.  Indicates that something went
283  * abnormally wrong with the driver such as programmer error, or other
284  * exceptional condition.  It should not be ignored so even on systems without
285  * printing capability, some action should be taken to notify the developer of
286  * it.  Works like printf().
287  */
288 extern _LONG_CALL_ void DWC_EXCEPTION(char *format, ...)
289 #if 0//def __GNUC__
290 	__attribute__ ((format(prvDiagPrintf, 1, 2)));
291 #else
292 	;
293 #endif
294 #define dwc_exception DWC_EXCEPTION
295 
296 #ifdef OTGDEBUG
297 /**
298  * Prints out a debug message.  Used for logging/trace messages.
299  *
300  * Use the DWC_DEBUG macro to call this function
301  */
302 extern _LONG_CALL_ void __DWC_DEBUG(char *format, ...);
303 #if 0
304 #ifdef __GNUC__
305 	__attribute__ ((format(printf, 1, 2)));
306 #else
307 	;
308 #endif
309 #endif
310 #else
311 #define __DWC_DEBUG(...)
312 #endif
313 
314 /**
315  * Prints out a Debug message.
316  */
317 #define DWC_DEBUG(fmt, args...)		            DBG_8195A_OTG("\n\rDWC_DEBUG:" fmt, ## args)
318 #define dwc_debug DWC_DEBUG
319 /**
320  * Prints out an informative message.
321  */
322 #define DWC_INFO(_format, _args...) DBG_8195A_OTG_INFO("INFO:%s: " _format "\n", \
323 					       dwc_irq(), ## _args)
324 #define dwc_info DWC_INFO
325 /**
326  * Prints out a warning message.
327  */
328 #define DWC_WARN(_format, _args...) DBG_8195A_OTG_WARN("WARN:%s: " _format "\n", \
329 					dwc_irq(), ## _args)
330 #define dwc_warn DWC_WARN
331 /**
332  * Prints out an error message.
333  */
334 #define DWC_ERROR(_format, _args...) DBG_8195A_OTG_ERR("ERROR:%s: " _format "\n", \
335 					dwc_irq(),  ## _args)
336 
337 #define dwc_error DWC_ERROR
338 
339 #define DWC_PROTO_ERROR(_format, _args...) DBG_8195A_OTG_ERR("ERROR:%s: " _format "\n", \
340 						dwc_irq(), ## _args)
341 #define dwc_proto_error DWC_PROTO_ERROR
342 
343 #ifdef OTGDEBUG
344 /** Prints out a exception error message if the _expr expression fails.  Disabled
345  * if DEBUG is not enabled. */
346 #define DWC_ASSERT(_expr, _format, _args...) do { \
347 	if (!(_expr)) { DBG_8195A_OTG("%s: " _format "\n", dwc_irq(), \
348 				       ## _args); } \
349 	} while (0)
350 #else
351 #define DWC_ASSERT(_x...)
352 #endif
353 #define dwc_assert DWC_ASSERT
354 
355 
356 /** @name Byte Ordering
357  * The following functions are for conversions between processor's byte ordering
358  * and specific ordering you want.
359  */
360 
361 /** Converts 32 bit data in CPU byte ordering to little endian. */
362 extern _LONG_CALL_ uint32_t DWC_CPU_TO_LE32(uint32_t *p);
363 #define dwc_cpu_to_le32 DWC_CPU_TO_LE32
364 
365 /** Converts 32 bit data in CPU byte orderint to big endian. */
366 extern _LONG_CALL_ uint32_t DWC_CPU_TO_BE32(uint32_t *p);
367 #define dwc_cpu_to_be32 DWC_CPU_TO_BE32
368 
369 /** Converts 32 bit little endian data to CPU byte ordering. */
370 extern _LONG_CALL_ uint32_t DWC_LE32_TO_CPU(uint32_t *p);
371 #define dwc_le32_to_cpu DWC_LE32_TO_CPU
372 
373 /** Converts 32 bit big endian data to CPU byte ordering. */
374 extern _LONG_CALL_ uint32_t DWC_BE32_TO_CPU(uint32_t *p);
375 #define dwc_be32_to_cpu DWC_BE32_TO_CPU
376 
377 /** Converts 16 bit data in CPU byte ordering to little endian. */
378 extern _LONG_CALL_ uint16_t DWC_CPU_TO_LE16(uint16_t *p);
379 #define dwc_cpu_to_le16 DWC_CPU_TO_LE16
380 
381 /** Converts 16 bit data in CPU byte orderint to big endian. */
382 extern _LONG_CALL_ uint16_t DWC_CPU_TO_BE16(uint16_t *p);
383 #define dwc_cpu_to_be16 DWC_CPU_TO_BE16
384 
385 /** Converts 16 bit little endian data to CPU byte ordering. */
386 extern _LONG_CALL_ uint16_t DWC_LE16_TO_CPU(uint16_t *p);
387 #define dwc_le16_to_cpu DWC_LE16_TO_CPU
388 
389 /** Converts 16 bit bi endian data to CPU byte ordering. */
390 extern _LONG_CALL_ uint16_t DWC_BE16_TO_CPU(uint16_t *p);
391 #define dwc_be16_to_cpu DWC_BE16_TO_CPU
392 
393 
394 /** @name Register Read/Write
395  *
396  * The following six functions should be implemented to read/write registers of
397  * 32-bit and 64-bit sizes.  All modules use this to read/write register values.
398  * The reg value is a pointer to the register calculated from the void *base
399  * variable passed into the driver when it is started.  */
400 
401 
402 /** @cond */
403 
404 /** @name Some convenience MACROS used internally.  Define DWC_DEBUG_REGS to log the
405  * register writes. */
406 
407 #ifdef DWC_OS_PORTING
408 
409 # ifdef DWC_DEBUG_REGS
410 XXXX
411 #define dwc_define_read_write_reg_n(_reg,_container_type) \
412 static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
413 	return DWC_READ_REG32(&container->regs->_reg[num]); \
414 } \
415 static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
416 	DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
417 		  &(((uint32_t*)container->regs->_reg)[num]), data); \
418 	DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
419 }
420 
421 #define dwc_define_read_write_reg(_reg,_container_type) \
422 static inline uint32_t dwc_read_##_reg(_container_type *container) { \
423 	return DWC_READ_REG32(&container->regs->_reg); \
424 } \
425 static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
426 	DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
427 	DWC_WRITE_REG32(&container->regs->_reg, data); \
428 }
429 
430 # else	/* DWC_DEBUG_REGS */
431 
432 #define dwc_define_read_write_reg_n(_reg,_container_type) \
433 static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
434 	return DWC_READ_REG32(&container->regs->_reg[num]); \
435 } \
436 static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
437 	DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
438 }
439 
440 #define dwc_define_read_write_reg(_reg,_container_type) \
441 static inline uint32_t dwc_read_##_reg(_container_type *container) { \
442 	return DWC_READ_REG32(&container->regs->_reg); \
443 } \
444 static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
445 	DWC_WRITE_REG32(&container->regs->_reg, data); \
446 }
447 
448 # endif	/* DWC_DEBUG_REGS */
449 
450 #endif	/* DWC_OS_PORTING */
451 
452 
453 /** @endcond */
454 
455 
456 #ifdef DWC_CRYPTOLIB
457 XXX
458 /** @name Crypto Functions
459  *
460  * These are the low-level cryptographic functions used by the driver. */
461 
462 /** Perform AES CBC */
463 extern _LONG_CALL_ int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
464 #define dwc_aes_cbc DWC_AES_CBC
465 
466 /** Fill the provided buffer with random bytes.  These should be cryptographic grade random numbers. */
467 extern _LONG_CALL_ void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
468 #define dwc_random_bytes DWC_RANDOM_BYTES
469 
470 /** Perform the SHA-256 hash function */
471 extern _LONG_CALL_ int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
472 #define dwc_sha256 DWC_SHA256
473 
474 /** Calculated the HMAC-SHA256 */
475 extern _LONG_CALL_ int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
476 #define dwc_hmac_sha256 DWC_HMAC_SHA256
477 
478 #endif	/* DWC_CRYPTOLIB */
479 
480 
481 /** @name Memory Allocation
482  *
483  * These function provide access to memory allocation.  There are only 2 DMA
484  * functions and 3 Regular memory functions that need to be implemented.  None
485  * of the memory debugging routines need to be implemented.  The allocation
486  * routines all ZERO the contents of the memory.
487  *
488  * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
489  * This checks for memory leaks, keeping track of alloc/free pairs.  It also
490  * keeps track of how much memory the driver is using at any given time. */
491 
492 #define DWC_PAGE_SIZE 4096
493 #define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
494 #define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
495 
496 #define DWC_INVALID_DMA_ADDR 0x0
497 
498 #ifdef DWC_OS_PORTING
499 /** Type for a DMA address */
500 typedef dma_addr_t dwc_dma_t;
501 #endif
502 
503 #if 0//defined(DWC_FREEBSD) || defined(DWC_NETBSD)
504 typedef bus_addr_t dwc_dma_t;
505 #endif
506 
507 #if 0//def DWC_FREEBSD
508 typedef struct dwc_dmactx {
509 	struct device *dev;
510 	bus_dma_tag_t dma_tag;
511 	bus_dmamap_t dma_map;
512 	bus_addr_t dma_paddr;
513 	void *dma_vaddr;
514 } dwc_dmactx_t;
515 #endif
516 
517 #if 0//def DWC_NETBSD
518 typedef struct dwc_dmactx {
519 	struct device *dev;
520 	bus_dma_tag_t dma_tag;
521 	bus_dmamap_t dma_map;
522 	bus_dma_segment_t segs[1];
523 	int nsegs;
524 	bus_addr_t dma_paddr;
525 	void *dma_vaddr;
526 } dwc_dmactx_t;
527 #endif
528 
529 /* @todo these functions will be added in the future */
530 #if 0
531 /**
532  * Creates a DMA pool from which you can allocate DMA buffers.  Buffers
533  * allocated from this pool will be guaranteed to meet the size, alignment, and
534  * boundary requirements specified.
535  *
536  * @param[in] size Specifies the size of the buffers that will be allocated from
537  * this pool.
538  * @param[in] align Specifies the byte alignment requirements of the buffers
539  * allocated from this pool.  Must be a power of 2.
540  * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
541  * this pool must not cross.
542  *
543  * @returns A pointer to an internal opaque structure which is not to be
544  * accessed outside of these library functions.  Use this handle to specify
545  * which pools to allocate/free DMA buffers from and also to destroy the pool,
546  * when you are done with it.
547  */
548 extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
549 
550 /**
551  * Destroy a DMA pool.  All buffers allocated from that pool must be freed first.
552  */
553 extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
554 
555 /**
556  * Allocate a buffer from the specified DMA pool and zeros its contents.
557  */
558 extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
559 
560 /**
561  * Free a previously allocated buffer from the DMA pool.
562  */
563 extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
564 #endif
565 
566 /** Allocates a DMA capable buffer and zeroes its contents. */
567 extern _LONG_CALL_ void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
568 
569 /** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
570 extern _LONG_CALL_ void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
571 
572 /** Frees a previously allocated buffer. */
573 extern _LONG_CALL_ void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
574 
575 /** Allocates a block of memory and zeroes its contents. */
576 extern _LONG_CALL_ void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
577 
578 /** Allocates a block of memory and zeroes its contents, in an atomic manner
579  * which can be used inside interrupt context.  The size should be sufficiently
580  * small, a few KB at most, such that failures are not likely to occur.  Can just call
581  * __DWC_ALLOC if it is atomic. */
582 extern _LONG_CALL_ void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
583 
584 /** Frees a previously allocated buffer. */
585 extern _LONG_CALL_ void __DWC_FREE(void *mem_ctx, void *addr);
586 
587 #ifndef DWC_DEBUG_MEMORY
588 
589 #define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
590 #define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
591 #define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
592 
593 #ifdef DWC_OS_PORTING
594 #define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
595 #define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
596 #define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
597 #endif
598 
599 #if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
600 XXX
601 #define DWC_DMA_ALLOC __DWC_DMA_ALLOC
602 #define DWC_DMA_FREE __DWC_DMA_FREE
603 #endif
604 
605 #else	/* DWC_DEBUG_MEMORY */
606 XXX
607 extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
608 extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
609 extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
610 extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
611 				 char const *func, int line);
612 extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
613 				char const *func, int line);
614 extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
615 			       dwc_dma_t dma_addr, char const *func, int line);
616 
617 extern int dwc_memory_debug_start(void *mem_ctx);
618 extern void dwc_memory_debug_stop(void);
619 extern void dwc_memory_debug_report(void);
620 
621 #endif /* DWC_DEBUG_MEMORY */
622 
623 #define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
624 #define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
625 #define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
626 
627 #ifdef DWC_OS_PORTING
628 /* Linux doesn't need any extra parameters for DMA buffer allocation, so we
629  * just throw away the DMA context parameter.
630  */
631 #define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
632 #define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
633 #define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
634 #endif
635 
636 #if 0//defined(DWC_FREEBSD) || defined(DWC_NETBSD)
637 /** BSD needs several extra parameters for DMA buffer allocation, so we pass
638  * them in using the DMA context parameter.
639  */
640 #define dwc_dma_alloc DWC_DMA_ALLOC
641 #define dwc_dma_free DWC_DMA_FREE
642 #endif
643 
644 
645 /** @name Memory and String Processing */
646 
647 /** memset() clone */
648 extern _LONG_CALL_ void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
649 #define dwc_memset DWC_MEMSET
650 
651 /** memcpy() clone */
652 extern _LONG_CALL_ void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
653 #define dwc_memcpy DWC_MEMCPY
654 
655 /** memmove() clone */
656 extern _LONG_CALL_ void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
657 #define dwc_memmove DWC_MEMMOVE
658 
659 /** memcmp() clone */
660 extern _LONG_CALL_ int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
661 #define dwc_memcmp DWC_MEMCMP
662 
663 /** strcmp() clone */
664 extern _LONG_CALL_ int DWC_STRCMP(void *s1, void *s2);
665 #define dwc_strcmp DWC_STRCMP
666 
667 /** strncmp() clone */
668 extern _LONG_CALL_ int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
669 #define dwc_strncmp DWC_STRNCMP
670 
671 /** strlen() clone, for NULL terminated ASCII strings */
672 extern _LONG_CALL_ int DWC_STRLEN(char const *str);
673 #define dwc_strlen DWC_STRLEN
674 
675 /** strcpy() clone, for NULL terminated ASCII strings */
676 extern _LONG_CALL_ char *DWC_STRCPY(char *to, const char *from);
677 #define dwc_strcpy DWC_STRCPY
678 
679 /** strdup() clone.  If you wish to use memory allocation debugging, this
680  * implementation of strdup should use the DWC_* memory routines instead of
681  * calling a predefined strdup.  Otherwise the memory allocated by this routine
682  * will not be seen by the debugging routines. */
683 extern _LONG_CALL_ char *DWC_STRDUP(char const *str);
684 #define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
685 
686 /** NOT an atoi() clone.  Read the description carefully.  Returns an integer
687  * converted from the string str in base 10 unless the string begins with a "0x"
688  * in which case it is base 16.  String must be a NULL terminated sequence of
689  * ASCII characters and may optionally begin with whitespace, a + or -, and a
690  * "0x" prefix if base 16.  The remaining characters must be valid digits for
691  * the number and end with a NULL character.  If any invalid characters are
692  * encountered or it returns with a negative error code and the results of the
693  * conversion are undefined.  On sucess it returns 0.  Overflow conditions are
694  * undefined.  An example implementation using atoi() can be referenced from the
695  * Linux implementation. */
696 extern _LONG_CALL_ int DWC_ATOI(const char *str, int32_t *value);
697 #define dwc_atoi DWC_ATOI
698 
699 /** Same as above but for unsigned. */
700 extern _LONG_CALL_ int DWC_ATOUI(const char *str, uint32_t *value);
701 #define dwc_atoui DWC_ATOUI
702 
703 #ifdef DWC_UTFLIB
704 XXX
705 /** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
706 extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
707 #define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
708 #endif
709 
710 
711 /** @name Wait queues
712  *
713  * Wait queues provide a means of synchronizing between threads or processes.  A
714  * process can block on a waitq if some condition is not true, waiting for it to
715  * become true.  When the waitq is triggered all waiting process will get
716  * unblocked and the condition will be check again.  Waitqs should be triggered
717  * every time a condition can potentially change.*/
718 //struct dwc_waitq;
719 
720 /** Type for a waitq */
721 //typedef struct dwc_waitq dwc_waitq_t;
722 
723 /** The type of waitq condition callback function.  This is called every time
724  * condition is evaluated. */
725 //typedef int (*dwc_waitq_condition_t)(void *data);
726 
727 /** Allocate a waitq */
728 //extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
729 //#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
730 
731 /** Free a waitq */
732 //extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
733 //#define dwc_waitq_free DWC_WAITQ_FREE
734 
735 /** Check the condition and if it is false, block on the waitq.  When unblocked, check the
736  * condition again.  The function returns when the condition becomes true.  The return value
737  * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
738 //extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
739 //#define dwc_waitq_wait DWC_WAITQ_WAIT
740 
741 /** Check the condition and if it is false, block on the waitq.  When unblocked,
742  * check the condition again.  The function returns when the condition become
743  * true or the timeout has passed.  The return value is 0 on condition true or
744  * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
745  * error. */
746 //extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
747 //				      void *data, int32_t msecs);
748 //#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
749 
750 /** Trigger a waitq, unblocking all processes.  This should be called whenever a condition
751  * has potentially changed. */
752 //extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
753 //#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
754 
755 /** Unblock all processes waiting on the waitq with an ABORTED result. */
756 //extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
757 //#define dwc_waitq_abort DWC_WAITQ_ABORT
758 
759 
760 /** @name Threads
761  *
762  * A thread must be explicitly stopped.  It must check DWC_THREAD_SHOULD_STOP
763  * whenever it is woken up, and then return.  The DWC_THREAD_STOP function
764  * returns the value from the thread.
765  */
766 
767 /** @name Work queues
768  *
769  * Workqs are used to queue a callback function to be called at some later time,
770  * in another thread. */
771 //struct dwc_workq;
772 
773 /** Type for a workq */
774 typedef struct dwc_workq dwc_workq_t;
775 
776 /** The type of the callback function to be called. */
777 //typedef void (*dwc_work_callback_t)(void *data);
778 
779 /** Allocate a workq */
780 //extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
781 //#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
782 
783 /** Free a workq.  All work must be completed before being freed. */
784 //extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
785 //#define dwc_workq_free DWC_WORKQ_FREE
786 
787 /** Schedule a callback on the workq, passing in data.  The function will be
788  * scheduled at some later time. */
789 //extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
790 //			       void *data, char *format, ...)
791 #if 0//def __GNUC__
792 	__attribute__ ((format(printf, 4, 5)));
793 #else
794 	;
795 #endif
796 //#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
797 
798 /** Schedule a callback on the workq, that will be called until at least
799  * given number miliseconds have passed. */
800 //extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
801 //				       void *data, uint32_t time, char *format, ...)
802 #if 0//def __GNUC__
803 	__attribute__ ((format(printf, 5, 6)));
804 #else
805 	;
806 #endif
807 //#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
808 
809 /** The number of processes in the workq */
810 //extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
811 //#define dwc_workq_pending DWC_WORKQ_PENDING
812 
813 /** Blocks until all the work in the workq is complete or timed out.  Returns <
814  * 0 on timeout. */
815 //extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
816 //#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
817 
818 
819 
820 
821 /** @name Tasklets
822  *
823  */
824 
825 //struct dwc_tasklet;
826 
827 /** Type for a tasklet */
828 typedef struct dwc_tasklet dwc_tasklet_t;
829 
830 /** The type of the callback function to be called */
831 //typedef void (*dwc_tasklet_callback_t)(void *data);
832 
833 /** Allocates a tasklet */
834 //extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
835 //#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
836 
837 /** Frees a tasklet */
838 //extern void DWC_TASK_FREE(dwc_tasklet_t *task);
839 //#define dwc_task_free DWC_TASK_FREE
840 
841 /** Schedules a tasklet to run */
842 //extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
843 //#define dwc_task_schedule DWC_TASK_SCHEDULE
844 
845 
846 /** @name Timer
847  *
848  * Callbacks must be small and atomic.
849  */
850 struct dwc_timer;
851 
852 /** Type for a timer */
853 typedef struct dwc_timer dwc_timer_t;
854 
855 /** The type of the callback function to be called */
856 typedef void (*dwc_timer_callback_t)(void *data);
857 
858 /** Allocates a timer */
859 extern _LONG_CALL_ dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
860 #define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
861 
862 /** Frees a timer */
863 extern _LONG_CALL_ void DWC_TIMER_FREE(dwc_timer_t *timer);
864 #define dwc_timer_free DWC_TIMER_FREE
865 
866 /** Schedules the timer to run at time ms from now.  And will repeat at every
867  * repeat_interval msec therafter
868  *
869  * Modifies a timer that is still awaiting execution to a new expiration time.
870  * The mod_time is added to the old time.  */
871 extern _LONG_CALL_ void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
872 #define dwc_timer_schedule DWC_TIMER_SCHEDULE
873 
874 /** Disables the timer from execution. */
875 extern _LONG_CALL_ void DWC_TIMER_CANCEL(dwc_timer_t *timer);
876 #define dwc_timer_cancel DWC_TIMER_CANCEL
877 
878 
879 /** @name Spinlocks
880  *
881  * These locks are used when the work between the lock/unlock is atomic and
882  * short.  Interrupts are also disabled during the lock/unlock and thus they are
883  * suitable to lock between interrupt/non-interrupt context.  They also lock
884  * between processes if you have multiple CPUs or Preemption.  If you don't have
885  * multiple CPUS or Preemption, then the you can simply implement the
886  * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts.  Because
887  * the work between the lock/unlock is atomic, the process context will never
888  * change, and so you never have to lock between processes.  */
889 
890 struct dwc_spinlock;
891 
892 /** Type for a spinlock */
893 //typedef struct dwc_spinlock dwc_spinlock_t;
894 typedef _lock dwc_spinlock_t;
895 
896 /** Type for the 'flags' argument to spinlock funtions */
897 typedef unsigned long dwc_irqflags_t;
898 
899 /** Returns an initialized lock variable.  This function should allocate and
900  * initialize the OS-specific data structure used for locking.  This data
901  * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
902  * be freed by the DWC_FREE_LOCK when it is no longer used. */
903 extern _LONG_CALL_ dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
904 #define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
905 
906 /** Frees an initialized lock variable. */
907 extern _LONG_CALL_ void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
908 #define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
909 
910 /** Disables interrupts and blocks until it acquires the lock.
911  *
912  * @param lock Pointer to the spinlock.
913  * @param flags Unsigned long for irq flags storage.
914  */
915 extern _LONG_CALL_ void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
916 #define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
917 
918 /** Re-enables the interrupt and releases the lock.
919  *
920  * @param lock Pointer to the spinlock.
921  * @param flags Unsigned long for irq flags storage.  Must be the same as was
922  * passed into DWC_LOCK.
923  */
924 extern _LONG_CALL_ void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
925 #define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
926 
927 /** Blocks until it acquires the lock.
928  *
929  * @param lock Pointer to the spinlock.
930  */
931 extern _LONG_CALL_ void DWC_SPINLOCK(dwc_spinlock_t *lock);
932 #define dwc_spinlock DWC_SPINLOCK
933 
934 /** Releases the lock.
935  *
936  * @param lock Pointer to the spinlock.
937  */
938 extern _LONG_CALL_ void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
939 #define dwc_spinunlock DWC_SPINUNLOCK
940 
941 
942 /** @name Mutexes
943  *
944  * Unlike spinlocks Mutexes lock only between processes and the work between the
945  * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
946  */
947 
948 struct dwc_mutex;
949 
950 /** Type for a mutex */
951 typedef struct dwc_mutex dwc_mutex_t;
952 
953 /* For Linux Mutex Debugging make it inline because the debugging routines use
954  * the symbol to determine recursive locking.  This makes it falsely think
955  * recursive locking occurs. */
956 #if defined(DWC_OS_PORTING) && defined(CONFIG_DEBUG_MUTEXES)
957 #define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
958 	__mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
959 	mutex_init((struct mutex *)__mutexp); \
960 })
961 #endif
962 
963 /** Allocate a mutex */
964 extern _LONG_CALL_ dwc_mutex_t *DWC_MUTEX_ALLOC(void);
965 #define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
966 
967 /* For memory leak debugging when using Linux Mutex Debugging */
968 #if defined(DWC_OS_PORTING) && defined(CONFIG_DEBUG_MUTEXES)
969 XXX
970 #define DWC_MUTEX_FREE(__mutexp) do { \
971 	mutex_destroy((struct mutex *)__mutexp); \
972 	DWC_FREE(__mutexp); \
973 } while(0)
974 #else
975 /** Free a mutex */
976 extern _LONG_CALL_ void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
977 #define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
978 #endif
979 
980 /** Lock a mutex */
981 extern _LONG_CALL_ void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
982 #define dwc_mutex_lock DWC_MUTEX_LOCK
983 
984 /** Non-blocking lock returns 1 on successful lock. */
985 extern _LONG_CALL_ int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
986 #define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
987 
988 /** Unlock a mutex */
989 extern _LONG_CALL_ void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
990 #define dwc_mutex_unlock DWC_MUTEX_UNLOCK
991 
992 
993 /** @name Time */
994 
995 /** Microsecond delay.
996  *
997  * @param usecs  Microseconds to delay.
998  */
999 extern _LONG_CALL_ void DWC_UDELAY(uint32_t usecs);
1000 #define dwc_udelay DWC_UDELAY
1001 
1002 /** Millisecond delay.
1003  *
1004  * @param msecs  Milliseconds to delay.
1005  */
1006 extern _LONG_CALL_ void DWC_MDELAY(uint32_t msecs);
1007 #define dwc_mdelay DWC_MDELAY
1008 
1009 /** Non-busy waiting.
1010  * Sleeps for specified number of milliseconds.
1011  *
1012  * @param msecs Milliseconds to sleep.
1013  */
1014 extern _LONG_CALL_ void DWC_MSLEEP(uint32_t msecs);
1015 #define dwc_msleep DWC_MSLEEP
1016 
1017 extern _LONG_CALL_ void DWC_ENTER_CRITICAL(VOID);
1018 extern _LONG_CALL_ void DWC_EXIT_CRITICAL(VOID);
1019 extern _LONG_CALL_ uint8_t DWC_IN_CRITICAL(VOID);
1020 /**
1021  * Returns number of milliseconds since boot.
1022  */
1023 //extern uint32_t DWC_TIME(void);
1024 //#define dwc_time DWC_TIME
1025 
1026 
1027 
1028 
1029 /* @mainpage DWC Portability and Common Library
1030  *
1031  * This is the documentation for the DWC Portability and Common Library.
1032  *
1033  * @section intro Introduction
1034  *
1035  * The DWC Portability library consists of wrapper calls and data structures to
1036  * all low-level functions which are typically provided by the OS.  The WUDEV
1037  * driver uses only these functions.  In order to port the WUDEV driver, only
1038  * the functions in this library need to be re-implemented, with the same
1039  * behavior as documented here.
1040  *
1041  * The Common library consists of higher level functions, which rely only on
1042  * calling the functions from the DWC Portability library.  These common
1043  * routines are shared across modules.  Some of the common libraries need to be
1044  * used directly by the driver programmer when porting WUDEV.  Such as the
1045  * parameter and notification libraries.
1046  *
1047  * @section low Portability Library OS Wrapper Functions
1048  *
1049  * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
1050  * needs to be implemented when porting, for example DWC_MUTEX_ALLOC().  All of
1051  * these functions are included in the dwc_os.h file.
1052  *
1053  * There are many functions here covering a wide array of OS services.  Please
1054  * see dwc_os.h for details, and implementation notes for each function.
1055  *
1056  * @section common Common Library Functions
1057  *
1058  * Any function starting with dwc and in all lowercase is a common library
1059  * routine.  These functions have a portable implementation and do not need to
1060  * be reimplemented when porting.  The common routines can be used by any
1061  * driver, and some must be used by the end user to control the drivers.  For
1062  * example, you must use the Parameter common library in order to set the
1063  * parameters in the WUDEV module.
1064  *
1065  * The common libraries consist of the following:
1066  *
1067  * - Connection Contexts - Used internally and can be used by end-user.  See dwc_cc.h
1068  * - Parameters - Used internally and can be used by end-user.  See dwc_params.h
1069  * - Notifications - Used internally and can be used by end-user.  See dwc_notifier.h
1070  * - Lists - Used internally and can be used by end-user.  See dwc_list.h
1071  * - Memory Debugging - Used internally and can be used by end-user.  See dwc_os.h
1072  * - Modpow - Used internally only.  See dwc_modpow.h
1073  * - DH - Used internally only.  See dwc_dh.h
1074  * - Crypto - Used internally only.  See dwc_crypto.h
1075  *
1076  *
1077  * @section prereq Prerequistes For dwc_os.h
1078  * @subsection types Data Types
1079  *
1080  * The dwc_os.h file assumes that several low-level data types are pre defined for the
1081  * compilation environment.  These data types are:
1082  *
1083  * - uint8_t - unsigned 8-bit data type
1084  * - int8_t - signed 8-bit data type
1085  * - uint16_t - unsigned 16-bit data type
1086  * - int16_t - signed 16-bit data type
1087  * - uint32_t - unsigned 32-bit data type
1088  * - int32_t - signed 32-bit data type
1089  * - uint64_t - unsigned 64-bit data type
1090  * - int64_t - signed 64-bit data type
1091  *
1092  * Ensure that these are defined before using dwc_os.h.  The easiest way to do
1093  * that is to modify the top of the file to include the appropriate header.
1094  * This is already done for the Linux environment.  If the DWC_OS_PORTING macro is
1095  * defined, the correct header will be added.  A standard header <stdint.h> is
1096  * also used for environments where standard C headers are available.
1097  *
1098  * @subsection stdarg Variable Arguments
1099  *
1100  * Variable arguments are provided by a standard C header <stdarg.h>.  it is
1101  * available in Both the Linux and ANSI C enviornment.  An equivalent must be
1102  * provided in your enviornment in order to use dwc_os.h with the debug and
1103  * tracing message functionality.
1104  *
1105  * @subsection thread Threading
1106  *
1107  * WUDEV Core must be run on an operating system that provides for multiple
1108  * threads/processes.  Threading can be implemented in many ways, even in
1109  * embedded systems without an operating system.  At the bare minimum, the
1110  * system should be able to start any number of processes at any time to handle
1111  * special work.  It need not be a pre-emptive system.  Process context can
1112  * change upon a call to a blocking function.  The hardware interrupt context
1113  * that calls the module's ISR() function must be differentiable from process
1114  * context, even if your processes are impemented via a hardware interrupt.
1115  * Further locking mechanism between process must exist (or be implemented), and
1116  * process context must have a way to disable interrupts for a period of time to
1117  * lock them out.  If all of this exists, the functions in dwc_os.h related to
1118  * threading should be able to be implemented with the defined behavior.
1119  *
1120  */
1121 
1122 
1123 
1124 
1125 #ifdef __cplusplus
1126 }
1127 #endif
1128 
1129 #endif /* _DWC_OS_H_ */
1130