2017-08-16 23:36:00 +00:00
|
|
|
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// This module implements runtime file I/O API for GCOV.
|
|
|
|
|
2017-09-30 10:07:19 +00:00
|
|
|
#include "esp_task_wdt.h"
|
2017-08-16 23:36:00 +00:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "soc/cpu.h"
|
2019-05-13 10:02:45 +00:00
|
|
|
#include "soc/timer_periph.h"
|
2017-08-16 23:36:00 +00:00
|
|
|
#include "esp_app_trace.h"
|
2019-03-15 09:44:27 +00:00
|
|
|
#include "esp_private/dbg_stubs.h"
|
2019-07-24 15:18:19 +00:00
|
|
|
#include "hal/timer_ll.h"
|
2017-08-16 23:36:00 +00:00
|
|
|
|
2019-09-13 12:49:11 +00:00
|
|
|
#if CONFIG_APPTRACE_GCOV_ENABLE
|
2018-02-15 17:09:03 +00:00
|
|
|
|
|
|
|
#define ESP_GCOV_DOWN_BUF_SIZE 4200
|
2017-08-16 23:36:00 +00:00
|
|
|
|
|
|
|
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL
|
|
|
|
#include "esp_log.h"
|
|
|
|
const static char *TAG = "esp_gcov_rtio";
|
|
|
|
|
2019-11-05 11:20:26 +00:00
|
|
|
extern void __gcov_dump(void);
|
|
|
|
extern void __gcov_reset(void);
|
2018-02-15 17:09:03 +00:00
|
|
|
|
|
|
|
static int esp_dbg_stub_gcov_dump_do(void)
|
|
|
|
{
|
|
|
|
int ret = ESP_OK;
|
|
|
|
|
2018-06-28 13:38:17 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "Alloc apptrace down buf %d bytes", ESP_GCOV_DOWN_BUF_SIZE);
|
|
|
|
void *down_buf = malloc(ESP_GCOV_DOWN_BUF_SIZE);
|
|
|
|
if (down_buf == NULL) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "Could not allocate memory for the buffer");
|
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
|
}
|
|
|
|
ESP_EARLY_LOGV(TAG, "Config apptrace down buf");
|
|
|
|
esp_apptrace_down_buffer_config(down_buf, ESP_GCOV_DOWN_BUF_SIZE);
|
|
|
|
ESP_EARLY_LOGV(TAG, "Dump data...");
|
|
|
|
__gcov_dump();
|
|
|
|
// reset dump status to allow incremental data accumulation
|
|
|
|
__gcov_reset();
|
|
|
|
ESP_EARLY_LOGV(TAG, "Free apptrace down buf");
|
|
|
|
free(down_buf);
|
2018-02-15 17:09:03 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "Finish file transfer session");
|
|
|
|
ret = esp_apptrace_fstop(ESP_APPTRACE_DEST_TRAX);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "Failed to send files transfer stop cmd (%d)!", ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-16 09:33:30 +00:00
|
|
|
void esp_gcov_dump(void)
|
2017-08-16 23:36:00 +00:00
|
|
|
{
|
2018-06-28 13:38:17 +00:00
|
|
|
// disable IRQs on this CPU, other CPU is halted by OpenOCD
|
|
|
|
unsigned irq_state = portENTER_CRITICAL_NESTED();
|
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
2018-02-15 17:09:03 +00:00
|
|
|
int other_core = xPortGetCoreID() ? 0 : 1;
|
|
|
|
esp_cpu_stall(other_core);
|
2017-08-16 23:36:00 +00:00
|
|
|
#endif
|
|
|
|
while (!esp_apptrace_host_is_connected(ESP_APPTRACE_DEST_TRAX)) {
|
|
|
|
// to avoid complains that task watchdog got triggered for other tasks
|
2019-07-24 15:18:19 +00:00
|
|
|
timer_ll_wdt_set_protect(&TIMERG0, false);
|
|
|
|
timer_ll_wdt_feed(&TIMERG0);
|
|
|
|
timer_ll_wdt_set_protect(&TIMERG0, true);
|
2017-08-16 23:36:00 +00:00
|
|
|
// to avoid reboot on INT_WDT
|
2019-07-24 15:18:19 +00:00
|
|
|
timer_ll_wdt_set_protect(&TIMERG1, false);
|
|
|
|
timer_ll_wdt_feed(&TIMERG1);
|
|
|
|
timer_ll_wdt_set_protect(&TIMERG1, true);
|
2017-08-16 23:36:00 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 17:09:03 +00:00
|
|
|
esp_dbg_stub_gcov_dump_do();
|
2018-06-28 13:38:17 +00:00
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
2018-02-15 17:09:03 +00:00
|
|
|
esp_cpu_unstall(other_core);
|
|
|
|
#endif
|
2018-06-28 13:38:17 +00:00
|
|
|
portEXIT_CRITICAL_NESTED(irq_state);
|
2017-08-16 23:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *gcov_rtio_fopen(const char *path, const char *mode)
|
|
|
|
{
|
2018-06-28 13:38:17 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "%s '%s' '%s'", __FUNCTION__, path, mode);
|
2017-08-16 23:36:00 +00:00
|
|
|
return esp_apptrace_fopen(ESP_APPTRACE_DEST_TRAX, path, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gcov_rtio_fclose(void *stream)
|
|
|
|
{
|
2018-02-15 17:09:03 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "%s", __FUNCTION__);
|
2017-08-16 23:36:00 +00:00
|
|
|
return esp_apptrace_fclose(ESP_APPTRACE_DEST_TRAX, stream);
|
|
|
|
}
|
|
|
|
|
2018-02-15 17:09:03 +00:00
|
|
|
size_t gcov_rtio_fread(void *ptr, size_t size, size_t nmemb, void *stream)
|
|
|
|
{
|
2018-06-28 13:38:17 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "%s read %u", __FUNCTION__, size*nmemb);
|
|
|
|
size_t sz = esp_apptrace_fread(ESP_APPTRACE_DEST_TRAX, ptr, size, nmemb, stream);
|
|
|
|
ESP_EARLY_LOGV(TAG, "%s actually read %u", __FUNCTION__, sz);
|
|
|
|
return sz;
|
2018-02-15 17:09:03 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 23:36:00 +00:00
|
|
|
size_t gcov_rtio_fwrite(const void *ptr, size_t size, size_t nmemb, void *stream)
|
|
|
|
{
|
2018-02-15 17:09:03 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "%s", __FUNCTION__);
|
2017-08-16 23:36:00 +00:00
|
|
|
return esp_apptrace_fwrite(ESP_APPTRACE_DEST_TRAX, ptr, size, nmemb, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gcov_rtio_fseek(void *stream, long offset, int whence)
|
|
|
|
{
|
2018-02-15 17:09:03 +00:00
|
|
|
int ret = esp_apptrace_fseek(ESP_APPTRACE_DEST_TRAX, stream, offset, whence);
|
2018-06-28 13:38:17 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "%s(%p %ld %d) = %d", __FUNCTION__, stream, offset, whence, ret);
|
2018-02-15 17:09:03 +00:00
|
|
|
return ret;
|
2017-08-16 23:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long gcov_rtio_ftell(void *stream)
|
|
|
|
{
|
2018-02-15 17:09:03 +00:00
|
|
|
long ret = esp_apptrace_ftell(ESP_APPTRACE_DEST_TRAX, stream);
|
2018-06-28 13:38:17 +00:00
|
|
|
ESP_EARLY_LOGV(TAG, "%s(%p) = %ld", __FUNCTION__, stream, ret);
|
2018-02-15 17:09:03 +00:00
|
|
|
return ret;
|
2017-08-16 23:36:00 +00:00
|
|
|
}
|
|
|
|
#endif
|