Fixed some bug, added the humidity sensor
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 8 Mar 2001 19:49:29 +0000 (19:49 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 8 Mar 2001 19:49:29 +0000 (19:49 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@676 4a8a32a2-be11-0410-ad9d-d568d2c75423

15 files changed:
device/examples/ds390/ow390/Makefile
device/examples/ds390/ow390/ad26.c [new file with mode: 0755]
device/examples/ds390/ow390/ad26.h [new file with mode: 0755]
device/examples/ds390/ow390/gethumd.c [new file with mode: 0755]
device/examples/ds390/ow390/owfile.c
device/examples/ds390/ow390/owllu.c
device/examples/ds390/ow390/ownet.h
device/examples/ds390/ow390/ownetu.c
device/examples/ds390/ow390/owsesu.c
device/examples/ds390/ow390/owtrnu.c
device/examples/ds390/ow390/temp.c
device/examples/ds390/ow390/time.c [deleted file]
device/examples/ds390/ow390/time.h [deleted file]
device/examples/ds390/ow390/tinilnk.c
device/examples/ds390/ow390/tstow.c

index 6519e97fcaa5176688dc70119f875d1342b7fd52..b20dc5b0e0ee946636d026dd066269a8351d573a 100755 (executable)
@@ -1,18 +1,18 @@
 #CC = sdcc
 CC = /home/johan/sdcc/bin/sdcc
 
-MFLAGS = -mds390 --model-flat24 --stack-10bit
+MFLAGS = -mds390
 LFLAGS = --xram-loc 0x180080 --code-loc 0x10000 -Wl-r
 
 TARGETS = tstfind.hex temp.hex swtloop.hex swtoper.hex counter.hex \
-       tstow.hex thermodl.hex
+       tstow.hex thermodl.hex gethumd.hex
 
 OW_OBJECTS = ownetu.rel owsesu.rel owllu.rel owlli.rel owtrnu.rel \
        crcutil.rel tinilnk.rel findtype.rel ds2480ut.rel owfile.rel
 
-SENSOR_OBJECTS = temp10.rel  swt12.rel cnt1d.rel thermo21.rel
+SENSOR_OBJECTS = temp10.rel  swt12.rel cnt1d.rel thermo21.rel ad26.rel
 
-TINI_TEST_OBJECTS = time.rel
+TINI_TEST_OBJECTS =
 
 all: ow.lib sensors.lib $(TINI_TEST_OBJECTS) $(TARGETS)
 
diff --git a/device/examples/ds390/ow390/ad26.c b/device/examples/ds390/ow390/ad26.c
new file mode 100755 (executable)
index 0000000..703bdc8
--- /dev/null
@@ -0,0 +1,265 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a 
+// copy of this software and associated documentation files (the "Software"), 
+// to deal in the Software without restriction, including without limitation 
+// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+// and/or sell copies of the Software, and to permit persons to whom the 
+// Software is furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included 
+// in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES 
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
+// OTHER DEALINGS IN THE SOFTWARE.
+// 
+// Except as contained in this notice, the name of Dallas Semiconductor 
+// shall not be used except as stated in the Dallas Semiconductor 
+// Branding Policy. 
+//--------------------------------------------------------------------------
+//
+//  ad26.c - Reads the voltage on the 1-Wire
+//  version 1.00
+//
+
+// Include Files
+#include <stdio.h>
+#include "ownet.h"
+#include "ad26.h"
+
+int Volt_AD(int portnum, int vdd, uchar *SNum)
+{
+   uchar send_block[50];
+   uchar test;
+   int send_cnt=0;
+   int i;
+   ushort lastcrc8;
+   int busybyte; 
+
+   owSerialNum(portnum,SNum,FALSE);
+   // Recall the Status/Configuration page
+   // Recall command
+   send_block[send_cnt++] = 0xB8;
+
+   // Page to Recall
+   send_block[send_cnt++] = 0x00;
+
+   if(!owBlock(portnum,FALSE,send_block,send_cnt))
+      return FALSE;
+
+   send_cnt = 0;
+
+   if(owAccess(portnum))
+   {
+      // Read the Status/Configuration byte
+      // Read scratchpad command
+      send_block[send_cnt++] = 0xBE;
+
+      // Page for the Status/Configuration byte
+      send_block[send_cnt++] = 0x00;
+
+      for(i=0;i<9;i++)
+         send_block[send_cnt++] = 0xFF;
+
+      if(owBlock(portnum,FALSE,send_block,send_cnt))
+      {
+       setcrc8(portnum,0);
+
+         for(i=2;i<send_cnt;i++)
+          lastcrc8 = docrc8(portnum,send_block[i]);
+
+         if(lastcrc8 != 0x00)
+            return FALSE;
+      }//Block
+      else
+         return FALSE;
+
+      test = send_block[2] & 0x08;
+      if(((test == 0x08) && vdd) || ((test == 0x00) && !(vdd)))
+         return TRUE;
+   }//Access
+
+   if(owAccess(portnum))
+   {
+      send_cnt = 0;
+      // Write the Status/Configuration byte
+      // Write scratchpad command
+      send_block[send_cnt++] = 0x4E;
+
+      // Write page
+      send_block[send_cnt++] = 0x00;
+
+      if(vdd)
+         send_block[send_cnt++] = send_block[2] | 0x08;
+      else
+         send_block[send_cnt++] = send_block[2] & 0xF7;
+
+      for(i=0;i<7;i++)
+         send_block[send_cnt++] = send_block[i+4];
+
+      if(owBlock(portnum,FALSE,send_block,send_cnt))
+      {
+         send_cnt = 0;
+
+         if(owAccess(portnum))
+         {
+            // Copy the Status/Configuration byte
+            // Copy scratchpad command
+            send_block[send_cnt++] = 0x48;
+
+            // Copy page
+            send_block[send_cnt++] = 0x00;
+
+            if(owBlock(portnum,FALSE,send_block,send_cnt))
+            {
+               busybyte = owReadByte(portnum);
+         
+               while(busybyte == 0)
+                  busybyte = owReadByte(portnum);
+
+               return TRUE;
+            }//Block
+         }//Access
+      }//Block
+
+   }//Access
+
+   return FALSE;
+}
+      
+
+float Volt_Reading(int portnum, int vdd, uchar *SNum)
+{
+   uchar send_block[50];
+   int send_cnt=0;
+   int i;
+   int busybyte; 
+   uchar lastcrc8;
+   ushort volts;
+   float ret=-1.0;
+
+   if(Volt_AD(portnum,vdd,SNum))
+   {
+
+      if(owAccess(portnum))
+      {
+         if(!owWriteByte(portnum,0xB4))
+         {
+          //output_status(LV_ALWAYS,(char *)"DIDN'T WRITE CORRECTLY\n");
+          printf ("DIDN'T WRITE CORRECTLY\n");
+          return ret;
+         }
+
+         busybyte = owReadByte(portnum);
+         
+         while(busybyte == 0)
+            busybyte = owReadByte(portnum);
+      }
+
+      if(owAccess(portnum))
+      {
+         // Recall the Status/Configuration page
+         // Recall command
+         send_block[send_cnt++] = 0xB8;
+
+         // Page to Recall
+         send_block[send_cnt++] = 0x00;
+
+         if(!owBlock(portnum,FALSE,send_block,send_cnt))
+            return ret;
+      }
+
+
+      send_cnt = 0;
+
+      if(owAccess(portnum))
+      {
+         // Read the Status/Configuration byte
+         // Read scratchpad command
+         send_block[send_cnt++] = 0xBE;
+
+         // Page for the Status/Configuration byte
+         send_block[send_cnt++] = 0x00;
+
+         for(i=0;i<9;i++)
+            send_block[send_cnt++] = 0xFF;
+
+         if(owBlock(portnum,FALSE,send_block,send_cnt))
+         {
+            setcrc8(portnum,0);
+
+            for(i=2;i<send_cnt;i++)
+               lastcrc8 = docrc8(portnum,send_block[i]);
+
+            if(lastcrc8 != 0x00)
+               return ret;
+
+         }
+         else
+            return ret;    
+      
+         volts = ((int)send_block[6] << 8) | send_block[5];
+         ret = (float) volts/100;
+      }//Access
+   }
+
+   return ret;
+
+}
+
+double Get_Temperature(int portnum,uchar *SNum)
+{
+   double ret=-1.0;
+   uchar send_block[50];
+   int send_cnt=0;
+   int i;
+   uchar lastcrc8;
+
+   owSerialNum(portnum,SNum,FALSE);
+
+   if(owAccess(portnum))
+      // Convert Temperature command
+      owWriteByte(portnum,0x44);
+
+   msDelay(10);
+
+
+   if(owAccess(portnum))
+   {
+      // Read the Status/Configuration byte
+      // Read scratchpad command
+      send_block[send_cnt++] = 0xBE;
+
+      // Page for the Status/Configuration byte
+      send_block[send_cnt++] = 0x00;
+
+      for(i=0;i<9;i++)
+         send_block[send_cnt++] = 0xFF;
+
+      if(owBlock(portnum,FALSE,send_block,send_cnt))
+      {
+         setcrc8(portnum,0);
+
+         for(i=2;i<send_cnt;i++) {
+            lastcrc8 = docrc8(portnum,send_block[i]);
+        } printf ("\n");
+
+         if(lastcrc8 != 0x00)
+            return ret;
+
+      }
+      else
+         return ret;    
+      
+      ret = ((((unsigned int)send_block[4] << 8) | send_block[3]) >> 3) * 0.03125;
+   }//Access
+
+   return ret;
+}
+
diff --git a/device/examples/ds390/ow390/ad26.h b/device/examples/ds390/ow390/ad26.h
new file mode 100755 (executable)
index 0000000..ae3fb69
--- /dev/null
@@ -0,0 +1,33 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a 
+// copy of this software and associated documentation files (the "Software"), 
+// to deal in the Software without restriction, including without limitation 
+// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+// and/or sell copies of the Software, and to permit persons to whom the 
+// Software is furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included 
+// in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES 
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
+// OTHER DEALINGS IN THE SOFTWARE.
+// 
+// Except as contained in this notice, the name of Dallas Semiconductor 
+// shall not be used except as stated in the Dallas Semiconductor 
+// Branding Policy. 
+//---------------------------------------------------------------------------
+//
+//  ad26.h - Include file for Smart Battery Monitor demo.
+//
+//  Version: 2.00
+
+int Volt_AD(int portnum, int vdd, uchar *);
+float Volt_Reading(int portnum, int vdd, uchar *);
+double Get_Temperature(int portnum,uchar *);
diff --git a/device/examples/ds390/ow390/gethumd.c b/device/examples/ds390/ow390/gethumd.c
new file mode 100755 (executable)
index 0000000..074e9a1
--- /dev/null
@@ -0,0 +1,111 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a 
+// copy of this software and associated documentation files (the "Software"), 
+// to deal in the Software without restriction, including without limitation 
+// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+// and/or sell copies of the Software, and to permit persons to whom the 
+// Software is furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included 
+// in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES 
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
+// OTHER DEALINGS IN THE SOFTWARE.
+// 
+// Except as contained in this notice, the name of Dallas Semiconductor 
+// shall not be used except as stated in the Dallas Semiconductor 
+// Branding Policy. 
+//---------------------------------------------------------------------------
+//
+//  getV.c - This utility gets the Volts for pins Vad and Vdd from the DS2438. 
+//
+//  Version:   2.00
+//  History: 
+
+#include <stdio.h>
+#include "ownet.h"  
+#include "ad26.h"
+
+#define MAXDEVICES 5
+
+// Global necessary for screenio
+int VERBOSE;
+
+// tini hack
+int argc=2;
+char *argv[]={__FILE__, "exow"};
+
+//----------------------------------------------------------------------
+//  This is the Main routine for debit
+//
+int main() //short argc, char **argv)
+{
+   char msg[200];
+   int portnum = 0;
+   float Vdd,Vad;
+   double humid,temp;
+   int i;
+   int numbat;
+   uchar famvolt[MAXDEVICES][8];
+
+   // check for required port name
+   if (argc != 2)
+   {
+      sprintf(msg,"1-Wire Net name required on command line!\n"
+                 " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
+                  "(Linux DS2480),\"1\" (Win32 TMEX)\n");
+      //output_status(LV_ALWAYS,msg);
+      printf (msg);
+      return 0;
+   }
+
+   if(!owAcquire(portnum,argv[1],msg))
+   {
+      //output_status(LV_ALWAYS,msg);
+      printf (msg);
+      return 0;
+   }
+   else
+   {
+
+      do
+      {
+         numbat = FindDevices(portnum,&famvolt[0],SBATTERY_FAM,MAXDEVICES);
+        if (numbat==0) {
+          printf ("No device found.\n");
+        }
+
+         for(i=0;i<numbat;i++)
+         {
+            Vdd = Volt_Reading(portnum,TRUE,&famvolt[0][0]);
+            Vad = Volt_Reading(portnum,FALSE,&famvolt[0][0]);
+
+            temp = Get_Temperature(portnum,&famvolt[0][0]);
+
+            humid = (((Vad/Vdd) - 0.16)/0.0062)/(1.0546 - 0.00216 * temp);
+               
+            printf("\n");
+            printf("The humidity is:  %4.4f\n", humid);
+            printf("Given that the temp was:   %2.2f\n", temp);
+            printf("and the volt supply was:   %2.2f\n", Vdd);
+            printf("with the volt output was:  %2.2f\n", Vad);
+            printf("\n");
+
+         }//for loop
+  
+      }while(!key_abort());  
+
+      owRelease(portnum,msg);
+      //output_status(LV_ALWAYS,msg);
+      printf (msg);
+   }
+
+   return 1;
+}
index 6ad8f9fbe3484fbf11c1be29181faa2f4bf2ea04..f192db572eb9a0188bfdea20e79f07d0dffde337 100644 (file)
@@ -1,3 +1,7 @@
+#define DEBUG_OW_FILE 0
+#if DEBUG_OW_FILE
+#include <stdio.h>
+#endif
 //---------------------------------------------------------------------------
 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
 // 
 //
 int owReadFile(int portnum, uchar *filename, uchar *buf)
 {  
-   uchar dirpg=0,pgbuf[32],filepg=0,pglen;
-   short bufcnt=0,i;
+  uchar dirpg=0,pgbuf[32],filepg=0;
+  char pglen;
+  ushort bufcnt=0,i;
                
+#if DEBUG_OW_FILE
+   printf ("owReadFile: %s\n", filename);
+#endif
    // loop read directory pages until the file entry is found
    do
    {
@@ -88,6 +96,9 @@ int owReadFile(int portnum, uchar *filename, uchar *buf)
          {
             // get the file starting page number
             filepg = pgbuf[i+5];
+#if DEBUG_OW_FILE
+           printf ("owReadFile: file %s starts at %d\n", filename, filepg);
+#endif
             break;
          }
       }
@@ -108,14 +119,16 @@ int owReadFile(int portnum, uchar *filename, uchar *buf)
       pglen = owReadPacketStd(portnum,TRUE,filepg,pgbuf);  
       
       // check result of read
-      if (pglen <= 0)
-         return READ_ERROR;
+      if (pglen <= 0) {
+       return READ_ERROR;
+      }
    
       // append the page data to the buffer
       for (i = 0; i < (pglen - 1); i++)
          buf[bufcnt++] = pgbuf[i];
 
       // get the next file page (from page pointer) 
+      _asm ;johan _endasm;
       filepg = pgbuf[pglen-1];
    }
    while (filepg);
@@ -154,6 +167,9 @@ int owFormatWriteFile(int portnum, uchar *filename, int fllen, uchar *buf)
       bmpg2[] = { 0,0,0,0,0 }, pgbuf[32];   
    int i,numdirpgs,flpg,bmpg1len,bmpg2len,cntleft,pos,numpgs;
 
+#if DEBUG_OW_FILE
+   printf ("owFormatWriteFile: %s %d\n", filename, fllen);
+#endif
    // calculate the number of pages needed to write the file
    numpgs = (fllen / 28) + ((fllen % 28) ? 1 : 0);
    
index 4030cf1a160739913824a6d414a5d01eae03eb50..63242ea2bff1d5b832e7a045cbd9220406ee22c3 100755 (executable)
@@ -1,3 +1,7 @@
+#define DEBUG_OW_LLU 0
+#if DEBUG_OW_LLU
+#include <stdio.h>
+#endif
 //---------------------------------------------------------------------------
 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
 // 
@@ -61,6 +65,9 @@ int owTouchReset(int portnum)
    uchar readbuffer[10],sendpacket[10];
    int sendlen=0;
 
+#if DEBUG_OW_LLU
+   printf ("owTouchReset\n");
+#endif
    // make sure normal level
    owLevel(portnum,MODE_NORMAL);
 
@@ -261,6 +268,9 @@ int owSpeed(int portnum, int new_speed)
    short sendlen=0;
    int rt = FALSE;
    
+#if DEBUG_OW_LLU
+   printf ("starting owSpeed: %d\n", new_speed);
+#endif
    // check if change from current mode
    if (((new_speed == MODE_OVERDRIVE) &&
         (USpeed[portnum] != SPEEDSEL_OD)) ||
@@ -308,7 +318,9 @@ int owSpeed(int portnum, int new_speed)
          }
       }
    }
