Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
sensor-common.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
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
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. 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
* 3. Neither the name of the copyright holder nor the names of its
14
* contributors may be used to endorse or promote products derived
15
* from this software without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
* OF THE POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*---------------------------------------------------------------------------*/
31
/**
32
* \addtogroup sensortag-cc26xx-sensor-common
33
* @{
34
*
35
* \file
36
* Utilities common among SensorTag sensors
37
*/
38
/*---------------------------------------------------------------------------*/
39
#include "
sensor-common.h
"
40
#include "
board-i2c.h
"
41
/*---------------------------------------------------------------------------*/
42
/* Data to use when an error occurs */
43
#define ERROR_DATA 0xCC
44
/*---------------------------------------------------------------------------*/
45
static
uint8_t buffer[32];
46
/*---------------------------------------------------------------------------*/
47
bool
48
sensor_common_read_reg
(uint8_t
addr
, uint8_t *buf, uint8_t len)
49
{
50
return
board_i2c_write_read
(&
addr
, 1, buf, len);
51
}
52
/*---------------------------------------------------------------------------*/
53
bool
54
sensor_common_write_reg
(uint8_t
addr
, uint8_t *buf, uint8_t len)
55
{
56
uint8_t i;
57
uint8_t *p = buffer;
58
59
/* Copy address and data to local buffer for burst write */
60
*p++ =
addr
;
61
for
(i = 0; i < len; i++) {
62
*p++ = *buf++;
63
}
64
len++;
65
66
/* Send data */
67
return
board_i2c_write
(buffer, len);
68
}
69
/*---------------------------------------------------------------------------*/
70
void
71
sensor_common_set_error_data
(uint8_t *buf, uint8_t len)
72
{
73
while
(len > 0) {
74
len--;
75
buf[len] = ERROR_DATA;
76
}
77
}
78
/*---------------------------------------------------------------------------*/
79
/** @} */
board-i2c.h
Header file for the Sensortag I2C Driver.
board_i2c_write
bool board_i2c_write(uint8_t *data, uint8_t len)
Burst write to an I2C device.
Definition
board-i2c.c:145
board_i2c_write_read
bool board_i2c_write_read(uint8_t *wdata, uint8_t wlen, uint8_t *rdata, uint8_t rlen)
Write and read in one operation.
Definition
board-i2c.c:247
sensor_common_set_error_data
void sensor_common_set_error_data(uint8_t *buf, uint8_t len)
Fill a result buffer with dummy error data.
Definition
sensor-common.c:71
sensor_common_read_reg
bool sensor_common_read_reg(uint8_t addr, uint8_t *buf, uint8_t len)
Reads a sensor's register over I2C.
Definition
sensor-common.c:48
sensor_common_write_reg
bool sensor_common_write_reg(uint8_t addr, uint8_t *buf, uint8_t len)
Write to a sensor's register over I2C.
Definition
sensor-common.c:54
sensor-common.h
Header file for the Sensortag Common sensor utilities.
addr
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition
uip-nd6.c:107
arch
platform
cc26x0-cc13x0
sensortag
sensor-common.c
Generated on
for Contiki-NG by
1.17.0