Fork of my original MQTTGateway
easy-connect/stm-spirit1-rf-driver/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Csma.c@0:a1734fe1ec4b, 2017-04-08 (annotated)
- Committer:
- vpcola
- Date:
- Sat Apr 08 14:43:14 2017 +0000
- Revision:
- 0:a1734fe1ec4b
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| vpcola | 0:a1734fe1ec4b | 1 | /** |
| vpcola | 0:a1734fe1ec4b | 2 | ****************************************************************************** |
| vpcola | 0:a1734fe1ec4b | 3 | * @file SPIRIT_Csma.c |
| 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 | * @attention |
| vpcola | 0:a1734fe1ec4b | 10 | * |
| vpcola | 0:a1734fe1ec4b | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
| vpcola | 0:a1734fe1ec4b | 12 | * |
| vpcola | 0:a1734fe1ec4b | 13 | * Redistribution and use in source and binary forms, with or without modification, |
| vpcola | 0:a1734fe1ec4b | 14 | * are permitted provided that the following conditions are met: |
| vpcola | 0:a1734fe1ec4b | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
| vpcola | 0:a1734fe1ec4b | 16 | * this list of conditions and the following disclaimer. |
| vpcola | 0:a1734fe1ec4b | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| vpcola | 0:a1734fe1ec4b | 18 | * this list of conditions and the following disclaimer in the documentation |
| vpcola | 0:a1734fe1ec4b | 19 | * and/or other materials provided with the distribution. |
| vpcola | 0:a1734fe1ec4b | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| vpcola | 0:a1734fe1ec4b | 21 | * may be used to endorse or promote products derived from this software |
| vpcola | 0:a1734fe1ec4b | 22 | * without specific prior written permission. |
| vpcola | 0:a1734fe1ec4b | 23 | * |
| vpcola | 0:a1734fe1ec4b | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| vpcola | 0:a1734fe1ec4b | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| vpcola | 0:a1734fe1ec4b | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| vpcola | 0:a1734fe1ec4b | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| vpcola | 0:a1734fe1ec4b | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| vpcola | 0:a1734fe1ec4b | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| vpcola | 0:a1734fe1ec4b | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| vpcola | 0:a1734fe1ec4b | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| vpcola | 0:a1734fe1ec4b | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| vpcola | 0:a1734fe1ec4b | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| vpcola | 0:a1734fe1ec4b | 34 | * |
| vpcola | 0:a1734fe1ec4b | 35 | ****************************************************************************** |
| vpcola | 0:a1734fe1ec4b | 36 | */ |
| vpcola | 0:a1734fe1ec4b | 37 | |
| vpcola | 0:a1734fe1ec4b | 38 | /* Includes ------------------------------------------------------------------*/ |
| vpcola | 0:a1734fe1ec4b | 39 | #include "SPIRIT_Csma.h" |
| vpcola | 0:a1734fe1ec4b | 40 | #include "MCU_Interface.h" |
| vpcola | 0:a1734fe1ec4b | 41 | |
| vpcola | 0:a1734fe1ec4b | 42 | |
| vpcola | 0:a1734fe1ec4b | 43 | /** |
| vpcola | 0:a1734fe1ec4b | 44 | * @addtogroup SPIRIT_Libraries |
| vpcola | 0:a1734fe1ec4b | 45 | * @{ |
| vpcola | 0:a1734fe1ec4b | 46 | */ |
| vpcola | 0:a1734fe1ec4b | 47 | |
| vpcola | 0:a1734fe1ec4b | 48 | |
| vpcola | 0:a1734fe1ec4b | 49 | /** |
| vpcola | 0:a1734fe1ec4b | 50 | * @addtogroup SPIRIT_Csma |
| vpcola | 0:a1734fe1ec4b | 51 | * @{ |
| vpcola | 0:a1734fe1ec4b | 52 | */ |
| vpcola | 0:a1734fe1ec4b | 53 | |
| vpcola | 0:a1734fe1ec4b | 54 | |
| vpcola | 0:a1734fe1ec4b | 55 | /** |
| vpcola | 0:a1734fe1ec4b | 56 | * @defgroup Csma_Private_TypesDefinitions CSMA Private TypesDefinitions |
| vpcola | 0:a1734fe1ec4b | 57 | * @{ |
| vpcola | 0:a1734fe1ec4b | 58 | */ |
| vpcola | 0:a1734fe1ec4b | 59 | |
| vpcola | 0:a1734fe1ec4b | 60 | |
| vpcola | 0:a1734fe1ec4b | 61 | /** |
| vpcola | 0:a1734fe1ec4b | 62 | *@} |
| vpcola | 0:a1734fe1ec4b | 63 | */ |
| vpcola | 0:a1734fe1ec4b | 64 | |
| vpcola | 0:a1734fe1ec4b | 65 | |
| vpcola | 0:a1734fe1ec4b | 66 | /** |
| vpcola | 0:a1734fe1ec4b | 67 | * @defgroup Csma_Private_Defines CSMA Private Defines |
| vpcola | 0:a1734fe1ec4b | 68 | * @{ |
| vpcola | 0:a1734fe1ec4b | 69 | */ |
| vpcola | 0:a1734fe1ec4b | 70 | |
| vpcola | 0:a1734fe1ec4b | 71 | /** |
| vpcola | 0:a1734fe1ec4b | 72 | *@} |
| vpcola | 0:a1734fe1ec4b | 73 | */ |
| vpcola | 0:a1734fe1ec4b | 74 | |
| vpcola | 0:a1734fe1ec4b | 75 | |
| vpcola | 0:a1734fe1ec4b | 76 | /** |
| vpcola | 0:a1734fe1ec4b | 77 | * @defgroup Csma_Private_Macros CSMA Private Macros |
| vpcola | 0:a1734fe1ec4b | 78 | * @{ |
| vpcola | 0:a1734fe1ec4b | 79 | */ |
| vpcola | 0:a1734fe1ec4b | 80 | |
| vpcola | 0:a1734fe1ec4b | 81 | /** |
| vpcola | 0:a1734fe1ec4b | 82 | *@} |
| vpcola | 0:a1734fe1ec4b | 83 | */ |
| vpcola | 0:a1734fe1ec4b | 84 | |
| vpcola | 0:a1734fe1ec4b | 85 | |
| vpcola | 0:a1734fe1ec4b | 86 | /** |
| vpcola | 0:a1734fe1ec4b | 87 | * @defgroup Csma_Private_Variables CSMA Private Variables |
| vpcola | 0:a1734fe1ec4b | 88 | * @{ |
| vpcola | 0:a1734fe1ec4b | 89 | */ |
| vpcola | 0:a1734fe1ec4b | 90 | |
| vpcola | 0:a1734fe1ec4b | 91 | /** |
| vpcola | 0:a1734fe1ec4b | 92 | *@} |
| vpcola | 0:a1734fe1ec4b | 93 | */ |
| vpcola | 0:a1734fe1ec4b | 94 | |
| vpcola | 0:a1734fe1ec4b | 95 | |
| vpcola | 0:a1734fe1ec4b | 96 | |
| vpcola | 0:a1734fe1ec4b | 97 | /** |
| vpcola | 0:a1734fe1ec4b | 98 | * @defgroup Csma_Private_FunctionPrototypes CSMA Private FunctionPrototypes |
| vpcola | 0:a1734fe1ec4b | 99 | * @{ |
| vpcola | 0:a1734fe1ec4b | 100 | */ |
| vpcola | 0:a1734fe1ec4b | 101 | |
| vpcola | 0:a1734fe1ec4b | 102 | /** |
| vpcola | 0:a1734fe1ec4b | 103 | *@} |
| vpcola | 0:a1734fe1ec4b | 104 | */ |
| vpcola | 0:a1734fe1ec4b | 105 | |
| vpcola | 0:a1734fe1ec4b | 106 | |
| vpcola | 0:a1734fe1ec4b | 107 | /** |
| vpcola | 0:a1734fe1ec4b | 108 | * @defgroup Csma_Private_Functions CSMA Private Functions |
| vpcola | 0:a1734fe1ec4b | 109 | * @{ |
| vpcola | 0:a1734fe1ec4b | 110 | */ |
| vpcola | 0:a1734fe1ec4b | 111 | |
| vpcola | 0:a1734fe1ec4b | 112 | |
| vpcola | 0:a1734fe1ec4b | 113 | /** |
| vpcola | 0:a1734fe1ec4b | 114 | * @brief Initializes the SPIRIT CSMA according to the specified parameters in the CsmaInit. |
| vpcola | 0:a1734fe1ec4b | 115 | * @param pxCsmaInit Csma init structure. |
| vpcola | 0:a1734fe1ec4b | 116 | * This parameter is a pointer to @ref CsmaInit. |
| vpcola | 0:a1734fe1ec4b | 117 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 118 | */ |
| vpcola | 0:a1734fe1ec4b | 119 | void SpiritCsmaInit(CsmaInit* pxCsmaInit) |
| vpcola | 0:a1734fe1ec4b | 120 | { |
| vpcola | 0:a1734fe1ec4b | 121 | uint8_t tempRegValue[5]; |
| vpcola | 0:a1734fe1ec4b | 122 | |
| vpcola | 0:a1734fe1ec4b | 123 | /* Check the parameters */ |
| vpcola | 0:a1734fe1ec4b | 124 | s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxCsmaInit->xCsmaPersistentMode)); |
| vpcola | 0:a1734fe1ec4b | 125 | s_assert_param(IS_CCA_PERIOD(pxCsmaInit->xMultiplierTbit)); |
| vpcola | 0:a1734fe1ec4b | 126 | s_assert_param(IS_CSMA_LENGTH(pxCsmaInit->xCcaLength)); |
| vpcola | 0:a1734fe1ec4b | 127 | s_assert_param(IS_BU_COUNTER_SEED(pxCsmaInit->nBuCounterSeed)); |
| vpcola | 0:a1734fe1ec4b | 128 | s_assert_param(IS_BU_PRESCALER(pxCsmaInit->cBuPrescaler)); |
| vpcola | 0:a1734fe1ec4b | 129 | s_assert_param(IS_CMAX_NB(pxCsmaInit->cMaxNb)); |
| vpcola | 0:a1734fe1ec4b | 130 | |
| vpcola | 0:a1734fe1ec4b | 131 | /* CSMA BU counter seed (MSB) config */ |
| vpcola | 0:a1734fe1ec4b | 132 | tempRegValue[0] = (uint8_t)(pxCsmaInit->nBuCounterSeed >> 8); |
| vpcola | 0:a1734fe1ec4b | 133 | |
| vpcola | 0:a1734fe1ec4b | 134 | /* CSMA BU counter seed (LSB) config */ |
| vpcola | 0:a1734fe1ec4b | 135 | tempRegValue[1] = (uint8_t) pxCsmaInit->nBuCounterSeed; |
| vpcola | 0:a1734fe1ec4b | 136 | |
| vpcola | 0:a1734fe1ec4b | 137 | /* CSMA BU prescaler config and CCA period config */ |
| vpcola | 0:a1734fe1ec4b | 138 | tempRegValue[2] = (pxCsmaInit->cBuPrescaler << 2) | pxCsmaInit->xMultiplierTbit; |
| vpcola | 0:a1734fe1ec4b | 139 | |
| vpcola | 0:a1734fe1ec4b | 140 | /* CSMA CCA length config and max number of back-off */ |
| vpcola | 0:a1734fe1ec4b | 141 | tempRegValue[3] = (pxCsmaInit->xCcaLength | pxCsmaInit->cMaxNb); |
| vpcola | 0:a1734fe1ec4b | 142 | |
| vpcola | 0:a1734fe1ec4b | 143 | /* Reads the PROTOCOL1_BASE register value, to write the SEED_RELOAD and CSMA_PERS_ON fields */ |
| vpcola | 0:a1734fe1ec4b | 144 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue[4]); |
| vpcola | 0:a1734fe1ec4b | 145 | |
| vpcola | 0:a1734fe1ec4b | 146 | /* Writes the new value for persistent mode */ |
| vpcola | 0:a1734fe1ec4b | 147 | if(pxCsmaInit->xCsmaPersistentMode==S_ENABLE) |
| vpcola | 0:a1734fe1ec4b | 148 | { |
| vpcola | 0:a1734fe1ec4b | 149 | tempRegValue[4] |= PROTOCOL1_CSMA_PERS_ON_MASK; |
| vpcola | 0:a1734fe1ec4b | 150 | } |
| vpcola | 0:a1734fe1ec4b | 151 | else |
| vpcola | 0:a1734fe1ec4b | 152 | { |
| vpcola | 0:a1734fe1ec4b | 153 | tempRegValue[4] &= ~PROTOCOL1_CSMA_PERS_ON_MASK; |
| vpcola | 0:a1734fe1ec4b | 154 | } |
| vpcola | 0:a1734fe1ec4b | 155 | |
| vpcola | 0:a1734fe1ec4b | 156 | /* Writes PROTOCOL1_BASE register */ |
| vpcola | 0:a1734fe1ec4b | 157 | g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue[4]); |
| vpcola | 0:a1734fe1ec4b | 158 | |
| vpcola | 0:a1734fe1ec4b | 159 | /* Writes CSMA_CONFIGx_BASE registers */ |
| vpcola | 0:a1734fe1ec4b | 160 | g_xStatus = SpiritSpiWriteRegisters(CSMA_CONFIG3_BASE, 4, tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 161 | |
| vpcola | 0:a1734fe1ec4b | 162 | } |
| vpcola | 0:a1734fe1ec4b | 163 | |
| vpcola | 0:a1734fe1ec4b | 164 | |
| vpcola | 0:a1734fe1ec4b | 165 | /** |
| vpcola | 0:a1734fe1ec4b | 166 | * @brief Returns the fitted structure CsmaInit starting from the registers values. |
| vpcola | 0:a1734fe1ec4b | 167 | * @param pxCsmaInit Csma structure to be fitted. |
| vpcola | 0:a1734fe1ec4b | 168 | * This parameter is a pointer to @ref CsmaInit. |
| vpcola | 0:a1734fe1ec4b | 169 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 170 | */ |
| vpcola | 0:a1734fe1ec4b | 171 | void SpiritCsmaGetInfo(CsmaInit* pxCsmaInit) |
| vpcola | 0:a1734fe1ec4b | 172 | { |
| vpcola | 0:a1734fe1ec4b | 173 | uint8_t tempRegValue[5]; |
| vpcola | 0:a1734fe1ec4b | 174 | |
| vpcola | 0:a1734fe1ec4b | 175 | /* Reads PROTOCOL1_BASE register */ |
| vpcola | 0:a1734fe1ec4b | 176 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue[4]); |
| vpcola | 0:a1734fe1ec4b | 177 | |
| vpcola | 0:a1734fe1ec4b | 178 | /* Reads CSMA_CONFIGx_BASE registers */ |
| vpcola | 0:a1734fe1ec4b | 179 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG3_BASE, 4, tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 180 | |
| vpcola | 0:a1734fe1ec4b | 181 | /* Reads the bu counter seed */ |
| vpcola | 0:a1734fe1ec4b | 182 | pxCsmaInit->nBuCounterSeed = (uint16_t)tempRegValue[1] | ((uint16_t)(tempRegValue[0] << 8)); |
| vpcola | 0:a1734fe1ec4b | 183 | |
| vpcola | 0:a1734fe1ec4b | 184 | /* Reads the bu prescaler */ |
| vpcola | 0:a1734fe1ec4b | 185 | pxCsmaInit->cBuPrescaler = tempRegValue[2]>>2; |
| vpcola | 0:a1734fe1ec4b | 186 | |
| vpcola | 0:a1734fe1ec4b | 187 | /* Reads the Cca period */ |
| vpcola | 0:a1734fe1ec4b | 188 | pxCsmaInit->xMultiplierTbit = (CcaPeriod)(tempRegValue[2] & 0x03); |
| vpcola | 0:a1734fe1ec4b | 189 | |
| vpcola | 0:a1734fe1ec4b | 190 | /* Reads the Cca length */ |
| vpcola | 0:a1734fe1ec4b | 191 | pxCsmaInit->xCcaLength = (CsmaLength)(tempRegValue[3]&0xF0); |
| vpcola | 0:a1734fe1ec4b | 192 | |
| vpcola | 0:a1734fe1ec4b | 193 | /* Reads the max number of back off */ |
| vpcola | 0:a1734fe1ec4b | 194 | pxCsmaInit->cMaxNb = tempRegValue[3] & 0x07; |
| vpcola | 0:a1734fe1ec4b | 195 | |
| vpcola | 0:a1734fe1ec4b | 196 | /* Reads the persistent mode enable bit */ |
| vpcola | 0:a1734fe1ec4b | 197 | pxCsmaInit->xCsmaPersistentMode = (SpiritFunctionalState)((tempRegValue[4]>>1) & 0x01); |
| vpcola | 0:a1734fe1ec4b | 198 | |
| vpcola | 0:a1734fe1ec4b | 199 | } |
| vpcola | 0:a1734fe1ec4b | 200 | |
| vpcola | 0:a1734fe1ec4b | 201 | |
| vpcola | 0:a1734fe1ec4b | 202 | /** |
| vpcola | 0:a1734fe1ec4b | 203 | * @brief Enables or Disables the CSMA. |
| vpcola | 0:a1734fe1ec4b | 204 | * @param xNewState the state of the CSMA mode. |
| vpcola | 0:a1734fe1ec4b | 205 | * This parameter can be: S_ENABLE or S_DISABLE. |
| vpcola | 0:a1734fe1ec4b | 206 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 207 | */ |
| vpcola | 0:a1734fe1ec4b | 208 | void SpiritCsma(SpiritFunctionalState xNewState) |
| vpcola | 0:a1734fe1ec4b | 209 | { |
| vpcola | 0:a1734fe1ec4b | 210 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 211 | |
| vpcola | 0:a1734fe1ec4b | 212 | /* Check the parameters */ |
| vpcola | 0:a1734fe1ec4b | 213 | s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); |
| vpcola | 0:a1734fe1ec4b | 214 | |
| vpcola | 0:a1734fe1ec4b | 215 | /* Reads the PROTOCOL1 register value */ |
| vpcola | 0:a1734fe1ec4b | 216 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 217 | |
| vpcola | 0:a1734fe1ec4b | 218 | /* Sets or resets the CSMA enable bit */ |
| vpcola | 0:a1734fe1ec4b | 219 | if(xNewState==S_ENABLE) |
| vpcola | 0:a1734fe1ec4b | 220 | { |
| vpcola | 0:a1734fe1ec4b | 221 | tempRegValue |= PROTOCOL1_CSMA_ON_MASK; |
| vpcola | 0:a1734fe1ec4b | 222 | } |
| vpcola | 0:a1734fe1ec4b | 223 | else |
| vpcola | 0:a1734fe1ec4b | 224 | { |
| vpcola | 0:a1734fe1ec4b | 225 | tempRegValue &= ~PROTOCOL1_CSMA_ON_MASK; |
| vpcola | 0:a1734fe1ec4b | 226 | } |
| vpcola | 0:a1734fe1ec4b | 227 | |
| vpcola | 0:a1734fe1ec4b | 228 | /* Writes the new value on the PROTOCOL1 register */ |
| vpcola | 0:a1734fe1ec4b | 229 | g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 230 | |
| vpcola | 0:a1734fe1ec4b | 231 | } |
| vpcola | 0:a1734fe1ec4b | 232 | |
| vpcola | 0:a1734fe1ec4b | 233 | /** |
| vpcola | 0:a1734fe1ec4b | 234 | * @brief Gets the CSMA mode. Says if it is enabled or disabled. |
| vpcola | 0:a1734fe1ec4b | 235 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 236 | * @retval SpiritFunctionalState: CSMA mode. |
| vpcola | 0:a1734fe1ec4b | 237 | */ |
| vpcola | 0:a1734fe1ec4b | 238 | SpiritFunctionalState SpiritCsmaGetCsma(void) |
| vpcola | 0:a1734fe1ec4b | 239 | { |
| vpcola | 0:a1734fe1ec4b | 240 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 241 | |
| vpcola | 0:a1734fe1ec4b | 242 | /* Reads the PROTOCOL1 register value */ |
| vpcola | 0:a1734fe1ec4b | 243 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 244 | |
| vpcola | 0:a1734fe1ec4b | 245 | /* Return if set or reset */ |
| vpcola | 0:a1734fe1ec4b | 246 | if(tempRegValue & PROTOCOL1_CSMA_ON_MASK) |
| vpcola | 0:a1734fe1ec4b | 247 | { |
| vpcola | 0:a1734fe1ec4b | 248 | return S_ENABLE; |
| vpcola | 0:a1734fe1ec4b | 249 | } |
| vpcola | 0:a1734fe1ec4b | 250 | else |
| vpcola | 0:a1734fe1ec4b | 251 | { |
| vpcola | 0:a1734fe1ec4b | 252 | return S_DISABLE; |
| vpcola | 0:a1734fe1ec4b | 253 | } |
| vpcola | 0:a1734fe1ec4b | 254 | |
| vpcola | 0:a1734fe1ec4b | 255 | } |
| vpcola | 0:a1734fe1ec4b | 256 | |
| vpcola | 0:a1734fe1ec4b | 257 | /** |
| vpcola | 0:a1734fe1ec4b | 258 | * @brief Enables or Disables the persistent CSMA mode. |
| vpcola | 0:a1734fe1ec4b | 259 | * @param xNewState the state of the persistent CSMA mode. |
| vpcola | 0:a1734fe1ec4b | 260 | * This parameter can be: S_ENABLE or S_DISABLE. |
| vpcola | 0:a1734fe1ec4b | 261 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 262 | */ |
| vpcola | 0:a1734fe1ec4b | 263 | void SpiritCsmaPersistentMode(SpiritFunctionalState xNewState) |
| vpcola | 0:a1734fe1ec4b | 264 | { |
| vpcola | 0:a1734fe1ec4b | 265 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 266 | |
| vpcola | 0:a1734fe1ec4b | 267 | /* Check the parameters */ |
| vpcola | 0:a1734fe1ec4b | 268 | s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); |
| vpcola | 0:a1734fe1ec4b | 269 | |
| vpcola | 0:a1734fe1ec4b | 270 | /* Reads the PROTOCOL1 register value */ |
| vpcola | 0:a1734fe1ec4b | 271 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 272 | |
| vpcola | 0:a1734fe1ec4b | 273 | /* Enables/disables the CSMA persistent mode */ |
| vpcola | 0:a1734fe1ec4b | 274 | if(xNewState==S_ENABLE) |
| vpcola | 0:a1734fe1ec4b | 275 | { |
| vpcola | 0:a1734fe1ec4b | 276 | tempRegValue |= PROTOCOL1_CSMA_PERS_ON_MASK; |
| vpcola | 0:a1734fe1ec4b | 277 | } |
| vpcola | 0:a1734fe1ec4b | 278 | else |
| vpcola | 0:a1734fe1ec4b | 279 | { |
| vpcola | 0:a1734fe1ec4b | 280 | tempRegValue &= ~PROTOCOL1_CSMA_PERS_ON_MASK; |
| vpcola | 0:a1734fe1ec4b | 281 | } |
| vpcola | 0:a1734fe1ec4b | 282 | |
| vpcola | 0:a1734fe1ec4b | 283 | /* Writes the new vaue on the PROTOCOL1 register */ |
| vpcola | 0:a1734fe1ec4b | 284 | g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 285 | |
| vpcola | 0:a1734fe1ec4b | 286 | } |
| vpcola | 0:a1734fe1ec4b | 287 | |
| vpcola | 0:a1734fe1ec4b | 288 | |
| vpcola | 0:a1734fe1ec4b | 289 | /** |
| vpcola | 0:a1734fe1ec4b | 290 | * @brief Gets the persistent CSMA mode. |
| vpcola | 0:a1734fe1ec4b | 291 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 292 | * @retval SpiritFunctionalState: CSMA persistent mode. |
| vpcola | 0:a1734fe1ec4b | 293 | */ |
| vpcola | 0:a1734fe1ec4b | 294 | SpiritFunctionalState SpiritCsmaGetPersistentMode(void) |
| vpcola | 0:a1734fe1ec4b | 295 | { |
| vpcola | 0:a1734fe1ec4b | 296 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 297 | |
| vpcola | 0:a1734fe1ec4b | 298 | /* Reads the PROTOCOL1 register value */ |
| vpcola | 0:a1734fe1ec4b | 299 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 300 | |
| vpcola | 0:a1734fe1ec4b | 301 | /* Return if set or reset */ |
| vpcola | 0:a1734fe1ec4b | 302 | if(tempRegValue & PROTOCOL1_CSMA_PERS_ON_MASK) |
| vpcola | 0:a1734fe1ec4b | 303 | { |
| vpcola | 0:a1734fe1ec4b | 304 | return S_ENABLE; |
| vpcola | 0:a1734fe1ec4b | 305 | } |
| vpcola | 0:a1734fe1ec4b | 306 | else |
| vpcola | 0:a1734fe1ec4b | 307 | { |
| vpcola | 0:a1734fe1ec4b | 308 | return S_DISABLE; |
| vpcola | 0:a1734fe1ec4b | 309 | } |
| vpcola | 0:a1734fe1ec4b | 310 | |
| vpcola | 0:a1734fe1ec4b | 311 | } |
| vpcola | 0:a1734fe1ec4b | 312 | |
| vpcola | 0:a1734fe1ec4b | 313 | |
| vpcola | 0:a1734fe1ec4b | 314 | /** |
| vpcola | 0:a1734fe1ec4b | 315 | * @brief Enables or Disables the seed reload mode (if enabled it reloads the back-off generator seed using the value written in the BU_COUNTER_SEED register). |
| vpcola | 0:a1734fe1ec4b | 316 | * @param xNewState the state of the seed reload mode. |
| vpcola | 0:a1734fe1ec4b | 317 | * This parameter can be: S_ENABLE or S_DISABLE. |
| vpcola | 0:a1734fe1ec4b | 318 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 319 | */ |
| vpcola | 0:a1734fe1ec4b | 320 | void SpiritCsmaSeedReloadMode(SpiritFunctionalState xNewState) |
| vpcola | 0:a1734fe1ec4b | 321 | { |
| vpcola | 0:a1734fe1ec4b | 322 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 323 | |
| vpcola | 0:a1734fe1ec4b | 324 | /* Check the parameters */ |
| vpcola | 0:a1734fe1ec4b | 325 | s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); |
| vpcola | 0:a1734fe1ec4b | 326 | |
| vpcola | 0:a1734fe1ec4b | 327 | /* Reads the PROTOCOL1 register value */ |
| vpcola | 0:a1734fe1ec4b | 328 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 329 | |
| vpcola | 0:a1734fe1ec4b | 330 | /* Enables/disables the seed reload mode */ |
| vpcola | 0:a1734fe1ec4b | 331 | if(xNewState==S_ENABLE) |
| vpcola | 0:a1734fe1ec4b | 332 | { |
| vpcola | 0:a1734fe1ec4b | 333 | tempRegValue |= PROTOCOL1_SEED_RELOAD_MASK; |
| vpcola | 0:a1734fe1ec4b | 334 | } |
| vpcola | 0:a1734fe1ec4b | 335 | else |
| vpcola | 0:a1734fe1ec4b | 336 | { |
| vpcola | 0:a1734fe1ec4b | 337 | tempRegValue &= ~PROTOCOL1_SEED_RELOAD_MASK; |
| vpcola | 0:a1734fe1ec4b | 338 | } |
| vpcola | 0:a1734fe1ec4b | 339 | |
| vpcola | 0:a1734fe1ec4b | 340 | /* Writes the new value on the PROTOCOL1 register */ |
| vpcola | 0:a1734fe1ec4b | 341 | g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 342 | |
| vpcola | 0:a1734fe1ec4b | 343 | } |
| vpcola | 0:a1734fe1ec4b | 344 | |
| vpcola | 0:a1734fe1ec4b | 345 | |
| vpcola | 0:a1734fe1ec4b | 346 | /** |
| vpcola | 0:a1734fe1ec4b | 347 | * @brief Gets the seed reload mode. |
| vpcola | 0:a1734fe1ec4b | 348 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 349 | * @retval SpiritFunctionalState: CSMA seed reload mode. |
| vpcola | 0:a1734fe1ec4b | 350 | */ |
| vpcola | 0:a1734fe1ec4b | 351 | SpiritFunctionalState SpiritCsmaGetSeedReloadMode(void) |
| vpcola | 0:a1734fe1ec4b | 352 | { |
| vpcola | 0:a1734fe1ec4b | 353 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 354 | |
| vpcola | 0:a1734fe1ec4b | 355 | /* Reads the PROTOCOL1 register value */ |
| vpcola | 0:a1734fe1ec4b | 356 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 357 | |
| vpcola | 0:a1734fe1ec4b | 358 | /* Return if set or reset */ |
| vpcola | 0:a1734fe1ec4b | 359 | if(tempRegValue & PROTOCOL1_SEED_RELOAD_MASK) |
| vpcola | 0:a1734fe1ec4b | 360 | { |
| vpcola | 0:a1734fe1ec4b | 361 | return S_ENABLE; |
| vpcola | 0:a1734fe1ec4b | 362 | } |
| vpcola | 0:a1734fe1ec4b | 363 | else |
| vpcola | 0:a1734fe1ec4b | 364 | { |
| vpcola | 0:a1734fe1ec4b | 365 | return S_DISABLE; |
| vpcola | 0:a1734fe1ec4b | 366 | } |
| vpcola | 0:a1734fe1ec4b | 367 | } |
| vpcola | 0:a1734fe1ec4b | 368 | |
| vpcola | 0:a1734fe1ec4b | 369 | |
| vpcola | 0:a1734fe1ec4b | 370 | /** |
| vpcola | 0:a1734fe1ec4b | 371 | * @brief Sets the BU counter seed (BU_COUNTER_SEED register). The CSMA back off time is given by the formula: BO = rand(2^NB)*BU. |
| vpcola | 0:a1734fe1ec4b | 372 | * @param nBuCounterSeed seed of the random number generator used to apply the BBE algorithm. |
| vpcola | 0:a1734fe1ec4b | 373 | * This parameter is an uint16_t. |
| vpcola | 0:a1734fe1ec4b | 374 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 375 | */ |
| vpcola | 0:a1734fe1ec4b | 376 | void SpiritCsmaSetBuCounterSeed(uint16_t nBuCounterSeed) |
| vpcola | 0:a1734fe1ec4b | 377 | { |
| vpcola | 0:a1734fe1ec4b | 378 | uint8_t tempRegValue[2]; |
| vpcola | 0:a1734fe1ec4b | 379 | |
| vpcola | 0:a1734fe1ec4b | 380 | /* Check parameters */ |
| vpcola | 0:a1734fe1ec4b | 381 | s_assert_param(IS_BU_COUNTER_SEED(nBuCounterSeed)); |
| vpcola | 0:a1734fe1ec4b | 382 | |
| vpcola | 0:a1734fe1ec4b | 383 | /* Build value (MSB)*/ |
| vpcola | 0:a1734fe1ec4b | 384 | tempRegValue[0]=(uint8_t)(nBuCounterSeed>>8); |
| vpcola | 0:a1734fe1ec4b | 385 | /* Build value (LSB) */ |
| vpcola | 0:a1734fe1ec4b | 386 | tempRegValue[1]=(uint8_t)nBuCounterSeed; |
| vpcola | 0:a1734fe1ec4b | 387 | |
| vpcola | 0:a1734fe1ec4b | 388 | /* Writes the CSMA_CONFIG3 registers */ |
| vpcola | 0:a1734fe1ec4b | 389 | g_xStatus = SpiritSpiWriteRegisters(CSMA_CONFIG3_BASE, 2, tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 390 | |
| vpcola | 0:a1734fe1ec4b | 391 | } |
| vpcola | 0:a1734fe1ec4b | 392 | |
| vpcola | 0:a1734fe1ec4b | 393 | /** |
| vpcola | 0:a1734fe1ec4b | 394 | * @brief Returns the BU counter seed (BU_COUNTER_SEED register). |
| vpcola | 0:a1734fe1ec4b | 395 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 396 | * @retval uint16_t Seed of the random number generator used to apply the BBE algorithm. |
| vpcola | 0:a1734fe1ec4b | 397 | */ |
| vpcola | 0:a1734fe1ec4b | 398 | uint16_t SpiritCsmaGetBuCounterSeed(void) |
| vpcola | 0:a1734fe1ec4b | 399 | { |
| vpcola | 0:a1734fe1ec4b | 400 | uint8_t tempRegValue[2]; |
| vpcola | 0:a1734fe1ec4b | 401 | |
| vpcola | 0:a1734fe1ec4b | 402 | /* Reads the CSMA_CONFIGx registers value */ |
| vpcola | 0:a1734fe1ec4b | 403 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG3_BASE, 2, tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 404 | |
| vpcola | 0:a1734fe1ec4b | 405 | /* Build the counter seed and return it */ |
| vpcola | 0:a1734fe1ec4b | 406 | return ((uint16_t)tempRegValue[1] + (((uint16_t)tempRegValue[0])<<8)); |
| vpcola | 0:a1734fe1ec4b | 407 | |
| vpcola | 0:a1734fe1ec4b | 408 | } |
| vpcola | 0:a1734fe1ec4b | 409 | |
| vpcola | 0:a1734fe1ec4b | 410 | |
| vpcola | 0:a1734fe1ec4b | 411 | /** |
| vpcola | 0:a1734fe1ec4b | 412 | * @brief Sets the BU prescaler. The CSMA back off time is given by the formula: BO = rand(2^NB)*BU. |
| vpcola | 0:a1734fe1ec4b | 413 | * @param cBuPrescaler used to program the back-off unit BU. |
| vpcola | 0:a1734fe1ec4b | 414 | * This parameter is an uint8_t. |
| vpcola | 0:a1734fe1ec4b | 415 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 416 | */ |
| vpcola | 0:a1734fe1ec4b | 417 | void SpiritCsmaSetBuPrescaler(uint8_t cBuPrescaler) |
| vpcola | 0:a1734fe1ec4b | 418 | { |
| vpcola | 0:a1734fe1ec4b | 419 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 420 | |
| vpcola | 0:a1734fe1ec4b | 421 | /* Check parameters */ |
| vpcola | 0:a1734fe1ec4b | 422 | s_assert_param(IS_BU_PRESCALER(cBuPrescaler)); |
| vpcola | 0:a1734fe1ec4b | 423 | |
| vpcola | 0:a1734fe1ec4b | 424 | /* Reads the CSMA_CONFIG1 register value */ |
| vpcola | 0:a1734fe1ec4b | 425 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 426 | |
| vpcola | 0:a1734fe1ec4b | 427 | /* Build the new value for the BU prescaler */ |
| vpcola | 0:a1734fe1ec4b | 428 | tempRegValue &= 0x03; |
| vpcola | 0:a1734fe1ec4b | 429 | tempRegValue |= (cBuPrescaler<<2); |
| vpcola | 0:a1734fe1ec4b | 430 | |
| vpcola | 0:a1734fe1ec4b | 431 | /* Writes the new value on the CSMA_CONFIG1_BASE register */ |
| vpcola | 0:a1734fe1ec4b | 432 | g_xStatus = SpiritSpiWriteRegisters(CSMA_CONFIG1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 433 | |
| vpcola | 0:a1734fe1ec4b | 434 | } |
| vpcola | 0:a1734fe1ec4b | 435 | |
| vpcola | 0:a1734fe1ec4b | 436 | |
| vpcola | 0:a1734fe1ec4b | 437 | /** |
| vpcola | 0:a1734fe1ec4b | 438 | * @brief Returns the BU prescaler. |
| vpcola | 0:a1734fe1ec4b | 439 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 440 | * @retval uint8_t Value back-off unit (BU). |
| vpcola | 0:a1734fe1ec4b | 441 | */ |
| vpcola | 0:a1734fe1ec4b | 442 | uint8_t SpiritCsmaGetBuPrescaler(void) |
| vpcola | 0:a1734fe1ec4b | 443 | { |
| vpcola | 0:a1734fe1ec4b | 444 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 445 | |
| vpcola | 0:a1734fe1ec4b | 446 | /* Reads the CSMA_CONFIG1 register value */ |
| vpcola | 0:a1734fe1ec4b | 447 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 448 | |
| vpcola | 0:a1734fe1ec4b | 449 | /* Build and return the BU prescaler value */ |
| vpcola | 0:a1734fe1ec4b | 450 | return (tempRegValue >> 2); |
| vpcola | 0:a1734fe1ec4b | 451 | |
| vpcola | 0:a1734fe1ec4b | 452 | } |
| vpcola | 0:a1734fe1ec4b | 453 | |
| vpcola | 0:a1734fe1ec4b | 454 | |
| vpcola | 0:a1734fe1ec4b | 455 | /** |
| vpcola | 0:a1734fe1ec4b | 456 | * @brief Sets the CCA period. |
| vpcola | 0:a1734fe1ec4b | 457 | * @param xMultiplierTbit value of CCA period to store. |
| vpcola | 0:a1734fe1ec4b | 458 | * This parameter can be a value of @ref CcaPeriod. |
| vpcola | 0:a1734fe1ec4b | 459 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 460 | */ |
| vpcola | 0:a1734fe1ec4b | 461 | void SpiritCsmaSetCcaPeriod(CcaPeriod xMultiplierTbit) |
| vpcola | 0:a1734fe1ec4b | 462 | { |
| vpcola | 0:a1734fe1ec4b | 463 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 464 | |
| vpcola | 0:a1734fe1ec4b | 465 | /* Check the parameters */ |
| vpcola | 0:a1734fe1ec4b | 466 | s_assert_param(IS_CCA_PERIOD(xMultiplierTbit)); |
| vpcola | 0:a1734fe1ec4b | 467 | |
| vpcola | 0:a1734fe1ec4b | 468 | /* Reads the CSMA_CONFIG1 register value */ |
| vpcola | 0:a1734fe1ec4b | 469 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 470 | |
| vpcola | 0:a1734fe1ec4b | 471 | /* Build the new value setting the the CCA period */ |
| vpcola | 0:a1734fe1ec4b | 472 | tempRegValue &= 0xFC; |
| vpcola | 0:a1734fe1ec4b | 473 | tempRegValue |= xMultiplierTbit; |
| vpcola | 0:a1734fe1ec4b | 474 | |
| vpcola | 0:a1734fe1ec4b | 475 | /* Writes the new value on the CSMA_CONFIG1 register */ |
| vpcola | 0:a1734fe1ec4b | 476 | g_xStatus = SpiritSpiWriteRegisters(CSMA_CONFIG1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 477 | |
| vpcola | 0:a1734fe1ec4b | 478 | } |
| vpcola | 0:a1734fe1ec4b | 479 | |
| vpcola | 0:a1734fe1ec4b | 480 | |
| vpcola | 0:a1734fe1ec4b | 481 | /** |
| vpcola | 0:a1734fe1ec4b | 482 | * @brief Returns the CCA period. |
| vpcola | 0:a1734fe1ec4b | 483 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 484 | * @retval CcaPeriod CCA period. |
| vpcola | 0:a1734fe1ec4b | 485 | */ |
| vpcola | 0:a1734fe1ec4b | 486 | CcaPeriod SpiritCsmaGetCcaPeriod(void) |
| vpcola | 0:a1734fe1ec4b | 487 | { |
| vpcola | 0:a1734fe1ec4b | 488 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 489 | |
| vpcola | 0:a1734fe1ec4b | 490 | /* Reads the CSMA_CONFIG1 register value */ |
| vpcola | 0:a1734fe1ec4b | 491 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG1_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 492 | |
| vpcola | 0:a1734fe1ec4b | 493 | /* Build and return the CCA period value */ |
| vpcola | 0:a1734fe1ec4b | 494 | return (CcaPeriod)(tempRegValue & 0x03); |
| vpcola | 0:a1734fe1ec4b | 495 | |
| vpcola | 0:a1734fe1ec4b | 496 | } |
| vpcola | 0:a1734fe1ec4b | 497 | |
| vpcola | 0:a1734fe1ec4b | 498 | |
| vpcola | 0:a1734fe1ec4b | 499 | /** |
| vpcola | 0:a1734fe1ec4b | 500 | * @brief Sets the CCA length. |
| vpcola | 0:a1734fe1ec4b | 501 | * @param xCcaLength the CCA length (a value between 1 and 15 that multiplies the CCA period). |
| vpcola | 0:a1734fe1ec4b | 502 | * This parameter can be any value of @ref CsmaLength. |
| vpcola | 0:a1734fe1ec4b | 503 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 504 | */ |
| vpcola | 0:a1734fe1ec4b | 505 | void SpiritCsmaSetCcaLength(CsmaLength xCcaLength) |
| vpcola | 0:a1734fe1ec4b | 506 | { |
| vpcola | 0:a1734fe1ec4b | 507 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 508 | |
| vpcola | 0:a1734fe1ec4b | 509 | /* Check the parameters */ |
| vpcola | 0:a1734fe1ec4b | 510 | s_assert_param(IS_CSMA_LENGTH(xCcaLength)); |
| vpcola | 0:a1734fe1ec4b | 511 | |
| vpcola | 0:a1734fe1ec4b | 512 | /* Reads the CSMA_CONFIG0 register value */ |
| vpcola | 0:a1734fe1ec4b | 513 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG0_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 514 | |
| vpcola | 0:a1734fe1ec4b | 515 | /* Build the value of CCA length to be set */ |
| vpcola | 0:a1734fe1ec4b | 516 | tempRegValue &= 0x0F; |
| vpcola | 0:a1734fe1ec4b | 517 | tempRegValue |= xCcaLength; |
| vpcola | 0:a1734fe1ec4b | 518 | |
| vpcola | 0:a1734fe1ec4b | 519 | /* Writes the new value on the CSMA_CONFIG0 register */ |
| vpcola | 0:a1734fe1ec4b | 520 | g_xStatus = SpiritSpiWriteRegisters(CSMA_CONFIG0_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 521 | |
| vpcola | 0:a1734fe1ec4b | 522 | } |
| vpcola | 0:a1734fe1ec4b | 523 | |
| vpcola | 0:a1734fe1ec4b | 524 | |
| vpcola | 0:a1734fe1ec4b | 525 | /** |
| vpcola | 0:a1734fe1ec4b | 526 | * @brief Returns the CCA length. |
| vpcola | 0:a1734fe1ec4b | 527 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 528 | * @retval uint8_t CCA length. |
| vpcola | 0:a1734fe1ec4b | 529 | */ |
| vpcola | 0:a1734fe1ec4b | 530 | uint8_t SpiritCsmaGetCcaLength(void) |
| vpcola | 0:a1734fe1ec4b | 531 | { |
| vpcola | 0:a1734fe1ec4b | 532 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 533 | |
| vpcola | 0:a1734fe1ec4b | 534 | /* Reads the CSMA_CONFIG0 register value */ |
| vpcola | 0:a1734fe1ec4b | 535 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG0_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 536 | |
| vpcola | 0:a1734fe1ec4b | 537 | /* Build and return the CCA length */ |
| vpcola | 0:a1734fe1ec4b | 538 | return tempRegValue >> 4; |
| vpcola | 0:a1734fe1ec4b | 539 | |
| vpcola | 0:a1734fe1ec4b | 540 | } |
| vpcola | 0:a1734fe1ec4b | 541 | |
| vpcola | 0:a1734fe1ec4b | 542 | |
| vpcola | 0:a1734fe1ec4b | 543 | /** |
| vpcola | 0:a1734fe1ec4b | 544 | * @brief Sets the max number of back-off. If reached Spirit stops the transmission. |
| vpcola | 0:a1734fe1ec4b | 545 | * @param cMaxNb the max number of back-off. |
| vpcola | 0:a1734fe1ec4b | 546 | * This parameter is an uint8_t. |
| vpcola | 0:a1734fe1ec4b | 547 | * @retval None. |
| vpcola | 0:a1734fe1ec4b | 548 | */ |
| vpcola | 0:a1734fe1ec4b | 549 | void SpiritCsmaSetMaxNumberBackoff(uint8_t cMaxNb) |
| vpcola | 0:a1734fe1ec4b | 550 | { |
| vpcola | 0:a1734fe1ec4b | 551 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 552 | |
| vpcola | 0:a1734fe1ec4b | 553 | /* Check the parameters */ |
| vpcola | 0:a1734fe1ec4b | 554 | s_assert_param(IS_CMAX_NB(cMaxNb)); |
| vpcola | 0:a1734fe1ec4b | 555 | |
| vpcola | 0:a1734fe1ec4b | 556 | /* Reads the CSMA_CONFIG0 register value */ |
| vpcola | 0:a1734fe1ec4b | 557 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG0_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 558 | |
| vpcola | 0:a1734fe1ec4b | 559 | /* Build the value of max back off to be set */ |
| vpcola | 0:a1734fe1ec4b | 560 | tempRegValue &= 0xF8; |
| vpcola | 0:a1734fe1ec4b | 561 | tempRegValue |= cMaxNb; |
| vpcola | 0:a1734fe1ec4b | 562 | |
| vpcola | 0:a1734fe1ec4b | 563 | /* Writes the new value on the CSMA_CONFIG0 register */ |
| vpcola | 0:a1734fe1ec4b | 564 | g_xStatus = SpiritSpiWriteRegisters(CSMA_CONFIG0_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 565 | } |
| vpcola | 0:a1734fe1ec4b | 566 | |
| vpcola | 0:a1734fe1ec4b | 567 | /** |
| vpcola | 0:a1734fe1ec4b | 568 | * @brief Returns the max number of back-off. |
| vpcola | 0:a1734fe1ec4b | 569 | * @param None. |
| vpcola | 0:a1734fe1ec4b | 570 | * @retval uint8_t Max number of back-off. |
| vpcola | 0:a1734fe1ec4b | 571 | */ |
| vpcola | 0:a1734fe1ec4b | 572 | uint8_t SpiritCsmaGetMaxNumberBackoff(void) |
| vpcola | 0:a1734fe1ec4b | 573 | { |
| vpcola | 0:a1734fe1ec4b | 574 | uint8_t tempRegValue; |
| vpcola | 0:a1734fe1ec4b | 575 | |
| vpcola | 0:a1734fe1ec4b | 576 | /* Reads the CSMA_CONFIG0 register value */ |
| vpcola | 0:a1734fe1ec4b | 577 | g_xStatus = SpiritSpiReadRegisters(CSMA_CONFIG0_BASE, 1, &tempRegValue); |
| vpcola | 0:a1734fe1ec4b | 578 | |
| vpcola | 0:a1734fe1ec4b | 579 | /* Build and return the max number of back-off */ |
| vpcola | 0:a1734fe1ec4b | 580 | return (tempRegValue & 0x07); |
| vpcola | 0:a1734fe1ec4b | 581 | |
| vpcola | 0:a1734fe1ec4b | 582 | } |
| vpcola | 0:a1734fe1ec4b | 583 | |
| vpcola | 0:a1734fe1ec4b | 584 | |
| vpcola | 0:a1734fe1ec4b | 585 | /** |
| vpcola | 0:a1734fe1ec4b | 586 | *@} |
| vpcola | 0:a1734fe1ec4b | 587 | */ |
| vpcola | 0:a1734fe1ec4b | 588 | |
| vpcola | 0:a1734fe1ec4b | 589 | /** |
| vpcola | 0:a1734fe1ec4b | 590 | *@} |
| vpcola | 0:a1734fe1ec4b | 591 | */ |
| vpcola | 0:a1734fe1ec4b | 592 | |
| vpcola | 0:a1734fe1ec4b | 593 | |
| vpcola | 0:a1734fe1ec4b | 594 | /** |
| vpcola | 0:a1734fe1ec4b | 595 | *@} |
| vpcola | 0:a1734fe1ec4b | 596 | */ |
| vpcola | 0:a1734fe1ec4b | 597 | |
| vpcola | 0:a1734fe1ec4b | 598 | |
| vpcola | 0:a1734fe1ec4b | 599 | |
| vpcola | 0:a1734fe1ec4b | 600 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |