Complete rewrite of scratch to support IT5570
This commit is contained in:
parent
d2591be256
commit
a013ca80f5
@ -19,6 +19,11 @@ CFLAGS+=-DI2C_DEBUGGER=0x76
|
||||
# Set battery I2C bus
|
||||
CFLAGS+=-DI2C_SMBUS=I2C_4
|
||||
|
||||
# Set scratch ROM parameters
|
||||
SCRATCH_OFFSET=1024
|
||||
SCRATCH_SIZE=1024
|
||||
CFLAGS+=-DSCRATCH_OFFSET=$(SCRATCH_OFFSET) -DSCRATCH_SIZE=$(SCRATCH_SIZE)
|
||||
|
||||
# Add scratch ROM source
|
||||
SCRATCH_DIR=$(BOARD_DIR)/scratch
|
||||
SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c)
|
||||
|
@ -1,63 +1,28 @@
|
||||
#include <8051.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <common/macro.h>
|
||||
|
||||
// Include scratch ROM, must be less than 4096 bytes, controlled by makefile
|
||||
uint8_t __code scratch_rom[] = {
|
||||
// Include scratch ROM
|
||||
uint8_t __code __at(SCRATCH_OFFSET) scratch_rom[] = {
|
||||
#include <scratch.h>
|
||||
};
|
||||
|
||||
// Scratch RAM 0 is 4096 bytes, located at 0x0000 bytes
|
||||
volatile uint8_t __xdata __at(0x0000) scratch_ram[4096];
|
||||
|
||||
volatile uint8_t __xdata __at(0x1040) SCAR0L;
|
||||
volatile uint8_t __xdata __at(0x1041) SCAR0M;
|
||||
volatile uint8_t __xdata __at(0x1042) SCAR0H;
|
||||
|
||||
// Create new segment located at 0x1000, after scratch ROM mapping
|
||||
static void scratch_start(void) __naked {
|
||||
__asm
|
||||
.area SCRATCH (ABS,CODE)
|
||||
__endasm;
|
||||
__asm
|
||||
.org 0x1000
|
||||
__endasm;
|
||||
}
|
||||
|
||||
// Enter or exit scratch ROM
|
||||
void scratch_trampoline(void) {
|
||||
// Uses SCAR0 which is mapped at 0x0000 in data space and are
|
||||
// 4096 bytes in size.
|
||||
|
||||
// Disable interrupts
|
||||
EA = 0;
|
||||
|
||||
// Ensure pdata is not used!
|
||||
int __data i;
|
||||
// Copy scratch ROM
|
||||
for (i = 0; i < ARRAY_SIZE(scratch_rom) && i < ARRAY_SIZE(scratch_ram); i++) {
|
||||
scratch_ram[i] = scratch_rom[i];
|
||||
}
|
||||
// Use DMA mapping to copy flash data
|
||||
SCAR0H = 0x80;
|
||||
SCAR0L = (uint8_t)(SCRATCH_OFFSET);
|
||||
SCAR0M = (uint8_t)(SCRATCH_OFFSET >> 8);
|
||||
SCAR0H = 0;
|
||||
|
||||
// Fill the rest with nop
|
||||
for (; i < ARRAY_SIZE(scratch_ram); i++) {
|
||||
scratch_ram[i] = 0x00;
|
||||
}
|
||||
|
||||
// Set scratch RAM 0 mapping at 0x0000 and enable
|
||||
SCAR0L = 0x00;
|
||||
SCAR0M = 0x00;
|
||||
SCAR0H = 0x00;
|
||||
|
||||
// Jump to reset function
|
||||
__asm__("ljmp 0");
|
||||
}
|
||||
|
||||
// Finish segment located at 0x1000
|
||||
static void scratch_end(void) __naked {
|
||||
__asm
|
||||
.area CSEG (REL,CODE)
|
||||
__endasm;
|
||||
// Jump to scratch reset function
|
||||
__asm__("ljmp " xstr(SCRATCH_OFFSET));
|
||||
}
|
||||
|
@ -15,11 +15,7 @@ struct Pmc {
|
||||
volatile uint8_t * control;
|
||||
};
|
||||
|
||||
extern struct Pmc __code PMC_1;
|
||||
extern struct Pmc __code PMC_2;
|
||||
extern struct Pmc __code PMC_3;
|
||||
extern struct Pmc __code PMC_4;
|
||||
extern struct Pmc __code PMC_5;
|
||||
|
||||
#define PMC_STS_OBF (1 << 0)
|
||||
#define PMC_STS_IBF (1 << 1)
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <scratch/pmc.h>
|
||||
@ -81,22 +80,12 @@ void pmc_event(struct Pmc * pmc) {
|
||||
state = PMC_STATE_ACPI_WRITE;
|
||||
break;
|
||||
case 0xEC:
|
||||
printf_tiny("RESET\n");
|
||||
// Attempt to trigger watchdog reset
|
||||
ETWCFG |= (1 << 5);
|
||||
EWDKEYR = 0;
|
||||
// Clear processor caches
|
||||
__asm__("mov 0xf7, #1");
|
||||
__asm__("nop");
|
||||
__asm__("mov 0xf7, #1");
|
||||
__asm__("nop");
|
||||
__asm__("mov 0xf7, #1");
|
||||
__asm__("nop");
|
||||
__asm__("mov 0xf7, #1");
|
||||
__asm__("nop");
|
||||
// Exit scratch ROM by going through trampoline
|
||||
__asm__("ljmp 0x1000");
|
||||
break;
|
||||
for (;;) {
|
||||
// Attempt to trigger watchdog reset
|
||||
ETWCFG |= (1 << 5);
|
||||
EWDKEYR = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (state) {
|
||||
@ -123,7 +112,6 @@ void pmc_event(struct Pmc * pmc) {
|
||||
|
||||
// Main program while running in scratch ROM
|
||||
void main(void) {
|
||||
printf_tiny("SCRATCH\n");
|
||||
for (;;) {
|
||||
pmc_event(&PMC_3);
|
||||
}
|
||||
|
@ -7,11 +7,7 @@
|
||||
.control = &PM ## NUM ## CTL, \
|
||||
}
|
||||
|
||||
struct Pmc __code PMC_1 = PMC(1);
|
||||
struct Pmc __code PMC_2 = PMC(2);
|
||||
struct Pmc __code PMC_3 = PMC(3);
|
||||
struct Pmc __code PMC_4 = PMC(4);
|
||||
struct Pmc __code PMC_5 = PMC(5);
|
||||
|
||||
uint8_t pmc_status(struct Pmc * pmc) {
|
||||
return *(pmc->status);
|
||||
|
@ -1,33 +1,17 @@
|
||||
# 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
|
||||
|
||||
# Enable I2C debug on 0x76
|
||||
SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76
|
||||
|
||||
# Set battery I2C bus
|
||||
SCRATCH_CFLAGS+=-DI2C_SMBUS=I2C_4
|
||||
|
||||
SCRATCH_BUILD=$(BUILD)/scratch
|
||||
SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC))
|
||||
SCRATCH_CC=\
|
||||
sdcc \
|
||||
-mmcs51 \
|
||||
--model-small \
|
||||
--code-size 4096 \
|
||||
--code-loc $(SCRATCH_OFFSET) \
|
||||
--code-size $(SCRATCH_SIZE) \
|
||||
--Werror
|
||||
|
||||
# Convert from binary file to C header
|
||||
$(BUILD)/include/scratch.h: $(SCRATCH_BUILD)/scratch.rom
|
||||
@mkdir -p $(@D)
|
||||
xxd --include < $< > $@
|
||||
xxd -s $(SCRATCH_OFFSET) --include < $< > $@
|
||||
|
||||
# Convert from Intel Hex file to binary file
|
||||
$(SCRATCH_BUILD)/scratch.rom: $(SCRATCH_BUILD)/scratch.ihx
|
||||
|
@ -1,20 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef SERIAL_DEBUGGER
|
||||
#include <mcs51/8051.h>
|
||||
#endif
|
||||
|
||||
#ifdef I2C_DEBUGGER
|
||||
#include <ec/i2c.h>
|
||||
#endif
|
||||
|
||||
int putchar(int c) {
|
||||
unsigned char byte = (unsigned char)c;
|
||||
#ifdef SERIAL_DEBUGGER
|
||||
SBUF = byte;
|
||||
#endif
|
||||
#ifdef I2C_DEBUGGER
|
||||
i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1);
|
||||
#endif
|
||||
return (int)byte;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user