Skip to content

Commit

Permalink
Merge branch 'astyle_format_coredump' into 'master'
Browse files Browse the repository at this point in the history
refactor(espcoredump): format coredump component with astyle

See merge request espressif/esp-idf!29114
  • Loading branch information
erhankur committed Feb 20, 2024
2 parents 41ee4ad + f4acf0b commit 5f42493
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 406 deletions.
6 changes: 3 additions & 3 deletions components/esp_event/host_test/fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ enum class CreateAnd {
};

struct MockQueue : public CMockFix {
MockQueue (CreateAnd flags) : queue(reinterpret_cast<QueueHandle_t>(0xdeadbeef))
MockQueue(CreateAnd flags) : queue(reinterpret_cast<QueueHandle_t>(0xdeadbeef))
{
if (flags == CreateAnd::FAIL) {
xQueueGenericCreate_ExpectAnyArgsAndReturn(nullptr);
Expand All @@ -101,7 +101,7 @@ struct MockQueue : public CMockFix {
};

struct MockMutex : public CMockFix {
MockMutex (CreateAnd flags) : sem(reinterpret_cast<QueueHandle_t>(0xdeadbeef))
MockMutex(CreateAnd flags) : sem(reinterpret_cast<QueueHandle_t>(0xdeadbeef))
{
if (flags == CreateAnd::FAIL) {
xQueueCreateMutex_ExpectAnyArgsAndReturn(nullptr);
Expand All @@ -124,7 +124,7 @@ struct MockMutex : public CMockFix {
};

struct MockTask : public CMockFix {
MockTask (CreateAnd flags) : task((TaskHandle_t) 1)
MockTask(CreateAnd flags) : task((TaskHandle_t) 1)
{
if (flags == CreateAnd::FAIL) {
xTaskCreatePinnedToCore_ExpectAnyArgsAndReturn(pdFALSE);
Expand Down
12 changes: 6 additions & 6 deletions components/espcoredump/include/esp_core_dump.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -142,11 +142,11 @@ esp_err_t esp_core_dump_image_erase(void);
*
* Example usage:
* @code{c}
char panic_reason[200];
esp_err_t err = esp_core_dump_get_panic_reason(panic_reason, sizeof(panic_reason));
if (err == ESP_OK) {
ESP_LOGW(TAG, "%s", panic_reason);
}
char panic_reason[200];
esp_err_t err = esp_core_dump_get_panic_reason(panic_reason, sizeof(panic_reason));
if (err == ESP_OK) {
ESP_LOGW(TAG, "%s", panic_reason);
}
* @endcode
*/
esp_err_t esp_core_dump_get_panic_reason(char *reason_buffer, size_t buffer_size);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -50,7 +50,6 @@ bool esp_core_dump_get_task_snapshot(core_dump_task_handle_t handle,
*/
void esp_core_dump_reset_tasks_snapshots_iter(void);


/**
* @brief Check if the TCB passed as a parameter is sane.
*
Expand All @@ -67,7 +66,6 @@ bool esp_core_dump_tcb_addr_is_sane(uint32_t addr);
*/
uint32_t esp_core_dump_get_user_ram_segments(void);


/**
* @brief Get start address and size of a memory region.
*
Expand All @@ -79,23 +77,20 @@ uint32_t esp_core_dump_get_user_ram_segments(void);
*/
int esp_core_dump_get_user_ram_info(coredump_region_t region, uint32_t *start);


/**
* @brief Check if the current task is in an ISR.
*
* @return true if task in an ISR, false else.
*/
bool esp_core_dump_in_isr_context(void);


/**
* @brief Get the size all the memory regions (DRAM, RTC, RTC_FAST, IRAM)
*
* @return Size, in bytes, of all the memory regions.
*/
uint32_t esp_core_dump_get_user_ram_size(void);


/**
* @brief Get TCB length, in bytes.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -60,15 +60,13 @@ void esp_core_dump_reset_fake_stacks(void);
*/
uint32_t esp_core_dump_get_isr_stack_end(void);


/**
* @brief Get the top of the ISR stack.
*
* @return Pointer to the top of the ISR stack.
*/
uint8_t* esp_core_dump_get_isr_stack_top(void);


/**
* @brief Check the stack defined by address given.
*
Expand All @@ -78,7 +76,6 @@ uint8_t* esp_core_dump_get_isr_stack_top(void);
*/
bool esp_core_dump_check_stack(core_dump_task_header_t *task);


/**
* @brief Check if the memory segment is sane.
*
Expand All @@ -89,7 +86,6 @@ bool esp_core_dump_check_stack(core_dump_task_header_t *task);
*/
bool esp_core_dump_mem_seg_is_sane(uint32_t addr, uint32_t sz);


/**
* @brief Get the stack of a task.
*
Expand All @@ -104,7 +100,6 @@ bool esp_core_dump_mem_seg_is_sane(uint32_t addr, uint32_t sz);
uint32_t esp_core_dump_get_stack(core_dump_task_header_t* task_snapshot,
uint32_t* stk_vaddr, uint32_t* stk_paddr);


/**
* @brief Check the task passed as a parameter.
*
Expand All @@ -120,7 +115,6 @@ uint32_t esp_core_dump_get_stack(core_dump_task_header_t* task_snapshot,
*/
bool esp_core_dump_check_task(core_dump_task_header_t *task);


/**
* @brief Get a dump of the task's registers.
*
Expand Down
19 changes: 6 additions & 13 deletions components/espcoredump/include_core_dump/esp_core_dump_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,15 @@ extern "C" {
* MUST be a multiple of 16.
*/
#if (COREDUMP_CACHE_SIZE % 16) != 0
#error "Coredump cache size must be a multiple of 16"
#error "Coredump cache size must be a multiple of 16"
#endif

/**
* @brief Chip ID associated to this implementation.
*/
#define COREDUMP_VERSION_CHIP CONFIG_IDF_FIRMWARE_CHIP_ID

typedef struct _core_dump_write_data_t
{
typedef struct _core_dump_write_data_t {
uint32_t off; /*!< Current offset of data being written */
uint8_t cached_data[COREDUMP_CACHE_SIZE]; /*!< Cache used to write to flash */
uint8_t cached_bytes; /*!< Number of bytes filled in the cached */
Expand All @@ -116,7 +115,6 @@ typedef esp_err_t (*esp_core_dump_flash_write_data_t)(core_dump_write_data_t* pr
void * data,
uint32_t data_len);


/**
* @brief Core dump emitter control structure.
* This structure contains the functions that are called in order to write
Expand All @@ -127,8 +125,7 @@ typedef esp_err_t (*esp_core_dump_flash_write_data_t)(core_dump_write_data_t* pr
* - write (called once or more)
* - end
*/
typedef struct _core_dump_write_config_t
{
typedef struct _core_dump_write_config_t {
esp_core_dump_write_prepare_t prepare; /*!< Function called for sanity checks */
esp_core_dump_write_start_t start; /*!< Function called at the beginning of data writing */
esp_core_dump_flash_write_data_t write; /*!< Function called to write data chunk */
Expand All @@ -139,8 +136,7 @@ typedef struct _core_dump_write_config_t
/**
* @brief Core dump data header
* This header predecesses the actual core dump data (ELF or binary). */
typedef struct _core_dump_header_t
{
typedef struct _core_dump_header_t {
uint32_t data_len; /*!< Data length */
uint32_t version; /*!< Core dump version */
uint32_t tasks_num; /*!< Number of tasks */
Expand All @@ -158,8 +154,7 @@ typedef void* core_dump_task_handle_t;
/**
* @brief Header for the tasks
*/
typedef struct _core_dump_task_header_t
{
typedef struct _core_dump_task_header_t {
core_dump_task_handle_t tcb_addr; /*!< TCB address */
uint32_t stack_start; /*!< Start of the stack address */
uint32_t stack_end; /*!< End of the stack address */
Expand All @@ -168,8 +163,7 @@ typedef struct _core_dump_task_header_t
/**
* @brief Core dump memory segment header
*/
typedef struct _core_dump_mem_seg_header_t
{
typedef struct _core_dump_mem_seg_header_t {
uint32_t start; /*!< Memory region start address */
uint32_t size; /*!< Memory region size */
} core_dump_mem_seg_header_t;
Expand All @@ -179,7 +173,6 @@ typedef struct _core_dump_mem_seg_header_t
*/
void esp_core_dump_flash_init(void);


/**
* @brief Common core dump write function
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -35,22 +35,21 @@ typedef struct {
*/
FORCE_INLINE_ATTR void esp_core_dump_replace_sp(void* new_sp, core_dump_stack_context_t* old_ctx)
{
asm volatile ("mv %0, sp \n\t\
asm volatile("mv %0, sp \n\t\
mv sp, %1 \n\t\
"
: "=&r"(old_ctx->sp)
: "r"(new_sp));
: "=&r"(old_ctx->sp)
: "r"(new_sp));
}


/**
* @brief Restore the stack pointer that was returned when calling `esp_core_dump_replace_sp()` function.
*
* @param ctx CPU context, related to SP, to restore.
*/
FORCE_INLINE_ATTR void esp_core_dump_restore_sp(core_dump_stack_context_t* old_ctx)
{
asm volatile ("mv sp, %0 \n\t" :: "r"(old_ctx->sp));
asm volatile("mv sp, %0 \n\t" :: "r"(old_ctx->sp));
}

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -48,22 +48,21 @@ FORCE_INLINE_ATTR void esp_core_dump_replace_sp(void* new_sp, core_dump_stack_co
xthal_window_spill();

/* Backup the special registers PS, WindowBase and WindowStart. We will need to restore them later */
asm volatile ("mov %0, sp \n" \
"mov %1, a0 \n" \
"rsr.ps %2 \n"\
"rsr.windowbase %3 \n"\
"rsr.windowstart %4 \n"\
: "=r"(old_ctx->sp),
"=r"(old_ctx->a0),
"=r"(old_ctx->ps),
"=r"(old_ctx->windowbase),
"=r"(old_ctx->windowstart) :);
asm volatile("mov %0, sp \n" \
"mov %1, a0 \n" \
"rsr.ps %2 \n"\
"rsr.windowbase %3 \n"\
"rsr.windowstart %4 \n"\
: "=r"(old_ctx->sp),
"=r"(old_ctx->a0),
"=r"(old_ctx->ps),
"=r"(old_ctx->windowbase),
"=r"(old_ctx->windowstart) :);

/* Set the new stack */
SET_STACK(new_sp);
}


/**
* @brief Restore the stack pointer that was returned when calling `esp_core_dump_replace_sp()` function.
*
Expand All @@ -74,23 +73,23 @@ FORCE_INLINE_ATTR void esp_core_dump_restore_sp(core_dump_stack_context_t* old_c
/* Start by disabling WindowOverflowEnable bit from PS to make sure we won't get a Window Overflow exception
* restoring WindowBase and WindowStart registers */
const uint32_t ps_woe = old_ctx->ps & ~(PS_WOE_MASK);
asm volatile ( \
"wsr.ps %0 \n"\
"rsync \n"\
"wsr.windowbase %1 \n"\
"rsync \n"\
"wsr.windowstart %2 \n"\
"rsync \n"\
"mov sp, %3 \n" \
"mov a0, %4 \n" \
"wsr.ps %5 \n"\
"rsync \n"\
:: "r"(ps_woe),
"r"(old_ctx->windowbase),
"r"(old_ctx->windowstart),
"r"(old_ctx->sp),
"r"(old_ctx->a0),
"r"(old_ctx->ps));
asm volatile(\
"wsr.ps %0 \n"\
"rsync \n"\
"wsr.windowbase %1 \n"\
"rsync \n"\
"wsr.windowstart %2 \n"\
"rsync \n"\
"mov sp, %3 \n" \
"mov a0, %4 \n" \
"wsr.ps %5 \n"\
"rsync \n"\
:: "r"(ps_woe),
"r"(old_ctx->windowbase),
"r"(old_ctx->windowstart),
"r"(old_ctx->sp),
"r"(old_ctx->a0),
"r"(old_ctx->ps));
}

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 5f42493

Please sign in to comment.