Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

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