Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

usbmacros.h

Go to the documentation of this file.
00001 
00058 #ifndef usbmacros_H
00059 
00060 #ifndef __doxygen_HIDE
00061 
00062 #define usbmacros_H
00063 
00064 #endif /* __doxygen_HIDE */
00065 
00066 #include "IxOsServicesMemAccess.h"
00067 #include "IxAssert.h"
00068  
00069 /* logMsg is provided in BSP. */
00070 #ifdef __vxworks
00071 extern int logMsg(char *fmt, ...);
00072 #else
00073 #define logMsg printk
00074 #endif
00075 /* macros for extracting type and direction from EPDescriptorTable */
00076 
00087 #define EP_DIRECTION(x) ((x) & (USB_IN | USB_OUT))
00088 
00099 #define EP_TYPE(x) ((x) & (USB_CONTROL | USB_BULK | USB_ISOCHRONOUS | USB_INTERRUPT))
00100 
00101 /* minimum */
00102 #ifndef MIN
00103 
00113 #define MIN(a, b)       ((a) < (b)? (a) : (b))
00114 #endif /* MIN */
00115 
00116 /* maximum */
00117 #ifndef MAX
00118 
00128 #define MAX(a, b)       ((a) > (b)? (a) : (b))
00129 #endif /* MAX */
00130 
00131 /* queue wrap */
00142 #define QUEUE_WRAP(tail)    ((tail) >= (MAX_QUEUE_SIZE) ? ((tail) - (MAX_QUEUE_SIZE)) : (tail))
00143 
00144 #if defined(__BIG_ENDIAN)
00145 
00149 #define SWAP_USB_WORD(wPtr)     (*(wPtr)) = ((*(wPtr) & 0xFF00) >> 8) | \
00150                                             ((*(wPtr) & 0x00FF) << 8)
00151 
00152 #else
00153 
00157 #define SWAP_USB_WORD(wPtr)     if (0); 
00158 
00159 #endif /* __HWEMU__ */
00160 
00161 /* macros for reading/writing UDC registers */
00162 
00163 #ifndef __HWEMU__
00164 
00166 #define REG_GET(reg_ptr)          IX_OSSERV_READ_LONG(reg_ptr)
00167 
00168 #define REG_SET(reg_ptr, val)     IX_OSSERV_WRITE_LONG(reg_ptr, val)
00169 
00171 #define DREG_GET(reg_ptr)         (IX_OSSERV_READ_LONG(reg_ptr) & UDC_UDDR_RW_MASK)
00172 
00173 #define DREG_SET(reg_ptr, val)    IX_OSSERV_WRITE_LONG(reg_ptr, val & UDC_UDDR_RW_MASK)
00174 
00175 #else
00176 
00177 /* prototypes */
00179 UINT32 
00180 reg32Get(volatile UINT32 *reg_ptr);
00181 
00183 void
00184 reg32Set(volatile UINT32 *reg_ptr, UINT32 val);
00185 
00186 #define REG_GET(reg_ptr)          (reg32Get(reg_ptr))
00187 #define REG_SET(reg_ptr, val)     (reg32Set(reg_ptr, val))
00188 
00189 #define DREG_GET(reg_ptr)         REG_GET(reg_ptr)
00190 #define DREG_SET(reg_ptr, val)    REG_SET(reg_ptr, val)
00191 
00192 #endif /* __HWEMU__ */
00193 
00194 /* macros to access device context data               */
00195 /* NB: all return pointers so write access is allowed */
00196 
00198 #define CONTEXT(device)           ((USBDeviceContext *)((device)->deviceContext))
00199 
00201 #define REGISTERS(device)         (CONTEXT(device)->registers)
00202 
00204 #define EP0CONTROL(device)        (&(CONTEXT(device)->ep0ControlData))
00205 
00207 #define EVENTS(device)            (&(CONTEXT(device)->eventProcessor))
00208 
00210 #define COUNTERS(device)          (&(CONTEXT(device)->counters))
00211 
00213 #define OPERATION(device)         (&(CONTEXT(device)->deviceOperation))
00214 
00216 #define EPSTATUS(device, endpointNumber)    (&(CONTEXT(device)->epStatusData[endpointNumber]))
00217 
00219 #define EPQUEUE(device, endpointNumber)     (&(EPSTATUS((device), (endpointNumber))->queue))
00220 
00222 #define EPCOUNTERS(device, endpointNumber)  (&(EPSTATUS((device), (endpointNumber))->counters))
00223 
00225 #define RETURN_OK(device)           \
00226     device->lastError = IX_SUCCESS; \
00227     return IX_SUCCESS;
00228 
00230 #define RETURN_ERROR(device)           \
00231     device->lastError = IX_USB_ERROR;  \
00232     return IX_FAIL;
00233 
00235 #define RETURN_INVALID_PARMS(device)           \
00236     device->lastError = IX_USB_INVALID_PARMS;  \
00237     return IX_FAIL;
00238 
00240 #define RETURN_REDUNDANT(device)           \
00241     device->lastError = IX_USB_REDUNDANT;  \
00242     return IX_FAIL;
00243 
00245 #define RETURN_INVALID_DEVICE(device)           \
00246     device->lastError = IX_USB_INVALID_DEVICE;  \
00247     return IX_FAIL;
00248 
00250 #define RETURN_NO_ENDPOINT(device)           \
00251     device->lastError = IX_USB_NO_ENDPOINT;  \
00252     return IX_FAIL;
00253 
00255 #define RETURN_ENDPOINT_STALLED(device)           \
00256     device->lastError = IX_USB_ENDPOINT_STALLED;  \
00257     return IX_FAIL;
00258 
00260 #define RETURN_SEND_QUEUE_FULL(device)           \
00261     device->lastError = IX_USB_SEND_QUEUE_FULL;  \
00262     return IX_FAIL;
00263 
00265 #define RETURN_NO_IN_CAPABILITY(device)          \
00266     device->lastError = IX_USB_NO_IN_CAPABILITY; \
00267     return IX_FAIL;
00268 
00270 #define RETURN_NO_STALL_CAPABILITY(device)          \
00271     device->lastError = IX_USB_NO_STALL_CAPABILITY; \
00272     return IX_FAIL;
00273 
00275 #define RETURN_NO_PERMISSION(device)          \
00276     device->lastError = IX_USB_NO_PERMISSION; \
00277     return IX_FAIL;
00278 
00280 #define CHECK_DEVICE(device)                                                \
00281     if (device == NULL)                                                     \
00282     {                                                                       \
00283         return IX_FAIL;                                                     \
00284     }                                                                       \
00285                                                                             \
00286     if (CONTEXT(device)->checkPattern != USB_DEVICE_CONTEXT_CHECK_PATTERN)  \
00287     {                                                                       \
00288         return IX_FAIL;                                                     \
00289     }                                               
00290 
00292 #define CHECK_DEVICE_ENABLED(device)                \
00293     if (!CONTEXT(device)->enabled)                  \
00294     {                                               \
00295         device->lastError = IX_USB_DEVICE_DISABLED; \
00296         return IX_FAIL;                             \
00297     }
00298 
00300 #define CHECK_ENDPOINT(device, endpointNumber)  \
00301     if (endpointNumber >= NUM_ENDPOINTS)        \
00302     {                                           \
00303         RETURN_NO_ENDPOINT(device);             \
00304     }
00305 
00307 #define CHECK_ENDPOINT_STALL(device, endpointNumber)                    \
00308     {                                                                   \
00309         BOOL stallState;                                                \
00310         ixUSBIsEndpointStalled(device, endpointNumber, &stallState);    \
00311                                                                         \
00312         if (stallState)                                                 \
00313         {                                                               \
00314             RETURN_ENDPOINT_STALLED(device);                            \
00315         }                                                               \
00316     }
00317 
00319 #define CHECK_EVENT_MASK(device, eventMask)                       \
00320     if ((eventMask & ~(USB_BUS_EVENTS | USB_DEVICE_EVENTS)) != 0) \
00321     {                                                             \
00322         RETURN_INVALID_PARMS(device);                             \
00323     }
00324 
00326 #define CHECK_ENDPOINT_QUEUE(epData)                \
00327     if (epData->queue.len == MAX_QUEUE_SIZE)        \
00328     {                                               \
00329         RETURN_SEND_QUEUE_FULL(epData->device);     \
00330     }
00331 
00333 #define CHECK_ENDPOINT_IN_CAPABILITY(epData, device) \
00334     if ((epData->direction & USB_IN) == 0)           \
00335     {                                                \
00336         RETURN_NO_IN_CAPABILITY(device);             \
00337     } 
00338 
00339 #ifdef __HWEMU__
00340 
00341 /* enable all debugging */
00342 
00343 #define IX_HWEMU_TRACE printf
00344 #define IX_USB_TRACE printf
00345 #define IX_USB_VERBOSE2_TRACE printf
00346 #define IX_USB_VERBOSE3_TRACE printf
00347 #define IX_USB_VERBOSE4_TRACE printf
00348 #define IX_USB_VERBOSE_MEM_TRACE printf
00349 #define IX_USB_VERBOSE_INIT_TRACE printf
00350 #define IX_USB_VERBOSE_WARN_TRACE printf
00351 
00352 #else
00353 
00354 #ifndef NDEBUG
00355 
00356 #undef IX_USB_HAS_TRACE_MACRO
00357 #undef IX_USB_HAS_VERBOSE_INIT_TRACE_MACRO
00358 #undef IX_USB_HAS_VERBOSE_WARN_TRACE_MACRO
00359 #undef IX_USB_HAS_VERBOSE_MEM_TRACE_MACRO
00360 #undef IX_USB_HAS_VERBOSE_TRACE_MACRO
00361 #undef IX_USB_HAS_VERBOSE_2_TRACE_MACRO
00362 #undef IX_USB_HAS_VERBOSE_3_TRACE_MACRO
00363 #undef IX_USB_HAS_VERBOSE_4_TRACE_MACRO
00364 #undef IX_USB_HAS_VERBOSE_5_TRACE_MACRO
00365 
00366 #endif
00367 
00368 #ifndef __doxygen_HIDE
00369 
00370 #define IX_HWEMU_TRACE if (0) printf /* nothing */
00371 
00372 #endif /* ndef __doxygen_HIDE */
00373 
00374 #ifdef IX_USB_HAS_TRACE_MACRO
00375 
00377 #define IX_USB_TRACE  logMsg
00378 
00379 #else
00380 
00382 #define IX_USB_TRACE if (0) logMsg /* nothing */
00383 
00384 #endif /* IX_USB_HAS_TRACE_MACRO */
00385 
00386 
00387 #ifndef __doxygen_HIDE
00388 
00389 #ifdef IX_USB_HAS_VERBOSE_TRACE_MACRO
00390 
00391 #define IX_USB_VERBOSE_TRACE logMsg
00392 
00393 #else
00394 
00395 #define IX_USB_VERBOSE_TRACE if (0) printf /* nothing */
00396 
00397 #endif /* IX_USB_HAS_VERBOSE_TRACE_MACRO */
00398 
00399 #ifdef IX_USB_HAS_VERBOSE_2_TRACE_MACRO
00400 
00401 #define IX_USB_VERBOSE2_TRACE logMsg
00402 
00403 #else
00404 
00405 #define IX_USB_VERBOSE2_TRACE if (0) printf /* nothing */
00406 
00407 #endif /* IX_USB_HAS_VERBOSE_2_TRACE_MACRO */
00408 
00409 #ifdef IX_USB_HAS_VERBOSE_3_TRACE_MACRO
00410 
00411 #define IX_USB_VERBOSE3_TRACE logMsg
00412 
00413 #else
00414 
00415 #define IX_USB_VERBOSE3_TRACE if (0) printf /* nothing */
00416 
00417 #endif /* IX_USB_HAS_VERBOSE_3_TRACE_MACRO */
00418 
00419 #ifdef IX_USB_HAS_VERBOSE_4_TRACE_MACRO
00420 
00421 int usbTraceVerbose4 = 0;
00422 
00423 #define IX_USB_VERBOSE4_TRACE if (usbTraceVerbose4) logMsg
00424 
00425 #else
00426 
00427 #define IX_USB_VERBOSE4_TRACE if (0) printf
00428 
00429 #endif /* IX_USB_HAS_VERBOSE_4_TRACE_MACRO */
00430 
00431 #ifdef IX_USB_HAS_VERBOSE_5_TRACE_MACRO
00432 
00433 int usbTraceVerbose5 = 0;
00434 
00435 #define IX_USB_VERBOSE5_TRACE if (usbTraceVerbose5) logMsg
00436 
00437 #else
00438 
00439 #define IX_USB_VERBOSE5_TRACE if (0) printf /* nothing */
00440 
00441 #endif /* IX_USB_HAS_VERBOSE_5_TRACE_MACRO */
00442 
00443 #ifdef IX_USB_HAS_VERBOSE_MEM_TRACE_MACRO
00444 
00445 #define IX_USB_VERBOSE_MEM_TRACE logMsg
00446 
00447 #else
00448 
00449 #define IX_USB_VERBOSE_MEM_TRACE if (0) printf /* nothing */
00450 
00451 #endif /* IX_USB_HAS_VERBOSE_MEM_TRACE_MACRO */
00452 
00453 #ifdef IX_USB_HAS_VERBOSE_WARN_TRACE_MACRO
00454 
00455 #define IX_USB_VERBOSE_WARN_TRACE logMsg
00456 
00457 #else
00458 
00459 #define IX_USB_VERBOSE_WARN_TRACE if (0) printf /* nothing */
00460 
00461 #endif /* IX_USB_HAS_VERBOSE_WARN_TRACE_MACRO */
00462 
00463 #ifdef IX_USB_HAS_VERBOSE_INIT_TRACE_MACRO
00464 
00465 #define IX_USB_VERBOSE_INIT_TRACE logMsg
00466 
00467 #else
00468 
00469 #define IX_USB_VERBOSE_INIT_TRACE if (0) printf /* nothing */
00470 
00471 #endif /* IX_USB_HAS_VERBOSE_INIT_TRACE_MACRO */
00472 
00473 #endif /* __HWEMU__ */
00474 
00475 #ifdef IX_USB_HAS_ASSERT_MACRO
00476 
00478 #define IX_USB_ASSERT(expr) \
00479     if (expr == FALSE) \
00480     { \
00481         IX_USB_TRACE("Assertion failed\n", 0, 0, 0, 0, 0, 0); \
00482         IX_ASSERT(expr); \
00483     }
00484 
00485 #else
00486 
00487 #ifndef __doxygen_HIDE
00488 
00489 #define IX_USB_ASSERT(expr) if (0); /* nothing */
00490 
00491 #endif /* ndef  __doxygen_HIDE */
00492 
00493 #endif /* IX_USB_HAS_ASSERT_MACRO */
00494 
00495 #ifdef IX_USB_HAS_CT_ASSERT_MACRO
00496 
00498 #define IX_USB_CT_ASSERT(expr) \
00499     switch (0) { case 0: case (expr):; }
00500 
00501 #else
00502 
00503 #ifndef __doxygen_HIDE
00504 
00505 #define IX_USB_CT_ASSERT(expr) /* nothing */
00506 
00507 #endif /* ndef  __doxygen_HIDE */
00508 
00509 #endif /* IX_USB_HAS_CT_ASSERT_MACRO */
00510 
00511 #endif /* ndef __doxygen_HIDE */
00512 
00513 #ifdef IX_USB_HAS_CRITICAL_DATA_LOCKS
00514 
00516 #define IX_USB_LOCK ixOsServIntLock()
00517 
00519 #define IX_USB_UNLOCK(state) ixOsServIntUnlock(state)
00520 
00522 #define IX_USB_IRQ_LOCK ixOsServIntLock()
00523 
00525 #define IX_USB_IRQ_UNLOCK(state) ixOsServIntUnlock(state)
00526 
00527 #else
00528 
00530 #define IX_USB_LOCK 0
00531 
00533 #define IX_USB_UNLOCK(state)
00534 
00536 #define IX_USB_IRQ_LOCK 0
00537 
00539 #define IX_USB_IRQ_UNLOCK(state)
00540 
00541 #endif /* IX_USB_HAS_CRITICAL_DATA_LOCKS */
00542 
00543 #ifdef IX_USB_HAS_INT_BIND_MACRO
00544 
00546 #define INT_BIND_MACRO(level, callback, instance) { ixOsServIntBind((int) level, (void (*) (void *)) callback, (void *) instance); }
00547 
00548 #else
00549 #ifndef __doxygen_HIDE
00550 
00551 #define INT_BIND_MACRO(level, callback, instance)   /* nothing */
00552 
00553 #endif /* ndef __doxygen_HIDE */
00554 
00555 #endif /* ndef IX_USB_HAS_INT_BIND_MACRO */
00556 
00557 #ifndef __doxygen_HIDE
00558 
00559 /* show macros */
00560 #define SHOW_NUMBER(x)    ((x) > 1000 ? (x) > 1000000 ? ((x) / 1000000) : ((x) / 1000) : (x))
00561 #define SHOW_METRIC(x)    ((x) > 1000 ? (x) > 1000000 ? "M" : "k" : " ")
00562 
00563 #endif /* ndif doxygen_HIDE */
00564 
00565 #endif /* usbmacros_H */
00566 
Automatically generated from sources. © Intel Corp. 2003