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