-
+#if DEBUG_OW_LLU
+   printf ("owSpeed: %d\n", rt);
+#endif
    // return the current speed
    return (USpeed[portnum] == SPEEDSEL_OD) ? MODE_OVERDRIVE : MODE_NORMAL;
 }
@@ -333,6 +345,9 @@ int owLevel(int portnum, int new_level)
    short sendlen=0;
    short rt=FALSE;
 
+#if DEBUG_OW_LLU
+   printf ("owLevel: %d\n", new_level);
+#endif
    // check if need to change level
    if (new_level != ULevel[portnum])
    {
index 96b4ef02b1a0ae7ee526d0be816ea83449ceb5d7..7c18362814a8f5459c092f89c40ff509ac859d62 100755 (executable)
 // family codes of devices
 #define DIR_FAMILY 0x01
 #define TEMP_FAMILY 0x10
+#define NVRAM64K_FAMILY 0x0c
 #define SWITCH_FAMILY 0x12
 #define COUNT_FAMILY 0x1D
 #define ATOD_FAMILY 0X20
 #define THERMO_FAM 0x21
+#define SBATTERY_FAM  0x26
 // this is weird, the DS2502 should be 0x09
 #define DS2502_FAMILY 0x89
 
index e96016a40a76737d449eb937736dce1e4d43fc02..8629d4300fcbd2f79a1682a2355699c8c7630112 100755 (executable)
@@ -1,3 +1,7 @@
+#define DEBUG_OW_NETU 0
+#if DEBUG_OW_NETU
+#include <stdio.h>
+#endif
 //---------------------------------------------------------------------------
 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
 // 
@@ -111,7 +115,10 @@ int owNext(int portnum, int do_reset, int alarm_only)
       // reset the search
       LastDiscrepancy[portnum] = 0;
       LastDevice[portnum] = FALSE;
-      LastFamilyDiscrepancy[portnum] = 0;          
+      LastFamilyDiscrepancy[portnum] = 0;  
+#if DEBUG_OW_NETU
+      printf ("owNext: no (more) devices\n");
+#endif
       return FALSE;
    }
 
