Added support for the WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Easy Connect

Easily add all supported connectivity methods to your mbed OS project

This project is derived from https://developer.mbed.org/teams/sandbox/code/simple-mbed-client-example/file/dd6231df71bb/easy-connect.lib. It give user the ability to switch between connectivity methods and includes support for the WNC14A2A Data Module. The `NetworkInterface` API makes this easy, but you still need a mechanism for the user to select the connection method, The selection is made by modifying the `mbed_app.json` file and using `easy_connect()` from your application.

Specifying connectivity method

To add support for the WNC14A2A, add the following to your ``mbed_app.json`` file:

mbed_app.json

{
    "config": {
        "network-interface":{
            "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD,WNC14A2A",
            "value": "WNC14A2A"
        }
    },
}

After you choose `WNC14A2A` you'll also need to indicate if you want debug output or not by Enabling (true) or Disabling (false) WNC_DEBUG.

If WNC_DEBUG is enabled, there are 3 different levels of debug output (selected via bit settings). These debug levels are set using the following values:

ValueDescription
1Basic WNC driver debug output
2Comprehensive WNC driver debug output
4Network Layer debug output

You can have any combination of these three bit values for a total value of 0 – 7.

WNC Debug Settings

    "config": {
        "WNC_DEBUG": {
            "value": false
        },
        "WNC_DEBUG_SETTING": {
            "value": 4
        },
    }

Using Easy Connect from your application

Easy Connect has just one function which will either return a `NetworkInterface`-pointer or `NULL`:

Sample Code

#include "easy-connect.h"

int main(int, char**) {
    NetworkInterface* network = easy_connect(true); /* has 1 argument, enable_logging (pass in true to log to serial port) */
    if (!network) {
        printf("Connecting to the network failed... See serial output.\r\n");
        return 1;
    }
 
    // Rest of your program
}

Tested on

  • K64F with Ethernet.
  • AT&T Cellular IoT Starter Kit with WNC M14A2A Cellular Data Module

The WNCInterface class currently supports the following version(s):

  • MPSS: M14A2A_v11.50.164451 APSS: M14A2A_v11.53.164451

License

This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Committer:
group-Avnet
Date:
Wed Apr 19 01:08:11 2017 +0000
Revision:
0:478cfd88041f
Initial commit

Who changed what in which revision?

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