• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "esp_log.h"
17 #include "esp_err.h"
18 #include "xtensa-debug-module.h"
19 #include "eri.h"
20 #include "trax.h"
21 #include "sdkconfig.h"
22 
23 #if defined(CONFIG_ESP32_TRAX) || defined(CONFIG_ESP32S2_TRAX)
24 #define WITH_TRAX 1
25 #endif
26 
27 static const char* TAG = "trax";
28 
29 
trax_start_trace(trax_downcount_unit_t units_until_stop)30 int trax_start_trace(trax_downcount_unit_t units_until_stop)
31 {
32 #if !WITH_TRAX
33     ESP_EARLY_LOGE(TAG, "Trax_start_trace called, but trax is disabled in menuconfig!");
34     return ESP_ERR_NO_MEM;
35 #endif
36     uint32_t v;
37     if (eri_read(ERI_TRAX_TRAXSTAT)&TRAXSTAT_TRACT) {
38         ESP_EARLY_LOGI(TAG, "Stopping active trace first.");
39         //Trace is active. Stop trace.
40         eri_write(ERI_TRAX_DELAYCNT, 0);
41         eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
42         //ToDo: This will probably trigger a trace done interrupt. ToDo: Fix, but how? -JD
43         eri_write(ERI_TRAX_TRAXCTRL, 0);
44     }
45     eri_write(ERI_TRAX_PCMATCHCTRL, 31); //do not stop at any pc match
46     v=TRAXCTRL_TREN | TRAXCTRL_TMEN | TRAXCTRL_PTOWS | (1<<TRAXCTRL_SMPER_SHIFT);
47     if (units_until_stop == TRAX_DOWNCOUNT_INSTRUCTIONS) v|=TRAXCTRL_CNTU;
48     //Enable trace. This trace has no stop condition and will just keep on running.
49     eri_write(ERI_TRAX_TRAXCTRL, v);
50     return ESP_OK;
51 }
52 
53 
trax_trigger_traceend_after_delay(int delay)54 int trax_trigger_traceend_after_delay(int delay)
55 {
56 #if !WITH_TRAX
57     ESP_EARLY_LOGE(TAG, "Trax_trigger_traceend_after_delay called, but trax is disabled in menuconfig!");
58     return ESP_ERR_NO_MEM;
59 #endif
60     eri_write(ERI_TRAX_DELAYCNT, delay);
61     eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
62     return ESP_OK;
63 }
64