ISSDK  1.7
IoT Sensing Software Development Kit
auto_detection_service.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 auto_detection_service.h
37  * @brief The auto_detection_service.h file describes the structures and definitions for a
38  * service that automatically detects the QN board and Sensor Shield.
39  */
40 
41 #ifndef AUTO_DETECTION_SERVICE_H_
42 #define AUTO_DETECTION_SERVICE_H_
43 
44 #include <stdio.h>
45 
46 /*******************************************************************************
47  * Definitions
48  ******************************************************************************/
49 #define ADS_NO_WHO_AM_I (0xFFFF) // Special value if sensor doesn't have WHO_AM_I register.
50 #define ADS_MAX_STRING_LENGTH (64) // Maximum length for sub-strings.
51 #define ADS_FLASH_STRING_LENGTH (128) // Maximum length of flash string.
52 #define ADS_NO_SHIELD_DETECTED (0xFFFFFFFF)
53 #define ADS_COOKIE_VALUE (0xDEADBEEF)
54 
55 /*!
56  * @brief This defines the return status.
57  */
58 typedef enum ADS_Status
59 {
60  ADS_OK, /* Sensor Detection status : "Found". */
61  ADS_FAIL, /* Sensor Detection status : "Not Found". */
62  ADS_NULL /* Sensor Detection status : "Dont Care". */
63 } ADS_Status_t;
64 
65 /*!
66  * @brief This defines the allowed communications channels.
67  */
68 typedef enum ADS_Channel
69 {
74 
75 /*!
76  * @brief This defines the allowed communications channels.
77  */
78 typedef enum ADS_Sensor
79 {
93 } ADS_Sensor_t;
94 
95 /*!
96  * @brief This enumeration defines the FRDM boards that ADS can detect.
97  */
98 typedef enum
99 {
104 
105 /*!
106  * @brief This enumeration defines the ADS Flash storage status.
107  */
108 typedef enum
109 {
114 
115 /*!
116  * @brief This defines a record type to store the expected field values of the LPC device ID.
117  */
118 typedef struct
119 {
120  uint32_t mcuChipId; // MCU Specific Chip ID
121  uint32_t mcuChipIdMask; // MCU Chip ID CID3 Bits to match (not all bits are defined)
122  ADS_SupportedBoards_t board; // MCU Board corresponding to Chip ID value.
123 } mcuDEVID_t;
124 
125 /*!
126  * @brief This defines a record type to store the communication channel info and WHO_AM_I address/value for various
127  * Sensor Shields.
128  */
129 typedef struct
130 {
131  ADS_Channel_t channel; // Channel type over which to attempt communications.
132  uint32_t slaveAddr; // I2C Slave Address or Chip-Select value.
133  uint32_t whoAmIAddr; // WHO_AM_I Register Address (Offset).
134  uint32_t whoAmIValue; // WHO_AM_I Register Value.
135  uint8_t whoAmIMask; // The Mask for Fixed who ami i bits for sensors with variants.
137 
138 /*!
139  * @brief This defines a record type to store ADS results string in Flash memory.
140  */
141 typedef struct
142 {
143  uint32_t cookie; // A unique 32-bit value unlikely to be randomly found in Flash.
144  uint32_t length; // Length of the ADS result string in bytes.
145  char ADSString[ADS_FLASH_STRING_LENGTH]; // The ADS results string.
147 
148 /******************************************************************************/
149 /*! @brief The function to register Application Name and initialte ADS.
150  * @details The API will read the Application Name from the user and return
151  * the result string with the ADS detection results. It will also update
152  * the FLASH with the new results.
153  * @param[in] pAppName - pointer to a buffer where the application name is placed.
154  * @param[in/out] boardString - pointer to a buffer to place the ADS board string.
155  * @param[in/out] shieldString - pointer to a buffer to place the ADS shield string.
156  * @param[in] bufferLength - Length of output buffers.
157  * @Constraints In case the combined string to be written to flash becomes greater than
158  * permissible, it will be truncated and may lead to unexpected results.
159  * @Return void
160  * @Reentrant No
161  */
162 void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength);
163 
164 #endif // AUTO_DETECTION_SERVICE_H_
enum ADS_Sensor ADS_Sensor_t
This defines the allowed communications channels.
enum ADS_Channel ADS_Channel_t
This defines the allowed communications channels.
char shieldString[ADS_MAX_STRING_LENGTH]
ADS_SupportedBoards_t
This enumeration defines the FRDM boards that ADS can detect.
ADS_Channel
This defines the allowed communications channels.
char boardString[ADS_MAX_STRING_LENGTH]
This defines a record type to store ADS results string in Flash memory.
ADS_Sensor
This defines the allowed communications channels.
This defines a record type to store the communication channel info and WHO_AM_I address/value for var...
ADS_Status
This defines the return status.
ADS_FlashStatus_t
This enumeration defines the ADS Flash storage status.
enum ADS_Status ADS_Status_t
This defines the return status.
#define ADS_FLASH_STRING_LENGTH
This defines a record type to store the expected field values of the LPC device ID.
void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength)
The function to register Application Name and initialte ADS.