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_PktBasic.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 Basic 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_PktBasic.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_PktBasic
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 PktBasic_Private_TypesDefinitions Pkt Basic 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 PktBasic_Private_Defines Pkt Basic 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 PktBasic_Private_Macros Pkt Basic 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 PktBasic_Private_Variables Pkt Basic 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 /**
group-Avnet 0:478cfd88041f 98 * @defgroup PktBasic_Private_FunctionPrototypes Pkt Basic Private Function Prototypes
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 /**
group-Avnet 0:478cfd88041f 108 * @defgroup PktBasic_Private_Functions Pkt Basic Private Functions
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 Basic packet according to the specified parameters in the PktBasicInit struct.
group-Avnet 0:478cfd88041f 114 * Notice that this function sets the autofiltering option on CRC if it is set to any value different from BASIC_NO_CRC.
group-Avnet 0:478cfd88041f 115 * @param pxPktBasicInit Basic packet init structure.
group-Avnet 0:478cfd88041f 116 * This parameter is a pointer to @ref PktBasicInit.
group-Avnet 0:478cfd88041f 117 * @retval None.
group-Avnet 0:478cfd88041f 118 */
group-Avnet 0:478cfd88041f 119 void SpiritPktBasicInit(PktBasicInit* pxPktBasicInit)
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_BASIC_PREAMBLE_LENGTH(pxPktBasicInit->xPreambleLength));
group-Avnet 0:478cfd88041f 125 s_assert_param(IS_BASIC_SYNC_LENGTH(pxPktBasicInit->xSyncLength));
group-Avnet 0:478cfd88041f 126 s_assert_param(IS_BASIC_CRC_MODE(pxPktBasicInit->xCrcMode));
group-Avnet 0:478cfd88041f 127 s_assert_param(IS_BASIC_LENGTH_WIDTH_BITS(pxPktBasicInit->cPktLengthWidth));
group-Avnet 0:478cfd88041f 128 s_assert_param(IS_BASIC_FIX_VAR_LENGTH(pxPktBasicInit->xFixVarLength));
group-Avnet 0:478cfd88041f 129 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicInit->xAddressField));
group-Avnet 0:478cfd88041f 130 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicInit->xFec));
group-Avnet 0:478cfd88041f 131 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicInit->xDataWhitening));
group-Avnet 0:478cfd88041f 132 s_assert_param(IS_BASIC_CONTROL_LENGTH(pxPktBasicInit->xControlLength));
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 (also if it is not present in basic) */
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 if(pxPktBasicInit->xAddressField == S_ENABLE)
group-Avnet 0:478cfd88041f 156 {
group-Avnet 0:478cfd88041f 157 tempRegValue[0]=0x08;
group-Avnet 0:478cfd88041f 158 }
group-Avnet 0:478cfd88041f 159 else
group-Avnet 0:478cfd88041f 160 {
group-Avnet 0:478cfd88041f 161 tempRegValue[0]=0x00;
group-Avnet 0:478cfd88041f 162 }
group-Avnet 0:478cfd88041f 163 /* Address and control length setting */
group-Avnet 0:478cfd88041f 164 tempRegValue[0] |= ((uint8_t) pxPktBasicInit->xControlLength);
group-Avnet 0:478cfd88041f 165
group-Avnet 0:478cfd88041f 166 /* Packet format and width length setting */
group-Avnet 0:478cfd88041f 167 pxPktBasicInit->cPktLengthWidth == 0 ? pxPktBasicInit->cPktLengthWidth=1 : pxPktBasicInit->cPktLengthWidth;
group-Avnet 0:478cfd88041f 168 tempRegValue[1] = ((uint8_t) PCKTCTRL3_PCKT_FRMT_BASIC) | ((uint8_t)(pxPktBasicInit->cPktLengthWidth-1));
group-Avnet 0:478cfd88041f 169
group-Avnet 0:478cfd88041f 170 /* Preamble, sync and fixed or variable length setting */
group-Avnet 0:478cfd88041f 171 tempRegValue[2] = ((uint8_t) pxPktBasicInit->xPreambleLength) | ((uint8_t) pxPktBasicInit->xSyncLength) |
group-Avnet 0:478cfd88041f 172 ((uint8_t) pxPktBasicInit->xFixVarLength);
group-Avnet 0:478cfd88041f 173
group-Avnet 0:478cfd88041f 174 /* CRC length, whitening and FEC setting */
group-Avnet 0:478cfd88041f 175 tempRegValue[3] = (uint8_t) pxPktBasicInit->xCrcMode;
group-Avnet 0:478cfd88041f 176
group-Avnet 0:478cfd88041f 177 if(pxPktBasicInit->xDataWhitening == S_ENABLE)
group-Avnet 0:478cfd88041f 178 {
group-Avnet 0:478cfd88041f 179 tempRegValue[3] |= PCKTCTRL1_WHIT_MASK;
group-Avnet 0:478cfd88041f 180 }
group-Avnet 0:478cfd88041f 181
group-Avnet 0:478cfd88041f 182 if(pxPktBasicInit->xFec == S_ENABLE)
group-Avnet 0:478cfd88041f 183 {
group-Avnet 0:478cfd88041f 184 tempRegValue[3] |= PCKTCTRL1_FEC_MASK;
group-Avnet 0:478cfd88041f 185 }
group-Avnet 0:478cfd88041f 186
group-Avnet 0:478cfd88041f 187 /* Writes registers */
group-Avnet 0:478cfd88041f 188 SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 4, tempRegValue);
group-Avnet 0:478cfd88041f 189
group-Avnet 0:478cfd88041f 190 /* Sync words setting */
group-Avnet 0:478cfd88041f 191 for(i=0;i<4;i++)
group-Avnet 0:478cfd88041f 192 {
group-Avnet 0:478cfd88041f 193 if(i<3-(pxPktBasicInit->xSyncLength >>1))
group-Avnet 0:478cfd88041f 194 {
group-Avnet 0:478cfd88041f 195 tempRegValue[i]=0;
group-Avnet 0:478cfd88041f 196 }
group-Avnet 0:478cfd88041f 197 else
group-Avnet 0:478cfd88041f 198 {
group-Avnet 0:478cfd88041f 199 tempRegValue[i] = (uint8_t)(pxPktBasicInit->lSyncWords>>(8*i));
group-Avnet 0:478cfd88041f 200 }
group-Avnet 0:478cfd88041f 201 }
group-Avnet 0:478cfd88041f 202
group-Avnet 0:478cfd88041f 203 /* Sets CRC check bit */
group-Avnet 0:478cfd88041f 204 if(pxPktBasicInit->xCrcMode == PKT_NO_CRC)
group-Avnet 0:478cfd88041f 205 {
group-Avnet 0:478cfd88041f 206 SpiritPktBasicFilterOnCrc(S_DISABLE);
group-Avnet 0:478cfd88041f 207 }
group-Avnet 0:478cfd88041f 208 else
group-Avnet 0:478cfd88041f 209 {
group-Avnet 0:478cfd88041f 210 SpiritPktBasicFilterOnCrc(S_ENABLE);
group-Avnet 0:478cfd88041f 211 }
group-Avnet 0:478cfd88041f 212
group-Avnet 0:478cfd88041f 213
group-Avnet 0:478cfd88041f 214 g_xStatus = SpiritSpiWriteRegisters(SYNC4_BASE, 4, tempRegValue);
group-Avnet 0:478cfd88041f 215
group-Avnet 0:478cfd88041f 216 }
group-Avnet 0:478cfd88041f 217
group-Avnet 0:478cfd88041f 218
group-Avnet 0:478cfd88041f 219 /**
group-Avnet 0:478cfd88041f 220 * @brief Returns the SPIRIT Basic packet structure according to the specified parameters in the registers.
group-Avnet 0:478cfd88041f 221 * @param pxPktBasicInit Basic packet init structure.
group-Avnet 0:478cfd88041f 222 * This parameter is a pointer to @ref PktBasicInit.
group-Avnet 0:478cfd88041f 223 * @retval None.
group-Avnet 0:478cfd88041f 224 */
group-Avnet 0:478cfd88041f 225 void SpiritPktBasicGetInfo(PktBasicInit* pxPktBasicInit)
group-Avnet 0:478cfd88041f 226 {
group-Avnet 0:478cfd88041f 227 uint8_t tempRegValue[10];
group-Avnet 0:478cfd88041f 228
group-Avnet 0:478cfd88041f 229 /* Reads registers */
group-Avnet 0:478cfd88041f 230 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 10, tempRegValue);
group-Avnet 0:478cfd88041f 231
group-Avnet 0:478cfd88041f 232 /* Length width */
group-Avnet 0:478cfd88041f 233 pxPktBasicInit->cPktLengthWidth=(tempRegValue[1] & 0x0F)+1;
group-Avnet 0:478cfd88041f 234
group-Avnet 0:478cfd88041f 235 /* Address field */
group-Avnet 0:478cfd88041f 236 pxPktBasicInit->xAddressField=(SpiritFunctionalState)((tempRegValue[0]>>3) & 0x01);
group-Avnet 0:478cfd88041f 237
group-Avnet 0:478cfd88041f 238 /* Control length */
group-Avnet 0:478cfd88041f 239 pxPktBasicInit->xControlLength=(BasicControlLength)(tempRegValue[0] & 0x07);
group-Avnet 0:478cfd88041f 240
group-Avnet 0:478cfd88041f 241 /* CRC mode */
group-Avnet 0:478cfd88041f 242 pxPktBasicInit->xCrcMode=(BasicCrcMode)(tempRegValue[3] & 0xE0);
group-Avnet 0:478cfd88041f 243
group-Avnet 0:478cfd88041f 244 /* Whitening */
group-Avnet 0:478cfd88041f 245 pxPktBasicInit->xDataWhitening=(SpiritFunctionalState)((tempRegValue[3] >> 4) & 0x01);
group-Avnet 0:478cfd88041f 246
group-Avnet 0:478cfd88041f 247 /* FEC */
group-Avnet 0:478cfd88041f 248 pxPktBasicInit->xFec=(SpiritFunctionalState)(tempRegValue[3] & 0x01);
group-Avnet 0:478cfd88041f 249
group-Avnet 0:478cfd88041f 250 /* FIX or VAR bit */
group-Avnet 0:478cfd88041f 251 pxPktBasicInit->xFixVarLength=(BasicFixVarLength)(tempRegValue[2] & 0x01);
group-Avnet 0:478cfd88041f 252
group-Avnet 0:478cfd88041f 253 /* Preamble length */
group-Avnet 0:478cfd88041f 254 pxPktBasicInit->xPreambleLength=(BasicPreambleLength)(tempRegValue[2] & 0xF8);
group-Avnet 0:478cfd88041f 255
group-Avnet 0:478cfd88041f 256 /* Sync length */
group-Avnet 0:478cfd88041f 257 pxPktBasicInit->xSyncLength=(BasicSyncLength)(tempRegValue[2] & 0x06);
group-Avnet 0:478cfd88041f 258
group-Avnet 0:478cfd88041f 259 /* sync Words */
group-Avnet 0:478cfd88041f 260 pxPktBasicInit->lSyncWords=0;
group-Avnet 0:478cfd88041f 261 for(uint8_t i=0 ; i<4 ; i++)
group-Avnet 0:478cfd88041f 262 {
group-Avnet 0:478cfd88041f 263 if(i>2-(((uint8_t)pxPktBasicInit->xSyncLength) >>1))
group-Avnet 0:478cfd88041f 264 {
group-Avnet 0:478cfd88041f 265 pxPktBasicInit->lSyncWords |= (uint32_t)(tempRegValue[i+6])<<(8*i);
group-Avnet 0:478cfd88041f 266 }
group-Avnet 0:478cfd88041f 267 }
group-Avnet 0:478cfd88041f 268
group-Avnet 0:478cfd88041f 269 }
group-Avnet 0:478cfd88041f 270
group-Avnet 0:478cfd88041f 271
group-Avnet 0:478cfd88041f 272 /**
group-Avnet 0:478cfd88041f 273 * @brief Initializes the SPIRIT Basic packet addresses according to the specified
group-Avnet 0:478cfd88041f 274 * parameters in the PktBasicAddressesInit struct.
group-Avnet 0:478cfd88041f 275 * @param pxPktBasicAddresses Basic packet addresses init structure.
group-Avnet 0:478cfd88041f 276 * This parameter is a pointer to @ref PktBasicAddresses.
group-Avnet 0:478cfd88041f 277 * @retval None.
group-Avnet 0:478cfd88041f 278 */
group-Avnet 0:478cfd88041f 279 void SpiritPktBasicAddressesInit(PktBasicAddressesInit* pxPktBasicAddresses)
group-Avnet 0:478cfd88041f 280 {
group-Avnet 0:478cfd88041f 281 uint8_t tempRegValue[3];
group-Avnet 0:478cfd88041f 282
group-Avnet 0:478cfd88041f 283 /* Check the parameters */
group-Avnet 0:478cfd88041f 284 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicAddresses->xFilterOnMyAddress));
group-Avnet 0:478cfd88041f 285 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicAddresses->xFilterOnMulticastAddress));
group-Avnet 0:478cfd88041f 286 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicAddresses->xFilterOnBroadcastAddress));
group-Avnet 0:478cfd88041f 287
group-Avnet 0:478cfd88041f 288
group-Avnet 0:478cfd88041f 289 /* Reads the PCKT_FLT_OPTIONS ragister */
group-Avnet 0:478cfd88041f 290 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
group-Avnet 0:478cfd88041f 291
group-Avnet 0:478cfd88041f 292 /* Enables or disables filtering on my address */
group-Avnet 0:478cfd88041f 293 if(pxPktBasicAddresses->xFilterOnMyAddress == S_ENABLE)
group-Avnet 0:478cfd88041f 294 {
group-Avnet 0:478cfd88041f 295 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_TX_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_TX_ADDR_MASK;
group-Avnet 0:478cfd88041f 300 }
group-Avnet 0:478cfd88041f 301
group-Avnet 0:478cfd88041f 302 /* Enables or disables filtering on multicast address */
group-Avnet 0:478cfd88041f 303 if(pxPktBasicAddresses->xFilterOnMulticastAddress == S_ENABLE)
group-Avnet 0:478cfd88041f 304 {
group-Avnet 0:478cfd88041f 305 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_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_MULTICAST_ADDR_MASK;
group-Avnet 0:478cfd88041f 310 }
group-Avnet 0:478cfd88041f 311
group-Avnet 0:478cfd88041f 312 /* Enables or disables filtering on broadcast address */
group-Avnet 0:478cfd88041f 313 if(pxPktBasicAddresses->xFilterOnBroadcastAddress == S_ENABLE)
group-Avnet 0:478cfd88041f 314 {
group-Avnet 0:478cfd88041f 315 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
group-Avnet 0:478cfd88041f 316 }
group-Avnet 0:478cfd88041f 317 else
group-Avnet 0:478cfd88041f 318 {
group-Avnet 0:478cfd88041f 319 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
group-Avnet 0:478cfd88041f 320 }
group-Avnet 0:478cfd88041f 321
group-Avnet 0:478cfd88041f 322 /* Writes the new value on the PCKT_FLT_OPTIONS register */
group-Avnet 0:478cfd88041f 323 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
group-Avnet 0:478cfd88041f 324
group-Avnet 0:478cfd88041f 325 /* Fills the array with the addresses passed in the structure */
group-Avnet 0:478cfd88041f 326 tempRegValue[0] = pxPktBasicAddresses->cBroadcastAddress;
group-Avnet 0:478cfd88041f 327 tempRegValue[1] = pxPktBasicAddresses->cMulticastAddress;
group-Avnet 0:478cfd88041f 328 tempRegValue[2] = pxPktBasicAddresses->cMyAddress;
group-Avnet 0:478cfd88041f 329
group-Avnet 0:478cfd88041f 330 /* Writes values on the PCKT_FLT_GOALS registers */
group-Avnet 0:478cfd88041f 331 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue);
group-Avnet 0:478cfd88041f 332
group-Avnet 0:478cfd88041f 333
group-Avnet 0:478cfd88041f 334 }
group-Avnet 0:478cfd88041f 335
group-Avnet 0:478cfd88041f 336
group-Avnet 0:478cfd88041f 337 /**
group-Avnet 0:478cfd88041f 338 * @brief Returns the SPIRIT Basic packet addresses structure according to the specified
group-Avnet 0:478cfd88041f 339 * parameters in the registers.
group-Avnet 0:478cfd88041f 340 * @param pxPktBasicAddresses Basic packet addresses init structure.
group-Avnet 0:478cfd88041f 341 * This parameter is a pointer to @ref PktBasicAddresses.
group-Avnet 0:478cfd88041f 342 * @retval None.
group-Avnet 0:478cfd88041f 343 */
group-Avnet 0:478cfd88041f 344 void SpiritPktBasicGetAddressesInfo(PktBasicAddressesInit* pxPktBasicAddresses)
group-Avnet 0:478cfd88041f 345 {
group-Avnet 0:478cfd88041f 346 uint8_t tempRegValue[3];
group-Avnet 0:478cfd88041f 347
group-Avnet 0:478cfd88041f 348 /* Reads values on the PCKT_FLT_GOALS registers */
group-Avnet 0:478cfd88041f 349 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue);
group-Avnet 0:478cfd88041f 350
group-Avnet 0:478cfd88041f 351 /* Fit the structure with the read addresses */
group-Avnet 0:478cfd88041f 352 pxPktBasicAddresses->cBroadcastAddress = tempRegValue[0];
group-Avnet 0:478cfd88041f 353 pxPktBasicAddresses->cMulticastAddress = tempRegValue[1];
group-Avnet 0:478cfd88041f 354 pxPktBasicAddresses->cMyAddress = tempRegValue[2];
group-Avnet 0:478cfd88041f 355
group-Avnet 0:478cfd88041f 356 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]);
group-Avnet 0:478cfd88041f 357
group-Avnet 0:478cfd88041f 358 /* Fit the structure with the read filtering bits */
group-Avnet 0:478cfd88041f 359 pxPktBasicAddresses->xFilterOnBroadcastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 1) & 0x01);
group-Avnet 0:478cfd88041f 360 pxPktBasicAddresses->xFilterOnMulticastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 2) & 0x01);
group-Avnet 0:478cfd88041f 361 pxPktBasicAddresses->xFilterOnMyAddress = (SpiritFunctionalState)((tempRegValue[0] >> 3) & 0x01);
group-Avnet 0:478cfd88041f 362
group-Avnet 0:478cfd88041f 363 }
group-Avnet 0:478cfd88041f 364
group-Avnet 0:478cfd88041f 365
group-Avnet 0:478cfd88041f 366 /**
group-Avnet 0:478cfd88041f 367 * @brief Configures the Basic packet format as packet used by SPIRIT.
group-Avnet 0:478cfd88041f 368 * @param None.
group-Avnet 0:478cfd88041f 369 * @retval None.
group-Avnet 0:478cfd88041f 370 */
group-Avnet 0:478cfd88041f 371 void SpiritPktBasicSetFormat(void)
group-Avnet 0:478cfd88041f 372 {
group-Avnet 0:478cfd88041f 373 uint8_t tempRegValue;
group-Avnet 0:478cfd88041f 374
group-Avnet 0:478cfd88041f 375 /* Reads the register value */
group-Avnet 0:478cfd88041f 376 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 377
group-Avnet 0:478cfd88041f 378 /* Build the new value. Also set to 0 the direct RX mode bits */
group-Avnet 0:478cfd88041f 379 tempRegValue &= 0x0F;
group-Avnet 0:478cfd88041f 380 tempRegValue |= (uint8_t)PCKTCTRL3_PCKT_FRMT_BASIC;
group-Avnet 0:478cfd88041f 381
group-Avnet 0:478cfd88041f 382 /* Writes the value on the PCKTCTRL3 register */
group-Avnet 0:478cfd88041f 383 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 384
group-Avnet 0:478cfd88041f 385 /* Reads the PCKTCTRL1_BASE register */
group-Avnet 0:478cfd88041f 386 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 387
group-Avnet 0:478cfd88041f 388 /* Build the new value. Set to 0 the direct TX mode bits */
group-Avnet 0:478cfd88041f 389 tempRegValue &= 0xF3;
group-Avnet 0:478cfd88041f 390
group-Avnet 0:478cfd88041f 391 /* Writes the value on the PCKTCTRL1 register */
group-Avnet 0:478cfd88041f 392 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 393
group-Avnet 0:478cfd88041f 394 /* Reads the PROTOCOL1 register */
group-Avnet 0:478cfd88041f 395 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 396
group-Avnet 0:478cfd88041f 397 /* Mask a reserved bit */
group-Avnet 0:478cfd88041f 398 tempRegValue &= ~0x20;
group-Avnet 0:478cfd88041f 399
group-Avnet 0:478cfd88041f 400 /* Writes the value on register */
group-Avnet 0:478cfd88041f 401 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 402 }
group-Avnet 0:478cfd88041f 403
group-Avnet 0:478cfd88041f 404
group-Avnet 0:478cfd88041f 405 /**
group-Avnet 0:478cfd88041f 406 * @brief Sets the address length for SPIRIT Basic packets.
group-Avnet 0:478cfd88041f 407 * @param xAddressField length of ADDRESS in bytes.
group-Avnet 0:478cfd88041f 408 * This parameter can be: S_ENABLE or S_DISABLE.
group-Avnet 0:478cfd88041f 409 * @retval None.
group-Avnet 0:478cfd88041f 410 */
group-Avnet 0:478cfd88041f 411 void SpiritPktBasicAddressField(SpiritFunctionalState xAddressField)
group-Avnet 0:478cfd88041f 412 {
group-Avnet 0:478cfd88041f 413 uint8_t tempRegValue;
group-Avnet 0:478cfd88041f 414
group-Avnet 0:478cfd88041f 415 /* Check the parameters */
group-Avnet 0:478cfd88041f 416 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xAddressField));
group-Avnet 0:478cfd88041f 417
group-Avnet 0:478cfd88041f 418 /* Reads the PCKTCTRL4 register value */
group-Avnet 0:478cfd88041f 419 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 420
group-Avnet 0:478cfd88041f 421 /* Build the address length for the register */
group-Avnet 0:478cfd88041f 422 if(xAddressField==S_ENABLE)
group-Avnet 0:478cfd88041f 423 {
group-Avnet 0:478cfd88041f 424 tempRegValue |= 0x08;
group-Avnet 0:478cfd88041f 425 }
group-Avnet 0:478cfd88041f 426 else
group-Avnet 0:478cfd88041f 427 {
group-Avnet 0:478cfd88041f 428 tempRegValue &= 0x07;
group-Avnet 0:478cfd88041f 429 }
group-Avnet 0:478cfd88041f 430
group-Avnet 0:478cfd88041f 431 /* Writes the new value on the PCKTCTRL4 register */
group-Avnet 0:478cfd88041f 432 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 433
group-Avnet 0:478cfd88041f 434 }
group-Avnet 0:478cfd88041f 435
group-Avnet 0:478cfd88041f 436
group-Avnet 0:478cfd88041f 437 /**
group-Avnet 0:478cfd88041f 438 * @brief Specifies if the Address field for SPIRIT Basic packets is enabled or disabled.
group-Avnet 0:478cfd88041f 439 * @param None.
group-Avnet 0:478cfd88041f 440 * @retval SpiritFunctionalState Notifies if the address field is enabled or disabled.
group-Avnet 0:478cfd88041f 441 */
group-Avnet 0:478cfd88041f 442 SpiritFunctionalState SpiritPktBasicGetAddressField(void)
group-Avnet 0:478cfd88041f 443 {
group-Avnet 0:478cfd88041f 444 uint8_t tempRegValue;
group-Avnet 0:478cfd88041f 445
group-Avnet 0:478cfd88041f 446 /* Reads the PCKTCTRL4 register value */
group-Avnet 0:478cfd88041f 447 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 448
group-Avnet 0:478cfd88041f 449 /* Returns the address field value */
group-Avnet 0:478cfd88041f 450 if(tempRegValue & PCKTCTRL4_ADDRESS_LEN_MASK)
group-Avnet 0:478cfd88041f 451 {
group-Avnet 0:478cfd88041f 452 return S_ENABLE;
group-Avnet 0:478cfd88041f 453 }
group-Avnet 0:478cfd88041f 454 else
group-Avnet 0:478cfd88041f 455 {
group-Avnet 0:478cfd88041f 456 return S_DISABLE;
group-Avnet 0:478cfd88041f 457 }
group-Avnet 0:478cfd88041f 458
group-Avnet 0:478cfd88041f 459 }
group-Avnet 0:478cfd88041f 460
group-Avnet 0:478cfd88041f 461
group-Avnet 0:478cfd88041f 462 /**
group-Avnet 0:478cfd88041f 463 * @brief Sets the payload length for SPIRIT Basic packets. Since the packet length
group-Avnet 0:478cfd88041f 464 * depends from the address and the control field size, this
group-Avnet 0:478cfd88041f 465 * function reads the correspondent registers in order to determine
group-Avnet 0:478cfd88041f 466 * the correct packet length to be written.
group-Avnet 0:478cfd88041f 467 * @param nPayloadLength payload length in bytes.
group-Avnet 0:478cfd88041f 468 * This parameter is an uint16_t.
group-Avnet 0:478cfd88041f 469 * @retval None.
group-Avnet 0:478cfd88041f 470 */
group-Avnet 0:478cfd88041f 471 void SpiritPktBasicSetPayloadLength(uint16_t nPayloadLength)
group-Avnet 0:478cfd88041f 472 {
group-Avnet 0:478cfd88041f 473 uint8_t tempRegValue[2];
group-Avnet 0:478cfd88041f 474 uint16_t overSize=0;
group-Avnet 0:478cfd88041f 475
group-Avnet 0:478cfd88041f 476 /* Computes the oversize (address + control) size */
group-Avnet 0:478cfd88041f 477 if(SpiritPktBasicGetAddressField())
group-Avnet 0:478cfd88041f 478 {
group-Avnet 0:478cfd88041f 479 overSize=1;
group-Avnet 0:478cfd88041f 480 }
group-Avnet 0:478cfd88041f 481 overSize += (uint16_t) SpiritPktBasicGetControlLength();
group-Avnet 0:478cfd88041f 482
group-Avnet 0:478cfd88041f 483 /* Computes PCKTLEN0 value from nPayloadLength */
group-Avnet 0:478cfd88041f 484 tempRegValue[1]=BASIC_BUILD_PCKTLEN0(nPayloadLength+overSize);
group-Avnet 0:478cfd88041f 485 /* Computes PCKTLEN1 value from nPayloadLength */
group-Avnet 0:478cfd88041f 486 tempRegValue[0]=BASIC_BUILD_PCKTLEN1(nPayloadLength+overSize);
group-Avnet 0:478cfd88041f 487
group-Avnet 0:478cfd88041f 488 /* Writes data on the PCKTLEN1/0 register */
group-Avnet 0:478cfd88041f 489 g_xStatus = SpiritSpiWriteRegisters(PCKTLEN1_BASE, 2, tempRegValue);
group-Avnet 0:478cfd88041f 490
group-Avnet 0:478cfd88041f 491 }
group-Avnet 0:478cfd88041f 492
group-Avnet 0:478cfd88041f 493
group-Avnet 0:478cfd88041f 494 /**
group-Avnet 0:478cfd88041f 495 * @brief Returns the payload length for SPIRIT Basic packets. Since the
group-Avnet 0:478cfd88041f 496 * packet length depends from the address and the control
group-Avnet 0:478cfd88041f 497 * field size, this function reads the correspondent
group-Avnet 0:478cfd88041f 498 * registers in order to determine the correct payload length
group-Avnet 0:478cfd88041f 499 * to be returned.
group-Avnet 0:478cfd88041f 500 * @param None.
group-Avnet 0:478cfd88041f 501 * @retval uint16_t Payload length in bytes.
group-Avnet 0:478cfd88041f 502 */
group-Avnet 0:478cfd88041f 503 uint16_t SpiritPktBasicGetPayloadLength(void)
group-Avnet 0:478cfd88041f 504 {
group-Avnet 0:478cfd88041f 505 uint8_t tempRegValue[2];
group-Avnet 0:478cfd88041f 506 uint16_t overSize=0;
group-Avnet 0:478cfd88041f 507
group-Avnet 0:478cfd88041f 508 /* Computes the oversize (address + control) size */
group-Avnet 0:478cfd88041f 509 if(SpiritPktBasicGetAddressField())
group-Avnet 0:478cfd88041f 510 {
group-Avnet 0:478cfd88041f 511 overSize=1;
group-Avnet 0:478cfd88041f 512 }
group-Avnet 0:478cfd88041f 513 overSize += (uint16_t) SpiritPktBasicGetControlLength();
group-Avnet 0:478cfd88041f 514
group-Avnet 0:478cfd88041f 515 /* Reads the packet length registers */
group-Avnet 0:478cfd88041f 516 g_xStatus = SpiritSpiReadRegisters(PCKTLEN1_BASE, 2, tempRegValue);
group-Avnet 0:478cfd88041f 517
group-Avnet 0:478cfd88041f 518 /* Returns the packet length */
group-Avnet 0:478cfd88041f 519 return ((((uint16_t)tempRegValue[0])<<8) + (uint16_t) tempRegValue[1]) - overSize;
group-Avnet 0:478cfd88041f 520 }
group-Avnet 0:478cfd88041f 521
group-Avnet 0:478cfd88041f 522 /**
group-Avnet 0:478cfd88041f 523 * @brief Returns the packet length field of the received packet.
group-Avnet 0:478cfd88041f 524 * @param None.
group-Avnet 0:478cfd88041f 525 * @retval uint16_t Packet length.
group-Avnet 0:478cfd88041f 526 */
group-Avnet 0:478cfd88041f 527 uint16_t SpiritPktBasicGetReceivedPktLength(void)
group-Avnet 0:478cfd88041f 528 {
group-Avnet 0:478cfd88041f 529 uint8_t tempRegValue[2];
group-Avnet 0:478cfd88041f 530 uint16_t overSize=0;
group-Avnet 0:478cfd88041f 531
group-Avnet 0:478cfd88041f 532 /* Computes the oversize (address + control) size */
group-Avnet 0:478cfd88041f 533 if(SpiritPktBasicGetAddressField())
group-Avnet 0:478cfd88041f 534 {
group-Avnet 0:478cfd88041f 535 overSize=1;
group-Avnet 0:478cfd88041f 536 }
group-Avnet 0:478cfd88041f 537 overSize += (uint16_t) SpiritPktBasicGetControlLength();
group-Avnet 0:478cfd88041f 538
group-Avnet 0:478cfd88041f 539 /* Reads the RX_PCKT_LENx registers value */
group-Avnet 0:478cfd88041f 540 g_xStatus = SpiritSpiReadRegisters(RX_PCKT_LEN1_BASE, 2, tempRegValue);
group-Avnet 0:478cfd88041f 541
group-Avnet 0:478cfd88041f 542 /* Rebuild and return the length field */
group-Avnet 0:478cfd88041f 543 return (((((uint16_t) tempRegValue[0]) << 8) + (uint16_t) tempRegValue[1]) - overSize);
group-Avnet 0:478cfd88041f 544 }
group-Avnet 0:478cfd88041f 545
group-Avnet 0:478cfd88041f 546 /**
group-Avnet 0:478cfd88041f 547 * @brief Computes and sets the variable payload length for SPIRIT Basic packets.
group-Avnet 0:478cfd88041f 548 * @param nMaxPayloadLength payload length in bytes.
group-Avnet 0:478cfd88041f 549 * This parameter is an uint16_t.
group-Avnet 0:478cfd88041f 550 * @param xAddressField Enable or Disable Address Field.
group-Avnet 0:478cfd88041f 551 * This parameter can be S_ENABLE or S_DISABLE.
group-Avnet 0:478cfd88041f 552 * @param xControlLength Control length in bytes.
group-Avnet 0:478cfd88041f 553 * This parameter can be any value of @ref BasicControlLength.
group-Avnet 0:478cfd88041f 554 * @retval None.
group-Avnet 0:478cfd88041f 555 */
group-Avnet 0:478cfd88041f 556 void SpiritPktBasicSetVarLengthWidth(uint16_t nMaxPayloadLength, SpiritFunctionalState xAddressField, BasicControlLength xControlLength)
group-Avnet 0:478cfd88041f 557 {
group-Avnet 0:478cfd88041f 558 uint8_t tempRegValue,
group-Avnet 0:478cfd88041f 559 addressLength,
group-Avnet 0:478cfd88041f 560 i;
group-Avnet 0:478cfd88041f 561 uint32_t packetLength;
group-Avnet 0:478cfd88041f 562
group-Avnet 0:478cfd88041f 563 /* Sets the address length according to xAddressField */
group-Avnet 0:478cfd88041f 564 if(xAddressField == S_ENABLE)
group-Avnet 0:478cfd88041f 565 {
group-Avnet 0:478cfd88041f 566 addressLength=1;
group-Avnet 0:478cfd88041f 567 }
group-Avnet 0:478cfd88041f 568 else
group-Avnet 0:478cfd88041f 569 {
group-Avnet 0:478cfd88041f 570 addressLength=0;
group-Avnet 0:478cfd88041f 571 }
group-Avnet 0:478cfd88041f 572
group-Avnet 0:478cfd88041f 573 /* packet length = payload length + address length + control length */
group-Avnet 0:478cfd88041f 574 packetLength=nMaxPayloadLength+addressLength+xControlLength;
group-Avnet 0:478cfd88041f 575
group-Avnet 0:478cfd88041f 576 /* Computes the number of bits */
group-Avnet 0:478cfd88041f 577 for(i=0;i<16;i++)
group-Avnet 0:478cfd88041f 578 {
group-Avnet 0:478cfd88041f 579 if(packetLength == 0) break;
group-Avnet 0:478cfd88041f 580 {
group-Avnet 0:478cfd88041f 581 packetLength >>= 1;
group-Avnet 0:478cfd88041f 582 }
group-Avnet 0:478cfd88041f 583 }
group-Avnet 0:478cfd88041f 584 i==0 ? i=1 : i;
group-Avnet 0:478cfd88041f 585
group-Avnet 0:478cfd88041f 586 /* Reads the PCKTCTRL3 register value */
group-Avnet 0:478cfd88041f 587 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 588
group-Avnet 0:478cfd88041f 589 /* Build value for the length width */
group-Avnet 0:478cfd88041f 590 tempRegValue &= ~PCKTCTRL3_LEN_WID_MASK;
group-Avnet 0:478cfd88041f 591 tempRegValue |= (uint8_t)(i-1);
group-Avnet 0:478cfd88041f 592
group-Avnet 0:478cfd88041f 593 /* Writes the PCKTCTRL3 register value */
group-Avnet 0:478cfd88041f 594 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
group-Avnet 0:478cfd88041f 595
group-Avnet 0:478cfd88041f 596 }
group-Avnet 0:478cfd88041f 597
group-Avnet 0:478cfd88041f 598
group-Avnet 0:478cfd88041f 599
group-Avnet 0:478cfd88041f 600 /**
group-Avnet 0:478cfd88041f 601 *@}
group-Avnet 0:478cfd88041f 602 */
group-Avnet 0:478cfd88041f 603
group-Avnet 0:478cfd88041f 604 /**
group-Avnet 0:478cfd88041f 605 *@}
group-Avnet 0:478cfd88041f 606 */
group-Avnet 0:478cfd88041f 607
group-Avnet 0:478cfd88041f 608
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
group-Avnet 0:478cfd88041f 614
group-Avnet 0:478cfd88041f 615 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/