/* =================================================================
 *   Copyright (C) 2013 Texas Instruments Incorporated
 *
 *   All rights reserved. Property of Texas Instruments Incorporated.
 *   Restricted rights to use, duplicate or disclose this code are
 *   granted through contract.
 *
 *   The program may not be used without the written permission
 *   of Texas Instruments Incorporated or against the terms and
 *   conditionsstipulated in the agreement under which this program
 *   has been supplied.
 * =================================================================*/
 /*
 * hw_types.h
 */


#ifndef _HW_TYPES_H_
#define _HW_TYPES_H_

#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
extern "C"
{
#endif


/******************************************************************************
 *
 * Macros for hardware access, both direct and via the bit-band region.
 *
 ******************************************************************************/
#define HWREG(x) \
    (*((volatile unsigned int *) (x)))
#define HWREGH(x) \
    (*((volatile unsigned short *) (x)))
#define HWREGB(x) \
    (*((volatile unsigned char *) (x)))
#define HWREGBITW(x, b)                                    \
    HWREG(((unsigned int) (x) & 0xF0000000) | 0x02000000 | \
          (((unsigned int) (x) & 0x000FFFFF) << 5) | ((b) << 2))
#define HWREGBITH(x, b)                                     \
    HWREGH(((unsigned int) (x) & 0xF0000000) | 0x02000000 | \
           (((unsigned int) (x) & 0x000FFFFF) << 5) | ((b) << 2))
#define HWREGBITB(x, b)                                     \
    HWREGB(((unsigned int) (x) & 0xF0000000) | 0x02000000 | \
           (((unsigned int) (x) & 0x000FFFFF) << 5) | ((b) << 2))

#define FLD_MASK(start, end) 	 (((1 << ((start) - (end) + 1)) - 1) << (end))
#define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
#define FLD_GET(val, start, end) (((val) & FLD_MASK(start, end)) >> (end))
#define FLD_MOD(orig, val, start, end) \
				 (((orig) & ~FLD_MASK(start, end)) | FLD_VAL(val, start, end))


#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
}
#endif

#endif // __HW_TYPES_H__
