1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "sdkconfig.h"
8 #include "esp_err.h"
9 #include "eri.h"
10 #include "xtensa-debug-module.h"
11 #include "xt_trax.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 typedef enum {
18     TRAX_DOWNCOUNT_WORDS,
19     TRAX_DOWNCOUNT_INSTRUCTIONS
20 } trax_downcount_unit_t;
21 
22 typedef enum {
23     TRAX_ENA_NONE = 0,
24     TRAX_ENA_PRO,
25     TRAX_ENA_APP,
26     TRAX_ENA_PRO_APP,
27     TRAX_ENA_PRO_APP_SWAP
28 } trax_ena_select_t;
29 
30 /**
31  * @brief  Enable the trax memory blocks to be used as Trax memory.
32  *
33  * @param  pro_cpu_enable : true if Trax needs to be enabled for the pro CPU
34  * @param  app_cpu_enable : true if Trax needs to be enabled for the pro CPU
35  * @param  swap_regions : Normally, the pro CPU writes to Trax mem block 0 while
36  *                        the app cpu writes to block 1. Setting this to true
37  *                        inverts this.
38  *
39  * @return esp_err_t. Fails with ESP_ERR_NO_MEM if Trax enable is requested for 2 CPUs
40  *                    but memmap only has room for 1, or if Trax memmap is disabled
41  *                    entirely.
42  */
43 int trax_enable(trax_ena_select_t ena);
44 
45 /**
46  * @brief  Start a Trax trace on the current CPU
47  *
48  * @param  units_until_stop : Set the units of the delay that gets passed to
49  *              trax_trigger_traceend_after_delay. One of TRAX_DOWNCOUNT_WORDS
50  *              or TRAX_DOWNCOUNT_INSTRUCTIONS.
51  *
52  * @return esp_err_t. Fails with ESP_ERR_NO_MEM if Trax is disabled.
53  */
54 int trax_start_trace(trax_downcount_unit_t units_until_stop);
55 
56 
57 /**
58  * @brief  Trigger a Trax trace stop after the indicated delay. If this is called
59  *         before and the previous delay hasn't ended yet, this will overwrite
60  *         that delay with the new value. The delay will always start at the time
61  *         the function is called.
62  *
63  * @param  delay : The delay to stop the trace in, in the unit indicated to
64  *              trax_start_trace. Note: the trace memory has 4K words available.
65  *
66  * @return esp_err_t
67  */
68 int trax_trigger_traceend_after_delay(int delay);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73