1 /*
2  * Copyright (c) 2023 - 2024, 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_STM_H__
35 #define NRF_STM_H__
36 
37 #include <nrfx.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * @defgroup nrf_stm_hal STM HAL
45  * @{
46  * @ingroup nrf_stm
47  * @brief   Hardware access layer for managing the System Trace Macrocell (STM) peripheral.
48  */
49 
50 /**
51  * @brief STM features.
52  *
53  * @warning Registers marked with (1) signal negative situation (disabled, not supported) using
54  *          non-zero value. Therefore the register value is negated when retrieving their setting
55  *          with nrf_stm_feature_present_check() or setting it with nrf_stm_feature_set().
56  *          This is to ensure that true always means enabled/supported and false disabled/not supported.
57  *
58  * @note Registers marked RO are read-only and may be only used in @ref nrf_stm_feature_check function.
59  *       Registers marked RW are read-write and may be used with both @ref nrf_stm_feature_check
60  *       and @ref nrf_stm_feature_set functions.
61  */
62 typedef enum {
63     NRF_STM_FEATURE_HETER,          /**< Hardware event trigger enable register support. RO */
64     NRF_STM_FEATURE_HEERR,          /**< Hardware event error detection support. RO */
65     NRF_STM_FEATURE_HEMASTR,        /**< Hardware event master number register support. RO */
66     NRF_STM_FEATURE_STM,            /**< Global STM enable. RW */
67     NRF_STM_FEATURE_TSEN,           /**< Timestamping enable. RW */
68     NRF_STM_FEATURE_SYNCEN,         /**< Synchronization control register implemented. RW */
69     NRF_STM_FEATURE_COMPEN,         /**< Compression enable. RW */
70     NRF_STM_FEATURE_BUSY,           /**< STM busy status. RW */
71     NRF_STM_FEATURE_FIFOAF,         /**< Auto-flush enable. RW */
72     NRF_STM_FEATURE_ASYNCPE,        /**< Async priority escalation enable. RW */
73     NRF_STM_FEATURE_PRIORINVDIS,    /**< Priority inversion enable. RW (1) */
74     NRF_STM_FEATURE_CLKON,          /**< Override for architectural clock gate enable. RW */
75     NRF_STM_FEATURE_AFREADYHIGH,    /**< Override for the AFREADY output enable. RW */
76     NRF_STM_FEATURE_TSFREQ,         /**< Timestamp frequency indication configuration. RO */
77     NRF_STM_FEATURE_FORCETS,        /**< timestamp stimulus register support. RO */
78     NRF_STM_FEATURE_TSPRESCALE,     /**< Timestamp prescale support. RO (1) */
79     NRF_STM_FEATURE_HWTEN,          /**< Hardware event trace packet emission support. RO (1) */
80     NRF_STM_FEATURE_SWOEN,          /**< Anynchronous-specific usage model for timestamps support. RO (1) */
81     NRF_STM_FEATURE_SPTER,          /**< Stimulus port trigger enable register support. RO */
82     NRF_STM_FEATURE_SPER,           /**< Stimulus port enable register support. RO (1) */
83     NRF_STM_FEATURE_SPOVERRIDE,     /**< Stimulus port override register support. RO */
84     NRF_STM_FEATURE_PRIVMASK,       /**< Trace privilege register support. RO (1) */
85     NRF_STM_FEATURE_INTEGRATION,    /**< Integration mode enable. RW */
86     NRF_STM_FEATURE_LC_PRESENT,     /**< Lock control mechanism support. RO */
87     NRF_STM_FEATURE_LC_LOCKED,      /**< Lock write access enable. RO */
88     NRF_STM_FEATURE_NSID,           /**< Security for non-secure invasive debug enable. RO */
89     NRF_STM_FEATURE_NSNID,          /**< Security for non-secure non-invasive debug enable. RO */
90     NRF_STM_FEATURE_SID,            /**< Security for secure invasive debug. RO */
91     NRF_STM_FEATURE_SNID,           /**< Security for secure non-invasive debug. RO */
92 } nrf_stm_feature_t;
93 
94 /** @brief STM outputs. */
95 typedef enum {
96     NRF_STM_OUTPUT_TRIGOUTSPTE, /**< Match using STMSPTER trigger event output. */
97     NRF_STM_OUTPUT_TRIGOUTSW,   /**< Write to TRIG location trigger event output. */
98     NRF_STM_OUTPUT_TRIGOUTHETE, /**< Match using STMHETER trigger event output. */
99     NRF_STM_OUTPUT_ASYNCOUT,    /**< Alignment synchronization output. */
100     NRF_STM_OUTPUT_ATDATAM_0,   /**< Trace data ATDATAM[0] output. */
101     NRF_STM_OUTPUT_ATDATAM_7,   /**< Trace data ATDATAM[7] output. */
102     NRF_STM_OUTPUT_ATDATAM_15,  /**< Trace data ATDATAM[15] output. */
103     NRF_STM_OUTPUT_ATDATAM_23,  /**< Trace data ATDATAM[23] output. */
104     NRF_STM_OUTPUT_ATDATAM_31,  /**< Trace data ATDATAM[31] output. */
105     NRF_STM_OUTPUT_ATIDM_0,     /**< Trace source ID bit 0 output. */
106     NRF_STM_OUTPUT_ATIDM_1,     /**< Trace source ID bit 1 output. */
107     NRF_STM_OUTPUT_ATIDM_2,     /**< Trace source ID bit 2 output. */
108     NRF_STM_OUTPUT_ATIDM_3,     /**< Trace source ID bit 3 output. */
109     NRF_STM_OUTPUT_ATIDM_4,     /**< Trace source ID bit 4 output. */
110     NRF_STM_OUTPUT_ATIDM_5,     /**< Trace source ID bit 5 output. */
111     NRF_STM_OUTPUT_ATIDM_6,     /**< Trace source ID bit 6 output. */
112     NRF_STM_OUTPUT_ATVALIDM,    /**< Transfer valid output. */
113     NRF_STM_OUTPUT_AFREADYM,    /**< ATB flush acknowledge output. */
114     NRF_STM_OUTPUT_ATBYTESM_0,  /**< Number of bytes on ATDATA to be captured bit 0 output. */
115     NRF_STM_OUTPUT_ATBYTESM_1,  /**< Number of bytes on ATDATA to be captured bit 1 output. */
116 } nrf_stm_output_t;
117 
118 /** @brief STM inputs. */
119 typedef enum {
120     NRF_STM_INPUT_ATREADYM, /**< Slave is ready to accept data input. */
121     NRF_STM_INPUT_AFVALIDM, /**< ATB flush request input. */
122 } nrf_stm_input_t;
123 
124 /** @brief Sensitivity of the DMA request to the current buffer level. */
125 typedef enum {
126     NRF_STM_DMACTLR_LT25  = STM_DMACTLR_SENS_LT25,  /**< Buffer is <25% full. */
127     NRF_STM_DMACTLR_LT50  = STM_DMACTLR_SENS_LT50,  /**< Buffer is <50% full. */
128     NRF_STM_DMACTLR_LT75  = STM_DMACTLR_SENS_LT75,  /**< Buffer is <75% full. */
129     NRF_STM_DMACTLR_LT100 = STM_DMACTLR_SENS_LT100, /**< Buffer is <100% full. */
130 } nrf_stm_dma_sens_t;
131 
132 /** @brief Programmer's models. */
133 typedef enum {
134     NRF_STM_HEIDR_CLASS_HARDWARE_EVENT_CONTROL = STM_HEIDR_CLASS_HardwareEventControl, /**< Hardware Event Control programmer's model. */
135 } nrf_stm_heidr_class_t;
136 
137 /** @brief STM protocols. */
138 typedef enum {
139     NRF_STM_SFPEAT1R_PROT_STPV2 = STM_SPFEAT1R_PROT_STPV2, /**< STPv2 protocol. */
140 } nrf_stm_spfeat1r_prot_t;
141 
142 /** @brief Timestamp support modes. */
143 typedef enum {
144     NRF_STM_SPFEAT1R_TS_ABSOLUTE = STM_SPFEAT1R_TS_Absolute, /**< Absolute timestaps implemented. */
145 } nrf_stm_spfeat1r_ts_t;
146 
147 /** @brief STMTCSR.SYNCEN support modes. */
148 typedef enum {
149     NRF_STM_SPFEAT1R_SYNCEN_READ_AS_ONE = STM_SPFEAT1R_SYNCEN_ReadAsOne, /**< STMTCSR.SYNCEN implemented, but always reads as 1. */
150 } nrf_stm_spfeat1r_syncen_t;
151 
152 /** @brief Data compression on stimulus port support modes. */
153 typedef enum {
154     NRF_STM_SPFEAT2R_SPCOMP_PROGRAMMABLE = STM_SPFEAT2R_SPCOMP_Programmable, /**< Data compression support is programmable. */
155 } nrf_stm_spfeat2r_spcomp_t;
156 
157 /** @brief Stimulus port transaction type support modes. */
158 typedef enum {
159     NRF_STM_SPFEAT2R_SPTRTYPE_INVARIANT_AND_GUARANTEED = STM_SPFEAT2R_SPTRTYPE_InvariantAndGuaranteed, /**< Both invariant timing and guaranteed transactions are supported. */
160 } nrf_stm_spfeat2r_sptrtype_t;
161 
162 /** @brief Fundamental data size modes. */
163 typedef enum {
164     NRF_STM_SPFEAT2R_DSIZE_32 = STM_SPFEAT2R_DSIZE_Bits32, /**< 32-bit data. */
165 } nrf_stm_spfeat2r_dsize_t;
166 
167 /** @brief Lock Access Register implementation modes. */
168 typedef enum {
169     NRF_STM_LSR_TYPE_8  = STM_LSR_TYPE_Bits8,   /**< 8-bit Lock Access Register implemented. */
170     NRF_STM_LSR_TYPE_32 = STM_LSR_TYPE_Bits32,  /**< 32-bit Lock Access Register implemented. */
171 } nrf_stm_lsr_type_t;
172 
173 /** Major classification grouping for this debug or trace component. */
174 typedef enum {
175     NRF_STM_DEVTYPE_MAJOR_TRACE_SOURCE = STM_DEVTYPE_MAJOR_TraceSource, /**< Peripheral is a trace source. */
176 } nrf_stm_devtype_major_t;
177 
178 /** Sub-classification for this debug or trace component. */
179 typedef enum {
180     NRF_STM_DEVTYPE_SUB_STIMULUS_TRACE = STM_DEVTYPE_SUB_StimulusTrace, /**< Peripheral is a stimulus trace source. */
181 } nrf_stm_devtype_sub_t;
182 
183 /**
184  * @brief Function for retrieving the state of a feature.
185  *
186  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
187  * @param[in] feature Feature to be checked.
188  *
189  * @retval true  The feature is supported/enabled.
190  * @retval false The feature is not supported/disabled.
191  */
192 NRF_STATIC_INLINE bool nrf_stm_feature_check(NRF_STM_Type const * p_reg,
193                                              nrf_stm_feature_t    feature);
194 
195 /**
196  * @brief Function for setting the state of a feature.
197  *
198  * @warning Only features that are RW may be used in this function.
199  *
200  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
201  * @param[in] feature Feature to be set.
202  * @param[in] enable  State to be set.
203  */
204 NRF_STATIC_INLINE void nrf_stm_feature_set(NRF_STM_Type *    p_reg,
205                                            nrf_stm_feature_t feature,
206                                            bool              enable);
207 
208 /**
209  * @brief Function for retrieving the state of an input.
210  *
211  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
212  * @param[in] input Input to be checked.
213  *
214  * @retval true  The input is high.
215  * @retval false The input is low.
216  */
217 NRF_STATIC_INLINE bool nrf_stm_input_check(NRF_STM_Type const * p_reg, nrf_stm_input_t input);
218 
219 /**
220  * @brief Function for setting the state of an output.
221  *
222  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
223  * @param[in] output Output to be set.
224  * @param[in] enable State to be set.
225  */
226 NRF_STATIC_INLINE void nrf_stm_output_set(NRF_STM_Type * p_reg, nrf_stm_output_t output, bool enable);
227 
228 /**
229  * @brief Function for setting the sensivity of the DMA request.
230  *
231  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
232  * @param[in] sens  Sensivity to be set.
233  */
234 NRF_STATIC_INLINE void nrf_stm_dmactlr_sens_set(NRF_STM_Type * p_reg, nrf_stm_dma_sens_t sens);
235 
236 /**
237  * @brief Function for getting the sensivity of the DMA request.
238  *
239  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
240  *
241  * @return Sensivity of the DMA request.
242  */
243 NRF_STATIC_INLINE nrf_stm_dma_sens_t nrf_stm_dmactlr_sens_get(NRF_STM_Type const * p_reg);
244 
245 /**
246  * @brief Function for getting the number of the hardware event trace of the STPv2 master.
247  *
248  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
249  *
250  * @return Number of the hardware event trace of the STPv2 master.
251  */
252 NRF_STATIC_INLINE uint16_t nrf_stm_hemastr_get(NRF_STM_Type const * p_reg);
253 
254 /**
255  * @brief Function for getting the number of hardware events suppoted by the STM.
256  *
257  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
258  *
259  * @return Number of hardware events suppoted by the STM.
260  */
261 NRF_STATIC_INLINE uint16_t nrf_stm_hefeat1r_numhe_get(NRF_STM_Type const * p_reg);
262 
263 /**
264  * @brief Function for getting the programmer's model of hardware event tracking.
265  *
266  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
267  *
268  * @return Programmer's model.
269  */
270 NRF_STATIC_INLINE nrf_stm_heidr_class_t nrf_stm_heidr_class_get(NRF_STM_Type const * p_reg);
271 
272 /**
273  * @brief Function for getting the revision of the programmer's model of hardware event tracking.
274  *
275  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
276  *
277  * @return Revision of the programmer's model.
278  */
279 NRF_STATIC_INLINE uint8_t nrf_stm_heidr_classrev_get(NRF_STM_Type const * p_reg);
280 
281 /**
282  * @brief Function for getting vendor specific modifications or mappings of hardware event tracking.
283  *
284  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
285  *
286  * @return Vendor specific modifications or mappings.
287  */
288 NRF_STATIC_INLINE uint8_t nrf_stm_heidr_vendspec_get(NRF_STM_Type const * p_reg);
289 
290 /**
291  * @brief Function for setting the ATB Trace ID.
292  *
293  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
294  * @param[in] trace_id ATB Trace ID to be set.
295  */
296 NRF_STATIC_INLINE void nrf_stm_tcsr_traceid_set(NRF_STM_Type * p_reg, uint8_t trace_id);
297 
298 /**
299  * @brief Function for getting the ATB Trace ID.
300  *
301  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
302  *
303  * @return ATB Trace ID.
304  */
305 NRF_STATIC_INLINE uint8_t nrf_stm_tcsr_traceid_get(NRF_STM_Type const * p_reg);
306 
307 /**
308  * @brief Function for getting the implemented STM protocol.
309  *
310  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
311  *
312  * @return Implemented STM protocol.
313  */
314 NRF_STATIC_INLINE nrf_stm_spfeat1r_prot_t nrf_stm_spfeat1r_prot_get(NRF_STM_Type const * p_reg);
315 
316 /**
317  * @brief Function for getting the timestamp support mode.
318  *
319  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
320  *
321  * @return Timestamp support mode.
322  */
323 NRF_STATIC_INLINE nrf_stm_spfeat1r_ts_t nrf_stm_spfeat1r_ts_get(NRF_STM_Type const * p_reg);
324 
325 /**
326  * @brief Function for getting the trace bus support.
327  *
328  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
329  *
330  * @return Trace bus support.
331  */
332 NRF_STATIC_INLINE uint8_t nrf_stm_spfeat1r_tracebus_get(NRF_STM_Type const * p_reg);
333 
334 /**
335  * @brief Function for getting the trigger control support.
336  *
337  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
338  *
339  * @return Trigger control support.
340  */
341 NRF_STATIC_INLINE uint8_t nrf_stm_spfeat1r_trigctl_get(NRF_STM_Type const * p_reg);
342 
343 /**
344  * @brief Function for getting the STMTCSR.SYNCEN support mode.
345  *
346  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
347  *
348  * @return STMTCSR.SYNCEN support mode.
349  */
350 NRF_STATIC_INLINE nrf_stm_spfeat1r_syncen_t nrf_stm_spfeat1r_syncen_get(NRF_STM_Type const * p_reg);
351 
352 /**
353  * @brief Function for getting the data compression on stimulus port support mode.
354  *
355  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
356  *
357  * @return Data compression on stimulus port support mode.
358  */
359 NRF_STATIC_INLINE nrf_stm_spfeat2r_spcomp_t nrf_stm_spfeat2r_spcomp_get(NRF_STM_Type const * p_reg);
360 
361 /**
362  * @brief Function for getting the stimulus port transaction type support mode.
363  *
364  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
365  *
366  * @return Stimulus port transaction type support mode.
367  */
368 NRF_STATIC_INLINE nrf_stm_spfeat2r_sptrtype_t nrf_stm_spfeat2r_sptrtype_get(NRF_STM_Type const * p_reg);
369 
370 /**
371  * @brief Function for getting the fundamental data size mode.
372  *
373  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
374  *
375  * @return Fundamental data size mode.
376  */
377 NRF_STATIC_INLINE nrf_stm_spfeat2r_dsize_t nrf_stm_spfeat2r_dsize_get(NRF_STM_Type const * p_reg);
378 
379 /**
380  * @brief Function for getting the number of stimulus ports masters implemented, minus 1.
381  *
382  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
383  *
384  * @return Number of stimulus ports masters implemented, minus 1.
385  */
386 NRF_STATIC_INLINE uint8_t nrf_stm_spfeat3r_nummast_get(NRF_STM_Type const * p_reg);
387 
388 /**
389  * @brief Function for setting the enable write access register.
390  *
391  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
392  * @param[in] value Value to be set for enable write access register.
393  */
394 NRF_STATIC_INLINE void nrf_stm_lar_access_set(NRF_STM_Type * p_reg, uint32_t value);
395 
396 /**
397  * @brief Function for getting the Lock Access Register implementation mode.
398  *
399  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
400  *
401  * @return Lock Access Register implementation mode.
402  */
403 NRF_STATIC_INLINE nrf_stm_lsr_type_t nrf_stm_lsr_type_get(NRF_STM_Type const * p_reg);
404 
405 /**
406  * @brief Function for getting the number of stimulus ports implemented.
407  *
408  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
409  *
410  * @return Number of stimulus ports implemented.
411  */
412 NRF_STATIC_INLINE uint32_t nrf_stm_devid_numsp_get(NRF_STM_Type const * p_reg);
413 
414 /**
415  * @brief Function for getting the major classification grouping for this debug or trace component.
416  *
417  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
418  *
419  * @return Major classification grouping for this debug or trace component.
420  */
421 NRF_STATIC_INLINE nrf_stm_devtype_major_t nrf_stm_devtype_major_get(NRF_STM_Type const * p_reg);
422 
423 /**
424  * @brief Function for getting the sub-classification for this debug or trace component.
425  *
426  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
427  *
428  * @return Sub-classification for this debug or trace component.
429  */
430 NRF_STATIC_INLINE nrf_stm_devtype_sub_t nrf_stm_devtype_sub_get(NRF_STM_Type const * p_reg);
431 
432 #ifndef NRF_DECLARE_ONLY
nrf_stm_feature_check(NRF_STM_Type const * p_reg,nrf_stm_feature_t feature)433 NRF_STATIC_INLINE bool nrf_stm_feature_check(NRF_STM_Type const * p_reg,
434                                              nrf_stm_feature_t    feature)
435 {
436     switch (feature)
437     {
438         case NRF_STM_FEATURE_HETER:
439             return (p_reg->HEFEAT1R & STM_HEFEAT1R_HETER_Msk);
440         case NRF_STM_FEATURE_HEERR:
441             return (p_reg->HEFEAT1R & STM_HEFEAT1R_HEERR_Msk);
442         case NRF_STM_FEATURE_HEMASTR:
443             return (p_reg->HEFEAT1R & STM_HEFEAT1R_HEMASTR_Msk);
444         case NRF_STM_FEATURE_STM:
445             return (p_reg->TCSR & STM_TCSR_EN_Msk);
446         case NRF_STM_FEATURE_TSEN:
447             return (p_reg->TCSR & STM_TCSR_TSEN_Msk);
448         case NRF_STM_FEATURE_SYNCEN:
449             return (p_reg->TCSR & STM_TCSR_SYNCEN_Msk);
450         case NRF_STM_FEATURE_COMPEN:
451             return (p_reg->TCSR & STM_TCSR_COMPEN_Msk);
452         case NRF_STM_FEATURE_BUSY:
453             return (p_reg->TCSR & STM_TCSR_BUSY_Msk);
454         case NRF_STM_FEATURE_FIFOAF:
455             return (p_reg->AUXCR & STM_AUXCR_FIFOAF_Msk);
456         case NRF_STM_FEATURE_ASYNCPE:
457             return (p_reg->AUXCR & STM_AUXCR_ASYNCPE_Msk);
458         case NRF_STM_FEATURE_PRIORINVDIS:
459             return !(p_reg->AUXCR & STM_AUXCR_PRIORINVDIS_Msk);
460         case NRF_STM_FEATURE_CLKON:
461             return (p_reg->AUXCR & STM_AUXCR_CLKON_Msk);
462         case NRF_STM_FEATURE_AFREADYHIGH:
463             return (p_reg->AUXCR & STM_AUXCR_AFREADYHIGH_Msk);
464         case NRF_STM_FEATURE_TSFREQ:
465             return (p_reg->SPFEAT1R & STM_SPFEAT1R_TSFREQ_Msk);
466         case NRF_STM_FEATURE_FORCETS:
467             return (p_reg->SPFEAT1R & STM_SPFEAT1R_FORCETS_Msk);
468         case NRF_STM_FEATURE_TSPRESCALE:
469             return !(p_reg->SPFEAT1R & STM_SPFEAT1R_TSPRESCALE_Msk);
470         case NRF_STM_FEATURE_HWTEN:
471             return !(p_reg->SPFEAT1R & STM_SPFEAT1R_HWTEN_Msk);
472         case NRF_STM_FEATURE_SWOEN:
473             return !(p_reg->SPFEAT1R & STM_SPFEAT1R_SWOEN_Msk);
474         case NRF_STM_FEATURE_SPTER:
475             return (p_reg->SPFEAT2R & STM_SPFEAT2R_SPTER_Msk);
476         case NRF_STM_FEATURE_SPER:
477             return !(p_reg->SPFEAT2R & STM_SPFEAT2R_SPER_Msk);
478         case NRF_STM_FEATURE_SPOVERRIDE:
479             return (p_reg->SPFEAT2R & STM_SPFEAT2R_SPOVERRIDE_Msk);
480         case NRF_STM_FEATURE_PRIVMASK:
481             return !(p_reg->SPFEAT2R & STM_SPFEAT2R_PRIVMASK_Msk);
482         case NRF_STM_FEATURE_INTEGRATION:
483             return (p_reg->ITCTRL & STM_ITCTRL_INTEGRATIONMODE_Msk);
484         case NRF_STM_FEATURE_LC_PRESENT:
485             return (p_reg->LSR & STM_LSR_PRESENT_Msk);
486         case NRF_STM_FEATURE_LC_LOCKED:
487             return (p_reg->LSR & STM_LSR_LOCKED_Msk);
488         case NRF_STM_FEATURE_NSID:
489             return (p_reg->AUTHSTATUS & STM_AUTHSTATUS_NSID_Msk);
490         case NRF_STM_FEATURE_NSNID:
491             return (p_reg->AUTHSTATUS & STM_AUTHSTATUS_NSNID_Msk);
492         case NRF_STM_FEATURE_SID:
493             return (p_reg->AUTHSTATUS & STM_AUTHSTATUS_SID_Msk);
494         case NRF_STM_FEATURE_SNID:
495             return (p_reg->AUTHSTATUS & STM_AUTHSTATUS_SNID_Msk);
496         default:
497             NRFX_ASSERT(0);
498             return false;
499     }
500 }
501 
nrf_stm_feature_set(NRF_STM_Type * p_reg,nrf_stm_feature_t feature,bool enable)502 NRF_STATIC_INLINE void nrf_stm_feature_set(NRF_STM_Type *    p_reg,
503                                            nrf_stm_feature_t feature,
504                                            bool              enable)
505 {
506     switch (feature)
507     {
508         case NRF_STM_FEATURE_STM:
509             p_reg->TCSR = ((p_reg->TCSR & ~STM_TCSR_EN_Msk) |
510                            (enable << STM_TCSR_EN_Pos));
511             break;
512         case NRF_STM_FEATURE_TSEN:
513             p_reg->TCSR = ((p_reg->TCSR & ~STM_TCSR_TSEN_Msk) |
514                            (enable << STM_TCSR_TSEN_Pos));
515             break;
516         case NRF_STM_FEATURE_SYNCEN:
517             p_reg->TCSR = ((p_reg->TCSR & ~STM_TCSR_SYNCEN_Msk) |
518                            (enable << STM_TCSR_SYNCEN_Pos));
519             break;
520         case NRF_STM_FEATURE_COMPEN:
521             p_reg->TCSR = ((p_reg->TCSR & ~STM_TCSR_COMPEN_Msk) |
522                            (enable << STM_TCSR_COMPEN_Pos));
523             break;
524         case NRF_STM_FEATURE_BUSY:
525             p_reg->TCSR = ((p_reg->TCSR & ~STM_TCSR_BUSY_Msk) |
526                            (enable << STM_TCSR_BUSY_Pos));
527             break;
528         case NRF_STM_FEATURE_FIFOAF:
529             p_reg->AUXCR = ((p_reg->AUXCR & ~STM_AUXCR_FIFOAF_Msk) |
530                             (enable << STM_AUXCR_FIFOAF_Pos));
531             break;
532         case NRF_STM_FEATURE_ASYNCPE:
533             p_reg->AUXCR = ((p_reg->AUXCR & ~STM_AUXCR_ASYNCPE_Msk) |
534                             (enable << STM_AUXCR_ASYNCPE_Pos));
535             break;
536         case NRF_STM_FEATURE_PRIORINVDIS:
537             p_reg->AUXCR = ((p_reg->AUXCR & ~STM_AUXCR_PRIORINVDIS_Msk) |
538                             ((!enable) << STM_AUXCR_PRIORINVDIS_Pos));
539             break;
540         case NRF_STM_FEATURE_CLKON:
541             p_reg->AUXCR = ((p_reg->AUXCR & ~STM_AUXCR_CLKON_Msk) |
542                             (enable << STM_AUXCR_CLKON_Pos));
543             break;
544         case NRF_STM_FEATURE_AFREADYHIGH:
545             p_reg->AUXCR = ((p_reg->AUXCR & ~STM_AUXCR_AFREADYHIGH_Msk) |
546                             (enable << STM_AUXCR_AFREADYHIGH_Pos));
547             break;
548         case NRF_STM_FEATURE_INTEGRATION:
549             p_reg->ITCTRL = ((p_reg->ITCTRL & ~STM_ITCTRL_INTEGRATIONMODE_Msk) |
550                              (enable << STM_ITCTRL_INTEGRATIONMODE_Pos));
551             break;
552         default:
553             NRFX_ASSERT(0);
554             break;
555     }
556 }
557 
nrf_stm_input_check(NRF_STM_Type const * p_reg,nrf_stm_input_t input)558 NRF_STATIC_INLINE bool nrf_stm_input_check(NRF_STM_Type const * p_reg, nrf_stm_input_t input)
559 {
560     switch (input)
561     {
562         case NRF_STM_INPUT_ATREADYM:
563             return ((p_reg->ITATBCTR2 & STM_ITATBCTR2_ATREADYM_R_Msk)
564                     >> STM_ITATBCTR2_ATREADYM_R_Pos);
565         case NRF_STM_INPUT_AFVALIDM:
566             return ((p_reg->ITATBCTR2 & STM_ITATBCTR2_AFVALIDM_R_Msk)
567                     >> STM_ITATBCTR2_AFVALIDM_R_Pos);
568         default:
569             NRFX_ASSERT(0);
570             return false;
571     }
572 }
573 
nrf_stm_output_set(NRF_STM_Type * p_reg,nrf_stm_output_t output,bool enable)574 NRF_STATIC_INLINE void nrf_stm_output_set(NRF_STM_Type * p_reg, nrf_stm_output_t output, bool enable)
575 {
576     switch (output)
577     {
578         case NRF_STM_OUTPUT_TRIGOUTSPTE:
579             p_reg->ITTRIGGER = ((p_reg->ITTRIGGER & ~STM_ITTRIGGER_TRIGOUTSPTE_W_Msk) |
580                                 (enable << STM_ITTRIGGER_TRIGOUTSPTE_W_Pos));
581             break;
582         case NRF_STM_OUTPUT_TRIGOUTSW:
583             p_reg->ITTRIGGER = ((p_reg->ITTRIGGER & ~STM_ITTRIGGER_TRIGOUTSW_W_Msk) |
584                                 (enable << STM_ITTRIGGER_TRIGOUTSW_W_Pos));
585             break;
586         case NRF_STM_OUTPUT_TRIGOUTHETE:
587             p_reg->ITTRIGGER = ((p_reg->ITTRIGGER & ~STM_ITTRIGGER_TRIGOUTHETE_W_Msk) |
588                                 (enable << STM_ITTRIGGER_TRIGOUTHETE_W_Pos));
589             break;
590         case NRF_STM_OUTPUT_ASYNCOUT:
591             p_reg->ITTRIGGER = ((p_reg->ITTRIGGER & ~STM_ITTRIGGER_ASYNCOUT_W_Msk) |
592                                 (enable << STM_ITTRIGGER_ASYNCOUT_W_Pos));
593             break;
594         case NRF_STM_OUTPUT_ATDATAM_0:
595             p_reg->ITATBDATA0 = ((p_reg->ITATBDATA0 & ~STM_ITATBDATA0_ATDATAM0_W_Msk) |
596                                 (enable << STM_ITATBDATA0_ATDATAM0_W_Pos));
597             break;
598         case NRF_STM_OUTPUT_ATDATAM_7:
599             p_reg->ITATBDATA0 = ((p_reg->ITATBDATA0 & ~STM_ITATBDATA0_ATDATAM7_W_Msk) |
600                                 (enable << STM_ITATBDATA0_ATDATAM7_W_Pos));
601             break;
602         case NRF_STM_OUTPUT_ATDATAM_15:
603             p_reg->ITATBDATA0 = ((p_reg->ITATBDATA0 & ~STM_ITATBDATA0_ATDATAM15_W_Msk) |
604                                 (enable << STM_ITATBDATA0_ATDATAM15_W_Pos));
605             break;
606         case NRF_STM_OUTPUT_ATDATAM_23:
607             p_reg->ITATBDATA0 = ((p_reg->ITATBDATA0 & ~STM_ITATBDATA0_ATDATAM23_W_Msk) |
608                                 (enable << STM_ITATBDATA0_ATDATAM23_W_Pos));
609             break;
610         case NRF_STM_OUTPUT_ATDATAM_31:
611             p_reg->ITATBDATA0 = ((p_reg->ITATBDATA0 & ~STM_ITATBDATA0_ATDATAM31_W_Msk) |
612                                 (enable << STM_ITATBDATA0_ATDATAM31_W_Pos));
613             break;
614         case NRF_STM_OUTPUT_ATIDM_0:
615             p_reg->ITATBID = ((p_reg->ITATBID & ~STM_ITATBID_ATIDM_W0_Msk) |
616                                 (enable << STM_ITATBID_ATIDM_W0_Pos));
617             break;
618         case NRF_STM_OUTPUT_ATIDM_1:
619             p_reg->ITATBID = ((p_reg->ITATBID & ~STM_ITATBID_ATIDM_W1_Msk) |
620                                 (enable << STM_ITATBID_ATIDM_W1_Pos));
621             break;
622         case NRF_STM_OUTPUT_ATIDM_2:
623             p_reg->ITATBID = ((p_reg->ITATBID & ~STM_ITATBID_ATIDM_W2_Msk) |
624                                 (enable << STM_ITATBID_ATIDM_W2_Pos));
625             break;
626         case NRF_STM_OUTPUT_ATIDM_3:
627             p_reg->ITATBID = ((p_reg->ITATBID & ~STM_ITATBID_ATIDM_W3_Msk) |
628                                 (enable << STM_ITATBID_ATIDM_W3_Pos));
629             break;
630         case NRF_STM_OUTPUT_ATIDM_4:
631             p_reg->ITATBID = ((p_reg->ITATBID & ~STM_ITATBID_ATIDM_W4_Msk) |
632                                 (enable << STM_ITATBID_ATIDM_W4_Pos));
633             break;
634         case NRF_STM_OUTPUT_ATIDM_5:
635             p_reg->ITATBID = ((p_reg->ITATBID & ~STM_ITATBID_ATIDM_W5_Msk) |
636                                 (enable << STM_ITATBID_ATIDM_W5_Pos));
637             break;
638         case NRF_STM_OUTPUT_ATIDM_6:
639             p_reg->ITATBID = ((p_reg->ITATBID & ~STM_ITATBID_ATIDM_W6_Msk) |
640                                 (enable << STM_ITATBID_ATIDM_W6_Pos));
641             break;
642         case NRF_STM_OUTPUT_ATVALIDM:
643             p_reg->ITATBCTR0 = ((p_reg->ITATBCTR0 & ~STM_ITATBCTR0_ATVALIDM_W_Msk) |
644                                 (enable << STM_ITATBCTR0_ATVALIDM_W_Pos));
645             break;
646         case NRF_STM_OUTPUT_AFREADYM:
647             p_reg->ITATBCTR0 = ((p_reg->ITATBCTR0 & ~STM_ITATBCTR0_AFREADYM_W_Msk) |
648                                 (enable << STM_ITATBCTR0_AFREADYM_W_Pos));
649             break;
650         case NRF_STM_OUTPUT_ATBYTESM_0:
651             p_reg->ITATBCTR0 = ((p_reg->ITATBCTR0 & ~STM_ITATBCTR0_ATBYTESM_W0_Msk) |
652                                 (enable << STM_ITATBCTR0_ATBYTESM_W0_Pos));
653             break;
654         case NRF_STM_OUTPUT_ATBYTESM_1:
655             p_reg->ITATBCTR0 = ((p_reg->ITATBCTR0 & ~STM_ITATBCTR0_ATBYTESM_W1_Msk) |
656                                 (enable << STM_ITATBCTR0_ATBYTESM_W1_Pos));
657             break;
658         default:
659             NRFX_ASSERT(0);
660             break;
661     }
662 }
663 
nrf_stm_dmactlr_sens_set(NRF_STM_Type * p_reg,nrf_stm_dma_sens_t sens)664 NRF_STATIC_INLINE void nrf_stm_dmactlr_sens_set(NRF_STM_Type * p_reg, nrf_stm_dma_sens_t sens)
665 {
666     p_reg->DMACTLR = (sens << STM_DMACTLR_SENS_Pos);
667 }
668 
nrf_stm_dmactlr_sens_get(NRF_STM_Type const * p_reg)669 NRF_STATIC_INLINE nrf_stm_dma_sens_t nrf_stm_dmactlr_sens_get(NRF_STM_Type const * p_reg)
670 {
671     return (nrf_stm_dma_sens_t)((p_reg->DMACTLR & STM_DMACTLR_SENS_Msk)
672                                 >> STM_DMACTLR_SENS_Pos);
673 }
674 
nrf_stm_hemastr_get(NRF_STM_Type const * p_reg)675 NRF_STATIC_INLINE uint16_t nrf_stm_hemastr_get(NRF_STM_Type const * p_reg)
676 {
677     return (uint16_t)((p_reg->HEMASTR & STM_HEMASTR_MASTER_Msk) >> STM_HEMASTR_MASTER_Pos);
678 }
679 
nrf_stm_hefeat1r_numhe_get(NRF_STM_Type const * p_reg)680 NRF_STATIC_INLINE uint16_t nrf_stm_hefeat1r_numhe_get(NRF_STM_Type const * p_reg)
681 {
682     return (uint16_t)((p_reg->HEFEAT1R & STM_HEFEAT1R_NUMHE_Msk) >> STM_HEFEAT1R_NUMHE_Pos);
683 }
684 
nrf_stm_heidr_class_get(NRF_STM_Type const * p_reg)685 NRF_STATIC_INLINE nrf_stm_heidr_class_t nrf_stm_heidr_class_get(NRF_STM_Type const * p_reg)
686 {
687     return (nrf_stm_heidr_class_t)((p_reg->HEIDR & STM_HEIDR_CLASS_Msk) >> STM_HEIDR_CLASS_Pos);
688 }
689 
nrf_stm_heidr_classrev_get(NRF_STM_Type const * p_reg)690 NRF_STATIC_INLINE uint8_t nrf_stm_heidr_classrev_get(NRF_STM_Type const * p_reg)
691 {
692     return (uint8_t)((p_reg->HEIDR & STM_HEIDR_CLASSREV_Msk) >> STM_HEIDR_CLASSREV_Pos);
693 }
694 
nrf_stm_heidr_vendspec_get(NRF_STM_Type const * p_reg)695 NRF_STATIC_INLINE uint8_t nrf_stm_heidr_vendspec_get(NRF_STM_Type const * p_reg)
696 {
697     return (uint8_t)((p_reg->HEIDR & STM_HEIDR_VENDSPEC_Msk) >> STM_HEIDR_VENDSPEC_Pos);
698 }
699 
nrf_stm_tcsr_traceid_set(NRF_STM_Type * p_reg,uint8_t trace_id)700 NRF_STATIC_INLINE void nrf_stm_tcsr_traceid_set(NRF_STM_Type * p_reg, uint8_t trace_id)
701 {
702     p_reg->TCSR = ((trace_id << STM_TCSR_TRACEID_Pos) & STM_TCSR_TRACEID_Msk);
703 }
704 
nrf_stm_tcsr_traceid_get(NRF_STM_Type const * p_reg)705 NRF_STATIC_INLINE uint8_t nrf_stm_tcsr_traceid_get(NRF_STM_Type const * p_reg)
706 {
707     return (uint8_t)((p_reg->TCSR & STM_TCSR_TRACEID_Msk) >> STM_TCSR_TRACEID_Pos);
708 }
709 
nrf_stm_spfeat1r_prot_get(NRF_STM_Type const * p_reg)710 NRF_STATIC_INLINE nrf_stm_spfeat1r_prot_t nrf_stm_spfeat1r_prot_get(NRF_STM_Type const * p_reg)
711 {
712     return (nrf_stm_spfeat1r_prot_t)((p_reg->SPFEAT1R & STM_SPFEAT1R_PROT_Msk)
713                                      >> STM_SPFEAT1R_PROT_Pos);
714 }
715 
nrf_stm_spfeat1r_ts_get(NRF_STM_Type const * p_reg)716 NRF_STATIC_INLINE nrf_stm_spfeat1r_ts_t nrf_stm_spfeat1r_ts_get(NRF_STM_Type const * p_reg)
717 {
718     return (nrf_stm_spfeat1r_ts_t)((p_reg->SPFEAT1R & STM_SPFEAT1R_TS_Msk)
719                                    >> STM_SPFEAT1R_TS_Pos);
720 }
721 
nrf_stm_spfeat1r_tracebus_get(NRF_STM_Type const * p_reg)722 NRF_STATIC_INLINE uint8_t nrf_stm_spfeat1r_tracebus_get(NRF_STM_Type const * p_reg)
723 {
724     return (uint8_t)((p_reg->SPFEAT1R & STM_SPFEAT1R_TRACEBUS_Msk) >> STM_SPFEAT1R_TRACEBUS_Pos);
725 }
726 
nrf_stm_spfeat1r_trigctl_get(NRF_STM_Type const * p_reg)727 NRF_STATIC_INLINE uint8_t nrf_stm_spfeat1r_trigctl_get(NRF_STM_Type const * p_reg)
728 {
729     return (uint8_t)((p_reg->SPFEAT1R & STM_SPFEAT1R_TRIGCTL_Msk) >> STM_SPFEAT1R_TRIGCTL_Pos);
730 }
731 
nrf_stm_spfeat1r_syncen_get(NRF_STM_Type const * p_reg)732 NRF_STATIC_INLINE nrf_stm_spfeat1r_syncen_t nrf_stm_spfeat1r_syncen_get(NRF_STM_Type const * p_reg)
733 {
734     return (nrf_stm_spfeat1r_syncen_t)((p_reg->SPFEAT1R & STM_SPFEAT1R_SYNCEN_Msk)
735                                        >> STM_SPFEAT1R_SYNCEN_Pos);
736 }
737 
nrf_stm_spfeat2r_spcomp_get(NRF_STM_Type const * p_reg)738 NRF_STATIC_INLINE nrf_stm_spfeat2r_spcomp_t nrf_stm_spfeat2r_spcomp_get(NRF_STM_Type const * p_reg)
739 {
740     return (nrf_stm_spfeat2r_spcomp_t)((p_reg->SPFEAT2R & STM_SPFEAT2R_SPCOMP_Msk)
741                                        >> STM_SPFEAT2R_SPCOMP_Pos);
742 }
743 
nrf_stm_spfeat2r_sptrtype_get(NRF_STM_Type const * p_reg)744 NRF_STATIC_INLINE nrf_stm_spfeat2r_sptrtype_t nrf_stm_spfeat2r_sptrtype_get(NRF_STM_Type const * p_reg)
745 {
746     return (nrf_stm_spfeat2r_sptrtype_t)((p_reg->SPFEAT2R & STM_SPFEAT2R_SPTRTYPE_Msk)
747                                          >> STM_SPFEAT2R_SPTRTYPE_Pos);
748 }
749 
nrf_stm_spfeat2r_dsize_get(NRF_STM_Type const * p_reg)750 NRF_STATIC_INLINE nrf_stm_spfeat2r_dsize_t nrf_stm_spfeat2r_dsize_get(NRF_STM_Type const * p_reg)
751 {
752     return (nrf_stm_spfeat2r_dsize_t)((p_reg->SPFEAT2R & STM_SPFEAT2R_DSIZE_Msk)
753                                       >> STM_SPFEAT2R_DSIZE_Pos);
754 }
755 
nrf_stm_spfeat3r_nummast_get(NRF_STM_Type const * p_reg)756 NRF_STATIC_INLINE uint8_t nrf_stm_spfeat3r_nummast_get(NRF_STM_Type const * p_reg)
757 {
758     return (uint8_t)((p_reg->SPFEAT3R & STM_SPFEAT3R_NUMMAST_Msk) >> STM_SPFEAT3R_NUMMAST_Pos);
759 }
760 
nrf_stm_lar_access_set(NRF_STM_Type * p_reg,uint32_t value)761 NRF_STATIC_INLINE void nrf_stm_lar_access_set(NRF_STM_Type * p_reg, uint32_t value)
762 {
763     p_reg->LAR = ((value << STM_LAR_ACCESS_Pos) & STM_LAR_ACCESS_Msk);
764 }
765 
nrf_stm_lsr_type_get(NRF_STM_Type const * p_reg)766 NRF_STATIC_INLINE nrf_stm_lsr_type_t nrf_stm_lsr_type_get(NRF_STM_Type const * p_reg)
767 {
768     return (nrf_stm_lsr_type_t)((p_reg->LSR & STM_LSR_TYPE_Msk) >> STM_LSR_TYPE_Pos);
769 }
770 
nrf_stm_devid_numsp_get(NRF_STM_Type const * p_reg)771 NRF_STATIC_INLINE uint32_t nrf_stm_devid_numsp_get(NRF_STM_Type const * p_reg)
772 {
773     return ((p_reg->DEVID & STM_DEVID_NUMSP_Msk) >> STM_DEVID_NUMSP_Pos);
774 }
775 
nrf_stm_devtype_major_get(NRF_STM_Type const * p_reg)776 NRF_STATIC_INLINE nrf_stm_devtype_major_t nrf_stm_devtype_major_get(NRF_STM_Type const * p_reg)
777 {
778     return (nrf_stm_devtype_major_t)((p_reg->DEVTYPE & STM_DEVTYPE_MAJOR_Msk)
779                                      >> STM_DEVTYPE_MAJOR_Pos);
780 }
781 
nrf_stm_devtype_sub_get(NRF_STM_Type const * p_reg)782 NRF_STATIC_INLINE nrf_stm_devtype_sub_t nrf_stm_devtype_sub_get(NRF_STM_Type const * p_reg)
783 {
784     return (nrf_stm_devtype_sub_t)((p_reg->DEVTYPE & STM_DEVTYPE_SUB_Msk) >> STM_DEVTYPE_SUB_Pos);
785 }
786 
787 #endif // NRF_DECLARE_ONLY
788 
789 /** @} */
790 
791 #ifdef __cplusplus
792 }
793 #endif
794 
795 #endif // NRF_STM_H__
796