1 // Copyright 2020 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_err.h"
17 #include "esp_log.h"
18 #include "trax.h"
19 #include "soc/dport_reg.h"
20 #include "sdkconfig.h"
21
22 #define TRACEMEM_MUX_PROBLK0_APPBLK1 0
23 #define TRACEMEM_MUX_BLK0_ONLY 1
24 #define TRACEMEM_MUX_BLK1_ONLY 2
25 #define TRACEMEM_MUX_PROBLK1_APPBLK0 3
26
27 static const char* __attribute__((unused)) TAG = "trax";
28
trax_enable(trax_ena_select_t which)29 int trax_enable(trax_ena_select_t which)
30 {
31 #ifndef CONFIG_ESP32_TRAX
32 ESP_LOGE(TAG, "Trax_enable called, but trax is disabled in menuconfig!");
33 return ESP_ERR_NO_MEM;
34 #endif
35 #ifndef CONFIG_ESP32_TRAX_TWOBANKS
36 if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) return ESP_ERR_NO_MEM;
37 #endif
38 if (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP) {
39 DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, (which == TRAX_ENA_PRO_APP_SWAP)?TRACEMEM_MUX_PROBLK1_APPBLK0:TRACEMEM_MUX_PROBLK0_APPBLK1);
40 } else {
41 DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, TRACEMEM_MUX_BLK0_ONLY);
42 }
43 DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_PRO));
44 DPORT_WRITE_PERI_REG(DPORT_APP_TRACEMEM_ENA_REG, (which == TRAX_ENA_PRO_APP || which == TRAX_ENA_PRO_APP_SWAP || which == TRAX_ENA_APP));
45 return ESP_OK;
46 }
47