coco3: better/conditional initialization of drivewire
authorBrett Gordon <beretta42@gmail.com>
Tue, 22 Nov 2016 18:28:33 +0000 (13:28 -0500)
committerBrett Gordon <beretta42@gmail.com>
Tue, 22 Nov 2016 18:28:33 +0000 (13:28 -0500)
Kernel/platform-coco3/devices.c
Kernel/platform-coco3/dwtime.c
Kernel/platform-coco3/libc.c
Kernel/platform-coco3/main.c
Kernel/platform-coco3/ttydw.c
Kernel/platform-coco3/ttydw.h

index 45c6003..79445ca 100644 (file)
@@ -49,7 +49,8 @@ void device_init(void)
 #ifdef CONFIG_COCOSDC
        devsdc_init( );
 #endif
-       dwtime_init( );
+       if ( ! dw_init() )
+               dwtime_init( );
        inittod();
        sock_init();
 }
index df138b2..df59892 100644 (file)
@@ -4,6 +4,7 @@
 #include <drivewire.h>
 #include <printf.h>
 #include <kdata.h>
+#include <ttydw.h>
 #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;
index 7b3842b..a8445fd 100644 (file)
@@ -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)
 {
index af0b957..68ee404 100644 (file)
@@ -3,10 +3,14 @@
 #include <kdata.h>
 #include <printf.h>
 #include <devtty.h>
+#include <ttydw.h>
+
+#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;
 }
 
index c9c5b2a..e899912 100644 (file)
 #include <printf.h>
 #include <tty.h>
 #include <devdw.h>
+#include <ttydw.h>
 
 #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;
 }
+
index 68e0e43..a007e8d 100644 (file)
@@ -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