Easily add all supported connectivity methods to your mbed OS project

Dependencies:   type-yd-driver

Committer:
MACRUM
Date:
Wed Jul 12 10:52:58 2017 +0000
Revision:
0:615f90842ce8
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:615f90842ce8 1 /**
MACRUM 0:615f90842ce8 2 ******************************************************************************
MACRUM 0:615f90842ce8 3 * @file SPIRIT_PktStack.c
MACRUM 0:615f90842ce8 4 * @author VMA division - AMS
MACRUM 0:615f90842ce8 5 * @version 3.2.2
MACRUM 0:615f90842ce8 6 * @date 08-July-2015
MACRUM 0:615f90842ce8 7 * @brief Configuration and management of SPIRIT STack packets.
MACRUM 0:615f90842ce8 8 * @details
MACRUM 0:615f90842ce8 9 *
MACRUM 0:615f90842ce8 10 * @attention
MACRUM 0:615f90842ce8 11 *
MACRUM 0:615f90842ce8 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
MACRUM 0:615f90842ce8 13 *
MACRUM 0:615f90842ce8 14 * Redistribution and use in source and binary forms, with or without modification,
MACRUM 0:615f90842ce8 15 * are permitted provided that the following conditions are met:
MACRUM 0:615f90842ce8 16 * 1. Redistributions of source code must retain the above copyright notice,
MACRUM 0:615f90842ce8 17 * this list of conditions and the following disclaimer.
MACRUM 0:615f90842ce8 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
MACRUM 0:615f90842ce8 19 * this list of conditions and the following disclaimer in the documentation
MACRUM 0:615f90842ce8 20 * and/or other materials provided with the distribution.
MACRUM 0:615f90842ce8 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
MACRUM 0:615f90842ce8 22 * may be used to endorse or promote products derived from this software
MACRUM 0:615f90842ce8 23 * without specific prior written permission.
MACRUM 0:615f90842ce8 24 *
MACRUM 0:615f90842ce8 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
MACRUM 0:615f90842ce8 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
MACRUM 0:615f90842ce8 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
MACRUM 0:615f90842ce8 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
MACRUM 0:615f90842ce8 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
MACRUM 0:615f90842ce8 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
MACRUM 0:615f90842ce8 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
MACRUM 0:615f90842ce8 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
MACRUM 0:615f90842ce8 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
MACRUM 0:615f90842ce8 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MACRUM 0:615f90842ce8 35 *
MACRUM 0:615f90842ce8 36 ******************************************************************************
MACRUM 0:615f90842ce8 37 */
MACRUM 0:615f90842ce8 38
MACRUM 0:615f90842ce8 39 /* Includes ------------------------------------------------------------------*/
MACRUM 0:615f90842ce8 40 #include "SPIRIT_PktStack.h"
MACRUM 0:615f90842ce8 41 #include "MCU_Interface.h"
MACRUM 0:615f90842ce8 42
MACRUM 0:615f90842ce8 43
MACRUM 0:615f90842ce8 44 /**
MACRUM 0:615f90842ce8 45 * @addtogroup SPIRIT_Libraries
MACRUM 0:615f90842ce8 46 * @{
MACRUM 0:615f90842ce8 47 */
MACRUM 0:615f90842ce8 48
MACRUM 0:615f90842ce8 49
MACRUM 0:615f90842ce8 50 /**
MACRUM 0:615f90842ce8 51 * @addtogroup SPIRIT_PktStack
MACRUM 0:615f90842ce8 52 * @{
MACRUM 0:615f90842ce8 53 */
MACRUM 0:615f90842ce8 54
MACRUM 0:615f90842ce8 55
MACRUM 0:615f90842ce8 56 /**
MACRUM 0:615f90842ce8 57 * @defgroup PktStack_Private_TypesDefinitions Pkt STack Private Types Definitions
MACRUM 0:615f90842ce8 58 * @{
MACRUM 0:615f90842ce8 59 */
MACRUM 0:615f90842ce8 60
MACRUM 0:615f90842ce8 61 /**
MACRUM 0:615f90842ce8 62 *@}
MACRUM 0:615f90842ce8 63 */
MACRUM 0:615f90842ce8 64
MACRUM 0:615f90842ce8 65
MACRUM 0:615f90842ce8 66 /**
MACRUM 0:615f90842ce8 67 * @defgroup PktStack_Private_Defines Pkt STack Private Defines
MACRUM 0:615f90842ce8 68 * @{
MACRUM 0:615f90842ce8 69 */
MACRUM 0:615f90842ce8 70
MACRUM 0:615f90842ce8 71 /**
MACRUM 0:615f90842ce8 72 *@}
MACRUM 0:615f90842ce8 73 */
MACRUM 0:615f90842ce8 74
MACRUM 0:615f90842ce8 75
MACRUM 0:615f90842ce8 76 /**
MACRUM 0:615f90842ce8 77 * @defgroup PktStack_Private_Macros Pkt STack Private Macros
MACRUM 0:615f90842ce8 78 * @{
MACRUM 0:615f90842ce8 79 */
MACRUM 0:615f90842ce8 80
MACRUM 0:615f90842ce8 81 /**
MACRUM 0:615f90842ce8 82 *@}
MACRUM 0:615f90842ce8 83 */
MACRUM 0:615f90842ce8 84
MACRUM 0:615f90842ce8 85
MACRUM 0:615f90842ce8 86 /**
MACRUM 0:615f90842ce8 87 * @defgroup PktStack_Private_Variables Pkt STack Private Variables
MACRUM 0:615f90842ce8 88 * @{
MACRUM 0:615f90842ce8 89 */
MACRUM 0:615f90842ce8 90
MACRUM 0:615f90842ce8 91 /**
MACRUM 0:615f90842ce8 92 *@}
MACRUM 0:615f90842ce8 93 */
MACRUM 0:615f90842ce8 94
MACRUM 0:615f90842ce8 95
MACRUM 0:615f90842ce8 96 /**
MACRUM 0:615f90842ce8 97 * @defgroup PktStack_Private_FunctionPrototypes Pkt STack Private Function Prototypes
MACRUM 0:615f90842ce8 98 * @{
MACRUM 0:615f90842ce8 99 */
MACRUM 0:615f90842ce8 100
MACRUM 0:615f90842ce8 101 /**
MACRUM 0:615f90842ce8 102 *@}
MACRUM 0:615f90842ce8 103 */
MACRUM 0:615f90842ce8 104
MACRUM 0:615f90842ce8 105
MACRUM 0:615f90842ce8 106 /**
MACRUM 0:615f90842ce8 107 * @defgroup PktStack_Private_Functions Pkt STack Private Functions
MACRUM 0:615f90842ce8 108 * @{
MACRUM 0:615f90842ce8 109 */
MACRUM 0:615f90842ce8 110
MACRUM 0:615f90842ce8 111
MACRUM 0:615f90842ce8 112 /**
MACRUM 0:615f90842ce8 113 * @brief Initializes the SPIRIT STack packet according to the specified
MACRUM 0:615f90842ce8 114 * parameters in the PktStackInit.
MACRUM 0:615f90842ce8 115 * @param pxPktStackInit STack packet init structure.
MACRUM 0:615f90842ce8 116 * This parameter is a pointer to @ref PktStackInit.
MACRUM 0:615f90842ce8 117 * @retval None.
MACRUM 0:615f90842ce8 118 */
MACRUM 0:615f90842ce8 119 void SpiritPktStackInit(PktStackInit* pxPktStackInit)
MACRUM 0:615f90842ce8 120 {
MACRUM 0:615f90842ce8 121 uint8_t tempRegValue[4], i;
MACRUM 0:615f90842ce8 122
MACRUM 0:615f90842ce8 123 /* Check the parameters */
MACRUM 0:615f90842ce8 124 s_assert_param(IS_STACK_PREAMBLE_LENGTH(pxPktStackInit->xPreambleLength));
MACRUM 0:615f90842ce8 125 s_assert_param(IS_STACK_SYNC_LENGTH(pxPktStackInit->xSyncLength));
MACRUM 0:615f90842ce8 126 s_assert_param(IS_STACK_CRC_MODE(pxPktStackInit->xCrcMode));
MACRUM 0:615f90842ce8 127 s_assert_param(IS_STACK_LENGTH_WIDTH_BITS(pxPktStackInit->cPktLengthWidth));
MACRUM 0:615f90842ce8 128 s_assert_param(IS_STACK_FIX_VAR_LENGTH(pxPktStackInit->xFixVarLength));
MACRUM 0:615f90842ce8 129 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackInit->xFec));
MACRUM 0:615f90842ce8 130 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackInit->xDataWhitening));
MACRUM 0:615f90842ce8 131 s_assert_param(IS_STACK_CONTROL_LENGTH(pxPktStackInit->xControlLength));
MACRUM 0:615f90842ce8 132
MACRUM 0:615f90842ce8 133
MACRUM 0:615f90842ce8 134 /* Reads the PROTOCOL1 register */
MACRUM 0:615f90842ce8 135 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue[0]);
MACRUM 0:615f90842ce8 136
MACRUM 0:615f90842ce8 137 /* Mask a reserved bit */
MACRUM 0:615f90842ce8 138 tempRegValue[0] &= ~0x20;
MACRUM 0:615f90842ce8 139
MACRUM 0:615f90842ce8 140 /* Always (!) set the automatic packet filtering */
MACRUM 0:615f90842ce8 141 tempRegValue[0] |= PROTOCOL1_AUTO_PCKT_FLT_MASK;
MACRUM 0:615f90842ce8 142
MACRUM 0:615f90842ce8 143 /* Writes the value on register */
MACRUM 0:615f90842ce8 144 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue[0]);
MACRUM 0:615f90842ce8 145
MACRUM 0:615f90842ce8 146 /* Reads the PCKT_FLT_OPTIONS register */
MACRUM 0:615f90842ce8 147 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
MACRUM 0:615f90842ce8 148
MACRUM 0:615f90842ce8 149 /* Always reset the control and source filtering */
MACRUM 0:615f90842ce8 150 tempRegValue[0] &= ~(PCKT_FLT_OPTIONS_SOURCE_FILTERING_MASK | PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK);
MACRUM 0:615f90842ce8 151
MACRUM 0:615f90842ce8 152 /* Writes the value on register */
MACRUM 0:615f90842ce8 153 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
MACRUM 0:615f90842ce8 154
MACRUM 0:615f90842ce8 155
MACRUM 0:615f90842ce8 156 /* Address and control length setting: source and destination address are always present so ADDRESS_LENGTH=2 */
MACRUM 0:615f90842ce8 157 tempRegValue[0] = 0x10 | ((uint8_t) pxPktStackInit->xControlLength);
MACRUM 0:615f90842ce8 158
MACRUM 0:615f90842ce8 159
MACRUM 0:615f90842ce8 160 /* Packet format and width length setting */
MACRUM 0:615f90842ce8 161 pxPktStackInit->cPktLengthWidth == 0 ? pxPktStackInit->cPktLengthWidth=1 : pxPktStackInit->cPktLengthWidth;
MACRUM 0:615f90842ce8 162 tempRegValue[1] = ((uint8_t) PCKTCTRL3_PCKT_FRMT_STACK) | ((uint8_t)(pxPktStackInit->cPktLengthWidth-1));
MACRUM 0:615f90842ce8 163
MACRUM 0:615f90842ce8 164 /* Preamble, sync and fixed or variable length setting */
MACRUM 0:615f90842ce8 165 tempRegValue[2] = ((uint8_t) pxPktStackInit->xPreambleLength) | ((uint8_t) pxPktStackInit->xSyncLength) |
MACRUM 0:615f90842ce8 166 ((uint8_t) pxPktStackInit->xFixVarLength);
MACRUM 0:615f90842ce8 167
MACRUM 0:615f90842ce8 168 /* CRC length, whitening and FEC setting */
MACRUM 0:615f90842ce8 169 tempRegValue[3] = (uint8_t) pxPktStackInit->xCrcMode;
MACRUM 0:615f90842ce8 170
MACRUM 0:615f90842ce8 171 if(pxPktStackInit->xDataWhitening == S_ENABLE)
MACRUM 0:615f90842ce8 172 {
MACRUM 0:615f90842ce8 173 tempRegValue[3] |= PCKTCTRL1_WHIT_MASK;
MACRUM 0:615f90842ce8 174 }
MACRUM 0:615f90842ce8 175
MACRUM 0:615f90842ce8 176 if(pxPktStackInit->xFec == S_ENABLE)
MACRUM 0:615f90842ce8 177 {
MACRUM 0:615f90842ce8 178 tempRegValue[3] |= PCKTCTRL1_FEC_MASK;
MACRUM 0:615f90842ce8 179 }
MACRUM 0:615f90842ce8 180
MACRUM 0:615f90842ce8 181 /* Writes registers */
MACRUM 0:615f90842ce8 182 SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 4, tempRegValue);
MACRUM 0:615f90842ce8 183
MACRUM 0:615f90842ce8 184 /* Sync words setting */
MACRUM 0:615f90842ce8 185 for(i=0;i<4;i++)
MACRUM 0:615f90842ce8 186 {
MACRUM 0:615f90842ce8 187 if(i<3-(pxPktStackInit->xSyncLength >>1))
MACRUM 0:615f90842ce8 188 {
MACRUM 0:615f90842ce8 189 tempRegValue[i]=0;
MACRUM 0:615f90842ce8 190 }
MACRUM 0:615f90842ce8 191 else
MACRUM 0:615f90842ce8 192 {
MACRUM 0:615f90842ce8 193 tempRegValue[i] = (uint8_t)(pxPktStackInit->lSyncWords>>(8*i));
MACRUM 0:615f90842ce8 194 }
MACRUM 0:615f90842ce8 195 }
MACRUM 0:615f90842ce8 196
MACRUM 0:615f90842ce8 197 /* Enables or disables the CRC check */
MACRUM 0:615f90842ce8 198 if(pxPktStackInit->xCrcMode == PKT_NO_CRC)
MACRUM 0:615f90842ce8 199 {
MACRUM 0:615f90842ce8 200 SpiritPktStackFilterOnCrc(S_DISABLE);
MACRUM 0:615f90842ce8 201 }
MACRUM 0:615f90842ce8 202 else
MACRUM 0:615f90842ce8 203 {
MACRUM 0:615f90842ce8 204 SpiritPktStackFilterOnCrc(S_ENABLE);
MACRUM 0:615f90842ce8 205 }
MACRUM 0:615f90842ce8 206
MACRUM 0:615f90842ce8 207 /* Writes registers */
MACRUM 0:615f90842ce8 208 g_xStatus = SpiritSpiWriteRegisters(SYNC4_BASE, 4, tempRegValue);
MACRUM 0:615f90842ce8 209
MACRUM 0:615f90842ce8 210 }
MACRUM 0:615f90842ce8 211
MACRUM 0:615f90842ce8 212
MACRUM 0:615f90842ce8 213 /**
MACRUM 0:615f90842ce8 214 * @brief Returns the SPIRIT STack packet structure according to the specified parameters in the registers.
MACRUM 0:615f90842ce8 215 * @param pxPktStackInit STack packet init structure.
MACRUM 0:615f90842ce8 216 * This parameter is a pointer to @ref PktStackInit.
MACRUM 0:615f90842ce8 217 * @retval None.
MACRUM 0:615f90842ce8 218 */
MACRUM 0:615f90842ce8 219 void SpiritPktStackGetInfo(PktStackInit* pxPktStackInit)
MACRUM 0:615f90842ce8 220 {
MACRUM 0:615f90842ce8 221 uint8_t tempRegValue[10];
MACRUM 0:615f90842ce8 222
MACRUM 0:615f90842ce8 223 /* Reads registers */
MACRUM 0:615f90842ce8 224 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 10, tempRegValue);
MACRUM 0:615f90842ce8 225
MACRUM 0:615f90842ce8 226 /* Length width */
MACRUM 0:615f90842ce8 227 pxPktStackInit->cPktLengthWidth=(tempRegValue[1] & 0x0F)+1;
MACRUM 0:615f90842ce8 228
MACRUM 0:615f90842ce8 229 /* Control length */
MACRUM 0:615f90842ce8 230 pxPktStackInit->xControlLength=(StackControlLength)(tempRegValue[0] & 0x07);
MACRUM 0:615f90842ce8 231
MACRUM 0:615f90842ce8 232 /* CRC mode */
MACRUM 0:615f90842ce8 233 pxPktStackInit->xCrcMode=(StackCrcMode)(tempRegValue[3] & 0xE0);
MACRUM 0:615f90842ce8 234
MACRUM 0:615f90842ce8 235 /* Whitening */
MACRUM 0:615f90842ce8 236 pxPktStackInit->xDataWhitening=(SpiritFunctionalState)((tempRegValue[3] >> 4) & 0x01);
MACRUM 0:615f90842ce8 237
MACRUM 0:615f90842ce8 238 /* FEC */
MACRUM 0:615f90842ce8 239 pxPktStackInit->xFec=(SpiritFunctionalState)(tempRegValue[3] & 0x01);
MACRUM 0:615f90842ce8 240
MACRUM 0:615f90842ce8 241 /* FIX or VAR bit */
MACRUM 0:615f90842ce8 242 pxPktStackInit->xFixVarLength=(StackFixVarLength)(tempRegValue[2] & 0x01);
MACRUM 0:615f90842ce8 243
MACRUM 0:615f90842ce8 244 /* Preamble length */
MACRUM 0:615f90842ce8 245 pxPktStackInit->xPreambleLength=(StackPreambleLength)(tempRegValue[2] & 0xF8);
MACRUM 0:615f90842ce8 246
MACRUM 0:615f90842ce8 247 /* Sync length */
MACRUM 0:615f90842ce8 248 pxPktStackInit->xSyncLength=(StackSyncLength)(tempRegValue[2] & 0x06);
MACRUM 0:615f90842ce8 249
MACRUM 0:615f90842ce8 250 /* sync Words */
MACRUM 0:615f90842ce8 251 pxPktStackInit->lSyncWords=0;
MACRUM 0:615f90842ce8 252 for(uint8_t i=0 ; i<4 ; i++)
MACRUM 0:615f90842ce8 253 {
MACRUM 0:615f90842ce8 254 if(i>2-(pxPktStackInit->xSyncLength >>1))
MACRUM 0:615f90842ce8 255 {
MACRUM 0:615f90842ce8 256 pxPktStackInit->lSyncWords |= tempRegValue[i+6]<<(8*i);
MACRUM 0:615f90842ce8 257 }
MACRUM 0:615f90842ce8 258 }
MACRUM 0:615f90842ce8 259
MACRUM 0:615f90842ce8 260 }
MACRUM 0:615f90842ce8 261
MACRUM 0:615f90842ce8 262
MACRUM 0:615f90842ce8 263 /**
MACRUM 0:615f90842ce8 264 * @brief Initializes the SPIRIT STack packet addresses according to the specified
MACRUM 0:615f90842ce8 265 * parameters in the PktStackAddresses struct.
MACRUM 0:615f90842ce8 266 * @param pxPktStackAddresses STack packet addresses init structure.
MACRUM 0:615f90842ce8 267 * This parameter is a pointer to @ref PktStackAddressesInit .
MACRUM 0:615f90842ce8 268 * @retval None.
MACRUM 0:615f90842ce8 269 */
MACRUM 0:615f90842ce8 270 void SpiritPktStackAddressesInit(PktStackAddressesInit* pxPktStackAddresses)
MACRUM 0:615f90842ce8 271 {
MACRUM 0:615f90842ce8 272 uint8_t tempRegValue[3];
MACRUM 0:615f90842ce8 273
MACRUM 0:615f90842ce8 274 /* Check the parameters */
MACRUM 0:615f90842ce8 275 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackAddresses->xFilterOnMyAddress));
MACRUM 0:615f90842ce8 276 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackAddresses->xFilterOnMulticastAddress));
MACRUM 0:615f90842ce8 277 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackAddresses->xFilterOnBroadcastAddress));
MACRUM 0:615f90842ce8 278
MACRUM 0:615f90842ce8 279 /* Reads the filtering options ragister */
MACRUM 0:615f90842ce8 280 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
MACRUM 0:615f90842ce8 281
MACRUM 0:615f90842ce8 282 /* Enables or disables filtering on my address */
MACRUM 0:615f90842ce8 283 if(pxPktStackAddresses->xFilterOnMyAddress == S_ENABLE)
MACRUM 0:615f90842ce8 284 {
MACRUM 0:615f90842ce8 285 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
MACRUM 0:615f90842ce8 286 }
MACRUM 0:615f90842ce8 287 else
MACRUM 0:615f90842ce8 288 {
MACRUM 0:615f90842ce8 289 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
MACRUM 0:615f90842ce8 290 }
MACRUM 0:615f90842ce8 291
MACRUM 0:615f90842ce8 292 /* Enables or disables filtering on multicast address */
MACRUM 0:615f90842ce8 293 if(pxPktStackAddresses->xFilterOnMulticastAddress == S_ENABLE)
MACRUM 0:615f90842ce8 294 {
MACRUM 0:615f90842ce8 295 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
MACRUM 0:615f90842ce8 296 }
MACRUM 0:615f90842ce8 297 else
MACRUM 0:615f90842ce8 298 {
MACRUM 0:615f90842ce8 299 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
MACRUM 0:615f90842ce8 300 }
MACRUM 0:615f90842ce8 301
MACRUM 0:615f90842ce8 302 /* Enables or disables filtering on broadcast address */
MACRUM 0:615f90842ce8 303 if(pxPktStackAddresses->xFilterOnBroadcastAddress == S_ENABLE)
MACRUM 0:615f90842ce8 304 {
MACRUM 0:615f90842ce8 305 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
MACRUM 0:615f90842ce8 306 }
MACRUM 0:615f90842ce8 307 else
MACRUM 0:615f90842ce8 308 {
MACRUM 0:615f90842ce8 309 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
MACRUM 0:615f90842ce8 310 }
MACRUM 0:615f90842ce8 311
MACRUM 0:615f90842ce8 312 /* Writes value on the register */
MACRUM 0:615f90842ce8 313 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
MACRUM 0:615f90842ce8 314
MACRUM 0:615f90842ce8 315 /* Fills array with the addresses passed in the structure */
MACRUM 0:615f90842ce8 316 tempRegValue[0] = pxPktStackAddresses->cBroadcastAddress;
MACRUM 0:615f90842ce8 317 tempRegValue[1] = pxPktStackAddresses->cMulticastAddress;
MACRUM 0:615f90842ce8 318 tempRegValue[2] = pxPktStackAddresses->cMyAddress;
MACRUM 0:615f90842ce8 319
MACRUM 0:615f90842ce8 320 /* Writes them on the addresses registers */
MACRUM 0:615f90842ce8 321 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue);
MACRUM 0:615f90842ce8 322
MACRUM 0:615f90842ce8 323 }
MACRUM 0:615f90842ce8 324
MACRUM 0:615f90842ce8 325
MACRUM 0:615f90842ce8 326 /**
MACRUM 0:615f90842ce8 327 * @brief Returns the SPIRIT STack packet addresses structure according to the specified
MACRUM 0:615f90842ce8 328 * parameters in the registers.
MACRUM 0:615f90842ce8 329 * @param pxPktStackAddresses STack packet addresses init structure.
MACRUM 0:615f90842ce8 330 * This parameter is a pointer to @ref PktStackAddresses.
MACRUM 0:615f90842ce8 331 * @retval None.
MACRUM 0:615f90842ce8 332 */
MACRUM 0:615f90842ce8 333 void SpiritPktStackGetAddressesInfo(PktStackAddressesInit* pxPktStackAddresses)
MACRUM 0:615f90842ce8 334 {
MACRUM 0:615f90842ce8 335 uint8_t tempRegValue[3];
MACRUM 0:615f90842ce8 336
MACRUM 0:615f90842ce8 337 /* Reads values on the PCKT_FLT_GOALS registers */
MACRUM 0:615f90842ce8 338 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue);
MACRUM 0:615f90842ce8 339
MACRUM 0:615f90842ce8 340 /* Fit the structure with the read addresses */
MACRUM 0:615f90842ce8 341 pxPktStackAddresses->cBroadcastAddress = tempRegValue[0];
MACRUM 0:615f90842ce8 342 pxPktStackAddresses->cMulticastAddress = tempRegValue[1];
MACRUM 0:615f90842ce8 343 pxPktStackAddresses->cMyAddress = tempRegValue[2];
MACRUM 0:615f90842ce8 344
MACRUM 0:615f90842ce8 345 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
MACRUM 0:615f90842ce8 346
MACRUM 0:615f90842ce8 347 /* Fit the structure with the read filtering bits */
MACRUM 0:615f90842ce8 348 pxPktStackAddresses->xFilterOnBroadcastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 1) & 0x01);
MACRUM 0:615f90842ce8 349 pxPktStackAddresses->xFilterOnMulticastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 2) & 0x01);
MACRUM 0:615f90842ce8 350 pxPktStackAddresses->xFilterOnMyAddress = (SpiritFunctionalState)((tempRegValue[0] >> 3) & 0x01);
MACRUM 0:615f90842ce8 351
MACRUM 0:615f90842ce8 352 }
MACRUM 0:615f90842ce8 353
MACRUM 0:615f90842ce8 354
MACRUM 0:615f90842ce8 355 /**
MACRUM 0:615f90842ce8 356 * @brief Initializes the SPIRIT STack packet LLP options according to the specified
MACRUM 0:615f90842ce8 357 * parameters in the PktStackLlpInit struct.
MACRUM 0:615f90842ce8 358 * @param pxPktStackLlpInit STack packet LLP init structure.
MACRUM 0:615f90842ce8 359 * This parameter is a pointer to @ref PktStackLlpInit.
MACRUM 0:615f90842ce8 360 * @retval None.
MACRUM 0:615f90842ce8 361 */
MACRUM 0:615f90842ce8 362 void SpiritPktStackLlpInit(PktStackLlpInit* pxPktStackLlpInit)
MACRUM 0:615f90842ce8 363 {
MACRUM 0:615f90842ce8 364 uint8_t tempRegValue[2];
MACRUM 0:615f90842ce8 365
MACRUM 0:615f90842ce8 366 /* Check the parameters */
MACRUM 0:615f90842ce8 367 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackLlpInit->xPiggybacking));
MACRUM 0:615f90842ce8 368 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackLlpInit->xAutoAck));
MACRUM 0:615f90842ce8 369 s_assert_param(IS_STACK_NMAX_RETX(pxPktStackLlpInit->xNMaxRetx));
MACRUM 0:615f90842ce8 370 /* check if piggybacking is enabled and autoack is disabled */
MACRUM 0:615f90842ce8 371 s_assert_param(!(pxPktStackLlpInit->xPiggybacking==S_ENABLE && pxPktStackLlpInit->xAutoAck==S_DISABLE));
MACRUM 0:615f90842ce8 372
MACRUM 0:615f90842ce8 373 /* Piggybacking mechanism setting on the PROTOCOL1 register */
MACRUM 0:615f90842ce8 374 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 2, tempRegValue);
MACRUM 0:615f90842ce8 375 if(pxPktStackLlpInit->xPiggybacking == S_ENABLE)
MACRUM 0:615f90842ce8 376 {
MACRUM 0:615f90842ce8 377 tempRegValue[0] |= PROTOCOL1_PIGGYBACKING_MASK;
MACRUM 0:615f90842ce8 378 }
MACRUM 0:615f90842ce8 379 else
MACRUM 0:615f90842ce8 380 {
MACRUM 0:615f90842ce8 381 tempRegValue[0] &= ~PROTOCOL1_PIGGYBACKING_MASK;
MACRUM 0:615f90842ce8 382 }
MACRUM 0:615f90842ce8 383
MACRUM 0:615f90842ce8 384 /* RX and TX autoack mechanisms setting on the PROTOCOL0 register */
MACRUM 0:615f90842ce8 385 if(pxPktStackLlpInit->xAutoAck == S_ENABLE)
MACRUM 0:615f90842ce8 386 {
MACRUM 0:615f90842ce8 387 tempRegValue[1] |= PROTOCOL0_AUTO_ACK_MASK;
MACRUM 0:615f90842ce8 388 }
MACRUM 0:615f90842ce8 389 else
MACRUM 0:615f90842ce8 390 {
MACRUM 0:615f90842ce8 391 tempRegValue[1] &= ~PROTOCOL0_AUTO_ACK_MASK;
MACRUM 0:615f90842ce8 392 }
MACRUM 0:615f90842ce8 393
MACRUM 0:615f90842ce8 394 /* Max number of retransmission setting */
MACRUM 0:615f90842ce8 395 tempRegValue[1] &= ~PROTOCOL0_NMAX_RETX_MASK;
MACRUM 0:615f90842ce8 396 tempRegValue[1] |= pxPktStackLlpInit->xNMaxRetx;
MACRUM 0:615f90842ce8 397
MACRUM 0:615f90842ce8 398 /* Writes registers */
MACRUM 0:615f90842ce8 399 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 2, tempRegValue);
MACRUM 0:615f90842ce8 400
MACRUM 0:615f90842ce8 401 }
MACRUM 0:615f90842ce8 402
MACRUM 0:615f90842ce8 403
MACRUM 0:615f90842ce8 404 /**
MACRUM 0:615f90842ce8 405 * @brief Returns the SPIRIT STack packet LLP options according to the specified
MACRUM 0:615f90842ce8 406 * values in the registers.
MACRUM 0:615f90842ce8 407 * @param pxPktStackLlpInit STack packet LLP structure.
MACRUM 0:615f90842ce8 408 * This parameter is a pointer to @ref PktStackLlpInit.
MACRUM 0:615f90842ce8 409 * @retval None.
MACRUM 0:615f90842ce8 410 */
MACRUM 0:615f90842ce8 411 void SpiritPktStackLlpGetInfo(PktStackLlpInit* pxPktStackLlpInit)
MACRUM 0:615f90842ce8 412 {
MACRUM 0:615f90842ce8 413 uint8_t tempRegValue[2];
MACRUM 0:615f90842ce8 414
MACRUM 0:615f90842ce8 415 /* Piggybacking mechanism setting on the PROTOCOL1 register */
MACRUM 0:615f90842ce8 416 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 2, tempRegValue);
MACRUM 0:615f90842ce8 417
MACRUM 0:615f90842ce8 418 /* Fit the structure with the read values */
MACRUM 0:615f90842ce8 419 pxPktStackLlpInit->xPiggybacking = (SpiritFunctionalState)((tempRegValue[0] >> 6) & 0x01);
MACRUM 0:615f90842ce8 420 pxPktStackLlpInit->xAutoAck = (SpiritFunctionalState)((tempRegValue[1] >> 2) & 0x01);
MACRUM 0:615f90842ce8 421 pxPktStackLlpInit->xNMaxRetx = (StackNMaxReTx)(tempRegValue[1] & PROTOCOL0_NMAX_RETX_MASK);
MACRUM 0:615f90842ce8 422
MACRUM 0:615f90842ce8 423 }
MACRUM 0:615f90842ce8 424
MACRUM 0:615f90842ce8 425
MACRUM 0:615f90842ce8 426 /**
MACRUM 0:615f90842ce8 427 * @brief Configures the STack packet format for SPIRIT.
MACRUM 0:615f90842ce8 428 * @param None.
MACRUM 0:615f90842ce8 429 * @retval None.
MACRUM 0:615f90842ce8 430 */
MACRUM 0:615f90842ce8 431 void SpiritPktStackSetFormat(void)
MACRUM 0:615f90842ce8 432 {
MACRUM 0:615f90842ce8 433 uint8_t tempRegValue;
MACRUM 0:615f90842ce8 434
MACRUM 0:615f90842ce8 435 /* Reads the PCKTCTRL3 register value */
MACRUM 0:615f90842ce8 436 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 437
MACRUM 0:615f90842ce8 438 /* Build value to be written. Also set to 0 the direct RX mode bits */
MACRUM 0:615f90842ce8 439 tempRegValue &= 0x0F;
MACRUM 0:615f90842ce8 440 tempRegValue |= ((uint8_t)PCKTCTRL3_PCKT_FRMT_STACK);
MACRUM 0:615f90842ce8 441
MACRUM 0:615f90842ce8 442 /* Writes the value on the PCKTCTRL3 register. */
MACRUM 0:615f90842ce8 443 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 444
MACRUM 0:615f90842ce8 445 /* Reads the PCKTCTRL1 register value */
MACRUM 0:615f90842ce8 446 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 447
MACRUM 0:615f90842ce8 448 /* Build the new value. Set to 0 the direct TX mode bits */
MACRUM 0:615f90842ce8 449 tempRegValue &= 0xF3;
MACRUM 0:615f90842ce8 450
MACRUM 0:615f90842ce8 451 /* Writes the PCKTCTRL1 value on register */
MACRUM 0:615f90842ce8 452 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 453
MACRUM 0:615f90842ce8 454 /* Reads the PROTOCOL1 register */
MACRUM 0:615f90842ce8 455 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 456
MACRUM 0:615f90842ce8 457 /* Mask a reserved bit */
MACRUM 0:615f90842ce8 458 tempRegValue &= ~0x20;
MACRUM 0:615f90842ce8 459
MACRUM 0:615f90842ce8 460 /* Writes the value on the PROTOCOL1 register */
MACRUM 0:615f90842ce8 461 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 462
MACRUM 0:615f90842ce8 463 }
MACRUM 0:615f90842ce8 464
MACRUM 0:615f90842ce8 465
MACRUM 0:615f90842ce8 466 /**
MACRUM 0:615f90842ce8 467 * @brief Sets the address length for SPIRIT STack packets (always 2).
MACRUM 0:615f90842ce8 468 * @param None.
MACRUM 0:615f90842ce8 469 * @retval None.
MACRUM 0:615f90842ce8 470 */
MACRUM 0:615f90842ce8 471 void SpiritPktStackSetAddressLength(void)
MACRUM 0:615f90842ce8 472 {
MACRUM 0:615f90842ce8 473 uint8_t tempRegValue;
MACRUM 0:615f90842ce8 474
MACRUM 0:615f90842ce8 475 /* Reads the PCKTCTRL4 register value */
MACRUM 0:615f90842ce8 476 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 477
MACRUM 0:615f90842ce8 478 /* Build the new value */
MACRUM 0:615f90842ce8 479 tempRegValue &= ~PCKTCTRL4_ADDRESS_LEN_MASK;
MACRUM 0:615f90842ce8 480 tempRegValue |= ((uint8_t)0x10);
MACRUM 0:615f90842ce8 481
MACRUM 0:615f90842ce8 482 /* Writes the value on the PCKTCTRL4 register */
MACRUM 0:615f90842ce8 483 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 484
MACRUM 0:615f90842ce8 485 }
MACRUM 0:615f90842ce8 486
MACRUM 0:615f90842ce8 487
MACRUM 0:615f90842ce8 488 /**
MACRUM 0:615f90842ce8 489 * @brief Sets the payload length for SPIRIT STack packets. Since the packet length
MACRUM 0:615f90842ce8 490 * depends from the address (always 2 for this packet format)
MACRUM 0:615f90842ce8 491 * and the control field size, this function reads the control length register
MACRUM 0:615f90842ce8 492 * content in order to determine the correct packet length to be written.
MACRUM 0:615f90842ce8 493 * @param nPayloadLength payload length in bytes.
MACRUM 0:615f90842ce8 494 * This parameter can be any value of uint16_t.
MACRUM 0:615f90842ce8 495 * @retval None.
MACRUM 0:615f90842ce8 496 */
MACRUM 0:615f90842ce8 497 void SpiritPktStackSetPayloadLength(uint16_t nPayloadLength)
MACRUM 0:615f90842ce8 498 {
MACRUM 0:615f90842ce8 499 uint8_t tempRegValue[2];
MACRUM 0:615f90842ce8 500
MACRUM 0:615f90842ce8 501 /* Computes the oversize (address + control) size */
MACRUM 0:615f90842ce8 502 uint16_t overSize = 2 + (uint16_t) SpiritPktStackGetControlLength();
MACRUM 0:615f90842ce8 503
MACRUM 0:615f90842ce8 504 /* Computes PCKTLEN0 value from lPayloadLength */
MACRUM 0:615f90842ce8 505 tempRegValue[1]=STACK_BUILD_PCKTLEN0(nPayloadLength+overSize);
MACRUM 0:615f90842ce8 506 /* Computes PCKTLEN1 value from lPayloadLength */
MACRUM 0:615f90842ce8 507 tempRegValue[0]=STACK_BUILD_PCKTLEN1(nPayloadLength+overSize);
MACRUM 0:615f90842ce8 508
MACRUM 0:615f90842ce8 509 /* Writes the value on the PCKTLENx registers */
MACRUM 0:615f90842ce8 510 g_xStatus = SpiritSpiWriteRegisters(PCKTLEN1_BASE, 2, tempRegValue);
MACRUM 0:615f90842ce8 511
MACRUM 0:615f90842ce8 512 }
MACRUM 0:615f90842ce8 513
MACRUM 0:615f90842ce8 514
MACRUM 0:615f90842ce8 515 /**
MACRUM 0:615f90842ce8 516 * @brief Returns the payload length for SPIRIT STack packets. Since the
MACRUM 0:615f90842ce8 517 * packet length depends from the address and the control
MACRUM 0:615f90842ce8 518 * field size, this function reads the correspondent
MACRUM 0:615f90842ce8 519 * registers in order to determine the correct payload length
MACRUM 0:615f90842ce8 520 * to be returned.
MACRUM 0:615f90842ce8 521 * @param None.
MACRUM 0:615f90842ce8 522 * @retval uint16_t Payload length.
MACRUM 0:615f90842ce8 523 */
MACRUM 0:615f90842ce8 524 uint16_t SpiritPktStackGetPayloadLength(void)
MACRUM 0:615f90842ce8 525 {
MACRUM 0:615f90842ce8 526 uint8_t tempRegValue[2];
MACRUM 0:615f90842ce8 527 /* Computes the oversize (address + control) size */
MACRUM 0:615f90842ce8 528 uint16_t overSize = 2 + (uint16_t) SpiritPktStackGetControlLength();
MACRUM 0:615f90842ce8 529
MACRUM 0:615f90842ce8 530 /* Reads the PCKTLEN1 registers value */
MACRUM 0:615f90842ce8 531 g_xStatus = SpiritSpiReadRegisters(PCKTLEN1_BASE, 2, tempRegValue);
MACRUM 0:615f90842ce8 532
MACRUM 0:615f90842ce8 533 /* Rebuild and return the payload length value */
MACRUM 0:615f90842ce8 534 return ((((uint16_t) tempRegValue[1])<<8) + (uint16_t) tempRegValue[0] - overSize);
MACRUM 0:615f90842ce8 535
MACRUM 0:615f90842ce8 536 }
MACRUM 0:615f90842ce8 537
MACRUM 0:615f90842ce8 538
MACRUM 0:615f90842ce8 539 /**
MACRUM 0:615f90842ce8 540 * @brief Computes and sets the variable payload length for SPIRIT STack packets.
MACRUM 0:615f90842ce8 541 * @param nMaxPayloadLength payload length in bytes.
MACRUM 0:615f90842ce8 542 * This parameter is an uint16_t.
MACRUM 0:615f90842ce8 543 * @param xControlLength control length in bytes.
MACRUM 0:615f90842ce8 544 * This parameter can be any value of @ref StackControlLength.
MACRUM 0:615f90842ce8 545 * @retval None.
MACRUM 0:615f90842ce8 546 */
MACRUM 0:615f90842ce8 547 void SpiritPktStackSetVarLengthWidth(uint16_t nMaxPayloadLength, StackControlLength xControlLength)
MACRUM 0:615f90842ce8 548 {
MACRUM 0:615f90842ce8 549 uint8_t tempRegValue,
MACRUM 0:615f90842ce8 550 i;
MACRUM 0:615f90842ce8 551 uint32_t packetLength;
MACRUM 0:615f90842ce8 552
MACRUM 0:615f90842ce8 553
MACRUM 0:615f90842ce8 554 /* packet length = payload length + address length (2) + control length */
MACRUM 0:615f90842ce8 555 packetLength=nMaxPayloadLength+2+xControlLength;
MACRUM 0:615f90842ce8 556
MACRUM 0:615f90842ce8 557 /* Computes the number of bits */
MACRUM 0:615f90842ce8 558 for(i=0;i<16;i++)
MACRUM 0:615f90842ce8 559 {
MACRUM 0:615f90842ce8 560 if(packetLength == 0)
MACRUM 0:615f90842ce8 561 {
MACRUM 0:615f90842ce8 562 break;
MACRUM 0:615f90842ce8 563 }
MACRUM 0:615f90842ce8 564 packetLength >>= 1;
MACRUM 0:615f90842ce8 565 }
MACRUM 0:615f90842ce8 566 i==0 ? i=1 : i;
MACRUM 0:615f90842ce8 567
MACRUM 0:615f90842ce8 568 /* Reads the PCKTCTRL3 register value */
MACRUM 0:615f90842ce8 569 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 570
MACRUM 0:615f90842ce8 571 /* Build the register value */
MACRUM 0:615f90842ce8 572 tempRegValue &= ~PCKTCTRL3_LEN_WID_MASK;
MACRUM 0:615f90842ce8 573 tempRegValue |= ((uint8_t)(i-1));
MACRUM 0:615f90842ce8 574
MACRUM 0:615f90842ce8 575 /* Writes the PCKTCTRL3 register value */
MACRUM 0:615f90842ce8 576 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 577
MACRUM 0:615f90842ce8 578 }
MACRUM 0:615f90842ce8 579
MACRUM 0:615f90842ce8 580
MACRUM 0:615f90842ce8 581 /**
MACRUM 0:615f90842ce8 582 * @brief Rx packet source mask. Used to mask the address of the accepted packets. If 0 -> no filtering.
MACRUM 0:615f90842ce8 583 * @param cMask Rx source mask.
MACRUM 0:615f90842ce8 584 * This parameter is an uint8_t.
MACRUM 0:615f90842ce8 585 * @retval None.
MACRUM 0:615f90842ce8 586 */
MACRUM 0:615f90842ce8 587 void SpiritPktStackSetRxSourceMask(uint8_t cMask)
MACRUM 0:615f90842ce8 588 {
MACRUM 0:615f90842ce8 589 /* Writes value on the register PCKT_FLT_GOALS_SOURCE_MASK */
MACRUM 0:615f90842ce8 590 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_SOURCE_MASK_BASE, 1, &cMask);
MACRUM 0:615f90842ce8 591
MACRUM 0:615f90842ce8 592 }
MACRUM 0:615f90842ce8 593
MACRUM 0:615f90842ce8 594
MACRUM 0:615f90842ce8 595 /**
MACRUM 0:615f90842ce8 596 * @brief Returns the Rx packet source mask. Used to mask the address of the accepted packets. If 0 -> no filtering.
MACRUM 0:615f90842ce8 597 * @param None.
MACRUM 0:615f90842ce8 598 * @retval uint8_t Rx source mask.
MACRUM 0:615f90842ce8 599 */
MACRUM 0:615f90842ce8 600 uint8_t SpiritPktStackGetRxSourceMask(void)
MACRUM 0:615f90842ce8 601 {
MACRUM 0:615f90842ce8 602 uint8_t tempRegValue;
MACRUM 0:615f90842ce8 603
MACRUM 0:615f90842ce8 604 /* Writes value on the PCKT_FLT_GOALS_SOURCE_MASK register */
MACRUM 0:615f90842ce8 605 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_SOURCE_MASK_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 606
MACRUM 0:615f90842ce8 607 /* Return the read value */
MACRUM 0:615f90842ce8 608 return tempRegValue;
MACRUM 0:615f90842ce8 609
MACRUM 0:615f90842ce8 610 }
MACRUM 0:615f90842ce8 611
MACRUM 0:615f90842ce8 612 /**
MACRUM 0:615f90842ce8 613 * @brief Returns the packet length field of the received packet.
MACRUM 0:615f90842ce8 614 * @param None.
MACRUM 0:615f90842ce8 615 * @retval uint16_t Packet length.
MACRUM 0:615f90842ce8 616 */
MACRUM 0:615f90842ce8 617 uint16_t SpiritPktStackGetReceivedPktLength(void)
MACRUM 0:615f90842ce8 618 {
MACRUM 0:615f90842ce8 619 uint8_t tempRegValue[2];
MACRUM 0:615f90842ce8 620 uint16_t tempLength;
MACRUM 0:615f90842ce8 621
MACRUM 0:615f90842ce8 622 /* Reads the RX_PCKT_LENx registers value */
MACRUM 0:615f90842ce8 623 g_xStatus = SpiritSpiReadRegisters(RX_PCKT_LEN1_BASE, 2, tempRegValue);
MACRUM 0:615f90842ce8 624
MACRUM 0:615f90842ce8 625 /* Rebuild and return the the length field */
MACRUM 0:615f90842ce8 626 tempLength = ((((uint16_t) tempRegValue[0]) << 8) + (uint16_t) tempRegValue[1]);
MACRUM 0:615f90842ce8 627
MACRUM 0:615f90842ce8 628 /* Computes the oversize (address + control) size */
MACRUM 0:615f90842ce8 629 tempLength -= 2 + (uint16_t) SpiritPktStackGetControlLength();
MACRUM 0:615f90842ce8 630
MACRUM 0:615f90842ce8 631 return tempLength;
MACRUM 0:615f90842ce8 632
MACRUM 0:615f90842ce8 633 }
MACRUM 0:615f90842ce8 634
MACRUM 0:615f90842ce8 635
MACRUM 0:615f90842ce8 636 /**
MACRUM 0:615f90842ce8 637 * @brief If enabled RX packet is accepted only if the masked source address field matches the
MACRUM 0:615f90842ce8 638 * masked source address field reference (SOURCE_MASK & SOURCE_FIELD_REF == SOURCE_MASK & RX_SOURCE_FIELD).
MACRUM 0:615f90842ce8 639 * @param xNewState new state for Source address filtering enable bit.
MACRUM 0:615f90842ce8 640 * This parameter can be S_ENABLE or S_DISABLE.
MACRUM 0:615f90842ce8 641 * @retval None.
MACRUM 0:615f90842ce8 642 * @note This filtering control is enabled by default but the source address mask is by default set to 0.
MACRUM 0:615f90842ce8 643 * As a matter of fact the user has to enable the source filtering bit after the packet initialization
MACRUM 0:615f90842ce8 644 * because the PktInit routine disables it.
MACRUM 0:615f90842ce8 645 */
MACRUM 0:615f90842ce8 646 void SpiritPktStackFilterOnSourceAddress(SpiritFunctionalState xNewState)
MACRUM 0:615f90842ce8 647 {
MACRUM 0:615f90842ce8 648 uint8_t tempRegValue;
MACRUM 0:615f90842ce8 649
MACRUM 0:615f90842ce8 650 /* Check the parameters */
MACRUM 0:615f90842ce8 651 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
MACRUM 0:615f90842ce8 652
MACRUM 0:615f90842ce8 653
MACRUM 0:615f90842ce8 654 /* Modify the register value: set or reset the source bit filtering */
MACRUM 0:615f90842ce8 655 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 656
MACRUM 0:615f90842ce8 657 /* Set or reset the SOURCE ADDRESS filtering enabling bit */
MACRUM 0:615f90842ce8 658 if(xNewState == S_ENABLE)
MACRUM 0:615f90842ce8 659 {
MACRUM 0:615f90842ce8 660 tempRegValue |= PCKT_FLT_OPTIONS_SOURCE_FILTERING_MASK;
MACRUM 0:615f90842ce8 661 }
MACRUM 0:615f90842ce8 662 else
MACRUM 0:615f90842ce8 663 {
MACRUM 0:615f90842ce8 664 tempRegValue &= ~PCKT_FLT_OPTIONS_SOURCE_FILTERING_MASK;
MACRUM 0:615f90842ce8 665 }
MACRUM 0:615f90842ce8 666
MACRUM 0:615f90842ce8 667 /* Writes the new value on the PCKT_FLT_OPTIONS register */
MACRUM 0:615f90842ce8 668 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
MACRUM 0:615f90842ce8 669
MACRUM 0:615f90842ce8 670 }
MACRUM 0:615f90842ce8 671
MACRUM 0:615f90842ce8 672 /**
MACRUM 0:615f90842ce8 673 *@}
MACRUM 0:615f90842ce8 674 */
MACRUM 0:615f90842ce8 675
MACRUM 0:615f90842ce8 676 /**
MACRUM 0:615f90842ce8 677 *@}
MACRUM 0:615f90842ce8 678 */
MACRUM 0:615f90842ce8 679
MACRUM 0:615f90842ce8 680
MACRUM 0:615f90842ce8 681 /**
MACRUM 0:615f90842ce8 682 *@}
MACRUM 0:615f90842ce8 683 */
MACRUM 0:615f90842ce8 684
MACRUM 0:615f90842ce8 685
MACRUM 0:615f90842ce8 686
MACRUM 0:615f90842ce8 687 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/