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_PktStack.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 SPIRIT STack 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_PktStack.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_PktStack
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 PktStack_Private_TypesDefinitions Pkt STack 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 PktStack_Private_Defines Pkt STack 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 PktStack_Private_Macros Pkt STack 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 PktStack_Private_Variables Pkt STack 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 * @defgroup PktStack_Private_FunctionPrototypes Pkt STack Private Function Prototypes
vpcola 0:f1d3878b8dd9 98 * @{
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 * @defgroup PktStack_Private_Functions Pkt STack Private Functions
vpcola 0:f1d3878b8dd9 108 * @{
vpcola 0:f1d3878b8dd9 109 */
vpcola 0:f1d3878b8dd9 110
vpcola 0:f1d3878b8dd9 111
vpcola 0:f1d3878b8dd9 112 /**
vpcola 0:f1d3878b8dd9 113 * @brief Initializes the SPIRIT STack packet according to the specified
vpcola 0:f1d3878b8dd9 114 * parameters in the PktStackInit.
vpcola 0:f1d3878b8dd9 115 * @param pxPktStackInit STack packet init structure.
vpcola 0:f1d3878b8dd9 116 * This parameter is a pointer to @ref PktStackInit.
vpcola 0:f1d3878b8dd9 117 * @retval None.
vpcola 0:f1d3878b8dd9 118 */
vpcola 0:f1d3878b8dd9 119 void SpiritPktStackInit(PktStackInit* pxPktStackInit)
vpcola 0:f1d3878b8dd9 120 {
vpcola 0:f1d3878b8dd9 121 uint8_t tempRegValue[4], i;
vpcola 0:f1d3878b8dd9 122
vpcola 0:f1d3878b8dd9 123 /* Check the parameters */
vpcola 0:f1d3878b8dd9 124 s_assert_param(IS_STACK_PREAMBLE_LENGTH(pxPktStackInit->xPreambleLength));
vpcola 0:f1d3878b8dd9 125 s_assert_param(IS_STACK_SYNC_LENGTH(pxPktStackInit->xSyncLength));
vpcola 0:f1d3878b8dd9 126 s_assert_param(IS_STACK_CRC_MODE(pxPktStackInit->xCrcMode));
vpcola 0:f1d3878b8dd9 127 s_assert_param(IS_STACK_LENGTH_WIDTH_BITS(pxPktStackInit->cPktLengthWidth));
vpcola 0:f1d3878b8dd9 128 s_assert_param(IS_STACK_FIX_VAR_LENGTH(pxPktStackInit->xFixVarLength));
vpcola 0:f1d3878b8dd9 129 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackInit->xFec));
vpcola 0:f1d3878b8dd9 130 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackInit->xDataWhitening));
vpcola 0:f1d3878b8dd9 131 s_assert_param(IS_STACK_CONTROL_LENGTH(pxPktStackInit->xControlLength));
vpcola 0:f1d3878b8dd9 132
vpcola 0:f1d3878b8dd9 133
vpcola 0:f1d3878b8dd9 134 /* Reads the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 135 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue[0]);
vpcola 0:f1d3878b8dd9 136
vpcola 0:f1d3878b8dd9 137 /* Mask a reserved bit */
vpcola 0:f1d3878b8dd9 138 tempRegValue[0] &= ~0x20;
vpcola 0:f1d3878b8dd9 139
vpcola 0:f1d3878b8dd9 140 /* Always (!) set the automatic packet filtering */
vpcola 0:f1d3878b8dd9 141 tempRegValue[0] |= PROTOCOL1_AUTO_PCKT_FLT_MASK;
vpcola 0:f1d3878b8dd9 142
vpcola 0:f1d3878b8dd9 143 /* Writes the value on register */
vpcola 0:f1d3878b8dd9 144 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue[0]);
vpcola 0:f1d3878b8dd9 145
vpcola 0:f1d3878b8dd9 146 /* Reads the PCKT_FLT_OPTIONS register */
vpcola 0:f1d3878b8dd9 147 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
vpcola 0:f1d3878b8dd9 148
vpcola 0:f1d3878b8dd9 149 /* Always reset the control and source filtering */
vpcola 0:f1d3878b8dd9 150 tempRegValue[0] &= ~(PCKT_FLT_OPTIONS_SOURCE_FILTERING_MASK | PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK);
vpcola 0:f1d3878b8dd9 151
vpcola 0:f1d3878b8dd9 152 /* Writes the value on register */
vpcola 0:f1d3878b8dd9 153 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
vpcola 0:f1d3878b8dd9 154
vpcola 0:f1d3878b8dd9 155
vpcola 0:f1d3878b8dd9 156 /* Address and control length setting: source and destination address are always present so ADDRESS_LENGTH=2 */
vpcola 0:f1d3878b8dd9 157 tempRegValue[0] = 0x10 | ((uint8_t) pxPktStackInit->xControlLength);
vpcola 0:f1d3878b8dd9 158
vpcola 0:f1d3878b8dd9 159
vpcola 0:f1d3878b8dd9 160 /* Packet format and width length setting */
vpcola 0:f1d3878b8dd9 161 pxPktStackInit->cPktLengthWidth == 0 ? pxPktStackInit->cPktLengthWidth=1 : pxPktStackInit->cPktLengthWidth;
vpcola 0:f1d3878b8dd9 162 tempRegValue[1] = ((uint8_t) PCKTCTRL3_PCKT_FRMT_STACK) | ((uint8_t)(pxPktStackInit->cPktLengthWidth-1));
vpcola 0:f1d3878b8dd9 163
vpcola 0:f1d3878b8dd9 164 /* Preamble, sync and fixed or variable length setting */
vpcola 0:f1d3878b8dd9 165 tempRegValue[2] = ((uint8_t) pxPktStackInit->xPreambleLength) | ((uint8_t) pxPktStackInit->xSyncLength) |
vpcola 0:f1d3878b8dd9 166 ((uint8_t) pxPktStackInit->xFixVarLength);
vpcola 0:f1d3878b8dd9 167
vpcola 0:f1d3878b8dd9 168 /* CRC length, whitening and FEC setting */
vpcola 0:f1d3878b8dd9 169 tempRegValue[3] = (uint8_t) pxPktStackInit->xCrcMode;
vpcola 0:f1d3878b8dd9 170
vpcola 0:f1d3878b8dd9 171 if(pxPktStackInit->xDataWhitening == S_ENABLE)
vpcola 0:f1d3878b8dd9 172 {
vpcola 0:f1d3878b8dd9 173 tempRegValue[3] |= PCKTCTRL1_WHIT_MASK;
vpcola 0:f1d3878b8dd9 174 }
vpcola 0:f1d3878b8dd9 175
vpcola 0:f1d3878b8dd9 176 if(pxPktStackInit->xFec == S_ENABLE)
vpcola 0:f1d3878b8dd9 177 {
vpcola 0:f1d3878b8dd9 178 tempRegValue[3] |= PCKTCTRL1_FEC_MASK;
vpcola 0:f1d3878b8dd9 179 }
vpcola 0:f1d3878b8dd9 180
vpcola 0:f1d3878b8dd9 181 /* Writes registers */
vpcola 0:f1d3878b8dd9 182 SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 183
vpcola 0:f1d3878b8dd9 184 /* Sync words setting */
vpcola 0:f1d3878b8dd9 185 for(i=0;i<4;i++)
vpcola 0:f1d3878b8dd9 186 {
vpcola 0:f1d3878b8dd9 187 if(i<3-(pxPktStackInit->xSyncLength >>1))
vpcola 0:f1d3878b8dd9 188 {
vpcola 0:f1d3878b8dd9 189 tempRegValue[i]=0;
vpcola 0:f1d3878b8dd9 190 }
vpcola 0:f1d3878b8dd9 191 else
vpcola 0:f1d3878b8dd9 192 {
vpcola 0:f1d3878b8dd9 193 tempRegValue[i] = (uint8_t)(pxPktStackInit->lSyncWords>>(8*i));
vpcola 0:f1d3878b8dd9 194 }
vpcola 0:f1d3878b8dd9 195 }
vpcola 0:f1d3878b8dd9 196
vpcola 0:f1d3878b8dd9 197 /* Enables or disables the CRC check */
vpcola 0:f1d3878b8dd9 198 if(pxPktStackInit->xCrcMode == PKT_NO_CRC)
vpcola 0:f1d3878b8dd9 199 {
vpcola 0:f1d3878b8dd9 200 SpiritPktStackFilterOnCrc(S_DISABLE);
vpcola 0:f1d3878b8dd9 201 }
vpcola 0:f1d3878b8dd9 202 else
vpcola 0:f1d3878b8dd9 203 {
vpcola 0:f1d3878b8dd9 204 SpiritPktStackFilterOnCrc(S_ENABLE);
vpcola 0:f1d3878b8dd9 205 }
vpcola 0:f1d3878b8dd9 206
vpcola 0:f1d3878b8dd9 207 /* Writes registers */
vpcola 0:f1d3878b8dd9 208 g_xStatus = SpiritSpiWriteRegisters(SYNC4_BASE, 4, tempRegValue);
vpcola 0:f1d3878b8dd9 209
vpcola 0:f1d3878b8dd9 210 }
vpcola 0:f1d3878b8dd9 211
vpcola 0:f1d3878b8dd9 212
vpcola 0:f1d3878b8dd9 213 /**
vpcola 0:f1d3878b8dd9 214 * @brief Returns the SPIRIT STack packet structure according to the specified parameters in the registers.
vpcola 0:f1d3878b8dd9 215 * @param pxPktStackInit STack packet init structure.
vpcola 0:f1d3878b8dd9 216 * This parameter is a pointer to @ref PktStackInit.
vpcola 0:f1d3878b8dd9 217 * @retval None.
vpcola 0:f1d3878b8dd9 218 */
vpcola 0:f1d3878b8dd9 219 void SpiritPktStackGetInfo(PktStackInit* pxPktStackInit)
vpcola 0:f1d3878b8dd9 220 {
vpcola 0:f1d3878b8dd9 221 uint8_t tempRegValue[10];
vpcola 0:f1d3878b8dd9 222
vpcola 0:f1d3878b8dd9 223 /* Reads registers */
vpcola 0:f1d3878b8dd9 224 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 10, tempRegValue);
vpcola 0:f1d3878b8dd9 225
vpcola 0:f1d3878b8dd9 226 /* Length width */
vpcola 0:f1d3878b8dd9 227 pxPktStackInit->cPktLengthWidth=(tempRegValue[1] & 0x0F)+1;
vpcola 0:f1d3878b8dd9 228
vpcola 0:f1d3878b8dd9 229 /* Control length */
vpcola 0:f1d3878b8dd9 230 pxPktStackInit->xControlLength=(StackControlLength)(tempRegValue[0] & 0x07);
vpcola 0:f1d3878b8dd9 231
vpcola 0:f1d3878b8dd9 232 /* CRC mode */
vpcola 0:f1d3878b8dd9 233 pxPktStackInit->xCrcMode=(StackCrcMode)(tempRegValue[3] & 0xE0);
vpcola 0:f1d3878b8dd9 234
vpcola 0:f1d3878b8dd9 235 /* Whitening */
vpcola 0:f1d3878b8dd9 236 pxPktStackInit->xDataWhitening=(SpiritFunctionalState)((tempRegValue[3] >> 4) & 0x01);
vpcola 0:f1d3878b8dd9 237
vpcola 0:f1d3878b8dd9 238 /* FEC */
vpcola 0:f1d3878b8dd9 239 pxPktStackInit->xFec=(SpiritFunctionalState)(tempRegValue[3] & 0x01);
vpcola 0:f1d3878b8dd9 240
vpcola 0:f1d3878b8dd9 241 /* FIX or VAR bit */
vpcola 0:f1d3878b8dd9 242 pxPktStackInit->xFixVarLength=(StackFixVarLength)(tempRegValue[2] & 0x01);
vpcola 0:f1d3878b8dd9 243
vpcola 0:f1d3878b8dd9 244 /* Preamble length */
vpcola 0:f1d3878b8dd9 245 pxPktStackInit->xPreambleLength=(StackPreambleLength)(tempRegValue[2] & 0xF8);
vpcola 0:f1d3878b8dd9 246
vpcola 0:f1d3878b8dd9 247 /* Sync length */
vpcola 0:f1d3878b8dd9 248 pxPktStackInit->xSyncLength=(StackSyncLength)(tempRegValue[2] & 0x06);
vpcola 0:f1d3878b8dd9 249
vpcola 0:f1d3878b8dd9 250 /* sync Words */
vpcola 0:f1d3878b8dd9 251 pxPktStackInit->lSyncWords=0;
vpcola 0:f1d3878b8dd9 252 for(uint8_t i=0 ; i<4 ; i++)
vpcola 0:f1d3878b8dd9 253 {
vpcola 0:f1d3878b8dd9 254 if(i>2-(pxPktStackInit->xSyncLength >>1))
vpcola 0:f1d3878b8dd9 255 {
vpcola 0:f1d3878b8dd9 256 pxPktStackInit->lSyncWords |= tempRegValue[i+6]<<(8*i);
vpcola 0:f1d3878b8dd9 257 }
vpcola 0:f1d3878b8dd9 258 }
vpcola 0:f1d3878b8dd9 259
vpcola 0:f1d3878b8dd9 260 }
vpcola 0:f1d3878b8dd9 261
vpcola 0:f1d3878b8dd9 262
vpcola 0:f1d3878b8dd9 263 /**
vpcola 0:f1d3878b8dd9 264 * @brief Initializes the SPIRIT STack packet addresses according to the specified
vpcola 0:f1d3878b8dd9 265 * parameters in the PktStackAddresses struct.
vpcola 0:f1d3878b8dd9 266 * @param pxPktStackAddresses STack packet addresses init structure.
vpcola 0:f1d3878b8dd9 267 * This parameter is a pointer to @ref PktStackAddressesInit .
vpcola 0:f1d3878b8dd9 268 * @retval None.
vpcola 0:f1d3878b8dd9 269 */
vpcola 0:f1d3878b8dd9 270 void SpiritPktStackAddressesInit(PktStackAddressesInit* pxPktStackAddresses)
vpcola 0:f1d3878b8dd9 271 {
vpcola 0:f1d3878b8dd9 272 uint8_t tempRegValue[3];
vpcola 0:f1d3878b8dd9 273
vpcola 0:f1d3878b8dd9 274 /* Check the parameters */
vpcola 0:f1d3878b8dd9 275 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackAddresses->xFilterOnMyAddress));
vpcola 0:f1d3878b8dd9 276 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackAddresses->xFilterOnMulticastAddress));
vpcola 0:f1d3878b8dd9 277 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackAddresses->xFilterOnBroadcastAddress));
vpcola 0:f1d3878b8dd9 278
vpcola 0:f1d3878b8dd9 279 /* Reads the filtering options ragister */
vpcola 0:f1d3878b8dd9 280 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
vpcola 0:f1d3878b8dd9 281
vpcola 0:f1d3878b8dd9 282 /* Enables or disables filtering on my address */
vpcola 0:f1d3878b8dd9 283 if(pxPktStackAddresses->xFilterOnMyAddress == S_ENABLE)
vpcola 0:f1d3878b8dd9 284 {
vpcola 0:f1d3878b8dd9 285 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
vpcola 0:f1d3878b8dd9 286 }
vpcola 0:f1d3878b8dd9 287 else
vpcola 0:f1d3878b8dd9 288 {
vpcola 0:f1d3878b8dd9 289 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
vpcola 0:f1d3878b8dd9 290 }
vpcola 0:f1d3878b8dd9 291
vpcola 0:f1d3878b8dd9 292 /* Enables or disables filtering on multicast address */
vpcola 0:f1d3878b8dd9 293 if(pxPktStackAddresses->xFilterOnMulticastAddress == S_ENABLE)
vpcola 0:f1d3878b8dd9 294 {
vpcola 0:f1d3878b8dd9 295 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 296 }
vpcola 0:f1d3878b8dd9 297 else
vpcola 0:f1d3878b8dd9 298 {
vpcola 0:f1d3878b8dd9 299 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 300 }
vpcola 0:f1d3878b8dd9 301
vpcola 0:f1d3878b8dd9 302 /* Enables or disables filtering on broadcast address */
vpcola 0:f1d3878b8dd9 303 if(pxPktStackAddresses->xFilterOnBroadcastAddress == S_ENABLE)
vpcola 0:f1d3878b8dd9 304 {
vpcola 0:f1d3878b8dd9 305 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 306 }
vpcola 0:f1d3878b8dd9 307 else
vpcola 0:f1d3878b8dd9 308 {
vpcola 0:f1d3878b8dd9 309 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
vpcola 0:f1d3878b8dd9 310 }
vpcola 0:f1d3878b8dd9 311
vpcola 0:f1d3878b8dd9 312 /* Writes value on the register */
vpcola 0:f1d3878b8dd9 313 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
vpcola 0:f1d3878b8dd9 314
vpcola 0:f1d3878b8dd9 315 /* Fills array with the addresses passed in the structure */
vpcola 0:f1d3878b8dd9 316 tempRegValue[0] = pxPktStackAddresses->cBroadcastAddress;
vpcola 0:f1d3878b8dd9 317 tempRegValue[1] = pxPktStackAddresses->cMulticastAddress;
vpcola 0:f1d3878b8dd9 318 tempRegValue[2] = pxPktStackAddresses->cMyAddress;
vpcola 0:f1d3878b8dd9 319
vpcola 0:f1d3878b8dd9 320 /* Writes them on the addresses registers */
vpcola 0:f1d3878b8dd9 321 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue);
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 Returns the SPIRIT STack packet addresses structure according to the specified
vpcola 0:f1d3878b8dd9 328 * parameters in the registers.
vpcola 0:f1d3878b8dd9 329 * @param pxPktStackAddresses STack packet addresses init structure.
vpcola 0:f1d3878b8dd9 330 * This parameter is a pointer to @ref PktStackAddresses.
vpcola 0:f1d3878b8dd9 331 * @retval None.
vpcola 0:f1d3878b8dd9 332 */
vpcola 0:f1d3878b8dd9 333 void SpiritPktStackGetAddressesInfo(PktStackAddressesInit* pxPktStackAddresses)
vpcola 0:f1d3878b8dd9 334 {
vpcola 0:f1d3878b8dd9 335 uint8_t tempRegValue[3];
vpcola 0:f1d3878b8dd9 336
vpcola 0:f1d3878b8dd9 337 /* Reads values on the PCKT_FLT_GOALS registers */
vpcola 0:f1d3878b8dd9 338 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue);
vpcola 0:f1d3878b8dd9 339
vpcola 0:f1d3878b8dd9 340 /* Fit the structure with the read addresses */
vpcola 0:f1d3878b8dd9 341 pxPktStackAddresses->cBroadcastAddress = tempRegValue[0];
vpcola 0:f1d3878b8dd9 342 pxPktStackAddresses->cMulticastAddress = tempRegValue[1];
vpcola 0:f1d3878b8dd9 343 pxPktStackAddresses->cMyAddress = tempRegValue[2];
vpcola 0:f1d3878b8dd9 344
vpcola 0:f1d3878b8dd9 345 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
vpcola 0:f1d3878b8dd9 346
vpcola 0:f1d3878b8dd9 347 /* Fit the structure with the read filtering bits */
vpcola 0:f1d3878b8dd9 348 pxPktStackAddresses->xFilterOnBroadcastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 1) & 0x01);
vpcola 0:f1d3878b8dd9 349 pxPktStackAddresses->xFilterOnMulticastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 2) & 0x01);
vpcola 0:f1d3878b8dd9 350 pxPktStackAddresses->xFilterOnMyAddress = (SpiritFunctionalState)((tempRegValue[0] >> 3) & 0x01);
vpcola 0:f1d3878b8dd9 351
vpcola 0:f1d3878b8dd9 352 }
vpcola 0:f1d3878b8dd9 353
vpcola 0:f1d3878b8dd9 354
vpcola 0:f1d3878b8dd9 355 /**
vpcola 0:f1d3878b8dd9 356 * @brief Initializes the SPIRIT STack packet LLP options according to the specified
vpcola 0:f1d3878b8dd9 357 * parameters in the PktStackLlpInit struct.
vpcola 0:f1d3878b8dd9 358 * @param pxPktStackLlpInit STack packet LLP init structure.
vpcola 0:f1d3878b8dd9 359 * This parameter is a pointer to @ref PktStackLlpInit.
vpcola 0:f1d3878b8dd9 360 * @retval None.
vpcola 0:f1d3878b8dd9 361 */
vpcola 0:f1d3878b8dd9 362 void SpiritPktStackLlpInit(PktStackLlpInit* pxPktStackLlpInit)
vpcola 0:f1d3878b8dd9 363 {
vpcola 0:f1d3878b8dd9 364 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 365
vpcola 0:f1d3878b8dd9 366 /* Check the parameters */
vpcola 0:f1d3878b8dd9 367 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackLlpInit->xPiggybacking));
vpcola 0:f1d3878b8dd9 368 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktStackLlpInit->xAutoAck));
vpcola 0:f1d3878b8dd9 369 s_assert_param(IS_STACK_NMAX_RETX(pxPktStackLlpInit->xNMaxRetx));
vpcola 0:f1d3878b8dd9 370 /* check if piggybacking is enabled and autoack is disabled */
vpcola 0:f1d3878b8dd9 371 s_assert_param(!(pxPktStackLlpInit->xPiggybacking==S_ENABLE && pxPktStackLlpInit->xAutoAck==S_DISABLE));
vpcola 0:f1d3878b8dd9 372
vpcola 0:f1d3878b8dd9 373 /* Piggybacking mechanism setting on the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 374 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 375 if(pxPktStackLlpInit->xPiggybacking == S_ENABLE)
vpcola 0:f1d3878b8dd9 376 {
vpcola 0:f1d3878b8dd9 377 tempRegValue[0] |= PROTOCOL1_PIGGYBACKING_MASK;
vpcola 0:f1d3878b8dd9 378 }
vpcola 0:f1d3878b8dd9 379 else
vpcola 0:f1d3878b8dd9 380 {
vpcola 0:f1d3878b8dd9 381 tempRegValue[0] &= ~PROTOCOL1_PIGGYBACKING_MASK;
vpcola 0:f1d3878b8dd9 382 }
vpcola 0:f1d3878b8dd9 383
vpcola 0:f1d3878b8dd9 384 /* RX and TX autoack mechanisms setting on the PROTOCOL0 register */
vpcola 0:f1d3878b8dd9 385 if(pxPktStackLlpInit->xAutoAck == S_ENABLE)
vpcola 0:f1d3878b8dd9 386 {
vpcola 0:f1d3878b8dd9 387 tempRegValue[1] |= PROTOCOL0_AUTO_ACK_MASK;
vpcola 0:f1d3878b8dd9 388 }
vpcola 0:f1d3878b8dd9 389 else
vpcola 0:f1d3878b8dd9 390 {
vpcola 0:f1d3878b8dd9 391 tempRegValue[1] &= ~PROTOCOL0_AUTO_ACK_MASK;
vpcola 0:f1d3878b8dd9 392 }
vpcola 0:f1d3878b8dd9 393
vpcola 0:f1d3878b8dd9 394 /* Max number of retransmission setting */
vpcola 0:f1d3878b8dd9 395 tempRegValue[1] &= ~PROTOCOL0_NMAX_RETX_MASK;
vpcola 0:f1d3878b8dd9 396 tempRegValue[1] |= pxPktStackLlpInit->xNMaxRetx;
vpcola 0:f1d3878b8dd9 397
vpcola 0:f1d3878b8dd9 398 /* Writes registers */
vpcola 0:f1d3878b8dd9 399 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 400
vpcola 0:f1d3878b8dd9 401 }
vpcola 0:f1d3878b8dd9 402
vpcola 0:f1d3878b8dd9 403
vpcola 0:f1d3878b8dd9 404 /**
vpcola 0:f1d3878b8dd9 405 * @brief Returns the SPIRIT STack packet LLP options according to the specified
vpcola 0:f1d3878b8dd9 406 * values in the registers.
vpcola 0:f1d3878b8dd9 407 * @param pxPktStackLlpInit STack packet LLP structure.
vpcola 0:f1d3878b8dd9 408 * This parameter is a pointer to @ref PktStackLlpInit.
vpcola 0:f1d3878b8dd9 409 * @retval None.
vpcola 0:f1d3878b8dd9 410 */
vpcola 0:f1d3878b8dd9 411 void SpiritPktStackLlpGetInfo(PktStackLlpInit* pxPktStackLlpInit)
vpcola 0:f1d3878b8dd9 412 {
vpcola 0:f1d3878b8dd9 413 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 414
vpcola 0:f1d3878b8dd9 415 /* Piggybacking mechanism setting on the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 416 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 417
vpcola 0:f1d3878b8dd9 418 /* Fit the structure with the read values */
vpcola 0:f1d3878b8dd9 419 pxPktStackLlpInit->xPiggybacking = (SpiritFunctionalState)((tempRegValue[0] >> 6) & 0x01);
vpcola 0:f1d3878b8dd9 420 pxPktStackLlpInit->xAutoAck = (SpiritFunctionalState)((tempRegValue[1] >> 2) & 0x01);
vpcola 0:f1d3878b8dd9 421 pxPktStackLlpInit->xNMaxRetx = (StackNMaxReTx)(tempRegValue[1] & PROTOCOL0_NMAX_RETX_MASK);
vpcola 0:f1d3878b8dd9 422
vpcola 0:f1d3878b8dd9 423 }
vpcola 0:f1d3878b8dd9 424
vpcola 0:f1d3878b8dd9 425
vpcola 0:f1d3878b8dd9 426 /**
vpcola 0:f1d3878b8dd9 427 * @brief Configures the STack packet format for SPIRIT.
vpcola 0:f1d3878b8dd9 428 * @param None.
vpcola 0:f1d3878b8dd9 429 * @retval None.
vpcola 0:f1d3878b8dd9 430 */
vpcola 0:f1d3878b8dd9 431 void SpiritPktStackSetFormat(void)
vpcola 0:f1d3878b8dd9 432 {
vpcola 0:f1d3878b8dd9 433 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 434
vpcola 0:f1d3878b8dd9 435 /* Reads the PCKTCTRL3 register value */
vpcola 0:f1d3878b8dd9 436 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 437
vpcola 0:f1d3878b8dd9 438 /* Build value to be written. Also set to 0 the direct RX mode bits */
vpcola 0:f1d3878b8dd9 439 tempRegValue &= 0x0F;
vpcola 0:f1d3878b8dd9 440 tempRegValue |= ((uint8_t)PCKTCTRL3_PCKT_FRMT_STACK);
vpcola 0:f1d3878b8dd9 441
vpcola 0:f1d3878b8dd9 442 /* Writes the value on the PCKTCTRL3 register. */
vpcola 0:f1d3878b8dd9 443 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 444
vpcola 0:f1d3878b8dd9 445 /* Reads the PCKTCTRL1 register value */
vpcola 0:f1d3878b8dd9 446 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 447
vpcola 0:f1d3878b8dd9 448 /* Build the new value. Set to 0 the direct TX mode bits */
vpcola 0:f1d3878b8dd9 449 tempRegValue &= 0xF3;
vpcola 0:f1d3878b8dd9 450
vpcola 0:f1d3878b8dd9 451 /* Writes the PCKTCTRL1 value on register */
vpcola 0:f1d3878b8dd9 452 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 453
vpcola 0:f1d3878b8dd9 454 /* Reads the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 455 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 456
vpcola 0:f1d3878b8dd9 457 /* Mask a reserved bit */
vpcola 0:f1d3878b8dd9 458 tempRegValue &= ~0x20;
vpcola 0:f1d3878b8dd9 459
vpcola 0:f1d3878b8dd9 460 /* Writes the value on the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 461 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 462
vpcola 0:f1d3878b8dd9 463 }
vpcola 0:f1d3878b8dd9 464
vpcola 0:f1d3878b8dd9 465
vpcola 0:f1d3878b8dd9 466 /**
vpcola 0:f1d3878b8dd9 467 * @brief Sets the address length for SPIRIT STack packets (always 2).
vpcola 0:f1d3878b8dd9 468 * @param None.
vpcola 0:f1d3878b8dd9 469 * @retval None.
vpcola 0:f1d3878b8dd9 470 */
vpcola 0:f1d3878b8dd9 471 void SpiritPktStackSetAddressLength(void)
vpcola 0:f1d3878b8dd9 472 {
vpcola 0:f1d3878b8dd9 473 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 474
vpcola 0:f1d3878b8dd9 475 /* Reads the PCKTCTRL4 register value */
vpcola 0:f1d3878b8dd9 476 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 477
vpcola 0:f1d3878b8dd9 478 /* Build the new value */
vpcola 0:f1d3878b8dd9 479 tempRegValue &= ~PCKTCTRL4_ADDRESS_LEN_MASK;
vpcola 0:f1d3878b8dd9 480 tempRegValue |= ((uint8_t)0x10);
vpcola 0:f1d3878b8dd9 481
vpcola 0:f1d3878b8dd9 482 /* Writes the value on the PCKTCTRL4 register */
vpcola 0:f1d3878b8dd9 483 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 484
vpcola 0:f1d3878b8dd9 485 }
vpcola 0:f1d3878b8dd9 486
vpcola 0:f1d3878b8dd9 487
vpcola 0:f1d3878b8dd9 488 /**
vpcola 0:f1d3878b8dd9 489 * @brief Sets the payload length for SPIRIT STack packets. Since the packet length
vpcola 0:f1d3878b8dd9 490 * depends from the address (always 2 for this packet format)
vpcola 0:f1d3878b8dd9 491 * and the control field size, this function reads the control length register
vpcola 0:f1d3878b8dd9 492 * content in order to determine the correct packet length to be written.
vpcola 0:f1d3878b8dd9 493 * @param nPayloadLength payload length in bytes.
vpcola 0:f1d3878b8dd9 494 * This parameter can be any value of uint16_t.
vpcola 0:f1d3878b8dd9 495 * @retval None.
vpcola 0:f1d3878b8dd9 496 */
vpcola 0:f1d3878b8dd9 497 void SpiritPktStackSetPayloadLength(uint16_t nPayloadLength)
vpcola 0:f1d3878b8dd9 498 {
vpcola 0:f1d3878b8dd9 499 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 500
vpcola 0:f1d3878b8dd9 501 /* Computes the oversize (address + control) size */
vpcola 0:f1d3878b8dd9 502 uint16_t overSize = 2 + (uint16_t) SpiritPktStackGetControlLength();
vpcola 0:f1d3878b8dd9 503
vpcola 0:f1d3878b8dd9 504 /* Computes PCKTLEN0 value from lPayloadLength */
vpcola 0:f1d3878b8dd9 505 tempRegValue[1]=STACK_BUILD_PCKTLEN0(nPayloadLength+overSize);
vpcola 0:f1d3878b8dd9 506 /* Computes PCKTLEN1 value from lPayloadLength */
vpcola 0:f1d3878b8dd9 507 tempRegValue[0]=STACK_BUILD_PCKTLEN1(nPayloadLength+overSize);
vpcola 0:f1d3878b8dd9 508
vpcola 0:f1d3878b8dd9 509 /* Writes the value on the PCKTLENx registers */
vpcola 0:f1d3878b8dd9 510 g_xStatus = SpiritSpiWriteRegisters(PCKTLEN1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 511
vpcola 0:f1d3878b8dd9 512 }
vpcola 0:f1d3878b8dd9 513
vpcola 0:f1d3878b8dd9 514
vpcola 0:f1d3878b8dd9 515 /**
vpcola 0:f1d3878b8dd9 516 * @brief Returns the payload length for SPIRIT STack packets. Since the
vpcola 0:f1d3878b8dd9 517 * packet length depends from the address and the control
vpcola 0:f1d3878b8dd9 518 * field size, this function reads the correspondent
vpcola 0:f1d3878b8dd9 519 * registers in order to determine the correct payload length
vpcola 0:f1d3878b8dd9 520 * to be returned.
vpcola 0:f1d3878b8dd9 521 * @param None.
vpcola 0:f1d3878b8dd9 522 * @retval uint16_t Payload length.
vpcola 0:f1d3878b8dd9 523 */
vpcola 0:f1d3878b8dd9 524 uint16_t SpiritPktStackGetPayloadLength(void)
vpcola 0:f1d3878b8dd9 525 {
vpcola 0:f1d3878b8dd9 526 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 527 /* Computes the oversize (address + control) size */
vpcola 0:f1d3878b8dd9 528 uint16_t overSize = 2 + (uint16_t) SpiritPktStackGetControlLength();
vpcola 0:f1d3878b8dd9 529
vpcola 0:f1d3878b8dd9 530 /* Reads the PCKTLEN1 registers value */
vpcola 0:f1d3878b8dd9 531 g_xStatus = SpiritSpiReadRegisters(PCKTLEN1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 532
vpcola 0:f1d3878b8dd9 533 /* Rebuild and return the payload length value */
vpcola 0:f1d3878b8dd9 534 return ((((uint16_t) tempRegValue[1])<<8) + (uint16_t) tempRegValue[0] - overSize);
vpcola 0:f1d3878b8dd9 535
vpcola 0:f1d3878b8dd9 536 }
vpcola 0:f1d3878b8dd9 537
vpcola 0:f1d3878b8dd9 538
vpcola 0:f1d3878b8dd9 539 /**
vpcola 0:f1d3878b8dd9 540 * @brief Computes and sets the variable payload length for SPIRIT STack packets.
vpcola 0:f1d3878b8dd9 541 * @param nMaxPayloadLength payload length in bytes.
vpcola 0:f1d3878b8dd9 542 * This parameter is an uint16_t.
vpcola 0:f1d3878b8dd9 543 * @param xControlLength control length in bytes.
vpcola 0:f1d3878b8dd9 544 * This parameter can be any value of @ref StackControlLength.
vpcola 0:f1d3878b8dd9 545 * @retval None.
vpcola 0:f1d3878b8dd9 546 */
vpcola 0:f1d3878b8dd9 547 void SpiritPktStackSetVarLengthWidth(uint16_t nMaxPayloadLength, StackControlLength xControlLength)
vpcola 0:f1d3878b8dd9 548 {
vpcola 0:f1d3878b8dd9 549 uint8_t tempRegValue,
vpcola 0:f1d3878b8dd9 550 i;
vpcola 0:f1d3878b8dd9 551 uint32_t packetLength;
vpcola 0:f1d3878b8dd9 552
vpcola 0:f1d3878b8dd9 553
vpcola 0:f1d3878b8dd9 554 /* packet length = payload length + address length (2) + control length */
vpcola 0:f1d3878b8dd9 555 packetLength=nMaxPayloadLength+2+xControlLength;
vpcola 0:f1d3878b8dd9 556
vpcola 0:f1d3878b8dd9 557 /* Computes the number of bits */
vpcola 0:f1d3878b8dd9 558 for(i=0;i<16;i++)
vpcola 0:f1d3878b8dd9 559 {
vpcola 0:f1d3878b8dd9 560 if(packetLength == 0)
vpcola 0:f1d3878b8dd9 561 {
vpcola 0:f1d3878b8dd9 562 break;
vpcola 0:f1d3878b8dd9 563 }
vpcola 0:f1d3878b8dd9 564 packetLength >>= 1;
vpcola 0:f1d3878b8dd9 565 }
vpcola 0:f1d3878b8dd9 566 i==0 ? i=1 : i;
vpcola 0:f1d3878b8dd9 567
vpcola 0:f1d3878b8dd9 568 /* Reads the PCKTCTRL3 register value */
vpcola 0:f1d3878b8dd9 569 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 570
vpcola 0:f1d3878b8dd9 571 /* Build the register value */
vpcola 0:f1d3878b8dd9 572 tempRegValue &= ~PCKTCTRL3_LEN_WID_MASK;
vpcola 0:f1d3878b8dd9 573 tempRegValue |= ((uint8_t)(i-1));
vpcola 0:f1d3878b8dd9 574
vpcola 0:f1d3878b8dd9 575 /* Writes the PCKTCTRL3 register value */
vpcola 0:f1d3878b8dd9 576 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 577
vpcola 0:f1d3878b8dd9 578 }
vpcola 0:f1d3878b8dd9 579
vpcola 0:f1d3878b8dd9 580
vpcola 0:f1d3878b8dd9 581 /**
vpcola 0:f1d3878b8dd9 582 * @brief Rx packet source mask. Used to mask the address of the accepted packets. If 0 -> no filtering.
vpcola 0:f1d3878b8dd9 583 * @param cMask Rx source mask.
vpcola 0:f1d3878b8dd9 584 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 585 * @retval None.
vpcola 0:f1d3878b8dd9 586 */
vpcola 0:f1d3878b8dd9 587 void SpiritPktStackSetRxSourceMask(uint8_t cMask)
vpcola 0:f1d3878b8dd9 588 {
vpcola 0:f1d3878b8dd9 589 /* Writes value on the register PCKT_FLT_GOALS_SOURCE_MASK */
vpcola 0:f1d3878b8dd9 590 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_SOURCE_MASK_BASE, 1, &cMask);
vpcola 0:f1d3878b8dd9 591
vpcola 0:f1d3878b8dd9 592 }
vpcola 0:f1d3878b8dd9 593
vpcola 0:f1d3878b8dd9 594
vpcola 0:f1d3878b8dd9 595 /**
vpcola 0:f1d3878b8dd9 596 * @brief Returns the Rx packet source mask. Used to mask the address of the accepted packets. If 0 -> no filtering.
vpcola 0:f1d3878b8dd9 597 * @param None.
vpcola 0:f1d3878b8dd9 598 * @retval uint8_t Rx source mask.
vpcola 0:f1d3878b8dd9 599 */
vpcola 0:f1d3878b8dd9 600 uint8_t SpiritPktStackGetRxSourceMask(void)
vpcola 0:f1d3878b8dd9 601 {
vpcola 0:f1d3878b8dd9 602 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 603
vpcola 0:f1d3878b8dd9 604 /* Writes value on the PCKT_FLT_GOALS_SOURCE_MASK register */
vpcola 0:f1d3878b8dd9 605 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_SOURCE_MASK_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 606
vpcola 0:f1d3878b8dd9 607 /* Return the read value */
vpcola 0:f1d3878b8dd9 608 return tempRegValue;
vpcola 0:f1d3878b8dd9 609
vpcola 0:f1d3878b8dd9 610 }
vpcola 0:f1d3878b8dd9 611
vpcola 0:f1d3878b8dd9 612 /**
vpcola 0:f1d3878b8dd9 613 * @brief Returns the packet length field of the received packet.
vpcola 0:f1d3878b8dd9 614 * @param None.
vpcola 0:f1d3878b8dd9 615 * @retval uint16_t Packet length.
vpcola 0:f1d3878b8dd9 616 */
vpcola 0:f1d3878b8dd9 617 uint16_t SpiritPktStackGetReceivedPktLength(void)
vpcola 0:f1d3878b8dd9 618 {
vpcola 0:f1d3878b8dd9 619 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 620 uint16_t tempLength;
vpcola 0:f1d3878b8dd9 621
vpcola 0:f1d3878b8dd9 622 /* Reads the RX_PCKT_LENx registers value */
vpcola 0:f1d3878b8dd9 623 g_xStatus = SpiritSpiReadRegisters(RX_PCKT_LEN1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 624
vpcola 0:f1d3878b8dd9 625 /* Rebuild and return the the length field */
vpcola 0:f1d3878b8dd9 626 tempLength = ((((uint16_t) tempRegValue[0]) << 8) + (uint16_t) tempRegValue[1]);
vpcola 0:f1d3878b8dd9 627
vpcola 0:f1d3878b8dd9 628 /* Computes the oversize (address + control) size */
vpcola 0:f1d3878b8dd9 629 tempLength -= 2 + (uint16_t) SpiritPktStackGetControlLength();
vpcola 0:f1d3878b8dd9 630
vpcola 0:f1d3878b8dd9 631 return tempLength;
vpcola 0:f1d3878b8dd9 632
vpcola 0:f1d3878b8dd9 633 }
vpcola 0:f1d3878b8dd9 634
vpcola 0:f1d3878b8dd9 635
vpcola 0:f1d3878b8dd9 636 /**
vpcola 0:f1d3878b8dd9 637 * @brief If enabled RX packet is accepted only if the masked source address field matches the
vpcola 0:f1d3878b8dd9 638 * masked source address field reference (SOURCE_MASK & SOURCE_FIELD_REF == SOURCE_MASK & RX_SOURCE_FIELD).
vpcola 0:f1d3878b8dd9 639 * @param xNewState new state for Source address filtering enable bit.
vpcola 0:f1d3878b8dd9 640 * This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 641 * @retval None.
vpcola 0:f1d3878b8dd9 642 * @note This filtering control is enabled by default but the source address mask is by default set to 0.
vpcola 0:f1d3878b8dd9 643 * As a matter of fact the user has to enable the source filtering bit after the packet initialization
vpcola 0:f1d3878b8dd9 644 * because the PktInit routine disables it.
vpcola 0:f1d3878b8dd9 645 */
vpcola 0:f1d3878b8dd9 646 void SpiritPktStackFilterOnSourceAddress(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 647 {
vpcola 0:f1d3878b8dd9 648 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 649
vpcola 0:f1d3878b8dd9 650 /* Check the parameters */
vpcola 0:f1d3878b8dd9 651 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 652
vpcola 0:f1d3878b8dd9 653
vpcola 0:f1d3878b8dd9 654 /* Modify the register value: set or reset the source bit filtering */
vpcola 0:f1d3878b8dd9 655 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 656
vpcola 0:f1d3878b8dd9 657 /* Set or reset the SOURCE ADDRESS filtering enabling bit */
vpcola 0:f1d3878b8dd9 658 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 659 {
vpcola 0:f1d3878b8dd9 660 tempRegValue |= PCKT_FLT_OPTIONS_SOURCE_FILTERING_MASK;
vpcola 0:f1d3878b8dd9 661 }
vpcola 0:f1d3878b8dd9 662 else
vpcola 0:f1d3878b8dd9 663 {
vpcola 0:f1d3878b8dd9 664 tempRegValue &= ~PCKT_FLT_OPTIONS_SOURCE_FILTERING_MASK;
vpcola 0:f1d3878b8dd9 665 }
vpcola 0:f1d3878b8dd9 666
vpcola 0:f1d3878b8dd9 667 /* Writes the new value on the PCKT_FLT_OPTIONS register */
vpcola 0:f1d3878b8dd9 668 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 669
vpcola 0:f1d3878b8dd9 670 }
vpcola 0:f1d3878b8dd9 671
vpcola 0:f1d3878b8dd9 672 /**
vpcola 0:f1d3878b8dd9 673 *@}
vpcola 0:f1d3878b8dd9 674 */
vpcola 0:f1d3878b8dd9 675
vpcola 0:f1d3878b8dd9 676 /**
vpcola 0:f1d3878b8dd9 677 *@}
vpcola 0:f1d3878b8dd9 678 */
vpcola 0:f1d3878b8dd9 679
vpcola 0:f1d3878b8dd9 680
vpcola 0:f1d3878b8dd9 681 /**
vpcola 0:f1d3878b8dd9 682 *@}
vpcola 0:f1d3878b8dd9 683 */
vpcola 0:f1d3878b8dd9 684
vpcola 0:f1d3878b8dd9 685
vpcola 0:f1d3878b8dd9 686
vpcola 0:f1d3878b8dd9 687 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/