Scratch debugging

This commit is contained in:
Jeremy Soller 2019-12-30 10:47:49 -07:00
parent 6029843c07
commit a9339a8204
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
3 changed files with 52 additions and 5 deletions

View File

@ -1,4 +1,5 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <scratch/pmc.h>
@ -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) {

View File

@ -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 $<

View File

@ -0,0 +1,21 @@
#include <stdio.h>
#ifdef SERIAL_DEBUGGER
#include <mcs51/8051.h>
#endif
#ifdef I2C_DEBUGGER
#include <common/i2c.h>
#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;
}