-ASRCS = crt0.s tricks.s commonmem.s rabbit.s
-CSRCS = devices.c main.c devtty.c
+ASRCS = crt0.s tricks.s commonmem.s rabbit.s interrupt.s
+CSRCS = devices.c main.c devtty.c spi.c
DISCARD_CSRCS =
DISCARD_DSRCS = ../dev/devsd_discard.c
DSRCS = ../dev/devsd.c ../dev/mbr.c ../dev/blkdev.c
-b _DISCARD=0xD800
platform-rabbit2000/crt0.rel
platform-rabbit2000/commonmem.rel
+platform-rabbit2000/interrupt.rel
platform-rabbit2000/rabbit.rel
platform-rabbit2000/main.rel
+platform-rabbit2000/tricks.rel
start.rel
version.rel
lowlevel-r2k.rel
usermem_std-r2k.rel
-platform-rabbit2000/tricks.rel
timer.rel
kdata.rel
usermem.rel
platform-rabbit2000/devtty.rel
platform-rabbit2000/devsd.rel
platform-rabbit2000/devsd_discard.rel
+platform-rabbit2000/spi.rel
platform-rabbit2000/mbr.rel
platform-rabbit2000/blkdev.rel
-e
;
.module iir
- .area _IIR
+ .area _DISCARD
+
+ .globl _iir
.globl unix_syscall_entry
.globl ticktock
+ .globl sera_rx,serc_rx,serd_rx
+ .globl sera_tx,serc_tx,serd_tx
+
+ .include 'kernel.def'
+ .include '../kernel-rabbit.def'
+
+_iir:
periodic:
eir0: ; If we use both we'll need to do some
spare:
ret
- .bindry 16
+ .bndry 16
rst38:
ret
timera:
push af
- ioi ld a,(TACSR)
+ ioi
+ ld a,(TACSR)
pop af
ipres
ret
timerb:
push af
- ioi ld a,(TBCSR)
+ ioi
+ ld a,(TBCSR)
pop af
ipres
ret
seriala:
push af
- ioi ld a,(SASR)
- or a
+ ioi
+ ld a,(SASR)
+ or a,a
jp m,sera_rx
jp sera_tx
serialc:
push af
- ioi ld a,(SCSR)
- or a
+ ioi
+ ld a,(SCSR)
+ or a,a
jp m,serc_rx
jp serc_tx
seriald:
push af
- ioi ld a,(SDSR)
- or a
+ ioi
+ ld a,(SDSR)
+ or a,a
jp m,serd_rx
jp serd_tx
#include <rabbit.h>
uaddr_t ramtop = PROGTOP;
+uint8_t ticker;
void pagemap_init(void)
{
#define GREV_R2000C 0x03
#define GCPU_R2000 0x01
+
+/* This lives in the flash in a protected (mostly) space and is written
+ into the board at manufacture */
+
+struct SysIDBlock {
+ uint16_t tableVersion; /* ?? */
+ uint16_t productID; /* Part Number */
+ uint16_t vendorID; /* 1 */
+ uint8_t timestamp[7];
+ uint32_t flashID; /* Vendor/Product ID */
+ uint16_t flashType; /* Write method */
+ uint16_t flashSize; /* 4K pages */
+ uint16_t sectorSize; /* bytes */
+ uint16_t numSectors;
+ uint16_t flashSpeed; /* ns */
+ uint32_t flash2ID;
+ uint16_t flash2Type;
+ uint16_t flash2Size;
+ uint16_t sector2Size;
+ uint16_t num2Sectors;
+ uint16_t flash2Speed;
+ uint32_t ramID;
+ uint16_t ramSize; /* 4K pages */
+ uint16_t ramSpeed; /* ns */
+ uint16_t cpuID;
+ uint32_t crystalFreq; /* HZ */
+ uint8_t macAddr[6]; /* If allocated */
+ uint8_t serialNumber[24];
+ char productName[30]; /* \0 terminated */
+ char reserved;
+ uint32_t idBlockSize; /* Size of SysIDBlock */
+ uint16_t userBlockSize;
+ uint16_t userBlockLoc; /* Offset from this one */
+ int idBlockCRC; /* CRC with this field 0 */
+ char marker[6]; /* 55 AA 55 AA 55 AA */
+};
.globl _ramsize
.globl _procmem
+ .globl _iir
init_early:
ret
or a,a
sbc hl,de
ld (_procmem),hl
+
+ ;
+ ; Set up the interrupt table
+ ;
+
+ ld hl,#_iir
+ ld de,#0
+ ld bc,#256
+doldir:
+ ldi
+ jp lo,doldir
+
+ xor a,a
+ ld iir,a
+ ld eir,a
+
ret
.area _COMMONMEM
.globl map_kernel_di
.globl map_save_kernel
.globl map_restore
+ .globl map_for_swap
.globl _kdataseg
or a,l
jr z, map_kernel
ld a,(hl)
+map_for_swap:
map_process_a:
ioi
ld (DATASEG),a
ld (SADR),a
ret
- .globl _spi_tx
;
; Low level Rabbit 2000 primitives to use Port B for SPI.
;
.globl _rabbit_spi_rx
.globl _rabbit_spi_slow
.globl _rabbit_spi_fast
+
+ .globl rabbit_spi_rxblock
+ .globl rabbit_spi_txblock
;
_rabbit_spi_tx:
+ ld e,l
+rabbit_spi_tx:
; Finish any previous transaction activity
ioi
ld a,(SBSR)
bit 7,a
jr nz,_rabbit_spi_tx
- ld a,l
+ ld a,e
ioi
ld (SBDR),a
ld a, #0x8C ; send, our clock (ie master)
ld l,a
ret
+ ;
+ ; SD card block transfer helpers
+ ; HL = address, 512 bytes map is correct
+ ;
+rabbit_spi_txblock:
+ ld b,#0
+txloop:
+ ld e,(hl)
+ inc hl
+ call rabbit_spi_tx
+ ld e,(hl)
+ inc hl
+ call rabbit_spi_tx
+ djnz txloop
+ ret
+
+rabbit_spi_rxblock:
+ ld b,#0
+ ex de,hl
+rxloop:
+ call _rabbit_spi_rx
+ ld (de),a
+ inc de
+ call _rabbit_spi_rx
+ ld (de),a
+ inc de
+ djnz rxloop
+ ret
;
; Slow speed for probing
.globl _ser'X'_q
.globl _ser'X'_rxbuf
+ .globl ser'X'_rx
+ .globl ser'X'_tx
+
ser'X'_rx:
push hl
push de
--- /dev/null
+#include <kernel.h>
+#include <rabbit.h>
+#include <blkdev.h>
+
+static uint8_t reverse[256] = {
+ 0,
+ /* TODO */
+};
+
+void sd_spi_clock(bool go_fast)
+{
+ if (go_fast)
+ rabbit_spi_fast();
+ else
+ rabbit_spi_slow();
+}
+
+void sd_spi_raise_cs(void)
+{
+ /* TODO pick a line */
+}
+
+void sd_spi_lower_cs(void)
+{
+ /* TODO pick a line */
+}
+
+void sd_spi_transmit_byte(uint8_t byte)
+{
+ rabbit_spi_tx(reverse[byte]);
+}
+
+uint8_t sd_spi_receive_byte(void)
+{
+ return reverse[rabbit_spi_rx()];
+}
+
+COMMON_MEMORY
+
+/*
+ * Could also unroll these a bit for speed
+ */
+
+bool sd_spi_receive_sector(void) __naked
+{
+ __asm
+ ld a, (_blk_op+BLKPARAM_IS_USER_OFFSET)
+ ld hl, (_blk_op+BLKPARAM_ADDR_OFFSET)
+#ifdef SWAPDEV
+ cp #2
+ jr nz, not_swapin
+ ld a,(_blk_op+BLKPARAM_SWAP_PAGE)
+ call map_for_swap
+ jr doread
+not_swapin:
+#endif
+ or a
+ jr z,doread
+ call map_process_always
+doread:
+ call rabbit_spi_rxblock
+ jp map_kernel
+ __endasm;
+}
+
+bool sd_spi_transmit_sector(void) __naked
+{
+ __asm
+ ld a, (_blk_op+BLKPARAM_IS_USER_OFFSET)
+ ld hl, (_blk_op+BLKPARAM_ADDR_OFFSET)
+#ifdef SWAPDEV
+ cp #2
+ jr nz, not_swapout
+ ld a, (_blk_op+BLKPARAM_SWAP_PAGE)
+ call map_for_swap
+ jr dowrite
+not_swapout:
+#endif
+ or a
+ jr z,dowrite
+ call map_process_always
+dowrite:
+ call rabbit_spi_txblock
+ jp map_kernel
+ __endasm;
+}