#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)
--- /dev/null
+//---------------------------------------------------------------------------
+// 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;
+}
+
--- /dev/null
+//---------------------------------------------------------------------------
+// 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 *);
--- /dev/null
+//---------------------------------------------------------------------------
+// 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;
+}
+#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
{
{
// 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;
}
}
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);
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);
+#define DEBUG_OW_LLU 0
+#if DEBUG_OW_LLU
+#include <stdio.h>
+#endif
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
uchar readbuffer[10],sendpacket[10];
int sendlen=0;
+#if DEBUG_OW_LLU
+ printf ("owTouchReset\n");
+#endif
// make sure normal level
owLevel(portnum,MODE_NORMAL);
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)) ||
}
}
}
-
+#if DEBUG_OW_LLU
+ printf ("owSpeed: %d\n", rt);
+#endif
// return the current speed
return (USpeed[portnum] == SPEEDSEL_OD) ? MODE_OVERDRIVE : MODE_NORMAL;
}
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])
{
// 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
+#define DEBUG_OW_NETU 0
+#if DEBUG_OW_NETU
+#include <stdio.h>
+#endif
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
// 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;
}
// 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
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
uchar sendpacket[8];
int i, bad_echo = FALSE;
+#if DEBUG_OW_NETU
+ printf ("owOverdriveAccess\n");
+#endif
// make sure normal level
owLevel(portnum,MODE_NORMAL);
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;
+ }
}
}
}
" 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))
+#define DEBUG_OW_TRNU 0
+#if DEBUG_OW_TRNU
+#include <stdio.h>
+#endif
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
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
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)
// 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;
}
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);
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;
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++)
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
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;
{
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;
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))
{
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;
}
if (ReadTemperature(portnum, FamilySN[i],¤t_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",
+++ /dev/null
-#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;
-}
+++ /dev/null
-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);
+#define DEBUG_OW_COM 0
+#if DEBUG_OW_COM
+#include <stdio.h>
+#endif
//---------------------------------------------------------------------------
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
//
{
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;
}
{
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;
void SetBaudCOM(int portnum, int new_baud)
{
unsigned long baud;
- //printf ("SetBaudCOM(%d,%d)\n", portnum, new_baud);
portnum; // hush the compiler
//----------------------------------------
// 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");
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);
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));
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++)
//----------------------------------------
// 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));
//----------------------------------------
// 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
//----------------------------------------
// 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
//----------------------------------------
// 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));
//----------------------------------------
// 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
//----------------------------------------
// 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));