Vergil Cola
/
MQTTGateway2
Fork of my original MQTTGateway
Embed:
(wiki syntax)
Show/hide line numbers
SPIRIT_PktBasic.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file SPIRIT_PktBasic.c 00004 * @author VMA division - AMS 00005 * @version 3.2.2 00006 * @date 08-July-2015 00007 * @brief Configuration and management of SPIRIT Basic packets. 00008 * @details 00009 * 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 #include "SPIRIT_PktBasic.h" 00041 #include "MCU_Interface.h" 00042 00043 00044 /** 00045 * @addtogroup SPIRIT_Libraries 00046 * @{ 00047 */ 00048 00049 00050 /** 00051 * @addtogroup SPIRIT_PktBasic 00052 * @{ 00053 */ 00054 00055 00056 /** 00057 * @defgroup PktBasic_Private_TypesDefinitions Pkt Basic Private Types Definitions 00058 * @{ 00059 */ 00060 00061 /** 00062 *@} 00063 */ 00064 00065 00066 /** 00067 * @defgroup PktBasic_Private_Defines Pkt Basic Private Defines 00068 * @{ 00069 */ 00070 00071 /** 00072 *@} 00073 */ 00074 00075 00076 /** 00077 * @defgroup PktBasic_Private_Macros Pkt Basic Private Macros 00078 * @{ 00079 */ 00080 00081 /** 00082 *@} 00083 */ 00084 00085 00086 /** 00087 * @defgroup PktBasic_Private_Variables Pkt Basic Private Variables 00088 * @{ 00089 */ 00090 00091 /** 00092 *@} 00093 */ 00094 00095 00096 00097 /** 00098 * @defgroup PktBasic_Private_FunctionPrototypes Pkt Basic Private Function Prototypes 00099 * @{ 00100 */ 00101 00102 /** 00103 *@} 00104 */ 00105 00106 00107 /** 00108 * @defgroup PktBasic_Private_Functions Pkt Basic Private Functions 00109 * @{ 00110 */ 00111 00112 /** 00113 * @brief Initializes the SPIRIT Basic packet according to the specified parameters in the PktBasicInit struct. 00114 * Notice that this function sets the autofiltering option on CRC if it is set to any value different from BASIC_NO_CRC. 00115 * @param pxPktBasicInit Basic packet init structure. 00116 * This parameter is a pointer to @ref PktBasicInit. 00117 * @retval None. 00118 */ 00119 void SpiritPktBasicInit(PktBasicInit* pxPktBasicInit) 00120 { 00121 uint8_t tempRegValue[4], i; 00122 00123 /* Check the parameters */ 00124 s_assert_param(IS_BASIC_PREAMBLE_LENGTH(pxPktBasicInit->xPreambleLength)); 00125 s_assert_param(IS_BASIC_SYNC_LENGTH(pxPktBasicInit->xSyncLength)); 00126 s_assert_param(IS_BASIC_CRC_MODE(pxPktBasicInit->xCrcMode)); 00127 s_assert_param(IS_BASIC_LENGTH_WIDTH_BITS(pxPktBasicInit->cPktLengthWidth)); 00128 s_assert_param(IS_BASIC_FIX_VAR_LENGTH(pxPktBasicInit->xFixVarLength)); 00129 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicInit->xAddressField)); 00130 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicInit->xFec)); 00131 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicInit->xDataWhitening)); 00132 s_assert_param(IS_BASIC_CONTROL_LENGTH(pxPktBasicInit->xControlLength)); 00133 00134 /* Reads the PROTOCOL1 register */ 00135 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue[0]); 00136 00137 /* Mask a reserved bit */ 00138 tempRegValue[0] &= ~0x20; 00139 00140 /* Always set the automatic packet filtering */ 00141 tempRegValue[0] |= PROTOCOL1_AUTO_PCKT_FLT_MASK; 00142 00143 /* Writes the value on register */ 00144 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue[0]); 00145 00146 /* Reads the PCKT_FLT_OPTIONS register */ 00147 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]); 00148 00149 /* Always reset the control and source filtering (also if it is not present in basic) */ 00150 tempRegValue[0] &= ~(PCKT_FLT_OPTIONS_SOURCE_FILTERING_MASK | PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK); 00151 00152 /* Writes the value on register */ 00153 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]); 00154 00155 if(pxPktBasicInit->xAddressField == S_ENABLE) 00156 { 00157 tempRegValue[0]=0x08; 00158 } 00159 else 00160 { 00161 tempRegValue[0]=0x00; 00162 } 00163 /* Address and control length setting */ 00164 tempRegValue[0] |= ((uint8_t) pxPktBasicInit->xControlLength); 00165 00166 /* Packet format and width length setting */ 00167 pxPktBasicInit->cPktLengthWidth == 0 ? pxPktBasicInit->cPktLengthWidth=1 : pxPktBasicInit->cPktLengthWidth; 00168 tempRegValue[1] = ((uint8_t) PCKTCTRL3_PCKT_FRMT_BASIC) | ((uint8_t)(pxPktBasicInit->cPktLengthWidth-1)); 00169 00170 /* Preamble, sync and fixed or variable length setting */ 00171 tempRegValue[2] = ((uint8_t) pxPktBasicInit->xPreambleLength) | ((uint8_t) pxPktBasicInit->xSyncLength) | 00172 ((uint8_t) pxPktBasicInit->xFixVarLength); 00173 00174 /* CRC length, whitening and FEC setting */ 00175 tempRegValue[3] = (uint8_t) pxPktBasicInit->xCrcMode; 00176 00177 if(pxPktBasicInit->xDataWhitening == S_ENABLE) 00178 { 00179 tempRegValue[3] |= PCKTCTRL1_WHIT_MASK; 00180 } 00181 00182 if(pxPktBasicInit->xFec == S_ENABLE) 00183 { 00184 tempRegValue[3] |= PCKTCTRL1_FEC_MASK; 00185 } 00186 00187 /* Writes registers */ 00188 SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 4, tempRegValue); 00189 00190 /* Sync words setting */ 00191 for(i=0;i<4;i++) 00192 { 00193 if(i<3-(pxPktBasicInit->xSyncLength >>1)) 00194 { 00195 tempRegValue[i]=0; 00196 } 00197 else 00198 { 00199 tempRegValue[i] = (uint8_t)(pxPktBasicInit->lSyncWords>>(8*i)); 00200 } 00201 } 00202 00203 /* Sets CRC check bit */ 00204 if(pxPktBasicInit->xCrcMode == PKT_NO_CRC) 00205 { 00206 SpiritPktBasicFilterOnCrc(S_DISABLE); 00207 } 00208 else 00209 { 00210 SpiritPktBasicFilterOnCrc(S_ENABLE); 00211 } 00212 00213 00214 g_xStatus = SpiritSpiWriteRegisters(SYNC4_BASE, 4, tempRegValue); 00215 00216 } 00217 00218 00219 /** 00220 * @brief Returns the SPIRIT Basic packet structure according to the specified parameters in the registers. 00221 * @param pxPktBasicInit Basic packet init structure. 00222 * This parameter is a pointer to @ref PktBasicInit. 00223 * @retval None. 00224 */ 00225 void SpiritPktBasicGetInfo(PktBasicInit* pxPktBasicInit) 00226 { 00227 uint8_t tempRegValue[10]; 00228 00229 /* Reads registers */ 00230 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 10, tempRegValue); 00231 00232 /* Length width */ 00233 pxPktBasicInit->cPktLengthWidth=(tempRegValue[1] & 0x0F)+1; 00234 00235 /* Address field */ 00236 pxPktBasicInit->xAddressField=(SpiritFunctionalState)((tempRegValue[0]>>3) & 0x01); 00237 00238 /* Control length */ 00239 pxPktBasicInit->xControlLength=(BasicControlLength)(tempRegValue[0] & 0x07); 00240 00241 /* CRC mode */ 00242 pxPktBasicInit->xCrcMode=(BasicCrcMode)(tempRegValue[3] & 0xE0); 00243 00244 /* Whitening */ 00245 pxPktBasicInit->xDataWhitening=(SpiritFunctionalState)((tempRegValue[3] >> 4) & 0x01); 00246 00247 /* FEC */ 00248 pxPktBasicInit->xFec=(SpiritFunctionalState)(tempRegValue[3] & 0x01); 00249 00250 /* FIX or VAR bit */ 00251 pxPktBasicInit->xFixVarLength=(BasicFixVarLength)(tempRegValue[2] & 0x01); 00252 00253 /* Preamble length */ 00254 pxPktBasicInit->xPreambleLength=(BasicPreambleLength)(tempRegValue[2] & 0xF8); 00255 00256 /* Sync length */ 00257 pxPktBasicInit->xSyncLength=(BasicSyncLength)(tempRegValue[2] & 0x06); 00258 00259 /* sync Words */ 00260 pxPktBasicInit->lSyncWords=0; 00261 for(uint8_t i=0 ; i<4 ; i++) 00262 { 00263 if(i>2-(((uint8_t)pxPktBasicInit->xSyncLength) >>1)) 00264 { 00265 pxPktBasicInit->lSyncWords |= (uint32_t)(tempRegValue[i+6])<<(8*i); 00266 } 00267 } 00268 00269 } 00270 00271 00272 /** 00273 * @brief Initializes the SPIRIT Basic packet addresses according to the specified 00274 * parameters in the PktBasicAddressesInit struct. 00275 * @param pxPktBasicAddresses Basic packet addresses init structure. 00276 * This parameter is a pointer to @ref PktBasicAddresses. 00277 * @retval None. 00278 */ 00279 void SpiritPktBasicAddressesInit(PktBasicAddressesInit* pxPktBasicAddresses) 00280 { 00281 uint8_t tempRegValue[3]; 00282 00283 /* Check the parameters */ 00284 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicAddresses->xFilterOnMyAddress)); 00285 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicAddresses->xFilterOnMulticastAddress)); 00286 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(pxPktBasicAddresses->xFilterOnBroadcastAddress)); 00287 00288 00289 /* Reads the PCKT_FLT_OPTIONS ragister */ 00290 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]); 00291 00292 /* Enables or disables filtering on my address */ 00293 if(pxPktBasicAddresses->xFilterOnMyAddress == S_ENABLE) 00294 { 00295 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK; 00296 } 00297 else 00298 { 00299 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK; 00300 } 00301 00302 /* Enables or disables filtering on multicast address */ 00303 if(pxPktBasicAddresses->xFilterOnMulticastAddress == S_ENABLE) 00304 { 00305 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK; 00306 } 00307 else 00308 { 00309 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK; 00310 } 00311 00312 /* Enables or disables filtering on broadcast address */ 00313 if(pxPktBasicAddresses->xFilterOnBroadcastAddress == S_ENABLE) 00314 { 00315 tempRegValue[0] |= PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK; 00316 } 00317 else 00318 { 00319 tempRegValue[0] &= ~PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK; 00320 } 00321 00322 /* Writes the new value on the PCKT_FLT_OPTIONS register */ 00323 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]); 00324 00325 /* Fills the array with the addresses passed in the structure */ 00326 tempRegValue[0] = pxPktBasicAddresses->cBroadcastAddress; 00327 tempRegValue[1] = pxPktBasicAddresses->cMulticastAddress; 00328 tempRegValue[2] = pxPktBasicAddresses->cMyAddress; 00329 00330 /* Writes values on the PCKT_FLT_GOALS registers */ 00331 g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue); 00332 00333 00334 } 00335 00336 00337 /** 00338 * @brief Returns the SPIRIT Basic packet addresses structure according to the specified 00339 * parameters in the registers. 00340 * @param pxPktBasicAddresses Basic packet addresses init structure. 00341 * This parameter is a pointer to @ref PktBasicAddresses. 00342 * @retval None. 00343 */ 00344 void SpiritPktBasicGetAddressesInfo(PktBasicAddressesInit* pxPktBasicAddresses) 00345 { 00346 uint8_t tempRegValue[3]; 00347 00348 /* Reads values on the PCKT_FLT_GOALS registers */ 00349 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 3, tempRegValue); 00350 00351 /* Fit the structure with the read addresses */ 00352 pxPktBasicAddresses->cBroadcastAddress = tempRegValue[0]; 00353 pxPktBasicAddresses->cMulticastAddress = tempRegValue[1]; 00354 pxPktBasicAddresses->cMyAddress = tempRegValue[2]; 00355 00356 g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue[0]); 00357 00358 /* Fit the structure with the read filtering bits */ 00359 pxPktBasicAddresses->xFilterOnBroadcastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 1) & 0x01); 00360 pxPktBasicAddresses->xFilterOnMulticastAddress = (SpiritFunctionalState)((tempRegValue[0] >> 2) & 0x01); 00361 pxPktBasicAddresses->xFilterOnMyAddress = (SpiritFunctionalState)((tempRegValue[0] >> 3) & 0x01); 00362 00363 } 00364 00365 00366 /** 00367 * @brief Configures the Basic packet format as packet used by SPIRIT. 00368 * @param None. 00369 * @retval None. 00370 */ 00371 void SpiritPktBasicSetFormat(void) 00372 { 00373 uint8_t tempRegValue; 00374 00375 /* Reads the register value */ 00376 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue); 00377 00378 /* Build the new value. Also set to 0 the direct RX mode bits */ 00379 tempRegValue &= 0x0F; 00380 tempRegValue |= (uint8_t)PCKTCTRL3_PCKT_FRMT_BASIC; 00381 00382 /* Writes the value on the PCKTCTRL3 register */ 00383 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue); 00384 00385 /* Reads the PCKTCTRL1_BASE register */ 00386 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue); 00387 00388 /* Build the new value. Set to 0 the direct TX mode bits */ 00389 tempRegValue &= 0xF3; 00390 00391 /* Writes the value on the PCKTCTRL1 register */ 00392 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue); 00393 00394 /* Reads the PROTOCOL1 register */ 00395 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); 00396 00397 /* Mask a reserved bit */ 00398 tempRegValue &= ~0x20; 00399 00400 /* Writes the value on register */ 00401 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue); 00402 } 00403 00404 00405 /** 00406 * @brief Sets the address length for SPIRIT Basic packets. 00407 * @param xAddressField length of ADDRESS in bytes. 00408 * This parameter can be: S_ENABLE or S_DISABLE. 00409 * @retval None. 00410 */ 00411 void SpiritPktBasicAddressField(SpiritFunctionalState xAddressField) 00412 { 00413 uint8_t tempRegValue; 00414 00415 /* Check the parameters */ 00416 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xAddressField)); 00417 00418 /* Reads the PCKTCTRL4 register value */ 00419 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue); 00420 00421 /* Build the address length for the register */ 00422 if(xAddressField==S_ENABLE) 00423 { 00424 tempRegValue |= 0x08; 00425 } 00426 else 00427 { 00428 tempRegValue &= 0x07; 00429 } 00430 00431 /* Writes the new value on the PCKTCTRL4 register */ 00432 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 1, &tempRegValue); 00433 00434 } 00435 00436 00437 /** 00438 * @brief Specifies if the Address field for SPIRIT Basic packets is enabled or disabled. 00439 * @param None. 00440 * @retval SpiritFunctionalState Notifies if the address field is enabled or disabled. 00441 */ 00442 SpiritFunctionalState SpiritPktBasicGetAddressField(void) 00443 { 00444 uint8_t tempRegValue; 00445 00446 /* Reads the PCKTCTRL4 register value */ 00447 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue); 00448 00449 /* Returns the address field value */ 00450 if(tempRegValue & PCKTCTRL4_ADDRESS_LEN_MASK) 00451 { 00452 return S_ENABLE; 00453 } 00454 else 00455 { 00456 return S_DISABLE; 00457 } 00458 00459 } 00460 00461 00462 /** 00463 * @brief Sets the payload length for SPIRIT Basic packets. Since the packet length 00464 * depends from the address and the control field size, this 00465 * function reads the correspondent registers in order to determine 00466 * the correct packet length to be written. 00467 * @param nPayloadLength payload length in bytes. 00468 * This parameter is an uint16_t. 00469 * @retval None. 00470 */ 00471 void SpiritPktBasicSetPayloadLength(uint16_t nPayloadLength) 00472 { 00473 uint8_t tempRegValue[2]; 00474 uint16_t overSize=0; 00475 00476 /* Computes the oversize (address + control) size */ 00477 if(SpiritPktBasicGetAddressField()) 00478 { 00479 overSize=1; 00480 } 00481 overSize += (uint16_t) SpiritPktBasicGetControlLength(); 00482 00483 /* Computes PCKTLEN0 value from nPayloadLength */ 00484 tempRegValue[1]=BASIC_BUILD_PCKTLEN0(nPayloadLength+overSize); 00485 /* Computes PCKTLEN1 value from nPayloadLength */ 00486 tempRegValue[0]=BASIC_BUILD_PCKTLEN1(nPayloadLength+overSize); 00487 00488 /* Writes data on the PCKTLEN1/0 register */ 00489 g_xStatus = SpiritSpiWriteRegisters(PCKTLEN1_BASE, 2, tempRegValue); 00490 00491 } 00492 00493 00494 /** 00495 * @brief Returns the payload length for SPIRIT Basic packets. Since the 00496 * packet length depends from the address and the control 00497 * field size, this function reads the correspondent 00498 * registers in order to determine the correct payload length 00499 * to be returned. 00500 * @param None. 00501 * @retval uint16_t Payload length in bytes. 00502 */ 00503 uint16_t SpiritPktBasicGetPayloadLength(void) 00504 { 00505 uint8_t tempRegValue[2]; 00506 uint16_t overSize=0; 00507 00508 /* Computes the oversize (address + control) size */ 00509 if(SpiritPktBasicGetAddressField()) 00510 { 00511 overSize=1; 00512 } 00513 overSize += (uint16_t) SpiritPktBasicGetControlLength(); 00514 00515 /* Reads the packet length registers */ 00516 g_xStatus = SpiritSpiReadRegisters(PCKTLEN1_BASE, 2, tempRegValue); 00517 00518 /* Returns the packet length */ 00519 return ((((uint16_t)tempRegValue[0])<<8) + (uint16_t) tempRegValue[1]) - overSize; 00520 } 00521 00522 /** 00523 * @brief Returns the packet length field of the received packet. 00524 * @param None. 00525 * @retval uint16_t Packet length. 00526 */ 00527 uint16_t SpiritPktBasicGetReceivedPktLength(void) 00528 { 00529 uint8_t tempRegValue[2]; 00530 uint16_t overSize=0; 00531 00532 /* Computes the oversize (address + control) size */ 00533 if(SpiritPktBasicGetAddressField()) 00534 { 00535 overSize=1; 00536 } 00537 overSize += (uint16_t) SpiritPktBasicGetControlLength(); 00538 00539 /* Reads the RX_PCKT_LENx registers value */ 00540 g_xStatus = SpiritSpiReadRegisters(RX_PCKT_LEN1_BASE, 2, tempRegValue); 00541 00542 /* Rebuild and return the length field */ 00543 return (((((uint16_t) tempRegValue[0]) << 8) + (uint16_t) tempRegValue[1]) - overSize); 00544 } 00545 00546 /** 00547 * @brief Computes and sets the variable payload length for SPIRIT Basic packets. 00548 * @param nMaxPayloadLength payload length in bytes. 00549 * This parameter is an uint16_t. 00550 * @param xAddressField Enable or Disable Address Field. 00551 * This parameter can be S_ENABLE or S_DISABLE. 00552 * @param xControlLength Control length in bytes. 00553 * This parameter can be any value of @ref BasicControlLength. 00554 * @retval None. 00555 */ 00556 void SpiritPktBasicSetVarLengthWidth(uint16_t nMaxPayloadLength, SpiritFunctionalState xAddressField, BasicControlLength xControlLength) 00557 { 00558 uint8_t tempRegValue, 00559 addressLength, 00560 i; 00561 uint32_t packetLength; 00562 00563 /* Sets the address length according to xAddressField */ 00564 if(xAddressField == S_ENABLE) 00565 { 00566 addressLength=1; 00567 } 00568 else 00569 { 00570 addressLength=0; 00571 } 00572 00573 /* packet length = payload length + address length + control length */ 00574 packetLength=nMaxPayloadLength+addressLength+xControlLength; 00575 00576 /* Computes the number of bits */ 00577 for(i=0;i<16;i++) 00578 { 00579 if(packetLength == 0) break; 00580 { 00581 packetLength >>= 1; 00582 } 00583 } 00584 i==0 ? i=1 : i; 00585 00586 /* Reads the PCKTCTRL3 register value */ 00587 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue); 00588 00589 /* Build value for the length width */ 00590 tempRegValue &= ~PCKTCTRL3_LEN_WID_MASK; 00591 tempRegValue |= (uint8_t)(i-1); 00592 00593 /* Writes the PCKTCTRL3 register value */ 00594 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue); 00595 00596 } 00597 00598 00599 00600 /** 00601 *@} 00602 */ 00603 00604 /** 00605 *@} 00606 */ 00607 00608 00609 /** 00610 *@} 00611 */ 00612 00613 00614 00615 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 18:06:47 by 1.7.2