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_Csma.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 Configuration and management of SPIRIT CSMA.
vpcola 0:a1734fe1ec4b 8 * @details
vpcola 0:a1734fe1ec4b 9 *
vpcola 0:a1734fe1ec4b 10 * The Spirit CSMA feature, when configured and enabled, is transparent
vpcola 0:a1734fe1ec4b 11 * for the user. It means the user has only to call the <i>@ref SpiritCsmaInit()</i>
vpcola 0:a1734fe1ec4b 12 * function on a filled structure and then enable the CSMA policy using the <i>@ref SpiritCsma()</i>
vpcola 0:a1734fe1ec4b 13 * function.
vpcola 0:a1734fe1ec4b 14 *
vpcola 0:a1734fe1ec4b 15 * <b>Example:</b>
vpcola 0:a1734fe1ec4b 16 * @code
vpcola 0:a1734fe1ec4b 17 *
vpcola 0:a1734fe1ec4b 18 * CsmaInit csmaInit={
vpcola 0:a1734fe1ec4b 19 * S_DISABLE, // persistent mode
vpcola 0:a1734fe1ec4b 20 * TBIT_TIME_64, // Tbit time
vpcola 0:a1734fe1ec4b 21 * TCCA_TIME_3, // Tcca time
vpcola 0:a1734fe1ec4b 22 * 5, // max number of backoffs
vpcola 0:a1734fe1ec4b 23 * 0xFA21, // BU counter seed
vpcola 0:a1734fe1ec4b 24 * 32 // CU prescaler
vpcola 0:a1734fe1ec4b 25 * };
vpcola 0:a1734fe1ec4b 26 *
vpcola 0:a1734fe1ec4b 27 * ...
vpcola 0:a1734fe1ec4b 28 *
vpcola 0:a1734fe1ec4b 29 * SpiritCsmaInit(&csmaInit);
vpcola 0:a1734fe1ec4b 30 * SpiritCsma(S_ENABLE);
vpcola 0:a1734fe1ec4b 31 *
vpcola 0:a1734fe1ec4b 32 *
vpcola 0:a1734fe1ec4b 33 * @endcode
vpcola 0:a1734fe1ec4b 34 *
vpcola 0:a1734fe1ec4b 35 * @note The CS status depends of the RSSI threshold set. Please see the Spirit_Qi
vpcola 0:a1734fe1ec4b 36 * module for details.
vpcola 0:a1734fe1ec4b 37 *
vpcola 0:a1734fe1ec4b 38 * @attention
vpcola 0:a1734fe1ec4b 39 *
vpcola 0:a1734fe1ec4b 40 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
vpcola 0:a1734fe1ec4b 41 *
vpcola 0:a1734fe1ec4b 42 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:a1734fe1ec4b 43 * are permitted provided that the following conditions are met:
vpcola 0:a1734fe1ec4b 44 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:a1734fe1ec4b 45 * this list of conditions and the following disclaimer.
vpcola 0:a1734fe1ec4b 46 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:a1734fe1ec4b 47 * this list of conditions and the following disclaimer in the documentation
vpcola 0:a1734fe1ec4b 48 * and/or other materials provided with the distribution.
vpcola 0:a1734fe1ec4b 49 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:a1734fe1ec4b 50 * may be used to endorse or promote products derived from this software
vpcola 0:a1734fe1ec4b 51 * without specific prior written permission.
vpcola 0:a1734fe1ec4b 52 *
vpcola 0:a1734fe1ec4b 53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:a1734fe1ec4b 54 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:a1734fe1ec4b 55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:a1734fe1ec4b 56 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:a1734fe1ec4b 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:a1734fe1ec4b 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:a1734fe1ec4b 59 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:a1734fe1ec4b 60 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:a1734fe1ec4b 61 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:a1734fe1ec4b 62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:a1734fe1ec4b 63 *
vpcola 0:a1734fe1ec4b 64 ******************************************************************************
vpcola 0:a1734fe1ec4b 65 */
vpcola 0:a1734fe1ec4b 66
vpcola 0:a1734fe1ec4b 67 /* Define to prevent recursive inclusion -------------------------------------*/
vpcola 0:a1734fe1ec4b 68 #ifndef __SPIRIT_CSMA_H
vpcola 0:a1734fe1ec4b 69 #define __SPIRIT_CSMA_H
vpcola 0:a1734fe1ec4b 70
vpcola 0:a1734fe1ec4b 71
vpcola 0:a1734fe1ec4b 72 /* Includes ------------------------------------------------------------------*/
vpcola 0:a1734fe1ec4b 73
vpcola 0:a1734fe1ec4b 74 #include "SPIRIT_Types.h"
vpcola 0:a1734fe1ec4b 75 #include "SPIRIT_Regs.h"
vpcola 0:a1734fe1ec4b 76
vpcola 0:a1734fe1ec4b 77
vpcola 0:a1734fe1ec4b 78 #ifdef __cplusplus
vpcola 0:a1734fe1ec4b 79 extern "C" {
vpcola 0:a1734fe1ec4b 80 #endif
vpcola 0:a1734fe1ec4b 81
vpcola 0:a1734fe1ec4b 82
vpcola 0:a1734fe1ec4b 83 /**
vpcola 0:a1734fe1ec4b 84 * @addtogroup SPIRIT_Libraries
vpcola 0:a1734fe1ec4b 85 * @{
vpcola 0:a1734fe1ec4b 86 */
vpcola 0:a1734fe1ec4b 87
vpcola 0:a1734fe1ec4b 88
vpcola 0:a1734fe1ec4b 89 /**
vpcola 0:a1734fe1ec4b 90 * @defgroup SPIRIT_Csma CSMA
vpcola 0:a1734fe1ec4b 91 * @brief Configuration and management of SPIRIT CSMA.
vpcola 0:a1734fe1ec4b 92 * @details See the file <i>@ref SPIRIT_Csma.h</i> for more details.
vpcola 0:a1734fe1ec4b 93 * @{
vpcola 0:a1734fe1ec4b 94 */
vpcola 0:a1734fe1ec4b 95
vpcola 0:a1734fe1ec4b 96 /**
vpcola 0:a1734fe1ec4b 97 * @defgroup Csma_Exported_Types CSMA Exported Types
vpcola 0:a1734fe1ec4b 98 * @{
vpcola 0:a1734fe1ec4b 99 */
vpcola 0:a1734fe1ec4b 100
vpcola 0:a1734fe1ec4b 101
vpcola 0:a1734fe1ec4b 102 /**
vpcola 0:a1734fe1ec4b 103 * @brief Multiplier for Tcca time enumeration (Tcca = Multiplier*Tbit).
vpcola 0:a1734fe1ec4b 104 */
vpcola 0:a1734fe1ec4b 105 typedef enum
vpcola 0:a1734fe1ec4b 106 {
vpcola 0:a1734fe1ec4b 107 TBIT_TIME_64 = CSMA_CCA_PERIOD_64TBIT, /*!< CSMA/CA: Sets CCA period to 64*TBIT */
vpcola 0:a1734fe1ec4b 108 TBIT_TIME_128 = CSMA_CCA_PERIOD_128TBIT, /*!< CSMA/CA: Sets CCA period to 128*TBIT */
vpcola 0:a1734fe1ec4b 109 TBIT_TIME_256 = CSMA_CCA_PERIOD_256TBIT, /*!< CSMA/CA: Sets CCA period to 256*TBIT */
vpcola 0:a1734fe1ec4b 110 TBIT_TIME_512 = CSMA_CCA_PERIOD_512TBIT, /*!< CSMA/CA: Sets CCA period to 512*TBIT */
vpcola 0:a1734fe1ec4b 111 }CcaPeriod;
vpcola 0:a1734fe1ec4b 112
vpcola 0:a1734fe1ec4b 113 #define IS_CCA_PERIOD(PERIOD) (PERIOD == TBIT_TIME_64 || \
vpcola 0:a1734fe1ec4b 114 PERIOD == TBIT_TIME_128 || \
vpcola 0:a1734fe1ec4b 115 PERIOD == TBIT_TIME_256 || \
vpcola 0:a1734fe1ec4b 116 PERIOD == TBIT_TIME_512)
vpcola 0:a1734fe1ec4b 117
vpcola 0:a1734fe1ec4b 118
vpcola 0:a1734fe1ec4b 119 /**
vpcola 0:a1734fe1ec4b 120 * @brief Multiplier of Tcca time enumeration to obtain Tlisten (Tlisten = [1...15]*Tcca).
vpcola 0:a1734fe1ec4b 121 */
vpcola 0:a1734fe1ec4b 122 typedef enum
vpcola 0:a1734fe1ec4b 123 {
vpcola 0:a1734fe1ec4b 124 TCCA_TIME_0 = 0x00, /*!< CSMA/CA: Sets CCA length to 0 */
vpcola 0:a1734fe1ec4b 125 TCCA_TIME_1 = 0x10, /*!< CSMA/CA: Sets CCA length to 1*TLISTEN */
vpcola 0:a1734fe1ec4b 126 TCCA_TIME_2 = 0x20, /*!< CSMA/CA: Sets CCA length to 2*TLISTEN */
vpcola 0:a1734fe1ec4b 127 TCCA_TIME_3 = 0x30, /*!< CSMA/CA: Sets CCA length to 3*TLISTEN */
vpcola 0:a1734fe1ec4b 128 TCCA_TIME_4 = 0x40, /*!< CSMA/CA: Sets CCA length to 4*TLISTEN */
vpcola 0:a1734fe1ec4b 129 TCCA_TIME_5 = 0x50, /*!< CSMA/CA: Sets CCA length to 5*TLISTEN */
vpcola 0:a1734fe1ec4b 130 TCCA_TIME_6 = 0x60, /*!< CSMA/CA: Sets CCA length to 6*TLISTEN */
vpcola 0:a1734fe1ec4b 131 TCCA_TIME_7 = 0x70, /*!< CSMA/CA: Sets CCA length to 7*TLISTEN */
vpcola 0:a1734fe1ec4b 132 TCCA_TIME_8 = 0x80, /*!< CSMA/CA: Sets CCA length to 8*TLISTEN */
vpcola 0:a1734fe1ec4b 133 TCCA_TIME_9 = 0x90, /*!< CSMA/CA: Sets CCA length to 9*TLISTEN */
vpcola 0:a1734fe1ec4b 134 TCCA_TIME_10 = 0xA0, /*!< CSMA/CA: Sets CCA length to 10*TLISTEN */
vpcola 0:a1734fe1ec4b 135 TCCA_TIME_11 = 0xB0, /*!< CSMA/CA: Sets CCA length to 11*TLISTEN */
vpcola 0:a1734fe1ec4b 136 TCCA_TIME_12 = 0xC0, /*!< CSMA/CA: Sets CCA length to 12*TLISTEN */
vpcola 0:a1734fe1ec4b 137 TCCA_TIME_13 = 0xD0, /*!< CSMA/CA: Sets CCA length to 13*TLISTEN */
vpcola 0:a1734fe1ec4b 138 TCCA_TIME_14 = 0xE0, /*!< CSMA/CA: Sets CCA length to 14*TLISTEN */
vpcola 0:a1734fe1ec4b 139 TCCA_TIME_15 = 0xF0, /*!< CSMA/CA: Sets CCA length to 15*TLISTEN */
vpcola 0:a1734fe1ec4b 140 }CsmaLength;
vpcola 0:a1734fe1ec4b 141
vpcola 0:a1734fe1ec4b 142 #define IS_CSMA_LENGTH(LENGTH) (LENGTH == TCCA_TIME_0 || \
vpcola 0:a1734fe1ec4b 143 LENGTH == TCCA_TIME_1 || \
vpcola 0:a1734fe1ec4b 144 LENGTH == TCCA_TIME_2 || \
vpcola 0:a1734fe1ec4b 145 LENGTH == TCCA_TIME_3 || \
vpcola 0:a1734fe1ec4b 146 LENGTH == TCCA_TIME_4 || \
vpcola 0:a1734fe1ec4b 147 LENGTH == TCCA_TIME_5 || \
vpcola 0:a1734fe1ec4b 148 LENGTH == TCCA_TIME_6 || \
vpcola 0:a1734fe1ec4b 149 LENGTH == TCCA_TIME_7 || \
vpcola 0:a1734fe1ec4b 150 LENGTH == TCCA_TIME_8 || \
vpcola 0:a1734fe1ec4b 151 LENGTH == TCCA_TIME_9 || \
vpcola 0:a1734fe1ec4b 152 LENGTH == TCCA_TIME_10 || \
vpcola 0:a1734fe1ec4b 153 LENGTH == TCCA_TIME_11 || \
vpcola 0:a1734fe1ec4b 154 LENGTH == TCCA_TIME_12 || \
vpcola 0:a1734fe1ec4b 155 LENGTH == TCCA_TIME_13 || \
vpcola 0:a1734fe1ec4b 156 LENGTH == TCCA_TIME_14 || \
vpcola 0:a1734fe1ec4b 157 LENGTH == TCCA_TIME_15)
vpcola 0:a1734fe1ec4b 158
vpcola 0:a1734fe1ec4b 159
vpcola 0:a1734fe1ec4b 160 /**
vpcola 0:a1734fe1ec4b 161 * @brief SPIRIT CSMA Init structure definition
vpcola 0:a1734fe1ec4b 162 */
vpcola 0:a1734fe1ec4b 163 typedef struct
vpcola 0:a1734fe1ec4b 164 {
vpcola 0:a1734fe1ec4b 165 SpiritFunctionalState xCsmaPersistentMode; /*!< Specifies if the CSMA persistent mode has to be on or off.
vpcola 0:a1734fe1ec4b 166 This parameter can be S_ENABLE or S_DISABLE */
vpcola 0:a1734fe1ec4b 167 CcaPeriod xMultiplierTbit; /*!< Specifies the Tbit multiplier to obtain the Tcca.
vpcola 0:a1734fe1ec4b 168 This parameter can be a value of @ref CcaPeriod */
vpcola 0:a1734fe1ec4b 169 CsmaLength xCcaLength; /*!< Specifies the Tcca multiplier to determinate the Tlisten.
vpcola 0:a1734fe1ec4b 170 This parameter can be a value of @ref CsmaLength. */
vpcola 0:a1734fe1ec4b 171 uint8_t cMaxNb; /*!< Specifies the max number of backoff cycles. Not used in persistent mode.
vpcola 0:a1734fe1ec4b 172 This parameter is an uint8_t. */
vpcola 0:a1734fe1ec4b 173 uint16_t nBuCounterSeed; /*!< Specifies the BU counter seed. Not used in persistent mode.
vpcola 0:a1734fe1ec4b 174 This parameter can be a value of 16 bits. */
vpcola 0:a1734fe1ec4b 175 uint8_t cBuPrescaler; /*!< Specifies the BU prescaler. Not used in persistent mode.
vpcola 0:a1734fe1ec4b 176 This parameter can be a value of 6 bits. */
vpcola 0:a1734fe1ec4b 177 }CsmaInit;
vpcola 0:a1734fe1ec4b 178
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 * @defgroup Csma_Exported_Constants CSMA Exported Constants
vpcola 0:a1734fe1ec4b 187 * @{
vpcola 0:a1734fe1ec4b 188 */
vpcola 0:a1734fe1ec4b 189
vpcola 0:a1734fe1ec4b 190 /**
vpcola 0:a1734fe1ec4b 191 * @defgroup Csma_Parameters CSMA Parameters
vpcola 0:a1734fe1ec4b 192 * @{
vpcola 0:a1734fe1ec4b 193 */
vpcola 0:a1734fe1ec4b 194
vpcola 0:a1734fe1ec4b 195 #define IS_BU_COUNTER_SEED(SEED) (SEED!=0)
vpcola 0:a1734fe1ec4b 196 #define IS_BU_PRESCALER(PRESCALER) (PRESCALER<64)
vpcola 0:a1734fe1ec4b 197 #define IS_CMAX_NB(NB) (NB<8)
vpcola 0:a1734fe1ec4b 198
vpcola 0:a1734fe1ec4b 199 /**
vpcola 0:a1734fe1ec4b 200 *@}
vpcola 0:a1734fe1ec4b 201 */
vpcola 0:a1734fe1ec4b 202
vpcola 0:a1734fe1ec4b 203 /**
vpcola 0:a1734fe1ec4b 204 *@}
vpcola 0:a1734fe1ec4b 205 */
vpcola 0:a1734fe1ec4b 206
vpcola 0:a1734fe1ec4b 207
vpcola 0:a1734fe1ec4b 208 /**
vpcola 0:a1734fe1ec4b 209 * @defgroup Csma_Exported_Macros CSMA Exported Macros
vpcola 0:a1734fe1ec4b 210 * @{
vpcola 0:a1734fe1ec4b 211 */
vpcola 0:a1734fe1ec4b 212
vpcola 0:a1734fe1ec4b 213
vpcola 0:a1734fe1ec4b 214 /**
vpcola 0:a1734fe1ec4b 215 *@}
vpcola 0:a1734fe1ec4b 216 */
vpcola 0:a1734fe1ec4b 217
vpcola 0:a1734fe1ec4b 218
vpcola 0:a1734fe1ec4b 219 /**
vpcola 0:a1734fe1ec4b 220 * @defgroup Csma_Exported_Functions CSMA Exported Functions
vpcola 0:a1734fe1ec4b 221 * @{
vpcola 0:a1734fe1ec4b 222 */
vpcola 0:a1734fe1ec4b 223
vpcola 0:a1734fe1ec4b 224 void SpiritCsmaInit(CsmaInit* pxCsmaInit);
vpcola 0:a1734fe1ec4b 225 void SpiritCsmaGetInfo(CsmaInit* pxCsmaInit);
vpcola 0:a1734fe1ec4b 226 void SpiritCsma(SpiritFunctionalState xNewState);
vpcola 0:a1734fe1ec4b 227 SpiritFunctionalState SpiritCsmaGetCsma(void);
vpcola 0:a1734fe1ec4b 228 void SpiritCsmaPersistentMode(SpiritFunctionalState xNewState);
vpcola 0:a1734fe1ec4b 229 SpiritFunctionalState SpiritCsmaGetPersistentMode(void);
vpcola 0:a1734fe1ec4b 230 void SpiritCsmaSeedReloadMode(SpiritFunctionalState xNewState);
vpcola 0:a1734fe1ec4b 231 SpiritFunctionalState SpiritCsmaGetSeedReloadMode(void);
vpcola 0:a1734fe1ec4b 232 void SpiritCsmaSetBuCounterSeed(uint16_t nBuCounterSeed);
vpcola 0:a1734fe1ec4b 233 uint16_t SpiritCsmaGetBuCounterSeed(void);
vpcola 0:a1734fe1ec4b 234 void SpiritCsmaSetBuPrescaler(uint8_t cBuPrescaler);
vpcola 0:a1734fe1ec4b 235 uint8_t SpiritCsmaGetBuPrescaler(void);
vpcola 0:a1734fe1ec4b 236 void SpiritCsmaSetCcaPeriod(CcaPeriod xMultiplierTbit);
vpcola 0:a1734fe1ec4b 237 CcaPeriod SpiritCsmaGetCcaPeriod(void);
vpcola 0:a1734fe1ec4b 238 void SpiritCsmaSetCcaLength(CsmaLength xCcaLength);
vpcola 0:a1734fe1ec4b 239 uint8_t SpiritCsmaGetCcaLength(void);
vpcola 0:a1734fe1ec4b 240 void SpiritCsmaSetMaxNumberBackoff(uint8_t cMaxNb);
vpcola 0:a1734fe1ec4b 241 uint8_t SpiritCsmaGetMaxNumberBackoff(void);
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 */
vpcola 0:a1734fe1ec4b 251
vpcola 0:a1734fe1ec4b 252
vpcola 0:a1734fe1ec4b 253 /**
vpcola 0:a1734fe1ec4b 254 *@}
vpcola 0:a1734fe1ec4b 255 */
vpcola 0:a1734fe1ec4b 256
vpcola 0:a1734fe1ec4b 257 #ifdef __cplusplus
vpcola 0:a1734fe1ec4b 258 }
vpcola 0:a1734fe1ec4b 259 #endif
vpcola 0:a1734fe1ec4b 260
vpcola 0:a1734fe1ec4b 261 #endif
vpcola 0:a1734fe1ec4b 262
vpcola 0:a1734fe1ec4b 263 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/