Annotation of sys/dev/onewire/onewire_bitbang.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: onewire_bitbang.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */
2:
3: /*
4: * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: /*
20: * 1-Wire bus bit-banging routines.
21: */
22:
23: #include <sys/param.h>
24: #include <sys/systm.h>
25: #include <sys/device.h>
26:
27: #include <dev/onewire/onewirevar.h>
28:
29: int
30: onewire_bb_reset(const struct onewire_bbops *ops, void *arg)
31: {
32: int s, rv, i;
33:
34: s = splhigh();
35: ops->bb_tx(arg);
36: ops->bb_set(arg, 0);
37: DELAY(480);
38: ops->bb_set(arg, 1);
39: ops->bb_rx(arg);
40: DELAY(30);
41: for (i = 0; i < 6; i++) {
42: if ((rv = ops->bb_get(arg)) == 0)
43: break;
44: DELAY(20);
45: }
46: DELAY(450);
47: splx(s);
48:
49: return (rv);
50: }
51:
52: int
53: onewire_bb_bit(const struct onewire_bbops *ops, void *arg, int value)
54: {
55: int s, rv, i;
56:
57: s = splhigh();
58: ops->bb_tx(arg);
59: ops->bb_set(arg, 0);
60: DELAY(2);
61: if (value) {
62: ops->bb_set(arg, 1);
63: ops->bb_rx(arg);
64: for (i = 0; i < 15; i++) {
65: if ((rv = ops->bb_get(arg)) == 0)
66: break;
67: DELAY(2);
68: }
69: ops->bb_tx(arg);
70: }
71: DELAY(60);
72: ops->bb_set(arg, 1);
73: DELAY(5);
74: splx(s);
75:
76: return (rv);
77: }
CVSweb