From a9339a82047d9b457619efadd4dec3a7d258d889 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 30 Dec 2019 10:47:49 -0700 Subject: [PATCH] Scratch debugging --- src/board/system76/galp3-c/scratch/main.c | 13 +++++++++++ src/board/system76/galp3-c/scratch/scratch.mk | 23 +++++++++++++++---- src/board/system76/galp3-c/scratch/stdio.c | 21 +++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/board/system76/galp3-c/scratch/stdio.c diff --git a/src/board/system76/galp3-c/scratch/main.c b/src/board/system76/galp3-c/scratch/main.c index ff82dd1..9fb4f5c 100644 --- a/src/board/system76/galp3-c/scratch/main.c +++ b/src/board/system76/galp3-c/scratch/main.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -33,6 +34,14 @@ enum PmcState { PMC_STATE_WRITE, }; +void puthex(uint8_t data) { + if (data <= 9) { + putchar(data + '0'); + } else { + putchar(data + 'A'); + } +} + static void pmc_event(struct Pmc * pmc) { static enum PmcState state = PMC_STATE_DEFAULT; @@ -40,6 +49,10 @@ static void pmc_event(struct Pmc * pmc) { if (sts & PMC_STS_IBF) { uint8_t data = pmc_read(pmc); if (sts & PMC_STS_CMD) { + puthex((data >> 4) & 0xF); + puthex(data & 0xF); + putchar('\n'); + switch (state) { case PMC_STATE_DEFAULT: switch (data) { diff --git a/src/board/system76/galp3-c/scratch/scratch.mk b/src/board/system76/galp3-c/scratch/scratch.mk index bcfb08a..ba018b5 100644 --- a/src/board/system76/galp3-c/scratch/scratch.mk +++ b/src/board/system76/galp3-c/scratch/scratch.mk @@ -1,4 +1,17 @@ -SCRATCH_OBJ=$(patsubst src/%.c,$(BUILD)/%.rel,$(SCRATCH_SRC)) +# Enable I2C debugging +SCRATCH_SRC+=\ + src/common/i2c.c \ + src/ec/$(EC)/i2c.c +SCRATCH_INCLUDE+=\ + src/common/include/common/*.h \ + src/ec/$(EC)/include/ec/*.h +SCRATCH_CFLAGS+=\ + -Isrc/common/include \ + -Isrc/ec/$(EC)/include \ + -DI2C_DEBUGGER=0x76 + +SCRATCH_BUILD=$(BUILD)/scratch +SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC)) SCRATCH_CC=\ sdcc \ -mmcs51 \ @@ -7,21 +20,21 @@ SCRATCH_CC=\ --Werror # Convert from binary file to C header -$(BUILD)/include/scratch.h: $(BUILD)/scratch.rom +$(BUILD)/include/scratch.h: $(SCRATCH_BUILD)/scratch.rom @mkdir -p $(@D) xxd --include < $< > $@ # Convert from Intel Hex file to binary file -$(BUILD)/scratch.rom: $(BUILD)/scratch.ihx +$(SCRATCH_BUILD)/scratch.rom: $(SCRATCH_BUILD)/scratch.ihx @mkdir -p $(@D) makebin -p < $< > $@ # Link object files into Intel Hex file -$(BUILD)/scratch.ihx: $(SCRATCH_OBJ) +$(SCRATCH_BUILD)/scratch.ihx: $(SCRATCH_OBJ) @mkdir -p $(@D) $(SCRATCH_CC) -o $@ $^ # Compile C files into object files -$(SCRATCH_OBJ): $(BUILD)/%.rel: src/%.c $(SCRATCH_INCLUDE) +$(SCRATCH_OBJ): $(SCRATCH_BUILD)/%.rel: src/%.c $(SCRATCH_INCLUDE) @mkdir -p $(@D) $(SCRATCH_CC) $(SCRATCH_CFLAGS) -o $@ -c $< diff --git a/src/board/system76/galp3-c/scratch/stdio.c b/src/board/system76/galp3-c/scratch/stdio.c new file mode 100644 index 0000000..d0610c3 --- /dev/null +++ b/src/board/system76/galp3-c/scratch/stdio.c @@ -0,0 +1,21 @@ +#include + +#ifdef SERIAL_DEBUGGER + #include +#endif + +#ifdef I2C_DEBUGGER + #include +#endif + +int putchar(int c) { + unsigned char byte = (unsigned char)c; + if (byte == '\n') putchar('\r'); +#ifdef SERIAL_DEBUGGER + SBUF = byte; +#endif +#ifdef I2C_DEBUGGER + i2c_send(I2C_DEBUGGER, &byte, 1); +#endif + return (int)byte; +}