1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22 // Except as contained in this notice, the name of Dallas Semiconductor
23 // shall not be used except as stated in the Dallas Semiconductor
24 // Branding Policy.
25 //---------------------------------------------------------------------------
26 //
27 //  owSesU.C - Acquire and release a Session on the 1-Wire Net.
28 //
29 //  Version: 2.01
30 //
31 //  History: 1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for
32 //                         multiple ports.
33 //          2.00 -> 2.01 Added error handling. Added circular-include check.
34 //          2.01 -> 2.10 Added raw memory error handling and SMALLINT
35 //          2.10 -> 3.00 Added memory bank functionality
36 //                       Added file I/O operations
37 //
38 
39 #include "ownet.h"
40 
41 // external functions defined in system specific link file
42 extern SMALLINT OpenCOM(int,char *);
43 extern void     CloseCOM(int);
44 
45 // external functions defined in ds248ut.c
46 extern SMALLINT DS2480Detect(int);
47 
48 // exportable functions defined in owsesu.c
49 SMALLINT owAcquire(int,char *);
50 void     owRelease(int);
51 
52 //---------------------------------------------------------------------------
53 // Attempt to acquire a 1-Wire net using a com port and a DS2480 based
54 // adapter.
55 //
56 // 'portnum'    - number 0 to MAX_PORTNUM-1.  This number was provided to
57 //                OpenCOM to indicate the port number.
58 // 'port_zstr'  - zero terminated port name.  For this platform
59 //                use format COMX where X is the port number.
60 //
61 // Returns: TRUE - success, COM port opened
62 //
63 // exportable functions defined in ownetu.c
owAcquire(int portnum,char * port_zstr)64 SMALLINT owAcquire(int portnum, char *port_zstr)
65 {
66    // attempt to open the communications port
67    if (!OpenCOM(portnum,port_zstr))
68    {
69       OWERROR(OWERROR_OPENCOM_FAILED);
70       return FALSE;
71    }
72 
73    // detect DS2480
74    if (!DS2480Detect(portnum))
75    {
76       CloseCOM(portnum);
77       OWERROR(OWERROR_DS2480_NOT_DETECTED);
78       return FALSE;
79    }
80 
81    return TRUE;
82 }
83 
84 //---------------------------------------------------------------------------
85 // Release the previously acquired a 1-Wire net.
86 //
87 // 'portnum'    - number 0 to MAX_PORTNUM-1.  This number was provided to
88 //                OpenCOM to indicate the port number.
89 //
owRelease(int portnum)90 void owRelease(int portnum)
91 {
92    CloseCOM(portnum);
93 }
94