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