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 <stdbool.h>
17 
18 #include "esp_err.h"
19 
20 #include "xtensa-debug-module.h"
21 #include "eri.h"
22 
xt_trax_trace_is_active(void)23 bool xt_trax_trace_is_active(void)
24 {
25     return eri_read(ERI_TRAX_TRAXSTAT)&TRAXSTAT_TRACT;
26 }
27 
_xt_trax_start_trace(bool instructions)28 static void _xt_trax_start_trace(bool instructions)
29 {
30     uint32_t v;
31     eri_write(ERI_TRAX_PCMATCHCTRL, 31); //do not stop at any pc match
32     v=TRAXCTRL_TREN | TRAXCTRL_TMEN | TRAXCTRL_PTOWS | (1<<TRAXCTRL_SMPER_SHIFT);
33     if (instructions) {
34         v|=TRAXCTRL_CNTU;
35     }
36     //Enable trace. This trace has no stop condition and will just keep on running.
37     eri_write(ERI_TRAX_TRAXCTRL, v);
38 }
39 
xt_trax_start_trace_instructions(void)40 void xt_trax_start_trace_instructions(void)
41 {
42     _xt_trax_start_trace(true);
43 }
44 
xt_trax_start_trace_words(void)45 void xt_trax_start_trace_words(void)
46 {
47     _xt_trax_start_trace(false);
48 }
49 
xt_trax_trigger_traceend_after_delay(int delay)50 void xt_trax_trigger_traceend_after_delay(int delay)
51 {
52     eri_write(ERI_TRAX_DELAYCNT, delay);
53     eri_write(ERI_TRAX_TRAXCTRL, eri_read(ERI_TRAX_TRAXCTRL)|TRAXCTRL_TRSTP);
54     //ToDo: This will probably trigger a trace done interrupt. ToDo: Fix, but how? -JD
55     eri_write(ERI_TRAX_TRAXCTRL, 0);
56 }
57