1f9f848faSopenharmony_ci/* 2f9f848faSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause 3f9f848faSopenharmony_ci * 4f9f848faSopenharmony_ci * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 5f9f848faSopenharmony_ci * 6f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without 7f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions 8f9f848faSopenharmony_ci * are met: 9f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 10f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer. 11f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 12f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 13f9f848faSopenharmony_ci * documentation and/or other materials provided with the distribution. 14f9f848faSopenharmony_ci * 15f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16f9f848faSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17f9f848faSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18f9f848faSopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19f9f848faSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20f9f848faSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21f9f848faSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22f9f848faSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23f9f848faSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24f9f848faSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25f9f848faSopenharmony_ci * SUCH DAMAGE. 26f9f848faSopenharmony_ci */ 27f9f848faSopenharmony_ci 28f9f848faSopenharmony_ci#ifndef _USB_ENDIAN_H_ 29f9f848faSopenharmony_ci#define _USB_ENDIAN_H_ 30f9f848faSopenharmony_ci 31f9f848faSopenharmony_ci/* 32f9f848faSopenharmony_ci * Declare the basic USB record types. USB records have an alignment 33f9f848faSopenharmony_ci * of 1 byte and are always packed. 34f9f848faSopenharmony_ci */ 35f9f848faSopenharmony_citypedef uint8_t uByte; 36f9f848faSopenharmony_citypedef uint8_t uWord[2]; 37f9f848faSopenharmony_citypedef uint8_t uDWord[4]; 38f9f848faSopenharmony_citypedef uint8_t uQWord[8]; 39f9f848faSopenharmony_ci 40f9f848faSopenharmony_ci/* 41f9f848faSopenharmony_ci * Define a set of macros that can get and set data independent of 42f9f848faSopenharmony_ci * CPU endianness and CPU alignment requirements: 43f9f848faSopenharmony_ci */ 44f9f848faSopenharmony_ci#define UGETB(w) \ 45f9f848faSopenharmony_ci ((w)[0]) 46f9f848faSopenharmony_ci 47f9f848faSopenharmony_ci#define UGETW(w) \ 48f9f848faSopenharmony_ci ((w)[0] | \ 49f9f848faSopenharmony_ci (((uint16_t)((w)[1])) << 8)) 50f9f848faSopenharmony_ci 51f9f848faSopenharmony_ci#define UGETDW(w) \ 52f9f848faSopenharmony_ci ((w)[0] | \ 53f9f848faSopenharmony_ci (((uint16_t)((w)[1])) << 8) | \ 54f9f848faSopenharmony_ci (((uint32_t)((w)[2])) << 16) | \ 55f9f848faSopenharmony_ci (((uint32_t)((w)[3])) << 24)) 56f9f848faSopenharmony_ci 57f9f848faSopenharmony_ci#define UGETQW(w) \ 58f9f848faSopenharmony_ci ((w)[0] | \ 59f9f848faSopenharmony_ci (((uint16_t)((w)[1])) << 8) | \ 60f9f848faSopenharmony_ci (((uint32_t)((w)[2])) << 16) | \ 61f9f848faSopenharmony_ci (((uint32_t)((w)[3])) << 24) | \ 62f9f848faSopenharmony_ci (((uint64_t)((w)[4])) << 32) | \ 63f9f848faSopenharmony_ci (((uint64_t)((w)[5])) << 40) | \ 64f9f848faSopenharmony_ci (((uint64_t)((w)[6])) << 48) | \ 65f9f848faSopenharmony_ci (((uint64_t)((w)[7])) << 56)) 66f9f848faSopenharmony_ci 67f9f848faSopenharmony_ci#define USETB(w,v) do { \ 68f9f848faSopenharmony_ci (w)[0] = (uint8_t)(v); \ 69f9f848faSopenharmony_ci} while (0) 70f9f848faSopenharmony_ci 71f9f848faSopenharmony_ci#define USETW(w,v) do { \ 72f9f848faSopenharmony_ci (w)[0] = (uint8_t)(v); \ 73f9f848faSopenharmony_ci (w)[1] = (uint8_t)((v) >> 8); \ 74f9f848faSopenharmony_ci} while (0) 75f9f848faSopenharmony_ci 76f9f848faSopenharmony_ci#define USETDW(w,v) do { \ 77f9f848faSopenharmony_ci (w)[0] = (uint8_t)(v); \ 78f9f848faSopenharmony_ci (w)[1] = (uint8_t)((v) >> 8); \ 79f9f848faSopenharmony_ci (w)[2] = (uint8_t)((v) >> 16); \ 80f9f848faSopenharmony_ci (w)[3] = (uint8_t)((v) >> 24); \ 81f9f848faSopenharmony_ci} while (0) 82f9f848faSopenharmony_ci 83f9f848faSopenharmony_ci#define USETQW(w,v) do { \ 84f9f848faSopenharmony_ci (w)[0] = (uint8_t)(v); \ 85f9f848faSopenharmony_ci (w)[1] = (uint8_t)((v) >> 8); \ 86f9f848faSopenharmony_ci (w)[2] = (uint8_t)((v) >> 16); \ 87f9f848faSopenharmony_ci (w)[3] = (uint8_t)((v) >> 24); \ 88f9f848faSopenharmony_ci (w)[4] = (uint8_t)((v) >> 32); \ 89f9f848faSopenharmony_ci (w)[5] = (uint8_t)((v) >> 40); \ 90f9f848faSopenharmony_ci (w)[6] = (uint8_t)((v) >> 48); \ 91f9f848faSopenharmony_ci (w)[7] = (uint8_t)((v) >> 56); \ 92f9f848faSopenharmony_ci} while (0) 93f9f848faSopenharmony_ci 94f9f848faSopenharmony_ci#define USETW2(w,b1,b0) do { \ 95f9f848faSopenharmony_ci (w)[0] = (uint8_t)(b0); \ 96f9f848faSopenharmony_ci (w)[1] = (uint8_t)(b1); \ 97f9f848faSopenharmony_ci} while (0) 98f9f848faSopenharmony_ci 99f9f848faSopenharmony_ci#define USETW4(w,b3,b2,b1,b0) do { \ 100f9f848faSopenharmony_ci (w)[0] = (uint8_t)(b0); \ 101f9f848faSopenharmony_ci (w)[1] = (uint8_t)(b1); \ 102f9f848faSopenharmony_ci (w)[2] = (uint8_t)(b2); \ 103f9f848faSopenharmony_ci (w)[3] = (uint8_t)(b3); \ 104f9f848faSopenharmony_ci} while (0) 105f9f848faSopenharmony_ci 106f9f848faSopenharmony_ci#define USETW8(w,b7,b6,b5,b4,b3,b2,b1,b0) do { \ 107f9f848faSopenharmony_ci (w)[0] = (uint8_t)(b0); \ 108f9f848faSopenharmony_ci (w)[1] = (uint8_t)(b1); \ 109f9f848faSopenharmony_ci (w)[2] = (uint8_t)(b2); \ 110f9f848faSopenharmony_ci (w)[3] = (uint8_t)(b3); \ 111f9f848faSopenharmony_ci (w)[4] = (uint8_t)(b4); \ 112f9f848faSopenharmony_ci (w)[5] = (uint8_t)(b5); \ 113f9f848faSopenharmony_ci (w)[6] = (uint8_t)(b6); \ 114f9f848faSopenharmony_ci (w)[7] = (uint8_t)(b7); \ 115f9f848faSopenharmony_ci} while (0) 116f9f848faSopenharmony_ci 117f9f848faSopenharmony_ci#endif /* _USB_ENDIAN_H_ */ 118