ISSDK  1.7
IoT Sensing Software Development Kit
fxlc95000_drv.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 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 fxlc95000_drv.h
37  * @brief The fxlc95000_drv.h file describes the FXLC95000L driver interface and structures.
38  */
39 
40 #ifndef MMA9553_DRV_H_
41 #define MMA9553_DRV_H_
42 
43 /* Standard C Includes */
44 #include <stdint.h>
45 
46 /* ISSDK Includes */
47 #include "fxlc95000.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 fxlc95000 pedometer data buffer. */
79 typedef struct
80 {
81  uint32_t timestamp; /*! The time, this sample was recorded. */
82  int16_t accel[3]; /*! The raw accel data */
84 
85 /*! @def FXLC95000_COCO_ERROR_MASK
86  * @brief The Error Bit Mask in COCO Byte. */
87 #define FXLC95000_COCO_ERROR_MASK (0x7F)
88 
89 /*! @def FXLC95000_SPI_MAX_MSG_SIZE
90  * @brief The MAX size of SPI message. */
91 #define FXLC95000_SPI_MAX_MSG_SIZE (64)
92 
93 /*! @def FXLC95000_SPI_CMD_LEN
94  * @brief The size of the Sensor specific SPI Header. */
95 #define FXLC95000_SPI_CMD_LEN (1)
96 
97 /*! @def FXLC95000_SS_ACTIVE_VALUE
98  * @brief Is the Slave Select Pin Active Low or High. */
99 #define FXLC95000_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
100 
101 /*! @def FXLC95000_ROM_CI_WRITE_MIN_LEN
102  * @brief The MIN Length of ROM CI_WRITE Data. */
103 #define FXLC95000_ROM_CI_WRITE_MIN_LEN 4
104 
105 /*! @def FXLC95000_ROM_CI_WRITE_MAX_LEN
106  * @brief The MAX Length of ROM CI_WRITE Data. */
107 #define FXLC95000_ROM_CI_WRITE_MAX_LEN 24
108 
109 /*! @def FXLC95000_ROM_CI_READ_WRITE_MAX_LEN
110  * @brief The MAX Length of ROM CI_READ_WRITE Command. */
111 #define FXLC95000_ROM_CI_READ_WRITE_MAX_LEN 32
112 
113 /*! @def FXLC95000_ROM_CI_READ_WRITE_HDR_LEN
114  * @brief The Length of ROM CI_READ_WRITE Command Header. */
115 #define FXLC95000_ROM_CI_READ_WRITE_HDR_LEN 6
116 
117 /*! @def FXLC95000_ROM_CI_READ_WRITE_ADDR_LEN
118  * @brief The Length of Address field in ROM CI_READ_WRITE Command Header. */
119 #define FXLC95000_ROM_CI_READ_WRITE_ADDR_LEN 2
120 
121 /*! @def FXLC95000_FLASH_PAYLOAD_ADDR_LEN
122  * @brief The Length of Address field in FLASH Payload form Host. */
123 #define FXLC95000_FLASH_PAYLOAD_ADDR_LEN 4
124 
125 /*******************************************************************************
126  * APIs
127  ******************************************************************************/
128 /*! @brief The interface function to check if the sensor is in ROM CI Mode.
129  * @details This function checks the Response of Version Info command to determine if Sensor is in ROM CI Mode.
130  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
131  * @param[in] index the I2C device number.
132  * @param[in] sAddress slave address of the device on the bus.
133  * @constraints This can be called any time.
134  * Application has to ensure that previous instances of these APIs have exited before invocation.
135  * @reeentrant No
136  * @return ::FXLC95000_I2C_CheckRomMode() returns the status.
137  */
138 int32_t FXLC95000_I2C_CheckRomMode(ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress);
139 
140 /*! @brief The interface function to write ROM CI Commands.
141  * @details This function Writes ROM CI commands over I2C to the Sensor.
142  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
143  * @param[in] index the I2C device number.
144  * @param[in] sAddress slave address of the device on the bus.
145  * @param[in] pCommandList pointer to the command read list.
146  * @constraints This can be called only if Sensor is in ROM CI Mode.
147  * Application has to ensure that previous instances of these APIs have exited before invocation.
148  * @reeentrant No
149  * @return ::FXLC95000_I2C_FlashCommands() returns the status.
150  */
151 int32_t FXLC95000_I2C_FlashCommands(ARM_DRIVER_I2C *pBus,
152  uint8_t index,
153  uint16_t sAddress,
154  const registercommandlist_t *pCommandList);
155 
156 /*! @brief The interface function to write ROM CI Data Payload.
157  * @details This function Writes ROM CI Payload Bytes by creating formatted Commands and writing over I2C to the
158  * Sensor.
159  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
160  * @param[in] index the I2C device number.
161  * @param[in] sAddress slave address of the device on the bus.
162  * @param[in] pFlashBytes pointer to payload bytes of flash data.
163  * @param[in] numBytes the number of bytes of flash data to be written.
164  * @constraints This can be called only if Sensor is in ROM CI Mode.
165  * Application has to ensure that previous instances of these APIs have exited before invocation.
166  * @reeentrant No
167  * @return ::FXLC95000_I2C_FlashPayload() returns the status.
168  */
170  ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *pFlashBytes, uint8_t numBytes);
171 
172 /*! @brief The interface function to initialize the sensor.
173  * @details This function initialize the sensor and sensor handle.
174  * @param[in] pSensorHandle handle to the sensor.
175  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
176  * @param[in] index the I2C device number.
177  * @param[in] sAddress slave address of the device on the bus.
178  * @param[in] buildId FXLC95000 firmware buid number.
179  * @constraints This should be the first API to be called.
180  * Application has to ensure that previous instances of these APIs have exited before invocation.
181  * @reeentrant No
182  * @return ::FXLC95000_I2C_Initialize() returns the status .
183  */
185  ARM_DRIVER_I2C *pBus,
186  uint8_t index,
187  uint16_t sAddress,
188  uint16_t buildId);
189 
190 /*! @brief : The interface function to set the I2C Idle Task.
191  * @param[in] : fxlc95000_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
192  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
193  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
194  * @return void.
195  * @constraints This can be called any number of times only after FXLC95000_I2C_Initialize().
196  * Application has to ensure that previous instances of these APIs have exited before invocation.
197  * @reeentrant No
198  */
200  registeridlefunction_t idleTask,
201  void *userParam);
202 
203 /*! @brief The interface function to read the sensor data.
204  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
205  * @param[in] pSensorHandle handle to the sensor.
206  * @param[in] pCommandList pointer to the command read list.
207  * @param[in] pReadList pointer to the list of device registers and values to read.
208  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
209  * command read in the list.
210  * @constraints This can be called any number of times only after FXLC95000_I2C_Initialize().
211  * Application has to ensure that previous instances of these APIs have exited before invocation.
212  * @reeentrant No
213  * @return ::FXLC95000_I2C_CommandResponse() returns the status .
214  */
216  const registercommandlist_t *pCommandList,
217  const registerreadlist_t *pReadList,
218  uint8_t *pBuffer);
219 
220 /*! @brief The interface function to initialize the sensor.
221  * @details This function initializes the sensor and sensor handle.
222  * @param[in] pSensorHandle handle to the sensor.
223  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
224  * @param[in] index the I2C device number.
225  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
226  * @param[in] pReset reset handle of the device on the bus.
227  * @param[in] buildId FXLC95000 firmware buid number.
228  * @constraints This should be the first API to be called.
229  * Application has to ensure that previous instances of these APIs have exited before invocation.
230  * @reeentrant No
231  * @return ::FXLC95000_SPI_Initialize() returns the status .
232  */
234  ARM_DRIVER_SPI *pBus,
235  uint8_t index,
236  void *pSpiSelect,
237  void *pSlaveSelect,
238  void *pReset,
239  uint16_t buildId);
240 
241 /*! @brief : The interface function to set the SPI Idle Task.
242  * @param[in] : fxlc95000_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
243  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
244  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
245  * @return void.
246  * @constraints This can be called any number of times only after FXLC95000_SPI_Initialize().
247  * Application has to ensure that previous instances of these APIs have exited before invocation.
248  * @reeentrant No
249  */
251  registeridlefunction_t idleTask,
252  void *userParam);
253 
254 /*! @brief The interface function to read the sensor data.
255  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
256  * @param[in] pSensorHandle handle to the sensor.
257  * @param[in] pCommandList pointer to the command read list.
258  * @param[in] pReadList pointer to the list of device registers and values to read.
259  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
260  * command read in the list.
261  * @constraints This can be called any number of times only after FXLC95000_SPI_Initialize().
262  * Application has to ensure that previous instances of these APIs have exited before invocation.
263  * @reeentrant No
264  * @return ::FXLC95000_SPI_CommandResponse() returns the status .
265  */
267  const registercommandlist_t *pCommandList,
268  const registerreadlist_t *pReadList,
269  uint8_t *pBuffer);
270 
271 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
272  * @details This function prepares the SPI Read Command Header with register address and
273  * R/W bit encoded as the Sensor.
274  * @param[out] pCmdOut handle to the output buffer.
275  * @param[in] offset the address of the register to start reading from.
276  * @param[in] size number of bytes to read.
277  * @constraints None
278  * Application has to ensure that previous instances of these APIs have exited before invocation.
279  * @reeentrant No
280  * @return :: None.
281  */
282 void FXLC95000_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
283 
284 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
285  * @details This function prepares the SPI Write Command Header with register address and
286  * R/W bit encoded as the Sensor.
287  * @param[out] pCmdOut handle to the output buffer.
288  * @param[in] offset the address of the register to start writing from.
289  * @param[in] size number of bytes to write.
290  * @constraints None
291  * Application has to ensure that previous instances of these APIs have exited before invocation.
292  * @reeentrant No
293  * @return :: None.
294  */
295 void FXLC95000_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
296 
297 #endif // FXLC95000_DRV_H_
void FXLC95000_I2C_SetIdleTask(fxlc95000_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
This structure defines the fxlc95000 pedometer data buffer.
Definition: fxlc95000_drv.h:79
void FXLC95000_SPI_SetIdleTask(fxlc95000_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
int32_t FXLC95000_I2C_CommandResponse(fxlc95000_i2c_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
registerDeviceInfo_t deviceInfo
Definition: fxlc95000_drv.h:61
registerDeviceInfo_t deviceInfo
Definition: fxlc95000_drv.h:72
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
int32_t FXLC95000_SPI_Initialize(fxlc95000_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSpiSelect, void *pSlaveSelect, void *pReset, uint16_t buildId)
The interface function to initialize the sensor.
Definition: fxlc95000_drv.c:94
int32_t FXLC95000_I2C_CheckRomMode(ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress)
The interface function to check if the sensor is in ROM CI Mode.
void FXLC95000_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: fxlc95000_drv.c:57
int32_t FXLC95000_SPI_CommandResponse(fxlc95000_spi_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
void FXLC95000_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: fxlc95000_drv.c:74
The fxlc95000.h contains the FXLC95000L Digital Accelerometer command definitions and access macros...
int32_t FXLC95000_I2C_FlashCommands(ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, const registercommandlist_t *pCommandList)
The interface function to write ROM CI Commands.
The sensor_io_spi.h file declares low-level interface functions for reading and writing sensor regist...
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
uint32_t size
int32_t FXLC95000_I2C_Initialize(fxlc95000_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint16_t buildId)
The interface function to initialize the sensor.
spiSlaveSpecificParams_t slaveParams
Definition: fxlc95000_drv.h:64
This defines the sensor specific information for SPI.
Definition: fxlc95000_drv.h:59
This structure defines the Read command List.
Definition: sensor_drv.h:104
This defines the sensor specific information for I2C.
Definition: fxlc95000_drv.h:70
This structure defines the device specific info required by register I/O.
Definition: sensor_drv.h:128
This structure defines the Block command List.
Definition: sensor_drv.h:113
int32_t FXLC95000_I2C_FlashPayload(ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *pFlashBytes, uint8_t numBytes)
The interface function to write ROM CI Data Payload.
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...