µracoli Manual Version foo

- µracoli
- User Guide
- Reference Guide

trxvtg.h
1 /* Copyright (c) 2013 - 2014 Axel Wachtler
2 All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the authors nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE. */
28
29 #ifndef TRXVTG_H
30 #define TRXVTG_H
31
40 /* === includes ============================================================ */
41 #include "sensor_defs.h"
42 #include "transceiver.h"
43
44
45 /* === macros ============================================================== */
46 #define TRXVTG_DEBUG (0)
47 #if TRXVTG_DEBUG == 1
48 # include "hif.h"
49 # define DBG_TRXVTG(...) PRINTF(__VA_ARGS__)
50 #else
51 # define DBG_TRXVTG(...)
52 #endif
53
54 /* === types =============================================================== */
55 typedef struct
56 {
57 sensor_driver_t g;
58 } trxvtg_ctx_t;
59
60 /* === prototypes ========================================================== */
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 /* === low level functions ================================================== */
65
66 /* === high level sensor functions ========================================= */
67
68 static inline void trxvtg_trigger(void *pctx, bool one_shot)
69 {
70 }
71
72 static inline uint8_t trxvtg_get_val(void *pctx, uint8_t *pdata)
73 {
74 sensor_voltage_t *p = (sensor_voltage_t*)pdata;
75 if (p)
76 {
77 uint8_t bmok, bm;
78 /* this we could do more clever with a tree search */
79 for(bm = 0; bm < 32; bm++)
80 {
81 if (bm == 0)
82 {
83 trx_bit_write(SR_BATMON_HR, 0);
84 }
85 if (bm == 16)
86 {
87 trx_bit_write(SR_BATMON_HR, 1);
88 }
89 trx_bit_write(SR_BATMON_VTH, bm & 0xf);
90 bmok = trx_bit_read(SR_BATMON_OK);
91 DBG_TRXVTG("bm=%x bmok=%d\n\r", bm, bmok);
92 if (bmok == 0)
93 {
94 break;
95 }
96 }
97
98 p->type = SENSOR_DATA_VOLTAGE;
99 p->sensor = SENSOR_TRXVTG;
100 if (bm > 15)
101 {
102 p->voltage = 2.555 + 0.075 * (bm & 0xf);
103 }
104 else
105 {
106 p->voltage = 1.7 + 0.05 * (bm & 0xf);
107 }
108 }
109 return sizeof(sensor_voltage_t);
110 }
111
112 #if 0
113 static inline uint8_t trxvtg_get_raw(void *pctx, uint8_t *pdata)
114 {
115 return 0;
116 }
117 #endif
118
119 static inline void trxvtg_sleep(void *pctx)
120 {
121 }
122
129 static inline uint8_t sensor_create_trxvtg(void *pdata)
130 {
131 uint8_t rv = sizeof(trxvtg_ctx_t);
132 trxvtg_ctx_t *pcfg;
133
134 if (pdata != NULL)
135 {
136 /* init generic sensor data */
137 pcfg = (trxvtg_ctx_t *)pdata;
138 pcfg->g.id = SENSOR_TRXVTG;
139 pcfg->g.f_trigger = trxvtg_trigger;
140 pcfg->g.f_get_val = trxvtg_get_val;
141 pcfg->g.f_sleep = NULL;
142
143 /* init private sensor data */
144
145 /* initialize sensor hardware */
146
147 }
148 return rv;
149 }
150
151 #ifdef __cplusplus
152 } /* extern "C" */
153 #endif
154
155 #endif /* #ifndef TRXVTG_H */
sensor_voltage_t
Definition: sensor_defs.h:95
trx_bit_write
void trx_bit_write(trx_regaddr_t addr, trx_regval_t mask, uint8_t pos, trx_regval_t value)
subregister write
sensor_create_trxvtg
static uint8_t sensor_create_trxvtg(void *pdata)
Definition: trxvtg.h:129
sensor_driver_t
Definition: sensor_defs.h:59
trx_bit_read
trx_regval_t trx_bit_read(trx_regaddr_t addr, trx_regval_t mask, uint8_t pos)
subregister read