1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "soc/dport_reg.h"
17 #include "sdkconfig.h"
20 #include "xtensa-debug-module.h"
24 #define TRACEMEM_MUX_PROBLK0_APPBLK1 0
25 #define TRACEMEM_MUX_BLK0_ONLY 1
26 #define TRACEMEM_MUX_BLK1_ONLY 2
27 #define TRACEMEM_MUX_PROBLK1_APPBLK0 3
29 static const char* TAG = "trax";
31 int trax_enable(trax_ena_select_t which)
33 #if !CONFIG_ESP32_TRAX
34 ESP_LOGE(TAG, "Trax_enable called, but trax is disabled in menuconfig!");
35 return ESP_ERR_NO_MEM;
37 #if !CONFIG_ESP32_TRAX_TWOBANKS
38 if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) return ESP_ERR_NO_MEM;
40 if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) {
41 DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, (which == TRAX_ENA_PRO_APP_SWAP)?TRACEMEM_MUX_PROBLK1_APPBLK0:TRACEMEM_MUX_PROBLK0_APPBLK1);
43 DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, TRACEMEM_MUX_BLK0_ONLY);
45 DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_PRO));
46 DPORT_WRITE_PERI_REG(DPORT_APP_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_APP));
51 int trax_start_trace(trax_downcount_unit_t units_until_stop)
53 #if !CONFIG_ESP32_TRAX
54 ESP_LOGE(TAG, "Trax_start_trace called, but trax is disabled in menuconfig!");
55 return ESP_ERR_NO_MEM;
58 if (eri_read(ERI_TRAX_TRAXSTAT)&TRAXSTAT_TRACT) {
59 ESP_LOGI(TAG, "Stopping active trace first.");
60 //Trace is active. Stop trace.
61 eri_write(ERI_TRAX_DELAYCNT, 0);
62 eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
63 //ToDo: This will probably trigger a trace done interrupt. ToDo: Fix, but how? -JD
64 eri_write(ERI_TRAX_TRAXCTRL, 0);
66 eri_write(ERI_TRAX_PCMATCHCTRL, 31); //do not stop at any pc match
67 v=TRAXCTRL_TREN | TRAXCTRL_TMEN | TRAXCTRL_PTOWS | (1<<TRAXCTRL_SMPER_SHIFT);
68 if (units_until_stop == TRAX_DOWNCOUNT_INSTRUCTIONS) v|=TRAXCTRL_CNTU;
69 //Enable trace. This trace has no stop condition and will just keep on running.
70 eri_write(ERI_TRAX_TRAXCTRL, v);
75 int trax_trigger_traceend_after_delay(int delay)
77 #if !CONFIG_ESP32_TRAX
78 ESP_LOGE(TAG, "Trax_trigger_traceend_after_delay called, but trax is disabled in menuconfig!");
79 return ESP_ERR_NO_MEM;
81 eri_write(ERI_TRAX_DELAYCNT, delay);
82 eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);