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_PktCommon.c
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 the common features of SPIRIT packets.
vpcola 0:f1d3878b8dd9 8 * @details
vpcola 0:f1d3878b8dd9 9 *
vpcola 0:f1d3878b8dd9 10 * @attention
vpcola 0:f1d3878b8dd9 11 *
vpcola 0:f1d3878b8dd9 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
vpcola 0:f1d3878b8dd9 13 *
vpcola 0:f1d3878b8dd9 14 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:f1d3878b8dd9 15 * are permitted provided that the following conditions are met:
vpcola 0:f1d3878b8dd9 16 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:f1d3878b8dd9 17 * this list of conditions and the following disclaimer.
vpcola 0:f1d3878b8dd9 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:f1d3878b8dd9 19 * this list of conditions and the following disclaimer in the documentation
vpcola 0:f1d3878b8dd9 20 * and/or other materials provided with the distribution.
vpcola 0:f1d3878b8dd9 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:f1d3878b8dd9 22 * may be used to endorse or promote products derived from this software
vpcola 0:f1d3878b8dd9 23 * without specific prior written permission.
vpcola 0:f1d3878b8dd9 24 *
vpcola 0:f1d3878b8dd9 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:f1d3878b8dd9 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:f1d3878b8dd9 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:f1d3878b8dd9 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:f1d3878b8dd9 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:f1d3878b8dd9 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:f1d3878b8dd9 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:f1d3878b8dd9 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:f1d3878b8dd9 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:f1d3878b8dd9 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:f1d3878b8dd9 35 *
vpcola 0:f1d3878b8dd9 36 ******************************************************************************
vpcola 0:f1d3878b8dd9 37 */
vpcola 0:f1d3878b8dd9 38
vpcola 0:f1d3878b8dd9 39 /* Includes ------------------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 40 #include "SPIRIT_PktCommon.h"
vpcola 0:f1d3878b8dd9 41 #include "MCU_Interface.h"
vpcola 0:f1d3878b8dd9 42
vpcola 0:f1d3878b8dd9 43
vpcola 0:f1d3878b8dd9 44 /**
vpcola 0:f1d3878b8dd9 45 * @addtogroup SPIRIT_Libraries
vpcola 0:f1d3878b8dd9 46 * @{
vpcola 0:f1d3878b8dd9 47 */
vpcola 0:f1d3878b8dd9 48
vpcola 0:f1d3878b8dd9 49
vpcola 0:f1d3878b8dd9 50 /**
vpcola 0:f1d3878b8dd9 51 * @addtogroup SPIRIT_PktCommon
vpcola 0:f1d3878b8dd9 52 * @{
vpcola 0:f1d3878b8dd9 53 */
vpcola 0:f1d3878b8dd9 54
vpcola 0:f1d3878b8dd9 55
vpcola 0:f1d3878b8dd9 56 /**
vpcola 0:f1d3878b8dd9 57 * @defgroup PktCommon_Private_TypesDefinitions Pkt Common Private Types Definitions
vpcola 0:f1d3878b8dd9 58 * @{
vpcola 0:f1d3878b8dd9 59 */
vpcola 0:f1d3878b8dd9 60
vpcola 0:f1d3878b8dd9 61 /**
vpcola 0:f1d3878b8dd9 62 *@}
vpcola 0:f1d3878b8dd9 63 */
vpcola 0:f1d3878b8dd9 64
vpcola 0:f1d3878b8dd9 65
vpcola 0:f1d3878b8dd9 66 /**
vpcola 0:f1d3878b8dd9 67 * @defgroup PktCommon_Private_Defines Pkt Common Private Defines
vpcola 0:f1d3878b8dd9 68 * @{
vpcola 0:f1d3878b8dd9 69 */
vpcola 0:f1d3878b8dd9 70
vpcola 0:f1d3878b8dd9 71 /**
vpcola 0:f1d3878b8dd9 72 *@}
vpcola 0:f1d3878b8dd9 73 */
vpcola 0:f1d3878b8dd9 74
vpcola 0:f1d3878b8dd9 75
vpcola 0:f1d3878b8dd9 76 /**
vpcola 0:f1d3878b8dd9 77 * @defgroup PktCommon_Private_Macros Pkt Common Private Macros
vpcola 0:f1d3878b8dd9 78 * @{
vpcola 0:f1d3878b8dd9 79 */
vpcola 0:f1d3878b8dd9 80
vpcola 0:f1d3878b8dd9 81 /**
vpcola 0:f1d3878b8dd9 82 *@}
vpcola 0:f1d3878b8dd9 83 */
vpcola 0:f1d3878b8dd9 84
vpcola 0:f1d3878b8dd9 85
vpcola 0:f1d3878b8dd9 86 /**
vpcola 0:f1d3878b8dd9 87 * @defgroup PktCommon_Private_Variables Pkt Common Private Variables
vpcola 0:f1d3878b8dd9 88 * @{
vpcola 0:f1d3878b8dd9 89 */
vpcola 0:f1d3878b8dd9 90
vpcola 0:f1d3878b8dd9 91 /**
vpcola 0:f1d3878b8dd9 92 *@}
vpcola 0:f1d3878b8dd9 93 */
vpcola 0:f1d3878b8dd9 94
vpcola 0:f1d3878b8dd9 95
vpcola 0:f1d3878b8dd9 96
vpcola 0:f1d3878b8dd9 97 /**
vpcola 0:f1d3878b8dd9 98 * @defgroup PktCommon_Private_FunctionPrototypes Pkt Common Private Function Prototypes
vpcola 0:f1d3878b8dd9 99 * @{
vpcola 0:f1d3878b8dd9 100 */
vpcola 0:f1d3878b8dd9 101
vpcola 0:f1d3878b8dd9 102 /**
vpcola 0:f1d3878b8dd9 103 *@}
vpcola 0:f1d3878b8dd9 104 */
vpcola 0:f1d3878b8dd9 105
vpcola 0:f1d3878b8dd9 106
vpcola 0:f1d3878b8dd9 107 /**
vpcola 0:f1d3878b8dd9 108 * @defgroup PktCommon_Private_Functions Pkt Common Private Functions
vpcola 0:f1d3878b8dd9 109 * @{
vpcola 0:f1d3878b8dd9 110 */
vpcola 0:f1d3878b8dd9 111
vpcola 0:f1d3878b8dd9 112 /**
vpcola 0:f1d3878b8dd9 113 * @brief Sets the CONTROL field length for SPIRIT packets.
vpcola 0:f1d3878b8dd9 114 * @param xControlLength length of CONTROL field in bytes.
vpcola 0:f1d3878b8dd9 115 * This parameter can be any value of @ref PktControlLength.
vpcola 0:f1d3878b8dd9 116 * @retval None.
vpcola 0:f1d3878b8dd9 117 */
vpcola 0:f1d3878b8dd9 118 void SpiritPktCommonSetControlLength(PktControlLength xControlLength)
vpcola 0:f1d3878b8dd9 119 {
vpcola 0:f1d3878b8dd9 120 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 121
vpcola 0:f1d3878b8dd9 122 /* Check the parameters */
vpcola 0:f1d3878b8dd9 123 s_assert_param(IS_PKT_CONTROL_LENGTH(xControlLength));
vpcola 0:f1d3878b8dd9 124
vpcola 0:f1d3878b8dd9 125 /* Reads the PCKTCTRL4 register value */
vpcola 0:f1d3878b8dd9 126 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 127
vpcola 0:f1d3878b8dd9 128 /* Set the control length */
vpcola 0:f1d3878b8dd9 129 tempRegValue &= ~PCKTCTRL4_CONTROL_LEN_MASK;
vpcola 0:f1d3878b8dd9 130 tempRegValue |= (uint8_t)xControlLength;
vpcola 0:f1d3878b8dd9 131
vpcola 0:f1d3878b8dd9 132 /* Writes the new value on the PCKTCTRL4 register */
vpcola 0:f1d3878b8dd9 133 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 134 }
vpcola 0:f1d3878b8dd9 135
vpcola 0:f1d3878b8dd9 136
vpcola 0:f1d3878b8dd9 137 /**
vpcola 0:f1d3878b8dd9 138 * @brief Returns the CONTROL field length for SPIRIT packets.
vpcola 0:f1d3878b8dd9 139 * @param None.
vpcola 0:f1d3878b8dd9 140 * @retval uint8_t Control field length.
vpcola 0:f1d3878b8dd9 141 */
vpcola 0:f1d3878b8dd9 142 uint8_t SpiritPktCommonGetControlLength(void)
vpcola 0:f1d3878b8dd9 143 {
vpcola 0:f1d3878b8dd9 144 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 145
vpcola 0:f1d3878b8dd9 146 /* Reads the PCKTCTRL4 register value */
vpcola 0:f1d3878b8dd9 147 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 148
vpcola 0:f1d3878b8dd9 149 /* Rebuild and return value */
vpcola 0:f1d3878b8dd9 150 return (tempRegValue & PCKTCTRL4_CONTROL_LEN_MASK);
vpcola 0:f1d3878b8dd9 151 }
vpcola 0:f1d3878b8dd9 152
vpcola 0:f1d3878b8dd9 153
vpcola 0:f1d3878b8dd9 154 /**
vpcola 0:f1d3878b8dd9 155 * @brief Sets the PREAMBLE field Length mode for SPIRIT packets.
vpcola 0:f1d3878b8dd9 156 * @param xPreambleLength length of PREAMBLE field in bytes.
vpcola 0:f1d3878b8dd9 157 * This parameter can be any value of @ref PktPreambleLength.
vpcola 0:f1d3878b8dd9 158 * @retval None.
vpcola 0:f1d3878b8dd9 159 */
vpcola 0:f1d3878b8dd9 160 void SpiritPktCommonSetPreambleLength(PktPreambleLength xPreambleLength)
vpcola 0:f1d3878b8dd9 161 {
vpcola 0:f1d3878b8dd9 162 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 163
vpcola 0:f1d3878b8dd9 164 /* Check the parameters */
vpcola 0:f1d3878b8dd9 165 s_assert_param(IS_PKT_PREAMBLE_LENGTH(xPreambleLength));
vpcola 0:f1d3878b8dd9 166
vpcola 0:f1d3878b8dd9 167 /* Reads the PCKTCTRL2 register value */
vpcola 0:f1d3878b8dd9 168 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 169
vpcola 0:f1d3878b8dd9 170 /* Set the preamble length */
vpcola 0:f1d3878b8dd9 171 tempRegValue &= ~PCKTCTRL2_PREAMBLE_LENGTH_MASK;
vpcola 0:f1d3878b8dd9 172 tempRegValue |= (uint8_t)xPreambleLength;
vpcola 0:f1d3878b8dd9 173
vpcola 0:f1d3878b8dd9 174 /* Writes the new value on the PCKTCTRL2 register */
vpcola 0:f1d3878b8dd9 175 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 176 }
vpcola 0:f1d3878b8dd9 177
vpcola 0:f1d3878b8dd9 178
vpcola 0:f1d3878b8dd9 179 /**
vpcola 0:f1d3878b8dd9 180 * @brief Returns the PREAMBLE field Length mode for SPIRIT packets.
vpcola 0:f1d3878b8dd9 181 * @param None.
vpcola 0:f1d3878b8dd9 182 * @retval uint8_t Preamble field length in bytes.
vpcola 0:f1d3878b8dd9 183 */
vpcola 0:f1d3878b8dd9 184 uint8_t SpiritPktCommonGetPreambleLength(void)
vpcola 0:f1d3878b8dd9 185 {
vpcola 0:f1d3878b8dd9 186 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 187
vpcola 0:f1d3878b8dd9 188 /* Reads the PCKTCTRL2 register value */
vpcola 0:f1d3878b8dd9 189 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 190
vpcola 0:f1d3878b8dd9 191 /* Rebuild and return value */
vpcola 0:f1d3878b8dd9 192 return ((tempRegValue & PCKTCTRL2_PREAMBLE_LENGTH_MASK)>>3) + 1;
vpcola 0:f1d3878b8dd9 193
vpcola 0:f1d3878b8dd9 194 }
vpcola 0:f1d3878b8dd9 195
vpcola 0:f1d3878b8dd9 196
vpcola 0:f1d3878b8dd9 197 /**
vpcola 0:f1d3878b8dd9 198 * @brief Sets the SYNC field Length for SPIRIT packets.
vpcola 0:f1d3878b8dd9 199 * @param xSyncLength length of SYNC field in bytes.
vpcola 0:f1d3878b8dd9 200 * This parameter can be any value of @ref PktSyncLength.
vpcola 0:f1d3878b8dd9 201 * @retval None.
vpcola 0:f1d3878b8dd9 202 */
vpcola 0:f1d3878b8dd9 203 void SpiritPktCommonSetSyncLength(PktSyncLength xSyncLength)
vpcola 0:f1d3878b8dd9 204 {
vpcola 0:f1d3878b8dd9 205 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 206
vpcola 0:f1d3878b8dd9 207 /* Check the parameters */
vpcola 0:f1d3878b8dd9 208 s_assert_param(IS_PKT_SYNC_LENGTH(xSyncLength));
vpcola 0:f1d3878b8dd9 209
vpcola 0:f1d3878b8dd9 210 /* Reads the PCKTCTRL2 register value */
vpcola 0:f1d3878b8dd9 211 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 212
vpcola 0:f1d3878b8dd9 213 /* Set the sync length */
vpcola 0:f1d3878b8dd9 214 tempRegValue &= ~PCKTCTRL2_SYNC_LENGTH_MASK;
vpcola 0:f1d3878b8dd9 215 tempRegValue |= (uint8_t)xSyncLength;
vpcola 0:f1d3878b8dd9 216
vpcola 0:f1d3878b8dd9 217 /* Writes the new value on the PCKTCTRL2 register */
vpcola 0:f1d3878b8dd9 218 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 219
vpcola 0:f1d3878b8dd9 220 }
vpcola 0:f1d3878b8dd9 221
vpcola 0:f1d3878b8dd9 222
vpcola 0:f1d3878b8dd9 223 /**
vpcola 0:f1d3878b8dd9 224 * @brief Returns the SYNC field Length for SPIRIT packets.
vpcola 0:f1d3878b8dd9 225 * @param None.
vpcola 0:f1d3878b8dd9 226 * @retval uint8_t Sync field length in bytes.
vpcola 0:f1d3878b8dd9 227 */
vpcola 0:f1d3878b8dd9 228 uint8_t SpiritPktCommonGetSyncLength(void)
vpcola 0:f1d3878b8dd9 229 {
vpcola 0:f1d3878b8dd9 230 uint8_t tempRetValue;
vpcola 0:f1d3878b8dd9 231
vpcola 0:f1d3878b8dd9 232 /* Reads the PCKTCTRL2 register value */
vpcola 0:f1d3878b8dd9 233 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRetValue);
vpcola 0:f1d3878b8dd9 234
vpcola 0:f1d3878b8dd9 235 /* Rebuild and return value */
vpcola 0:f1d3878b8dd9 236 return ((tempRetValue & PCKTCTRL2_SYNC_LENGTH_MASK)>>1) + 1;
vpcola 0:f1d3878b8dd9 237
vpcola 0:f1d3878b8dd9 238 }
vpcola 0:f1d3878b8dd9 239
vpcola 0:f1d3878b8dd9 240
vpcola 0:f1d3878b8dd9 241 /**
vpcola 0:f1d3878b8dd9 242 * @brief Sets fixed or variable payload length mode for SPIRIT packets.
vpcola 0:f1d3878b8dd9 243 * @param xFixVarLength variable or fixed length.
vpcola 0:f1d3878b8dd9 244 * PKT_FIXED_LENGTH_VAR -> variable (the length is extracted from the received packet).
vpcola 0:f1d3878b8dd9 245 * PKT_FIXED_LENGTH_FIX -> fix (the length is set by PCKTLEN0 and PCKTLEN1).
vpcola 0:f1d3878b8dd9 246 * @retval None.
vpcola 0:f1d3878b8dd9 247 */
vpcola 0:f1d3878b8dd9 248 void SpiritPktCommonSetFixVarLength(PktFixVarLength xFixVarLength)
vpcola 0:f1d3878b8dd9 249 {
vpcola 0:f1d3878b8dd9 250 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 251
vpcola 0:f1d3878b8dd9 252 /* Check the parameters */
vpcola 0:f1d3878b8dd9 253 s_assert_param(IS_PKT_FIX_VAR_LENGTH(xFixVarLength));
vpcola 0:f1d3878b8dd9 254
vpcola 0:f1d3878b8dd9 255 /* Reads the PCKTCTRL2 register value */
vpcola 0:f1d3878b8dd9 256 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 257
vpcola 0:f1d3878b8dd9 258 /* Set fixed or variable address mode */
vpcola 0:f1d3878b8dd9 259 tempRegValue &= ~PCKTCTRL2_FIX_VAR_LEN_MASK;
vpcola 0:f1d3878b8dd9 260 tempRegValue |= (uint8_t)xFixVarLength;
vpcola 0:f1d3878b8dd9 261
vpcola 0:f1d3878b8dd9 262 /* Writes the new value on the PCKTCTRL2 register */
vpcola 0:f1d3878b8dd9 263 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 264
vpcola 0:f1d3878b8dd9 265 }
vpcola 0:f1d3878b8dd9 266
vpcola 0:f1d3878b8dd9 267
vpcola 0:f1d3878b8dd9 268 /**
vpcola 0:f1d3878b8dd9 269 * @brief Enables or Disables the filtering on CRC.
vpcola 0:f1d3878b8dd9 270 * @param xNewState new state for CRC_CHECK.
vpcola 0:f1d3878b8dd9 271 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 272 * @retval None.
vpcola 0:f1d3878b8dd9 273 */
vpcola 0:f1d3878b8dd9 274 void SpiritPktCommonFilterOnCrc(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 275 {
vpcola 0:f1d3878b8dd9 276 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 277
vpcola 0:f1d3878b8dd9 278 /* Check the parameters */
vpcola 0:f1d3878b8dd9 279 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 280
vpcola 0:f1d3878b8dd9 281 /* Reads the PCKT_FLT_OPTIONS register value */
vpcola 0:f1d3878b8dd9 282 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 283
vpcola 0:f1d3878b8dd9 284 /* Modify the register value: enable or disable the CRC filtering */
vpcola 0:f1d3878b8dd9 285 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 286 {
vpcola 0:f1d3878b8dd9 287 tempRegValue |= PCKT_FLT_OPTIONS_CRC_CHECK_MASK;
vpcola 0:f1d3878b8dd9 288 }
vpcola 0:f1d3878b8dd9 289 else
vpcola 0:f1d3878b8dd9 290 {
vpcola 0:f1d3878b8dd9 291 tempRegValue &= ~PCKT_FLT_OPTIONS_CRC_CHECK_MASK;
vpcola 0:f1d3878b8dd9 292 }
vpcola 0:f1d3878b8dd9 293
vpcola 0:f1d3878b8dd9 294 /* Writes the PCKT_FLT_OPTIONS register value */
vpcola 0:f1d3878b8dd9 295 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 296
vpcola 0:f1d3878b8dd9 297 }
vpcola 0:f1d3878b8dd9 298
vpcola 0:f1d3878b8dd9 299
vpcola 0:f1d3878b8dd9 300 /**
vpcola 0:f1d3878b8dd9 301 * @brief Returns the CRC filtering enable bit.
vpcola 0:f1d3878b8dd9 302 * @param None.
vpcola 0:f1d3878b8dd9 303 * @retval SpiritFunctionalState CRC filtering.
vpcola 0:f1d3878b8dd9 304 */
vpcola 0:f1d3878b8dd9 305 SpiritFunctionalState SpiritPktCommonGetFilterOnCrc(void)
vpcola 0:f1d3878b8dd9 306 {
vpcola 0:f1d3878b8dd9 307 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 308
vpcola 0:f1d3878b8dd9 309
vpcola 0:f1d3878b8dd9 310 /* Reads the PCKT_FLT_OPTIONS register value */
vpcola 0:f1d3878b8dd9 311 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 312
vpcola 0:f1d3878b8dd9 313 /* Check the CRC filtering bit */
vpcola 0:f1d3878b8dd9 314 if(tempRegValue & PCKT_FLT_OPTIONS_CRC_CHECK_MASK)
vpcola 0:f1d3878b8dd9 315 {
vpcola 0:f1d3878b8dd9 316 return S_ENABLE;
vpcola 0:f1d3878b8dd9 317 }
vpcola 0:f1d3878b8dd9 318 else
vpcola 0:f1d3878b8dd9 319 {
vpcola 0:f1d3878b8dd9 320 return S_DISABLE;
vpcola 0:f1d3878b8dd9 321 }
vpcola 0:f1d3878b8dd9 322
vpcola 0:f1d3878b8dd9 323 }
vpcola 0:f1d3878b8dd9 324
vpcola 0:f1d3878b8dd9 325
vpcola 0:f1d3878b8dd9 326 /**
vpcola 0:f1d3878b8dd9 327 * @brief Sets the CRC mode for SPIRIT packets.
vpcola 0:f1d3878b8dd9 328 * @param xCrcMode length of CRC field in bytes.
vpcola 0:f1d3878b8dd9 329 * This parameter can be any value of @ref PktCrcMode.
vpcola 0:f1d3878b8dd9 330 * @retval None.
vpcola 0:f1d3878b8dd9 331 */
vpcola 0:f1d3878b8dd9 332 void SpiritPktCommonSetCrcMode(PktCrcMode xCrcMode)
vpcola 0:f1d3878b8dd9 333 {
vpcola 0:f1d3878b8dd9 334 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 335
vpcola 0:f1d3878b8dd9 336 /* Check the parameters */
vpcola 0:f1d3878b8dd9 337 s_assert_param(IS_PKT_CRC_MODE(xCrcMode));
vpcola 0:f1d3878b8dd9 338
vpcola 0:f1d3878b8dd9 339 /* Reads the PCKTCTRL1 register value */
vpcola 0:f1d3878b8dd9 340 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 341
vpcola 0:f1d3878b8dd9 342 /* Build data to write setting the CRC mode */
vpcola 0:f1d3878b8dd9 343 tempRegValue &= ~PCKTCTRL1_CRC_MODE_MASK;
vpcola 0:f1d3878b8dd9 344 tempRegValue |= (uint8_t)xCrcMode;
vpcola 0:f1d3878b8dd9 345
vpcola 0:f1d3878b8dd9 346 /* Writes the new value on the PCKTCTRL1 register */
vpcola 0:f1d3878b8dd9 347 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 348
vpcola 0:f1d3878b8dd9 349 }
vpcola 0:f1d3878b8dd9 350
vpcola 0:f1d3878b8dd9 351
vpcola 0:f1d3878b8dd9 352 /**
vpcola 0:f1d3878b8dd9 353 * @brief Returns the CRC mode for SPIRIT packets.
vpcola 0:f1d3878b8dd9 354 * @param None.
vpcola 0:f1d3878b8dd9 355 * @retval PktCrcMode Crc mode.
vpcola 0:f1d3878b8dd9 356 */
vpcola 0:f1d3878b8dd9 357 PktCrcMode SpiritPktCommonGetCrcMode(void)
vpcola 0:f1d3878b8dd9 358 {
vpcola 0:f1d3878b8dd9 359 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 360
vpcola 0:f1d3878b8dd9 361 /* Reads the PCKTCTRL1 register */
vpcola 0:f1d3878b8dd9 362 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 363
vpcola 0:f1d3878b8dd9 364 /* Rebuild and return value */
vpcola 0:f1d3878b8dd9 365 return (PktCrcMode)(tempRegValue & 0xE0);
vpcola 0:f1d3878b8dd9 366
vpcola 0:f1d3878b8dd9 367 }
vpcola 0:f1d3878b8dd9 368
vpcola 0:f1d3878b8dd9 369
vpcola 0:f1d3878b8dd9 370 /**
vpcola 0:f1d3878b8dd9 371 * @brief Enables or Disables WHITENING for SPIRIT packets.
vpcola 0:f1d3878b8dd9 372 * @param xNewState new state for WHITENING mode.
vpcola 0:f1d3878b8dd9 373 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 374 * @retval None.
vpcola 0:f1d3878b8dd9 375 */
vpcola 0:f1d3878b8dd9 376 void SpiritPktCommonWhitening(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 377 {
vpcola 0:f1d3878b8dd9 378 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 379
vpcola 0:f1d3878b8dd9 380 /* Check the parameters */
vpcola 0:f1d3878b8dd9 381 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 382
vpcola 0:f1d3878b8dd9 383 /* Reads the PCKTCTRL1 register value */
vpcola 0:f1d3878b8dd9 384 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 385
vpcola 0:f1d3878b8dd9 386 /* Build data to write: set or reset the whitening enable bit */
vpcola 0:f1d3878b8dd9 387 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 388 {
vpcola 0:f1d3878b8dd9 389 tempRegValue |= PCKTCTRL1_WHIT_MASK;
vpcola 0:f1d3878b8dd9 390 }
vpcola 0:f1d3878b8dd9 391 else
vpcola 0:f1d3878b8dd9 392 {
vpcola 0:f1d3878b8dd9 393 tempRegValue &= ~PCKTCTRL1_WHIT_MASK;
vpcola 0:f1d3878b8dd9 394 }
vpcola 0:f1d3878b8dd9 395
vpcola 0:f1d3878b8dd9 396 /* Writes the new value on the PCKTCTRL1 register */
vpcola 0:f1d3878b8dd9 397 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 398
vpcola 0:f1d3878b8dd9 399 }
vpcola 0:f1d3878b8dd9 400
vpcola 0:f1d3878b8dd9 401
vpcola 0:f1d3878b8dd9 402 /**
vpcola 0:f1d3878b8dd9 403 * @brief Enables or Disables FEC for SPIRIT packets.
vpcola 0:f1d3878b8dd9 404 * @param xNewState new state for FEC mode.
vpcola 0:f1d3878b8dd9 405 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 406 * @retval None.
vpcola 0:f1d3878b8dd9 407 */
vpcola 0:f1d3878b8dd9 408 void SpiritPktCommonFec(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 409 {
vpcola 0:f1d3878b8dd9 410 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 411
vpcola 0:f1d3878b8dd9 412 /* Check the parameters */
vpcola 0:f1d3878b8dd9 413 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 414
vpcola 0:f1d3878b8dd9 415 /* Reads the PCKTCTRL1 register value */
vpcola 0:f1d3878b8dd9 416 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 417
vpcola 0:f1d3878b8dd9 418 /* Build data to write: set or reset the FEC enable bit */
vpcola 0:f1d3878b8dd9 419 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 420 {
vpcola 0:f1d3878b8dd9 421 tempRegValue |= PCKTCTRL1_FEC_MASK;
vpcola 0:f1d3878b8dd9 422 }
vpcola 0:f1d3878b8dd9 423 else
vpcola 0:f1d3878b8dd9 424 {
vpcola 0:f1d3878b8dd9 425 tempRegValue &= ~PCKTCTRL1_FEC_MASK;
vpcola 0:f1d3878b8dd9 426 }
vpcola 0:f1d3878b8dd9 427
vpcola 0:f1d3878b8dd9 428 /* Writes data on the PCKTCTRL1 register */
vpcola 0:f1d3878b8dd9 429 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 430
vpcola 0:f1d3878b8dd9 431 }
vpcola 0:f1d3878b8dd9 432
vpcola 0:f1d3878b8dd9 433
vpcola 0:f1d3878b8dd9 434 /**
vpcola 0:f1d3878b8dd9 435 * @brief Sets a specific SYNC word for SPIRIT packets.
vpcola 0:f1d3878b8dd9 436 * @param xSyncX SYNC word number to be set.
vpcola 0:f1d3878b8dd9 437 * This parameter can be any value of @ref PktSyncX.
vpcola 0:f1d3878b8dd9 438 * @param cSyncWord SYNC word.
vpcola 0:f1d3878b8dd9 439 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 440 * @retval None.
vpcola 0:f1d3878b8dd9 441 */
vpcola 0:f1d3878b8dd9 442 void SpiritPktCommonSetSyncxWord(PktSyncX xSyncX , uint8_t cSyncWord)
vpcola 0:f1d3878b8dd9 443 {
vpcola 0:f1d3878b8dd9 444 uint8_t tempRegAddress;
vpcola 0:f1d3878b8dd9 445
vpcola 0:f1d3878b8dd9 446 /* Check the parameters */
vpcola 0:f1d3878b8dd9 447 s_assert_param(IS_PKT_SYNCx(xSyncX));
vpcola 0:f1d3878b8dd9 448
vpcola 0:f1d3878b8dd9 449 /* Set the specified address */
vpcola 0:f1d3878b8dd9 450 switch(xSyncX)
vpcola 0:f1d3878b8dd9 451 {
vpcola 0:f1d3878b8dd9 452 case PKT_SYNC_WORD_1:
vpcola 0:f1d3878b8dd9 453 tempRegAddress=SYNC1_BASE;
vpcola 0:f1d3878b8dd9 454 break;
vpcola 0:f1d3878b8dd9 455 case PKT_SYNC_WORD_2:
vpcola 0:f1d3878b8dd9 456 tempRegAddress=SYNC2_BASE;
vpcola 0:f1d3878b8dd9 457 break;
vpcola 0:f1d3878b8dd9 458 case PKT_SYNC_WORD_3:
vpcola 0:f1d3878b8dd9 459 tempRegAddress=SYNC3_BASE;
vpcola 0:f1d3878b8dd9 460 break;
vpcola 0:f1d3878b8dd9 461 default:
vpcola 0:f1d3878b8dd9 462 tempRegAddress=SYNC4_BASE;
vpcola 0:f1d3878b8dd9 463 break;
vpcola 0:f1d3878b8dd9 464 }
vpcola 0:f1d3878b8dd9 465
vpcola 0:f1d3878b8dd9 466 /* Writes value on the selected register */
vpcola 0:f1d3878b8dd9 467 g_xStatus = SpiritSpiWriteRegisters(tempRegAddress, 1, &cSyncWord);
vpcola 0:f1d3878b8dd9 468
vpcola 0:f1d3878b8dd9 469 }
vpcola 0:f1d3878b8dd9 470
vpcola 0:f1d3878b8dd9 471
vpcola 0:f1d3878b8dd9 472 /**
vpcola 0:f1d3878b8dd9 473 * @brief Returns a specific SYNC word for SPIRIT packets.
vpcola 0:f1d3878b8dd9 474 * @param xSyncX SYNC word number to be get.
vpcola 0:f1d3878b8dd9 475 * This parameter can be any value of @ref PktSyncX.
vpcola 0:f1d3878b8dd9 476 * @retval uint8_t Sync word x.
vpcola 0:f1d3878b8dd9 477 */
vpcola 0:f1d3878b8dd9 478 uint8_t SpiritPktCommonGetSyncxWord(PktSyncX xSyncX)
vpcola 0:f1d3878b8dd9 479 {
vpcola 0:f1d3878b8dd9 480 uint8_t tempRegAddress, tempRegValue;
vpcola 0:f1d3878b8dd9 481
vpcola 0:f1d3878b8dd9 482 /* Check the parameters */
vpcola 0:f1d3878b8dd9 483 s_assert_param(IS_PKT_SYNCx(xSyncX));
vpcola 0:f1d3878b8dd9 484
vpcola 0:f1d3878b8dd9 485 /* Set the specified address */
vpcola 0:f1d3878b8dd9 486 switch(xSyncX)
vpcola 0:f1d3878b8dd9 487 {
vpcola 0:f1d3878b8dd9 488 case PKT_SYNC_WORD_1:
vpcola 0:f1d3878b8dd9 489 tempRegAddress=SYNC1_BASE;
vpcola 0:f1d3878b8dd9 490 break;
vpcola 0:f1d3878b8dd9 491 case PKT_SYNC_WORD_2:
vpcola 0:f1d3878b8dd9 492 tempRegAddress=SYNC2_BASE;
vpcola 0:f1d3878b8dd9 493 break;
vpcola 0:f1d3878b8dd9 494 case PKT_SYNC_WORD_3:
vpcola 0:f1d3878b8dd9 495 tempRegAddress=SYNC3_BASE;
vpcola 0:f1d3878b8dd9 496 break;
vpcola 0:f1d3878b8dd9 497 default:
vpcola 0:f1d3878b8dd9 498 tempRegAddress=SYNC4_BASE;
vpcola 0:f1d3878b8dd9 499 break;
vpcola 0:f1d3878b8dd9 500 }
vpcola 0:f1d3878b8dd9 501
vpcola 0:f1d3878b8dd9 502 /* Reads the selected register value */
vpcola 0:f1d3878b8dd9 503 g_xStatus = SpiritSpiReadRegisters(tempRegAddress, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 504
vpcola 0:f1d3878b8dd9 505 /* Returns the read value */
vpcola 0:f1d3878b8dd9 506 return tempRegValue;
vpcola 0:f1d3878b8dd9 507
vpcola 0:f1d3878b8dd9 508 }
vpcola 0:f1d3878b8dd9 509
vpcola 0:f1d3878b8dd9 510
vpcola 0:f1d3878b8dd9 511 /**
vpcola 0:f1d3878b8dd9 512 * @brief Sets multiple SYNC words for SPIRIT packets.
vpcola 0:f1d3878b8dd9 513 * @param lSyncWords SYNC words to be set with format: 0x|SYNC1|SYNC2|SYNC3|SYNC4|.
vpcola 0:f1d3878b8dd9 514 * This parameter is a uint32_t.
vpcola 0:f1d3878b8dd9 515 * @param xSyncLength SYNC length in bytes. The 32bit word passed will be stored in the SYNCx registers from the MSb
vpcola 0:f1d3878b8dd9 516 * until the number of bytes in xSyncLength has been stored.
vpcola 0:f1d3878b8dd9 517 * This parameter is a @ref PktSyncLength.
vpcola 0:f1d3878b8dd9 518 * @retval None.
vpcola 0:f1d3878b8dd9 519 */
vpcola 0:f1d3878b8dd9 520 void SpiritPktCommonSetSyncWords(uint32_t lSyncWords, PktSyncLength xSyncLength)
vpcola 0:f1d3878b8dd9 521 {
vpcola 0:f1d3878b8dd9 522 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 523
vpcola 0:f1d3878b8dd9 524 /* Split the 32-bit value in 4 8-bit values */
vpcola 0:f1d3878b8dd9 525 for(uint8_t i=0 ; i<4 ; i++)
vpcola 0:f1d3878b8dd9 526 {
vpcola 0:f1d3878b8dd9 527 if(i< ((3-xSyncLength) >>1) )
vpcola 0:f1d3878b8dd9 528 {
vpcola 0:f1d3878b8dd9 529 tempRegValue[i]=0;
vpcola 0:f1d3878b8dd9 530 }
vpcola 0:f1d3878b8dd9 531 else
vpcola 0:f1d3878b8dd9 532 {
vpcola 0:f1d3878b8dd9 533 tempRegValue[i]=(uint8_t)(lSyncWords>>(8*i));
vpcola 0:f1d3878b8dd9 534 }
vpcola 0:f1d3878b8dd9 535 }
vpcola 0:f1d3878b8dd9 536
vpcola 0:f1d3878b8dd9 537 /* Writes SYNC value on the SYNCx registers */
vpcola 0:f1d3878b8dd9 538 g_xStatus = SpiritSpiWriteRegisters(SYNC4_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 539
vpcola 0:f1d3878b8dd9 540 }
vpcola 0:f1d3878b8dd9 541
vpcola 0:f1d3878b8dd9 542
vpcola 0:f1d3878b8dd9 543 /**
vpcola 0:f1d3878b8dd9 544 * @brief Returns multiple SYNC words for SPIRIT packets.
vpcola 0:f1d3878b8dd9 545 * @param xSyncLength SYNC length in bytes. The 32bit word passed will be stored in the SYNCx registers from the MSb
vpcola 0:f1d3878b8dd9 546 * until the number of bytes in xSyncLength has been stored.
vpcola 0:f1d3878b8dd9 547 * This parameter is a pointer to @ref PktSyncLength.
vpcola 0:f1d3878b8dd9 548 * @retval uint32_t Sync words. The format of the read 32 bit word is 0x|SYNC1|SYNC2|SYNC3|SYNC4|.
vpcola 0:f1d3878b8dd9 549 */
vpcola 0:f1d3878b8dd9 550 uint32_t SpiritPktCommonGetSyncWords(PktSyncLength xSyncLength)
vpcola 0:f1d3878b8dd9 551 {
vpcola 0:f1d3878b8dd9 552 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 553 uint32_t tempRetValue=0;
vpcola 0:f1d3878b8dd9 554
vpcola 0:f1d3878b8dd9 555 /* Reads the SYNCx registers value */
vpcola 0:f1d3878b8dd9 556 g_xStatus = SpiritSpiReadRegisters(SYNC4_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 557
vpcola 0:f1d3878b8dd9 558 /* Rebuild the SYNC words */
vpcola 0:f1d3878b8dd9 559 for(uint8_t i=0 ; i<4 ; i++)
vpcola 0:f1d3878b8dd9 560 {
vpcola 0:f1d3878b8dd9 561 if(i>2-(xSyncLength >>1))
vpcola 0:f1d3878b8dd9 562 {
vpcola 0:f1d3878b8dd9 563 tempRetValue |= tempRegValue[i]<<(8*i);
vpcola 0:f1d3878b8dd9 564 }
vpcola 0:f1d3878b8dd9 565 }
vpcola 0:f1d3878b8dd9 566
vpcola 0:f1d3878b8dd9 567 /* Return SYNC words */
vpcola 0:f1d3878b8dd9 568 return tempRetValue;
vpcola 0:f1d3878b8dd9 569
vpcola 0:f1d3878b8dd9 570 }
vpcola 0:f1d3878b8dd9 571
vpcola 0:f1d3878b8dd9 572
vpcola 0:f1d3878b8dd9 573 /**
vpcola 0:f1d3878b8dd9 574 * @brief Returns the variable length width (in number of bits).
vpcola 0:f1d3878b8dd9 575 * @param None.
vpcola 0:f1d3878b8dd9 576 * @retval uint8_t Variable length width in bits.
vpcola 0:f1d3878b8dd9 577 */
vpcola 0:f1d3878b8dd9 578 uint8_t SpiritPktCommonGetVarLengthWidth(void)
vpcola 0:f1d3878b8dd9 579 {
vpcola 0:f1d3878b8dd9 580 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 581
vpcola 0:f1d3878b8dd9 582 /* Reads the PCKTCTRL3 register value */
vpcola 0:f1d3878b8dd9 583 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 584
vpcola 0:f1d3878b8dd9 585 /* Rebuild and return value */
vpcola 0:f1d3878b8dd9 586 return (tempRegValue & PCKTCTRL3_LEN_WID_MASK)+1;
vpcola 0:f1d3878b8dd9 587
vpcola 0:f1d3878b8dd9 588 }
vpcola 0:f1d3878b8dd9 589
vpcola 0:f1d3878b8dd9 590
vpcola 0:f1d3878b8dd9 591 /**
vpcola 0:f1d3878b8dd9 592 * @brief Sets the destination address for the Tx packet.
vpcola 0:f1d3878b8dd9 593 * @param cAddress Destination address.
vpcola 0:f1d3878b8dd9 594 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 595 * @retval None.
vpcola 0:f1d3878b8dd9 596 */
vpcola 0:f1d3878b8dd9 597 void SpiritPktCommonSetDestinationAddress(uint8_t cAddress)
vpcola 0:f1d3878b8dd9 598 {
vpcola 0:f1d3878b8dd9 599 /* Writes value on PCKT_FLT_GOALS_SOURCE_ADDR register */
vpcola 0:f1d3878b8dd9 600 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_SOURCE_ADDR_BASE, 1, &cAddress);
vpcola 0:f1d3878b8dd9 601
vpcola 0:f1d3878b8dd9 602 }
vpcola 0:f1d3878b8dd9 603
vpcola 0:f1d3878b8dd9 604
vpcola 0:f1d3878b8dd9 605 /**
vpcola 0:f1d3878b8dd9 606 * @brief Returns the settled destination address.
vpcola 0:f1d3878b8dd9 607 * @param None.
vpcola 0:f1d3878b8dd9 608 * @retval uint8_t Transmitted destination address.
vpcola 0:f1d3878b8dd9 609 */
vpcola 0:f1d3878b8dd9 610 uint8_t SpiritPktCommonGetTransmittedDestAddress(void)
vpcola 0:f1d3878b8dd9 611 {
vpcola 0:f1d3878b8dd9 612 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 613
vpcola 0:f1d3878b8dd9 614 /* Reads value on the PCKT_FLT_GOALS_SOURCE_ADDR register */
vpcola 0:f1d3878b8dd9 615 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_SOURCE_ADDR_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 616
vpcola 0:f1d3878b8dd9 617 /* Return value */
vpcola 0:f1d3878b8dd9 618 return tempRegValue;
vpcola 0:f1d3878b8dd9 619
vpcola 0:f1d3878b8dd9 620 }
vpcola 0:f1d3878b8dd9 621
vpcola 0:f1d3878b8dd9 622
vpcola 0:f1d3878b8dd9 623 /**
vpcola 0:f1d3878b8dd9 624 * @brief Sets the node my address. When the filtering on my address is on, if the destination address extracted from the received packet is equal to the content of the
vpcola 0:f1d3878b8dd9 625 * my address, then the packet is accepted (this is the address of the node).
vpcola 0:f1d3878b8dd9 626 * @param cAddress Address of the present node.
vpcola 0:f1d3878b8dd9 627 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 628 * @retval None.
vpcola 0:f1d3878b8dd9 629 */
vpcola 0:f1d3878b8dd9 630 void SpiritPktCommonSetMyAddress(uint8_t cAddress)
vpcola 0:f1d3878b8dd9 631 {
vpcola 0:f1d3878b8dd9 632 /* Writes value on the PCKT_FLT_GOALS_TX_ADDR register */
vpcola 0:f1d3878b8dd9 633 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_TX_ADDR_BASE, 1, &cAddress);
vpcola 0:f1d3878b8dd9 634
vpcola 0:f1d3878b8dd9 635 }
vpcola 0:f1d3878b8dd9 636
vpcola 0:f1d3878b8dd9 637
vpcola 0:f1d3878b8dd9 638 /**
vpcola 0:f1d3878b8dd9 639 * @brief Returns the address of the present node.
vpcola 0:f1d3878b8dd9 640 * @param None.
vpcola 0:f1d3878b8dd9 641 * @retval uint8_t My address (address of this node).
vpcola 0:f1d3878b8dd9 642 */
vpcola 0:f1d3878b8dd9 643 uint8_t SpiritPktCommonGetMyAddress(void)
vpcola 0:f1d3878b8dd9 644 {
vpcola 0:f1d3878b8dd9 645 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 646
vpcola 0:f1d3878b8dd9 647 /* Reads value on the PCKT_FLT_GOALS_TX_ADDR register */
vpcola 0:f1d3878b8dd9 648 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_TX_ADDR_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 649
vpcola 0:f1d3878b8dd9 650 /* Return value */
vpcola 0:f1d3878b8dd9 651 return tempRegValue;
vpcola 0:f1d3878b8dd9 652
vpcola 0:f1d3878b8dd9 653 }
vpcola 0:f1d3878b8dd9 654
vpcola 0:f1d3878b8dd9 655
vpcola 0:f1d3878b8dd9 656 /**
vpcola 0:f1d3878b8dd9 657 * @brief Sets the broadcast address. If the destination address extracted from the received packet is equal to the content of the
vpcola 0:f1d3878b8dd9 658 * BROADCAST_ADDR register, then the packet is accepted.
vpcola 0:f1d3878b8dd9 659 * @param cAddress Broadcast address.
vpcola 0:f1d3878b8dd9 660 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 661 * @retval None.
vpcola 0:f1d3878b8dd9 662 */
vpcola 0:f1d3878b8dd9 663 void SpiritPktCommonSetBroadcastAddress(uint8_t cAddress)
vpcola 0:f1d3878b8dd9 664 {
vpcola 0:f1d3878b8dd9 665 /* Writes value on the PCKT_FLT_GOALS_BROADCAST register */
vpcola 0:f1d3878b8dd9 666 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 1, &cAddress);
vpcola 0:f1d3878b8dd9 667
vpcola 0:f1d3878b8dd9 668 }
vpcola 0:f1d3878b8dd9 669
vpcola 0:f1d3878b8dd9 670
vpcola 0:f1d3878b8dd9 671 /**
vpcola 0:f1d3878b8dd9 672 * @brief Returns the broadcast address.
vpcola 0:f1d3878b8dd9 673 * @param None.
vpcola 0:f1d3878b8dd9 674 * @retval uint8_t Broadcast address.
vpcola 0:f1d3878b8dd9 675 */
vpcola 0:f1d3878b8dd9 676 uint8_t SpiritPktCommonGetBroadcastAddress(void)
vpcola 0:f1d3878b8dd9 677 {
vpcola 0:f1d3878b8dd9 678 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 679
vpcola 0:f1d3878b8dd9 680 /* Reads value on the PCKT_FLT_GOALS_BROADCAST register */
vpcola 0:f1d3878b8dd9 681 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 682
vpcola 0:f1d3878b8dd9 683 /* Return value */
vpcola 0:f1d3878b8dd9 684 return tempRegValue;
vpcola 0:f1d3878b8dd9 685
vpcola 0:f1d3878b8dd9 686 }
vpcola 0:f1d3878b8dd9 687
vpcola 0:f1d3878b8dd9 688
vpcola 0:f1d3878b8dd9 689 /**
vpcola 0:f1d3878b8dd9 690 * @brief Sets the multicast address. When the multicast filtering is on, if the destination address extracted from the received packet is equal to the content of the
vpcola 0:f1d3878b8dd9 691 * MULTICAST_ADDR register, then the packet is accepted.
vpcola 0:f1d3878b8dd9 692 * @param cAddress Multicast address.
vpcola 0:f1d3878b8dd9 693 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 694 * @retval None.
vpcola 0:f1d3878b8dd9 695 */
vpcola 0:f1d3878b8dd9 696 void SpiritPktCommonSetMulticastAddress(uint8_t cAddress)
vpcola 0:f1d3878b8dd9 697 {
vpcola 0:f1d3878b8dd9 698 /* Writes value on the PCKT_FLT_GOALS_MULTICAST register */
vpcola 0:f1d3878b8dd9 699 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_MULTICAST_BASE, 1, &cAddress);
vpcola 0:f1d3878b8dd9 700
vpcola 0:f1d3878b8dd9 701 }
vpcola 0:f1d3878b8dd9 702
vpcola 0:f1d3878b8dd9 703
vpcola 0:f1d3878b8dd9 704 /**
vpcola 0:f1d3878b8dd9 705 * @brief Returns the multicast address.
vpcola 0:f1d3878b8dd9 706 * @param None.
vpcola 0:f1d3878b8dd9 707 * @retval uint8_t Multicast address.
vpcola 0:f1d3878b8dd9 708 */
vpcola 0:f1d3878b8dd9 709 uint8_t SpiritPktCommonGetMulticastAddress(void)
vpcola 0:f1d3878b8dd9 710 {
vpcola 0:f1d3878b8dd9 711 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 712
vpcola 0:f1d3878b8dd9 713 /* Reads value on the PCKT_FLT_GOALS_MULTICAST register */
vpcola 0:f1d3878b8dd9 714 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_MULTICAST_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 715
vpcola 0:f1d3878b8dd9 716 /* Return value */
vpcola 0:f1d3878b8dd9 717 return tempRegValue;
vpcola 0:f1d3878b8dd9 718
vpcola 0:f1d3878b8dd9 719 }
vpcola 0:f1d3878b8dd9 720
vpcola 0:f1d3878b8dd9 721
vpcola 0:f1d3878b8dd9 722 /**
vpcola 0:f1d3878b8dd9 723 * @brief Sets the control mask. The 1 bits of the CONTROL_MASK indicate the
vpcola 0:f1d3878b8dd9 724 * bits to be used in filtering. (All 0s no filtering)
vpcola 0:f1d3878b8dd9 725 * @param lMask Control mask.
vpcola 0:f1d3878b8dd9 726 * This parameter is an uint32_t.
vpcola 0:f1d3878b8dd9 727 * @retval None.
vpcola 0:f1d3878b8dd9 728 */
vpcola 0:f1d3878b8dd9 729 void SpiritPktCommonSetCtrlMask(uint32_t lMask)
vpcola 0:f1d3878b8dd9 730 {
vpcola 0:f1d3878b8dd9 731 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 732
vpcola 0:f1d3878b8dd9 733 /* Split the 32-bit value in 4 8-bit values */
vpcola 0:f1d3878b8dd9 734 tempRegValue[0] = (uint8_t) lMask;
vpcola 0:f1d3878b8dd9 735 tempRegValue[1] = (uint8_t)(lMask >> 8);
vpcola 0:f1d3878b8dd9 736 tempRegValue[2] = (uint8_t)(lMask >> 16);
vpcola 0:f1d3878b8dd9 737 tempRegValue[3] = (uint8_t)(lMask >> 24);
vpcola 0:f1d3878b8dd9 738
vpcola 0:f1d3878b8dd9 739 /* Writes values on the CKT_FLT_GOALS_CONTROLx_MASK registers */
vpcola 0:f1d3878b8dd9 740 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_CONTROL0_MASK_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 741
vpcola 0:f1d3878b8dd9 742 }
vpcola 0:f1d3878b8dd9 743
vpcola 0:f1d3878b8dd9 744
vpcola 0:f1d3878b8dd9 745 /**
vpcola 0:f1d3878b8dd9 746 * @brief Returns the control mask. The 1 bits of the CONTROL_MASK indicate the
vpcola 0:f1d3878b8dd9 747 * bits to be used in filtering. (All 0s no filtering)
vpcola 0:f1d3878b8dd9 748 * @param None.
vpcola 0:f1d3878b8dd9 749 * @retval uint32_t Control mask.
vpcola 0:f1d3878b8dd9 750 */
vpcola 0:f1d3878b8dd9 751 uint32_t SpiritPktCommonGetCtrlMask(void)
vpcola 0:f1d3878b8dd9 752 {
vpcola 0:f1d3878b8dd9 753 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 754 uint32_t tempRetValue=0;
vpcola 0:f1d3878b8dd9 755
vpcola 0:f1d3878b8dd9 756 /* Reads the PCKT_FLT_GOALS_CONTROLx_MASK registers */
vpcola 0:f1d3878b8dd9 757 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_CONTROL0_MASK_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 758
vpcola 0:f1d3878b8dd9 759 /* Rebuild the control mask value on a 32-bit integer variable */
vpcola 0:f1d3878b8dd9 760 for(uint8_t i=0 ; i<4 ; i++)
vpcola 0:f1d3878b8dd9 761 {
vpcola 0:f1d3878b8dd9 762 tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*i);
vpcola 0:f1d3878b8dd9 763 }
vpcola 0:f1d3878b8dd9 764
vpcola 0:f1d3878b8dd9 765 /* Return value */
vpcola 0:f1d3878b8dd9 766 return tempRetValue;
vpcola 0:f1d3878b8dd9 767 }
vpcola 0:f1d3878b8dd9 768
vpcola 0:f1d3878b8dd9 769 /**
vpcola 0:f1d3878b8dd9 770 * @brief Sets the control field reference. If the bits enabled by the CONTROL_MASK
vpcola 0:f1d3878b8dd9 771 * match the ones of the control fields extracted from the received packet
vpcola 0:f1d3878b8dd9 772 * then the packet is accepted.
vpcola 0:f1d3878b8dd9 773 * @param lReference Control reference.
vpcola 0:f1d3878b8dd9 774 * This parameter is an uint32_t.
vpcola 0:f1d3878b8dd9 775 * @retval None.
vpcola 0:f1d3878b8dd9 776 */
vpcola 0:f1d3878b8dd9 777 void SpiritPktCommonSetCtrlReference(uint32_t lReference)
vpcola 0:f1d3878b8dd9 778 {
vpcola 0:f1d3878b8dd9 779 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 780
vpcola 0:f1d3878b8dd9 781 /* Split the 32-bit value in 4 8-bit values */
vpcola 0:f1d3878b8dd9 782 tempRegValue[0] = (uint8_t) lReference;
vpcola 0:f1d3878b8dd9 783 tempRegValue[1] = (uint8_t)(lReference >> 8);
vpcola 0:f1d3878b8dd9 784 tempRegValue[2] = (uint8_t)(lReference >> 16);
vpcola 0:f1d3878b8dd9 785 tempRegValue[3] = (uint8_t)(lReference >> 24);
vpcola 0:f1d3878b8dd9 786
vpcola 0:f1d3878b8dd9 787 /* Writes values on the CKT_FLT_GOALS_CONTROLx_FIELD registers */
vpcola 0:f1d3878b8dd9 788 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_CONTROL0_FIELD_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 789
vpcola 0:f1d3878b8dd9 790 }
vpcola 0:f1d3878b8dd9 791
vpcola 0:f1d3878b8dd9 792
vpcola 0:f1d3878b8dd9 793 /**
vpcola 0:f1d3878b8dd9 794 * @brief Returns the control field reference.
vpcola 0:f1d3878b8dd9 795 * @param None.
vpcola 0:f1d3878b8dd9 796 * @retval uint32_t Control reference.
vpcola 0:f1d3878b8dd9 797 */
vpcola 0:f1d3878b8dd9 798 uint32_t SpiritPktCommonGetCtrlReference(void)
vpcola 0:f1d3878b8dd9 799 {
vpcola 0:f1d3878b8dd9 800 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 801 uint32_t tempRetValue=0;
vpcola 0:f1d3878b8dd9 802
vpcola 0:f1d3878b8dd9 803 /* Reads the PCKT_FLT_GOALS_CONTROLx_FIELD registers */
vpcola 0:f1d3878b8dd9 804 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_CONTROL0_FIELD_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 805
vpcola 0:f1d3878b8dd9 806 /* Rebuild the control mask value on a 32-bit integer variable */
vpcola 0:f1d3878b8dd9 807 for(uint8_t i=0 ; i<4 ; i++)
vpcola 0:f1d3878b8dd9 808 {
vpcola 0:f1d3878b8dd9 809 tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*i);
vpcola 0:f1d3878b8dd9 810 }
vpcola 0:f1d3878b8dd9 811
vpcola 0:f1d3878b8dd9 812 /* Return value */
vpcola 0:f1d3878b8dd9 813 return tempRetValue;
vpcola 0:f1d3878b8dd9 814 }
vpcola 0:f1d3878b8dd9 815
vpcola 0:f1d3878b8dd9 816
vpcola 0:f1d3878b8dd9 817 /**
vpcola 0:f1d3878b8dd9 818 * @brief Sets the TX control field.
vpcola 0:f1d3878b8dd9 819 * @param lField Tx contro field.
vpcola 0:f1d3878b8dd9 820 * This parameter is an uint32_t.
vpcola 0:f1d3878b8dd9 821 * @retval None.
vpcola 0:f1d3878b8dd9 822 */
vpcola 0:f1d3878b8dd9 823 void SpiritPktCommonSetTransmittedCtrlField(uint32_t lField)
vpcola 0:f1d3878b8dd9 824 {
vpcola 0:f1d3878b8dd9 825 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 826
vpcola 0:f1d3878b8dd9 827 /* Split the 32-bit value in 4 8-bit values */
vpcola 0:f1d3878b8dd9 828 tempRegValue[3] = (uint8_t) lField;
vpcola 0:f1d3878b8dd9 829 tempRegValue[2] = (uint8_t)(lField >> 8);
vpcola 0:f1d3878b8dd9 830 tempRegValue[1] = (uint8_t)(lField >> 16);
vpcola 0:f1d3878b8dd9 831 tempRegValue[0] = (uint8_t)(lField >> 24);
vpcola 0:f1d3878b8dd9 832
vpcola 0:f1d3878b8dd9 833 /* Writes value on the TX_CTRL_FIELDx register */
vpcola 0:f1d3878b8dd9 834 g_xStatus = SpiritSpiWriteRegisters(TX_CTRL_FIELD3_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 835
vpcola 0:f1d3878b8dd9 836 }
vpcola 0:f1d3878b8dd9 837
vpcola 0:f1d3878b8dd9 838
vpcola 0:f1d3878b8dd9 839 /**
vpcola 0:f1d3878b8dd9 840 * @brief Returns the Tx control field.
vpcola 0:f1d3878b8dd9 841 * @param None.
vpcola 0:f1d3878b8dd9 842 * @retval uint32_t Control field of the transmitted packet.
vpcola 0:f1d3878b8dd9 843 */
vpcola 0:f1d3878b8dd9 844 uint32_t SpiritPktCommonGetTransmittedCtrlField(void)
vpcola 0:f1d3878b8dd9 845 {
vpcola 0:f1d3878b8dd9 846 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 847 uint32_t tempRetValue=0;
vpcola 0:f1d3878b8dd9 848
vpcola 0:f1d3878b8dd9 849 /* Reads the TX_CTRL_FIELDx registers */
vpcola 0:f1d3878b8dd9 850 g_xStatus = SpiritSpiReadRegisters(TX_CTRL_FIELD3_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 851
vpcola 0:f1d3878b8dd9 852 /* Rebuild value: build a 32-bit value from the read bytes */
vpcola 0:f1d3878b8dd9 853 for(uint8_t i=0 ; i<4 ; i++)
vpcola 0:f1d3878b8dd9 854 {
vpcola 0:f1d3878b8dd9 855 tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*(3-i));
vpcola 0:f1d3878b8dd9 856 }
vpcola 0:f1d3878b8dd9 857
vpcola 0:f1d3878b8dd9 858 /* Return value */
vpcola 0:f1d3878b8dd9 859 return tempRetValue;
vpcola 0:f1d3878b8dd9 860
vpcola 0:f1d3878b8dd9 861 }
vpcola 0:f1d3878b8dd9 862
vpcola 0:f1d3878b8dd9 863
vpcola 0:f1d3878b8dd9 864 /**
vpcola 0:f1d3878b8dd9 865 * @brief If enabled RX packet is accepted if its destination address matches with My address.
vpcola 0:f1d3878b8dd9 866 * @param xNewState new state for DEST_VS_SOURCE_ADDRESS.
vpcola 0:f1d3878b8dd9 867 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 868 * @retval None.
vpcola 0:f1d3878b8dd9 869 */
vpcola 0:f1d3878b8dd9 870 void SpiritPktCommonFilterOnMyAddress(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 871 {
vpcola 0:f1d3878b8dd9 872 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 873
vpcola 0:f1d3878b8dd9 874 /* Check the parameters */
vpcola 0:f1d3878b8dd9 875 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 876
vpcola 0:f1d3878b8dd9 877
vpcola 0:f1d3878b8dd9 878 /* Modify the register value: set or reset the TX source address control */
vpcola 0:f1d3878b8dd9 879 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 880
vpcola 0:f1d3878b8dd9 881 /* Set or reset the DESTINATION vs TX enabling bit */
vpcola 0:f1d3878b8dd9 882 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 883 {
vpcola 0:f1d3878b8dd9 884 tempRegValue |= PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
vpcola 0:f1d3878b8dd9 885 }
vpcola 0:f1d3878b8dd9 886 else
vpcola 0:f1d3878b8dd9 887 {
vpcola 0:f1d3878b8dd9 888 tempRegValue &= ~PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
vpcola 0:f1d3878b8dd9 889 }
vpcola 0:f1d3878b8dd9 890
vpcola 0:f1d3878b8dd9 891 /* Writes the new value on the PCKT_FLT_OPTIONS register */
vpcola 0:f1d3878b8dd9 892 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 893
vpcola 0:f1d3878b8dd9 894 }
vpcola 0:f1d3878b8dd9 895
vpcola 0:f1d3878b8dd9 896
vpcola 0:f1d3878b8dd9 897 /**
vpcola 0:f1d3878b8dd9 898 * @brief If enabled RX packet is accepted if its destination address matches with multicast address.
vpcola 0:f1d3878b8dd9 899 * @param xNewState new state for DEST_VS_MULTICAST_ADDRESS.
vpcola 0:f1d3878b8dd9 900 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 901 * @retval None.
vpcola 0:f1d3878b8dd9 902 */
vpcola 0:f1d3878b8dd9 903 void SpiritPktCommonFilterOnMulticastAddress(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 904 {
vpcola 0:f1d3878b8dd9 905 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 906
vpcola 0:f1d3878b8dd9 907 /* Check the parameters */
vpcola 0:f1d3878b8dd9 908 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 909
vpcola 0:f1d3878b8dd9 910 /* Reads the PCKT_FLT_OPTIONS register value */
vpcola 0:f1d3878b8dd9 911 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 912
vpcola 0:f1d3878b8dd9 913 /* Enable or disable the filtering option */
vpcola 0:f1d3878b8dd9 914 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 915 {
vpcola 0:f1d3878b8dd9 916 tempRegValue |= PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 917 }
vpcola 0:f1d3878b8dd9 918 else
vpcola 0:f1d3878b8dd9 919 {
vpcola 0:f1d3878b8dd9 920 tempRegValue &= ~PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 921 }
vpcola 0:f1d3878b8dd9 922
vpcola 0:f1d3878b8dd9 923 /* Writes the new value on the PCKT_FLT_OPTIONS register */
vpcola 0:f1d3878b8dd9 924 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 925
vpcola 0:f1d3878b8dd9 926 }
vpcola 0:f1d3878b8dd9 927
vpcola 0:f1d3878b8dd9 928
vpcola 0:f1d3878b8dd9 929 /**
vpcola 0:f1d3878b8dd9 930 * @brief If enabled RX packet is accepted if its destination address matches with broadcast address.
vpcola 0:f1d3878b8dd9 931 * @param xNewState new state for DEST_VS_BROADCAST_ADDRESS.
vpcola 0:f1d3878b8dd9 932 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 933 * @retval None.
vpcola 0:f1d3878b8dd9 934 */
vpcola 0:f1d3878b8dd9 935 void SpiritPktCommonFilterOnBroadcastAddress(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 936 {
vpcola 0:f1d3878b8dd9 937 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 938
vpcola 0:f1d3878b8dd9 939 /* Check the parameters */
vpcola 0:f1d3878b8dd9 940 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 941
vpcola 0:f1d3878b8dd9 942 /* Reads the register value */
vpcola 0:f1d3878b8dd9 943 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 944
vpcola 0:f1d3878b8dd9 945 /* Enable or disable the filtering option */
vpcola 0:f1d3878b8dd9 946 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 947 {
vpcola 0:f1d3878b8dd9 948 tempRegValue |= PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 949 }
vpcola 0:f1d3878b8dd9 950 else
vpcola 0:f1d3878b8dd9 951 {
vpcola 0:f1d3878b8dd9 952 tempRegValue &= ~PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 953 }
vpcola 0:f1d3878b8dd9 954
vpcola 0:f1d3878b8dd9 955 /* Writes the new value on the PCKT_FLT_OPTIONS register */
vpcola 0:f1d3878b8dd9 956 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 957
vpcola 0:f1d3878b8dd9 958 }
vpcola 0:f1d3878b8dd9 959
vpcola 0:f1d3878b8dd9 960
vpcola 0:f1d3878b8dd9 961 /**
vpcola 0:f1d3878b8dd9 962 * @brief Returns the enable bit of the my address filtering.
vpcola 0:f1d3878b8dd9 963 * @param None.
vpcola 0:f1d3878b8dd9 964 * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 965 */
vpcola 0:f1d3878b8dd9 966 SpiritFunctionalState SpiritPktCommonGetFilterOnMyAddress(void)
vpcola 0:f1d3878b8dd9 967 {
vpcola 0:f1d3878b8dd9 968 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 969
vpcola 0:f1d3878b8dd9 970 /* Reads the register value */
vpcola 0:f1d3878b8dd9 971 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 972
vpcola 0:f1d3878b8dd9 973 /* Gets the enable/disable bit in form of SpiritFunctionalState type */
vpcola 0:f1d3878b8dd9 974 if(tempRegValue & 0x08)
vpcola 0:f1d3878b8dd9 975 {
vpcola 0:f1d3878b8dd9 976 return S_ENABLE;
vpcola 0:f1d3878b8dd9 977 }
vpcola 0:f1d3878b8dd9 978 else
vpcola 0:f1d3878b8dd9 979 {
vpcola 0:f1d3878b8dd9 980 return S_DISABLE;
vpcola 0:f1d3878b8dd9 981 }
vpcola 0:f1d3878b8dd9 982
vpcola 0:f1d3878b8dd9 983 }
vpcola 0:f1d3878b8dd9 984
vpcola 0:f1d3878b8dd9 985 /**
vpcola 0:f1d3878b8dd9 986 * @brief Returns the enable bit of the multicast address filtering.
vpcola 0:f1d3878b8dd9 987 * @param None.
vpcola 0:f1d3878b8dd9 988 * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 989 */
vpcola 0:f1d3878b8dd9 990 SpiritFunctionalState SpiritPktCommonGetFilterOnMulticastAddress(void)
vpcola 0:f1d3878b8dd9 991 {
vpcola 0:f1d3878b8dd9 992 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 993
vpcola 0:f1d3878b8dd9 994 /* Reads the register value */
vpcola 0:f1d3878b8dd9 995 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 996
vpcola 0:f1d3878b8dd9 997 /* Get the enable/disable bit in form of SpiritFunctionalState type */
vpcola 0:f1d3878b8dd9 998 if(tempRegValue & 0x04)
vpcola 0:f1d3878b8dd9 999 {
vpcola 0:f1d3878b8dd9 1000 return S_ENABLE;
vpcola 0:f1d3878b8dd9 1001 }
vpcola 0:f1d3878b8dd9 1002 else
vpcola 0:f1d3878b8dd9 1003 {
vpcola 0:f1d3878b8dd9 1004 return S_DISABLE;
vpcola 0:f1d3878b8dd9 1005 }
vpcola 0:f1d3878b8dd9 1006
vpcola 0:f1d3878b8dd9 1007 }
vpcola 0:f1d3878b8dd9 1008
vpcola 0:f1d3878b8dd9 1009 /**
vpcola 0:f1d3878b8dd9 1010 * @brief Returns the enable bit of the broadcast address filtering.
vpcola 0:f1d3878b8dd9 1011 * @param None.
vpcola 0:f1d3878b8dd9 1012 * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 1013 */
vpcola 0:f1d3878b8dd9 1014 SpiritFunctionalState SpiritPktCommonGetFilterOnBroadcastAddress(void)
vpcola 0:f1d3878b8dd9 1015 {
vpcola 0:f1d3878b8dd9 1016 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1017
vpcola 0:f1d3878b8dd9 1018 /* Reads the register value */
vpcola 0:f1d3878b8dd9 1019 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1020
vpcola 0:f1d3878b8dd9 1021 /* Get the enable/disable bit in form of SpiritFunctionalState type */
vpcola 0:f1d3878b8dd9 1022 if(tempRegValue & 0x02)
vpcola 0:f1d3878b8dd9 1023 {
vpcola 0:f1d3878b8dd9 1024 return S_ENABLE;
vpcola 0:f1d3878b8dd9 1025 }
vpcola 0:f1d3878b8dd9 1026 else
vpcola 0:f1d3878b8dd9 1027 {
vpcola 0:f1d3878b8dd9 1028 return S_DISABLE;
vpcola 0:f1d3878b8dd9 1029 }
vpcola 0:f1d3878b8dd9 1030
vpcola 0:f1d3878b8dd9 1031 }
vpcola 0:f1d3878b8dd9 1032
vpcola 0:f1d3878b8dd9 1033
vpcola 0:f1d3878b8dd9 1034 /**
vpcola 0:f1d3878b8dd9 1035 * @brief Returns the destination address of the received packet.
vpcola 0:f1d3878b8dd9 1036 * @param None.
vpcola 0:f1d3878b8dd9 1037 * @retval uint8_t Destination address of the received address.
vpcola 0:f1d3878b8dd9 1038 */
vpcola 0:f1d3878b8dd9 1039 uint8_t SpiritPktCommonGetReceivedDestAddress(void)
vpcola 0:f1d3878b8dd9 1040 {
vpcola 0:f1d3878b8dd9 1041 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1042
vpcola 0:f1d3878b8dd9 1043 /* Reads the RX_ADDR_FIELD0 register value */
vpcola 0:f1d3878b8dd9 1044 g_xStatus = SpiritSpiReadRegisters(RX_ADDR_FIELD0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1045
vpcola 0:f1d3878b8dd9 1046 /* Return value */
vpcola 0:f1d3878b8dd9 1047 return tempRegValue;
vpcola 0:f1d3878b8dd9 1048
vpcola 0:f1d3878b8dd9 1049 }
vpcola 0:f1d3878b8dd9 1050
vpcola 0:f1d3878b8dd9 1051
vpcola 0:f1d3878b8dd9 1052 /**
vpcola 0:f1d3878b8dd9 1053 * @brief Returns the control field of the received packet.
vpcola 0:f1d3878b8dd9 1054 * @param None.
vpcola 0:f1d3878b8dd9 1055 * @retval uint32_t Received control field.
vpcola 0:f1d3878b8dd9 1056 */
vpcola 0:f1d3878b8dd9 1057 uint32_t SpiritPktCommonGetReceivedCtrlField(void)
vpcola 0:f1d3878b8dd9 1058 {
vpcola 0:f1d3878b8dd9 1059 uint8_t tempRegValue[4];
vpcola 0:f1d3878b8dd9 1060 uint32_t tempRetValue=0;
vpcola 0:f1d3878b8dd9 1061
vpcola 0:f1d3878b8dd9 1062 /* Reads the PCKT_FLT_GOALS_CONTROLx_MASK registers */
vpcola 0:f1d3878b8dd9 1063 g_xStatus = SpiritSpiReadRegisters(RX_CTRL_FIELD0_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 1064
vpcola 0:f1d3878b8dd9 1065 /* Rebuild the control mask value on a 32-bit integer variable */
vpcola 0:f1d3878b8dd9 1066 for(uint8_t i=0 ; i<4 ; i++)
vpcola 0:f1d3878b8dd9 1067 {
vpcola 0:f1d3878b8dd9 1068 tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*i);
vpcola 0:f1d3878b8dd9 1069 }
vpcola 0:f1d3878b8dd9 1070
vpcola 0:f1d3878b8dd9 1071 /* Returns value */
vpcola 0:f1d3878b8dd9 1072 return tempRetValue;
vpcola 0:f1d3878b8dd9 1073 }
vpcola 0:f1d3878b8dd9 1074
vpcola 0:f1d3878b8dd9 1075
vpcola 0:f1d3878b8dd9 1076 /**
vpcola 0:f1d3878b8dd9 1077 * @brief Returns the CRC field of the received packet.
vpcola 0:f1d3878b8dd9 1078 * @param cCrcFieldVect array in which the CRC field has to be stored.
vpcola 0:f1d3878b8dd9 1079 * This parameter is an uint8_t array of 3 elements.
vpcola 0:f1d3878b8dd9 1080 * @retval None.
vpcola 0:f1d3878b8dd9 1081 */
vpcola 0:f1d3878b8dd9 1082 void SpiritPktCommonGetReceivedCrcField(uint8_t* cCrcFieldVect)
vpcola 0:f1d3878b8dd9 1083 {
vpcola 0:f1d3878b8dd9 1084 uint8_t tempRegValue[3],crcLength;
vpcola 0:f1d3878b8dd9 1085 PktCrcMode crcMode;
vpcola 0:f1d3878b8dd9 1086
vpcola 0:f1d3878b8dd9 1087 /* Gets the CRC mode in PktCrcMode enum */
vpcola 0:f1d3878b8dd9 1088 crcMode=SpiritPktCommonGetCrcMode();
vpcola 0:f1d3878b8dd9 1089
vpcola 0:f1d3878b8dd9 1090 /* Cast to uint8_t */
vpcola 0:f1d3878b8dd9 1091 crcLength = (uint8_t)crcMode;
vpcola 0:f1d3878b8dd9 1092
vpcola 0:f1d3878b8dd9 1093 /* Obtains the real length: see the @ref PktCrcMode enumeration */
vpcola 0:f1d3878b8dd9 1094 crcLength >>= 5;
vpcola 0:f1d3878b8dd9 1095 if(crcLength>=3) crcLength--;
vpcola 0:f1d3878b8dd9 1096
vpcola 0:f1d3878b8dd9 1097 /* Reads the CRC_FIELDx registers value */
vpcola 0:f1d3878b8dd9 1098 g_xStatus = SpiritSpiReadRegisters(CRC_FIELD2_BASE, 3,tempRegValue);
vpcola 0:f1d3878b8dd9 1099
vpcola 0:f1d3878b8dd9 1100 /* Sets the array to be returned */
vpcola 0:f1d3878b8dd9 1101 for(uint8_t i=0 ; i<3 ; i++)
vpcola 0:f1d3878b8dd9 1102 {
vpcola 0:f1d3878b8dd9 1103 if(i<crcLength)
vpcola 0:f1d3878b8dd9 1104 {
vpcola 0:f1d3878b8dd9 1105 cCrcFieldVect[i]=tempRegValue[2-i];
vpcola 0:f1d3878b8dd9 1106 }
vpcola 0:f1d3878b8dd9 1107 else
vpcola 0:f1d3878b8dd9 1108 {
vpcola 0:f1d3878b8dd9 1109 cCrcFieldVect[i]=0;
vpcola 0:f1d3878b8dd9 1110 }
vpcola 0:f1d3878b8dd9 1111 }
vpcola 0:f1d3878b8dd9 1112
vpcola 0:f1d3878b8dd9 1113 }
vpcola 0:f1d3878b8dd9 1114
vpcola 0:f1d3878b8dd9 1115
vpcola 0:f1d3878b8dd9 1116 /**
vpcola 0:f1d3878b8dd9 1117 * @brief Sets the AUTO ACKNOLEDGEMENT mechanism on the receiver. When the feature is enabled and
vpcola 0:f1d3878b8dd9 1118 * a data packet has been correctly received, then an acknowledgement packet is sent back to the originator of the received
vpcola 0:f1d3878b8dd9 1119 * packet. If the PIGGYBACKING bit is also set, payload data will be read from the FIFO; otherwise an empty packet is sent
vpcola 0:f1d3878b8dd9 1120 * only containing the source and destination addresses and the sequence number of the packet being acknowledged.
vpcola 0:f1d3878b8dd9 1121 * @param xAutoAck new state for autoack.
vpcola 0:f1d3878b8dd9 1122 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 1123 * @param xPiggybacking new state for autoack.
vpcola 0:f1d3878b8dd9 1124 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 1125 * @retval None.
vpcola 0:f1d3878b8dd9 1126 */
vpcola 0:f1d3878b8dd9 1127 void SpiritPktCommonAutoAck(SpiritFunctionalState xAutoAck , SpiritFunctionalState xPiggybacking)
vpcola 0:f1d3878b8dd9 1128 {
vpcola 0:f1d3878b8dd9 1129 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 1130
vpcola 0:f1d3878b8dd9 1131 /* Check the parameters */
vpcola 0:f1d3878b8dd9 1132 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xAutoAck));
vpcola 0:f1d3878b8dd9 1133 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xPiggybacking));
vpcola 0:f1d3878b8dd9 1134 /* Check if piggybacking is enabled and autoack is disabled */
vpcola 0:f1d3878b8dd9 1135 s_assert_param(!(xPiggybacking==S_ENABLE && xAutoAck==S_DISABLE));
vpcola 0:f1d3878b8dd9 1136
vpcola 0:f1d3878b8dd9 1137 /* Reads the PROTOCOL[1:0] registers value */
vpcola 0:f1d3878b8dd9 1138 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 1139
vpcola 0:f1d3878b8dd9 1140 /* Sets the specified LLP option */
vpcola 0:f1d3878b8dd9 1141 /* Autoack setting */
vpcola 0:f1d3878b8dd9 1142 if(xAutoAck == S_ENABLE)
vpcola 0:f1d3878b8dd9 1143 {
vpcola 0:f1d3878b8dd9 1144 tempRegValue[1] |= PROTOCOL0_AUTO_ACK_MASK;
vpcola 0:f1d3878b8dd9 1145 }
vpcola 0:f1d3878b8dd9 1146 else
vpcola 0:f1d3878b8dd9 1147 {
vpcola 0:f1d3878b8dd9 1148 tempRegValue[1] &= (~PROTOCOL0_AUTO_ACK_MASK);
vpcola 0:f1d3878b8dd9 1149 }
vpcola 0:f1d3878b8dd9 1150
vpcola 0:f1d3878b8dd9 1151 /* Piggybacking setting */
vpcola 0:f1d3878b8dd9 1152 if(xPiggybacking == S_ENABLE)
vpcola 0:f1d3878b8dd9 1153 {
vpcola 0:f1d3878b8dd9 1154 tempRegValue[0] |= PROTOCOL1_PIGGYBACKING_MASK;
vpcola 0:f1d3878b8dd9 1155 }
vpcola 0:f1d3878b8dd9 1156 else
vpcola 0:f1d3878b8dd9 1157 {
vpcola 0:f1d3878b8dd9 1158 tempRegValue[0] &= (~PROTOCOL1_PIGGYBACKING_MASK);
vpcola 0:f1d3878b8dd9 1159 }
vpcola 0:f1d3878b8dd9 1160
vpcola 0:f1d3878b8dd9 1161 /* Writes data on the PROTOCOL[1:0] registers */
vpcola 0:f1d3878b8dd9 1162 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 1163
vpcola 0:f1d3878b8dd9 1164 }
vpcola 0:f1d3878b8dd9 1165
vpcola 0:f1d3878b8dd9 1166
vpcola 0:f1d3878b8dd9 1167 /**
vpcola 0:f1d3878b8dd9 1168 * @brief Sets the AUTO ACKNOLEDGEMENT mechanism on the transmitter. On the transmitter side, the NACK_TX field can be used to require or not an acknowledgment for each individual packet: if
vpcola 0:f1d3878b8dd9 1169 * NACK_TX is set to "1" then acknowledgment will not be required; if NACK_TX is set to "0" then acknowledgment will be
vpcola 0:f1d3878b8dd9 1170 * required.
vpcola 0:f1d3878b8dd9 1171 * @param xNewState new state for TX_AUTOACK.
vpcola 0:f1d3878b8dd9 1172 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 1173 * @retval None.
vpcola 0:f1d3878b8dd9 1174 */
vpcola 0:f1d3878b8dd9 1175 void SpiritPktCommonRequireAck(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 1176 {
vpcola 0:f1d3878b8dd9 1177 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1178
vpcola 0:f1d3878b8dd9 1179 /* Check the parameters */
vpcola 0:f1d3878b8dd9 1180 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 1181
vpcola 0:f1d3878b8dd9 1182 /* Reads value on the PROTOCOL0 register */
vpcola 0:f1d3878b8dd9 1183 g_xStatus = SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1184
vpcola 0:f1d3878b8dd9 1185 /* Enables or disables the ack requirement option */
vpcola 0:f1d3878b8dd9 1186 if(xNewState == S_DISABLE)
vpcola 0:f1d3878b8dd9 1187 {
vpcola 0:f1d3878b8dd9 1188 tempRegValue |= PROTOCOL0_NACK_TX_MASK;
vpcola 0:f1d3878b8dd9 1189 }
vpcola 0:f1d3878b8dd9 1190 else
vpcola 0:f1d3878b8dd9 1191 {
vpcola 0:f1d3878b8dd9 1192 tempRegValue &= ~PROTOCOL0_NACK_TX_MASK;
vpcola 0:f1d3878b8dd9 1193 }
vpcola 0:f1d3878b8dd9 1194
vpcola 0:f1d3878b8dd9 1195 /* Writes value on the PROTOCOL0 register */
vpcola 0:f1d3878b8dd9 1196 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1197
vpcola 0:f1d3878b8dd9 1198 }
vpcola 0:f1d3878b8dd9 1199
vpcola 0:f1d3878b8dd9 1200
vpcola 0:f1d3878b8dd9 1201 /**
vpcola 0:f1d3878b8dd9 1202 * @brief Sets the TX sequence number to be used to start counting.
vpcola 0:f1d3878b8dd9 1203 * @param cSeqNumberReload new value for Tx seq number reload.
vpcola 0:f1d3878b8dd9 1204 * @retval None.
vpcola 0:f1d3878b8dd9 1205 */
vpcola 0:f1d3878b8dd9 1206 void SpiritPktCommonSetTransmittedSeqNumberReload(uint8_t cSeqNumberReload){
vpcola 0:f1d3878b8dd9 1207 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1208
vpcola 0:f1d3878b8dd9 1209 /* Check the parameters */
vpcola 0:f1d3878b8dd9 1210 s_assert_param(IS_PKT_SEQ_NUMBER_RELOAD(cSeqNumberReload));
vpcola 0:f1d3878b8dd9 1211
vpcola 0:f1d3878b8dd9 1212 /* Reads value on the PROTOCOL2 register */
vpcola 0:f1d3878b8dd9 1213 g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1214
vpcola 0:f1d3878b8dd9 1215 tempRegValue &= 0xE7;
vpcola 0:f1d3878b8dd9 1216 tempRegValue |= (cSeqNumberReload << 3);
vpcola 0:f1d3878b8dd9 1217
vpcola 0:f1d3878b8dd9 1218 /* Writes value on the PROTOCOL2 register */
vpcola 0:f1d3878b8dd9 1219 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1220
vpcola 0:f1d3878b8dd9 1221 }
vpcola 0:f1d3878b8dd9 1222
vpcola 0:f1d3878b8dd9 1223
vpcola 0:f1d3878b8dd9 1224 /**
vpcola 0:f1d3878b8dd9 1225 * @brief Sets the TX sequence number to be used to start counting.
vpcola 0:f1d3878b8dd9 1226 * @param cSeqNumberReload new value for Tx seq number reload.
vpcola 0:f1d3878b8dd9 1227 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 1228 * @retval None.
vpcola 0:f1d3878b8dd9 1229 */
vpcola 0:f1d3878b8dd9 1230 void SpiritPktCommonSetNMaxReTx(PktNMaxReTx xNMaxReTx)
vpcola 0:f1d3878b8dd9 1231 {
vpcola 0:f1d3878b8dd9 1232 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1233
vpcola 0:f1d3878b8dd9 1234 /* Check the parameters */
vpcola 0:f1d3878b8dd9 1235 s_assert_param(IS_PKT_NMAX_RETX(xNMaxReTx));
vpcola 0:f1d3878b8dd9 1236
vpcola 0:f1d3878b8dd9 1237 /* Reads the PROTOCOL0 register value */
vpcola 0:f1d3878b8dd9 1238 g_xStatus = SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1239
vpcola 0:f1d3878b8dd9 1240 /* Build the value to be written */
vpcola 0:f1d3878b8dd9 1241 tempRegValue &= ~PROTOCOL0_NMAX_RETX_MASK;
vpcola 0:f1d3878b8dd9 1242 tempRegValue |= xNMaxReTx;
vpcola 0:f1d3878b8dd9 1243
vpcola 0:f1d3878b8dd9 1244 /* Writes value on the PROTOCOL0 register */
vpcola 0:f1d3878b8dd9 1245 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1246
vpcola 0:f1d3878b8dd9 1247 }
vpcola 0:f1d3878b8dd9 1248
vpcola 0:f1d3878b8dd9 1249
vpcola 0:f1d3878b8dd9 1250 /**
vpcola 0:f1d3878b8dd9 1251 * @brief Returns the max number of automatic retransmission.
vpcola 0:f1d3878b8dd9 1252 * @param None.
vpcola 0:f1d3878b8dd9 1253 * @retval uint8_t Max number of retransmissions.
vpcola 0:f1d3878b8dd9 1254 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 1255 */
vpcola 0:f1d3878b8dd9 1256 uint8_t SpiritPktCommonGetNMaxReTx(void)
vpcola 0:f1d3878b8dd9 1257 {
vpcola 0:f1d3878b8dd9 1258 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1259
vpcola 0:f1d3878b8dd9 1260 /* Reads the PROTOCOL0 register value */
vpcola 0:f1d3878b8dd9 1261 g_xStatus = SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1262
vpcola 0:f1d3878b8dd9 1263 /* Build the value to be written */
vpcola 0:f1d3878b8dd9 1264 return ((tempRegValue & PROTOCOL0_NMAX_RETX_MASK)>>4);
vpcola 0:f1d3878b8dd9 1265
vpcola 0:f1d3878b8dd9 1266 }
vpcola 0:f1d3878b8dd9 1267
vpcola 0:f1d3878b8dd9 1268 /**
vpcola 0:f1d3878b8dd9 1269 * @brief Returns the TX ACK request
vpcola 0:f1d3878b8dd9 1270 * @param None.
vpcola 0:f1d3878b8dd9 1271 * @retval uint8_t Max number of retransmissions.
vpcola 0:f1d3878b8dd9 1272 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 1273 */
vpcola 0:f1d3878b8dd9 1274 SpiritFunctionalState SpiritPktCommonGetTxAckRequest(void)
vpcola 0:f1d3878b8dd9 1275 {
vpcola 0:f1d3878b8dd9 1276 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1277
vpcola 0:f1d3878b8dd9 1278 /* Reads the PROTOCOL0 register value */
vpcola 0:f1d3878b8dd9 1279 g_xStatus = SpiritSpiReadRegisters(RX_PCKT_INFO_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1280
vpcola 0:f1d3878b8dd9 1281 /* Build the value to be written */
vpcola 0:f1d3878b8dd9 1282 return (SpiritFunctionalState)((tempRegValue & TX_PCKT_INFO_NACK_RX)>>2);
vpcola 0:f1d3878b8dd9 1283
vpcola 0:f1d3878b8dd9 1284 }
vpcola 0:f1d3878b8dd9 1285
vpcola 0:f1d3878b8dd9 1286
vpcola 0:f1d3878b8dd9 1287 /**
vpcola 0:f1d3878b8dd9 1288 * @brief Returns the source address of the received packet.
vpcola 0:f1d3878b8dd9 1289 * @param None.
vpcola 0:f1d3878b8dd9 1290 * @retval uint8_t Source address of the received packet.
vpcola 0:f1d3878b8dd9 1291 */
vpcola 0:f1d3878b8dd9 1292 uint8_t SpiritPktCommonGetReceivedSourceAddress(void)
vpcola 0:f1d3878b8dd9 1293 {
vpcola 0:f1d3878b8dd9 1294 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1295
vpcola 0:f1d3878b8dd9 1296 /* Reads the RX_ADDR_FIELD1 register value */
vpcola 0:f1d3878b8dd9 1297 g_xStatus = SpiritSpiReadRegisters(RX_ADDR_FIELD1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1298
vpcola 0:f1d3878b8dd9 1299 /* Returns value */
vpcola 0:f1d3878b8dd9 1300 return tempRegValue;
vpcola 0:f1d3878b8dd9 1301
vpcola 0:f1d3878b8dd9 1302 }
vpcola 0:f1d3878b8dd9 1303
vpcola 0:f1d3878b8dd9 1304
vpcola 0:f1d3878b8dd9 1305 /**
vpcola 0:f1d3878b8dd9 1306 * @brief Returns the sequence number of the received packet.
vpcola 0:f1d3878b8dd9 1307 * @param None.
vpcola 0:f1d3878b8dd9 1308 * @retval uint8_t Received Sequence number.
vpcola 0:f1d3878b8dd9 1309 */
vpcola 0:f1d3878b8dd9 1310 uint8_t SpiritPktCommonGetReceivedSeqNumber(void)
vpcola 0:f1d3878b8dd9 1311 {
vpcola 0:f1d3878b8dd9 1312 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1313
vpcola 0:f1d3878b8dd9 1314 /* Reads the RX_PCKT_INFO register value */
vpcola 0:f1d3878b8dd9 1315 g_xStatus = SpiritSpiReadRegisters(RX_PCKT_INFO_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1316
vpcola 0:f1d3878b8dd9 1317 /* Obtains and returns the sequence number */
vpcola 0:f1d3878b8dd9 1318 return tempRegValue & 0x03;
vpcola 0:f1d3878b8dd9 1319
vpcola 0:f1d3878b8dd9 1320 }
vpcola 0:f1d3878b8dd9 1321
vpcola 0:f1d3878b8dd9 1322
vpcola 0:f1d3878b8dd9 1323 /**
vpcola 0:f1d3878b8dd9 1324 * @brief Returns the Nack bit of the received packet
vpcola 0:f1d3878b8dd9 1325 * @param None.
vpcola 0:f1d3878b8dd9 1326 * @retval uint8_t Value of the Nack bit.
vpcola 0:f1d3878b8dd9 1327 */
vpcola 0:f1d3878b8dd9 1328 uint8_t SpiritPktCommonGetReceivedNackRx(void)
vpcola 0:f1d3878b8dd9 1329 {
vpcola 0:f1d3878b8dd9 1330 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1331
vpcola 0:f1d3878b8dd9 1332 /* Reads the RX_PCKT_INFO register value */
vpcola 0:f1d3878b8dd9 1333 g_xStatus = SpiritSpiReadRegisters(RX_PCKT_INFO_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1334
vpcola 0:f1d3878b8dd9 1335 /* Obtains and returns the RX nack bit */
vpcola 0:f1d3878b8dd9 1336 return (tempRegValue >> 2) & 0x01;
vpcola 0:f1d3878b8dd9 1337
vpcola 0:f1d3878b8dd9 1338 }
vpcola 0:f1d3878b8dd9 1339
vpcola 0:f1d3878b8dd9 1340
vpcola 0:f1d3878b8dd9 1341 /**
vpcola 0:f1d3878b8dd9 1342 * @brief Returns the sequence number of the transmitted packet.
vpcola 0:f1d3878b8dd9 1343 * @param None.
vpcola 0:f1d3878b8dd9 1344 * @retval uint8_t Sequence number of the transmitted packet.
vpcola 0:f1d3878b8dd9 1345 */
vpcola 0:f1d3878b8dd9 1346 uint8_t SpiritPktCommonGetTransmittedSeqNumber(void)
vpcola 0:f1d3878b8dd9 1347 {
vpcola 0:f1d3878b8dd9 1348 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1349
vpcola 0:f1d3878b8dd9 1350 /* Reads the TX_PCKT_INFO register value */
vpcola 0:f1d3878b8dd9 1351 g_xStatus = SpiritSpiReadRegisters(TX_PCKT_INFO_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1352
vpcola 0:f1d3878b8dd9 1353 /* Obtains and returns the TX sequence number */
vpcola 0:f1d3878b8dd9 1354 return (tempRegValue >> 4) & 0x07;
vpcola 0:f1d3878b8dd9 1355
vpcola 0:f1d3878b8dd9 1356 }
vpcola 0:f1d3878b8dd9 1357
vpcola 0:f1d3878b8dd9 1358
vpcola 0:f1d3878b8dd9 1359 /**
vpcola 0:f1d3878b8dd9 1360 * @brief Returns the number of retransmission done on the transmitted packet.
vpcola 0:f1d3878b8dd9 1361 * @param None.
vpcola 0:f1d3878b8dd9 1362 * @retval uint8_t Number of retransmissions done until now.
vpcola 0:f1d3878b8dd9 1363 */
vpcola 0:f1d3878b8dd9 1364 uint8_t SpiritPktCommonGetNReTx(void)
vpcola 0:f1d3878b8dd9 1365 {
vpcola 0:f1d3878b8dd9 1366 uint8_t tempRetValue;
vpcola 0:f1d3878b8dd9 1367
vpcola 0:f1d3878b8dd9 1368 /* Reads the TX_PCKT_INFO register value */
vpcola 0:f1d3878b8dd9 1369 g_xStatus = SpiritSpiReadRegisters(TX_PCKT_INFO_BASE, 1, &tempRetValue);
vpcola 0:f1d3878b8dd9 1370
vpcola 0:f1d3878b8dd9 1371 /* Obtains and returns the number of retransmission done */
vpcola 0:f1d3878b8dd9 1372 return (tempRetValue & 0x0F);
vpcola 0:f1d3878b8dd9 1373
vpcola 0:f1d3878b8dd9 1374 }
vpcola 0:f1d3878b8dd9 1375
vpcola 0:f1d3878b8dd9 1376
vpcola 0:f1d3878b8dd9 1377 /**
vpcola 0:f1d3878b8dd9 1378 * @brief If enabled RX packet is accepted only if the masked control field matches the
vpcola 0:f1d3878b8dd9 1379 * masked control field reference (CONTROL_MASK & CONTROL_FIELD_REF == CONTROL_MASK & RX_CONTROL_FIELD).
vpcola 0:f1d3878b8dd9 1380 * @param xNewState new state for Control filtering enable bit.
vpcola 0:f1d3878b8dd9 1381 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 1382 * @retval None.
vpcola 0:f1d3878b8dd9 1383 * @note This filtering control is enabled by default but the control mask is by default set to 0.
vpcola 0:f1d3878b8dd9 1384 * As a matter of fact the user has to enable the control filtering bit after the packet initialization
vpcola 0:f1d3878b8dd9 1385 * because the PktInit routine disables it.
vpcola 0:f1d3878b8dd9 1386 */
vpcola 0:f1d3878b8dd9 1387 void SpiritPktCommonFilterOnControlField(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 1388 {
vpcola 0:f1d3878b8dd9 1389 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1390
vpcola 0:f1d3878b8dd9 1391 /* Check the parameters */
vpcola 0:f1d3878b8dd9 1392 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 1393
vpcola 0:f1d3878b8dd9 1394
vpcola 0:f1d3878b8dd9 1395 /* Modify the register value: set or reset the control bit filtering */
vpcola 0:f1d3878b8dd9 1396 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1397
vpcola 0:f1d3878b8dd9 1398 /* Set or reset the CONTROL filtering enabling bit */
vpcola 0:f1d3878b8dd9 1399 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 1400 {
vpcola 0:f1d3878b8dd9 1401 tempRegValue |= PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK;
vpcola 0:f1d3878b8dd9 1402 }
vpcola 0:f1d3878b8dd9 1403 else
vpcola 0:f1d3878b8dd9 1404 {
vpcola 0:f1d3878b8dd9 1405 tempRegValue &= ~PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK;
vpcola 0:f1d3878b8dd9 1406 }
vpcola 0:f1d3878b8dd9 1407
vpcola 0:f1d3878b8dd9 1408 /* Writes the new value on the PCKT_FLT_OPTIONS register */
vpcola 0:f1d3878b8dd9 1409 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1410
vpcola 0:f1d3878b8dd9 1411 }
vpcola 0:f1d3878b8dd9 1412
vpcola 0:f1d3878b8dd9 1413
vpcola 0:f1d3878b8dd9 1414 /**
vpcola 0:f1d3878b8dd9 1415 * @brief Returns the enable bit of the control field filtering.
vpcola 0:f1d3878b8dd9 1416 * @param None.
vpcola 0:f1d3878b8dd9 1417 * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 1418 */
vpcola 0:f1d3878b8dd9 1419 SpiritFunctionalState SpiritPktCommonGetFilterOnControlField(void)
vpcola 0:f1d3878b8dd9 1420 {
vpcola 0:f1d3878b8dd9 1421 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 1422
vpcola 0:f1d3878b8dd9 1423 /* Reads the register value */
vpcola 0:f1d3878b8dd9 1424 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 1425
vpcola 0:f1d3878b8dd9 1426 /* Gets the enable/disable bit in form of SpiritFunctionalState type */
vpcola 0:f1d3878b8dd9 1427 if(tempRegValue & PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK)
vpcola 0:f1d3878b8dd9 1428 {
vpcola 0:f1d3878b8dd9 1429 return S_ENABLE;
vpcola 0:f1d3878b8dd9 1430 }
vpcola 0:f1d3878b8dd9 1431 else
vpcola 0:f1d3878b8dd9 1432 {
vpcola 0:f1d3878b8dd9 1433 return S_DISABLE;
vpcola 0:f1d3878b8dd9 1434 }
vpcola 0:f1d3878b8dd9 1435
vpcola 0:f1d3878b8dd9 1436 }
vpcola 0:f1d3878b8dd9 1437
vpcola 0:f1d3878b8dd9 1438
vpcola 0:f1d3878b8dd9 1439 /**
vpcola 0:f1d3878b8dd9 1440 *@}
vpcola 0:f1d3878b8dd9 1441 */
vpcola 0:f1d3878b8dd9 1442
vpcola 0:f1d3878b8dd9 1443 /**
vpcola 0:f1d3878b8dd9 1444 *@}
vpcola 0:f1d3878b8dd9 1445 */
vpcola 0:f1d3878b8dd9 1446
vpcola 0:f1d3878b8dd9 1447
vpcola 0:f1d3878b8dd9 1448 /**
vpcola 0:f1d3878b8dd9 1449 *@}
vpcola 0:f1d3878b8dd9 1450 */
vpcola 0:f1d3878b8dd9 1451
vpcola 0:f1d3878b8dd9 1452
vpcola 0:f1d3878b8dd9 1453 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/