@@ -231,7 +238,10 @@ int owNext(int portnum, int do_reset, int alarm_only)
             // reset the search
             LastDiscrepancy[portnum] = 0;
             LastDevice[portnum] = FALSE;
-            LastFamilyDiscrepancy[portnum] = 0;          
+            LastFamilyDiscrepancy[portnum] = 0;        
+#if DEBUG_OW_NETU
+           printf ("owNext: check results failed\n");
+#endif
             return FALSE;
          }
          // successful search
@@ -249,7 +259,15 @@ int owNext(int portnum, int do_reset, int alarm_only)
             LastDiscrepancy[portnum] = tmp_last_desc;
             return TRUE;
          }
+      } else {
+#if DEBUG_OW_NETU
+       printf ("owNext: ReadCOM failed\n");
+#endif
       }
+   } else {
+#if DEBUG_OW_NETU
+     printf ("owNext: WriteCOM failed\n");
+#endif
    }
 
    // an error occured so re-sync with DS2480
@@ -473,6 +491,9 @@ int owOverdriveAccess(int portnum)
    uchar sendpacket[8];
    int i, bad_echo = FALSE;
 
+#if DEBUG_OW_NETU
+   printf ("owOverdriveAccess\n");
+#endif
    // make sure normal level
    owLevel(portnum,MODE_NORMAL);
 
