1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  *   list of conditions and the following disclaimer in the documentation and/or
13  *   other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  *   contributors may be used to endorse or promote products derived from this
17  *   software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #ifndef _DBG_RAM_CAPTURE_H_
31 /* clang-format off */
32 #define _DBG_RAM_CAPTURE_H_
33 /* clang-format on */
34 
35 #include "fsl_common.h"
36 #include "fsl_device_registers.h"
37 
38 /*!
39  * @addtogroup xcvr
40  * @{
41  */
42 
43 /*! @file*/
44 
45 /*******************************************************************************
46  * Definitions
47  ******************************************************************************/
48 /* Page definitions */
49 #define DBG_PAGE_IDLE           (0x00)
50 #define DBG_PAGE_RXDIGIQ        (0x01)
51 #define DBG_PAGE_RAWADCIQ       (0x04)
52 #define DBG_PAGE_DCESTIQ        (0x07)
53 #define DBG_PAGE_RXINPH         (0x0A)
54 #define DBG_PAGE_DEMOD_HARD     (0x0B)
55 #define DBG_PAGE_DEMOD_SOFT     (0x0C)
56 #define DBG_PAGE_DEMOD_DATA     (0x0D)
57 #define DBG_PAGE_DEMOD_CFO_PH   (0x0E)
58 
59 typedef enum _dbgRamStatus
60 {
61     DBG_RAM_SUCCESS = 0,
62     DBG_RAM_FAIL_SAMPLE_NUM_LIMIT = 1,
63     DBG_RAM_FAIL_PAGE_ERROR = 2,
64     DBG_RAM_FAIL_NULL_POINTER = 3,
65     DBG_RAM_INVALID_TRIG_SETTING = 4,
66     DBG_RAM_FAIL_NOT_ENOUGH_SAMPLES = 5,
67     DBG_RAM_CAPTURE_NOT_COMPLETE = 6, /* Not an error response, but an indication that capture isn't complete for status polling */
68 } dbgRamStatus_t;
69 
70 #if RADIO_IS_GEN_3P0
71 typedef enum _dbgRamStartTriggerType
72 {
73     NO_START_TRIG = 0,
74     START_ON_FSK_PREAMBLE_FOUND = 1,
75     START_ON_FSK_AA_MATCH = 2,
76     START_ON_ZBDEMOD_PREAMBLE_FOUND = 3,
77     START_ON_ZBDEMOD_SFD_MATCH = 4,
78     START_ON_AGC_DCOC_GAIN_CHG = 5,
79     START_ON_TSM_RX_DIG_EN = 6,
80     START_ON_TSM_SPARE2_EN = 7,
81     INVALID_START_TRIG = 8
82 } dbgRamStartTriggerType;
83 
84 typedef enum _dbgRamStopTriggerType
85 {
86     NO_STOP_TRIG = 0,
87     STOP_ON_FSK_PREAMBLE_FOUND = 1,
88     STOP_ON_FSK_AA_MATCH = 2,
89     STOP_ON_ZBDEMOD_PREAMBLE_FOUND = 3,
90     STOP_ON_ZBDEMOD_SFD_MATCH = 4,
91     STOP_ON_AGC_DCOC_GAIN_CHG = 5,
92     STOP_ON_TSM_RX_DIG_EN = 6,
93     STOP_ON_TSM_SPARE3_EN = 7,
94     STOP_ON_TSM_PLL_UNLOCK = 8,
95     STOP_ON_BLE_CRC_ERROR_INC = 9,
96     STOP_ON_CRC_FAIL_ZGBE_GENFSK = 10,
97     STOP_ON_GENFSK_HEADER_FAIL = 11,
98     INVALID_STOP_TRIG = 12
99 } dbgRamStopTriggerType;
100 #endif /* RADIO_IS_GEN_3P0 */
101 
102 /*! *********************************************************************************
103  * \brief  This function prepares for sample capture to packet RAM.
104  *
105  * \return None.
106  *
107  * \details
108  * This routine assumes that some other functions in the calling routine both set
109  * the channel and force RX warmup before calling ::dbg_ram_capture().
110  ***********************************************************************************/
111 void dbg_ram_init(void);
112 
113 /*! *********************************************************************************
114  * \brief  This function performs any state restoration at the completion of PKT RAM capture.
115  *
116  * \details
117  * Any clocks enabled to the packet RAM capture circuitry are disabled.
118  ***********************************************************************************/
119 void dbg_ram_release(void);
120 
121 #if RADIO_IS_GEN_3P0
122 /*! *********************************************************************************
123  * \brief  This function initiates the capture of transceiver data to the transceiver packet RAM.
124  *
125  * \param[in] dbg_page - The page selector (DBG_PAGE).
126  * \param[in] dbg_start_trigger - The trigger to start acquisition (must be "no trigger" if a stop trigger is enabled).
127  * \param[in] dbg_stop_trigger - The trigger to stop acquisition (must be "no trigger" if a start trigger is enabled).
128  *
129  * \return Status of the request.
130  *
131  * \details
132  * This function starts the process of capturing data to the packet RAM. Depending upon the start and stop trigger
133  * settings, the actual capture process can take an indeterminate amount of time. Other APIs are provided to
134  * perform a blocking wait for completion or allow polling for completion of the capture.
135  * After any capture has completed, a separate routine must be called to postprocess the capture and copy all
136  * data out of the packet RAM into a normal RAM buffer.
137  ***********************************************************************************/
138 dbgRamStatus_t dbg_ram_start_capture(uint8_t dbg_page, dbgRamStartTriggerType start_trig, dbgRamStopTriggerType stop_trig);
139 
140 /*! *********************************************************************************
141  * \brief  This function performs a blocking wait for completion of the capture of transceiver data to the transceiver packet RAM.
142  *
143  * \return Status of the request, DBG_RAM_SUCCESS if capture is complete.
144  *
145  * \details
146  * This function performs a wait loop for capture completion and may take an indeterminate amount of time for
147  * some capture trigger types.
148  ***********************************************************************************/
149 dbgRamStatus_t dbg_ram_wait_for_complete(void); /* Blocking wait for capture completion, no matter what trigger type */
150 
151 /*! *********************************************************************************
152  * \brief  This function polls the state of the capture of transceiver data to the transceiver packet RAM.
153  *
154  * \return Status of the request, DBG_RAM_SUCCESS if capture is complete, DBG_RAM_CAPTURE_NOT_COMPLETE if not complete.
155  *
156  ***********************************************************************************/
157 dbgRamStatus_t dbg_ram_poll_capture_status(void); /* Non-blocking completion check, just reads the current status of the capure */
158 
159 /*! *********************************************************************************
160  * \brief  This function processes the captured data into a usable order and copies from packet RAM to normal RAM.
161  *
162  * \param[in] dbg_page - The page selector (DBG_PAGE).
163  * \param[in] buffer_sz_bytes - The size of the output buffer (in bytes)
164  * \param[in] result_buffer - The pointer to the output buffer of a size large enough for the samples.
165  *
166  * \return None.
167  *
168  * \details
169  * Data is copied from packet RAM in bytes to ensure no access problems. Data is unpacked from packet RAM
170  * (either sequentially captured or simultaneously captured) into a linear RAM buffer in system RAM.
171  * If a start trigger is enabled then the first buffer_sz_bytes that are captured are copied out.
172  * If a stop trigger is enabled then the last buffer_sz_bytes that are captured are copied out.
173  ***********************************************************************************/
174 dbgRamStatus_t dbg_ram_postproc_capture(uint8_t dbg_page, uint16_t buffer_sz_bytes, void * result_buffer); /* postprocess a capture to unpack data */
175 
176 #else
177 /*! *********************************************************************************
178  * \brief  This function captures transceiver data to the transceiver packet RAM.
179  *
180  * \param[in] dbg_page - The page selector (DBG_PAGE).
181  * \param[in] buffer_sz_bytes - The size of the output buffer (in bytes)
182  * \param[in] result_buffer - The pointer to the output buffer of a size large enough for the samples.
183  *
184  * \return None.
185  *
186  * \details
187  * The capture to packet RAM always captures a full PKT_RAM worth of samples. The samples will be
188  * copied to the buffer pointed to by result_buffer parameter until buffer_sz_bytes worth of data have
189  * been copied. Data will be copied
190  * NOTE: This routine has a slight hazard of getting stuck waiting for debug RAM to fill up when RX has
191  * not been enabled or RX ends before the RAM fills up (such as when capturing packet data ). It is
192  * intended to be used with manually triggered RX where RX data will continue as long as needed.
193  ***********************************************************************************/
194 dbgRamStatus_t dbg_ram_capture(uint8_t dbg_page, uint16_t buffer_sz_bytes, void * result_buffer);
195 #endif /* RADIO_IS_GEN_3P0 */
196 
197 /* @} */
198 
199 #if defined(__cplusplus)
200 }
201 #endif
202 
203 /*! @}*/
204 
205 #endif /* _DBG_RAM_CAPTURE_H_ */
206 
207