1 /*******************************************************************************
\r
2 * (c) Copyright 2007-2013 Microsemi SoC Products Group. All rights reserved.
\r
4 * Hardware registers access macros.
\r
6 * THE MACROS DEFINED IN THIS FILE ARE DEPRECATED. DO NOT USED FOR NEW
\r
9 * These macros are used to access peripheral's registers. They allow access to
\r
10 * 8, 16 and 32 bit wide registers. All accesses to peripheral registers should
\r
11 * be done through these macros in order to ease porting accross different
\r
12 * processors/bus architectures.
\r
14 * Some of these macros also allow to access a specific register field.
\r
16 * SVN $Revision: 5258 $
\r
17 * SVN $Date: 2013-03-21 12:41:02 +0000 (Thu, 21 Mar 2013) $
\r
19 #ifndef __HW_REGISTER_MACROS_H
\r
20 #define __HW_REGISTER_MACROS_H 1
\r
22 /*------------------------------------------------------------------------------
\r
23 * 32 bits registers access:
\r
25 #define HW_get_uint32_reg(BASE_ADDR, REG_OFFSET) (*((uint32_t volatile *)(BASE_ADDR + REG_OFFSET##_REG_OFFSET)))
\r
27 #define HW_set_uint32_reg(BASE_ADDR, REG_OFFSET, VALUE) (*((uint32_t volatile *)(BASE_ADDR + REG_OFFSET##_REG_OFFSET)) = (VALUE))
\r
29 #define HW_set_uint32_reg_field(BASE_ADDR, FIELD, VALUE) \
\r
30 (*((uint32_t volatile *)(BASE_ADDR + FIELD##_OFFSET)) = \
\r
34 (*((uint32_t volatile *)(BASE_ADDR + FIELD##_OFFSET))) & ~FIELD##_MASK) | \
\r
35 (uint32_t)(((VALUE) << FIELD##_SHIFT) & FIELD##_MASK) \
\r
39 #define HW_get_uint32_reg_field( BASE_ADDR, FIELD ) \
\r
40 (( (*((uint32_t volatile *)(BASE_ADDR + FIELD##_OFFSET))) & FIELD##_MASK) >> FIELD##_SHIFT)
\r
42 /*------------------------------------------------------------------------------
\r
43 * 32 bits memory access:
\r
45 #define HW_get_uint32(BASE_ADDR) (*((uint32_t volatile *)(BASE_ADDR)))
\r
47 #define HW_set_uint32(BASE_ADDR, VALUE) (*((uint32_t volatile *)(BASE_ADDR)) = (VALUE))
\r
49 /*------------------------------------------------------------------------------
\r
50 * 16 bits registers access:
\r
52 #define HW_get_uint16_reg(BASE_ADDR, REG_OFFSET) (*((uint16_t volatile *)(BASE_ADDR + REG_OFFSET##_REG_OFFSET)))
\r
54 #define HW_set_uint16_reg(BASE_ADDR, REG_OFFSET, VALUE) (*((uint16_t volatile *)(BASE_ADDR + REG_OFFSET##_REG_OFFSET)) = (VALUE))
\r
56 #define HW_set_uint16_reg_field(BASE_ADDR, FIELD, VALUE) \
\r
57 (*((uint16_t volatile *)(BASE_ADDR + FIELD##_OFFSET)) = \
\r
61 (*((uint16_t volatile *)(BASE_ADDR + FIELD##_OFFSET))) & ~FIELD##_MASK) | \
\r
62 (uint16_t)(((VALUE) << FIELD##_SHIFT) & FIELD##_MASK) \
\r
66 #define HW_get_uint16_reg_field( BASE_ADDR, FIELD ) \
\r
67 (( (*((uint16_t volatile *)(BASE_ADDR + FIELD##_OFFSET))) & FIELD##_MASK) >> FIELD##_SHIFT)
\r
69 /*------------------------------------------------------------------------------
\r
70 * 8 bits registers access:
\r
72 #define HW_get_uint8_reg(BASE_ADDR, REG_OFFSET) (*((uint8_t volatile *)(BASE_ADDR + REG_OFFSET##_REG_OFFSET)))
\r
74 #define HW_set_uint8_reg(BASE_ADDR, REG_OFFSET, VALUE) (*((uint8_t volatile *)(BASE_ADDR + REG_OFFSET##_REG_OFFSET)) = (VALUE))
\r
76 #define HW_set_uint8_reg_field(BASE_ADDR, FIELD, VALUE) \
\r
77 (*((uint8_t volatile *)(BASE_ADDR + FIELD##_OFFSET)) = \
\r
81 (*((uint8_t volatile *)(BASE_ADDR + FIELD##_OFFSET))) & ~FIELD##_MASK) | \
\r
82 (uint8_t)(((VALUE) << FIELD##_SHIFT) & FIELD##_MASK) \
\r
86 #define HW_get_uint8_reg_field( BASE_ADDR, FIELD ) \
\r
87 (( (*((uint8_t volatile *)(BASE_ADDR + FIELD##_OFFSET))) & FIELD##_MASK) >> FIELD##_SHIFT)
\r
89 /*------------------------------------------------------------------------------
\r
90 * 8 bits memory access:
\r
92 #define HW_get_uint8(BASE_ADDR) (*((uint8_t volatile *)(BASE_ADDR)))
\r
94 #define HW_set_uint8(BASE_ADDR, VALUE) (*((uint8_t volatile *)(BASE_ADDR)) = (VALUE))
\r
96 #endif /* __HW_REGISTER_MACROS_H */
\r