1 /*
2  * Copyright (c) 2023, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  *    list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  *    contributors may be used to endorse or promote products derived from this
19  *    software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef NRF_VPR_CSR_VEVIF_H__
35 #define NRF_VPR_CSR_VEVIF_H__
36 
37 #include <nrfx.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * @defgroup nrf_vpr_csr_vevif_hal VPR CSR VEVIF HAL
45  * @{
46  * @ingroup nrf_vpr
47  * @brief   Hardware access layer for managing the VPR RISC-V CPU Control
48  *          and Status Registers for VPR Event Interface (VPR CSR VEVIF).
49  */
50 
51 /** @brief Number of VEVIF events/tasks. */
52 #define NRF_VPR_CSR_VEVIF_EVENT_TASK_COUNT VPR_VEVIF_EVENT_MaxCount
53 
54 /**
55  * @brief Function for getting mask of pending VEVIF tasks.
56  *
57  * @return Mask of pending VEVIF tasks.
58  */
59 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_tasks_get(void);
60 
61 /**
62  * @brief Function for clearing mask of pending VEVIF tasks.
63  *
64  * @param[in] mask Mask of VEVIF tasks to be cleared.
65  */
66 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_tasks_clear(uint32_t mask);
67 
68 /**
69  * @brief Function for setting pending VEVIF tasks.
70  *
71  * @param[in] value VEVIF tasks value to be set.
72  */
73 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_tasks_set(uint32_t value);
74 
75 /**
76  * @brief Function for getting mask of triggered VEVIF events.
77  *
78  * @return Mask of triggered VEVIF events.
79  */
80 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_events_get(void);
81 
82 /**
83  * @brief Function for setting triggered VEVIF events.
84  *
85  * @param[in] value VEVIF events value to be set.
86  */
87 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_events_set(uint32_t value);
88 
89 /**
90  * @brief Function for triggering VEVIF events.
91  *
92  * @param[in] mask Mask of VEVIF events to be triggered.
93  */
94 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_events_trigger(uint32_t mask);
95 
96 /**
97  * @brief Function for setting buffered triggered VEVIF events.
98  *
99  * @param[in] value Buffered VEVIF events value to be set.
100  */
101 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_events_buffered_set(uint32_t value);
102 
103 /**
104  * @brief Function for retrieving the dirty status of buffered VEVIF events.
105  *
106  * @retval true  Buffer is dirty.
107  * @retval false Buffer is clean.
108  */
109 NRF_STATIC_INLINE bool nrf_vpr_csr_vevif_events_buffered_dirty_check(void);
110 
111 /**
112  * @brief Function for getting the subscribe configuration for VEVIF.
113  *
114  * @return Mask of tasks with enabled subscription.
115  */
116 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_subscribe_get(void);
117 
118 /**
119  * @brief Function for setting the subscribe configuration for VEVIF.
120  *
121  * @param[in] value VEVIF subscription configuration mask to be set.
122  */
123 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_subscribe_set(uint32_t value);
124 
125 /**
126  * @brief Function for getting the publish configuration for VEVIF.
127  *
128  * @return Mask of events with enabled publication.
129  */
130 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_publish_get(void);
131 
132 /**
133  * @brief Function for setting the publish configuration for VEVIF.
134  *
135  * @param[in] value VEVIF publication configuration mask to be set.
136  */
137 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_publish_set(uint32_t value);
138 
139 /**
140  * @brief Function for enabling the specified interrupts.
141  *
142  * @param[in] mask Mask of interrupts to be enabled.
143  */
144 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_int_enable(uint32_t mask);
145 
146 /**
147  * @brief Function for disabling the specified interrupts.
148  *
149  * @param[in] mask Mask of interrupts to be disabled.
150  */
151 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_int_disable(uint32_t mask);
152 
153 /**
154  * @brief Function for checking it the specified interrupts are enabled.
155  *
156  * @param[in] mask Mask of interrupts to be checked.
157  *
158  * @return Mask of enabled interrupts.
159  */
160 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_int_enable_check(uint32_t mask);
161 
162 #ifndef NRF_DECLARE_ONLY
nrf_vpr_csr_vevif_tasks_get(void)163 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_tasks_get(void)
164 {
165     return nrf_csr_read(VPRCSR_NORDIC_TASKS);
166 }
167 
nrf_vpr_csr_vevif_tasks_clear(uint32_t mask)168 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_tasks_clear(uint32_t mask)
169 {
170     nrf_csr_clear_bits(VPRCSR_NORDIC_TASKS, mask);
171 }
172 
nrf_vpr_csr_vevif_tasks_set(uint32_t value)173 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_tasks_set(uint32_t value)
174 {
175     nrf_csr_write(VPRCSR_NORDIC_TASKS, value);
176 }
177 
nrf_vpr_csr_vevif_events_get(void)178 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_events_get(void)
179 {
180     return nrf_csr_read(VPRCSR_NORDIC_EVENTS);
181 }
182 
nrf_vpr_csr_vevif_events_set(uint32_t value)183 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_events_set(uint32_t value)
184 {
185     nrf_csr_write(VPRCSR_NORDIC_EVENTS, value);
186 }
187 
nrf_vpr_csr_vevif_events_trigger(uint32_t mask)188 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_events_trigger(uint32_t mask)
189 {
190     nrf_csr_set_bits(VPRCSR_NORDIC_EVENTS, mask);
191 }
192 
nrf_vpr_csr_vevif_events_buffered_set(uint32_t value)193 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_events_buffered_set(uint32_t value)
194 {
195     nrf_csr_write(VPRCSR_NORDIC_EVENTSB, value);
196 }
197 
nrf_vpr_csr_vevif_events_buffered_dirty_check(void)198 NRF_STATIC_INLINE bool nrf_vpr_csr_vevif_events_buffered_dirty_check(void)
199 {
200     return ((nrf_csr_read(VPRCSR_NORDIC_EVENTSBS) & VPRCSR_NORDIC_EVENTSBS_DIRTYBIT_Msk)
201             >> VPRCSR_NORDIC_EVENTSBS_DIRTYBIT_Pos) == VPRCSR_NORDIC_EVENTSBS_DIRTYBIT_DIRTY;
202 }
203 
nrf_vpr_csr_vevif_subscribe_get(void)204 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_subscribe_get(void)
205 {
206     return nrf_csr_read(VPRCSR_NORDIC_SUBSCRIBE);
207 }
208 
nrf_vpr_csr_vevif_subscribe_set(uint32_t value)209 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_subscribe_set(uint32_t value)
210 {
211     nrf_csr_write(VPRCSR_NORDIC_SUBSCRIBE, value);
212 }
213 
nrf_vpr_csr_vevif_publish_get(void)214 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_publish_get(void)
215 {
216     return nrf_csr_read(VPRCSR_NORDIC_PUBLISH);
217 }
218 
nrf_vpr_csr_vevif_publish_set(uint32_t value)219 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_publish_set(uint32_t value)
220 {
221     nrf_csr_write(VPRCSR_NORDIC_PUBLISH, value);
222 }
223 
nrf_vpr_csr_vevif_int_enable(uint32_t mask)224 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_int_enable(uint32_t mask)
225 {
226     nrf_csr_set_bits(VPRCSR_NORDIC_INTEN, mask);
227 }
228 
nrf_vpr_csr_vevif_int_disable(uint32_t mask)229 NRF_STATIC_INLINE void nrf_vpr_csr_vevif_int_disable(uint32_t mask)
230 {
231     nrf_csr_clear_bits(VPRCSR_NORDIC_INTEN, mask);
232 }
233 
nrf_vpr_csr_vevif_int_enable_check(uint32_t mask)234 NRF_STATIC_INLINE uint32_t nrf_vpr_csr_vevif_int_enable_check(uint32_t mask)
235 {
236     return nrf_csr_read(VPRCSR_NORDIC_INTEN) & mask;
237 }
238 
239 #endif // NRF_DECLARE_ONLY
240 
241 /** @} */
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif // NRF_VPR_CSR_VEVIF_H__
248