From 26674f1e2221b5fc9e6b939e9aa3607665cce60a Mon Sep 17 00:00:00 2001 From: Brett Gordon Date: Tue, 22 Nov 2016 13:28:33 -0500 Subject: [PATCH] coco3: better/conditional initialization of drivewire --- Kernel/platform-coco3/devices.c | 3 +- Kernel/platform-coco3/dwtime.c | 5 +++- Kernel/platform-coco3/libc.c | 9 ++++++ Kernel/platform-coco3/main.c | 16 ++++++++--- Kernel/platform-coco3/ttydw.c | 51 +++++++++++++++++++++++++++++++-- Kernel/platform-coco3/ttydw.h | 14 ++++++++- 6 files changed, 88 insertions(+), 10 deletions(-) diff --git a/Kernel/platform-coco3/devices.c b/Kernel/platform-coco3/devices.c index 45c6003a..79445ca7 100644 --- a/Kernel/platform-coco3/devices.c +++ b/Kernel/platform-coco3/devices.c @@ -49,7 +49,8 @@ void device_init(void) #ifdef CONFIG_COCOSDC devsdc_init( ); #endif - dwtime_init( ); + if ( ! dw_init() ) + dwtime_init( ); inittod(); sock_init(); } diff --git a/Kernel/platform-coco3/dwtime.c b/Kernel/platform-coco3/dwtime.c index df138b28..df59892f 100644 --- a/Kernel/platform-coco3/dwtime.c +++ b/Kernel/platform-coco3/dwtime.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "config.h" #define DISC __attribute__((section(".discard"))) @@ -15,7 +16,9 @@ static const uint16_t mktime_moffset[12]= { 0, 31, 59, 90, 120, 151, 181, 212, 2 static int get_time( uint8_t *tbuf ) { int ret; - + + if ( dwtype == DWTYPE_NOTFOUND ) + return -1; tbuf[0]=0x23; ret=dw_transaction( tbuf, 1, tbuf, 6, 0 ); if( ret ) return -1; diff --git a/Kernel/platform-coco3/libc.c b/Kernel/platform-coco3/libc.c index 7b3842b1..a8445fd1 100644 --- a/Kernel/platform-coco3/libc.c +++ b/Kernel/platform-coco3/libc.c @@ -1,5 +1,14 @@ #include "cpu.h" +int strcmp( char *a, char *b ){ + int ret; + while (1){ + ret = *a - *b++; + if( ! *a || ret ) + return ret; + a++; + } +} size_t strlen(const char *p) { diff --git a/Kernel/platform-coco3/main.c b/Kernel/platform-coco3/main.c index af0b957f..68ee4040 100644 --- a/Kernel/platform-coco3/main.c +++ b/Kernel/platform-coco3/main.c @@ -3,10 +3,14 @@ #include #include #include +#include + +#define DISC __attribute__((section(".discard"))) struct blkbuf *bufpool_end = bufpool + NBUFS; + void platform_discard(void) { extern uint8_t discard_size; @@ -34,7 +38,7 @@ void do_beep(void) } /* Scan memory return number of 8k pages found */ -__attribute__((section(".discard"))) +DISC int scanmem(void) { volatile uint8_t *mmu=(uint8_t *)0xffa8; @@ -60,7 +64,7 @@ int scanmem(void) Map handling: We have flexible paging. Each map table consists of a set of pages with the last page repeated to fill any holes. */ - +DISC void pagemap_init(void) { int i; @@ -75,14 +79,18 @@ void pagemap_init(void) pagemap_add(6); } - +DISC void map_init(void) { } - +DISC uint8_t platform_param(char *p) { + if( !strcmp(p,"NODW") ){ + dwtype = DWTYPE_NOTFOUND; + return -1; + } return 0; } diff --git a/Kernel/platform-coco3/ttydw.c b/Kernel/platform-coco3/ttydw.c index c9c5b2a8..e899912c 100644 --- a/Kernel/platform-coco3/ttydw.c +++ b/Kernel/platform-coco3/ttydw.c @@ -80,12 +80,14 @@ #include #include #include +#include #define DW_FASTWRITE 0x80 #define DW_SETSTAT 0xC4 #define DW_SERREAD 0x43 #define DW_SERREADM 0x63 #define DW_INIT 0x5a +#define DW_TIME 0x23 #define DW_VOPEN 0x29 #define DW_VCLOSE 0x2A @@ -93,6 +95,9 @@ #define DW_NS_OFF ( DW_MIN_OFF + DW_VSER_NUM ) +/* type of connected drivewire server */ +uint8_t dwtype = 0; + /* Internal Structure to represent state of DW ports */ struct dw_in{ uint8_t flags; /* flags for port */ @@ -276,9 +281,49 @@ int dw_carrier( uint8_t minor ){ /* (re) Initializes DW */ -void dw_init( ){ - unsigned char buf[2]; +__attribute__((section(".discard"))) +int dw_init( ){ + unsigned char buf[6]; + char *s; buf[0]=DW_INIT; buf[1]=0x42; - dw_transaction( buf,2,buf,1,0 ); + kprintf("DW: "); + if ( dwtype == DWTYPE_NOTFOUND ){ + kprintf("disabled\n"); + return -1; + } + if ( dw_transaction( buf,2,buf,1,0 ) ){ + buf[0] = DW_TIME; + if (dw_transaction( buf,1,buf,6,0 ) ){ + dwtype = DWTYPE_NOTFOUND; + kprintf("not found\n"); + return -1; + } + else { + s = "dw3"; + dwtype = DWTYPE_DW3; + } + } + else { + kprintf(" 0x%x: ", buf[0] ); + switch ( buf[0] ){ + case DWTYPE_DW4: + s = "dw4"; + break; + case DWTYPE_LWWIRE: + s = "lwwire"; + break; + case DWTYPE_PYDRIVEWIRE: + s = "n6il"; + break; + default: + s = "unknown"; + buf[0] = DWTYPE_UNKNOWN; + break; + } + dwtype = buf[0]; + } + kprintf("%s\n", s); + return 0; } + diff --git a/Kernel/platform-coco3/ttydw.h b/Kernel/platform-coco3/ttydw.h index 68e0e434..a007e8df 100644 --- a/Kernel/platform-coco3/ttydw.h +++ b/Kernel/platform-coco3/ttydw.h @@ -1,9 +1,21 @@ #ifndef __TTYDW_DOT_H__ #define __TTYDW_DOT_H__ +/* Stores drivewire server type on boot */ +extern uint8_t dwtype; +#define DWTYPE_DW3 0xfc +#define DWTYPE_UNKNOWN 0xfd +#define DWTYPE_NOTFOUND 0xfe +#define DWTYPE_PYDRIVEWIRE 0xff +#define DWTYPE_DW4 0x04 +#define DWTYPE_LWWIRE 0x80 + + void dw_putc( uint8_t minor, unsigned char c ); void dw_vopen( uint8_t minor ); void dw_vclose( uint8_t minor ); int dw_carrier( uint8_t minor ); -void dw_vpoll( ); +void dw_vpoll( void ); +int dw_init( void ); + #endif -- 2.34.1