onewirevar.h revision 1.5
1/* $OpenBSD: onewirevar.h,v 1.5 2008/04/07 22:50:41 miod 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#ifndef _DEV_ONEWIRE_ONEWIREVAR_H_ 20#define _DEV_ONEWIRE_ONEWIREVAR_H_ 21 22/* 23 * 1-Wire bus interface. 24 */ 25 26/* Bus master interface */ 27struct onewire_bus { 28 void * bus_cookie; 29 30 int (*bus_reset)(void *); 31 int (*bus_bit)(void *, int); 32 int (*bus_read_byte)(void *); 33 void (*bus_write_byte)(void *, int); 34 void (*bus_read_block)(void *, void *, int); 35 void (*bus_write_block)(void *, const void *, int); 36 int (*bus_triplet)(void *, int); 37 void (*bus_matchrom)(void *, u_int64_t); 38 int (*bus_search)(void *, u_int64_t *, int, u_int64_t); 39}; 40 41/* Bus methods */ 42int onewire_lock(void *, int); 43void onewire_unlock(void *); 44 45int onewire_reset(void *); 46int onewire_bit(void *, int); 47int onewire_read_byte(void *); 48void onewire_write_byte(void *, int); 49void onewire_read_block(void *, void *, int); 50void onewire_write_block(void *, const void *, int); 51int onewire_triplet(void *, int); 52void onewire_matchrom(void *, u_int64_t); 53int onewire_search(void *, u_int64_t *, int, u_int64_t); 54 55#define ONEWIRE_NOWAIT 0x0001 56 57/* Bus attachment */ 58struct onewirebus_attach_args { 59 struct onewire_bus * oba_bus; 60 int oba_flags; 61#define ONEWIRE_SCAN_NOW 0x0001 62#define ONEWIRE_NO_PERIODIC_SCAN 0x0002 63}; 64 65int onewirebus_print(void *, const char *); 66 67/* Device attachment */ 68struct onewire_attach_args { 69 void * oa_onewire; 70 u_int64_t oa_rom; 71}; 72 73/* Family matching */ 74struct onewire_matchfam { 75 int om_type; 76}; 77 78/* Miscellaneous routines */ 79int onewire_crc(const void *, int); 80const char * onewire_famname(int); 81int onewire_matchbyfam(struct onewire_attach_args *, 82 const struct onewire_matchfam *, int); 83 84/* Bus bit-banging */ 85struct onewire_bbops { 86 void (*bb_rx)(void *); 87 void (*bb_tx)(void *); 88 int (*bb_get)(void *); 89 void (*bb_set)(void *, int); 90}; 91 92int onewire_bb_reset(const struct onewire_bbops *, void *); 93int onewire_bb_bit(const struct onewire_bbops *, void *, int); 94 95#endif /* !_DEV_ONEWIRE_ONEWIREVAR_H_ */ 96