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