diff --git a/Kernel/dev/cpc/ch375.c b/Kernel/dev/cpc/ch375.c index 7c3d8391c..7620fb4b6 100644 --- a/Kernel/dev/cpc/ch375.c +++ b/Kernel/dev/cpc/ch375.c @@ -19,82 +19,148 @@ * as 1,5us wont be a problem in many cases */ -#include -#include -#include "ch375.h" - - + #include + #include + #include + #define _CH375_PRIVATE + + #include "ch375.h" + + #ifdef CONFIG_CH375 -static uint8_t ch_rd = CH375_CMD_RD_USB_DATA; -static uint8_t ch_wd = CH375_CMD_WR_USB_DATA7; +uint8_t ch_rd = CH375_CMD_RD_USB_DATA; +uint8_t ch_wd = CH375_CMD_WR_USB_DATA7; -/* Some guesswork here on how the get status polling is meant to work */ -uint8_t ch375_rpoll(void) +uint8_t ch375_rdata(uint8_t dev) { uint16_t count = 0x8000; - uint8_t r; - while(--count && ((ch375_rstatus() & 0x80) != 0)) nap2(); - if (count == 0) { - kprintf("ch375: timeout.\n"); - return 0xFF; + /*kprintf("ch375_rdata: %u\n", dev);*/ + if (ch375_comm_type[dev] == CH375_COMM_SERIAL) + { + while(--count && (in16(ch375_sports[dev]) == CH375_SERIAL_WAIT)); + if (count == 0) { + kprintf("ch375_serial: timeout.\n"); + return 0xFF; + } } - /* Get interrupt status, and clear interrupt */ - ch375_wcmd(CH375_CMD_GET_STATUS); - nap2(); - r = ch375_rdata(); -/* kprintf("ch375_rpoll %2x", r); */; - return r; + return in16(ch375_dports[dev]); } +uint8_t ch375_rstatus(uint8_t dev) +{ + /*kprintf("ch375_rstatus: %u\n", dev);*/ + switch (ch375_comm_type[dev]) + { + case CH375_COMM_PARALLEL: + return in16(ch375_sports[dev]); + break; + case CH375_COMM_SERIAL: + return ch375_rdata(dev); + break; + default: + break; + } +} -int ch375_xfer(uint_fast8_t dev, bool is_read, uint32_t lba, uint8_t *dptr) +void ch375_wdata(uint8_t dev, uint8_t data) { - uint_fast8_t n = 0; - uint_fast8_t r; + out16(ch375_dports[dev], data); + /*kprintf("ch375_wdata: %u, %2x\n", dev, data);*/ +} - if (is_read) - ch375_wcmd(CH375_CMD_DISK_READ); - else - ch375_wcmd(CH375_CMD_DISK_WRITE); - nap2(); - ch375_wdata(lba); - ch375_wdata(lba >> 8); - ch375_wdata(lba >> 16); - ch375_wdata(lba >> 24); - ch375_wdata(1); - for (n = 0; n < 8; n++) { - r = ch375_rpoll(); - if (is_read) { - if (r != CH375_USB_INT_DISK_READ) - return 0; - ch375_wcmd(ch_rd); - nap2(); - r = ch375_rdata(); /* Throw byte count away - always 64 */ - if (r != 64) { -/* kprintf("weird rd len %d\n", r); */ - return 0; - } - ch375_rblock(dptr); - ch375_wcmd(CH375_CMD_DISK_RD_GO); - } else { - if (r != CH375_USB_INT_DISK_WRITE) - return 0; - ch375_wcmd(ch_wd); - nap2(); - ch375_wdata(0x40); /* Send write count */ - ch375_wblock(dptr); - ch375_wcmd(CH375_CMD_DISK_WR_GO); - } - dptr += 0x40; - } - r = ch375_rpoll(); - if (r != CH375_USB_INT_SUCCESS) { - kprintf("ch375: error %d\n", r); - return 0; +void ch375_wcmd(uint8_t dev, uint8_t cmd) +{ + /*kprintf("ch375_wcmd: %u, %2x\n", dev, cmd);*/ + switch (ch375_comm_type[dev]) + { + case CH375_COMM_PARALLEL: + out16(ch375_sports[dev], cmd); + break; + case CH375_COMM_SERIAL: + ch375_wdata(dev, 0x57); + ch375_wdata(dev, 0xAB); + ch375_wdata(dev, cmd); + break; } - return 1; } -#endif + + /* Some guesswork here on how the get status polling is meant to work */ + uint8_t ch375_rpoll(uint_fast8_t dev) + { + uint16_t count = 0x8000; + uint8_t r; + while(--count && ((((r = ch375_rstatus(dev)) & 0x80) != 0 ))) nap2(); + if (count == 0) { + kprintf("ch375: timeout. rstat=%2x\n", r); + return 0xFF; + } + /*kprintf("rstat=%2x\n", r);*/ + /* Get interrupt status, and clear interrupt */ + ch375_wcmd(dev, CH375_CMD_GET_STATUS); + nap2(); + r = ch375_rdata(dev); + /*kprintf("ch375_rpoll %u,%u,%2x\n", dev, count, r);*/ + return r; + } + +int ch375_xfer(uint_fast8_t dev, bool is_read, uint32_t lba, uint8_t *dptr) + { + uint_fast8_t n = 0; + uint_fast8_t r; + + td_io_data_reg = ch375_dports[dev]; + td_io_data_count = 8; + /*kprintf("dr:%x\n",ch375_data_reg);*/ + if (is_read) + ch375_wcmd(dev, CH375_CMD_DISK_READ); + else + ch375_wcmd(dev, CH375_CMD_DISK_WRITE); + nap2(); + ch375_wdata(dev, lba); + ch375_wdata(dev, lba >> 8); + ch375_wdata(dev, lba >> 16); + ch375_wdata(dev, lba >> 24); + ch375_wdata(dev, 1); + for (n = 0; n < 8; n++) { + r = ch375_rpoll(dev); + if (is_read) { + /*kprintf("rd %u\n", n);*/ + if (r != CH375_USB_INT_DISK_READ){ + /*kprintf("r != CH375_USB_INT_DISK_READ = %2x\n", r);*/ + continue; + } + ch375_wcmd(dev, ch_rd); + nap2(); + r = ch375_rdata(dev); /* Throw byte count away - always 64 */ + if (r != 64) { + kprintf("weird rd len %d\n", r); + continue; + } + /*kprintf("rblock(%x)\n", dptr);*/ + td_io_rblock(dptr); + ch375_wcmd(dev, CH375_CMD_DISK_RD_GO); + } else { + /*kprintf("wr\n");*/ + if (r != CH375_USB_INT_DISK_WRITE) + continue; + ch375_wcmd(dev, ch_wd); + nap2(); + ch375_wdata(dev, 0x40); /* Send write count */ + td_io_wblock(dptr); + ch375_wcmd(dev, CH375_CMD_DISK_WR_GO); + } + dptr += 0x40; + } + r = ch375_rpoll(dev); + if (r != CH375_USB_INT_SUCCESS) { + kprintf("ch375: error %d\n", r); + return 0; + } + return 1; + } + + + #endif diff --git a/Kernel/dev/cpc/ch375.h b/Kernel/dev/cpc/ch375.h index 3bd786fc6..39116be5e 100644 --- a/Kernel/dev/cpc/ch375.h +++ b/Kernel/dev/cpc/ch375.h @@ -1,36 +1,46 @@ -#ifndef _CH375_H -#define _CH375_H +#ifndef CH375_H +#define CH375_H #include "plt_ch375.h" #define CH375_CMD_GET_IC_VER 0x01 +#define CH375_CMD_SET_BAUDRATE 0x02 #define CH375_CMD_RESET_ALL 0x05 #define CH375_CMD_CHECK_EXIST 0x06 #define CH375_CMD_SET_USB_MODE 0x15 +#define CH375_CMD_TEST_CONNECT 0x16 #define CH375_CMD_GET_STATUS 0x22 +#define CH375_CMD_DIRTY_BUFFER 0x25 #define CH376_CMD_RD_USB_DATA 0x27 #define CH375_CMD_RD_USB_DATA 0x28 #define CH375_CMD_WR_USB_DATA7 0x2B #define CH376_CMD_WR_HOST_DATA 0x2C +#define CH375_CMD_DISK_CONNECT 0x30 +#define CH375_CMD_DISK_MOUNT 0x31 +#define CH375_CMD_CLR_STALL 0x41 #define CH375_CMD_DISK_INIT 0x51 +#define CH375_CMD_DISK_RESET 0x52 #define CH375_CMD_DISK_READ 0x54 #define CH375_CMD_DISK_RD_GO 0x55 #define CH375_CMD_DISK_WRITE 0x56 #define CH375_CMD_DISK_WR_GO 0x57 +#define CH375_CMD_DISK_R_SENSE 0x5A #define CH375_USB_INT_SUCCESS 0x14 #define CH375_USB_INT_CONNECT 0x15 #define CH375_USB_INT_DISK_READ 0x1D #define CH375_USB_INT_DISK_WRITE 0x1E -/* TODO: 2 us delay should be implemented by platform */ - #ifndef nap2() #define nap2() nap20() #endif -uint_fast8_t ch375_probe(void); -uint8_t ch375_rpoll(void); -int ch375_xfer(uint_fast8_t dev, bool is_read, uint32_t lba, uint8_t *dptr); - +extern uint_fast8_t ch375_probe(void); +extern void* td_io_data_reg; +extern uint8_t td_io_data_count; +extern void ch375_wcmd(uint8_t dev, uint8_t cmd); +extern void ch375_wdata(uint8_t dev, uint8_t data); +extern uint8_t ch375_rdata(uint8_t dev); +extern uint8_t ch375_rpoll(uint_fast8_t dev); +extern int ch375_xfer(uint_fast8_t dev, bool is_read, uint32_t lba, uint8_t *dptr); #endif \ No newline at end of file diff --git a/Kernel/dev/cpc/ch375_discard.c b/Kernel/dev/cpc/ch375_discard.c index f37264476..52e903aa1 100644 --- a/Kernel/dev/cpc/ch375_discard.c +++ b/Kernel/dev/cpc/ch375_discard.c @@ -1,100 +1,83 @@ /* * CH375 and CH376 driver for Fuzix. - * - * Controller in parallel mode and running internal block firmware rather - * than being a raw USB controller. - * - * Caller provides - * ch375_rdata(); - * ch375_rstatus(); - * ch375_wcmd(cmd); - * ch375_wdata(data); - * nap20(); nap 20us or so - * - * Plus the usually asm block copies for the read/write of the block - * - * TODO: handle hotplugging once we get the infrastructure - * - * Q: do we need to check 0x10 status before write or read ? Push it to host - * as 1,5us wont be a problem in many cases */ -#include -#include -#include -#include "ch375.h" + #include + #include + #include + #include "ch375.h" + #ifdef CONFIG_CH375 -static uint8_t ch_ver; -static uint8_t ch_rd = CH375_CMD_RD_USB_DATA; -static uint8_t ch_wd = CH375_CMD_WR_USB_DATA7; -static uint8_t ch_dev = 0xFF; +extern uint8_t ch_rd; +extern uint8_t ch_wd; -static void ch375_cmd2(uint8_t cmd, uint8_t data) -{ -/* kprintf("cmd2: %2x %2x\n", cmd, data); */ - ch375_wcmd(cmd); - nap2(); - ch375_wdata(data); -} -uint_fast8_t ch375_probe(void) -{ - uint16_t i; - uint_fast8_t chip = 5; - uint_fast8_t r; +void ch375_cmd2(uint_fast8_t dev, uint8_t cmd, uint8_t data) + { + /*kprintf("cmd2: %2x %2x\n", cmd, data);*/ + ch375_wcmd(dev, cmd); + nap2(); + ch375_wdata(dev, data); + } - /* Reset module in case of a crash. Takes 40 ms. */ - ch375_wcmd(CH375_CMD_RESET_ALL); - for (i = 0; i < 2000; i++) - nap20(); - - ch375_cmd2(CH375_CMD_CHECK_EXIST, 0x55); - nap2(); - r = ch375_rdata(); - if (r != 0xAA) { -/* kprintf("ch375: response %2x not AA\n", r); */ - return 0; - } - ch375_wcmd(CH375_CMD_GET_IC_VER); /* Version */ - nap2(); - ch_ver = ch375_rdata(); - kprintf("ch375: version %2x\n", ch_ver); - if (ch_ver == 0xFF) - return 0; - /* 376 - update commands to use */ - if ((ch_ver & 0xC0) == 0x40) { - ch_rd = CH376_CMD_RD_USB_DATA; - ch_wd = CH376_CMD_WR_HOST_DATA; - chip = 6; - } - kprintf("ch37%d: firmware version %d\n", chip, ch_ver & 0x3F); + uint_fast8_t ch375_probe(void) + { + uint16_t i; + uint_fast8_t chip = 5; + uint_fast8_t r; + uint8_t ch_ver; + for (uint_fast8_t dev = 0; dev < CH375_DEVICES; dev++){ - /* Enable USB host mode, reset USB bus */ - ch375_cmd2(CH375_CMD_SET_USB_MODE, 0x07); - nap20(); /* 20 us */ - /* Enable USB host mode, automatically generating SOF */ - ch375_cmd2(CH375_CMD_SET_USB_MODE, 0x06); - nap20(); - /* After setting USB mode 0x06 an interrupt is generated when - * an USB storage device is present */ - r = ch375_rpoll(); - if (r != CH375_USB_INT_CONNECT) { - return 0; + kprintf("Probing ch375/ch376 device #%u\n", dev); + ch375_cmd2(dev, CH375_CMD_CHECK_EXIST, 0x55); + nap2(); + r = ch375_rdata(dev); + if (r != 0xAA) { + kprintf("ch375: response %2x not AA\n", r); + continue; + } + ch375_wcmd(dev, CH375_CMD_GET_IC_VER); /* Version */ + nap2(); + ch_ver = ch375_rdata(dev); + kprintf("ch375: version %2x\n", ch_ver); + if (ch_ver == 0xFF) + continue; + /* 376 - update commands to use */ + if ((ch_ver & 0xC0) == 0x40) { + ch_rd = CH376_CMD_RD_USB_DATA; + ch_wd = CH376_CMD_WR_HOST_DATA; + chip = 6; + } + kprintf("ch37%d: firmware version %d\n", chip, ch_ver & 0x3F); + /* Enable USB host mode, reset USB bus */ + ch375_cmd2(dev, CH375_CMD_SET_USB_MODE, 0x07); + nap20(); /* 20 us */ + /* Enable USB host mode, automatically generating SOF */ + ch375_cmd2(dev, CH375_CMD_SET_USB_MODE, 0x06); + nap20(); + /* After setting USB mode 0x06 an interrupt is generated when + * an USB storage device is present */ + r = ch375_rpoll(dev); + if (r == 0x51) + r = ch375_rpoll(dev); + if (r != CH375_USB_INT_CONNECT) { + continue; + } + + /* Initialize USB storage device */ + ch375_wcmd(dev, CH375_CMD_DISK_INIT); + r = ch375_rpoll(dev); + if (r != CH375_USB_INT_SUCCESS) + continue; + + /* And done */ + td_register(dev, ch375_xfer, td_ioctl_none, 1); } - - /* Initialize USB storage device */ - ch375_wcmd(CH375_CMD_DISK_INIT); - r = ch375_rpoll(); - if (r != CH375_USB_INT_SUCCESS) - return 0; - - /* And done */ - ch_dev = td_register(0, ch375_xfer, td_ioctl_none, 1); return 1; -} - -#endif + } + + #endif diff --git a/Kernel/dev/cpc/cpcidesme.c b/Kernel/dev/cpc/cpcidesme.c index 182d59a22..6d1c89554 100644 --- a/Kernel/dev/cpc/cpcidesme.c +++ b/Kernel/dev/cpc/cpcidesme.c @@ -2,147 +2,26 @@ #include #include -/* We have to provide slightly custom methods here because of the banked - kernel */ - #ifdef CONFIG_TD_IDE -COMMON_MEMORY -void devide_read_data(uint8_t *p) __naked +extern void* td_io_data_reg; +extern uint8_t td_io_data_count; +extern void td_io_rblock(uint8_t *p) __naked; +extern void td_io_wblock(uint8_t *p) __naked; + +void devide_read_data(uint8_t *p) { - __asm - .globl a_map_to_bc -#ifdef CONFIG_BANKED - pop bc - pop de - pop hl - push hl - push de - push bc -#else - pop de - pop hl - push hl - push de -#endif - ld a, (_td_raw) ; I/O type ? -#ifdef SWAPDEV - cp #2 - jr nz, not_swapin - ld a, (_td_page) ; swap page - call map_for_swap - jr doread -not_swapin: -#endif - or a ; test is_user - jr z, doread ; map user memory first if required - ld a, (_td_page) - call a_map_to_bc - out (c),c -doread: - ld bc,#0x7f10 - out (c),c - ld c,#0x51 ; Sea Green - out (c),c - ld bc, #IDE_REG_DATA ; setup port number - ; and count - ld a,#64 -doread1: ; transfer 512 bytes - ini - inc b - ini - inc b - ini - inc b - ini - inc b - ini - inc b - ini - inc b - ini - inc b - ini - inc b - dec a - jr nz,doread1 - ld bc,#0x7fc2 - out (c),c - ld bc,#0x7f10 - out (c),c - ld a,(_vtborder) - out (c),a - ret - __endasm; + td_io_data_reg = IDE_REG_DATA; + td_io_data_count = 64; + td_io_rblock(p); } -void devide_write_data(uint8_t *p) __naked +void devide_write_data(uint8_t *p) { - __asm - .globl a_map_to_bc -#ifdef CONFIG_BANKED - pop bc - pop de - pop hl - push hl - push de - push bc -#else - pop de - pop hl - push hl - push de -#endif - ld a, (_td_raw) ; ; I/O type - ; and count -#ifdef SWAPDEV - cp #2 - jr nz, not_swapout - ld a, (_td_page) ; page to swap - call map_for_swap - jr dowrite -not_swapout: -#endif - or a ; test is_user - jr z, dowrite ; map user memory first if required - ld a, (_td_page) - call a_map_to_bc - out (c),c -dowrite: - - ld bc,#0x7f10 - out (c),c - ld c,#0x45 ;Purple - out (c),c - ld bc, #IDE_REG_DATA ; setup port number - ; and count - ld a,#64 -dowrite1: ; transfer 512 bytes - inc b - outi - inc b - outi - inc b - outi - inc b - outi - inc b - outi - inc b - outi - inc b - outi - inc b - outi - dec a - jr nz,dowrite1 - ld bc,#0x7fc2 - out (c),c - ld bc,#0x7f10 - out (c),c - ld a,(_vtborder) - out (c),a - ret - __endasm; + uint8_t n; + td_io_data_reg = IDE_REG_DATA; + td_io_data_count = 64; + td_io_wblock(p); } + #endif diff --git a/Kernel/dev/cpc/albireosme.c b/Kernel/dev/cpc/td_block_io.c similarity index 67% rename from Kernel/dev/cpc/albireosme.c rename to Kernel/dev/cpc/td_block_io.c index 2a57b55cb..7d807246b 100644 --- a/Kernel/dev/cpc/albireosme.c +++ b/Kernel/dev/cpc/td_block_io.c @@ -1,14 +1,14 @@ #include #include -#include /* We have to provide slightly custom methods here because of the banked kernel */ -#ifdef CONFIG_ALBIREO +#ifdef CONFIG_TD + COMMON_MEMORY -void ch375_rblock(uint8_t *p) __naked +void td_io_rblock(uint8_t *p) __naked { __asm .globl a_map_to_bc @@ -25,6 +25,14 @@ void ch375_rblock(uint8_t *p) __naked push hl push de #endif + ld bc,#0x7f10 + out (c),c + ld c,#0x51 ; Sea Green + out (c),c + ld bc, (_td_io_data_reg) ; setup port number + ex af,af' ;' + ld a, (_td_io_data_count) + ex af,af' ;' ld a, (_td_raw) ; I/O type ? #ifdef SWAPDEV cp #2 @@ -34,20 +42,18 @@ void ch375_rblock(uint8_t *p) __naked jr doread not_swapin: #endif - or a ; test is_user - jr z, doread ; map user memory first if required + or a ; test is_user + jr z, doread ; map user memory first if required ld a, (_td_page) + exx call a_map_to_bc out (c),c + exx doread: - ld bc,#0x7f10 - out (c),c - ld c,#0x4a ;bright yellow - out (c),c - ld bc, #CH376_REG_DATA ; setup port number - ; and count + + ; and count ; transfer 64 bytes - ld a,#8 + ex af,af' ;' doread1: ini inc b @@ -66,7 +72,8 @@ void ch375_rblock(uint8_t *p) __naked ini inc b dec a - jr nz,doread1 + jr nz,doread1 + ex af,af' ;' ld bc,#0x7fc2 out (c),c ld bc,#0x7f10 @@ -77,7 +84,7 @@ void ch375_rblock(uint8_t *p) __naked __endasm; } -void ch375_wblock(uint8_t *p) __naked +void td_io_wblock(uint8_t *p) __naked { __asm .globl a_map_to_bc @@ -94,6 +101,14 @@ void ch375_wblock(uint8_t *p) __naked push hl push de #endif + ld bc,#0x7f10 + out (c),c + ld c,#0x45 ;Purple + out (c),c + ld bc, (_td_io_data_reg) ; setup port number + ex af,af' ;' + ld a, (_td_io_data_count) + ex af,af' ;' ld a, (_td_raw) ; ; I/O type ; and count #ifdef SWAPDEV @@ -104,20 +119,18 @@ void ch375_wblock(uint8_t *p) __naked jr dowrite not_swapout: #endif - or a ; test is_user - jr z, dowrite ; map user memory first if required + or a ; test is_user + jr z, dowrite ; map user memory first if required ld a, (_td_page) + exx call a_map_to_bc out (c),c + exx + dowrite: - ld bc,#0x7f10 - out (c),c - ld c,#0x55 ;bright blue - out (c),c - ld bc, #CH376_REG_DATA ; setup port number - ; and count + ; and count ; transfer 64 bytes - ld a,#8 + ex af,af' ;' dowrite1: inc b outi @@ -136,9 +149,10 @@ void ch375_wblock(uint8_t *p) __naked inc b outi dec a - jr nz,dowrite1 + jr nz,dowrite1 + ex af,af' ;' ld bc,#0x7fc2 - out (c),c + out (c),c ld bc,#0x7f10 out (c),c ld a,(_vtborder) diff --git a/Kernel/platform/platform-cpcsme/Makefile b/Kernel/platform/platform-cpcsme/Makefile index c14f47c3a..d8d783d82 100644 --- a/Kernel/platform/platform-cpcsme/Makefile +++ b/Kernel/platform/platform-cpcsme/Makefile @@ -1,9 +1,10 @@ CSRCS = devtty.c devices.c main.c devfdc765.c wiznet.c CDSRCS = discard.c -DSRCS = ../../dev/tinyide.c ../../dev/tinydisk.c ../../dev/ch375.c +DSRCS = ../../dev/tinyide.c ../../dev/tinydisk.c DDSRCS = ../../dev/tinyide_discard.c ../../dev/tinydisk_discard.c -DZSRCS = ../../dev/cpc/cpcidesme.c ../../dev/cpc/cpckeyboard.c ../../dev/cpc/devinput.c ../../dev/cpc/albireosme.c -DDZSRCS = +DZSRCS = ../../dev/cpc/cpcidesme.c ../../dev/cpc/cpckeyboard.c ../../dev/cpc/devinput.c +DZSRCS += ../../dev/cpc/ch375.c ../../dev/cpc/td_block_io.c +DDZSRCS = ../../dev/cpc/ch375_discard.c ASRCS = crt0.s cpcsme.s cpcvideo.s fdc765.s ASRCS += usermem.s tricks.s commonmem.s NSRCS = ../../dev/net/net_w5x00.c ../../dev/net/net_native.c @@ -76,7 +77,7 @@ image: flip -m fuzix.bas #Insert files to DSK image iDSK $(IMAGES)/fuzix.dsk -i fuzix.bas -t 0 -f -# iDSK $(IMAGES)/fuzix.dsk -i fuzix.scr -t 1 -c c000 -f + iDSK $(IMAGES)/fuzix.dsk -i fuzix.scr -t 1 -c c000 -f iDSK $(IMAGES)/fuzix.dsk -i runfuzix.bin -e 4000 -c 4000 -t 1 -f iDSK $(IMAGES)/fuzix.dsk -i fuzix1.bin -t 1 -c 4100 -f iDSK $(IMAGES)/fuzix.dsk -i fuzix2.bin -t 1 -c 4000 -f diff --git a/Kernel/platform/platform-cpcsme/config.h b/Kernel/platform/platform-cpcsme/config.h index 5ad1c446f..d27a2b343 100644 --- a/Kernel/platform/platform-cpcsme/config.h +++ b/Kernel/platform/platform-cpcsme/config.h @@ -59,18 +59,21 @@ #define NUM_DEV_TTY 2 #endif -/* Core networking support */ -#define CONFIG_NET -/* With a WizNet card */ -#define CONFIG_NET_WIZNET -#define CONFIG_NET_W5100 -/* Or native (eg SLIP) */ -#undef CONFIG_NET_NATIVE -#undef CONFIG_USIFAC_SLIP +/* SLIP on Usifac */ +#undef CONFIG_USIFAC_SLIP +#ifdef CONFIG_USIFAC_SLIP + #ifdef CONFIG_USIFAC_SERIAL + /* Core networking support */ + #define CONFIG_NET + #define CONFIG_NET_NATIVE + #else + #undef CONFIG_USIFAC_SLIP + #endif +#endif #define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */ -#define NBUFS 5 /* Number of block buffers MUST be big enough to push discard above 0xC000*/ +#define NBUFS 8 /* Number of block buffers MUST be big enough to push discard above 0xC000*/ /*Remember to set it also in kernel.def*/ #define NMOUNTS 4 /* Number of mounts at a time */ @@ -79,7 +82,7 @@ #define CONFIG_FDC765 #define CONFIG_TD -#define CONFIG_TD_NUM 2 +#define CONFIG_TD_NUM 4 /* IDE/CF support */ #define CONFIG_TD_IDE #ifdef CONFIG_TD_IDE @@ -89,9 +92,26 @@ #endif /* Albireo ch376 USB storage support*/ #define CONFIG_ALBIREO -#ifdef CONFIG_ALBIREO +/* USIFAC/ULIFAC ch376 USB storage support*/ +#define CONFIG_USIFAC_CH376 +#ifdef CONFIG_USIFAC_CH376 + #undef CONFIG_USIFAC_SERIAL + #undef CONFIG_USIFAC_SLIP + #undef CONFIG_NET + #undef CONFIG_NET_NATIVE +#endif + +#if ((defined CONFIG_ALBIREO)||(defined CONFIG_USIFAC_CH376)) #define CONFIG_CH375 #endif +/* Net4CPC card */ +#undef CONFIG_NET4CPC +#ifdef CONFIG_NET4CPC + /* Core networking support */ + #define CONFIG_NET + #define CONFIG_NET_WIZNET + #define CONFIG_NET_W5100 +#endif #define BOOTDEVICENAMES "hd#,fd" diff --git a/Kernel/platform/platform-cpcsme/cpcsme.s b/Kernel/platform/platform-cpcsme/cpcsme.s index 6db9376fb..614d9e747 100644 --- a/Kernel/platform/platform-cpcsme/cpcsme.s +++ b/Kernel/platform/platform-cpcsme/cpcsme.s @@ -28,13 +28,14 @@ .globl _int_disabled .globl _MMR_for_this_bank - .globl _n_valid_maps - .globl _valid_maps_array .globl _vtborder + .globl _td_io_data_reg + .globl _td_io_data_count + ; exported debugging tools .globl _plt_monitor @@ -130,12 +131,14 @@ _int_disabled: _vtborder: ; needs to be common .db 0 +_td_io_data_reg: + .dw 0 +_td_io_data_count: + .db 0 + _MMR_for_this_bank: .db 0 -_n_valid_maps: - .db 0 -_valid_maps_array: - .ds 15 + ; ----------------------------------------------------------------------------- ; KERNEL MEMORY BANK (only accessible when the kernel is mapped) ; In this port, as DISCARD area is in the upper 16K we can use C1 map to see the @@ -147,6 +150,11 @@ _valid_maps_array: ; ----------------------------------------------------------------------------- .area _DISCARD +_n_valid_maps: + .db 0 +_valid_maps_array: + .ds 15 + init_early: ld bc, #0x7fc1 ;convenient map to copy common to a visible area for copy routine out (c),c ;also used for video output @@ -260,7 +268,7 @@ not_valid: jp early_ret nmaps: .db 15 -MMR_array_for_copy_common:; cambiar esto- otro array para 7f, 7e, etc. recorrer ambos marcando cada 64k y aƱadiendo a pagemap init los marcados haciendo balance del total de RAM->discard +MMR_array_for_copy_common: .db 0xcf .db 0xd7 .db 0xdf @@ -327,25 +335,6 @@ ramsize_loop: ld bc,#stubs_low_end-stubs_low ldir - ;init usifac serial - - ld bc,#0xfbd1 - ld a,#16 - out (c),a ; try to set usifac baudrate 115200 - ld c,#0xdd - in a,(c) - cp #16 - jr nz, end_usifac ;usifac is not present - ld c,#0xd1 -flush_usifac: - in a,(c) - dec a - jr z,end_usifac - dec c - in a,(c) - inc c - jr flush_usifac -end_usifac: ld bc,#0x7f10 out (c),c ld a,#0x54 ; diff --git a/Kernel/platform/platform-cpcsme/devtty.h b/Kernel/platform/platform-cpcsme/devtty.h index 3dd3956d1..b1a3abc54 100644 --- a/Kernel/platform/platform-cpcsme/devtty.h +++ b/Kernel/platform/platform-cpcsme/devtty.h @@ -30,15 +30,5 @@ extern void cpckbd_conswitch(uint8_t console); __sfr __banked __at 0x7F00 gatearray; /* see: https://www.cpcwiki.eu/index.php/Gate_Array */ -#ifdef CONFIG_USIFAC_SERIAL -__sfr __banked __at 0xFBD0 usifdata; -__sfr __banked __at 0xFBD1 usifctrl; -__sfr __banked __at 0xFBDD usifspr; - -#define USIFAC_RESET_COMMAND 0 -#define USIFAC_CLEAR_RECEIVE_BUFFER_COMMAND 1 -#define USIFAC_DISABLE_BURST_MODE_COMMAND 3 -#define USIFAC_DISABLE_DIRECT_MODE_COMMAND 4 -#define USIFAC_SET_115200B_COMMAND 16 -#endif + #endif diff --git a/Kernel/platform/platform-cpcsme/discard.c b/Kernel/platform/platform-cpcsme/discard.c index 914317cc1..d21da7a1a 100644 --- a/Kernel/platform/platform-cpcsme/discard.c +++ b/Kernel/platform/platform-cpcsme/discard.c @@ -1,6 +1,7 @@ #include #include #include +#include "plt_ch375.h" extern int8_t n_valid_maps; extern uint8_t valid_maps_array[MAX_MAPS]; @@ -16,21 +17,7 @@ void pagemap_init(void) /* Nothing to do for the map of init but we do set our vectors up here */ void map_init(void) { - /*if (request_irq(0xE7, tuart0_rx_ring) | - request_irq(0xEF, tuart0_txd) | - request_irq(0xF7, tuart0_timer4)) - panic("irqset");*/ - /* We need to claim these in case we set one off as they are at odd vectors - as the base tu_uart is strapped for 8080 mode */ - /*if ( - request_irq(0xC7, spurious) | - request_irq(0xCF, spurious) | - request_irq(0xD7, spurious) | - request_irq(0xDF, spurious) | - request_irq(0xFF, spurious) - ) - panic("irqset2");*/ - /* FIXME: request vectors for uart1 and 2 */ + } uint8_t plt_param(char *p) @@ -44,34 +31,59 @@ void plt_copyright(void) kprintf("Amstrad CPC with standard memory expansion platform\nCopyright (c) 2024-2025 Antonio J. Casado Alias\n"); } -#if defined CONFIG_USIFAC_SERIAL -void usifac_serial_init() -{ +#if (defined CONFIG_USIFAC_SERIAL || defined CONFIG_USIFAC_CH376) +void usifac_flush(){ char c; - kprintf("Configuring Usifac serial port\n"); - usifctrl = USIFAC_RESET_COMMAND; - usifctrl = USIFAC_CLEAR_RECEIVE_BUFFER_COMMAND; - usifctrl = USIFAC_DISABLE_BURST_MODE_COMMAND; - usifctrl = USIFAC_DISABLE_DIRECT_MODE_COMMAND; - usifctrl = USIFAC_SET_115200B_COMMAND; - while (usifctrl == 0xff) /*Use some kind of timeout*/ + while ((usifctrl == 0xff)){ c=usifdata; /*flush transmit buffer*/ - c=usifspr; /*read baudrate*/ - if (c == USIFAC_SET_115200B_COMMAND) - { + /*kprintf("%2x:",c);*/ + } + /*kprintf("\n");*/ +} +void usifac_init() +{ + kprintf("Configuring Usifac\n"); + if (usifexists == 255){ + kprintf("Usifac not present\n"); + return; + } +#if (defined CONFIG_USIFAC_SERIAL && !(defined CONFIG_USIFAC_CH376)) + usifctrl = USIFAC_SET_115200B_COMMAND; + usifac_flush(); +#endif +#if (!(defined CONFIG_USIFAC_SERIAL) && (defined CONFIG_USIFAC_CH376)) + usifctrl = USIFAC_SET_9600B_COMMAND; + usifac_flush(); + usifdata = 0x57; + usifdata = 0xAB; + usifdata = 0x02; /*CH375_CMD_SET_BAUDRATE*/ + usifdata = 0x03; + usifdata = 0xFA; + usifctrl = USIFAC_SET_1MBPS_COMMAND; + usifac_flush(); +#endif + switch (usifgetbaud){ + case USIFAC_SET_1MBPS_COMMAND: + kprintf("Usifac CH376 module serial comunication configured at 1MBPS\n"); + break; + case USIFAC_SET_115200B_COMMAND: kprintf("Usifac serial port configured at 115200 baud\n"); - /* usifac_present = 1;*/ + break; + default: + kprintf("Error configuring Usifac, baudcode:%u\n",usifgetbaud); } } #endif + void device_init(void) { -#ifdef CONFIG_ALBIREO - ch375_probe(); +#if (defined CONFIG_USIFAC_SERIAL || defined CONFIG_USIFAC_CH376) + usifac_init(); #endif -#ifdef CONFIG_USIFAC_SERIAL - usifac_serial_init(); +#if (defined CONFIG_ALBIREO || defined CONFIG_USIFAC_CH376) + ch375_probe(); #endif + #ifdef CONFIG_TD_IDE ide_probe(); #endif diff --git a/Kernel/platform/platform-cpcsme/fuzix.lnk b/Kernel/platform/platform-cpcsme/fuzix.lnk index 0fea5cfa7..347a54546 100644 --- a/Kernel/platform/platform-cpcsme/fuzix.lnk +++ b/Kernel/platform/platform-cpcsme/fuzix.lnk @@ -41,16 +41,17 @@ devsys.rel devinput.rel network.rel platform/platform-cpcsme/devtty.rel +platform/platform-cpcsme/td_block_io.rel platform/platform-cpcsme/tinyide.rel platform/platform-cpcsme/tinyide_discard.rel platform/platform-cpcsme/cpcidesme.rel platform/platform-cpcsme/tinydisk.rel platform/platform-cpcsme/tinydisk_discard.rel +platform/platform-cpcsme/ch375.rel +platform/platform-cpcsme/ch375_discard.rel platform/platform-cpcsme/cpckeyboard.rel platform/platform-cpcsme/devfdc765.rel platform/platform-cpcsme/fdc765.rel -platform/platform-cpcsme/ch375.rel -platform/platform-cpcsme/albireosme.rel platform/platform-cpcsme/net_native.rel platform/platform-cpcsme/net_w5x00.rel platform/platform-cpcsme/wiznet.rel diff --git a/Kernel/platform/platform-cpcsme/main.c b/Kernel/platform/platform-cpcsme/main.c index 44dbbeeaa..8d3764c81 100644 --- a/Kernel/platform/platform-cpcsme/main.c +++ b/Kernel/platform/platform-cpcsme/main.c @@ -49,8 +49,9 @@ size_t strlen(const char *p) /* This points to the last buffer in the disk buffers. There must be at least four buffers to avoid deadlocks. */ +#ifdef CONFIG_DYNAMIC_BUFPOOL struct blkbuf *bufpool_end = bufpool + NBUFS; - +#endif /* * We pack discard into the memory image is if it were just normal * code but place it at the end after the buffers. When we finish up @@ -59,6 +60,7 @@ struct blkbuf *bufpool_end = bufpool + NBUFS; */ void plt_discard(void) { +#ifdef CONFIG_DYNAMIC_BUFPOOL uint16_t discard_size = PROGTOP - (uint16_t)bufpool_end; bufptr bp = bufpool_end; @@ -74,4 +76,5 @@ void plt_discard(void) bp->bf_dev = NO_DEVICE; bp->bf_busy = BF_FREE; } +#endif } diff --git a/Kernel/platform/platform-cpcsme/plt_ch375.h b/Kernel/platform/platform-cpcsme/plt_ch375.h index f924685be..98328e14e 100644 --- a/Kernel/platform/platform-cpcsme/plt_ch375.h +++ b/Kernel/platform/platform-cpcsme/plt_ch375.h @@ -1,16 +1,56 @@ +#ifndef PLT_CH375_H +#define PLT_CH375_H + extern void nap20(void); -extern void ch375_rblock(uint8_t *ptr);/* __z88dk_fastcall; */ -extern void ch375_wblock(uint8_t *ptr);/* __z88dk_fastcall; */ +extern void td_io_rblock(uint8_t *ptr);/* __z88dk_fastcall; */ +extern void td_io_wblock(uint8_t *ptr);/* __z88dk_fastcall; */ + +#define nap2() __asm__ ("nop\nnop"); + +#define CH375_COMM_PARALLEL 0 +#define CH375_COMM_SERIAL 1 +#define CH375_SERIAL_WAIT 1 + +#if ((defined CONFIG_ALBIREO) && (defined CONFIG_USIFAC_CH376)) +#define CH375_DEVICES 3 +#ifdef _CH375_PRIVATE +uint16_t ch375_dports[CH375_DEVICES] = {0xFE80, 0xFE40, 0xFBD0}; +uint16_t ch375_sports[CH375_DEVICES] = {0xFE81, 0xFE41, 0XFBD1}; +uint8_t ch375_comm_type[CH375_DEVICES] = {CH375_COMM_PARALLEL, CH375_COMM_PARALLEL, CH375_COMM_SERIAL}; +#endif +#endif -__sfr __banked __at 0xFE80 ch375_dport; -__sfr __banked __at 0xFE81 ch375_sport; +#if ((defined CONFIG_ALBIREO) && !(defined CONFIG_USIFAC_CH376)) +#define CH375_DEVICES 2 +#ifdef _CH375_PRIVATE +uint16_t ch375_dports[CH375_DEVICES] = {0xFE80, 0xFE40}; +uint16_t ch375_sports[CH375_DEVICES] = {0xFE81, 0xFE41}; +uint8_t ch375_comm_type[CH375_DEVICES] = {CH375_COMM_PARALLEL, CH375_COMM_PARALLEL}; +#endif +#endif -#define ch375_rdata() ch375_dport -#define ch375_rstatus() ch375_sport +#if (!(defined CONFIG_ALBIREO) && (defined CONFIG_USIFAC_CH376)) +#define CH375_DEVICES 1 +#ifdef _CH375_PRIVATE +uint16_t ch375_dports[CH375_DEVICES] = {0xFBD0}; +uint16_t ch375_sports[CH375_DEVICES] = {0XFBD1}; +uint8_t ch375_comm_type[CH375_DEVICES] = {CH375_COMM_SERIAL}; +#endif +#endif -#define ch375_wdata(x) do {ch375_dport = (x); } while(0) -#define ch375_wcmd(x) do {ch375_sport = (x); } while(0) +#if (defined CONFIG_USIFAC_SERIAL || defined CONFIG_USIFAC_CH376) +__sfr __banked __at 0xFBD0 usifdata; +__sfr __banked __at 0xFBD1 usifctrl; +__sfr __banked __at 0xFBD8 usifexists; +__sfr __banked __at 0xFBDD usifgetbaud; +__sfr __banked __at 0xFBDE usifgetusbstat; -#define CH376_REG_DATA 0xFE80 -#define nap2() __asm__ ("nop\nnop"); \ No newline at end of file +#define USIFAC_RESET_COMMAND 0 +#define USIFAC_CLEAR_RECEIVE_BUFFER_COMMAND 1 +#define USIFAC_SET_9600B_COMMAND 12 +#define USIFAC_SET_115200B_COMMAND 16 +#define USIFAC_SET_1MBPS_COMMAND 22 +#define USIFAC_SET_ONLY_SERIAL 100 +#endif +#endif \ No newline at end of file diff --git a/Kernel/platform/platform-cpcsme/runfuzix.s b/Kernel/platform/platform-cpcsme/runfuzix.s index 045601a12..5ce3c608c 100644 --- a/Kernel/platform/platform-cpcsme/runfuzix.s +++ b/Kernel/platform/platform-cpcsme/runfuzix.s @@ -1,10 +1,9 @@ .area BOOT (ABS) .org #0x4000 - ld hl,#0x100+#switch_to_fuzix-#switch_to_fuzix_end - ld de,#switch_to_fuzix + ld hl,#switch_to_fuzix + ld de,#0x100+#switch_to_fuzix-#switch_to_fuzix_end ld bc,#switch_to_fuzix_end-#switch_to_fuzix - push hl - ex de,hl + push de ldir pop hl jp (hl) diff --git a/Kernel/platform/platform-cpcsme/userspace/resolv.conf b/Kernel/platform/platform-cpcsme/userspace/resolv.conf index eacfef0c0..9ec404f44 100644 --- a/Kernel/platform/platform-cpcsme/userspace/resolv.conf +++ b/Kernel/platform/platform-cpcsme/userspace/resolv.conf @@ -1,3 +1,3 @@ -nameserver 8.8.8.8 -nameserver 8.8.4.4 -nameserver 192.168.1.1 +nameserver 193.110.81.0 +nameserver 185.253.5.0 +