OpenCores
URL https://opencores.org/ocsvn/sockit_owm/sockit_owm/trunk

Subversion Repositories sockit_owm

[/] [sockit_owm/] [trunk/] [HAL/] [src/] [owses.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 iztok
//---------------------------------------------------------------------------
2
// Copyright (C) 1999 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
//  todoses.C - Acquire and release a Session Todo for general 1-Wire Net
28
//              library
29
//
30
//  Version: 2.00
31
//           1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for
32
//                         multiple ports.
33
//
34
 
35
#include "ownet.h"
36
#include "sockit_owm.h"
37
 
38
extern sockit_owm_state sockit_owm;
39
 
40
// local function prototypes
41
SMALLINT owAcquire(int,char *);
42
void     owRelease(int);
43
 
44
//---------------------------------------------------------------------------
45
// Attempt to acquire a 1-Wire net
46
//
47
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
48
//                indicate the symbolic port number.
49
// 'port_zstr'  - zero terminated port name.
50
//
51
// Returns: TRUE - success, port opened
52
//
53
// The current implementation does not wait for a port to be freed,
54
// it returns FALSE.
55
//
56
SMALLINT owAcquire(int portnum, char *port_zstr)
57
{
58
   // check if there are enough ports available
59
   if (sockit_owm.own <= portnum) {
60
      // TODO some error message might be added
61
      return FALSE;
62
   }
63
   // check if port is already in use
64
   if ((sockit_owm.use >> portnum) & 0x1) {
65
      return FALSE;
66
   }
67
   // if it is unused take it
68
   else {
69
      sockit_owm.use |= (0x1 << portnum);
70
      return TRUE;
71
   }
72
}
73
 
74
//---------------------------------------------------------------------------
75
// Release the previously acquired a 1-Wire net.
76
//
77
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
78
//                indicate the symbolic port number.
79
//
80
void owRelease(int portnum)
81
{
82
   // check if port is already in use and release it
83
   if ((sockit_owm.use >> portnum) & 0x1) {
84
      sockit_owm.use &= ~(0x1 << portnum);
85
   }
86
   // releasing an unused port is not supported
87
   else {
88
      // TODO some error message might be added
89
   }
90
}
91
 
92
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.