Fork of my original MQTTGateway

Dependencies:   mbed-http

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SPIRIT_PktCommon.c Source File

SPIRIT_PktCommon.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    SPIRIT_PktCommon.c
00004   * @author  VMA division - AMS
00005   * @version 3.2.2
00006   * @date    08-July-2015
00007   * @brief   Configuration and management of the common features of SPIRIT packets.
00008   * @details
00009   *
00010   * @attention
00011   *
00012   * <h2><center>&copy; 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_PktCommon.h"
00041 #include "MCU_Interface.h"
00042 
00043 
00044 /**
00045  * @addtogroup SPIRIT_Libraries
00046  * @{
00047  */
00048 
00049 
00050 /**
00051  * @addtogroup SPIRIT_PktCommon
00052  * @{
00053  */
00054 
00055 
00056 /**
00057  * @defgroup PktCommon_Private_TypesDefinitions         Pkt Common Private Types Definitions
00058  * @{
00059  */
00060 
00061 /**
00062  *@}
00063  */
00064 
00065 
00066 /**
00067  * @defgroup PktCommon_Private_Defines                  Pkt Common Private Defines
00068  * @{
00069  */
00070 
00071 /**
00072  *@}
00073  */
00074 
00075 
00076 /**
00077  * @defgroup PktCommon_Private_Macros                   Pkt Common Private Macros
00078  * @{
00079  */
00080 
00081 /**
00082  *@}
00083  */
00084 
00085 
00086 /**
00087  * @defgroup PktCommon_Private_Variables                Pkt Common Private Variables
00088  * @{
00089  */
00090 
00091 /**
00092  *@}
00093  */
00094 
00095 
00096 
00097 /**
00098  * @defgroup PktCommon_Private_FunctionPrototypes       Pkt Common Private Function Prototypes
00099  * @{
00100  */
00101 
00102 /**
00103  *@}
00104  */
00105 
00106 
00107 /**
00108  * @defgroup PktCommon_Private_Functions                Pkt Common Private Functions
00109  * @{
00110  */
00111 
00112 /**
00113  * @brief  Sets the CONTROL field length for SPIRIT packets.
00114  * @param  xControlLength length of CONTROL field in bytes.
00115  *         This parameter can be any value of @ref PktControlLength.
00116  * @retval None.
00117  */
00118 void SpiritPktCommonSetControlLength(PktControlLength xControlLength)
00119 {
00120   uint8_t tempRegValue;
00121 
00122   /* Check the parameters */
00123   s_assert_param(IS_PKT_CONTROL_LENGTH(xControlLength));
00124 
00125   /* Reads the PCKTCTRL4 register value */
00126   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
00127 
00128   /* Set the control length */
00129   tempRegValue &= ~PCKTCTRL4_CONTROL_LEN_MASK;
00130   tempRegValue |= (uint8_t)xControlLength;
00131 
00132   /* Writes the new value on the PCKTCTRL4 register */
00133   g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
00134 }
00135 
00136 
00137 /**
00138  * @brief  Returns the CONTROL field length for SPIRIT packets.
00139  * @param  None.
00140  * @retval uint8_t Control field length.
00141  */
00142 uint8_t SpiritPktCommonGetControlLength(void)
00143 {
00144   uint8_t tempRegValue;
00145 
00146   /* Reads the PCKTCTRL4 register value */
00147   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL4_BASE, 1, &tempRegValue);
00148 
00149   /* Rebuild and return value */
00150   return (tempRegValue & PCKTCTRL4_CONTROL_LEN_MASK);
00151 }
00152 
00153 
00154 /**
00155  * @brief  Sets the PREAMBLE field Length mode for SPIRIT packets.
00156  * @param  xPreambleLength length of PREAMBLE field in bytes.
00157  *         This parameter can be any value of @ref PktPreambleLength.
00158  * @retval None.
00159  */
00160 void SpiritPktCommonSetPreambleLength(PktPreambleLength xPreambleLength)
00161 {
00162   uint8_t tempRegValue;
00163 
00164   /* Check the parameters */
00165   s_assert_param(IS_PKT_PREAMBLE_LENGTH(xPreambleLength));
00166 
00167   /* Reads the PCKTCTRL2 register value */
00168   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
00169 
00170   /* Set the preamble length */
00171   tempRegValue &= ~PCKTCTRL2_PREAMBLE_LENGTH_MASK;
00172   tempRegValue |= (uint8_t)xPreambleLength;
00173 
00174   /* Writes the new value on the PCKTCTRL2 register */
00175   g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
00176 }
00177 
00178 
00179 /**
00180  * @brief  Returns the PREAMBLE field Length mode for SPIRIT packets.
00181  * @param  None.
00182  * @retval uint8_t Preamble field length in bytes.
00183  */
00184 uint8_t SpiritPktCommonGetPreambleLength(void)
00185 {
00186   uint8_t tempRegValue;
00187 
00188   /* Reads the PCKTCTRL2 register value */
00189   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
00190 
00191   /* Rebuild and return value */
00192   return ((tempRegValue & PCKTCTRL2_PREAMBLE_LENGTH_MASK)>>3) + 1;
00193 
00194 }
00195 
00196 
00197 /**
00198  * @brief  Sets the SYNC field Length for SPIRIT packets.
00199  * @param  xSyncLength length of SYNC field in bytes.
00200  *         This parameter can be any value of @ref PktSyncLength.
00201  * @retval None.
00202  */
00203 void SpiritPktCommonSetSyncLength(PktSyncLength xSyncLength)
00204 {
00205   uint8_t tempRegValue;
00206 
00207   /* Check the parameters */
00208   s_assert_param(IS_PKT_SYNC_LENGTH(xSyncLength));
00209 
00210   /* Reads the PCKTCTRL2 register value */
00211   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
00212 
00213   /* Set the sync length */
00214   tempRegValue &= ~PCKTCTRL2_SYNC_LENGTH_MASK;
00215   tempRegValue |= (uint8_t)xSyncLength;
00216 
00217   /* Writes the new value on the PCKTCTRL2 register */
00218   g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
00219 
00220 }
00221 
00222 
00223 /**
00224  * @brief  Returns the SYNC field Length for SPIRIT packets.
00225  * @param  None.
00226  * @retval uint8_t Sync field length in bytes.
00227  */
00228 uint8_t SpiritPktCommonGetSyncLength(void)
00229 {
00230   uint8_t tempRetValue;
00231 
00232   /* Reads the PCKTCTRL2 register value */
00233   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRetValue);
00234 
00235   /* Rebuild and return value */
00236   return ((tempRetValue & PCKTCTRL2_SYNC_LENGTH_MASK)>>1) + 1;
00237 
00238 }
00239 
00240 
00241 /**
00242  * @brief  Sets fixed or variable payload length mode for SPIRIT packets.
00243  * @param  xFixVarLength variable or fixed length.
00244  *         PKT_FIXED_LENGTH_VAR -> variable (the length is extracted from the received packet).
00245  *         PKT_FIXED_LENGTH_FIX -> fix (the length is set by PCKTLEN0 and PCKTLEN1).
00246  * @retval None.
00247  */
00248 void SpiritPktCommonSetFixVarLength(PktFixVarLength xFixVarLength)
00249 {
00250   uint8_t tempRegValue;
00251 
00252   /* Check the parameters */
00253   s_assert_param(IS_PKT_FIX_VAR_LENGTH(xFixVarLength));
00254 
00255   /* Reads the PCKTCTRL2 register value */
00256   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
00257 
00258   /* Set fixed or variable address mode */
00259   tempRegValue &= ~PCKTCTRL2_FIX_VAR_LEN_MASK;
00260   tempRegValue |= (uint8_t)xFixVarLength;
00261 
00262   /* Writes the new value on the PCKTCTRL2 register */
00263   g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL2_BASE, 1, &tempRegValue);
00264 
00265 }
00266 
00267 
00268 /**
00269  * @brief  Enables or Disables the filtering on CRC.
00270  * @param  xNewState new state for CRC_CHECK.
00271  *         This parameter can be S_ENABLE or S_DISABLE.
00272  * @retval None.
00273  */
00274 void SpiritPktCommonFilterOnCrc(SpiritFunctionalState xNewState)
00275 {
00276   uint8_t tempRegValue;
00277 
00278   /* Check the parameters */
00279   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
00280 
00281   /* Reads the PCKT_FLT_OPTIONS register value */
00282   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00283 
00284   /* Modify the register value: enable or disable the CRC filtering */
00285   if(xNewState == S_ENABLE)
00286   {
00287     tempRegValue |= PCKT_FLT_OPTIONS_CRC_CHECK_MASK;
00288   }
00289   else
00290   {
00291     tempRegValue &= ~PCKT_FLT_OPTIONS_CRC_CHECK_MASK;
00292   }
00293 
00294   /* Writes the PCKT_FLT_OPTIONS register value */
00295   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00296 
00297 }
00298 
00299 
00300 /**
00301  * @brief  Returns the CRC filtering enable bit.
00302  * @param  None.
00303  * @retval SpiritFunctionalState CRC filtering.
00304  */
00305 SpiritFunctionalState SpiritPktCommonGetFilterOnCrc(void)
00306 {
00307   uint8_t tempRegValue;
00308 
00309 
00310   /* Reads the PCKT_FLT_OPTIONS register value */
00311   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00312 
00313   /* Check the CRC filtering bit */
00314   if(tempRegValue & PCKT_FLT_OPTIONS_CRC_CHECK_MASK)
00315   {
00316     return S_ENABLE;
00317   }
00318   else
00319   {
00320     return S_DISABLE;
00321   }
00322 
00323 }
00324 
00325 
00326 /**
00327  * @brief  Sets the CRC mode for SPIRIT packets.
00328  * @param  xCrcMode length of CRC field in bytes.
00329  *         This parameter can be any value of @ref PktCrcMode.
00330  * @retval None.
00331  */
00332 void SpiritPktCommonSetCrcMode(PktCrcMode xCrcMode)
00333 {
00334   uint8_t tempRegValue;
00335 
00336   /* Check the parameters */
00337   s_assert_param(IS_PKT_CRC_MODE(xCrcMode));
00338 
00339   /* Reads the PCKTCTRL1 register value */
00340   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
00341 
00342   /* Build data to write setting the CRC mode */
00343   tempRegValue &= ~PCKTCTRL1_CRC_MODE_MASK;
00344   tempRegValue |= (uint8_t)xCrcMode;
00345 
00346   /* Writes the new value on the PCKTCTRL1 register */
00347   g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
00348 
00349 }
00350 
00351 
00352 /**
00353  * @brief  Returns the CRC mode for SPIRIT packets.
00354  * @param  None.
00355  * @retval PktCrcMode Crc mode.
00356  */
00357 PktCrcMode SpiritPktCommonGetCrcMode(void)
00358 {
00359   uint8_t tempRegValue;
00360 
00361   /* Reads the PCKTCTRL1 register */
00362   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
00363 
00364   /* Rebuild and return value */
00365   return (PktCrcMode)(tempRegValue & 0xE0);
00366 
00367 }
00368 
00369 
00370 /**
00371  * @brief  Enables or Disables WHITENING for SPIRIT packets.
00372  * @param  xNewState new state for WHITENING mode.
00373  *         This parameter can be S_ENABLE or S_DISABLE.
00374  * @retval None.
00375  */
00376 void SpiritPktCommonWhitening(SpiritFunctionalState xNewState)
00377 {
00378   uint8_t tempRegValue;
00379 
00380   /* Check the parameters */
00381   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
00382 
00383   /* Reads the PCKTCTRL1 register value */
00384   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
00385 
00386   /* Build data to write: set or reset the whitening enable bit */
00387   if(xNewState == S_ENABLE)
00388   {
00389     tempRegValue |= PCKTCTRL1_WHIT_MASK;
00390   }
00391   else
00392   {
00393     tempRegValue &= ~PCKTCTRL1_WHIT_MASK;
00394   }
00395 
00396   /* Writes the new value on the PCKTCTRL1 register */
00397   g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
00398 
00399 }
00400 
00401 
00402 /**
00403  * @brief  Enables or Disables FEC for SPIRIT packets.
00404  * @param  xNewState new state for FEC mode.
00405  *         This parameter can be S_ENABLE or S_DISABLE.
00406  * @retval None.
00407  */
00408 void SpiritPktCommonFec(SpiritFunctionalState xNewState)
00409 {
00410   uint8_t tempRegValue;
00411 
00412   /* Check the parameters */
00413   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
00414 
00415   /* Reads the PCKTCTRL1 register value */
00416   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
00417 
00418   /* Build data to write: set or reset the FEC enable bit */
00419   if(xNewState == S_ENABLE)
00420   {
00421     tempRegValue |= PCKTCTRL1_FEC_MASK;
00422   }
00423   else
00424   {
00425     tempRegValue &= ~PCKTCTRL1_FEC_MASK;
00426   }
00427 
00428   /* Writes data on the PCKTCTRL1 register */
00429   g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
00430 
00431 }
00432 
00433 
00434 /**
00435  * @brief  Sets a specific SYNC word for SPIRIT packets.
00436  * @param  xSyncX SYNC word number to be set.
00437  *         This parameter can be any value of @ref PktSyncX.
00438  * @param  cSyncWord SYNC word.
00439  *         This parameter is an uint8_t.
00440  * @retval None.
00441  */
00442 void SpiritPktCommonSetSyncxWord(PktSyncX xSyncX ,  uint8_t cSyncWord)
00443 {
00444   uint8_t tempRegAddress;
00445 
00446   /* Check the parameters */
00447   s_assert_param(IS_PKT_SYNCx(xSyncX));
00448 
00449   /* Set the specified address */
00450   switch(xSyncX)
00451   {
00452     case PKT_SYNC_WORD_1:
00453       tempRegAddress=SYNC1_BASE;
00454       break;
00455     case PKT_SYNC_WORD_2:
00456       tempRegAddress=SYNC2_BASE;
00457       break;
00458     case PKT_SYNC_WORD_3:
00459       tempRegAddress=SYNC3_BASE;
00460       break;
00461     default:
00462       tempRegAddress=SYNC4_BASE;
00463       break;
00464   }
00465 
00466   /* Writes value on the selected register */
00467   g_xStatus = SpiritSpiWriteRegisters(tempRegAddress, 1, &cSyncWord);
00468 
00469 }
00470 
00471 
00472 /**
00473  * @brief  Returns a specific SYNC word for SPIRIT packets.
00474  * @param  xSyncX SYNC word number to be get.
00475  *         This parameter can be any value of @ref PktSyncX.
00476  * @retval uint8_t Sync word x.
00477  */
00478 uint8_t SpiritPktCommonGetSyncxWord(PktSyncX xSyncX)
00479 {
00480   uint8_t tempRegAddress, tempRegValue;
00481 
00482   /* Check the parameters */
00483   s_assert_param(IS_PKT_SYNCx(xSyncX));
00484 
00485   /* Set the specified address */
00486   switch(xSyncX)
00487   {
00488     case PKT_SYNC_WORD_1:
00489       tempRegAddress=SYNC1_BASE;
00490       break;
00491     case PKT_SYNC_WORD_2:
00492       tempRegAddress=SYNC2_BASE;
00493       break;
00494     case PKT_SYNC_WORD_3:
00495       tempRegAddress=SYNC3_BASE;
00496       break;
00497     default:
00498       tempRegAddress=SYNC4_BASE;
00499       break;
00500   }
00501 
00502   /* Reads the selected register value */
00503   g_xStatus = SpiritSpiReadRegisters(tempRegAddress, 1, &tempRegValue);
00504 
00505   /* Returns the read value */
00506   return tempRegValue;
00507 
00508 }
00509 
00510 
00511 /**
00512  * @brief  Sets multiple SYNC words for SPIRIT packets.
00513  * @param  lSyncWords SYNC words to be set with format: 0x|SYNC1|SYNC2|SYNC3|SYNC4|.
00514  *         This parameter is a uint32_t.
00515  * @param  xSyncLength SYNC length in bytes. The 32bit word passed will be stored in the SYNCx registers from the MSb
00516  *         until the number of bytes in xSyncLength has been stored.
00517  *         This parameter is a @ref PktSyncLength.
00518  * @retval None.
00519  */
00520 void SpiritPktCommonSetSyncWords(uint32_t lSyncWords, PktSyncLength xSyncLength)
00521 {
00522   uint8_t tempRegValue[4];
00523 
00524   /* Split the 32-bit value in 4 8-bit values */
00525   for(uint8_t i=0 ; i<4 ; i++)
00526   {
00527     if(i< ((3-xSyncLength) >>1) )
00528     {
00529       tempRegValue[i]=0;
00530     }
00531     else
00532     {
00533       tempRegValue[i]=(uint8_t)(lSyncWords>>(8*i));
00534     }
00535   }
00536 
00537   /* Writes SYNC value on the SYNCx registers */
00538   g_xStatus = SpiritSpiWriteRegisters(SYNC4_BASE, 4, tempRegValue);
00539 
00540 }
00541 
00542 
00543 /**
00544  * @brief  Returns multiple SYNC words for SPIRIT packets.
00545  * @param  xSyncLength SYNC length in bytes. The 32bit word passed will be stored in the SYNCx registers from the MSb
00546  *         until the number of bytes in xSyncLength has been stored.
00547  *         This parameter is a pointer to @ref PktSyncLength.
00548  * @retval uint32_t Sync words. The format of the read 32 bit word is 0x|SYNC1|SYNC2|SYNC3|SYNC4|.
00549  */
00550 uint32_t SpiritPktCommonGetSyncWords(PktSyncLength xSyncLength)
00551 {
00552   uint8_t tempRegValue[4];
00553   uint32_t tempRetValue=0;
00554 
00555   /* Reads the SYNCx registers value */
00556   g_xStatus = SpiritSpiReadRegisters(SYNC4_BASE, 4, tempRegValue);
00557 
00558   /* Rebuild the SYNC words */
00559   for(uint8_t i=0 ; i<4 ; i++)
00560   {
00561     if(i>2-(xSyncLength >>1))
00562     {
00563       tempRetValue |= tempRegValue[i]<<(8*i);
00564     }
00565   }
00566 
00567   /* Return SYNC words */
00568   return tempRetValue;
00569 
00570 }
00571 
00572 
00573 /**
00574  * @brief  Returns the variable length width (in number of bits).
00575  * @param  None.
00576  * @retval uint8_t Variable length width in bits.
00577  */
00578 uint8_t SpiritPktCommonGetVarLengthWidth(void)
00579 {
00580   uint8_t tempRegValue;
00581 
00582   /* Reads the PCKTCTRL3 register value */
00583   g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
00584 
00585   /* Rebuild and return value */
00586   return (tempRegValue & PCKTCTRL3_LEN_WID_MASK)+1;
00587 
00588 }
00589 
00590 
00591 /**
00592  * @brief  Sets the destination address for the Tx packet.
00593  * @param  cAddress Destination address.
00594  *         This parameter is an uint8_t.
00595  * @retval None.
00596  */
00597 void SpiritPktCommonSetDestinationAddress(uint8_t cAddress)
00598 {
00599   /* Writes value on PCKT_FLT_GOALS_SOURCE_ADDR register */
00600   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_SOURCE_ADDR_BASE, 1, &cAddress);
00601 
00602 }
00603 
00604 
00605 /**
00606  * @brief  Returns the settled destination address.
00607  * @param  None.
00608  * @retval uint8_t Transmitted destination address.
00609  */
00610 uint8_t SpiritPktCommonGetTransmittedDestAddress(void)
00611 {
00612   uint8_t tempRegValue;
00613 
00614   /* Reads value on the PCKT_FLT_GOALS_SOURCE_ADDR register */
00615   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_SOURCE_ADDR_BASE, 1, &tempRegValue);
00616 
00617   /* Return value */
00618   return tempRegValue;
00619 
00620 }
00621 
00622 
00623 /**
00624  * @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
00625  *         my address, then the packet is accepted (this is the address of the node).
00626  * @param  cAddress Address of the present node.
00627  *         This parameter is an uint8_t.
00628  * @retval None.
00629  */
00630 void SpiritPktCommonSetMyAddress(uint8_t cAddress)
00631 {
00632   /* Writes value on the PCKT_FLT_GOALS_TX_ADDR register */
00633   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_TX_ADDR_BASE, 1, &cAddress);
00634 
00635 }
00636 
00637 
00638 /**
00639  * @brief  Returns the address of the present node.
00640  * @param  None.
00641  * @retval uint8_t My address (address of this node).
00642  */
00643 uint8_t SpiritPktCommonGetMyAddress(void)
00644 {
00645   uint8_t tempRegValue;
00646 
00647   /* Reads value on the PCKT_FLT_GOALS_TX_ADDR register */
00648   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_TX_ADDR_BASE, 1, &tempRegValue);
00649 
00650   /* Return value */
00651   return tempRegValue;
00652 
00653 }
00654 
00655 
00656 /**
00657  * @brief  Sets the broadcast address. If the destination address extracted from the received packet is equal to the content of the
00658  *         BROADCAST_ADDR register, then the packet is accepted.
00659  * @param  cAddress Broadcast address.
00660  *         This parameter is an uint8_t.
00661  * @retval None.
00662  */
00663 void SpiritPktCommonSetBroadcastAddress(uint8_t cAddress)
00664 {
00665   /* Writes value on the PCKT_FLT_GOALS_BROADCAST register */
00666   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 1, &cAddress);
00667 
00668 }
00669 
00670 
00671 /**
00672  * @brief  Returns the broadcast address.
00673  * @param  None.
00674  * @retval uint8_t Broadcast address.
00675  */
00676 uint8_t SpiritPktCommonGetBroadcastAddress(void)
00677 {
00678   uint8_t tempRegValue;
00679 
00680   /* Reads value on the PCKT_FLT_GOALS_BROADCAST register */
00681   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_BROADCAST_BASE, 1, &tempRegValue);
00682 
00683   /* Return value */
00684   return tempRegValue;
00685 
00686 }
00687 
00688 
00689 /**
00690  * @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
00691  *         MULTICAST_ADDR register, then the packet is accepted.
00692  * @param  cAddress Multicast address.
00693  *         This parameter is an uint8_t.
00694  * @retval None.
00695  */
00696 void SpiritPktCommonSetMulticastAddress(uint8_t cAddress)
00697 {
00698   /* Writes value on the PCKT_FLT_GOALS_MULTICAST register */
00699   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_MULTICAST_BASE, 1, &cAddress);
00700 
00701 }
00702 
00703 
00704 /**
00705  * @brief  Returns the multicast address.
00706  * @param  None.
00707  * @retval uint8_t Multicast address.
00708  */
00709 uint8_t SpiritPktCommonGetMulticastAddress(void)
00710 {
00711   uint8_t tempRegValue;
00712 
00713   /* Reads value on the PCKT_FLT_GOALS_MULTICAST register */
00714   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_MULTICAST_BASE, 1, &tempRegValue);
00715 
00716   /* Return value */
00717   return tempRegValue;
00718 
00719 }
00720 
00721 
00722 /**
00723  * @brief  Sets the control mask. The 1 bits of the CONTROL_MASK indicate the
00724  *         bits to be used in filtering. (All 0s no filtering)
00725  * @param  lMask Control mask.
00726  *         This parameter is an uint32_t.
00727  * @retval None.
00728  */
00729 void SpiritPktCommonSetCtrlMask(uint32_t lMask)
00730 {
00731   uint8_t tempRegValue[4];
00732 
00733   /* Split the 32-bit value in 4 8-bit values */
00734   tempRegValue[0] = (uint8_t) lMask;
00735   tempRegValue[1] = (uint8_t)(lMask >> 8);
00736   tempRegValue[2] = (uint8_t)(lMask >> 16);
00737   tempRegValue[3] = (uint8_t)(lMask >> 24);
00738 
00739   /* Writes values on the CKT_FLT_GOALS_CONTROLx_MASK registers */
00740   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_CONTROL0_MASK_BASE, 4, tempRegValue);
00741 
00742 }
00743 
00744 
00745 /**
00746  * @brief  Returns the control mask. The 1 bits of the CONTROL_MASK indicate the
00747  *         bits to be used in filtering. (All 0s no filtering)
00748  * @param  None.
00749  * @retval uint32_t Control mask.
00750  */
00751 uint32_t SpiritPktCommonGetCtrlMask(void)
00752 {
00753   uint8_t tempRegValue[4];
00754   uint32_t tempRetValue=0;
00755 
00756   /* Reads the PCKT_FLT_GOALS_CONTROLx_MASK registers */
00757   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_CONTROL0_MASK_BASE, 4, tempRegValue);
00758 
00759   /* Rebuild the control mask value on a 32-bit integer variable */
00760   for(uint8_t i=0 ; i<4 ; i++)
00761   {
00762     tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*i);
00763   }
00764 
00765   /* Return value */
00766   return tempRetValue;
00767 }
00768 
00769 /**
00770  * @brief  Sets the control field reference. If the bits enabled by the CONTROL_MASK
00771  *         match the ones of the control fields extracted from the received packet
00772  *         then the packet is accepted.
00773  * @param  lReference Control reference.
00774  *         This parameter is an uint32_t.
00775  * @retval None.
00776  */
00777 void SpiritPktCommonSetCtrlReference(uint32_t lReference)
00778 {
00779   uint8_t tempRegValue[4];
00780 
00781   /* Split the 32-bit value in 4 8-bit values */
00782   tempRegValue[0] = (uint8_t) lReference;
00783   tempRegValue[1] = (uint8_t)(lReference >> 8);
00784   tempRegValue[2] = (uint8_t)(lReference >> 16);
00785   tempRegValue[3] = (uint8_t)(lReference >> 24);
00786 
00787   /* Writes values on the CKT_FLT_GOALS_CONTROLx_FIELD registers */
00788   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_GOALS_CONTROL0_FIELD_BASE, 4, tempRegValue);
00789 
00790 }
00791 
00792 
00793 /**
00794  * @brief  Returns the control field reference.
00795  * @param  None.
00796  * @retval uint32_t Control reference.
00797  */
00798 uint32_t SpiritPktCommonGetCtrlReference(void)
00799 {
00800   uint8_t tempRegValue[4];
00801   uint32_t tempRetValue=0;
00802 
00803   /* Reads the PCKT_FLT_GOALS_CONTROLx_FIELD registers */
00804   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_GOALS_CONTROL0_FIELD_BASE, 4, tempRegValue);
00805 
00806   /* Rebuild the control mask value on a 32-bit integer variable */
00807   for(uint8_t i=0 ; i<4 ; i++)
00808   {
00809     tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*i);
00810   }
00811 
00812   /* Return value */
00813   return tempRetValue;
00814 }
00815 
00816 
00817 /**
00818  * @brief  Sets the TX control field.
00819  * @param  lField Tx contro field.
00820  *         This parameter is an uint32_t.
00821  * @retval None.
00822  */
00823 void SpiritPktCommonSetTransmittedCtrlField(uint32_t lField)
00824 {
00825   uint8_t tempRegValue[4];
00826 
00827   /* Split the 32-bit value in 4 8-bit values */
00828   tempRegValue[3] = (uint8_t) lField;
00829   tempRegValue[2] = (uint8_t)(lField >> 8);
00830   tempRegValue[1] = (uint8_t)(lField >> 16);
00831   tempRegValue[0] = (uint8_t)(lField >> 24);
00832 
00833   /* Writes value on the TX_CTRL_FIELDx register */
00834   g_xStatus = SpiritSpiWriteRegisters(TX_CTRL_FIELD3_BASE, 4, tempRegValue);
00835 
00836 }
00837 
00838 
00839 /**
00840  * @brief  Returns the Tx control field.
00841  * @param  None.
00842  * @retval uint32_t Control field of the transmitted packet.
00843  */
00844 uint32_t SpiritPktCommonGetTransmittedCtrlField(void)
00845 {
00846   uint8_t tempRegValue[4];
00847   uint32_t tempRetValue=0;
00848 
00849   /* Reads the TX_CTRL_FIELDx registers */
00850   g_xStatus = SpiritSpiReadRegisters(TX_CTRL_FIELD3_BASE, 4, tempRegValue);
00851 
00852   /* Rebuild value: build a 32-bit value from the read bytes */
00853   for(uint8_t i=0 ; i<4 ; i++)
00854   {
00855     tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*(3-i));
00856   }
00857 
00858   /* Return value */
00859   return tempRetValue;
00860 
00861 }
00862 
00863 
00864 /**
00865  * @brief  If enabled RX packet is accepted if its destination address matches with My address.
00866  * @param  xNewState new state for DEST_VS_SOURCE_ADDRESS.
00867  *         This parameter can be S_ENABLE or S_DISABLE.
00868  * @retval None.
00869  */
00870 void SpiritPktCommonFilterOnMyAddress(SpiritFunctionalState xNewState)
00871 {
00872   uint8_t tempRegValue;
00873 
00874    /* Check the parameters */
00875   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
00876 
00877 
00878   /* Modify the register value: set or reset the TX source address control */
00879   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00880 
00881   /* Set or reset the DESTINATION vs TX enabling bit */
00882   if(xNewState == S_ENABLE)
00883   {
00884     tempRegValue |= PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
00885   }
00886   else
00887   {
00888     tempRegValue &= ~PCKT_FLT_OPTIONS_DEST_VS_TX_ADDR_MASK;
00889   }
00890 
00891   /* Writes the new value on the PCKT_FLT_OPTIONS register */
00892   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00893 
00894 }
00895 
00896 
00897 /**
00898  * @brief  If enabled RX packet is accepted if its destination address matches with multicast address.
00899  * @param  xNewState new state for DEST_VS_MULTICAST_ADDRESS.
00900  *         This parameter can be S_ENABLE or S_DISABLE.
00901  * @retval None.
00902  */
00903 void SpiritPktCommonFilterOnMulticastAddress(SpiritFunctionalState xNewState)
00904 {
00905   uint8_t tempRegValue;
00906 
00907   /* Check the parameters */
00908   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
00909 
00910   /* Reads the PCKT_FLT_OPTIONS register value */
00911   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00912 
00913   /* Enable or disable the filtering option */
00914   if(xNewState == S_ENABLE)
00915   {
00916     tempRegValue |= PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
00917   }
00918   else
00919   {
00920     tempRegValue &= ~PCKT_FLT_OPTIONS_DEST_VS_MULTICAST_ADDR_MASK;
00921   }
00922 
00923   /* Writes the new value on the PCKT_FLT_OPTIONS register */
00924   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00925 
00926 }
00927 
00928 
00929 /**
00930  * @brief  If enabled RX packet is accepted if its destination address matches with broadcast address.
00931  * @param  xNewState new state for DEST_VS_BROADCAST_ADDRESS.
00932  *         This parameter can be S_ENABLE or S_DISABLE.
00933  * @retval None.
00934  */
00935 void SpiritPktCommonFilterOnBroadcastAddress(SpiritFunctionalState xNewState)
00936 {
00937   uint8_t tempRegValue;
00938 
00939   /* Check the parameters */
00940   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
00941 
00942   /* Reads the register value */
00943   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00944 
00945   /* Enable or disable the filtering option */
00946   if(xNewState == S_ENABLE)
00947   {
00948     tempRegValue |= PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
00949   }
00950   else
00951   {
00952     tempRegValue &= ~PCKT_FLT_OPTIONS_DEST_VS_BROADCAST_ADDR_MASK;
00953   }
00954 
00955   /* Writes the new value on the PCKT_FLT_OPTIONS register */
00956   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00957 
00958 }
00959 
00960 
00961 /**
00962  * @brief  Returns the enable bit of the my address filtering.
00963  * @param  None.
00964  * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
00965  */
00966 SpiritFunctionalState SpiritPktCommonGetFilterOnMyAddress(void)
00967 {
00968   uint8_t tempRegValue;
00969 
00970   /* Reads the register value */
00971   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00972 
00973   /* Gets the enable/disable bit in form of SpiritFunctionalState type */
00974   if(tempRegValue & 0x08)
00975   {
00976     return S_ENABLE;
00977   }
00978   else
00979   {
00980     return S_DISABLE;
00981   }
00982 
00983 }
00984 
00985 /**
00986  * @brief  Returns the enable bit of the multicast address filtering.
00987  * @param  None.
00988  * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
00989  */
00990 SpiritFunctionalState SpiritPktCommonGetFilterOnMulticastAddress(void)
00991 {
00992   uint8_t tempRegValue;
00993 
00994   /* Reads the register value */
00995   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
00996 
00997   /* Get the enable/disable bit in form of SpiritFunctionalState type */
00998   if(tempRegValue & 0x04)
00999   {
01000     return S_ENABLE;
01001   }
01002   else
01003   {
01004     return S_DISABLE;
01005   }
01006 
01007 }
01008 
01009 /**
01010  * @brief  Returns the enable bit of the broadcast address filtering.
01011  * @param  None.
01012  * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
01013  */
01014 SpiritFunctionalState SpiritPktCommonGetFilterOnBroadcastAddress(void)
01015 {
01016   uint8_t tempRegValue;
01017 
01018   /* Reads the register value */
01019   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
01020 
01021   /* Get the enable/disable bit in form of SpiritFunctionalState type */
01022   if(tempRegValue & 0x02)
01023   {
01024     return S_ENABLE;
01025   }
01026   else
01027   {
01028     return S_DISABLE;
01029   }
01030 
01031 }
01032 
01033 
01034 /**
01035  * @brief  Returns the destination address of the received packet.
01036  * @param  None.
01037  * @retval uint8_t Destination address of the received address.
01038  */
01039 uint8_t SpiritPktCommonGetReceivedDestAddress(void)
01040 {
01041   uint8_t tempRegValue;
01042 
01043   /* Reads the RX_ADDR_FIELD0 register value */
01044   g_xStatus = SpiritSpiReadRegisters(RX_ADDR_FIELD0_BASE, 1, &tempRegValue);
01045 
01046   /* Return value */
01047   return tempRegValue;
01048 
01049 }
01050 
01051 
01052 /**
01053  * @brief  Returns the control field of the received packet.
01054  * @param  None.
01055  * @retval uint32_t Received control field.
01056  */
01057 uint32_t SpiritPktCommonGetReceivedCtrlField(void)
01058 {
01059   uint8_t tempRegValue[4];
01060   uint32_t tempRetValue=0;
01061 
01062   /* Reads the PCKT_FLT_GOALS_CONTROLx_MASK registers */
01063   g_xStatus = SpiritSpiReadRegisters(RX_CTRL_FIELD0_BASE, 4, tempRegValue);
01064 
01065   /* Rebuild the control mask value on a 32-bit integer variable */
01066   for(uint8_t i=0 ; i<4 ; i++)
01067   {
01068     tempRetValue |= ((uint32_t)tempRegValue[i])<<(8*i);
01069   }
01070 
01071   /* Returns value */
01072   return tempRetValue;
01073 }
01074 
01075 
01076 /**
01077  * @brief  Returns the CRC field of the received packet.
01078  * @param  cCrcFieldVect array in which the CRC field has to be stored.
01079  *         This parameter is an uint8_t array of 3 elements.
01080  * @retval None.
01081  */
01082 void SpiritPktCommonGetReceivedCrcField(uint8_t* cCrcFieldVect)
01083 {
01084   uint8_t tempRegValue[3],crcLength;
01085   PktCrcMode crcMode;
01086   
01087   /* Gets the CRC mode in PktCrcMode enum */
01088   crcMode=SpiritPktCommonGetCrcMode();
01089   
01090   /* Cast to uint8_t */
01091   crcLength = (uint8_t)crcMode;
01092   
01093   /* Obtains the real length: see the @ref PktCrcMode enumeration */
01094   crcLength >>= 5;
01095   if(crcLength>=3) crcLength--;
01096   
01097   /* Reads the CRC_FIELDx registers value */
01098   g_xStatus = SpiritSpiReadRegisters(CRC_FIELD2_BASE, 3,tempRegValue);
01099   
01100   /* Sets the array to be returned */
01101   for(uint8_t i=0 ; i<3 ; i++)
01102   {
01103     if(i<crcLength) 
01104     {
01105       cCrcFieldVect[i]=tempRegValue[2-i];
01106     }
01107     else 
01108     {
01109       cCrcFieldVect[i]=0;
01110     }
01111   }
01112   
01113 }
01114 
01115 
01116 /**
01117  * @brief  Sets the AUTO ACKNOLEDGEMENT mechanism on the receiver. When the feature is enabled and
01118  *         a data packet has been correctly received, then an acknowledgement packet is sent back to the originator of the received
01119  *         packet. If the PIGGYBACKING bit is also set, payload data will be read from the FIFO; otherwise an empty packet is sent
01120  *         only containing the source and destination addresses and the sequence number of the packet being acknowledged.
01121  * @param  xAutoAck new state for autoack.
01122  *         This parameter can be: S_ENABLE or S_DISABLE.
01123  * @param  xPiggybacking new state for autoack.
01124  *         This parameter can be: S_ENABLE or S_DISABLE.
01125  * @retval None.
01126  */
01127 void SpiritPktCommonAutoAck(SpiritFunctionalState xAutoAck , SpiritFunctionalState xPiggybacking)
01128 {
01129   uint8_t tempRegValue[2];
01130 
01131   /* Check the parameters */
01132   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xAutoAck));
01133   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xPiggybacking));
01134   /* Check if piggybacking is enabled and autoack is disabled */
01135   s_assert_param(!(xPiggybacking==S_ENABLE && xAutoAck==S_DISABLE));
01136 
01137   /* Reads the PROTOCOL[1:0] registers value */
01138   g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 2, tempRegValue);
01139 
01140   /* Sets the specified LLP option */
01141   /* Autoack setting */
01142   if(xAutoAck == S_ENABLE)
01143   {
01144     tempRegValue[1] |= PROTOCOL0_AUTO_ACK_MASK;
01145   }
01146   else
01147   {
01148     tempRegValue[1] &= (~PROTOCOL0_AUTO_ACK_MASK);
01149   }
01150 
01151   /* Piggybacking setting */
01152   if(xPiggybacking == S_ENABLE)
01153   {
01154     tempRegValue[0] |= PROTOCOL1_PIGGYBACKING_MASK;
01155   }
01156   else
01157   {
01158     tempRegValue[0] &= (~PROTOCOL1_PIGGYBACKING_MASK);
01159   }
01160 
01161   /* Writes data on the PROTOCOL[1:0] registers */
01162   g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 2, tempRegValue);
01163 
01164 }
01165 
01166 
01167 /**
01168  * @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
01169  *         NACK_TX is set to "1" then acknowledgment will not be required; if NACK_TX is set to "0" then acknowledgment will be
01170  *         required.
01171  * @param  xNewState new state for TX_AUTOACK.
01172  *         This parameter can be: S_ENABLE or S_DISABLE.
01173  * @retval None.
01174  */
01175 void SpiritPktCommonRequireAck(SpiritFunctionalState xNewState)
01176 {
01177   uint8_t tempRegValue;
01178 
01179   /* Check the parameters */
01180   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
01181 
01182   /* Reads value on the PROTOCOL0 register */
01183   g_xStatus = SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
01184 
01185   /* Enables or disables the ack requirement option */
01186   if(xNewState == S_DISABLE)
01187   {
01188     tempRegValue |= PROTOCOL0_NACK_TX_MASK;
01189   }
01190   else
01191   {
01192     tempRegValue &= ~PROTOCOL0_NACK_TX_MASK;
01193   }
01194 
01195   /* Writes value on the PROTOCOL0 register */
01196   g_xStatus = SpiritSpiWriteRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
01197 
01198 }
01199 
01200 
01201 /**
01202  * @brief  Sets the TX sequence number to be used to start counting.
01203  * @param  cSeqNumberReload new value for Tx seq number reload.
01204  * @retval None.
01205  */
01206 void SpiritPktCommonSetTransmittedSeqNumberReload(uint8_t cSeqNumberReload){
01207   uint8_t tempRegValue;
01208 
01209   /* Check the parameters */
01210   s_assert_param(IS_PKT_SEQ_NUMBER_RELOAD(cSeqNumberReload));
01211 
01212   /* Reads value on the PROTOCOL2 register */
01213   g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
01214 
01215   tempRegValue &= 0xE7;
01216   tempRegValue |= (cSeqNumberReload << 3);
01217 
01218   /* Writes value on the PROTOCOL2 register */
01219   g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
01220 
01221 }
01222 
01223 
01224 /**
01225  * @brief  Sets the TX sequence number to be used to start counting.
01226  * @param  cSeqNumberReload new value for Tx seq number reload.
01227  *         This parameter can be: S_ENABLE or S_DISABLE.
01228  * @retval None.
01229  */
01230 void SpiritPktCommonSetNMaxReTx(PktNMaxReTx xNMaxReTx)
01231 {
01232   uint8_t tempRegValue;
01233 
01234   /* Check the parameters */
01235   s_assert_param(IS_PKT_NMAX_RETX(xNMaxReTx));
01236 
01237   /* Reads the PROTOCOL0 register value */
01238   g_xStatus = SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
01239 
01240   /* Build the value to be written */
01241   tempRegValue &= ~PROTOCOL0_NMAX_RETX_MASK;
01242   tempRegValue |= xNMaxReTx;
01243 
01244   /* Writes value on the PROTOCOL0 register */
01245   g_xStatus = SpiritSpiWriteRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
01246 
01247 }
01248 
01249 
01250 /**
01251  * @brief  Returns the max number of automatic retransmission.
01252  * @param  None.
01253  * @retval uint8_t Max number of retransmissions.
01254  *         This parameter is an uint8_t.
01255  */
01256 uint8_t SpiritPktCommonGetNMaxReTx(void)
01257 {
01258   uint8_t tempRegValue;
01259 
01260   /* Reads the PROTOCOL0 register value */
01261   g_xStatus = SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
01262 
01263   /* Build the value to be written */
01264   return ((tempRegValue & PROTOCOL0_NMAX_RETX_MASK)>>4);
01265 
01266 }
01267 
01268 /**
01269  * @brief  Returns the TX ACK request
01270  * @param  None.
01271  * @retval uint8_t Max number of retransmissions.
01272  *         This parameter is an uint8_t.
01273  */
01274 SpiritFunctionalState SpiritPktCommonGetTxAckRequest(void)
01275 {
01276   uint8_t tempRegValue;
01277 
01278   /* Reads the PROTOCOL0 register value */
01279   g_xStatus = SpiritSpiReadRegisters(RX_PCKT_INFO_BASE, 1, &tempRegValue);
01280 
01281   /* Build the value to be written */
01282   return (SpiritFunctionalState)((tempRegValue & TX_PCKT_INFO_NACK_RX)>>2);
01283 
01284 }
01285    
01286    
01287 /**
01288  * @brief  Returns the source address of the received packet.
01289  * @param  None.
01290  * @retval uint8_t Source address of the received packet.
01291  */
01292 uint8_t SpiritPktCommonGetReceivedSourceAddress(void)
01293 {
01294   uint8_t tempRegValue;
01295 
01296   /* Reads the RX_ADDR_FIELD1 register value */
01297   g_xStatus = SpiritSpiReadRegisters(RX_ADDR_FIELD1_BASE, 1, &tempRegValue);
01298 
01299   /* Returns value */
01300   return tempRegValue;
01301 
01302 }
01303 
01304 
01305 /**
01306  * @brief  Returns the sequence number of the received packet.
01307  * @param  None.
01308  * @retval uint8_t Received Sequence number.
01309  */
01310 uint8_t SpiritPktCommonGetReceivedSeqNumber(void)
01311 {
01312   uint8_t tempRegValue;
01313 
01314   /* Reads the RX_PCKT_INFO register value */
01315   g_xStatus = SpiritSpiReadRegisters(RX_PCKT_INFO_BASE, 1, &tempRegValue);
01316 
01317   /* Obtains and returns the sequence number */
01318   return tempRegValue & 0x03;
01319 
01320 }
01321 
01322 
01323 /**
01324  * @brief  Returns the Nack bit of the received packet
01325  * @param  None.
01326  * @retval uint8_t Value of the Nack bit.
01327  */
01328 uint8_t SpiritPktCommonGetReceivedNackRx(void)
01329 {
01330   uint8_t tempRegValue;
01331 
01332   /* Reads the RX_PCKT_INFO register value */
01333   g_xStatus = SpiritSpiReadRegisters(RX_PCKT_INFO_BASE, 1, &tempRegValue);
01334 
01335   /* Obtains and returns the RX nack bit */
01336   return (tempRegValue >> 2) & 0x01;
01337 
01338 }
01339 
01340 
01341 /**
01342  * @brief  Returns the sequence number of the transmitted packet.
01343  * @param  None.
01344  * @retval uint8_t Sequence number of the transmitted packet.
01345  */
01346 uint8_t SpiritPktCommonGetTransmittedSeqNumber(void)
01347 {
01348   uint8_t tempRegValue;
01349 
01350   /* Reads the TX_PCKT_INFO register value */
01351   g_xStatus = SpiritSpiReadRegisters(TX_PCKT_INFO_BASE, 1, &tempRegValue);
01352 
01353   /* Obtains and returns the TX sequence number */
01354   return (tempRegValue >> 4) & 0x07;
01355 
01356 }
01357 
01358 
01359 /**
01360  * @brief  Returns the number of retransmission done on the transmitted packet.
01361  * @param  None.
01362  * @retval uint8_t Number of retransmissions done until now.
01363  */
01364 uint8_t SpiritPktCommonGetNReTx(void)
01365 {
01366   uint8_t tempRetValue;
01367 
01368   /* Reads the TX_PCKT_INFO register value */
01369   g_xStatus = SpiritSpiReadRegisters(TX_PCKT_INFO_BASE, 1, &tempRetValue);
01370 
01371   /* Obtains and returns the number of retransmission done */
01372   return (tempRetValue & 0x0F);
01373 
01374 }
01375 
01376 
01377 /**
01378  * @brief  If enabled RX packet is accepted only if the masked control field matches the
01379  *         masked control field reference (CONTROL_MASK & CONTROL_FIELD_REF == CONTROL_MASK & RX_CONTROL_FIELD).
01380  * @param  xNewState new state for Control filtering enable bit.
01381  *         This parameter can be S_ENABLE or S_DISABLE.
01382  * @retval None.
01383  * @note   This filtering control is enabled by default but the control mask is by default set to 0.
01384  *         As a matter of fact the user has to enable the control filtering bit after the packet initialization
01385  *         because the PktInit routine disables it.
01386  */
01387 void SpiritPktCommonFilterOnControlField(SpiritFunctionalState xNewState)
01388 {
01389   uint8_t tempRegValue;
01390 
01391    /* Check the parameters */
01392   s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
01393 
01394 
01395   /* Modify the register value: set or reset the control bit filtering */
01396   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
01397 
01398   /* Set or reset the CONTROL filtering enabling bit */
01399   if(xNewState == S_ENABLE)
01400   {
01401     tempRegValue |= PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK;
01402   }
01403   else
01404   {
01405     tempRegValue &= ~PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK;
01406   }
01407 
01408   /* Writes the new value on the PCKT_FLT_OPTIONS register */
01409   g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
01410 
01411 }
01412 
01413 
01414 /**
01415  * @brief  Returns the enable bit of the control field filtering.
01416  * @param  None.
01417  * @retval SpiritFunctionalState This parameter can be S_ENABLE or S_DISABLE.
01418  */
01419 SpiritFunctionalState SpiritPktCommonGetFilterOnControlField(void)
01420 {
01421   uint8_t tempRegValue;
01422 
01423   /* Reads the register value */
01424   g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 1, &tempRegValue);
01425 
01426   /* Gets the enable/disable bit in form of SpiritFunctionalState type */
01427   if(tempRegValue & PCKT_FLT_OPTIONS_CONTROL_FILTERING_MASK)
01428   {
01429     return S_ENABLE;
01430   }
01431   else
01432   {
01433     return S_DISABLE;
01434   }
01435 
01436 }
01437 
01438 
01439 /**
01440  *@}
01441  */
01442 
01443 /**
01444  *@}
01445  */
01446 
01447 
01448 /**
01449  *@}
01450  */
01451 
01452 
01453 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/