BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
hh10d.h
Go to the documentation of this file.
1 /* Copyright 2014, 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 
32 #ifndef BSP430_SENSORS_HH10D_H
33 #define BSP430_SENSORS_HH10D_H
34 
61 #include <bsp430/serial.h>
62 #include <bsp430/periph/timer.h>
63 
66 #define BSP430_SENSORS_HH10D_I2C_ADDRESS 0x51
67 
70 #define BSP430_SENSORS_HH10D_FLAG_VALID_CAPTURE 0x01
71 
74 #define BSP430_SENSORS_HH10D_FLAG_VALID_COUNT 0x02
75 
79 #define BSP430_SENSORS_HH10D_FLAG_WAKE_ON_COUNT 0x04
80 
85 #define BSP430_SENSORS_HH10D_FLAG_AUTOSAMPLE 0x08
86 
88 typedef struct sBSP430sensorsHH10Dstate {
93 
96  unsigned int cal_offs;
97 
100  unsigned int cal_sens;
101 
104 
109  unsigned int interval_tck;
110 
113  unsigned int last_capture;
114 
118  unsigned int last_period_count;
119 
121  unsigned int flags;
123 
126 
142  void *context,
143  int idx);
144 
166 
180 static BSP430_CORE_INLINE
182  unsigned int interval_s)
183 {
184  unsigned long ul;
185 
186  if (! hh10d) {
187  return -1;
188  }
189  if (! (BSP430_SENSORS_HH10D_FLAG_VALID_COUNT & hh10d->flags)) {
190  return -1;
191  }
192  ul = hh10d->last_period_count / interval_s;
193  ul = hh10d->cal_offs - ul;
194  ul *= 10UL * hh10d->cal_sens;
195  return (unsigned int) (ul / 4096);
196 }
197 
198 #endif /* BSP430_SENSORS_HH10D_H */
unsigned int flags
Definition: hh10d.h:121
unsigned int last_capture
Definition: hh10d.h:113
struct sBSP430sensorsHH10Dstate sBSP430sensorsHH10Dstate
sBSP430halISRIndexedChainNode cb
Definition: hh10d.h:92
int iBSP430sensorsHH10DgetCalibration(hBSP430halSERIAL i2c, hBSP430sensorsHH10Dstate hh10d)
#define BSP430_SENSORS_HH10D_FLAG_VALID_COUNT
Definition: hh10d.h:74
Definition: timer.h:993
static BSP430_CORE_INLINE int iBSP430sensorsHH10Dconvert_ppth_ni(hBSP430sensorsHH10Dstate hh10d, unsigned int interval_s)
Definition: hh10d.h:181
Definition: serial_.h:193
unsigned int interval_tck
Definition: hh10d.h:109
Hardware presentation/abstraction for generic timers (Timer_A/Timer_B)
#define BSP430_CORE_INLINE
Definition: core.h:439
Declarations for abstracted serial interface.
Definition: periph.h:437
Definition: hh10d.h:88
unsigned int cal_sens
Definition: hh10d.h:100
unsigned int cal_offs
Definition: hh10d.h:96
int iBSP430sensorsHH10DperiodicCallback_ni(const struct sBSP430halISRIndexedChainNode *cb, void *context, int idx)
sBSP430sensorsHH10Dstate * hBSP430sensorsHH10Dstate
Definition: hh10d.h:125
unsigned int last_period_count
Definition: hh10d.h:118
volatile sBSP430hplTIMER * freq_timer
Definition: hh10d.h:103