]> granicus.if.org Git - esp-idf/blob - components/xtensa-debug-module/trax.c
heap: test: don’t warn about oversized mallocs
[esp-idf] / components / xtensa-debug-module / trax.c
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 <stdio.h>
16 #include "soc/dport_reg.h"
17 #include "sdkconfig.h"
18 #include "esp_err.h"
19 #include "eri.h"
20 #include "xtensa-debug-module.h"
21 #include "trax.h"
22 #include "esp_log.h"
23
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
28
29 static const char* TAG = "trax";
30
31 int trax_enable(trax_ena_select_t which) 
32 {
33 #if !CONFIG_ESP32_TRAX
34     ESP_LOGE(TAG, "Trax_enable called, but trax is disabled in menuconfig!");
35     return ESP_ERR_NO_MEM;
36 #endif
37 #if !CONFIG_ESP32_TRAX_TWOBANKS
38     if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) return ESP_ERR_NO_MEM;
39 #endif
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);
42     } else {
43         DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, TRACEMEM_MUX_BLK0_ONLY);
44     }
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));
47     return ESP_OK;
48 }
49
50
51 int trax_start_trace(trax_downcount_unit_t units_until_stop) 
52 {
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;
56 #endif
57     uint32_t v;
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);
65     }
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);
71     return ESP_OK;
72 }
73
74
75 int trax_trigger_traceend_after_delay(int delay) 
76 {
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;
80 #endif
81     eri_write(ERI_TRAX_DELAYCNT, delay);
82     eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
83     return ESP_OK;
84 }