Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:a1734fe1ec4b 1 /**
vpcola 0:a1734fe1ec4b 2 ******************************************************************************
vpcola 0:a1734fe1ec4b 3 * @file SPIRIT_Types.h
vpcola 0:a1734fe1ec4b 4 * @author VMA division - AMS
vpcola 0:a1734fe1ec4b 5 * @version 3.2.2
vpcola 0:a1734fe1ec4b 6 * @date 08-July-2015
vpcola 0:a1734fe1ec4b 7 * @brief Header file for SPIRIT types.
vpcola 0:a1734fe1ec4b 8 * @details
vpcola 0:a1734fe1ec4b 9 *
vpcola 0:a1734fe1ec4b 10 * This module provide some types definitions which will be used in
vpcola 0:a1734fe1ec4b 11 * all the modules of this library. Here is defined also the global
vpcola 0:a1734fe1ec4b 12 * variable @ref g_xStatus which contains the status of Spirit and
vpcola 0:a1734fe1ec4b 13 * is updated every time an SPI transaction occurs.
vpcola 0:a1734fe1ec4b 14 *
vpcola 0:a1734fe1ec4b 15 * @attention
vpcola 0:a1734fe1ec4b 16 *
vpcola 0:a1734fe1ec4b 17 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
vpcola 0:a1734fe1ec4b 18 *
vpcola 0:a1734fe1ec4b 19 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:a1734fe1ec4b 20 * are permitted provided that the following conditions are met:
vpcola 0:a1734fe1ec4b 21 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:a1734fe1ec4b 22 * this list of conditions and the following disclaimer.
vpcola 0:a1734fe1ec4b 23 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:a1734fe1ec4b 24 * this list of conditions and the following disclaimer in the documentation
vpcola 0:a1734fe1ec4b 25 * and/or other materials provided with the distribution.
vpcola 0:a1734fe1ec4b 26 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:a1734fe1ec4b 27 * may be used to endorse or promote products derived from this software
vpcola 0:a1734fe1ec4b 28 * without specific prior written permission.
vpcola 0:a1734fe1ec4b 29 *
vpcola 0:a1734fe1ec4b 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:a1734fe1ec4b 31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:a1734fe1ec4b 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:a1734fe1ec4b 33 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:a1734fe1ec4b 34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:a1734fe1ec4b 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:a1734fe1ec4b 36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:a1734fe1ec4b 37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:a1734fe1ec4b 38 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:a1734fe1ec4b 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:a1734fe1ec4b 40 *
vpcola 0:a1734fe1ec4b 41 ******************************************************************************
vpcola 0:a1734fe1ec4b 42 */
vpcola 0:a1734fe1ec4b 43
vpcola 0:a1734fe1ec4b 44 /* Define to prevent recursive inclusion -------------------------------------*/
vpcola 0:a1734fe1ec4b 45 #ifndef __SPIRIT_GENERICTYPES_H
vpcola 0:a1734fe1ec4b 46 #define __SPIRIT_GENERICTYPES_H
vpcola 0:a1734fe1ec4b 47
vpcola 0:a1734fe1ec4b 48
vpcola 0:a1734fe1ec4b 49 /* Includes ------------------------------------------------------------------*/
vpcola 0:a1734fe1ec4b 50
vpcola 0:a1734fe1ec4b 51 /* Include all integer types definitions */
vpcola 0:a1734fe1ec4b 52 #include <stdint.h>
vpcola 0:a1734fe1ec4b 53 #include <stdio.h>
vpcola 0:a1734fe1ec4b 54 #include "SPIRIT_Regs.h"
vpcola 0:a1734fe1ec4b 55
vpcola 0:a1734fe1ec4b 56
vpcola 0:a1734fe1ec4b 57
vpcola 0:a1734fe1ec4b 58 #ifdef __cplusplus
vpcola 0:a1734fe1ec4b 59 extern "C" {
vpcola 0:a1734fe1ec4b 60 #endif
vpcola 0:a1734fe1ec4b 61
vpcola 0:a1734fe1ec4b 62
vpcola 0:a1734fe1ec4b 63 /**
vpcola 0:a1734fe1ec4b 64 * @addtogroup SPIRIT_Libraries
vpcola 0:a1734fe1ec4b 65 * @{
vpcola 0:a1734fe1ec4b 66 */
vpcola 0:a1734fe1ec4b 67
vpcola 0:a1734fe1ec4b 68
vpcola 0:a1734fe1ec4b 69 /**
vpcola 0:a1734fe1ec4b 70 * @defgroup SPIRIT_Types Types
vpcola 0:a1734fe1ec4b 71 * @brief Module for SPIRIT types definition.
vpcola 0:a1734fe1ec4b 72 * * @details See the file <i>@ref SPIRIT_Types.h</i> for more details.
vpcola 0:a1734fe1ec4b 73 * @{
vpcola 0:a1734fe1ec4b 74 */
vpcola 0:a1734fe1ec4b 75
vpcola 0:a1734fe1ec4b 76 /**
vpcola 0:a1734fe1ec4b 77 * @defgroup Types_Exported_Types Types Exported Types
vpcola 0:a1734fe1ec4b 78 * @{
vpcola 0:a1734fe1ec4b 79 */
vpcola 0:a1734fe1ec4b 80
vpcola 0:a1734fe1ec4b 81 /**
vpcola 0:a1734fe1ec4b 82 * @brief Spirit Functional state. Used to enable or disable a specific option.
vpcola 0:a1734fe1ec4b 83 */
vpcola 0:a1734fe1ec4b 84 typedef enum
vpcola 0:a1734fe1ec4b 85 {
vpcola 0:a1734fe1ec4b 86 S_DISABLE = 0,
vpcola 0:a1734fe1ec4b 87 S_ENABLE = !S_DISABLE
vpcola 0:a1734fe1ec4b 88
vpcola 0:a1734fe1ec4b 89 } SpiritFunctionalState;
vpcola 0:a1734fe1ec4b 90
vpcola 0:a1734fe1ec4b 91 #define IS_SPIRIT_FUNCTIONAL_STATE(STATE) (STATE == S_DISABLE || STATE == S_ENABLE)
vpcola 0:a1734fe1ec4b 92
vpcola 0:a1734fe1ec4b 93 /**
vpcola 0:a1734fe1ec4b 94 * @brief Spirit Flag status. Used to control the state of a flag.
vpcola 0:a1734fe1ec4b 95 */
vpcola 0:a1734fe1ec4b 96 typedef enum
vpcola 0:a1734fe1ec4b 97 {
vpcola 0:a1734fe1ec4b 98 S_RESET = 0,
vpcola 0:a1734fe1ec4b 99 S_SET = !S_RESET
vpcola 0:a1734fe1ec4b 100
vpcola 0:a1734fe1ec4b 101 } SpiritFlagStatus;
vpcola 0:a1734fe1ec4b 102
vpcola 0:a1734fe1ec4b 103 #define IS_SPIRIT_FLAG_STATUS(STATUS) (STATUS == S_RESET || STATUS == S_SET)
vpcola 0:a1734fe1ec4b 104
vpcola 0:a1734fe1ec4b 105
vpcola 0:a1734fe1ec4b 106 /**
vpcola 0:a1734fe1ec4b 107 * @brief boolean type enumeration.
vpcola 0:a1734fe1ec4b 108 */
vpcola 0:a1734fe1ec4b 109 typedef enum
vpcola 0:a1734fe1ec4b 110 {
vpcola 0:a1734fe1ec4b 111 S_FALSE = 0,
vpcola 0:a1734fe1ec4b 112 S_TRUE = !S_FALSE
vpcola 0:a1734fe1ec4b 113
vpcola 0:a1734fe1ec4b 114 } SpiritBool;
vpcola 0:a1734fe1ec4b 115
vpcola 0:a1734fe1ec4b 116
vpcola 0:a1734fe1ec4b 117 /**
vpcola 0:a1734fe1ec4b 118 * @brief SPIRIT States enumeration.
vpcola 0:a1734fe1ec4b 119 */
vpcola 0:a1734fe1ec4b 120 typedef enum
vpcola 0:a1734fe1ec4b 121 {
vpcola 0:a1734fe1ec4b 122 MC_STATE_STANDBY =0x40, /*!< STANDBY */
vpcola 0:a1734fe1ec4b 123 MC_STATE_SLEEP =0x36, /*!< SLEEP */
vpcola 0:a1734fe1ec4b 124 MC_STATE_READY =0x03, /*!< READY */
vpcola 0:a1734fe1ec4b 125 MC_STATE_PM_SETUP =0x3D, /*!< PM_SETUP */
vpcola 0:a1734fe1ec4b 126 MC_STATE_XO_SETTLING =0x23, /*!< XO_SETTLING */
vpcola 0:a1734fe1ec4b 127 MC_STATE_SYNTH_SETUP =0x53, /*!< SYNT_SETUP */
vpcola 0:a1734fe1ec4b 128 MC_STATE_PROTOCOL =0x1F, /*!< PROTOCOL */
vpcola 0:a1734fe1ec4b 129 MC_STATE_SYNTH_CALIBRATION =0x4F, /*!< SYNTH */
vpcola 0:a1734fe1ec4b 130 MC_STATE_LOCK =0x0F, /*!< LOCK */
vpcola 0:a1734fe1ec4b 131 MC_STATE_RX =0x33, /*!< RX */
vpcola 0:a1734fe1ec4b 132 MC_STATE_TX =0x5F /*!< TX */
vpcola 0:a1734fe1ec4b 133
vpcola 0:a1734fe1ec4b 134 } SpiritState;
vpcola 0:a1734fe1ec4b 135
vpcola 0:a1734fe1ec4b 136
vpcola 0:a1734fe1ec4b 137
vpcola 0:a1734fe1ec4b 138 /**
vpcola 0:a1734fe1ec4b 139 * @brief SPIRIT Status. This definition represents the single field of the SPIRIT
vpcola 0:a1734fe1ec4b 140 * status returned on each SPI transaction, equal also to the MC_STATE registers.
vpcola 0:a1734fe1ec4b 141 * This field-oriented structure allows user to address in simple way the single
vpcola 0:a1734fe1ec4b 142 * field of the SPIRIT status.
vpcola 0:a1734fe1ec4b 143 * The user shall define a variable of SpiritStatus type to access on SPIRIT status fields.
vpcola 0:a1734fe1ec4b 144 * @note The fields order in the structure depends on used endianness (little or big
vpcola 0:a1734fe1ec4b 145 * endian). The actual definition is valid ONLY for LITTLE ENDIAN mode. Be sure to
vpcola 0:a1734fe1ec4b 146 * change opportunely the fields order when use a different endianness.
vpcola 0:a1734fe1ec4b 147 */
vpcola 0:a1734fe1ec4b 148
vpcola 0:a1734fe1ec4b 149 typedef struct
vpcola 0:a1734fe1ec4b 150 {
vpcola 0:a1734fe1ec4b 151 uint8_t XO_ON:1; /*!< This one bit field notifies if XO is operating
vpcola 0:a1734fe1ec4b 152 (XO_ON is 1) or not (XO_On is 0) */
vpcola 0:a1734fe1ec4b 153 SpiritState MC_STATE: 7; /*!< This 7 bits field indicates the state of the
vpcola 0:a1734fe1ec4b 154 Main Controller of SPIRIT. The possible states
vpcola 0:a1734fe1ec4b 155 and their corresponding values are defined in
vpcola 0:a1734fe1ec4b 156 @ref SpiritState */
vpcola 0:a1734fe1ec4b 157 uint8_t ERROR_LOCK: 1; /*!< This one bit field notifies if there is an
vpcola 0:a1734fe1ec4b 158 error on RCO calibration (ERROR_LOCK is 1) or
vpcola 0:a1734fe1ec4b 159 not (ERROR_LOCK is 0) */
vpcola 0:a1734fe1ec4b 160 uint8_t RX_FIFO_EMPTY: 1; /*!< This one bit field notifies if RX FIFO is empty
vpcola 0:a1734fe1ec4b 161 (RX_FIFO_EMPTY is 1) or not (RX_FIFO_EMPTY is 0) */
vpcola 0:a1734fe1ec4b 162 uint8_t TX_FIFO_FULL: 1; /*!< This one bit field notifies if TX FIFO is full
vpcola 0:a1734fe1ec4b 163 (TX_FIFO_FULL is 1) or not (TX_FIFO_FULL is 0) */
vpcola 0:a1734fe1ec4b 164 uint8_t ANT_SELECT: 1; /*!< This one bit field notifies the currently selected
vpcola 0:a1734fe1ec4b 165 antenna */
vpcola 0:a1734fe1ec4b 166 uint8_t : 4; /*!< This 4 bits field are reserved and equal to 5 */
vpcola 0:a1734fe1ec4b 167
vpcola 0:a1734fe1ec4b 168 }SpiritStatus;
vpcola 0:a1734fe1ec4b 169
vpcola 0:a1734fe1ec4b 170
vpcola 0:a1734fe1ec4b 171
vpcola 0:a1734fe1ec4b 172 /**
vpcola 0:a1734fe1ec4b 173 * @}
vpcola 0:a1734fe1ec4b 174 */
vpcola 0:a1734fe1ec4b 175
vpcola 0:a1734fe1ec4b 176
vpcola 0:a1734fe1ec4b 177 /**
vpcola 0:a1734fe1ec4b 178 * @defgroup Types_Exported_Constants Types Exported Constants
vpcola 0:a1734fe1ec4b 179 * @{
vpcola 0:a1734fe1ec4b 180 */
vpcola 0:a1734fe1ec4b 181
vpcola 0:a1734fe1ec4b 182
vpcola 0:a1734fe1ec4b 183 /**
vpcola 0:a1734fe1ec4b 184 * @}
vpcola 0:a1734fe1ec4b 185 */
vpcola 0:a1734fe1ec4b 186
vpcola 0:a1734fe1ec4b 187 /**
vpcola 0:a1734fe1ec4b 188 * @defgroup Types_Exported_Variables Types Exported Variables
vpcola 0:a1734fe1ec4b 189 * @{
vpcola 0:a1734fe1ec4b 190 */
vpcola 0:a1734fe1ec4b 191
vpcola 0:a1734fe1ec4b 192 extern volatile SpiritStatus g_xStatus;
vpcola 0:a1734fe1ec4b 193
vpcola 0:a1734fe1ec4b 194 /**
vpcola 0:a1734fe1ec4b 195 * @}
vpcola 0:a1734fe1ec4b 196 */
vpcola 0:a1734fe1ec4b 197
vpcola 0:a1734fe1ec4b 198 /**
vpcola 0:a1734fe1ec4b 199 * @defgroup Types_Exported_Macros Types Exported Macros
vpcola 0:a1734fe1ec4b 200 * @{
vpcola 0:a1734fe1ec4b 201 */
vpcola 0:a1734fe1ec4b 202
vpcola 0:a1734fe1ec4b 203 #ifdef SPIRIT_USE_FULL_ASSERT
vpcola 0:a1734fe1ec4b 204 /**
vpcola 0:a1734fe1ec4b 205 * @brief The s_assert_param macro is used for function's parameters check.
vpcola 0:a1734fe1ec4b 206 * @param expr If expr is false, it calls assert_failed function which reports
vpcola 0:a1734fe1ec4b 207 * the name of the source file and the source line number of the call
vpcola 0:a1734fe1ec4b 208 * that failed. If expr is true, it returns no value.
vpcola 0:a1734fe1ec4b 209 * @retval None
vpcola 0:a1734fe1ec4b 210 */
vpcola 0:a1734fe1ec4b 211 #define s_assert_param(expr) ((expr) ? (void)0 : s_assert_failed((uint8_t *)__FILE__, __LINE__))
vpcola 0:a1734fe1ec4b 212 void s_assert_failed(uint8_t* file, uint32_t line);
vpcola 0:a1734fe1ec4b 213 #elif SPIRIT_USE_VCOM_ASSERT
vpcola 0:a1734fe1ec4b 214 /**
vpcola 0:a1734fe1ec4b 215 * @brief The s_assert_param macro is used for function's parameters check.
vpcola 0:a1734fe1ec4b 216 * @param expr If expr is false, it calls assert_failed function which reports
vpcola 0:a1734fe1ec4b 217 * the name of the source file and the source line number of the call
vpcola 0:a1734fe1ec4b 218 * that failed. If expr is true, it returns no value.
vpcola 0:a1734fe1ec4b 219 * @retval None
vpcola 0:a1734fe1ec4b 220 */
vpcola 0:a1734fe1ec4b 221 #define s_assert_param(expr) ((expr) ? (void)0 : s_assert_failed((uint8_t *)__FILE__, __LINE__,#expr))
vpcola 0:a1734fe1ec4b 222 void s_assert_failed(uint8_t* file, uint32_t line, char* expression);
vpcola 0:a1734fe1ec4b 223
vpcola 0:a1734fe1ec4b 224 #elif SPIRIT_USE_FRAME_ASSERT
vpcola 0:a1734fe1ec4b 225 /**
vpcola 0:a1734fe1ec4b 226 * @brief The s_assert_param macro is used for function's parameters check.
vpcola 0:a1734fe1ec4b 227 * @param expr If expr is false, it calls assert_failed function which reports
vpcola 0:a1734fe1ec4b 228 * the name of the source file and the source line number of the call
vpcola 0:a1734fe1ec4b 229 * that failed. If expr is true, it returns no value.
vpcola 0:a1734fe1ec4b 230 * @retval None
vpcola 0:a1734fe1ec4b 231 */
vpcola 0:a1734fe1ec4b 232 #define s_assert_param(expr) ((expr) ? (void)0 : s_assert_failed(#expr))
vpcola 0:a1734fe1ec4b 233 void s_assert_failed(char* expression);
vpcola 0:a1734fe1ec4b 234 #else
vpcola 0:a1734fe1ec4b 235 #define s_assert_param(expr) {}
vpcola 0:a1734fe1ec4b 236 #endif
vpcola 0:a1734fe1ec4b 237
vpcola 0:a1734fe1ec4b 238 /**
vpcola 0:a1734fe1ec4b 239 * @brief Returns the absolute value.
vpcola 0:a1734fe1ec4b 240 */
vpcola 0:a1734fe1ec4b 241 #define S_ABS(a) ((a)>0?(a):-(a))
vpcola 0:a1734fe1ec4b 242
vpcola 0:a1734fe1ec4b 243
vpcola 0:a1734fe1ec4b 244 /**
vpcola 0:a1734fe1ec4b 245 * @}
vpcola 0:a1734fe1ec4b 246 */
vpcola 0:a1734fe1ec4b 247
vpcola 0:a1734fe1ec4b 248
vpcola 0:a1734fe1ec4b 249 /**
vpcola 0:a1734fe1ec4b 250 * @defgroup Types_Exported_Functions Types Exported Functions
vpcola 0:a1734fe1ec4b 251 * @{
vpcola 0:a1734fe1ec4b 252 */
vpcola 0:a1734fe1ec4b 253
vpcola 0:a1734fe1ec4b 254 void SpiritRefreshStatus(void);
vpcola 0:a1734fe1ec4b 255
vpcola 0:a1734fe1ec4b 256 /**
vpcola 0:a1734fe1ec4b 257 *@}
vpcola 0:a1734fe1ec4b 258 */
vpcola 0:a1734fe1ec4b 259
vpcola 0:a1734fe1ec4b 260 /**
vpcola 0:a1734fe1ec4b 261 * @}
vpcola 0:a1734fe1ec4b 262 */
vpcola 0:a1734fe1ec4b 263
vpcola 0:a1734fe1ec4b 264
vpcola 0:a1734fe1ec4b 265 /**
vpcola 0:a1734fe1ec4b 266 * @}
vpcola 0:a1734fe1ec4b 267 */
vpcola 0:a1734fe1ec4b 268
vpcola 0:a1734fe1ec4b 269
vpcola 0:a1734fe1ec4b 270 #ifdef __cplusplus
vpcola 0:a1734fe1ec4b 271 }
vpcola 0:a1734fe1ec4b 272 #endif
vpcola 0:a1734fe1ec4b 273
vpcola 0:a1734fe1ec4b 274 #endif
vpcola 0:a1734fe1ec4b 275
vpcola 0:a1734fe1ec4b 276 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/