Kernel: RTC driver for DS1202 on platform-p112
authorWill Sowerbutts <will@sowerbutts.com>
Thu, 1 Jan 2015 14:01:52 +0000 (14:01 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Thu, 1 Jan 2015 14:50:02 +0000 (14:50 +0000)
Kernel/platform-p112/Makefile
Kernel/platform-p112/config.h
Kernel/platform-p112/crt0.s
Kernel/platform-p112/devices.c
Kernel/platform-p112/ds1302-p112.s [new file with mode: 0644]
Kernel/platform-p112/uzi.lnk

index 70a1bf3..c132819 100644 (file)
@@ -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)
index c5985ce..316ee2a 100644 (file)
@@ -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
index 98ac696..9f811a8 100644 (file)
@@ -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
index 2e861aa..9f69e36 100644 (file)
@@ -5,6 +5,7 @@
 #include <devsys.h>
 #include <devtty.h>
 #include <devide.h>
+#include <ds1302.h>
 
 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 (file)
index 0000000..b87f47f
--- /dev/null
@@ -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
+
index 73e8928..b0c579e 100644 (file)
@@ -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