sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
onewire.h
Go to the documentation of this file.
1 #ifndef ONEWIRE_H
2 #define ONEWIRE_H
3 
4 /*
5  * Copyright © 2010-2015, Matthias Urlichs <matthias@urlichs.de>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License (included; see the file LICENSE)
16  * for more details.
17  */
18 
19 #include <stdint.h>
20 #include "features.h"
21 
22 #ifdef HAVE_ONEWIRE
23 /* return to idle state, i.e. wait for the next RESET pulse. */
24 void set_idle(void);
25 
26 /* aborts and return to idle state */
27 #ifdef ONE_WIRE_DEBUG
28 void next_idle(char reason) __attribute__((noreturn));
29 #else
30 #define next_idle(x) _next_idle()
31 void _next_idle(void) __attribute__((noreturn));
32 #endif
33 
34 /* send something. Will return as soon as transmission is active. */
35 void xmit_bit(uint8_t bit);
36 void xmit_byte(uint8_t bit);
37 uint16_t xmit_byte_crc(uint16_t crc, uint8_t val);
38 uint16_t xmit_bytes_crc(uint16_t crc, uint8_t *buf, uint8_t len);
39 
40 /* receive something. For concurrency, you need to declare your intention
41  to receive as soon as possible. Then call recv_bit() or recv_byte()
42  when you really need the data. */
43 void recv_bit(void);
44 void recv_byte(void);
45 uint16_t recv_bytes_crc(uint16_t crc, uint8_t *buf, uint8_t len);
46 
47 uint8_t recv_any_in(void); // don't call directly
48 static inline uint8_t recv_bit_in(void)
49 {
50  uint8_t byte;
51  byte = ((recv_any_in() & 0x80) != 0);
52  // DBG_X(byte);
53  return byte;
54 }
55 static inline uint8_t recv_byte_in(void)
56 {
57  uint8_t byte;
58  byte = recv_any_in();
59  // DBG_X(byte);
60  return byte;
61 }
62 
63 /* If you want to do background work, check whether the next unit can be
64  received by calling rx_ready() */
65 uint8_t rx_ready(void);
66 
67 void next_command(void) __attribute__((noreturn));
68 
69 /* Set up onewire-specific hardware */
70 void onewire_init(void);
71 
72 /* Poll the bus. Will not return while a transaction is in progress. */
73 void onewire_poll(void);
74 
75 #else /* !HAVE_ONEWIRE */
76 #define onewire_init() do {} while(0)
77 #define onewire_poll() do {} while(0)
78 
79 #endif
80 
81 #endif // onewire.h
void set_idle(void)
Definition: onewire.c:369
#define onewire_init()
Definition: onewire.h:76
uint8_t byte
Definition: Arduino.h:123
tuple buf
Definition: DeviceGeneric.py:119
void _next_idle(void)
Definition: onewire.c:77
uint16_t xmit_byte_crc(uint16_t crc, uint8_t val)
uint16_t recv_bytes_crc(uint16_t crc, uint8_t *buf, uint8_t len)
Definition: onewire.c:220
#define noreturn
Definition: stdnoreturn.h:27
char __v64qi __attribute__((__vector_size__(64)))
Definition: avx512bwintrin.h:33
void next_command(void)
Definition: onewire.c:90
uint8_t recv_any_in(void)
Definition: onewire.c:194
#define onewire_poll()
Definition: onewire.h:77
void xmit_byte(uint8_t val)
Definition: onewire.c:155
uint16_t xmit_bytes_crc(uint16_t crc, uint8_t *buf, uint8_t len)
void recv_byte(void)
Definition: onewire.c:215