@@ -501,8 +522,12 @@ int owOverdriveAccess(int portnum)
                if (sendpacket[i] != SerialNum[portnum][i])
                   bad_echo = TRUE;
             // if echo ok then success
-            if (!bad_echo)
+            if (!bad_echo) {
+#if DEBUG_OW_NETU
+             printf ("owOverdriveAccess success\n");
+#endif
                return TRUE;               
+           }
          }
       }
    }
index 508c3cd32b31046a98b127a3bbe1533448203b5c..2a4adf798b1304213ca68621842288c1badb904b 100755 (executable)
@@ -64,7 +64,7 @@ int owAcquire(int portnum, char *port_zstr, char *return_msg)
               " aborting.\nClosing port %s.\n",port_zstr,port_zstr);
       return FALSE;
    }
-   //printf (return_msg); // TODO: tini bug
+   printf (return_msg); // TODO: tini bug
 
    // detect DS2480
    if (DS2480Detect(portnum))
index bf67642bb356ffb58ea9aa77bed6f3c61713aad7..abd2e8418813f5caa77c4cc2e6be5a2da7d9f80b 100755 (executable)
@@ -1,3 +1,7 @@
+#define DEBUG_OW_TRNU 0
+#if DEBUG_OW_TRNU
+#include <stdio.h>
+#endif
 //---------------------------------------------------------------------------
 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
 // 
