ISSDK  1.7
IoT Sensing Software Development Kit
register_io_spi.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 register_io_spi.h
37  * @brief The register_io_spi.h file declares low-level interface functions for reading
38  * and writing sensor registers using CMSIS APIs.
39  */
40 
41 #ifndef __REGISTER_IO_SPI_H__
42 #define __REGISTER_IO_SPI_H__
43 
44 #include "Driver_SPI.h"
45 #include "sensor_drv.h"
46 
47 #define SPI_SS_ACTIVE_LOW (ARM_SPI_SS_INACTIVE)
48 #define SPI_SS_ACTIVE_HIGH (ARM_SPI_SS_ACTIVE)
49 
50 /*! Function pointer for the slave read information*/
51 typedef void (*fpSpiReadPreprocessFn_t)(void *pCmdOut, uint32_t offset, uint32_t size);
52 /*! Function pointer for the slave write information*/
53 typedef void (*fpSpiWritePreprocessFn_t)(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
54 
55 /*! @brief The SPI Slave Control Command Params SDK2.0 Driver. */
56 typedef struct
57 {
59  uint8_t activeValue;
60  uint8_t cmdCode;
62 
63 /*! @brief The SPI Slave Transfer Command Params SDK2.0 Driver. */
64 typedef struct spi_mater_SlaveCmd
65 {
66  uint32_t size; /*!< The tranfer size.*/
67  uint8_t *pReadBuffer; /*!< The handle the readbuffer.*/
68  uint8_t *pWriteBuffer; /*!< The handle the writecommand.*/
70 
71 /*! @brief This structure defines the spi slave command format. */
72 typedef struct
73 {
77  uint8_t spiCmdLen;
78  uint8_t ssActiveValue;
80 
81 #if defined(SPI0)
82 /*! @brief The SPI0 device index. */
83 #define SPI0_INDEX 0
84 
85 /*! @brief Defines the SPI signal event handler.
86  * @details The Signal Event Handler function required by register_io_i2c.c.
87  * @param[in] event The SPI event that occured.
88  * @Constraints None
89  * @Reentrant Yes
90  * @return void
91  */
92 void SPI0_SignalEvent_t(uint32_t event);
93 #endif
94 
95 #if defined(SPI1)
96 /*! @brief The SPI1 device index. */
97 #define SPI1_INDEX 1
98 
99 /*! @brief Defines the SPI signal event handler.
100  * @details The Signal Event Handler function required by register_io_i2c.c.
101  * @param[in] event The SPI event that occured.
102  * @Constraints None
103  * @Reentrant Yes
104  * @return void
105  */
106 void SPI1_SignalEvent_t(uint32_t event);
107 #endif
108 
109 #if defined(SPI2)
110 /*! @brief The SPI2 device index. */
111 #define SPI2_INDEX 2
112 
113 /*! @brief Defines the SPI signal event handler.
114  * @details The Signal Event Handler function required by register_io_i2c.c.
115  * @param[in] event The SPI event that occured.
116  * @Constraints None
117  * @Reentrant Yes
118  * @return void
119  */
120 void SPI2_SignalEvent_t(uint32_t event);
121 #endif
122 
123 #if defined(SPI3)
124 /*! @brief The SPI3 device index. */
125 #define SPI3_INDEX 3
126 
127 /*! @brief Defines the SPI signal event handler.
128  * @details The Signal Event Handler function required by register_io_i2c.c.
129  * @param[in] event The SPI event that occured.
130  * @Constraints None
131  * @Reentrant Yes
132  * @return void
133  */
134 void SPI3_SignalEvent_t(uint32_t event);
135 #endif
136 
137 #if defined(SPI4)
138 /*! @brief The SPI4 device index. */
139 #define SPI4_INDEX 4
140 
141 /*! @brief Defines the SPI signal event handler.
142  * @details The Signal Event Handler function required by register_io_i2c.c.
143  * @param[in] event The SPI event that occured.
144  * @Constraints None
145  * @Reentrant Yes
146  * @return void
147  */
148 void SPI4_SignalEvent_t(uint32_t event);
149 #endif
150 
151 #if defined(SPI5)
152 /*! @brief The SPI5 device index. */
153 #define SPI5_INDEX 5
154 
155 /*! @brief Defines the SPI signal event handler.
156  * @details The Signal Event Handler function required by register_io_i2c.c.
157  * @param[in] event The SPI event that occured.
158  * @Constraints None
159  * @Reentrant Yes
160  * @return void
161  */
162 void SPI5_SignalEvent_t(uint32_t event);
163 #endif
164 
165 #if defined(SPI6)
166 /*! @brief The SPI6 device index. */
167 #define SPI6_INDEX 6
168 
169 /*! @brief Defines the SPI signal event handler.
170  * @details The Signal Event Handler function required by register_io_i2c.c.
171  * @param[in] event The SPI event that occured.
172  * @Constraints None
173  * @Reentrant Yes
174  * @return void
175  */
176 void SPI6_SignalEvent_t(uint32_t event);
177 #endif
178 
179 #if defined(SPI7)
180 /*! @brief The SPI7 device index. */
181 #define SPI7_INDEX 7
182 
183 /*! @brief Defines the SPI signal event handler.
184  * @details The Signal Event Handler function required by register_io_i2c.c.
185  * @param[in] event The SPI event that occured.
186  * @Constraints None
187  * @Reentrant Yes
188  * @return void
189  */
190 void SPI7_SignalEvent_t(uint32_t event);
191 #endif
192 
193 /*!
194  * @brief The interface function to block write to a sensor register.
195  *
196  * @param ARM_DRIVER_SPI *pCommDrv - The SPI driver to use.
197  * @param registerDeviceInfo_t *devInfo - The SPI device number and idle function.
198  * @param void *pWriteParams - the sensor's SPI slave select params.
199  * @param uint8_t offset - The register/offset to write to
200  * @param uint8_t *pBuffer - The buffer containing bytes to write.
201  * @param uint8_t bytesToWrite - A number of bytes to write.
202  *
203  * @return ARM_DRIVER_OK if success or ARM_DRIVER_ERROR if error.
204  */
205 int32_t Register_SPI_BlockWrite(ARM_DRIVER_SPI *pCommDrv,
206  registerDeviceInfo_t *devInfo,
207  void *pWriteParams,
208  uint8_t offset,
209  const uint8_t *pBuffer,
210  uint8_t bytesToWrite);
211 
212 /*!
213  * @brief The interface function to write a sensor register.
214  *
215  * @param ARM_DRIVER_SPI *pCommDrv - The SPI driver to use.
216  * @param registerDeviceInfo_t *devInfo - The SPI device number and idle function.
217  * @param void *pWriteParams - the sensor's SPI slave select params.
218  * @param uint8_t offset - The register/offset to write to
219  * @param uint8_t value - The value to write to the register
220  * @param uint8_t mask - A mask value to use when writing.
221  * A non-zero mask indicates that a read-modify-write operation should be used.
222  * where only the bits set in the mask will be updated according to the value param.
223  * @return ARM_DRIVER_OK if success or ARM_DRIVER_ERROR if error.
224  */
225 int32_t Register_SPI_Write(ARM_DRIVER_SPI *pCommDrv,
226  registerDeviceInfo_t *devInfo,
227  void *pWriteParams,
228  uint8_t offset,
229  uint8_t value,
230  uint8_t mask);
231 
232 /*!
233  * @brief The interface function to read a sensor register.
234  *
235  * @param ARM_DRIVER_SPI *pCommDrv - The SPI driver to use.
236  * @param registerDeviceInfo_t *devInfo - The SPI device number and idle function.
237  * @param void *pReadParams - the sensor's SPI slave select params.
238  * @param uint8_t offset - The register/offset to read from
239  * @param uint8_t length - The number of bytes to read
240  * @param uint8_t *pOutBuffer - The pointer to the buffer to store the register value read.
241  *
242  * @return ARM_DRIVER_OK if success or ARM_DRIVER_ERROR if error.
243  */
244 int32_t Register_SPI_Read(ARM_DRIVER_SPI *pCommDrv,
245  registerDeviceInfo_t *devInfo,
246  void *pReadParams,
247  uint8_t offset,
248  uint8_t length,
249  uint8_t *pOutBuffer);
250 
251 #endif // __REGISTER_IO_SPI_H__
The sensor_drv.h file contains sensor state and error definitions.
fpSpiWritePreprocessFn_t pWritePreprocessFN
int32_t Register_SPI_Write(ARM_DRIVER_SPI *pCommDrv, registerDeviceInfo_t *devInfo, void *pWriteParams, uint8_t offset, uint8_t value, uint8_t mask)
The interface function to write a sensor register.
int32_t Register_SPI_Read(ARM_DRIVER_SPI *pCommDrv, registerDeviceInfo_t *devInfo, void *pReadParams, uint8_t offset, uint8_t length, uint8_t *pOutBuffer)
The interface function to read a sensor register.
void(* fpSpiWritePreprocessFn_t)(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer)
The SPI Slave Transfer Command Params SDK2.0 Driver.
int32_t Register_SPI_BlockWrite(ARM_DRIVER_SPI *pCommDrv, registerDeviceInfo_t *devInfo, void *pWriteParams, uint8_t offset, const uint8_t *pBuffer, uint8_t bytesToWrite)
The interface function to block write to a sensor register.
void(* fpSpiReadPreprocessFn_t)(void *pCmdOut, uint32_t offset, uint32_t size)
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
uint32_t size
The SPI Slave Control Command Params SDK2.0 Driver.
This structure defines the device specific info required by register I/O.
Definition: sensor_drv.h:128
This structure defines the spi slave command format.
struct spi_mater_SlaveCmd spiCmdParams_t
The SPI Slave Transfer Command Params SDK2.0 Driver.
fpSpiReadPreprocessFn_t pReadPreprocessFN