From c055b9b3889d173e04e925555866c693f0d4c22e Mon Sep 17 00:00:00 2001 From: Will Sowerbutts Date: Thu, 1 Jan 2015 14:01:52 +0000 Subject: [PATCH] Kernel: RTC driver for DS1202 on platform-p112 --- Kernel/platform-p112/Makefile | 5 +-- Kernel/platform-p112/config.h | 3 ++ Kernel/platform-p112/crt0.s | 1 + Kernel/platform-p112/devices.c | 2 + Kernel/platform-p112/ds1302-p112.s | 71 ++++++++++++++++++++++++++++++ Kernel/platform-p112/uzi.lnk | 2 + 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 Kernel/platform-p112/ds1302-p112.s diff --git a/Kernel/platform-p112/Makefile b/Kernel/platform-p112/Makefile index 70a1bf31..c1328197 100644 --- a/Kernel/platform-p112/Makefile +++ b/Kernel/platform-p112/Makefile @@ -1,7 +1,6 @@ CSRCS += devices.c main.c devtty.c -DSRCS = ../dev/devide.c ../dev/mbr.c - -ASRCS = crt0.s z180.s p112.s commonmem.s +DSRCS = ../dev/devide.c ../dev/mbr.c ../dev/ds1302.c +ASRCS = crt0.s z180.s commonmem.s p112.s ds1302-p112.s AOBJS = $(ASRCS:.s=.rel) COBJS = $(CSRCS:.c=.rel) diff --git a/Kernel/platform-p112/config.h b/Kernel/platform-p112/config.h index c5985ce3..316ee2a0 100644 --- a/Kernel/platform-p112/config.h +++ b/Kernel/platform-p112/config.h @@ -54,3 +54,6 @@ #define IDE_REG_CS0_FIRST #define IDE_REG_CS0_BASE (IDE_REG_BASE+0x00) #define IDE_REG_CS1_BASE (IDE_REG_BASE+0x08) + +/* We have a DS1302, we can read the time of day from it */ +#define CONFIG_RTC diff --git a/Kernel/platform-p112/crt0.s b/Kernel/platform-p112/crt0.s index 98ac696f..9f811a8d 100644 --- a/Kernel/platform-p112/crt0.s +++ b/Kernel/platform-p112/crt0.s @@ -7,6 +7,7 @@ ; we don't use them all, because their ordering is set ; when they are first seen. .area _CODE + .area _HOME ; compiler stores __mullong etc in here if you use them .area _CODE2 .area _CONST .area _DATA diff --git a/Kernel/platform-p112/devices.c b/Kernel/platform-p112/devices.c index 2e861aa2..9f69e361 100644 --- a/Kernel/platform-p112/devices.c +++ b/Kernel/platform-p112/devices.c @@ -5,6 +5,7 @@ #include #include #include +#include struct devsw dev_tab[] = /* The device driver switch table */ { @@ -36,4 +37,5 @@ bool validdev(uint16_t dev) void device_init(void) { devide_init(); + ds1302_init(); } diff --git a/Kernel/platform-p112/ds1302-p112.s b/Kernel/platform-p112/ds1302-p112.s new file mode 100644 index 00000000..b87f47fa --- /dev/null +++ b/Kernel/platform-p112/ds1302-p112.s @@ -0,0 +1,71 @@ +; 2015-01-01 William R Sowerbutts +; DX-Designs P112 SBC DS1202 real time clock interface code + + .module ds1302-p112 + .z180 + + ; exported symbols + .globl _ds1302_set_pin_ce + .globl _ds1302_set_pin_clk + .globl _ds1302_set_pin_data_driven + .globl _ds1302_set_pin_data + .globl _ds1302_get_pin_data + + .include "kernel.def" + .include "../cpu-z180/z180.def" + .include "../kernel.def" + +; ----------------------------------------------------------------------------- +; DS1202 interface +; ----------------------------------------------------------------------------- + +PIN_DATA = 0x01 ; PA0 +PIN_CLK = 0x02 ; PA1 +PIN_CE = 0x04 ; PA2 + +.area _CODE + +_ds1302_get_pin_data: + in0 a, (PORT_A_DATA) ; read IO pins + and #PIN_DATA ; mask off data bit + ld l, a ; return result in L + ret + +_ds1302_set_pin_data_driven: + in0 a, (PORT_A_DDR) ; a 1 in each bit makes the corresponding pin tristate (input), 0 makes it an output + and #~(PIN_DATA|PIN_CE|PIN_CLK) ; bits to 0 -> set all pins as outputs + ld hl, #2 ; get address of function argument + add hl, sp + ld b, (hl) ; load argument from stack + bit 0, b ; test bit + jr nz, writeddr ; nonzero -> we want an output + or #PIN_DATA ; zero -> we want an input; change bit to 1 -> set data pin as input +writeddr: + out0 (PORT_A_DDR), a ; update data direction register + ret + +_ds1302_set_pin_data: + ld bc, #(((~PIN_DATA) << 8) | PIN_DATA) + jr setpin + +_ds1302_set_pin_ce: + ld bc, #(((~PIN_CE) << 8) | PIN_CE) + jr setpin + +_ds1302_set_pin_clk: + ld bc, #(((~PIN_CLK) << 8) | PIN_CLK) + jr setpin + +setpin: + in0 a, (PORT_A_DATA) ; load current register contents + and b ; unset the pin + ld hl, #2 ; get address of function argument + add hl, sp + ld b, (hl) ; load argument from stack + bit 0, b ; test bit + jr z, writereg ; arg is false, bit is already 0 + or c ; arg is true, set bit to 1 +writereg: + out0 (PORT_A_DATA), a ; write out new register contents + ret + diff --git a/Kernel/platform-p112/uzi.lnk b/Kernel/platform-p112/uzi.lnk index 73e89287..b0c579e0 100644 --- a/Kernel/platform-p112/uzi.lnk +++ b/Kernel/platform-p112/uzi.lnk @@ -34,4 +34,6 @@ devsys.rel platform-p112/devtty.rel platform-p112/devide.rel platform-p112/mbr.rel +platform-p112/ds1302.rel +platform-p112/ds1302-p112.rel -e -- 2.34.1