@@ -107,8 +111,9 @@ int owBlock(int portnum, int do_reset, uchar *tran_buf, int tran_len)
    if (WriteCOM(portnum,sendlen,sendpacket)) 
    {
       // read back the response 
-      if (ReadCOM(portnum,tran_len,tran_buf) == tran_len)
-         return TRUE;
+     if (ReadCOM(portnum,tran_len,tran_buf) == tran_len) {
+       return TRUE;
+     }
    }
 
    // an error occured so re-sync with DS2480
@@ -155,6 +160,9 @@ int owReadPacketStd(int portnum, int do_access, int start_page, uchar *read_buf)
    uchar sendpacket[50];
    ushort lastcrc16;
 
+#if DEBUG_OW_TRNU
+   printf ("owReadPacketStd: %d %d\n", do_access, start_page);
+#endif
    // check if access header is done 
    // (only use if in sequention read with one access at begining)
    if (do_access)
@@ -205,9 +213,14 @@ int owReadPacketStd(int portnum, int do_access, int start_page, uchar *read_buf)
          // verify the CRC16 is correct           
          if (lastcrc16 == 0xB001) 
            return length;        // return number of byte in record
+#if DEBUG_OW_TRNU
+        printf ("owReadPacketStd: crc error in page %d\n", start_page);
+#endif
       }  
    }
-
+#if DEBUG_OW_TRNU
+   printf ("owReadPacketStd: block>29 : %d\n", length);
+#endif
    // failed block or incorrect CRC
    return -1;
 }
