/******************************************************************************/ /* Copyright 1998 MLML - Moss Landing Marine Labs */ /******************************************************************************/ /******************************************************************************/ /* Summary : Routines for Dallas Semi DS1994 Real Time Clock */ /* Filename : DS1994.C */ /* Author : Luke Coletti */ /* Project : */ /* Version : 1.0 */ /* Compiler : Aztec C68k/ROM v5.2D */ /* Created : 11/18/98 */ /* Archived : */ /******************************************************************************/ /* Modification History: */ /* */ /******************************************************************************/ #include /* Tattletale Model 8 Definitions */ #include /* definitions and prototypes for Model 8 library */ #include #include #include #include "lobo.h" ulong RdDS1994FracTime(uchar *ROM_ID, float *fracsecs) { int i; uchar touch_ret; ushort data[4]; #define TIMEREG 0x0202 TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0xF0); /* read memory command */ touch_ret = TouchByte(TIMEREG & 0xFF); /* send LSB of target addr then MSB */ touch_ret = TouchByte((TIMEREG & 0xFF00) / 0x100); *fracsecs = TouchByte(0xFF); /* read 1 byte of frac (1/256) binary secs */ for(i = 0; i <= 3; i ++){ /* read 4 bytes of secs */ data[i] = TouchByte(0xFF); } TouchReset(); /* initialize bus */ *fracsecs = (*fracsecs)/256.0; /* convert value to fractional decimal secs */ return( data[0] | (data[1]*0x100) | (data[2]*0x10000) | (data[3]*0x1000000) ); } long RdDS1994Long(ushort ADDR, uchar *ROM_ID) { int i; uchar touch_ret; ushort data[4]; TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0xF0); /* read memory command */ touch_ret = TouchByte(ADDR & 0xFF); /* send LSB of target addr then MSB */ touch_ret = TouchByte((ADDR & 0xFF00) / 0x100); for(i = 0; i <= 3; i ++){ /* read 4 bytes of data */ data[i] = TouchByte(0xFF); } TouchReset(); /* initialize bus */ return( data[0] | (data[1]*0x100) | (data[2]*0x10000) | (data[3]*0x1000000) ); } uchar WrDS1994Long(ushort ADDR, long VALUE, uchar *ROM_ID) { int i; uchar touch_ret; uchar A1r, A2r, STATr; uchar DATAr[4]; TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0x0F); /* write scratchpad command */ touch_ret = TouchByte(ADDR & 0xFF); /* send LSB of target addr then MSB */ touch_ret = TouchByte((ADDR & 0xFF00) / 0x100); touch_ret = TouchByte(VALUE & 0xFF); /* send four bytes (long) */ touch_ret = TouchByte((VALUE & 0xFF00) / 0x100); touch_ret = TouchByte((VALUE & 0xFF0000) / 0x10000); touch_ret = TouchByte(((VALUE & 0xFF000000) / 0x1000000) & 0xFF); TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0xAA); /* read scratchpad command */ A1r = TouchByte(0xFF); /* returned target address lo byte */ A2r = TouchByte(0xFF); /* returned target address hi byte */ STATr = TouchByte(0xFF); /* returned ending offset w/status */ for(i = 0; i <= 3; i ++){ /* read back 4 bytes sent */ DATAr[i] = TouchByte(0xFF); } TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0x55); /* copy scratchpad command */ touch_ret = TouchByte(A1r); /* verify ret target address lo byte */ touch_ret = TouchByte(A2r); /* verify ret target address hi byte */ touch_ret = TouchByte(STATr); /* verify ret offset w/status */ TouchReset(); /* initialize bus */ return(STATr); } short RdDS1994Short(ushort ADDR, uchar *ROM_ID) { int i; uchar touch_ret; uchar data[2]; TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0xF0); /* read memory command */ touch_ret = TouchByte(ADDR & 0xFF); /* send LSB of target addr then MSB */ touch_ret = TouchByte((ADDR & 0xFF00) / 0x100); for(i = 0; i <= 1; i ++){ /* read 2 data bytes of data */ data[i] = TouchByte(0xFF); } TouchReset(); /* initialize bus */ return( data[0] | (data[1]*0x100) ); } uchar WrDS1994Short(ushort ADDR, short VALUE, uchar *ROM_ID) { int i; uchar touch_ret; uchar A1r, A2r, STATr; uchar DATAr[2]; TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0x0F); /* write scratchpad command */ touch_ret = TouchByte(ADDR & 0xFF); /* send LSB of target addr then MSB */ touch_ret = TouchByte((ADDR & 0xFF00) / 0x100); touch_ret = TouchByte(VALUE & 0xFF); /* send two bytes (short) */ touch_ret = TouchByte((VALUE & 0xFF00) / 0x100); TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0xAA); /* read scratchpad command */ A1r = TouchByte(0xFF); /* returned target address lo byte */ A2r = TouchByte(0xFF); /* returned target address hi byte */ STATr = TouchByte(0xFF); /* returned ending offset w/status */ for(i = 0; i <= 1; i ++){ /* read back 2 data bytes */ DATAr[i] = TouchByte(0xFF); } /* ADD code to confirm value = DATAr */ TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0x55); /* copy scratchpad command */ touch_ret = TouchByte(A1r); /* verify ret target address lo byte */ touch_ret = TouchByte(A2r); /* verify ret target address hi byte */ touch_ret = TouchByte(STATr); /* verify ret offset w/status */ TouchReset(); /* initialize bus */ return(STATr); } uchar RdDS1994Byte(ushort ADDR, uchar *ROM_ID) { int i; uchar touch_ret; uchar data; TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0xF0); /* read memory command */ touch_ret = TouchByte(ADDR & 0xFF); /* send LSB of target addr then MSB */ touch_ret = TouchByte((ADDR & 0xFF00) / 0x100); data = TouchByte(0xFF); /* read 1 byte of data */ TouchReset(); /* initialize bus */ return(data); } uchar WrDS1994Byte(ushort ADDR, uchar VALUE, uchar *ROM_ID) { int i; uchar touch_ret; uchar A1r, A2r, STATr, DATAr; TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0x0F); /* write scratchpad command */ touch_ret = TouchByte(ADDR & 0xFF); /* send LSB of target addr then MSB */ touch_ret = TouchByte((ADDR & 0xFF00) / 0x100); touch_ret = TouchByte(VALUE); /* send one byte (uchar) */ TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0xAA); /* read scratchpad command */ A1r = TouchByte(0xFF); /* returned target address lo byte */ A2r = TouchByte(0xFF); /* returned target address hi byte */ STATr = TouchByte(0xFF); /* returned ending offset w/status */ DATAr = TouchByte(0xFF); /* read back 1 byte sent */ TouchReset(); /* initialize bus */ touch_ret = TouchByte(0x55); /* match ROM ID command */ for(i = 0; i <= 7; i++){ /* send ROM contents */ TouchByte(ROM_ID[i]); } touch_ret = TouchByte(0x55); /* copy scratchpad command */ touch_ret = TouchByte(A1r); /* verify ret target address lo byte */ touch_ret = TouchByte(A2r); /* verify ret target address hi byte */ touch_ret = TouchByte(STATr); /* verify ret offset w/status */ TouchReset(); /* initialize bus */ return(STATr); }