1 /*
2  * Copyright (c) 2022 - 2025, 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 NRFX_TBM_H__
35 #define NRFX_TBM_H__
36 
37 #include <nrfx.h>
38 #include <hal/nrf_tbm.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /**
45  * @defgroup nrfx_tbm TBM driver
46  * @{
47  * @ingroup nrf_tbm
48  * @brief   Trace Buffer Monitor (TBM) driver.
49  */
50 
51 /** @brief Structure for TBM configuration. */
52 typedef struct
53 {
54     uint32_t size;               /**< Buffer size (32 bit words). */
55     uint8_t  interrupt_priority; /**< Interrupt priority. */
56 } nrfx_tbm_config_t;
57 
58 /** @brief tbm default configuration. */
59 #define NRFX_TBM_DEFAULT_CONFIG                                        \
60     {                                                                  \
61         .size = 128,                                                   \
62         .interrupt_priority = NRFX_TBM_DEFAULT_CONFIG_IRQ_PRIORITY,    \
63     }
64 
65 /**
66  * @brief tbm driver data ready handler type.
67  *
68  * @param event Event.
69  */
70 typedef void (* nrfx_tbm_event_handler_t)(nrf_tbm_event_t event);
71 
72 /**
73  * @brief Function for initializing the TBM driver.
74  *
75  * @param[in] p_config  pointer to the structure with initial configuration.
76  * @param[in] handler   data handler provided by the user. if not provided,
77  *                      the driver is initialized in blocking mode.
78  *
79  * @retval NRFX_SUCCESS       Driver was successfully initialized.
80  * @retval NRFX_ERROR_ALREADY Driver was already initialized.
81  */
82 nrfx_err_t nrfx_tbm_init(nrfx_tbm_config_t const * p_config, nrfx_tbm_event_handler_t handler);
83 
84 /** @brief Function for starting the TBM. */
85 void nrfx_tbm_start(void);
86 
87 /** @brief Function for stopping the TBM. */
88 void nrfx_tbm_stop(void);
89 
90 /** @brief Function for uninitializing the TBM driver. */
91 void nrfx_tbm_uninit(void);
92 
93 /**
94  * @brief Function for checking if the TBM driver is initialized.
95  *
96  * @retval true  Driver is already initialized.
97  * @retval false Driver is not initialized.
98  */
99 bool nrfx_tbm_init_check(void);
100 
101 /**
102  * @brief Function for getting current counter value.
103  *
104  * @return Current counter value.
105  */
106 uint32_t nrfx_tbm_count_get(void);
107 
108 /** @} */
109 
110 void nrfx_tbm_irq_handler(void);
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif // NRFX_TBM_H__
117