Add PMC support to scratch ram, move makefile targets to new makefile
This commit is contained in:
parent
8950a783f4
commit
885fb3ed44
@ -10,34 +10,11 @@ CFLAGS+=-DLEVEL=2
|
||||
# CFLAGS+=-DI2C_DEBUGGER=0x76
|
||||
|
||||
# Add scratch ROM source
|
||||
SCRATCH_SRC=$(wildcard $(BOARD_DIR)/scratch/*.c)
|
||||
SCRATCH_OBJ=$(patsubst src/%.c,$(BUILD)/%.rel,$(SCRATCH_SRC))
|
||||
SCRATCH_CC=\
|
||||
sdcc \
|
||||
-mmcs51 \
|
||||
--model-small \
|
||||
--code-size 2048 \
|
||||
--Werror
|
||||
|
||||
# Convert from binary file to C header
|
||||
$(BUILD)/include/scratch.h: $(BUILD)/scratch.rom
|
||||
@mkdir -p $(@D)
|
||||
xxd --include < $< > $@
|
||||
|
||||
# Convert from Intel Hex file to binary file
|
||||
$(BUILD)/scratch.rom: $(BUILD)/scratch.ihx
|
||||
@mkdir -p $(@D)
|
||||
makebin -p < $< > $@
|
||||
|
||||
# Link object files into Intel Hex file
|
||||
$(BUILD)/scratch.ihx: $(SCRATCH_OBJ)
|
||||
@mkdir -p $(@D)
|
||||
$(SCRATCH_CC) -o $@ $^
|
||||
|
||||
# Compile C files into object files
|
||||
$(SCRATCH_OBJ): $(BUILD)/%.rel: src/%.c
|
||||
@mkdir -p $(@D)
|
||||
$(SCRATCH_CC) -o $@ -c $<
|
||||
SCRATCH_DIR=$(BOARD_DIR)/scratch
|
||||
SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c)
|
||||
SCRATCH_INCLUDE=$(wildcard $(SCRATCH_DIR)/include/scratch/*.h)
|
||||
SCRATCH_CFLAGS=-I$(SCRATCH_DIR)/include
|
||||
include $(SCRATCH_DIR)/scratch.mk
|
||||
|
||||
# Require scratch.rom to be compiled before main firmware
|
||||
CFLAGS+=-I$(BUILD)/include
|
||||
|
33
src/board/system76/galp3-c/scratch/include/scratch/pmc.h
Normal file
33
src/board/system76/galp3-c/scratch/include/scratch/pmc.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef _EC_PMC_H
|
||||
#define _EC_PMC_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct Pmc {
|
||||
// Status register
|
||||
volatile uint8_t * status;
|
||||
// Data out register
|
||||
volatile uint8_t * data_out;
|
||||
// Data in register
|
||||
volatile uint8_t * data_in;
|
||||
// Control register
|
||||
volatile uint8_t * control;
|
||||
};
|
||||
|
||||
extern struct Pmc __code PMC_1;
|
||||
|
||||
#define PMC_STS_OBF (1 << 0)
|
||||
#define PMC_STS_IBF (1 << 1)
|
||||
#define PMC_STS_CMD (1 << 3)
|
||||
|
||||
uint8_t pmc_status(struct Pmc * pmc);
|
||||
uint8_t pmc_read(struct Pmc * pmc);
|
||||
bool pmc_write(struct Pmc * pmc, uint8_t data, int timeout);
|
||||
|
||||
volatile uint8_t __xdata __at(0x1500) PM1STS;
|
||||
volatile uint8_t __xdata __at(0x1501) PM1DO;
|
||||
volatile uint8_t __xdata __at(0x1504) PM1DI;
|
||||
volatile uint8_t __xdata __at(0x1506) PM1CTL;
|
||||
|
||||
#endif // _EC_PMC_H
|
@ -1,6 +1,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <scratch/pmc.h>
|
||||
|
||||
volatile uint8_t __xdata __at(0x103B) ECINDAR0;
|
||||
volatile uint8_t __xdata __at(0x103C) ECINDAR1;
|
||||
volatile uint8_t __xdata __at(0x103D) ECINDAR2;
|
||||
@ -26,9 +28,21 @@ static int flash_transaction(uint32_t offset, uint8_t * data, int length, bool r
|
||||
return i;
|
||||
}
|
||||
|
||||
#define PMC_TIMEOUT 1000
|
||||
|
||||
static void pmc_event(struct Pmc * pmc) {
|
||||
uint8_t sts = pmc_status(pmc);
|
||||
if (sts & PMC_STS_IBF) {
|
||||
uint8_t data = pmc_read(pmc);
|
||||
if (sts & PMC_STS_CMD) {
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main program while running in scratch ROM
|
||||
void main(void) {
|
||||
// TODO: implement flashing protocol and prevent access to flash
|
||||
// data (i.e. calling functions in CSEG) during this process
|
||||
for (;;) {}
|
||||
for (;;) {
|
||||
pmc_event(&PMC_1);
|
||||
}
|
||||
}
|
||||
|
32
src/board/system76/galp3-c/scratch/pmc.c
Normal file
32
src/board/system76/galp3-c/scratch/pmc.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <scratch/pmc.h>
|
||||
|
||||
#define PMC(NUM) { \
|
||||
.status = &PM ## NUM ## STS, \
|
||||
.data_out = &PM ## NUM ## DO, \
|
||||
.data_in = &PM ## NUM ## DI, \
|
||||
.control = &PM ## NUM ## CTL, \
|
||||
}
|
||||
|
||||
struct Pmc __code PMC_1 = PMC(1);
|
||||
|
||||
uint8_t pmc_status(struct Pmc * pmc) {
|
||||
return *(pmc->status);
|
||||
}
|
||||
|
||||
uint8_t pmc_read(struct Pmc * pmc) {
|
||||
return *(pmc->data_in);
|
||||
}
|
||||
|
||||
static bool pmc_wait(struct Pmc * pmc, int timeout) {
|
||||
while (pmc_status(pmc) & PMC_STS_OBF) {
|
||||
if (timeout == 0) return false;
|
||||
timeout -= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pmc_write(struct Pmc * pmc, uint8_t data, int timeout) {
|
||||
if (!pmc_wait(pmc, timeout)) return false;
|
||||
*(pmc->data_out) = data;
|
||||
return true;
|
||||
}
|
27
src/board/system76/galp3-c/scratch/scratch.mk
Normal file
27
src/board/system76/galp3-c/scratch/scratch.mk
Normal file
@ -0,0 +1,27 @@
|
||||
SCRATCH_OBJ=$(patsubst src/%.c,$(BUILD)/%.rel,$(SCRATCH_SRC))
|
||||
SCRATCH_CC=\
|
||||
sdcc \
|
||||
-mmcs51 \
|
||||
--model-small \
|
||||
--code-size 2048 \
|
||||
--Werror
|
||||
|
||||
# Convert from binary file to C header
|
||||
$(BUILD)/include/scratch.h: $(BUILD)/scratch.rom
|
||||
@mkdir -p $(@D)
|
||||
xxd --include < $< > $@
|
||||
|
||||
# Convert from Intel Hex file to binary file
|
||||
$(BUILD)/scratch.rom: $(BUILD)/scratch.ihx
|
||||
@mkdir -p $(@D)
|
||||
makebin -p < $< > $@
|
||||
|
||||
# Link object files into Intel Hex file
|
||||
$(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)
|
||||
@mkdir -p $(@D)
|
||||
$(SCRATCH_CC) $(SCRATCH_CFLAGS) -o $@ -c $<
|
Loading…
x
Reference in New Issue
Block a user