@@ -254,9 +267,16 @@ int owWritePacketStd(int portnum, int start_page, uchar *write_buf,
    int i,buffer_cnt=0,start_address,do_access;
    ushort lastcrc16;
 
+#if DEBUG_OW_TRNU
+   printf ("owWritePacketStd: %d %d\n", start_page, write_len);
+#endif
    // check to see if data too long to fit on device
-   if (write_len > 29)
+   if (write_len > 29) {
+#if DEBUG_OW_TRNU
+     printf ("owWritePacketStd: too long\n");
+#endif
      return FALSE;
+   }
               
    // seed crc with page number           
    setcrc16(portnum,(ushort)start_page); 
@@ -280,12 +300,20 @@ int owWritePacketStd(int portnum, int start_page, uchar *write_buf,
    if (!is_eprom)
    {
       // write the page
-      if (!Write_Scratchpad(portnum,construct_buffer,start_page,buffer_cnt))
-         return FALSE;
+     if (!Write_Scratchpad(portnum,construct_buffer,start_page,buffer_cnt)) {
+#if DEBUG_OW_TRNU
+       printf ("owWritePacketStd: couldn't Write_Scratchpad\n");
+#endif
+       return FALSE;
+     }
    
       // copy the scratchpad            
-      if (!Copy_Scratchpad(portnum,start_page,buffer_cnt))
-         return FALSE;
+     if (!Copy_Scratchpad(portnum,start_page,buffer_cnt)) {
+#if DEBUG_OW_TRNU
+       printf ("owWritePacketStd: couldn't Copy_Scratchpad\n");
+#endif
+       return FALSE;
+     }
      
       // copy scratch pad was good then success
       return TRUE;
@@ -428,6 +456,9 @@ int Write_Scratchpad(int portnum, uchar *write_buf, int start_page, int write_le
    int i,sendlen=0;
    uchar sendpacket[50];
    
+#if DEBUG_OW_TRNU
+   printf ("Write_Scratchpad: %d %d\n", start_page, write_len);
+#endif
    // match command
    sendpacket[sendlen++] = 0x55;    
    for (i = 0; i < 8; i++)
@@ -436,6 +467,7 @@ int Write_Scratchpad(int portnum, uchar *write_buf, int start_page, int write_le
    sendpacket[sendlen++] = 0x0F;     
    // write the target address
    sendpacket[sendlen++] = ((start_page << 5) & 0xFF);    
+   _asm ;johan 1 _endasm;
    sendpacket[sendlen++] = (start_page >> 3);
 
    // write packet bytes 
@@ -461,20 +493,31 @@ int Write_Scratchpad(int portnum, uchar *write_buf, int start_page, int write_le
       if (owBlock(portnum,TRUE,sendpacket,sendlen))
       {
          // check address and offset of scratchpad read
-         if ((sendpacket[10] != (int)((start_page << 5) & 0xFF)) ||
-             (sendpacket[11] != (int)(start_page >> 3)) ||
-             (sendpacket[12] != (int)(write_len - 1)))
-            return FALSE;
+       if ((sendpacket[10] != (int)((start_page << 5) & 0xFF)) ||
+           (sendpacket[11] != (int)(start_page >> 3)) ||
+           (sendpacket[12] != (int)(write_len - 1))) {
+#if DEBUG_OW_TRNU
+          printf ("\nWrite_Scratchpad: check failed\n");
+#endif
+          //return FALSE;
+        }
 
          // verify each data byte
          for (i = 0; i < write_len; i++)
-            if (sendpacket[i+13] != write_buf[i])
-               return FALSE;
+          if (sendpacket[i+13] != write_buf[i]) {
+#if DEBUG_OW_TRNU
+            printf ("\nWrite_Scratchpad: data check failed\n");
+#endif
+            return FALSE;
+          }
 
          // must have verified
          return TRUE;
       }
-   }
+   } 
+#if DEBUG_OW_TRNU
+   printf ("\nWrite_Scratchpad: owBlock failed\n");
+#endif
    
    // failed a block tranfer
    return FALSE;
@@ -497,6 +540,10 @@ int Copy_Scratchpad(int portnum, int start_page, int write_len)
 {
    int i,sendlen=0;
    uchar sendpacket[50];
+
+#if DEBUG_OW_TRNU
+   printf ("Copy_Scratchpad: %d %d\n", start_page, write_len);
+#endif
    
    // match command
    sendpacket[sendlen++] = 0x55;    
@@ -506,11 +553,16 @@ int Copy_Scratchpad(int portnum, int start_page, int write_len)
    sendpacket[sendlen++] = 0x55;     
    // write the target address
    sendpacket[sendlen++] = ((start_page << 5) & 0xFF);    
+   _asm ;johan 2 _endasm;
    sendpacket[sendlen++] = (start_page >> 3);
    sendpacket[sendlen++] = write_len - 1;
    // read copy result
    sendpacket[sendlen++] = 0xFF;
-
+   
+#if DEBUG_OW_TRNU
+   printf ("Copy_Scratchpad: %d, %02x %02x %02x %02x\n", sendlen,
+          sendpacket[10],sendpacket[11],sendpacket[12],sendpacket[13]);
+#endif
    // send/recieve the transfer buffer   
    if (owBlock(portnum,TRUE,sendpacket,sendlen))
    {
@@ -518,12 +570,25 @@ int Copy_Scratchpad(int portnum, int start_page, int write_len)
       if ((sendpacket[10] != (int)((start_page << 5) & 0xFF)) ||
           (sendpacket[11] != (int)(start_page >> 3)) ||
           (sendpacket[12] != (int)(write_len - 1)) ||
-          (sendpacket[13] & 0xF0))
-         return FALSE;
-      else
+          (sendpacket[13] & 0xF0)) {
+#if DEBUG_OW_TRNU
+       printf ("Copy_Scratchpad: %d, check failed: %02x %02x %02x %02x\n",
+               sendlen,
+               sendpacket[10],sendpacket[11],sendpacket[12],sendpacket[13]);
+#endif
+       return FALSE;
+      }
+      else {
+#if DEBUG_OW_TRNU
+       printf ("Copy_Scratchpad: %02x %02x %02x %02x\n",
+               sendpacket[10],sendpacket[11],sendpacket[12],sendpacket[13]);
+#endif
          return TRUE;   
+      }
    }
-      
+#if DEBUG_OW_TRNU
+   printf ("Copy_Scratchpad: owBlock failed\n");
+#endif
    // failed a block tranfer
    return FALSE;
 }
index a9c62a28a01881d16483ebddaafa244acb14ad4d..52b4d0f575bb66f39bbc05cfcb80e944d9acaa95 100755 (executable)
@@ -121,7 +121,7 @@ int main() //short argc, char **argv)
             if (ReadTemperature(portnum, FamilySN[i],&current_temp))
             {  
                PrintSerialNum(FamilySN[i]);
-               printf("     %5.1f \n", current_temp); 
+               printf("     %5.2f \n", current_temp); 
             }
             else
                printf("     Error reading temperature, verify device present:%d\n",
diff --git a/device/examples/ds390/ow390/time.c b/device/examples/ds390/ow390/time.c
deleted file mode 100755 (executable)
index 3b61353..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "time.h"
-
-// let's just pretend it's 01 jan 1970 00.00:00 for now
-
-time_t time(time_t *t) {
-  *t=0;
-  return *t;
-}
-
-struct tm lastTime;
-
-struct tm *localtime(const time_t *timep) {
-  timep; // hush the compiler
-  lastTime.tm_sec=0;
-  lastTime.tm_min=0;
-  lastTime.tm_hour=0;
-  lastTime.tm_mday=1;
-  lastTime.tm_mon=0;
-  lastTime.tm_year=101;
-  lastTime.tm_wday=0;
-  lastTime.tm_yday=0;
-  lastTime.tm_isdst=0;
-  return &lastTime;
-}
diff --git a/device/examples/ds390/ow390/time.h b/device/examples/ds390/ow390/time.h
deleted file mode 100644 (file)
index 54dd150..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-struct tm
-{
-  int tm_sec;                   /* Seconds.     [0-60] (1 leap second) */
-  int tm_min;                   /* Minutes.     [0-59] */
-  int tm_hour;                  /* Hours.       [0-23] */
-  int tm_mday;                  /* Day.         [1-31] */
-  int tm_mon;                   /* Month.       [0-11] */
-  int tm_year;                  /* Year - 1900.  */
-  int tm_wday;                  /* Day of week. [0-6] */
-  int tm_yday;                  /* Days in year.[0-365] */
-  int tm_isdst;                 /* Daylight saving time */
-};
-
-typedef unsigned long time_t;
-
-time_t time(time_t *t);
-struct tm *localtime(time_t *timep);
index 95e95e90f902162d2ae97fa6d5705afd39bfed17..d1b1669f2a6f74828125b06dd3cb1a9c1f4908bf 100644 (file)
@@ -1,3 +1,7 @@
+#define DEBUG_OW_COM 0
+#if DEBUG_OW_COM
+#include <stdio.h>
+#endif
 //---------------------------------------------------------------------------
 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
 // 
@@ -146,16 +150,22 @@ int WriteCOM(int portnum, int outlen, uchar *outbuf)
 {
   int i;
 
-  //printf ("WriteCOM(%d, %d,...): ", portnum, outlen, outbuf);
+#if DEBUG_OW_COM
+  printf ("WriteCOM(%d, %d,...): ", portnum, outlen, outbuf);
+#endif
 
   // hush the compiler
   portnum;
 
   for (i=0; i<outlen; i++) {
-    //printf ("%02x ", outbuf[i]);
+#if DEBUG_OW_COM
+    printf ("%02x ", outbuf[i]);
+#endif
     Serial1PutChar(outbuf[i]);
   }
-  //printf ("\n");
+#if DEBUG_OW_COM
+  printf ("\n");
+#endif
   return TRUE;
 }  
 
@@ -175,16 +185,22 @@ int ReadCOM(int portnum, int inlen, uchar *inbuf)
 {  
   int i;
 
-  //printf ("ReadCOM(%d,%d,...): ", portnum, inlen);
+#if DEBUG_OW_COM
+  printf ("ReadCOM(%d,%d,...): ", portnum, inlen);
+#endif
 
   // hush the compiler
   portnum;
 
   for (i=0; i<inlen; i++) {
     inbuf[i]=Serial1GetChar();
-    //printf ("%02x ", inbuf[i]);
+#if DEBUG_OW_COM
+    printf ("%02x ", inbuf[i]&0xff);
+#endif
   }
-  //printf ("\n");
+#if DEBUG_OW_COM
+  printf ("\n");
+#endif
   
    // success, so return desired length
    return i;
@@ -242,7 +258,6 @@ void BreakCOM(int portnum)
 void SetBaudCOM(int portnum, int new_baud)
 {
   unsigned long baud;
-  //printf ("SetBaudCOM(%d,%d)\n", portnum, new_baud);
 
   portnum; // hush the compiler
 
index cd68247f4abdd30803d9745146be6080946db257..01c561f71596d49668faaefb7ad094ad57ea1097 100755 (executable)
@@ -81,7 +81,7 @@ int main() //short argc, char **argv)
    //----------------------------------------
    // Introduction
    printf("\n/---------------------------------------------\n");
-   printf("  The following is a test excersize of the\n"
+    printf("  The following is a test excersize of the\n"
           "  1-Wire Net public domain library Version 2.00.\n\n"
           "  This test was run using with 2 DS1920's (DS1820),\n"
           "  1 DS1971 (DS2430), and 1 DS1996.\n\n");
@@ -109,8 +109,12 @@ int main() //short argc, char **argv)
 
    owFamilySearchSetup(portnum,0x0C);
 
-   // find the next device
-   printf("search result %d\n",owNext(portnum,TRUE, FALSE));
+   // find the first 0x0c device
+   TempSerialNum[0]=0;
+   while (TempSerialNum[0]!=0x0c && owNext(portnum,TRUE,FALSE)) {
+     owSerialNum(portnum,TempSerialNum,TRUE);
+   }
+   printf("search result %d\n",TempSerialNum[0]==0x0c);
 
    // print the Serial Number of the device just found
    PrintSerialNum(portnum);
@@ -158,7 +162,7 @@ int main() //short argc, char **argv)
    for (j = 0; j < 4; j++)
    {
       for (i = 0; i < 29; i++)
-         tran_buffer[i] = (uchar)i + j;
+       tran_buffer[i] = (uchar)i + j;
 
       printf("Write page %d: %d\n",j,owWritePacketStd(portnum,j,tran_buffer,29,FALSE,FALSE));
 
@@ -183,10 +187,12 @@ int main() //short argc, char **argv)
    for (i = 0; i < 2000; i++)
       tran_buffer[i] = i % 255;
    printf("Format and write file DEMO.000 %d\n",
-           owFormatWriteFile(portnum,filename,2000,tran_buffer));
+         owFormatWriteFile(portnum,filename,2000,tran_buffer));
+
    // clear the buffer
    for (i = 0; i < 2000; i++)
-      tran_buffer[i] = 0;
+      tran_buffer[i] = 0x55;
+   _asm ;johan _endasm;
    printf("Read file DEMO.000 %d\n",owReadFile(portnum,filename,tran_buffer));
    // print the data result
    for (i = 0; i < 2000; i++)
@@ -200,12 +206,14 @@ int main() //short argc, char **argv)
    //----------------------------------------
    // Turn off overdrive
    printf("\n/---------------------------------------------\n");
+   _asm ;johan 7 _endasm;
    printf("TEST%d: Turn off overdrive\n",testcnt++);
    printf("Set 1-Wire Net speed to normal %d\n",owSpeed(portnum,MODE_NORMAL));
 
    //----------------------------------------
    // Verify a device
    printf("\n/---------------------------------------------\n");
+   _asm ;johan 8 _endasm;
    printf("TEST%d: Verify the current device\n",testcnt++);
 
    printf("owVerify (normal) %d\n",owVerify(portnum,FALSE));
@@ -214,6 +222,7 @@ int main() //short argc, char **argv)
    //----------------------------------------
    // Skip the first family code found
    printf("\n/---------------------------------------------\n");
+   _asm ;johan 9 _endasm;
    printf("TEST%d: Skip the first family code found\n",testcnt++);
    
    // find the next device
@@ -235,6 +244,7 @@ int main() //short argc, char **argv)
    //----------------------------------------
    // Find first family code (DS1920) and read temperature
    printf("\n/---------------------------------------------\n");
+   _asm ;johan 10 _endasm;
    printf("TEST%d: Find first family code (DS1920) and read temperature\n",testcnt++);
 
    // find the next device
@@ -268,6 +278,7 @@ int main() //short argc, char **argv)
    //----------------------------------------
    //  Verify the current device, could also be alarming
    printf("\n/---------------------------------------------\n");
+   _asm ;johan 11 _endasm;
    printf("TEST%d: Verify the current device, could also be alarming\n",testcnt++);
 
    printf("owVerify (normal) %d\n",owVerify(portnum,FALSE));
@@ -276,6 +287,7 @@ int main() //short argc, char **argv)
    //----------------------------------------
    // Test setting the Serial Number with owSerialNum
    printf("\n/---------------------------------------------\n");
+   _asm ;johan 12 _endasm;
    printf("TEST%d: Test setting the Serial Number with owSerialNum\n",testcnt++);
 
    // set the Serial Num to 0 to 7
@@ -289,6 +301,7 @@ int main() //short argc, char **argv)
    //----------------------------------------
    //  Verify the current device (should fail, no such device)
    printf("\n/---------------------------------------------\n");
+   _asm ;johan 13 _endasm;
    printf("TEST%d: Verify the current device (should fail, no such device)\n",testcnt++);
 
    printf("owVerify (normal) %d\n",owVerify(portnum,FALSE));