move dump_xxx functions to debug_uart.c.

This commit is contained in:
jun2sak 2021-02-23 12:16:37 +09:00
parent 372c98626a
commit ec64fa6a29
4 changed files with 30 additions and 35 deletions

10
main.c
View File

@ -588,12 +588,10 @@ int __attribute__((used)) main(void) {
serial_init();
#if 0 //XXX
int rr = (int)common_hal_mcu_processor_get_reset_reason();
const char* rrstr[] = {
"POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM",
"RESET_PIN", "WATCHDOG", "UNKNOWN"
};
dbg_printf("reset_reason=%s\r\n", rrstr[rr]);
{
extern void dbg_dump_reset_reason(void);
dbg_dump_reset_reason();
}
#endif
#if CIRCUITPY_BLEIO

View File

@ -47,26 +47,15 @@ static int is_sleep_memory_valid(void) {
return 0;
}
static void dumpRAMreg(void) {
#ifdef MY_DEBUGUART
int i;
for(i = 0; i <= 8; ++i) {
dbg_printf(" RAM%d:%08X", i, (int)(NRF_POWER->RAM[i].POWER));
if (i==4) dbg_printf("\r\n");
}
dbg_printf("\r\n");
#endif
}
extern void dbg_dump_RAMreg(void);
static void initialize_sleep_memory(void) {
memset((uint8_t *)_sleep_mem, 0, SLEEP_MEMORY_LENGTH);
// also, set RAM[n].POWER register for RAM retention
// nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5]
// nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1]
dumpRAMreg();
for(int ram = 0; ram <= 7; ++ram) {
NRF_POWER->RAM[ram].POWERSET = 0x00030000; // RETENTION for section 0,1
NRF_POWER->RAM[ram].POWERSET = 0x00030000; // RETENTION for section 0,1
};
#ifdef NRF52840
NRF_POWER->RAM[8].POWERSET = 0x001F0000; // RETENTION for section 0..5
@ -74,7 +63,9 @@ static void initialize_sleep_memory(void) {
#ifdef NRF52833
NRF_POWER->RAM[8].POWERSET = 0x00030000; // RETENTION for section 0,1
#endif
dumpRAMreg();
#ifdef MY_DEBUGUART
dbg_dump_RAMreg();
#endif
_sleep_mem_magicnum = SLEEP_MEMORY_DATA_GUARD;
}
@ -82,9 +73,6 @@ static void initialize_sleep_memory(void) {
void alarm_sleep_memory_reset(void) {
if (!is_sleep_memory_valid()) {
initialize_sleep_memory();
#ifdef MY_DEBUGUART
dbg_printf("_sleep_mem[] initialized\r\n");
#endif
}
}

View File

@ -51,17 +51,6 @@
#include "nrfx.h"
#include "nrfx_gpiote.h"
#if 0
// XXX
#define DEBUG_LED_PIN (NRF_GPIO_PIN_MAP(1, 11)) // P1_11 = LED
void _debug_led_init(void) {
nrf_gpio_cfg_output(DEBUG_LED_PIN);
}
void _debug_led_set(int v) {
nrf_gpio_pin_write(DEBUG_LED_PIN, v);
}
#endif
// Singleton instance of SleepMemory.
const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
.base = {

View File

@ -20,9 +20,11 @@
#include "nrfx_uarte.h"
#include "nrfx_rtc.h"
#include "supervisor/serial.h" // dbg_printf()
#include "shared-bindings/microcontroller/Processor.h"
extern const nrfx_rtc_t rtc_instance; // port.c
extern volatile int rtc_woke_up_counter; // port.c
extern uint32_t reset_reason_saved;
const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1);
static int _dbg_uart_initialized = 0;
@ -87,7 +89,7 @@ int dbg_printf(const char *fmt, ...) {
}
void dbg_dumpRTC(void) {
void dbg_dump_RTCreg(void) {
dbg_printf("\r\nRTC2\r\n");
NRF_RTC_Type *r = rtc_instance.p_reg;
dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER);
@ -99,6 +101,24 @@ void dbg_dumpRTC(void) {
dbg_printf("woke_up=%d\r\n", rtc_woke_up_counter);
}
void dbg_dump_RAMreg(void) {
int i;
for(i = 0; i <= 8; ++i) {
dbg_printf(" RAM%d:%08X", i, (int)(NRF_POWER->RAM[i].POWER));
if (i==4) dbg_printf("\r\n");
}
dbg_printf("\r\n");
}
void dbg_dump_reset_reason(void) {
int reset_reason = (int)common_hal_mcu_processor_get_reset_reason();
const char* rr_str[] = {
"POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM",
"RESET_PIN", "WATCHDOG", "UNKNOWN"
};
dbg_printf("reset_reason=%s\r\n", rr_str[reset_reason]);
}
#else /*!MY_DEBUGUART*/
int dbg_printf(const char *fmt, ...) {
return 0;