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 FRDM 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 {
109 
110 /*!
111  * @brief This enumeration defines the ADS Flash storage status.
112  */
113 typedef enum
114 {
119 
120 /*!
121  * @brief This defines a record type to store the expected field values in the MCU SDID register word aligned.
122  */
123 typedef struct
124 {
125  uint32_t mcuFamilyId; // MCU Specific Family ID
126  uint32_t mcuSubfamilyId; // MCU Specific Subfamily ID
127  uint32_t mcuSeriesId; // MCU Specific Series ID
128  uint32_t mcuFamId; // MCU Specific Family ID (separate field, not a typo).
129  uint32_t mcuPinId; // MCU Specific Pin ID
130  ADS_SupportedBoards_t board; // MCU Board corresponding to SDID values.
131 } mcuSDID_t;
132 
133 /*!
134  * @brief This defines a record type to store the communication channel info and WHO_AM_I address/value for various
135  * Sensor Shields.
136  */
137 typedef struct
138 {
139  ADS_Channel_t channel; // Channel type over which to attempt communications.
140  uint32_t slaveAddr; // I2C Slave Address or Chip-Select value.
141  uint32_t whoAmIAddr; // WHO_AM_I Register Address (Offset).
142  uint32_t whoAmIValue; // WHO_AM_I Register Value.
143  uint8_t whoAmIMask; // The Mask for Fixed who ami i bits for sensors with variants.
145 
146 /*!
147  * @brief This defines a record type to store ADS results string in Flash memory.
148  */
149 typedef struct
150 {
151  uint32_t cookie; // A unique 32-bit value unlikely to be randomly found in Flash.
152  uint32_t length; // Length of the ADS result string in bytes.
153  char ADSString[ADS_FLASH_STRING_LENGTH]; // The ADS results string.
155 
156 /******************************************************************************/
157 /*! @brief The function to register Application Name and initialte ADS.
158  * @details The API will read the Application Name from the user and return
159  * the result string with the ADS detection results. It will also update
160  * the FLASH with the new results.
161  * @param[in] pAppName - pointer to a buffer where the application name is placed.
162  * @param[in/out] boardString - pointer to a buffer to place the ADS board string.
163  * @param[in/out] shieldString - pointer to a buffer to place the ADS shield string.
164  * @param[in] bufferLength - Length of output buffers.
165  * @Constraints In case the combined string to be written to flash becomes greater than
166  * permissible, it will be truncated and may lead to unexpected results.
167  * @Return void
168  * @Reentrant No
169  */
170 void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength);
171 
172 #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]
#define ADS_FLASH_STRING_LENGTH
ADS_SupportedBoards_t
This enumeration defines the FRDM boards that ADS can detect.
ADS_SupportedBoards_t board
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.
This defines a record type to store the expected field values in the MCU SDID register word aligned...
ADS_FlashStatus_t
This enumeration defines the ADS Flash storage status.
enum ADS_Status ADS_Status_t
This defines the return status.
void BOARD_RunADS(const char *appName, char *boardString, char *shieldString, size_t bufferLength)
The function to register Application Name and initialte ADS.