source: svn/trunk/newcon3bcm2_21bu/magnum/basemodules/reg/breg_endian.h @ 49

Last change on this file since 49 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 3.4 KB
Line 
1/***************************************************************************
2 *         Copyright (c) 2003, Broadcom Corporation
3 *         All Rights Reserved
4 *         Confidential Property of Broadcom Corporation
5 *
6 *      THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *      AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *      EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: breg_endian.h $
11 * $brcm_Revision: Hydra_Software_Devel/5 $
12 * $brcm_Date: 1/16/04 10:37a $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/basemodules/reg/breg_endian.h $
19 *
20 * Hydra_Software_Devel/5   1/16/04 10:37a vsilyaev
21 * PR 9372: Replaced BREG_BEXX on BE and BREG_LEXX on LE plaforms with no-
22 * ops.
23 *
24 * Hydra_Software_Devel/4   4/4/03 3:16p marcusk
25 * Updated references of BSTD_XXX_ENDIAN to BSTD_ENDIAN_XXX
26 *
27 * Hydra_Software_Devel/3   3/31/03 8:57a marcusk
28 * Added comments.
29 *
30 * Hydra_Software_Devel/2   3/5/03 4:19p marcusk
31 * Fixed minor issues (got it to compile).
32 *
33 * Hydra_Software_Devel/1   3/5/03 3:34p marcusk
34 * Initial version.
35 *
36 ***************************************************************************/
37
38/*= Module Overview ********************************************************
39This module supplies standard macros that are used to correct endianess for
40hardware registers that do not match the endian-ness of the CPU.  An example
41of this would be a register that is always big endian regardless of whether
42the CPU was little endian or big endian.
43
44It is recommended that these macros be used on a variable after
45the BREG_ReadXX() functions are called, NOT around the functions themselves.
46This is to prevent executing the BREG_ReadXX() multiple times inside the
47macro (which could also cause inconsistent results if the register happens
48to change while executing the macro).
49
50These macros depend on the BSTD_CPU_ENDIAN define to be set properly.
51
52For a big endian CPU: BSTD_CPU_ENDIAN should equal BSTD_ENDIAN_BIG
53For a little endian CPU: BSTD_CPU_ENDIAN should equal BSTD_ENDIAN_LITTLE
54***************************************************************************/
55
56#ifndef BREG_ENDIAN_H
57#define BREG_ENDIAN_H
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63/*
64This macro is used to swap bytes of a 32 bit value.
65*/
66#define BREG_SWAP32( a )  do{a=((a&0xFF)<<24|(a&0xFF00)<<8|(a&0xFF0000)>>8|(a&0xFF000000)>>24);}while(0)
67
68/*
69This macro is used to swap bytes of a 16 bit value.
70*/
71#define BREG_SWAP16( a )  do{a=((a&0xFF)<<8|(a&0xFF00)>>8);}while(0)
72
73#if BSTD_CPU_ENDIAN == BSTD_ENDIAN_BIG
74
75/*
76This macro is used to ensure that a 32-bit value is properly formatted for
77a big endian register access.
78*/
79#define BREG_BE32( value )
80
81/*
82This macro is used to ensure that a 16-bit value is properly formatted for
83a big endian register access.
84*/
85#define BREG_BE16( value )
86
87/*
88This macro is used to ensure that a 32-bit value is properly formatted for
89a little endian register access.
90*/
91#define BREG_LE32( value ) BREG_SWAP32( value )
92
93/*
94This macro is used to ensure that a 16-bit value is properly formatted for
95a little endian register access.
96*/
97#define BREG_LE16( value ) BREG_SWAP16( value )
98
99#else
100#define BREG_BE32( value ) BREG_SWAP32( value )
101#define BREG_BE16( value ) BREG_SWAP16( value )
102#define BREG_LE32( value )
103#define BREG_LE16( value )
104#endif
105
106#ifdef __cplusplus
107}
108#endif
109 
110#endif
111/* End of File */
112
113
114
Note: See TracBrowser for help on using the repository browser.