1 /** @file wl_macros.h 2 * 3 * @brief Common macros are defined here. Must include "wltypes.h" before this file 4 * 5 * Copyright (C) 2014-2017, Marvell International Ltd. 6 * 7 * This software file (the "File") is distributed by Marvell International 8 * Ltd. under the terms of the GNU General Public License Version 2, June 1991 9 * (the "License"). You may use, redistribute and/or modify this File in 10 * accordance with the terms and conditions of the License, a copy of which 11 * is available by writing to the Free Software Foundation, Inc., 12 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the 13 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 14 * 15 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE 17 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about 18 * this warranty disclaimer. 19 */ 20 21 /****************************************************** 22 Change log: 23 03/07/2014: Initial version 24 ******************************************************/ 25 #if !defined(WL_MACROS_H__) 26 #define WL_MACROS_H__ 27 28 #define MACRO_START do { 29 #define MACRO_END } while (0) 30 31 #define WL_REGS8(x) (*(volatile unsigned char *)(x)) 32 #define WL_REGS16(x) (*(volatile unsigned short *)(x)) 33 #define WL_REGS32(x) (*(volatile unsigned int *)(x)) 34 35 #define WL_READ_REGS8(reg,val) ((val) = WL_REGS8(reg)) 36 #define WL_READ_REGS16(reg,val) ((val) = WL_REGS16(reg)) 37 #define WL_READ_REGS32(reg,val) ((val) = WL_REGS32(reg)) 38 #define WL_READ_BYTE(reg,val) ((val) = WL_REGS8(reg)) 39 #define WL_READ_HWORD(reg,val) ((val) = WL_REGS16(reg)) /*half word; */ 40 /*16bits */ 41 #define WL_READ_WORD(reg,val) ((val) = WL_REGS32(reg)) /*32 bits */ 42 #define WL_WRITE_REGS8(reg,val) (WL_REGS8(reg) = (val)) 43 #define WL_WRITE_REGS16(reg,val) (WL_REGS16(reg) = (val)) 44 #define WL_WRITE_REGS32(reg,val) (WL_REGS32(reg) = (val)) 45 #define WL_WRITE_BYTE(reg,val) (WL_REGS8(reg) = (val)) 46 #define WL_WRITE_HWORD(reg,val) (WL_REGS16(reg) = (val)) /*half word; */ 47 /*16bits */ 48 #define WL_WRITE_WORD(reg,val) (WL_REGS32(reg) = (val)) /*32 bits */ 49 #define WL_REGS8_SETBITS(reg, val) (WL_REGS8(reg) |= (UINT8)(val)) 50 #define WL_REGS16_SETBITS(reg, val) (WL_REGS16(reg) |= (UINT16)(val)) 51 #define WL_REGS32_SETBITS(reg, val) (WL_REGS32(reg) |= (val)) 52 53 #define WL_REGS8_CLRBITS(reg, val) (WL_REGS8(reg) = \ 54 (UINT8)(WL_REGS8(reg)&~(val))) 55 56 #define WL_REGS16_CLRBITS(reg, val) (WL_REGS16(reg) = \ 57 (UINT16)(WL_REGS16(reg)&~(val))) 58 59 #define WL_REGS32_CLRBITS(reg, val) (WL_REGS32(reg) = \ 60 (WL_REGS32(reg)&~(val))) 61 62 #define WL_WRITE_CHUNK(dst, src, length) (memcpy((void*) (dst), \ 63 (void*) (src), (length))) 64 /*! 65 * Bitmask macros 66 */ 67 #define WL_BITMASK(nbits) ((0x1 << nbits) - 1) 68 69 /*! 70 * Macro to put the WLAN SoC into sleep mode 71 */ 72 #define WL_GO_TO_SLEEP asm volatile ("MCR p15, 0, r3, c7, c0, 4;") 73 74 /*! 75 * BE vs. LE macros 76 */ 77 #ifdef BE /* Big Endian */ 78 #define SHORT_SWAP(X) (X) 79 #define WORD_SWAP(X) (X) 80 #define LONG_SWAP(X) ((l64)(X)) 81 #else /* Little Endian */ 82 83 #define SHORT_SWAP(X) ((X <<8 ) | (X >> 8)) //!< swap bytes in a 16 bit short 84 85 #define WORD_SWAP(X) (((X)&0xff)<<24)+ \ 86 (((X)&0xff00)<<8)+ \ 87 (((X)&0xff0000)>>8)+ \ 88 (((X)&0xff000000)>>24) //!< swap bytes in a 32 bit word 89 90 #define LONG_SWAP(X) ( (l64) (((X)&0xffULL)<<56)+ \ 91 (((X)&0xff00ULL)<<40)+ \ 92 (((X)&0xff0000ULL)<<24)+ \ 93 (((X)&0xff000000ULL)<<8)+ \ 94 (((X)&0xff00000000ULL)>>8)+ \ 95 (((X)&0xff0000000000ULL)>>24)+ \ 96 (((X)&0xff000000000000ULL)>>40)+ \ 97 (((X)&0xff00000000000000ULL)>>56)) //!< swap bytes in a 64 bit long 98 #endif 99 100 /*! 101 * Alignment macros 102 */ 103 #define ALIGN4(x) (((x) + 3) & ~3) 104 #define ALIGN4BYTE(x) (x=ALIGN4(x)) 105 #define ROUNDUP4US(x) (ALIGN4(x)) 106 107 #ifndef min 108 #define min(a,b) (((a) < (b)) ? (a) : (b)) 109 #endif 110 #ifndef max 111 #define max(a,b) (((a) > (b)) ? (a) : (b)) 112 #endif 113 114 #ifndef MIN 115 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 116 #endif 117 #ifndef MAX 118 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 119 #endif 120 121 #ifndef NELEMENTS 122 #define NELEMENTS(x) (sizeof(x)/sizeof(x[0])) 123 #endif 124 125 #define HWORD_LOW_BYTE(x) ((x) & 0xFF) 126 #define HWORD_HIGH_BYTE(x) (((x) >> 8) & 0xFF) 127 128 #define htons(x) (UINT16)SHORT_SWAP(x) 129 #define htonl(x) (UINT32)WORD_SWAP(x) 130 131 #define ntohs(x) (UINT16)SHORT_SWAP(x) 132 #define ntohl(x) (UINT32)WORD_SWAP(x) 133 134 #define CEIL_aByb(a, b) ((a + b - 1) / b) 135 136 #endif /* _WL_MACROS_H_ */ 137