Scratch debugging
This commit is contained in:
		| @@ -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) { | ||||
|   | ||||
| @@ -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 $< | ||||
|   | ||||
							
								
								
									
										21
									
								
								src/board/system76/galp3-c/scratch/stdio.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/board/system76/galp3-c/scratch/stdio.c
									
									
									
									
									
										Normal 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; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user