Committer:
svlach
Date:
Wed Dec 08 21:23:21 2010 +0000
Revision:
1:dcf2f8359398
Parent:
0:70c3bea805ee

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
svlach 0:70c3bea805ee 1 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
svlach 0:70c3bea805ee 3 //
svlach 0:70c3bea805ee 4 // Permission is hereby granted, free of charge, to any person obtaining a
svlach 0:70c3bea805ee 5 // copy of this software and associated documentation files (the "Software"),
svlach 0:70c3bea805ee 6 // to deal in the Software without restriction, including without limitation
svlach 0:70c3bea805ee 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
svlach 0:70c3bea805ee 8 // and/or sell copies of the Software, and to permit persons to whom the
svlach 0:70c3bea805ee 9 // Software is furnished to do so, subject to the following conditions:
svlach 0:70c3bea805ee 10 //
svlach 0:70c3bea805ee 11 // The above copyright notice and this permission notice shall be included
svlach 0:70c3bea805ee 12 // in all copies or substantial portions of the Software.
svlach 0:70c3bea805ee 13 //
svlach 0:70c3bea805ee 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
svlach 0:70c3bea805ee 15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
svlach 0:70c3bea805ee 16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
svlach 0:70c3bea805ee 17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
svlach 0:70c3bea805ee 18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
svlach 0:70c3bea805ee 19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
svlach 0:70c3bea805ee 20 // OTHER DEALINGS IN THE SOFTWARE.
svlach 0:70c3bea805ee 21 //
svlach 0:70c3bea805ee 22 // Except as contained in this notice, the name of Dallas Semiconductor
svlach 0:70c3bea805ee 23 // shall not be used except as stated in the Dallas Semiconductor
svlach 0:70c3bea805ee 24 // Branding Policy.
svlach 0:70c3bea805ee 25 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 26 //
svlach 0:70c3bea805ee 27 // TODO.C - COM functions required to communicate with the DS2480 based
svlach 0:70c3bea805ee 28 // Universal Serial Adapter 'U'. Fill in the platform specific code.
svlach 0:70c3bea805ee 29 //
svlach 0:70c3bea805ee 30 // Version: 2.00
svlach 0:70c3bea805ee 31 //
svlach 0:70c3bea805ee 32 // History: 1.00 -> 1.01 Added function msDelay.
svlach 0:70c3bea805ee 33 //
svlach 0:70c3bea805ee 34 // 1.01 -> 1.02 Changed to generic OpenCOM/CloseCOM for easier
svlach 0:70c3bea805ee 35 // use with other platforms.
svlach 0:70c3bea805ee 36 //
svlach 0:70c3bea805ee 37 // 1.02 -> 1.03 Removed caps in #includes for Linux capatibility
svlach 0:70c3bea805ee 38 // Add function msGettick()
svlach 0:70c3bea805ee 39 // 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
svlach 0:70c3bea805ee 40 // multiple ports.
svlach 0:70c3bea805ee 41 //
svlach 0:70c3bea805ee 42
svlach 1:dcf2f8359398 43 #include "onewire_config.h"
svlach 1:dcf2f8359398 44
svlach 1:dcf2f8359398 45 #include "ownet.h"
svlach 0:70c3bea805ee 46 #include "mbed.h"
svlach 0:70c3bea805ee 47 #include <string>
svlach 0:70c3bea805ee 48 using namespace std;
svlach 0:70c3bea805ee 49
svlach 1:dcf2f8359398 50
svlach 1:dcf2f8359398 51 Serial comport( ONEWIRE_TX , ONEWIRE_RX ); // tx, rx
svlach 0:70c3bea805ee 52
svlach 0:70c3bea805ee 53
svlach 0:70c3bea805ee 54 // exportable functions required
svlach 0:70c3bea805ee 55 SMALLINT OpenCOM(int,char *);
svlach 0:70c3bea805ee 56 SMALLINT WriteCOM(int,int,uchar *);
svlach 0:70c3bea805ee 57 void FlushCOM(int);
svlach 0:70c3bea805ee 58 int ReadCOM(int,int,uchar *);
svlach 0:70c3bea805ee 59 void BreakCOM(int);
svlach 0:70c3bea805ee 60 void SetBaudCOM(int,int);
svlach 0:70c3bea805ee 61 void CloseCOM(int);
svlach 0:70c3bea805ee 62 long msGettick(void);
svlach 0:70c3bea805ee 63 void msDelay(int);
svlach 0:70c3bea805ee 64 SMALLINT owHasPowerDelivery(int);
svlach 0:70c3bea805ee 65 SMALLINT owHasOverDrive(int);
svlach 0:70c3bea805ee 66 SMALLINT owHasProgramPulse(int);
svlach 0:70c3bea805ee 67 SMALLINT owWriteBytePower(int,SMALLINT);
svlach 0:70c3bea805ee 68 SMALLINT owReadBitPower(int,SMALLINT);
svlach 0:70c3bea805ee 69
svlach 0:70c3bea805ee 70
svlach 0:70c3bea805ee 71 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 72 // Attempt to open a com port. Keep the handle in ComID.
svlach 0:70c3bea805ee 73 // Set the starting baud rate to 9600.
svlach 0:70c3bea805ee 74 //
svlach 0:70c3bea805ee 75 // 'portnum' - number 0 to MAX_PORTNUM-1. This number provided will
svlach 0:70c3bea805ee 76 // be used to indicate the port number desired when calling
svlach 0:70c3bea805ee 77 // all other functions in this library.
svlach 0:70c3bea805ee 78 //
svlach 0:70c3bea805ee 79 // 'port_zstr' - zero terminate port name. For this platform
svlach 0:70c3bea805ee 80 // use format COMX where X is the port number.
svlach 0:70c3bea805ee 81 //
svlach 0:70c3bea805ee 82 //
svlach 0:70c3bea805ee 83 // Returns: TRUE(1) - success, COM port opened
svlach 0:70c3bea805ee 84 // FALSE(0) - failure, could not open specified port
svlach 0:70c3bea805ee 85 //
svlach 0:70c3bea805ee 86 SMALLINT OpenCOM(int portnum, char *port_zstr)
svlach 0:70c3bea805ee 87 {
svlach 0:70c3bea805ee 88 comport.baud( 9600);
svlach 0:70c3bea805ee 89 return 1;
svlach 0:70c3bea805ee 90 }
svlach 0:70c3bea805ee 91
svlach 0:70c3bea805ee 92 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 93 // Attempt to open a com port. Keep the handle in ComID.
svlach 0:70c3bea805ee 94 // Set the starting baud rate to 9600.
svlach 0:70c3bea805ee 95 //
svlach 0:70c3bea805ee 96 // 'portnum' - number 0 to MAX_PORTNUM-1. This number provided will
svlach 0:70c3bea805ee 97 // be used to indicate the port number desired when calling
svlach 0:70c3bea805ee 98 // all other functions in this library.
svlach 0:70c3bea805ee 99 //
svlach 0:70c3bea805ee 100 //
svlach 0:70c3bea805ee 101 // Returns: the port number if it was successful otherwise -1
svlach 0:70c3bea805ee 102 //
svlach 0:70c3bea805ee 103 int OpenCOMEx(char *port_zstr)
svlach 0:70c3bea805ee 104 {
svlach 0:70c3bea805ee 105 int portnum = -1;
svlach 0:70c3bea805ee 106
svlach 0:70c3bea805ee 107 if ( port_zstr[0] == '0')
svlach 0:70c3bea805ee 108 {
svlach 0:70c3bea805ee 109 portnum = 0;
svlach 0:70c3bea805ee 110 }
svlach 0:70c3bea805ee 111
svlach 0:70c3bea805ee 112 if ( port_zstr[0] == '1')
svlach 0:70c3bea805ee 113 {
svlach 0:70c3bea805ee 114 portnum = 1;
svlach 0:70c3bea805ee 115 }
svlach 1:dcf2f8359398 116
svlach 1:dcf2f8359398 117 if ( port_zstr[0] == '2')
svlach 1:dcf2f8359398 118 {
svlach 1:dcf2f8359398 119 portnum = 2;
svlach 1:dcf2f8359398 120 }
svlach 1:dcf2f8359398 121
svlach 1:dcf2f8359398 122 if ( port_zstr[0] == '3')
svlach 1:dcf2f8359398 123 {
svlach 1:dcf2f8359398 124 portnum = 3;
svlach 1:dcf2f8359398 125 }
svlach 0:70c3bea805ee 126
svlach 0:70c3bea805ee 127 if(!OpenCOM(portnum, port_zstr))
svlach 0:70c3bea805ee 128 {
svlach 0:70c3bea805ee 129 return -1;
svlach 0:70c3bea805ee 130 }
svlach 0:70c3bea805ee 131
svlach 0:70c3bea805ee 132 return portnum;
svlach 0:70c3bea805ee 133 }
svlach 0:70c3bea805ee 134
svlach 0:70c3bea805ee 135 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 136 // Closes the connection to the port.
svlach 0:70c3bea805ee 137 //
svlach 0:70c3bea805ee 138 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 139 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 140 //
svlach 0:70c3bea805ee 141 void CloseCOM(int portnum)
svlach 0:70c3bea805ee 142 {
svlach 0:70c3bea805ee 143 // add platform specific code here - Done
svlach 0:70c3bea805ee 144 }
svlach 0:70c3bea805ee 145
svlach 0:70c3bea805ee 146 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 147 // Flush the rx and tx buffers
svlach 0:70c3bea805ee 148 //
svlach 0:70c3bea805ee 149 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 150 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 151 //
svlach 0:70c3bea805ee 152 void FlushCOM(int portnum)
svlach 0:70c3bea805ee 153 {
svlach 0:70c3bea805ee 154 // add platform specific code here - Done
svlach 0:70c3bea805ee 155 while( comport.readable() )
svlach 0:70c3bea805ee 156 {
svlach 0:70c3bea805ee 157 comport.getc();
svlach 0:70c3bea805ee 158 }
svlach 0:70c3bea805ee 159 }
svlach 0:70c3bea805ee 160
svlach 0:70c3bea805ee 161 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 162 // Write an array of bytes to the COM port, verify that it was
svlach 0:70c3bea805ee 163 // sent out. Assume that baud rate has been set.
svlach 0:70c3bea805ee 164 //
svlach 0:70c3bea805ee 165 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 166 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 167 // 'outlen' - number of bytes to write to COM port
svlach 0:70c3bea805ee 168 // 'outbuf' - pointer ot an array of bytes to write
svlach 0:70c3bea805ee 169 //
svlach 0:70c3bea805ee 170 // Returns: TRUE(1) - success
svlach 0:70c3bea805ee 171 // FALSE(0) - failure
svlach 0:70c3bea805ee 172 //
svlach 0:70c3bea805ee 173 SMALLINT WriteCOM(int portnum, int outlen, uchar *outbuf)
svlach 0:70c3bea805ee 174 {
svlach 0:70c3bea805ee 175 // add platform specific code here - Done
svlach 0:70c3bea805ee 176 for ( int x=0; x < outlen; x++ )
svlach 0:70c3bea805ee 177 {
svlach 0:70c3bea805ee 178 comport.putc( outbuf[x]);
svlach 0:70c3bea805ee 179 }
svlach 0:70c3bea805ee 180
svlach 0:70c3bea805ee 181 while ( (LPC_UART3->LSR & 0x40) == 0 );
svlach 0:70c3bea805ee 182 {
svlach 0:70c3bea805ee 183 }
svlach 0:70c3bea805ee 184
svlach 0:70c3bea805ee 185 /*
svlach 0:70c3bea805ee 186 printf ("\r\n Sent Data: ");
svlach 0:70c3bea805ee 187 for ( int x=0; x < outlen; x++ )
svlach 0:70c3bea805ee 188 {
svlach 0:70c3bea805ee 189 printf ( " %X ", outbuf[x] );
svlach 0:70c3bea805ee 190 }
svlach 0:70c3bea805ee 191 printf ("\r\n");
svlach 0:70c3bea805ee 192 */
svlach 0:70c3bea805ee 193 return 1;
svlach 0:70c3bea805ee 194 }
svlach 0:70c3bea805ee 195
svlach 0:70c3bea805ee 196 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 197 // Read an array of bytes from the COM port, verify that it was
svlach 0:70c3bea805ee 198 // received. Assume that baud rate has been set.
svlach 0:70c3bea805ee 199 //
svlach 0:70c3bea805ee 200 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 201 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 202 // 'inlen' - number of bytes to read from COM port
svlach 0:70c3bea805ee 203 // 'inbuf' - pointer to a buffer to hold the incoming bytes
svlach 0:70c3bea805ee 204 //
svlach 0:70c3bea805ee 205 // Returns: number of characters read
svlach 0:70c3bea805ee 206 //
svlach 0:70c3bea805ee 207 int ReadCOM(int portnum, int inlen, unsigned char *inbuf)
svlach 0:70c3bea805ee 208 {
svlach 0:70c3bea805ee 209 // add platform specific code here - Done
svlach 0:70c3bea805ee 210 string buffer ("");
svlach 0:70c3bea805ee 211 Timer t;
svlach 0:70c3bea805ee 212 int numchar = 0;
svlach 0:70c3bea805ee 213
svlach 0:70c3bea805ee 214 t.start(); // Start timeout timer
svlach 0:70c3bea805ee 215
svlach 0:70c3bea805ee 216 while ( t.read_ms() < 1000 ) // If we haven't timed out....
svlach 0:70c3bea805ee 217 {
svlach 0:70c3bea805ee 218 if ( comport.readable() )
svlach 0:70c3bea805ee 219 {
svlach 0:70c3bea805ee 220 int read = comport.getc();
svlach 0:70c3bea805ee 221
svlach 0:70c3bea805ee 222 buffer += read;
svlach 0:70c3bea805ee 223 numchar++;
svlach 0:70c3bea805ee 224 t.reset();
svlach 0:70c3bea805ee 225 }
svlach 0:70c3bea805ee 226
svlach 0:70c3bea805ee 227 if (numchar == inlen)
svlach 0:70c3bea805ee 228 {
svlach 0:70c3bea805ee 229 break;
svlach 0:70c3bea805ee 230 }
svlach 0:70c3bea805ee 231 }
svlach 0:70c3bea805ee 232
svlach 0:70c3bea805ee 233 buffer.copy( (char*)inbuf, numchar );
svlach 0:70c3bea805ee 234 /*
svlach 0:70c3bea805ee 235 printf ("\r\n Received Data: ");
svlach 0:70c3bea805ee 236 for ( int x=0; x < numchar; x++ )
svlach 0:70c3bea805ee 237 {
svlach 0:70c3bea805ee 238 printf ( " %X ", inbuf[x] );
svlach 0:70c3bea805ee 239 }
svlach 0:70c3bea805ee 240 printf ("\r\n");
svlach 0:70c3bea805ee 241 */
svlach 0:70c3bea805ee 242 return numchar;
svlach 0:70c3bea805ee 243 }
svlach 0:70c3bea805ee 244
svlach 0:70c3bea805ee 245
svlach 0:70c3bea805ee 246 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 247 // Send a break on the com port for at least 2 ms
svlach 0:70c3bea805ee 248 //
svlach 0:70c3bea805ee 249 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 250 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 251 //
svlach 0:70c3bea805ee 252 void BreakCOM(int portnum)
svlach 0:70c3bea805ee 253 {
svlach 0:70c3bea805ee 254 // add platform specific code here - Done
svlach 0:70c3bea805ee 255 int time_BREAK = 2;
svlach 0:70c3bea805ee 256
svlach 0:70c3bea805ee 257 // BREAK
svlach 0:70c3bea805ee 258 LPC_UART3->LCR |= 0x40;
svlach 0:70c3bea805ee 259 wait_ms( time_BREAK);
svlach 0:70c3bea805ee 260
svlach 0:70c3bea805ee 261 // MARK AFTER BREAK
svlach 0:70c3bea805ee 262 LPC_UART3->LCR &= ~(0x40);
svlach 0:70c3bea805ee 263 }
svlach 0:70c3bea805ee 264
svlach 0:70c3bea805ee 265 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 266 // Set the baud rate on the com port.
svlach 0:70c3bea805ee 267 //
svlach 0:70c3bea805ee 268 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 269 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 270 // 'new_baud' - new baud rate defined as
svlach 0:70c3bea805ee 271 // PARMSET_9600 0x00
svlach 0:70c3bea805ee 272 // PARMSET_19200 0x02
svlach 0:70c3bea805ee 273 // PARMSET_57600 0x04
svlach 0:70c3bea805ee 274 // PARMSET_115200 0x06
svlach 0:70c3bea805ee 275 //
svlach 0:70c3bea805ee 276 void SetBaudCOM(int portnum, int new_baud)
svlach 0:70c3bea805ee 277 {
svlach 0:70c3bea805ee 278 // add platform specific code here
svlach 0:70c3bea805ee 279 }
svlach 0:70c3bea805ee 280
svlach 0:70c3bea805ee 281 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 282 // Description:
svlach 0:70c3bea805ee 283 // Delay for at least 'len' ms
svlach 0:70c3bea805ee 284 //
svlach 0:70c3bea805ee 285 void msDelay(int len)
svlach 0:70c3bea805ee 286 {
svlach 0:70c3bea805ee 287 // add platform specific code here
svlach 0:70c3bea805ee 288 wait_ms( len );
svlach 0:70c3bea805ee 289 }
svlach 0:70c3bea805ee 290
svlach 0:70c3bea805ee 291 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 292 // Get the current millisecond tick count. Does not have to represent
svlach 0:70c3bea805ee 293 // an actual time, it just needs to be an incrementing timer.
svlach 0:70c3bea805ee 294 //
svlach 0:70c3bea805ee 295 long msGettick(void)
svlach 0:70c3bea805ee 296 {
svlach 0:70c3bea805ee 297 // add platform specific code here
svlach 0:70c3bea805ee 298 return 0;
svlach 0:70c3bea805ee 299 }
svlach 0:70c3bea805ee 300
svlach 0:70c3bea805ee 301 /*
svlach 0:70c3bea805ee 302 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 303 // This procedure indicates wether the adapter can deliver power.
svlach 0:70c3bea805ee 304 //
svlach 0:70c3bea805ee 305 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 306 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 307 //
svlach 0:70c3bea805ee 308 // Returns: TRUE if adapter is capable of delivering power.
svlach 0:70c3bea805ee 309 //
svlach 0:70c3bea805ee 310 SMALLINT owHasPowerDelivery(int portnum)
svlach 0:70c3bea805ee 311 {
svlach 0:70c3bea805ee 312 // add adapter specific code here
svlach 0:70c3bea805ee 313 return TRUE;
svlach 0:70c3bea805ee 314 }
svlach 0:70c3bea805ee 315
svlach 0:70c3bea805ee 316 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 317 // This procedure indicates wether the adapter can deliver power.
svlach 0:70c3bea805ee 318 //
svlach 0:70c3bea805ee 319 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 320 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 321 //
svlach 0:70c3bea805ee 322 // Returns: TRUE if adapter is capable of over drive.
svlach 0:70c3bea805ee 323 //
svlach 0:70c3bea805ee 324 SMALLINT owHasOverDrive(int portnum)
svlach 0:70c3bea805ee 325 {
svlach 0:70c3bea805ee 326 // add adapter specific code here
svlach 0:70c3bea805ee 327 return TRUE;
svlach 0:70c3bea805ee 328 }
svlach 0:70c3bea805ee 329 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 330 // This procedure creates a fixed 480 microseconds 12 volt pulse
svlach 0:70c3bea805ee 331 // on the 1-Wire Net for programming EPROM iButtons.
svlach 0:70c3bea805ee 332 //
svlach 0:70c3bea805ee 333 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 334 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 335 //
svlach 0:70c3bea805ee 336 // Returns: TRUE program volatage available
svlach 0:70c3bea805ee 337 // FALSE program voltage not available
svlach 0:70c3bea805ee 338 SMALLINT owHasProgramPulse(int portnum)
svlach 0:70c3bea805ee 339 {
svlach 0:70c3bea805ee 340 // add adapter specific code here
svlach 0:70c3bea805ee 341 return TRUE;
svlach 0:70c3bea805ee 342 }
svlach 1:dcf2f8359398 343
svlach 1:dcf2f8359398 344
svlach 0:70c3bea805ee 345 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 346 // Send 8 bits of communication to the 1-Wire Net and verify that the
svlach 0:70c3bea805ee 347 // 8 bits read from the 1-Wire Net is the same (write operation).
svlach 0:70c3bea805ee 348 // The parameter 'sendbyte' least significant 8 bits are used. After the
svlach 0:70c3bea805ee 349 // 8 bits are sent change the level of the 1-Wire net.
svlach 0:70c3bea805ee 350 //
svlach 0:70c3bea805ee 351 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 352 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 353 // 'sendbyte' - 8 bits to send (least significant byte)
svlach 0:70c3bea805ee 354 //
svlach 0:70c3bea805ee 355 // Returns: TRUE: bytes written and echo was the same
svlach 0:70c3bea805ee 356 // FALSE: echo was not the same
svlach 0:70c3bea805ee 357 //
svlach 0:70c3bea805ee 358 SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte)
svlach 0:70c3bea805ee 359 {
svlach 0:70c3bea805ee 360 // replace if platform has better implementation (faster response)
svlach 1:dcf2f8359398 361 if (!owHasPowerDelivery(portnum))
svlach 0:70c3bea805ee 362 return FALSE;
svlach 0:70c3bea805ee 363
svlach 0:70c3bea805ee 364 if(owTouchByte(portnum,sendbyte) != sendbyte)
svlach 0:70c3bea805ee 365 return FALSE;
svlach 0:70c3bea805ee 366
svlach 0:70c3bea805ee 367 if(owLevel(portnum,MODE_STRONG5) != MODE_STRONG5)
svlach 0:70c3bea805ee 368 return FALSE;
svlach 0:70c3bea805ee 369
svlach 0:70c3bea805ee 370 return TRUE;
svlach 0:70c3bea805ee 371 }
svlach 1:dcf2f8359398 372
svlach 1:dcf2f8359398 373
svlach 0:70c3bea805ee 374 //--------------------------------------------------------------------------
svlach 0:70c3bea805ee 375 // Send 1 bit of communication to the 1-Wire Net and verify that the
svlach 0:70c3bea805ee 376 // response matches the 'applyPowerResponse' bit and apply power delivery
svlach 0:70c3bea805ee 377 // to the 1-Wire net. Note that some implementations may apply the power
svlach 0:70c3bea805ee 378 // first and then turn it off if the response is incorrect.
svlach 0:70c3bea805ee 379 //
svlach 0:70c3bea805ee 380 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 381 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 382 // 'applyPowerResponse' - 1 bit response to check, if correct then start
svlach 0:70c3bea805ee 383 // power delivery
svlach 0:70c3bea805ee 384 //
svlach 0:70c3bea805ee 385 // Returns: TRUE: bit written and response correct, strong pullup now on
svlach 0:70c3bea805ee 386 // FALSE: response incorrect
svlach 0:70c3bea805ee 387 //
svlach 0:70c3bea805ee 388 SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse)
svlach 0:70c3bea805ee 389 {
svlach 0:70c3bea805ee 390 // replace if platform has better implementation (faster response)
svlach 1:dcf2f8359398 391 if (!owHasPowerDelivery(portnum))
svlach 0:70c3bea805ee 392 return FALSE;
svlach 0:70c3bea805ee 393
svlach 0:70c3bea805ee 394 if(owTouchBit(portnum,0x01) != applyPowerResponse)
svlach 0:70c3bea805ee 395 return FALSE;
svlach 0:70c3bea805ee 396
svlach 0:70c3bea805ee 397 if(owLevel(portnum,MODE_STRONG5) != MODE_STRONG5)
svlach 0:70c3bea805ee 398 return FALSE;
svlach 0:70c3bea805ee 399
svlach 0:70c3bea805ee 400 return TRUE;
svlach 0:70c3bea805ee 401 }
svlach 1:dcf2f8359398 402
svlach 1:dcf2f8359398 403 */