xref: /freebsd/share/man/man9/own.9 (revision cc68614da8232d8baaca0ae0d0dd8f890f06623e)
1.\"
2.\" Copyright (c) 2015 M. Warner Losh <imp@FreeBSD.org>
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. The name of the author may not be used to endorse or promote products
10.\"    derived from this software without specific prior written permission.
11.\"
12.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22.\" SUCH DAMAGE.
23.\"
24.\" $FreeBSD$
25.\"
26.Dd July 20, 2015
27.Dt OWN 9
28.Os
29.Sh NAME
30.Nm own ,
31.Nm own_send_command ,
32.Nm own_commmand_wait ,
33.Nm own_self_command ,
34.Nm own_acquire_bus ,
35.Nm own crc ,
36.Nm own_release_bus ,
37.Nm OWN_ACQUIRE_BUS ,
38.Nm OWN_CRC ,
39.Nm OWN_RELEASE_BUS ,
40.Nm OWN_SEND_COMMAND
41.Nd Dallas Semiconductor 1-Wire Network and Transport Interface
42.Sh SYNOPSIS
43.In sys/bus.h
44.In dev/ow/own.h
45.Ft int
46.Fn own_send_command "device_t pdev" "struct ow_cmd *cmd"
47.Ft int
48.Fn own_command_wait "device_t pdev" "struct ow_cmd *cmd"
49.Ft int
50.Fn own_self_command "device_t pdev" "struct ow_cmd *cmd" "uint8_t xpt_cmd"
51.Ft int
52.Fn own_acquire_bus "device_t pdev" "int how"
53.Ft int
54.Fn own_release_bus "device_t pdev"
55.Ft int
56.Fn own_crc "device_t pdev" "uint8_t *buffer" "size_t len"
57.Ft int
58.Fn OWN_SEND_COMMAND "device_t ndev" "device_t pdev" "struct ow_cmd *cmd"
59.Ft int
60.Fn OWN_ACQUIRE_BUS "device_t ndev" "device_t pdev" "int how"
61.Ft void
62.Fn OWN_RELEASE_BUS "device_t ndev" "device_t pdev"
63.Ft uint8_t
64.Fn OWN_CRC "device_t ndev" "device_t pdev" "uint8_t *buffer" "size_t len"
65.Sh DESCRIPTION
66The
67.Nm
68interface defines three sets of functions for interacting with 1-Wire
69devices:
70sending commands,
71reserving the bus,
72and
73ensuring data integrity.
74Wrappers are provided for the raw
75.Nm OWN
76.Xr kobj 9
77interfaces and should be used for improved safety over the
78.Xr kobj 9
79ones.
80.Ss Bus Commands
81The 1-Wire bus defines different layers of access to the devices on
82the bus.
83The
84.Nm
85functions provide access to the network and transport layers.
86The network layer designates the next command as being either for all
87devices on the bus, or for a specific device.
88The network layer also specifies the speed used by the link layer.
89.Pp
90.Vt "struct ow_cmd"
91encapsulates network access, speed, and timing information.
92It specifies the commands to send and whether or not to read data.
93Its members are:
94.Bl -tag -width ".Va xxxx"
95.It Va flags
96Flags controlling the interpretation of the structure.
97These flags are defined in
98.In dev/ow/ow.h :
99.Bl -tag -width indent
100.It OW_FLAG_OVERDRIVE
101Send
102.Va xpt_cmd
103bytes and read
104.Va xpt_read
105bytes at overdrive speed.
106.It OW_FLAG_READ_BIT
107Interpret
108.Va xpt_read_len
109to be in bits to be read after
110.Va xpt_cmd
111rather than bytes.
112.El
113.It Va rom_cmd
114ROM command bytes to send.
115.It Va rom_len
116Number of ROM command bytes to send.
117.It Va rom_read_len
118Number of bytes to read after sending the ROM command.
119.It Va rom_read
120Buffer for bytes read after the ROM command.
121.It Va xpt_cmd
122Transport command to send.
123.It Va xpt_len
124Length of the transport command bytes to send.
125Specify 0 for no transport command.
126.It Va xpt_read_len
127Number of bytes to read after
128.Va xpt_cmd
129bytes are sent.
130If the
131.Dv OW_FLAG_READ_BIT
132bit is set in
133.Va flags ,
134then it is the number of bits to read.
135Bits read are packed into bytes.
136.It Va xpt_read
137Buffer for data read.
138.El
139.Pp
140.Fn own_command_wait
141acquires the 1-Wire bus, waiting if necessary,
142sends the command,
143and
144then releases the bus.
145.Fn own_send_command
146sends the command without bus reservation.
147.Fa pdev
148is the client device (the presentation layer device) sending the command.
149The
150.Fa cmd
151argument describes the transaction to send to the 1-Wire bus.
152.Pp
153.Fn own_self_command
154fills in
155.Fa cmd
156with a MATCH_ROM ROM command, the ROM address of
157.Fa pdev
158and the
159.Fa xpt_cmd
160as a convenient way to create directed commands.
161.Ss Bus Reservation
162The 1-Wire system includes an advisory lock for the bus that
163presentation layer devices can use to coordinate access.
164Locking is purely advisory at this time.
165.Pp
166.Fn own_acquire_bus
167reserves the bus.
168It waits indefinitely if the
169.Fa how
170argument is
171.Dv OWN_WAIT
172and returns the error
173.Dv EWOULDBLOCK
174if passed
175.Dv OWN_DONTWAIT
176when the bus is owned by another client.
177.Pp
178.Fn own_release_bus
179releases the bus.
180.Ss Data Integrity
181.Fn own_crc
182computes the 1-Wire standard CRC function over the data
183passed in
184.Fa buffer
185and
186.Fa len
187and returns the result.
188.Ss Notes
189The 1-Wire standard (Maxim AN937) defines layers that are akin to ISO
190networking layers.
191The lowest relevant layer, the link layer, defines the polling windows
192and the timing of the signaling of different modes.
193The network layer is built on top of the link layer
194and is used to address devices in a unicast or multicast manner.
195The transport layer defines commands and responses from the devices.
196The presentation layer is composed of the device specific commands and
197actions used to control the specific 1-Wire devices on bus.
198.Pp
199These interfaces are implemented by the
200.Xr ow 4
201device.
202Presentation layer devices (children of the newbus
203.Xr ow 4
204device) should only call the functions described here.
205The functionality provided by the
206.Xr owc 4
207device (specifically the
208.Xr owll 9
209interface) should only be called by the
210.Xr ow 4
211driver.
212.Sh SEE ALSO
213.Xr ow 4 ,
214.Xr owc 4 ,
215.Xr owll 9
216.Pa  https://pdfserv.maximintegrated.com/en/an/AN937.pdf
217.Sh LEGAL
218.Tn 1-Wire
219is a registered trademark of Maxim Integrated Products, Inc.
220.Sh HISTORY
221The
222.Nm
223driver first appeared in
224.Fx 11.0 .
225.Sh AUTHORS
226The
227.Nm
228device driver and this manual page were written by
229.An Warner Losh .
230