mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 05:59:15 +01:00
[SC64][SW] Added controller stack usage diagnostics
This commit is contained in:
parent
65baa521b4
commit
285d5d6a6f
@ -22,3 +22,4 @@
|
|||||||
| `p` | **FLASH_WAIT_BUSY** | wait | --- | --- | erase_block_size | Wait until flash ready / get flash block erase size |
|
| `p` | **FLASH_WAIT_BUSY** | wait | --- | --- | erase_block_size | Wait until flash ready / get flash block erase size |
|
||||||
| `P` | **FLASH_ERASE_BLOCK** | address | --- | --- | --- | Start flash block erase |
|
| `P` | **FLASH_ERASE_BLOCK** | address | --- | --- | --- | Start flash block erase |
|
||||||
| `?` | **DEBUG_GET** | --- | --- | --- | debug_data | Get internal FPGA debug info |
|
| `?` | **DEBUG_GET** | --- | --- | --- | debug_data | Get internal FPGA debug info |
|
||||||
|
| `%` | **STACK_USAGE_GET** | --- | --- | --- | stack_usage | Get per task stack usage |
|
||||||
|
@ -31,16 +31,13 @@ $(BUILD_DIR)/$(EXE_NAME).elf: $(OBJS) $(LD_SCRIPT)
|
|||||||
$(BUILD_DIR)/$(EXE_NAME).bin: $(BUILD_DIR)/$(EXE_NAME).elf
|
$(BUILD_DIR)/$(EXE_NAME).bin: $(BUILD_DIR)/$(EXE_NAME).elf
|
||||||
$(OBJCOPY) -O binary --gap-fill 0xFF $< $@
|
$(OBJCOPY) -O binary --gap-fill 0xFF $< $@
|
||||||
|
|
||||||
$(BUILD_DIR)/$(EXE_NAME).hex: $(BUILD_DIR)/$(EXE_NAME).bin
|
|
||||||
@$(OBJCOPY) -I binary -O ihex $< $@
|
|
||||||
|
|
||||||
print_size: $(BUILD_DIR)/$(EXE_NAME).elf
|
print_size: $(BUILD_DIR)/$(EXE_NAME).elf
|
||||||
@echo 'Size of modules:'
|
@echo 'Size of modules:'
|
||||||
@$(SIZE) -B -d -t --common $(OBJS)
|
@$(SIZE) -B -d -t --common $(OBJS)
|
||||||
@echo 'Size of $(EXE_NAME):'
|
@echo 'Size of $(EXE_NAME):'
|
||||||
@$(SIZE) -B -d $<
|
@$(SIZE) -B -d $<
|
||||||
|
|
||||||
all: $(BUILD_DIR)/$(EXE_NAME).hex print_size
|
all: $(BUILD_DIR)/$(EXE_NAME).bin print_size
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rf ./$(BUILD_DIR)/*
|
@rm -rf ./$(BUILD_DIR)/*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include <stdint.h>
|
#include "app.h"
|
||||||
#include "cic.h"
|
#include "cic.h"
|
||||||
#include "gvr.h"
|
#include "gvr.h"
|
||||||
#include "hw.h"
|
#include "hw.h"
|
||||||
@ -19,6 +19,13 @@ uint8_t led_stack[LED_STACK_SIZE] __attribute__((aligned(8)));
|
|||||||
uint8_t gvr_stack[GVR_STACK_SIZE] __attribute__((aligned(8)));
|
uint8_t gvr_stack[GVR_STACK_SIZE] __attribute__((aligned(8)));
|
||||||
|
|
||||||
|
|
||||||
|
void app_get_stack_usage (uint32_t *usage) {
|
||||||
|
*usage++ = task_get_stack_usage(cic_stack, CIC_STACK_SIZE);
|
||||||
|
*usage++ = task_get_stack_usage(rtc_stack, RTC_STACK_SIZE);
|
||||||
|
*usage++ = task_get_stack_usage(led_stack, LED_STACK_SIZE);
|
||||||
|
*usage++ = task_get_stack_usage(gvr_stack, GVR_STACK_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
void app (void) {
|
void app (void) {
|
||||||
hw_init();
|
hw_init();
|
||||||
cic_hw_init();
|
cic_hw_init();
|
||||||
|
11
sw/controller/src/app.h
Normal file
11
sw/controller/src/app.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef APP_H__
|
||||||
|
#define APP_H__
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
void app_get_stack_usage (uint32_t *usage);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define TASK_INITIAL_XPSR (0x21000000UL)
|
#define TASK_INITIAL_XPSR (0x21000000UL)
|
||||||
#define TASK_CONTEXT_SWITCH() { SCB->ICSR = (1 << SCB_ICSR_PENDSVSET_Pos); }
|
#define TASK_CONTEXT_SWITCH() { SCB->ICSR = (1 << SCB_ICSR_PENDSVSET_Pos); }
|
||||||
|
#define TASK_STACK_FILL_VALUE (0xDEADBEEF)
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -38,7 +39,9 @@ static void task_initialize (task_id_t id) {
|
|||||||
*--sp = TASK_INITIAL_XPSR;
|
*--sp = TASK_INITIAL_XPSR;
|
||||||
*--sp = task->initial_pc;
|
*--sp = task->initial_pc;
|
||||||
*--sp = ((uint32_t) (task_exit));
|
*--sp = ((uint32_t) (task_exit));
|
||||||
sp -= 13;
|
for (int i = 0; i < 13; i++) {
|
||||||
|
*--sp = 0;
|
||||||
|
}
|
||||||
task->sp = ((uint32_t) (sp));
|
task->sp = ((uint32_t) (sp));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +70,9 @@ static uint32_t task_switch_context (uint32_t sp) {
|
|||||||
|
|
||||||
void task_create (task_id_t id, void (*code)(void), void *stack, size_t stack_size) {
|
void task_create (task_id_t id, void (*code)(void), void *stack, size_t stack_size) {
|
||||||
if (id < __TASK_ID_MAX) {
|
if (id < __TASK_ID_MAX) {
|
||||||
|
for (size_t i = 0; i < stack_size; i += sizeof(uint32_t)) {
|
||||||
|
(*(uint32_t *) (stack + i)) = TASK_STACK_FILL_VALUE;
|
||||||
|
}
|
||||||
task_t *task = &task_table[id];
|
task_t *task = &task_table[id];
|
||||||
task->initial_pc = (uint32_t) (code);
|
task->initial_pc = (uint32_t) (code);
|
||||||
task->initial_sp = (((uint32_t) (stack)) + stack_size);
|
task->initial_sp = (((uint32_t) (stack)) + stack_size);
|
||||||
@ -90,6 +96,15 @@ void task_set_ready_and_reset (task_id_t id) {
|
|||||||
TASK_CONTEXT_SWITCH();
|
TASK_CONTEXT_SWITCH();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t task_get_stack_usage (void *stack, size_t stack_size) {
|
||||||
|
for (size_t i = 0; i < stack_size; i += sizeof(uint32_t)) {
|
||||||
|
if ((*(uint32_t *) (stack + i)) != TASK_STACK_FILL_VALUE) {
|
||||||
|
return (stack_size - i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
__attribute__((naked)) void task_scheduler_start (void) {
|
__attribute__((naked)) void task_scheduler_start (void) {
|
||||||
uint32_t sp = task_table[task_current].sp;
|
uint32_t sp = task_table[task_current].sp;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ void task_create (task_id_t id, void (*code)(void), void *stack, size_t stack_si
|
|||||||
void task_yield (void);
|
void task_yield (void);
|
||||||
void task_set_ready (task_id_t id);
|
void task_set_ready (task_id_t id);
|
||||||
void task_set_ready_and_reset (task_id_t id);
|
void task_set_ready_and_reset (task_id_t id);
|
||||||
|
size_t task_get_stack_usage (void *stack, size_t stack_size);
|
||||||
void task_scheduler_start (void);
|
void task_scheduler_start (void);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "app.h"
|
||||||
#include "cfg.h"
|
#include "cfg.h"
|
||||||
#include "cic.h"
|
#include "cic.h"
|
||||||
#include "dd.h"
|
#include "dd.h"
|
||||||
@ -295,6 +296,13 @@ static void usb_rx_process (void) {
|
|||||||
p.response_info.data[1] = fpga_reg_get(REG_DEBUG_1);
|
p.response_info.data[1] = fpga_reg_get(REG_DEBUG_1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '%':
|
||||||
|
p.rx_state = RX_STATE_IDLE;
|
||||||
|
p.response_pending = true;
|
||||||
|
p.response_info.data_length = 16;
|
||||||
|
app_get_stack_usage(p.response_info.data);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
p.rx_state = RX_STATE_IDLE;
|
p.rx_state = RX_STATE_IDLE;
|
||||||
p.response_pending = true;
|
p.response_pending = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user