1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "sdkconfig.h"
16 #include "esp_err.h"
17 #include "eri.h"
18 #include "xtensa-debug-module.h"
19 #include "xt_trax.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 typedef enum {
26     TRAX_DOWNCOUNT_WORDS,
27     TRAX_DOWNCOUNT_INSTRUCTIONS
28 } trax_downcount_unit_t;
29 
30 typedef enum {
31     TRAX_ENA_NONE = 0,
32     TRAX_ENA_PRO,
33     TRAX_ENA_APP,
34     TRAX_ENA_PRO_APP,
35     TRAX_ENA_PRO_APP_SWAP
36 } trax_ena_select_t;
37 
38 /**
39  * @brief  Enable the trax memory blocks to be used as Trax memory.
40  *
41  * @param  pro_cpu_enable : true if Trax needs to be enabled for the pro CPU
42  * @param  app_cpu_enable : true if Trax needs to be enabled for the pro CPU
43  * @param  swap_regions : Normally, the pro CPU writes to Trax mem block 0 while
44  *                        the app cpu writes to block 1. Setting this to true
45  *                        inverts this.
46  *
47  * @return esp_err_t. Fails with ESP_ERR_NO_MEM if Trax enable is requested for 2 CPUs
48  *                    but memmap only has room for 1, or if Trax memmap is disabled
49  *                    entirely.
50  */
51 int trax_enable(trax_ena_select_t ena);
52 
53 /**
54  * @brief  Start a Trax trace on the current CPU
55  *
56  * @param  units_until_stop : Set the units of the delay that gets passed to
57  *              trax_trigger_traceend_after_delay. One of TRAX_DOWNCOUNT_WORDS
58  *              or TRAX_DOWNCOUNT_INSTRUCTIONS.
59  *
60  * @return esp_err_t. Fails with ESP_ERR_NO_MEM if Trax is disabled.
61  */
62 int trax_start_trace(trax_downcount_unit_t units_until_stop);
63 
64 
65 /**
66  * @brief  Trigger a Trax trace stop after the indicated delay. If this is called
67  *         before and the previous delay hasn't ended yet, this will overwrite
68  *         that delay with the new value. The delay will always start at the time
69  *         the function is called.
70  *
71  * @param  delay : The delay to stop the trace in, in the unit indicated to
72  *              trax_start_trace. Note: the trace memory has 4K words available.
73  *
74  * @return esp_err_t
75  */
76 int trax_trigger_traceend_after_delay(int delay);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81