📄 usbmacros.h
字号:
/** * @file usbmacros.h * * @author Intel Corporation * @date 30-OCT-2001 * * @brief This file containes macros used by the USB driver implementation * * * @par * IXP400 SW Release version 2.1 * * -- Copyright Notice -- * * @par * Copyright (c) 2001-2005, Intel Corporation. * All rights reserved. * * @par * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Intel Corporation nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * * @par * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * @par * -- End of Copyright Notice -- *//** * @addtogroup IxUsbAPI * * @brief Definition of macros used by the USB driver code * * @{ */#ifndef usbmacros_H#ifndef __doxygen_HIDE#define usbmacros_H#endif /* __doxygen_HIDE */#include "IxOsal.h"/* macros for extracting type and direction from EPDescriptorTable *//** * @def EP_DIRECTION(x) * * @brief Macro used to extract the endpoint direction from * an EPDescriptorTable[] entry. * * @param x int (in) - the endpoint description entry * * @return the endpoint direction (USB_IN, USB_OUT or USB_IN_OUT) */#define EP_DIRECTION(x) ((x) & (USB_IN | USB_OUT))/** * @def EP_TYPE(x) * * @brief Macro used to extract the endpoint type from * an EPDescriptorTable[] entry. * * @param x int (in) - the endpoint description entry * * @return the endpoint type (USB_CONTROL, USB_BULK, USB_ISOCHRONOUS, USB_INTERRUPT) */#define EP_TYPE(x) ((x) & (USB_CONTROL | USB_BULK | USB_ISOCHRONOUS | USB_INTERRUPT))/* minimum */#ifndef MIN/** * @def MIN(a, b) * * @brief Compares two values and returns the minimum * * @param a - first value * @param b - second value * * @return minimum of the two input values */#define MIN(a, b) ((a) < (b)? (a) : (b))#endif /* MIN *//* maximum */#ifndef MAX/** * @def MAX(a, b) * * @brief Compares two values and returns the maximum * * @param a - first value * @param b - second value * * @return maximum of the two input values */#define MAX(a, b) ((a) > (b)? (a) : (b))#endif /* MAX *//* queue wrap *//** * @def QUEUE_WRAP(tail) * * @brief Ajusts the tail of a queue implemented in a circular buffer * by wrapping at the buffer boundary * * @param tail int - virtual tail offset * * @return the real adjusted tail offset */#define QUEUE_WRAP(tail) ((tail) >= (MAX_QUEUE_SIZE) ? ((tail) - (MAX_QUEUE_SIZE)) : (tail))#if defined(__BIG_ENDIAN)/** * USB byte swapping routine for a big endian platform */#define SWAP_USB_WORD(wPtr) (*(wPtr)) = ((*(wPtr) & 0xFF00) >> 8) | \ ((*(wPtr) & 0x00FF) << 8)#else/** * USB byte swapping routine for a little endian platform */#define SWAP_USB_WORD(wPtr) if (0); #endif /* __HWEMU__ *//* macros for reading/writing UDC registers */#ifndef __HWEMU__/** read generic register access via register pointers */#define REG_GET(reg_ptr) IX_OSAL_READ_LONG(reg_ptr)/** write generic register access via register pointers */#define REG_SET(reg_ptr, val) IX_OSAL_WRITE_LONG(reg_ptr, val)/** generic data register read access via register pointers */#define DREG_GET(reg_ptr) (IX_OSAL_READ_LONG(reg_ptr) & UDC_UDDR_RW_MASK)/** generic data register write access via register pointers */#define DREG_SET(reg_ptr, val) IX_OSAL_WRITE_LONG(reg_ptr, val & UDC_UDDR_RW_MASK)#else/* prototypes *//** Data register read access via register pointers */UINT32 reg32Get(volatile UINT32 *reg_ptr);/** Data register write access via register pointers */voidreg32Set(volatile UINT32 *reg_ptr, UINT32 val);#define REG_GET(reg_ptr) (reg32Get(reg_ptr))#define REG_SET(reg_ptr, val) (reg32Set(reg_ptr, val))#define DREG_GET(reg_ptr) REG_GET(reg_ptr)#define DREG_SET(reg_ptr, val) REG_SET(reg_ptr, val)#endif /* __HWEMU__ *//* macros to access device context data *//* NB: all return pointers so write access is allowed *//** get context from device pointer */#define CONTEXT(device) ((USBDeviceContext *)((device)->deviceContext))/** get registers from device pointer */#define REGISTERS(device) (CONTEXT(device)->registers)/** get endpoint 0 control data from device pointer */#define EP0CONTROL(device) (&(CONTEXT(device)->ep0ControlData))/** get event processor from device pointer */#define EVENTS(device) (&(CONTEXT(device)->eventProcessor))/** get device counters */#define COUNTERS(device) (&(CONTEXT(device)->counters))/** get device operation */#define OPERATION(device) (&(CONTEXT(device)->deviceOperation))/** get endpoint status from device pointer and endpoint number */#define EPSTATUS(device, endpointNumber) (&(CONTEXT(device)->epStatusData[endpointNumber]))/** get endpoint queue from device pointer and endpoint number */#define EPQUEUE(device, endpointNumber) (&(EPSTATUS((device), (endpointNumber))->queue))/** get endpoint counters from device pointer and endpoint number */#define EPCOUNTERS(device, endpointNumber) (&(EPSTATUS((device), (endpointNumber))->counters))/** set IX_SUCCESS on device and return IX_SUCCESS */#define RETURN_OK(device) \ device->lastError = IX_SUCCESS; \ return IX_SUCCESS;/** set IX_USB_ERROR on device and return IX_FAIL */#define RETURN_ERROR(device) \ device->lastError = IX_USB_ERROR; \ return IX_FAIL;/** set IX_USB_INVALID_PARAMS on device and return IX_FAIL */#define RETURN_INVALID_PARMS(device) \ device->lastError = IX_USB_INVALID_PARMS; \ return IX_FAIL;/** set IX_USB_REDUNDANT on device and return IX_FAIL */#define RETURN_REDUNDANT(device) \ device->lastError = IX_USB_REDUNDANT; \ return IX_FAIL;/** set IX_USB_INVALID_PARAMS on device and return IX_FAIL */#define RETURN_INVALID_DEVICE(device) \ device->lastError = IX_USB_INVALID_DEVICE; \ return IX_FAIL;/** set IX_USB_INVALID_PARAMS on device and return IX_FAIL */#define RETURN_NO_ENDPOINT(device) \ device->lastError = IX_USB_NO_ENDPOINT; \ return IX_FAIL;/** set IX_USB_ENDPOINT_STALLED on device and return IX_FAIL */#define RETURN_ENDPOINT_STALLED(device) \ device->lastError = IX_USB_ENDPOINT_STALLED; \ return IX_FAIL;/** set IX_USB_SEND_QUEUE_FULL on device and return IX_FAIL */#define RETURN_SEND_QUEUE_FULL(device) \ device->lastError = IX_USB_SEND_QUEUE_FULL; \ return IX_FAIL;/** set IX_USB_NO_IN_CAPABILITY on device and return IX_FAIL */#define RETURN_NO_IN_CAPABILITY(device) \ device->lastError = IX_USB_NO_IN_CAPABILITY; \ return IX_FAIL;/** set IX_USB_NO_STALL_CAPABILITY on device and return IX_FAIL */#define RETURN_NO_STALL_CAPABILITY(device) \ device->lastError = IX_USB_NO_STALL_CAPABILITY; \ return IX_FAIL;/** set IX_USB_NO_PERMISSION on device and return IX_FAIL */#define RETURN_NO_PERMISSION(device) \ device->lastError = IX_USB_NO_PERMISSION; \ return IX_FAIL;/** sanity checks for device existence */#define CHECK_DEVICE(device) \ if (device == NULL) \ { \ return IX_FAIL; \ } \ \ if (CONTEXT(device)->checkPattern != USB_DEVICE_CONTEXT_CHECK_PATTERN) \ { \ return IX_FAIL; \ } /** sanity checks for device enable status */#define CHECK_DEVICE_ENABLED(device) \ if (!CONTEXT(device)->enabled) \ { \ device->lastError = IX_USB_DEVICE_DISABLED; \ return IX_FAIL; \ }/** sanity check for endpoint existence */#define CHECK_ENDPOINT(device, endpointNumber) \ if (endpointNumber >= NUM_ENDPOINTS) \ { \ RETURN_NO_ENDPOINT(device); \ }/** sanity check for endpoint stall */#define CHECK_ENDPOINT_STALL(device, endpointNumber) \ { \ BOOL stallState; \ ixUSBIsEndpointStalled(device, endpointNumber, &stallState); \ \ if (stallState) \ { \ RETURN_ENDPOINT_STALLED(device); \ } \ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -