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 // owSesU.C - Acquire and release a Session on the 1-Wire Net.
svlach 0:70c3bea805ee 28 //
svlach 0:70c3bea805ee 29 // Version: 2.01
svlach 0:70c3bea805ee 30 //
svlach 0:70c3bea805ee 31 // History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
svlach 0:70c3bea805ee 32 // multiple ports.
svlach 0:70c3bea805ee 33 // 2.00 -> 2.01 Added error handling. Added circular-include check.
svlach 0:70c3bea805ee 34 // 2.01 -> 2.10 Added raw memory error handling and SMALLINT
svlach 0:70c3bea805ee 35 // 2.10 -> 3.00 Added memory bank functionality
svlach 0:70c3bea805ee 36 // Added file I/O operations
svlach 0:70c3bea805ee 37 //
svlach 0:70c3bea805ee 38
svlach 0:70c3bea805ee 39 #include "mbed.h"
svlach 1:dcf2f8359398 40 #include "ownet.h"
svlach 0:70c3bea805ee 41 #include "./Headers/ds2480.h"
svlach 0:70c3bea805ee 42
svlach 0:70c3bea805ee 43 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 44 // Attempt to acquire a 1-Wire net using a com port and a DS2480 based
svlach 0:70c3bea805ee 45 // adapter.
svlach 0:70c3bea805ee 46 //
svlach 0:70c3bea805ee 47 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 48 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 49 // 'port_zstr' - zero terminated port name. For this platform
svlach 0:70c3bea805ee 50 // use format COMX where X is the port number.
svlach 0:70c3bea805ee 51 //
svlach 0:70c3bea805ee 52 // Returns: TRUE - success, COM port opened
svlach 0:70c3bea805ee 53 //
svlach 0:70c3bea805ee 54 // exportable functions defined in ownetu.c
svlach 0:70c3bea805ee 55 SMALLINT owAcquire(int portnum, char *port_zstr)
svlach 0:70c3bea805ee 56 {
svlach 0:70c3bea805ee 57 // attempt to open the communications port
svlach 0:70c3bea805ee 58 if (OpenCOM(portnum,port_zstr) < 0)
svlach 0:70c3bea805ee 59 {
svlach 0:70c3bea805ee 60 OWERROR(OWERROR_OPENCOM_FAILED);
svlach 0:70c3bea805ee 61 return FALSE;
svlach 0:70c3bea805ee 62 }
svlach 0:70c3bea805ee 63
svlach 0:70c3bea805ee 64 // detect DS2480
svlach 0:70c3bea805ee 65 if (!DS2480Detect(portnum))
svlach 0:70c3bea805ee 66 {
svlach 0:70c3bea805ee 67 CloseCOM(portnum);
svlach 0:70c3bea805ee 68 OWERROR(OWERROR_DS2480_NOT_DETECTED);
svlach 0:70c3bea805ee 69 return FALSE;
svlach 0:70c3bea805ee 70 }
svlach 0:70c3bea805ee 71
svlach 0:70c3bea805ee 72 return TRUE;
svlach 0:70c3bea805ee 73 }
svlach 0:70c3bea805ee 74
svlach 0:70c3bea805ee 75 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 76 // Attempt to acquire a 1-Wire net using a com port and a DS2480 based
svlach 0:70c3bea805ee 77 // adapter.
svlach 0:70c3bea805ee 78 //
svlach 0:70c3bea805ee 79 // 'port_zstr' - zero terminated 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 // Returns: valid handle, or -1 if an error occurred
svlach 0:70c3bea805ee 83 //
svlach 0:70c3bea805ee 84 // exportable functions defined in ownetu.c
svlach 0:70c3bea805ee 85 //
svlach 0:70c3bea805ee 86 int owAcquireEx(char *port_zstr)
svlach 0:70c3bea805ee 87 {
svlach 0:70c3bea805ee 88 int portnum;
svlach 0:70c3bea805ee 89
svlach 0:70c3bea805ee 90 // attempt to open the communications port
svlach 0:70c3bea805ee 91 if ((portnum = OpenCOMEx(port_zstr)) < 0)
svlach 0:70c3bea805ee 92 {
svlach 0:70c3bea805ee 93 OWERROR(OWERROR_OPENCOM_FAILED);
svlach 0:70c3bea805ee 94 return -1;
svlach 0:70c3bea805ee 95 }
svlach 0:70c3bea805ee 96
svlach 0:70c3bea805ee 97 // detect DS2480
svlach 0:70c3bea805ee 98 if (!DS2480Detect(portnum))
svlach 0:70c3bea805ee 99 {
svlach 0:70c3bea805ee 100 CloseCOM(portnum);
svlach 0:70c3bea805ee 101 OWERROR(OWERROR_DS2480_NOT_DETECTED);
svlach 0:70c3bea805ee 102 return -1;
svlach 0:70c3bea805ee 103 }
svlach 0:70c3bea805ee 104
svlach 0:70c3bea805ee 105 return portnum;
svlach 0:70c3bea805ee 106 }
svlach 0:70c3bea805ee 107
svlach 0:70c3bea805ee 108 //---------------------------------------------------------------------------
svlach 0:70c3bea805ee 109 // Release the previously acquired a 1-Wire net.
svlach 0:70c3bea805ee 110 //
svlach 0:70c3bea805ee 111 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
svlach 0:70c3bea805ee 112 // OpenCOM to indicate the port number.
svlach 0:70c3bea805ee 113 //
svlach 0:70c3bea805ee 114 void owRelease(int portnum)
svlach 0:70c3bea805ee 115 {
svlach 0:70c3bea805ee 116 CloseCOM(portnum);
svlach 0:70c3bea805ee 117 }