BSPACM  20150113
Board Support Package for ARM Cortex-M Microcontrollers
onewire.h
Go to the documentation of this file.
1 /* Copyright 2012-2015, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
44 #ifndef BSPACM_UTILITY_ONEWIRE_H
45 #define BSPACM_UTILITY_ONEWIRE_H
46 
47 #include <bspacm/core.h>
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif /* __cplusplus */
52 
53 /* Forward declaration. Definition found in device-specific header
54  * included below. */
55 struct sBSPACMonewireBus;
56 
62 typedef const struct sBSPACMonewireBus * hBSPACMonewireBus;
63 
67  uint8_t id[6];
69 
72 enum {
75 
78 
81 
84 
87 
90 
93 
96 
99 };
100 
101 enum {
104 
107 
111 
114 
117 
128 };
129 
142 int iBSPACMonewireReset (hBSPACMonewireBus bus);
143 
153 void vBSPACMonewireShutdown (hBSPACMonewireBus bus);
154 
169 void
170 vBSPACMonewireParasitePower (hBSPACMonewireBus bus,
171  bool powered);
172 
179 void vBSPACMonewireWriteByte (hBSPACMonewireBus bus,
180  uint8_t byte);
181 
187 int iBSPACMonewireReadBit (hBSPACMonewireBus bus);
188 
197 int iBSPACMonewireReadByte (hBSPACMonewireBus bus);
198 
209 int iBSPACMonewireComputeCRC (const unsigned char * data, int len);
210 
219 int iBSPACMonewireReadSerialNumber (hBSPACMonewireBus bus,
221 
229 int iBSPACMonewireReadPowerSupply (hBSPACMonewireBus bus);
230 
249 int iBSPACMonewireRequestTemperature (hBSPACMonewireBus bus);
250 
259 static BSPACM_CORE_INLINE
260 int
261 iBSPACMonewireTemperatureReady (hBSPACMonewireBus bus)
262 {
263  return iBSPACMonewireReadBit(bus);
264 }
265 
282 int iBSPACMonewireReadTemperature (hBSPACMonewireBus bus,
283  int16_t * temp_xCel);
284 
292 #define BSPACM_ONEWIRE_xCel_TO_dCel(xcel_) ((10 * (xcel_)) / 16)
293 
300 #define BSPACM_ONEWIRE_xCel_TO_ddegF(xcel_) (320 + ((9 * (xcel_)) / 8))
301 
313 #define BSPACM_ONEWIRE_xCel_TO_dK(xcel_) ((unsigned int)(21852U + 5U * (xcel_)) / 8U)
314 
315 /* Include the device-specific header which defines struct
316  * sBSPACMonewireBus and provides hBSPACMonewireConfigureBus(). */
317 #include <bspacm/utility/onewire_.h>
318 
319 #ifdef __cplusplus
320 }
321 #endif /* __cplusplus */
322 
323 #endif /* BSPACM_UTILITY_ONEWIRE_H */
Definition: onewire.h:106
Definition: onewire.h:95
void vBSPACMonewireShutdown(hBSPACMonewireBus bus)
Definition: onewire_.h:50
void vBSPACMonewireParasitePower(hBSPACMonewireBus bus, bool powered)
Definition: onewire.h:116
static BSPACM_CORE_INLINE int iBSPACMonewireTemperatureReady(hBSPACMonewireBus bus)
Definition: onewire.h:261
struct sBSPACMonewireSerialNumber sBSPACMonewireSerialNumber
Common header included by all BSPACM leaf headers.
Definition: onewire.h:80
Definition: onewire.h:98
Implementation-specific support for onewire bus configurations on boards in the Nordic Semiconductor ...
int iBSPACMonewireReadTemperature(hBSPACMonewireBus bus, int16_t *temp_xCel)
const struct sBSPACMonewireBus * hBSPACMonewireBus
Definition: onewire.h:62
Definition: onewire.h:92
int iBSPACMonewireReadByte(hBSPACMonewireBus bus)
Definition: onewire.h:65
void vBSPACMonewireWriteByte(hBSPACMonewireBus bus, uint8_t byte)
int iBSPACMonewireReset(hBSPACMonewireBus bus)
Definition: onewire.h:86
Definition: onewire.h:127
int iBSPACMonewireRequestTemperature(hBSPACMonewireBus bus)
Definition: onewire.h:103
int iBSPACMonewireReadPowerSupply(hBSPACMonewireBus bus)
#define BSPACM_CORE_INLINE
Definition: core.h:65
Definition: onewire.h:74
Definition: onewire.h:83
Definition: onewire.h:77
Definition: onewire.h:89
Definition: onewire.h:113
int iBSPACMonewireReadBit(hBSPACMonewireBus bus)
int iBSPACMonewireReadSerialNumber(hBSPACMonewireBus bus, sBSPACMonewireSerialNumber *snp)
Definition: onewire.h:110
int iBSPACMonewireComputeCRC(const unsigned char *data, int len)