1 /*******************************************************************************
\r
2 * (c) Copyright 2011-2013 Microsemi SoC Products Group. All rights reserved.
\r
4 * SmartFusion2 Cortex Microcontroller Software Interface - Peripheral
\r
7 * This file provides interfaces to perform register and register bit level
\r
8 * read / write operations. These interfaces support bit-banding in case of
\r
11 * SVN $Revision: 5263 $
\r
12 * SVN $Date: 2013-03-21 14:44:58 +0000 (Thu, 21 Mar 2013) $
\r
15 #ifndef HW_REG_IO_H_
\r
16 #define HW_REG_IO_H_
\r
18 #include <stdint.h> /* Include standard types */
\r
20 #if defined ( __CC_ARM )
\r
21 #define __INLINE __inline /*!< inline keyword for ARM Compiler */
\r
23 #elif defined ( __ICCARM__ )
\r
24 #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */
\r
26 #elif defined ( __GNUC__ )
\r
27 #define __INLINE inline /*!< inline keyword for GNU Compiler */
\r
30 /*****************************************************************************************
\r
31 * Definitions for register access
\r
34 #define HW_REG(addr) (*((volatile uint32_t *) (addr)))
\r
36 static __INLINE void write_reg32(volatile uint32_t * reg, uint32_t val)
\r
40 static __INLINE void write_reg16(volatile uint16_t * reg, uint16_t val)
\r
44 static __INLINE void write_reg8(volatile uint8_t * reg, uint8_t val)
\r
49 static __INLINE uint32_t read_reg32(volatile uint32_t * reg)
\r
51 return ( HW_REG(reg) );
\r
53 static __INLINE uint16_t read_reg16(volatile uint16_t * reg)
\r
55 return ( HW_REG(reg) );
\r
57 static __INLINE uint8_t read_reg8(volatile uint8_t * reg)
\r
59 return ( HW_REG(reg) );
\r
61 /*****************************************************************************************
\r
62 * Definitions for register bits access using bit-band aliases for Cortex-M3
\r
64 #define BITBAND(addr,bitnum) (((uint32_t)addr & 0xF0000000)+0x02000000+(((uint32_t)addr & 0xFFFFF)<<5)+(bitnum<<2))
\r
65 #define HW_REG_BIT(reg,bitnum) (*(volatile unsigned int *)((BITBAND(reg,bitnum))))
\r
67 /*****************************************************************************************
\r
68 * Functions to set a bit field in Cortex-M3
\r
70 static __INLINE void set_bit_reg32(volatile uint32_t * reg, uint8_t bit)
\r
72 HW_REG_BIT(reg,bit) = 0x1;
\r
74 static __INLINE void set_bit_reg16(volatile uint16_t * reg, uint8_t bit)
\r
76 HW_REG_BIT(reg,bit) = 0x1;
\r
78 static __INLINE void set_bit_reg8(volatile uint8_t * reg, uint8_t bit)
\r
80 HW_REG_BIT(reg,bit) = 0x1;
\r
82 /*****************************************************************************************
\r
83 * Functions to clear a bit field in Cortex-M3
\r
85 static __INLINE void clear_bit_reg32(volatile uint32_t * reg, uint8_t bit)
\r
87 HW_REG_BIT(reg,bit) = 0x0;
\r
89 static __INLINE void clear_bit_reg16(volatile uint16_t * reg, uint8_t bit)
\r
91 HW_REG_BIT(reg,bit) = 0x0;
\r
93 static __INLINE void clear_bit_reg8(volatile uint8_t * reg, uint8_t bit)
\r
95 HW_REG_BIT(reg,bit) = 0x0;
\r
97 /*****************************************************************************************
\r
98 * Functions to read a bit field in Cortex-M3
\r
100 static __INLINE uint8_t read_bit_reg32(volatile uint32_t * reg, uint8_t bit)
\r
102 return (HW_REG_BIT(reg,bit));
\r
104 static __INLINE uint8_t read_bit_reg16(volatile uint16_t * reg, uint8_t bit)
\r
106 return (HW_REG_BIT(reg,bit));
\r
108 static __INLINE uint8_t read_bit_reg8(volatile uint8_t * reg, uint8_t bit)
\r
110 return (HW_REG_BIT(reg,bit));
\r
113 #endif /* HW_REG_IO_H_ */
\r