]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo_Hardware_Platform/CMSIS/hw_reg_io.h
Rename the SmartFusion2 demo directory.
[freertos] / FreeRTOS / Demo / CORTEX_SmartFusion2_M2S050_SoftConsole / RTOSDemo_Hardware_Platform / CMSIS / hw_reg_io.h
1 /*******************************************************************************\r
2  * (c) Copyright 2011-2013 Microsemi SoC Products Group. All rights reserved.\r
3  *\r
4  *  SmartFusion2 Cortex Microcontroller Software Interface - Peripheral\r
5  *  Access Layer.\r
6  *\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
9  *  Cortex-M3 CPU.\r
10  *\r
11  * SVN $Revision: 5263 $\r
12  * SVN $Date: 2013-03-21 14:44:58 +0000 (Thu, 21 Mar 2013) $\r
13  */\r
14 \r
15 #ifndef HW_REG_IO_H_\r
16 #define HW_REG_IO_H_\r
17 \r
18 #include <stdint.h>                       /* Include standard types */\r
19 \r
20 #if defined ( __CC_ARM   )\r
21   #define __INLINE         __inline       /*!< inline keyword for ARM Compiler       */\r
22 \r
23 #elif defined ( __ICCARM__ )\r
24   #define __INLINE        inline          /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */\r
25 \r
26 #elif defined   (  __GNUC__  )\r
27   #define __INLINE        inline          /*!< inline keyword for GNU Compiler       */\r
28 #endif\r
29 \r
30 /*****************************************************************************************\r
31  * Definitions for register access\r
32  */\r
33 \r
34 #define HW_REG(addr)            (*((volatile uint32_t *) (addr)))\r
35 \r
36 static __INLINE void write_reg32(volatile uint32_t * reg, uint32_t val)\r
37 {\r
38     HW_REG(reg) = val;\r
39 }\r
40 static __INLINE void write_reg16(volatile uint16_t * reg, uint16_t val)\r
41 {\r
42     HW_REG(reg) = val;\r
43 }\r
44 static __INLINE void write_reg8(volatile uint8_t * reg, uint8_t val)\r
45 {\r
46     HW_REG(reg) = val;\r
47 }\r
48 \r
49 static __INLINE uint32_t read_reg32(volatile uint32_t * reg)\r
50 {\r
51     return ( HW_REG(reg) );\r
52 }\r
53 static __INLINE uint16_t read_reg16(volatile uint16_t * reg)\r
54 {\r
55     return ( HW_REG(reg) );\r
56 }\r
57 static __INLINE uint8_t read_reg8(volatile uint8_t * reg)\r
58 {\r
59     return ( HW_REG(reg) );\r
60 }\r
61 /*****************************************************************************************\r
62  * Definitions for register bits access using bit-band aliases for Cortex-M3 \r
63  */\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
66 \r
67 /*****************************************************************************************\r
68  * Functions to set a bit field in Cortex-M3 \r
69  */\r
70 static __INLINE void set_bit_reg32(volatile uint32_t * reg, uint8_t bit)\r
71 {\r
72     HW_REG_BIT(reg,bit) = 0x1;\r
73 }\r
74 static __INLINE void set_bit_reg16(volatile uint16_t * reg, uint8_t bit)\r
75 {\r
76     HW_REG_BIT(reg,bit) = 0x1;\r
77 }\r
78 static __INLINE void set_bit_reg8(volatile uint8_t * reg, uint8_t bit)\r
79 {\r
80     HW_REG_BIT(reg,bit) = 0x1;\r
81 }\r
82 /*****************************************************************************************\r
83  * Functions to clear a bit field in Cortex-M3\r
84  */\r
85 static __INLINE void clear_bit_reg32(volatile uint32_t * reg, uint8_t bit)\r
86 {\r
87     HW_REG_BIT(reg,bit) = 0x0;\r
88 }\r
89 static __INLINE void clear_bit_reg16(volatile uint16_t * reg, uint8_t bit)\r
90 {\r
91     HW_REG_BIT(reg,bit) = 0x0;\r
92 }\r
93 static __INLINE void clear_bit_reg8(volatile uint8_t * reg, uint8_t bit)\r
94 {\r
95     HW_REG_BIT(reg,bit) = 0x0;\r
96 }\r
97 /*****************************************************************************************\r
98  * Functions to read a bit field in Cortex-M3\r
99  */\r
100 static __INLINE uint8_t read_bit_reg32(volatile uint32_t * reg, uint8_t bit)\r
101 {\r
102     return (HW_REG_BIT(reg,bit));\r
103 }\r
104 static __INLINE uint8_t read_bit_reg16(volatile uint16_t * reg, uint8_t bit)\r
105 {\r
106     return (HW_REG_BIT(reg,bit));\r
107 }\r
108 static __INLINE uint8_t read_bit_reg8(volatile uint8_t * reg, uint8_t bit)\r
109 {\r
110     return (HW_REG_BIT(reg,bit));\r
111 }\r
112 \r
113 #endif /* HW_REG_IO_H_ */\r