ISSDK  1.7
IoT Sensing Software Development Kit
diff_p_drv.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /**
36  * @file diff_p_drv.h
37  * @brief The diff_p_drv.h file describes the DIFF_P driver interface and structures.
38  */
39 
40 #ifndef DIFF_P_FI_H_
41 #define DIFF_P_FI_H_
42 
43 /* Standard C Includes */
44 #include <stdint.h>
45 
46 /* ISSDK Includes */
47 #include "diff_p.h"
48 #include "sensor_io_i2c.h"
49 #include "sensor_io_spi.h"
50 #include "register_io_i2c.h"
51 #include "register_io_spi.h"
52 
53 /*******************************************************************************
54  * Definitions
55  ******************************************************************************/
56 /*!
57  * @brief This defines the sensor specific information for SPI.
58  */
59 typedef struct
60 {
61  registerDeviceInfo_t deviceInfo; /*!< SPI device context. */
62  ARM_DRIVER_SPI *pCommDrv; /*!< Pointer to the spi driver. */
63  bool isInitialized; /*!< Whether sensor is intialized or not.*/
64  spiSlaveSpecificParams_t slaveParams; /*!< Slave Specific Params.*/
66 
67 /*!
68  * @brief This defines the sensor specific information for I2C.
69  */
70 typedef struct
71 {
72  registerDeviceInfo_t deviceInfo; /*!< I2C device context. */
73  ARM_DRIVER_I2C *pCommDrv; /*!< Pointer to the i2c driver. */
74  bool isInitialized; /*!< whether sensor is intialized or not.*/
75  uint16_t slaveAddress; /*!< slave address.*/
77 
78 /*! @brief This structure defines the diff_p data buffer in Pressure Mode.*/
79 typedef struct
80 {
81  uint32_t timestamp; /*!< Time stamp value in micro-seconds. */
82  int16_t pressure; /*!< Sensor pressure output: unsigned 16-bits justified to MSBs. */
83  int8_t temperature; /*!< Sensor temperature output; 2's complement 8-bits justified to MSBs. */
85 
86 /*! @def DIFF_P_SPI_MAX_MSG_SIZE
87  * @brief The MAX size of SPI message. */
88 #define DIFF_P_SPI_MAX_MSG_SIZE (64)
89 
90 /*! @def DIFF_P_SPI_CMD_LEN
91  * @brief The size of the Sensor specific SPI Header. */
92 #define DIFF_P_SPI_CMD_LEN (1)
93 
94 /*! @def DIFF_P_SS_ACTIVE_VALUE
95  * @brief Is the Slave Select Pin Active Low or High. */
96 #define DIFF_P_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
97 
98 /*******************************************************************************
99  * APIs
100  ******************************************************************************/
101 /*! @brief The interface function to initialize the sensor.
102  * @details This function initialize the sensor and sensor handle.
103  * @param[in] pSensorHandle handle to the sensor.
104  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
105  * @param[in] index the I2C device number.
106  * @param[in] sAddress slave address of the device on the bus.
107  * @param[in] whoami WHO_AM_I value of the device.
108  * @constraints This should be the first API to be called.
109  * Application has to ensure that previous instances of these APIs have exited before invocation.
110  * @reeentrant No
111  * @return ::DIFF_P_I2C_Initialize() returns the status.
112  */
114  diff_p_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi);
115 
116 /*! @brief : The interface function to set the I2C Idle Task.
117  * @param[in] : diff_p_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
118  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
119  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
120  * @return void.
121  * @constraints This can be called any number of times only after DIFF_P_I2C_Initialize().
122  * Application has to ensure that previous instances of these APIs have exited before invocation.
123  * @reeentrant No
124  */
125 void DIFF_P_I2C_SetIdleTask(diff_p_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam);
126 
127 /*! @brief The interface function to configure he sensor.
128  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
129  * @param[in] pSensorHandle handle to the sensor.
130  * @param[in] pRegWriteList pointer to the register list.
131  * @constraints This can be called any number of times only after DIFF_P_I2C_Initialize().
132  * Application has to ensure that previous instances of these APIs have exited before invocation.
133  * @reeentrant No
134  * @return ::DIFF_P_I2C_Configure() returns the status.
135  */
136 int32_t DIFF_P_I2C_Configure(diff_p_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList);
137 
138 /*! @brief The interface function to read the sensor data.
139  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
140  * @param[in] pSensorHandle handle to the sensor.
141  * @param[in] pReadList pointer to the list of device registers and values to read.
142  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
143  * command read in the list.
144  * @constraints This can be called only after DIFF_P_I2C_Initialize().
145  * Application has to ensure that previous instances of these APIs have exited before invocation.
146  * @reeentrant No
147  * @return ::DIFF_P_I2C_ReadData() returns the status .
148  */
150  const registerreadlist_t *pReadList,
151  uint8_t *pBuffer);
152 
153 /*! @brief The interface function to De Initialize sensor..
154  * @details This function made sensor in a power safe state and de initialize its handle.
155  * @param[in] pSensorHandle handle to the sensor.
156  * @constraints This can be called only after DIFF_P_I2C_Initialize() has been called.
157  * Application has to ensure that previous instances of these APIs have exited before invocation.
158  * @reeentrant No
159  * @return ::DIFF_P_I2C_DeInit() returns the status.
160  */
162 
163 /*! @brief The interface function to initialize the sensor.
164  * @details This function initializes the sensor and sensor handle.
165  * @param[in] pSensorHandle handle to the sensor.
166  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
167  * @param[in] index the I2C device number.
168  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
169  * @param[in] whoami WHO_AM_I value of the device.
170  * @constraints This should be the first API to be called.
171  * Application has to ensure that previous instances of these APIs have exited before invocation.
172  * @reeentrant No
173  * @return ::DIFF_P_SPI_Initialize() returns the status .
174  */
176  diff_p_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t whoAmi);
177 
178 /*! @brief : The interface function to set the SPI Idle Task.
179  * @param[in] : diff_p_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
180  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
181  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
182  * @return void.
183  * @constraints This can be called any number of times only after DIFF_P_SPI_Initialize().
184  * Application has to ensure that previous instances of these APIs have exited before invocation.
185  * @reeentrant No
186  */
187 void DIFF_P_SPI_SetIdleTask(diff_p_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam);
188 
189 /*! @brief The interface function to configure he sensor.
190  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
191  * @param[in] pSensorHandle handle to the sensor.
192  * @param[in] pRegWriteList pointer to the register list.
193  * @constraints This can be called any number of times only after DIFF_P_SPI_Initialize().
194  * Application has to ensure that previous instances of these APIs have exited before invocation.
195  * @reeentrant No
196  * @return ::DIFF_P_SPI_Configure() returns the status .
197  */
198 int32_t DIFF_P_SPI_Configure(diff_p_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList);
199 
200 /*! @brief The interface function to read the sensor data.
201  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
202  * @param[in] pSensorHandle handle to the sensor.
203  * @param[in] pReadList pointer to the list of device registers and values to read.
204  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
205  * command read in the list.
206  * @constraints This can be called any number of times only after DIFF_P_SPI_Initialize().
207  * Application has to ensure that previous instances of these APIs have exited before invocation.
208  * @reeentrant No
209  * @return ::DIFF_P_SPI_ReadData() returns the status .
210  */
212  const registerreadlist_t *pReadList,
213  uint8_t *pBuffer);
214 
215 /*! @brief The interface function to De Initialize sensor..
216  * @details This function made sensor in a power safe state and de initialize its handle.
217  * @param[in] pSensorHandle handle to the sensor.
218  * @constraints This can be called only after after DIFF_P_SPI_Initialize().
219  * Application has to ensure that previous instances of these APIs have exited before invocation.
220  * @reeentrant No
221  * @return ::DIFF_P_SPI_Deinit() returns the status .
222  */
224 
225 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
226  * @details This function prepares the SPI Read Command Header with register address and
227  * R/W bit encoded as the Sensor.
228  * @param[out] pCmdOut handle to the output buffer.
229  * @param[in] offset the address of the register to start reading from.
230  * @param[in] size number of bytes to read.
231  * @constraints None
232  * Application has to ensure that previous instances of these APIs have exited before invocation.
233  * @reeentrant No
234  * @return :: None.
235  */
236 void DIFF_P_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
237 
238 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
239  * @details This function prepares the SPI Write Command Header with register address and
240  * R/W bit encoded as the Sensor.
241  * @param[out] pCmdOut handle to the output buffer.
242  * @param[in] offset the address of the register to start writing from.
243  * @param[in] size number of bytes to write.
244  * @constraints None
245  * Application has to ensure that previous instances of these APIs have exited before invocation.
246  * @reeentrant No
247  * @return :: None.
248  */
249 void DIFF_P_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
250 
251 #endif // DIFF_P_FI_H_
This defines the sensor specific information for I2C.
Definition: diff_p_drv.h:70
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
int32_t DIFF_P_I2C_DeInit(diff_p_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: diff_p_drv.c:444
spiSlaveSpecificParams_t slaveParams
Definition: diff_p_drv.h:64
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
void DIFF_P_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer)
The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
Definition: diff_p_drv.c:73
int32_t DIFF_P_SPI_Initialize(diff_p_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t whoAmi)
The interface function to initialize the sensor.
Definition: diff_p_drv.c:92
int32_t DIFF_P_I2C_ReadData(diff_p_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: diff_p_drv.c:415
registerDeviceInfo_t deviceInfo
Definition: diff_p_drv.h:72
void DIFF_P_I2C_SetIdleTask(diff_p_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: diff_p_drv.c:366
registerDeviceInfo_t deviceInfo
Definition: diff_p_drv.h:61
int32_t DIFF_P_I2C_Configure(diff_p_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: diff_p_drv.c:372
int32_t DIFF_P_SPI_DeInit(diff_p_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: diff_p_drv.c:261
int32_t DIFF_P_I2C_Initialize(diff_p_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
Definition: diff_p_drv.c:292
This defines the sensor specific information for SPI.
Definition: diff_p_drv.h:59
void DIFF_P_SPI_SetIdleTask(diff_p_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
Definition: diff_p_drv.c:183
The sensor_io_spi.h file declares low-level interface functions for reading and writing sensor regist...
int32_t DIFF_P_SPI_ReadData(diff_p_spi_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: diff_p_drv.c:232
The diff_p.h contains the DIFF_P Pressure sensor register definitions, access macros, and its bit mask.
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
This structure defines the diff_p data buffer in Pressure Mode.
Definition: diff_p_drv.h:79
uint32_t size
ARM_DRIVER_I2C * pCommDrv
Definition: diff_p_drv.h:73
This structure defines the Write command List.
Definition: sensor_drv.h:94
This structure defines the Read command List.
Definition: sensor_drv.h:104
This structure defines the device specific info required by register I/O.
Definition: sensor_drv.h:128
void DIFF_P_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: diff_p_drv.c:57
This structure defines the spi slave command format.
The register_io_spi.h file declares low-level interface functions for reading and writing sensor regi...
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...
ARM_DRIVER_SPI * pCommDrv
Definition: diff_p_drv.h:62
int32_t DIFF_P_SPI_Configure(diff_p_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: diff_p_drv.c:189