1 /*******************************************************************************
2  * Copyright 2019-2020 Microchip FPGA Embedded Systems Solutions.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * MPFS HAL Embedded Software
7  *
8  */
9 /***************************************************************************//**
10  *
11  * Hardware registers access functions.
12  * The implementation of these function is platform and tool-chain specific.
13  * The functions declared here are implemented using assembler as part of the
14  * processor/tool-chain specific HAL.
15  *
16  */
17 #ifndef HW_REG_ACCESS
18 #define HW_REG_ACCESS
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 
25 #include "cpu_types.h"
26 /***************************************************************************//**
27  * HW_set_32bit_reg is used to write the content of a 32 bits wide peripheral
28  * register.
29  *
30  * @param reg_addr  Address in the processor's memory map of the register to
31  *                  write.
32  * @param value     Value to be written into the peripheral register.
33  */
34 void
35 HW_set_32bit_reg
36 (
37     addr_t reg_addr,
38     uint32_t value
39 );
40 
41 /***************************************************************************//**
42  * HW_get_32bit_reg is used to read the content of a 32 bits wide peripheral
43  * register.
44  *
45  * @param reg_addr  Address in the processor's memory map of the register to
46  *                  read.
47  * @return          32 bits value read from the peripheral register.
48  */
49 uint32_t
50 HW_get_32bit_reg
51 (
52     addr_t reg_addr
53 );
54 
55 /***************************************************************************//**
56  * HW_set_32bit_reg_field is used to set the content of a field in a 32 bits
57  * wide peripheral register.
58  *
59  * @param reg_addr  Address in the processor's memory map of the register to
60  *                  be written.
61  * @param shift     Bit offset of the register field to be read within the
62  *                  register.
63  * @param mask      Bit mask to be applied to the raw register value to filter
64  *                  out the other register fields values.
65  * @param value     Value to be written in the specified field.
66  */
67 void
68 HW_set_32bit_reg_field
69 (
70     addr_t reg_addr,
71     int_fast8_t shift,
72     uint32_t mask,
73     uint32_t value
74 );
75 
76 /***************************************************************************//**
77  * HW_get_32bit_reg_field is used to read the content of a field out of a
78  * 32 bits wide peripheral register.
79  *
80  * @param reg_addr  Address in the processor's memory map of the register to
81  *                  read.
82  * @param shift     Bit offset of the register field to be written within the
83  *                  register.
84  * @param mask      Bit mask to be applied to the raw register value to filter
85  *                  out the other register fields values.
86  *
87  * @return          32 bits value containing the register field value specified
88  *                  as parameter.
89  */
90 uint32_t
91 HW_get_32bit_reg_field
92 (
93     addr_t reg_addr,
94     int_fast8_t shift,
95     uint32_t mask
96 );
97 
98 /***************************************************************************//**
99  * HW_set_16bit_reg is used to write the content of a 16 bits wide peripheral
100  * register.
101  *
102  * @param reg_addr  Address in the processor's memory map of the register to
103  *                  write.
104  * @param value     Value to be written into the peripheral register.
105  */
106 void
107 HW_set_16bit_reg
108 (
109     addr_t reg_addr,
110     uint_fast16_t value
111 );
112 
113 /***************************************************************************//**
114  * HW_get_16bit_reg is used to read the content of a 16 bits wide peripheral
115  * register.
116  *
117  * @param reg_addr  Address in the processor's memory map of the register to
118  *                  read.
119  * @return          16 bits value read from the peripheral register.
120  */
121 uint16_t
122 HW_get_16bit_reg
123 (
124     addr_t reg_addr
125 );
126 
127 /***************************************************************************//**
128  * HW_set_16bit_reg_field is used to set the content of a field in a 16 bits
129  * wide peripheral register.
130  *
131  * @param reg_addr  Address in the processor's memory map of the register to
132  *                  be written.
133  * @param shift     Bit offset of the register field to be read within the
134  *                  register.
135  * @param mask      Bit mask to be applied to the raw register value to filter
136  *                  out the other register fields values.
137  * @param value     Value to be written in the specified field.
138  */
139 void HW_set_16bit_reg_field
140 (
141     addr_t reg_addr,
142     int_fast8_t shift,
143     uint_fast16_t mask,
144     uint_fast16_t value
145 );
146 
147 /***************************************************************************//**
148  * HW_get_16bit_reg_field is used to read the content of a field from a
149  * 16 bits wide peripheral register.
150  *
151  * @param reg_addr  Address in the processor's memory map of the register to
152  *                  read.
153  * @param shift     Bit offset of the register field to be written within the
154  *                  register.
155  * @param mask      Bit mask to be applied to the raw register value to filter
156  *                  out the other register fields values.
157  *
158  * @return          16 bits value containing the register field value specified
159  *                  as parameter.
160  */
161 uint16_t HW_get_16bit_reg_field
162 (
163     addr_t reg_addr,
164     int_fast8_t shift,
165     uint_fast16_t mask
166 );
167 
168 /***************************************************************************//**
169  * HW_set_8bit_reg is used to write the content of a 8 bits wide peripheral
170  * register.
171  *
172  * @param reg_addr  Address in the processor's memory map of the register to
173  *                  write.
174  * @param value     Value to be written into the peripheral register.
175  */
176 void
177 HW_set_8bit_reg
178 (
179     addr_t reg_addr,
180     uint_fast8_t value
181 );
182 
183 /***************************************************************************//**
184  * HW_get_8bit_reg is used to read the content of a 8 bits wide peripheral
185  * register.
186  *
187  * @param reg_addr  Address in the processor's memory map of the register to
188  *                  read.
189  * @return          8 bits value read from the peripheral register.
190  */
191 uint8_t
192 HW_get_8bit_reg
193 (
194     addr_t reg_addr
195 );
196 
197 /***************************************************************************//**
198  * HW_set_8bit_reg_field is used to set the content of a field in a 8 bits
199  * wide peripheral register.
200  *
201  * @param reg_addr  Address in the processor's memory map of the register to
202  *                  be written.
203  * @param shift     Bit offset of the register field to be read within the
204  *                  register.
205  * @param mask      Bit mask to be applied to the raw register value to filter
206  *                  out the other register fields values.
207  * @param value     Value to be written in the specified field.
208  */
209 void HW_set_8bit_reg_field
210 (
211     addr_t reg_addr,
212     int_fast8_t shift,
213     uint_fast8_t mask,
214     uint_fast8_t value
215 );
216 
217 /***************************************************************************//**
218  * HW_get_8bit_reg_field is used to read the content of a field from a
219  * 8 bits wide peripheral register.
220  *
221  * @param reg_addr  Address in the processor's memory map of the register to
222  *                  read.
223  * @param shift     Bit offset of the register field to be written within the
224  *                  register.
225  * @param mask      Bit mask to be applied to the raw register value to filter
226  *                  out the other register fields values.
227  *
228  * @return          8 bits value containing the register field value specified
229  *                  as parameter.
230  */
231 uint8_t HW_get_8bit_reg_field
232 (
233     addr_t reg_addr,
234     int_fast8_t shift,
235     uint_fast8_t mask
236 );
237 
238 
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif /* HW_REG_ACCESS */
245 
246 
247 
248