Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * |
| 4 | * \brief USB Include Header Files. |
| 5 | * |
| 6 | * This file contains the USB definitions and data structures provided by the |
| 7 | * USB 2.0 specification. |
| 8 | * |
| 9 | * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. |
| 10 | * |
| 11 | * \asf_license_start |
| 12 | * |
| 13 | * \page License |
| 14 | * |
| 15 | * Subject to your compliance with these terms, you may use Microchip |
| 16 | * software and any derivatives exclusively with Microchip products. |
| 17 | * It is your responsibility to comply with third party license terms applicable |
| 18 | * to your use of third party software (including open source software) that |
| 19 | * may accompany Microchip software. |
| 20 | * |
| 21 | * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, |
| 22 | * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, |
| 23 | * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, |
| 24 | * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE |
| 25 | * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL |
| 26 | * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE |
| 27 | * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE |
| 28 | * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT |
| 29 | * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY |
| 30 | * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, |
| 31 | * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. |
| 32 | * |
| 33 | * \asf_license_stop |
| 34 | */ |
| 35 | |
| 36 | #ifndef _USB_INCLUDES_H_ |
| 37 | #define _USB_INCLUDES_H_ |
| 38 | |
| 39 | #ifdef USB_USER_INCLUDES |
| 40 | |
| 41 | #include "usb_user_includes.h" |
| 42 | |
| 43 | #else |
| 44 | /* Include START headers */ |
| 45 | #include <stdbool.h> |
| 46 | #include <stdint.h> |
| 47 | #include <string.h> |
| 48 | #include <utils.h> |
| 49 | #include <utils_list.h> |
| 50 | #include <utils_assert.h> |
| 51 | #include <hal_atomic.h> |
| 52 | |
| 53 | typedef uint16_t le16_t; |
| 54 | typedef uint32_t le32_t; |
| 55 | typedef uint16_t be16_t; |
| 56 | typedef uint32_t be32_t; |
| 57 | |
| 58 | #if (defined __GNUC__) || (defined __CC_ARM) |
| 59 | #define is_constant(exp) __builtin_constant_p(exp) |
| 60 | #else |
| 61 | #define is_constant(exp) (0) |
| 62 | #endif |
| 63 | |
| 64 | /*! \brief Toggles the endianism of \a u16 (by swapping its bytes). |
| 65 | * |
| 66 | * \param u16 U16 of which to toggle the endianism. |
| 67 | * |
| 68 | * \return Value resulting from \a u16 with toggled endianism. |
| 69 | * |
| 70 | * \note More optimized if only used with values known at compile time. |
| 71 | */ |
| 72 | #define swap_u16(u16) ((uint16_t)(((uint16_t)(u16) >> 8) | ((uint16_t)(u16) << 8))) |
| 73 | |
| 74 | /*! \brief Toggles the endianism of \a u32 (by swapping its bytes). |
| 75 | * |
| 76 | * \param u32 U32 of which to toggle the endianism. |
| 77 | * |
| 78 | * \return Value resulting from \a u32 with toggled endianism. |
| 79 | * |
| 80 | * \note More optimized if only used with values known at compile time. |
| 81 | */ |
| 82 | #if (defined __GNUC__) |
| 83 | #define swap_u32(u32) \ |
| 84 | (is_constant(u32) \ |
| 85 | ? ((uint32_t)(((uint32_t)swap_u16((uint32_t)(u32) >> 16)) | ((uint32_t)swap_u16((uint32_t)(u32)) << 16))) \ |
| 86 | : ((uint32_t)__builtin_bswap32((uint32_t)(u32)))) |
| 87 | #else |
| 88 | #define swap_u32(u32) \ |
| 89 | ((uint32_t)(((uint32_t)swap_u16((uint32_t)(u32) >> 16)) | ((uint32_t)swap_u16((uint32_t)(u32)) << 16))) |
| 90 | #endif |
| 91 | |
| 92 | /** Get a value from/to LE16 data */ |
| 93 | #define LE16(x) (x) |
| 94 | /** Get a value from/to LE32 data */ |
| 95 | #define LE32(x) (x) |
| 96 | /** Get a value from/to BE16 data */ |
| 97 | #define BE16(x) swap_u16(x) |
| 98 | /** Get a value from/to BE32 data */ |
| 99 | #define BE32(x) swap_u32(x) |
| 100 | |
| 101 | /** Get byte 0 for BE 16-bit value */ |
| 102 | #define BE16B0(a) ((uint8_t)((a) >> 8)) |
| 103 | /** Get byte 1 for BE 16-bit value */ |
| 104 | #define BE16B1(a) ((uint8_t)((a) >> 0)) |
| 105 | |
| 106 | /** Get byte 0 for BE 32-bit value */ |
| 107 | #define BE32B0(a) ((uint8_t)((a) >> 24)) |
| 108 | /** Get byte 1 for BE 32-bit value */ |
| 109 | #define BE32B1(a) ((uint8_t)((a) >> 16)) |
| 110 | /** Get byte 2 for BE 32-bit value */ |
| 111 | #define BE32B2(a) ((uint8_t)((a) >> 8)) |
| 112 | /** Get byte 3 for BE 32-bit value */ |
| 113 | #define BE32B3(a) ((uint8_t)((a) >> 0)) |
| 114 | |
| 115 | /** Get byte 0 for LE 16-bit value */ |
| 116 | #define LE16B0(a) ((uint8_t)((a) >> 0)) |
| 117 | /** Get byte 1 for LE 16-bit value */ |
| 118 | #define LE16B1(a) ((uint8_t)((a) >> 8)) |
| 119 | |
| 120 | /** Get byte 0 for LE 32-bit value */ |
| 121 | #define LE32B0(a) ((uint8_t)((a) >> 0)) |
| 122 | /** Get byte 1 for LE 32-bit value */ |
| 123 | #define LE32B1(a) ((uint8_t)((a) >> 8)) |
| 124 | /** Get byte 2 for LE 32-bit value */ |
| 125 | #define LE32B2(a) ((uint8_t)((a) >> 16)) |
| 126 | /** Get byte 3 for LE 32-bit value */ |
| 127 | #define LE32B3(a) ((uint8_t)((a) >> 24)) |
| 128 | |
| 129 | #endif /* USB_USER_INCLUDES */ |
| 130 | |
| 131 | #endif /* _USB_INCLUDES_H_ */ |