Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 /**
vpcola 0:f1d3878b8dd9 2 ******************************************************************************
vpcola 0:f1d3878b8dd9 3 * @file SPIRIT_PktMbus.c
vpcola 0:f1d3878b8dd9 4 * @author VMA division - AMS
vpcola 0:f1d3878b8dd9 5 * @version 3.2.2
vpcola 0:f1d3878b8dd9 6 * @date 08-July-2015
vpcola 0:f1d3878b8dd9 7 * @brief Configuration and management of SPIRIT MBUS packets.
vpcola 0:f1d3878b8dd9 8 * @details
vpcola 0:f1d3878b8dd9 9 *
vpcola 0:f1d3878b8dd9 10 * @attention
vpcola 0:f1d3878b8dd9 11 *
vpcola 0:f1d3878b8dd9 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
vpcola 0:f1d3878b8dd9 13 *
vpcola 0:f1d3878b8dd9 14 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:f1d3878b8dd9 15 * are permitted provided that the following conditions are met:
vpcola 0:f1d3878b8dd9 16 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:f1d3878b8dd9 17 * this list of conditions and the following disclaimer.
vpcola 0:f1d3878b8dd9 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:f1d3878b8dd9 19 * this list of conditions and the following disclaimer in the documentation
vpcola 0:f1d3878b8dd9 20 * and/or other materials provided with the distribution.
vpcola 0:f1d3878b8dd9 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:f1d3878b8dd9 22 * may be used to endorse or promote products derived from this software
vpcola 0:f1d3878b8dd9 23 * without specific prior written permission.
vpcola 0:f1d3878b8dd9 24 *
vpcola 0:f1d3878b8dd9 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:f1d3878b8dd9 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:f1d3878b8dd9 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:f1d3878b8dd9 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:f1d3878b8dd9 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:f1d3878b8dd9 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:f1d3878b8dd9 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:f1d3878b8dd9 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:f1d3878b8dd9 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:f1d3878b8dd9 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:f1d3878b8dd9 35 *
vpcola 0:f1d3878b8dd9 36 ******************************************************************************
vpcola 0:f1d3878b8dd9 37 */
vpcola 0:f1d3878b8dd9 38
vpcola 0:f1d3878b8dd9 39 /* Includes ------------------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 40 #include "SPIRIT_PktMbus.h"
vpcola 0:f1d3878b8dd9 41 #include "SPIRIT_Radio.h"
vpcola 0:f1d3878b8dd9 42 #include "MCU_Interface.h"
vpcola 0:f1d3878b8dd9 43
vpcola 0:f1d3878b8dd9 44 /**
vpcola 0:f1d3878b8dd9 45 * @addtogroup SPIRIT_Libraries
vpcola 0:f1d3878b8dd9 46 * @{
vpcola 0:f1d3878b8dd9 47 */
vpcola 0:f1d3878b8dd9 48
vpcola 0:f1d3878b8dd9 49
vpcola 0:f1d3878b8dd9 50 /**
vpcola 0:f1d3878b8dd9 51 * @addtogroup SPIRIT_PktMbus
vpcola 0:f1d3878b8dd9 52 * @{
vpcola 0:f1d3878b8dd9 53 */
vpcola 0:f1d3878b8dd9 54
vpcola 0:f1d3878b8dd9 55
vpcola 0:f1d3878b8dd9 56 /**
vpcola 0:f1d3878b8dd9 57 * @defgroup PktMbus_Private_TypesDefinitions Pkt MBUS Private Types Definitions
vpcola 0:f1d3878b8dd9 58 * @{
vpcola 0:f1d3878b8dd9 59 */
vpcola 0:f1d3878b8dd9 60
vpcola 0:f1d3878b8dd9 61 /**
vpcola 0:f1d3878b8dd9 62 *@}
vpcola 0:f1d3878b8dd9 63 */
vpcola 0:f1d3878b8dd9 64
vpcola 0:f1d3878b8dd9 65
vpcola 0:f1d3878b8dd9 66 /**
vpcola 0:f1d3878b8dd9 67 * @defgroup PktMbus_Private_Defines Pkt MBUS Private Defines
vpcola 0:f1d3878b8dd9 68 * @{
vpcola 0:f1d3878b8dd9 69 */
vpcola 0:f1d3878b8dd9 70
vpcola 0:f1d3878b8dd9 71 /**
vpcola 0:f1d3878b8dd9 72 *@}
vpcola 0:f1d3878b8dd9 73 */
vpcola 0:f1d3878b8dd9 74
vpcola 0:f1d3878b8dd9 75
vpcola 0:f1d3878b8dd9 76 /**
vpcola 0:f1d3878b8dd9 77 * @defgroup PktMbus_Private_Macros Pkt MBUS Private Macros
vpcola 0:f1d3878b8dd9 78 * @{
vpcola 0:f1d3878b8dd9 79 */
vpcola 0:f1d3878b8dd9 80
vpcola 0:f1d3878b8dd9 81 /**
vpcola 0:f1d3878b8dd9 82 *@}
vpcola 0:f1d3878b8dd9 83 */
vpcola 0:f1d3878b8dd9 84
vpcola 0:f1d3878b8dd9 85
vpcola 0:f1d3878b8dd9 86 /**
vpcola 0:f1d3878b8dd9 87 * @defgroup PktMbus_Private_Variables Pkt MBUS Private Variables
vpcola 0:f1d3878b8dd9 88 * @{
vpcola 0:f1d3878b8dd9 89 */
vpcola 0:f1d3878b8dd9 90
vpcola 0:f1d3878b8dd9 91 /**
vpcola 0:f1d3878b8dd9 92 *@}
vpcola 0:f1d3878b8dd9 93 */
vpcola 0:f1d3878b8dd9 94
vpcola 0:f1d3878b8dd9 95
vpcola 0:f1d3878b8dd9 96 /**
vpcola 0:f1d3878b8dd9 97 * @defgroup PktMbus_Private_FunctionPrototypes Pkt MBUS Private Function Prototypes
vpcola 0:f1d3878b8dd9 98 * @{
vpcola 0:f1d3878b8dd9 99 */
vpcola 0:f1d3878b8dd9 100
vpcola 0:f1d3878b8dd9 101 /**
vpcola 0:f1d3878b8dd9 102 *@}
vpcola 0:f1d3878b8dd9 103 */
vpcola 0:f1d3878b8dd9 104
vpcola 0:f1d3878b8dd9 105
vpcola 0:f1d3878b8dd9 106 /**
vpcola 0:f1d3878b8dd9 107 * @defgroup PktMbus_Private_Functions Pkt MBUS Private Functions
vpcola 0:f1d3878b8dd9 108 * @{
vpcola 0:f1d3878b8dd9 109 */
vpcola 0:f1d3878b8dd9 110
vpcola 0:f1d3878b8dd9 111
vpcola 0:f1d3878b8dd9 112 /**
vpcola 0:f1d3878b8dd9 113 * @brief Initializes the SPIRIT MBUS packet according to the specified parameters in the PktMbusInit struct.
vpcola 0:f1d3878b8dd9 114 * @param pxPktMbusInit pointer to a PktMbusInit structure that contains the configuration information for the specified SPIRIT MBUS PACKET FORMAT.
vpcola 0:f1d3878b8dd9 115 * This parameter is a pointer to @ref PktMbusInit.
vpcola 0:f1d3878b8dd9 116 * @retval None.
vpcola 0:f1d3878b8dd9 117 */
vpcola 0:f1d3878b8dd9 118 void SpiritPktMbusInit(PktMbusInit* pxPktMbusInit)
vpcola 0:f1d3878b8dd9 119 {
vpcola 0:f1d3878b8dd9 120 uint8_t tempRegValue[3];
vpcola 0:f1d3878b8dd9 121
vpcola 0:f1d3878b8dd9 122 /* Check the parameters */
vpcola 0:f1d3878b8dd9 123 s_assert_param(IS_MBUS_SUBMODE(pxPktMbusInit->xMbusSubmode));
vpcola 0:f1d3878b8dd9 124
vpcola 0:f1d3878b8dd9 125 /* Packet format config */
vpcola 0:f1d3878b8dd9 126 SpiritPktMbusSetFormat();
vpcola 0:f1d3878b8dd9 127 SpiritPktCommonFilterOnCrc(S_DISABLE);
vpcola 0:f1d3878b8dd9 128 SpiritRadioCsBlanking(S_ENABLE);
vpcola 0:f1d3878b8dd9 129
vpcola 0:f1d3878b8dd9 130 /* Preamble, postamble and submode config */
vpcola 0:f1d3878b8dd9 131 tempRegValue[0] = pxPktMbusInit->cPreambleLength;
vpcola 0:f1d3878b8dd9 132 tempRegValue[1] = pxPktMbusInit->cPostambleLength;
vpcola 0:f1d3878b8dd9 133 tempRegValue[2] = (uint8_t) pxPktMbusInit->xMbusSubmode;
vpcola 0:f1d3878b8dd9 134
vpcola 0:f1d3878b8dd9 135 /* Writes the new values on the MBUS_PRMBL registers */
vpcola 0:f1d3878b8dd9 136 g_xStatus = SpiritSpiWriteRegisters(MBUS_PRMBL_BASE, 3, tempRegValue);
vpcola 0:f1d3878b8dd9 137
vpcola 0:f1d3878b8dd9 138 }
vpcola 0:f1d3878b8dd9 139
vpcola 0:f1d3878b8dd9 140 /**
vpcola 0:f1d3878b8dd9 141 * @brief Returns the SPIRIT MBUS packet structure according to the specified parameters in the registers.
vpcola 0:f1d3878b8dd9 142 * @param pxPktMbusInit MBUS packet init structure.
vpcola 0:f1d3878b8dd9 143 * This parameter is a pointer to @ref PktMbusInit.
vpcola 0:f1d3878b8dd9 144 * @retval None.
vpcola 0:f1d3878b8dd9 145 */
vpcola 0:f1d3878b8dd9 146 void SpiritPktMbusGetInfo(PktMbusInit* pxPktMbusInit)
vpcola 0:f1d3878b8dd9 147 {
vpcola 0:f1d3878b8dd9 148 uint8_t tempRegValue[3];
vpcola 0:f1d3878b8dd9 149
vpcola 0:f1d3878b8dd9 150 /* Reads the MBUS regs value */
vpcola 0:f1d3878b8dd9 151 g_xStatus = SpiritSpiReadRegisters(MBUS_PRMBL_BASE, 3, tempRegValue);
vpcola 0:f1d3878b8dd9 152
vpcola 0:f1d3878b8dd9 153 /* Fit the structure */
vpcola 0:f1d3878b8dd9 154 pxPktMbusInit->cPreambleLength = tempRegValue[0];
vpcola 0:f1d3878b8dd9 155 pxPktMbusInit->cPostambleLength = tempRegValue[1];
vpcola 0:f1d3878b8dd9 156 pxPktMbusInit->xMbusSubmode = (MbusSubmode) (tempRegValue[2]&0x0E);
vpcola 0:f1d3878b8dd9 157
vpcola 0:f1d3878b8dd9 158 }
vpcola 0:f1d3878b8dd9 159
vpcola 0:f1d3878b8dd9 160
vpcola 0:f1d3878b8dd9 161 /**
vpcola 0:f1d3878b8dd9 162 * @brief Configures the MBUS packet format as the one used by SPIRIT.
vpcola 0:f1d3878b8dd9 163 * @param None.
vpcola 0:f1d3878b8dd9 164 * @retval None.
vpcola 0:f1d3878b8dd9 165 */
vpcola 0:f1d3878b8dd9 166 void SpiritPktMbusSetFormat(void)
vpcola 0:f1d3878b8dd9 167 {
vpcola 0:f1d3878b8dd9 168 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 169
vpcola 0:f1d3878b8dd9 170 /* Reads the PCKTCTRL3 register value */
vpcola 0:f1d3878b8dd9 171 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 172
vpcola 0:f1d3878b8dd9 173 /* Sets format bits. Also set to 0 the direct RX mode bits */
vpcola 0:f1d3878b8dd9 174 tempRegValue &= 0x0F;
vpcola 0:f1d3878b8dd9 175 tempRegValue |= ((uint8_t)PCKTCTRL3_PCKT_FRMT_MBUS);
vpcola 0:f1d3878b8dd9 176
vpcola 0:f1d3878b8dd9 177 /* Writes value on the PCKTCTRL3 register */
vpcola 0:f1d3878b8dd9 178 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 179
vpcola 0:f1d3878b8dd9 180 /* Reads the PCKTCTRL1 register value */
vpcola 0:f1d3878b8dd9 181 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 182
vpcola 0:f1d3878b8dd9 183 /* Build the new value. Set to 0 the direct TX mode bits */
vpcola 0:f1d3878b8dd9 184 tempRegValue &= 0xF3;
vpcola 0:f1d3878b8dd9 185
vpcola 0:f1d3878b8dd9 186 /* Writes the value on the PCKTCTRL1 register */
vpcola 0:f1d3878b8dd9 187 g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 188
vpcola 0:f1d3878b8dd9 189 /* Reads the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 190 g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 191
vpcola 0:f1d3878b8dd9 192 /* Mask a reserved bit */
vpcola 0:f1d3878b8dd9 193 tempRegValue &= ~0x20;
vpcola 0:f1d3878b8dd9 194
vpcola 0:f1d3878b8dd9 195 /* Writes the value on the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 196 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 197
vpcola 0:f1d3878b8dd9 198 }
vpcola 0:f1d3878b8dd9 199
vpcola 0:f1d3878b8dd9 200
vpcola 0:f1d3878b8dd9 201 /**
vpcola 0:f1d3878b8dd9 202 * @brief Sets how many chip sequence “01” shall be added in the preamble
vpcola 0:f1d3878b8dd9 203 * respect to the minimum value as defined according to the specified sub-mode.
vpcola 0:f1d3878b8dd9 204 * @param cPreamble the number of chip sequence.
vpcola 0:f1d3878b8dd9 205 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 206 * @retval None.
vpcola 0:f1d3878b8dd9 207 */
vpcola 0:f1d3878b8dd9 208 void SpiritPktMbusSetPreamble(uint8_t cPreamble)
vpcola 0:f1d3878b8dd9 209 {
vpcola 0:f1d3878b8dd9 210 /* Modifies the MBUS_PRMBL register value */
vpcola 0:f1d3878b8dd9 211 g_xStatus = SpiritSpiWriteRegisters(MBUS_PRMBL_BASE, 1, &cPreamble);
vpcola 0:f1d3878b8dd9 212
vpcola 0:f1d3878b8dd9 213 }
vpcola 0:f1d3878b8dd9 214
vpcola 0:f1d3878b8dd9 215
vpcola 0:f1d3878b8dd9 216 /**
vpcola 0:f1d3878b8dd9 217 * @brief Returns how many chip sequence "01" are added in the preamble
vpcola 0:f1d3878b8dd9 218 * respect to the minimum value as defined according to the specified sub-mode.
vpcola 0:f1d3878b8dd9 219 * @param None.
vpcola 0:f1d3878b8dd9 220 * @retval uint8_t Preable in number of "01" chip sequences.
vpcola 0:f1d3878b8dd9 221 */
vpcola 0:f1d3878b8dd9 222 uint8_t SpiritPktMbusGetPreamble(void)
vpcola 0:f1d3878b8dd9 223 {
vpcola 0:f1d3878b8dd9 224 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 225
vpcola 0:f1d3878b8dd9 226 /* Modifies the MBUS_PRMBL register value */
vpcola 0:f1d3878b8dd9 227 g_xStatus = SpiritSpiReadRegisters(MBUS_PRMBL_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 228
vpcola 0:f1d3878b8dd9 229 /* Return value */
vpcola 0:f1d3878b8dd9 230 return tempRegValue;
vpcola 0:f1d3878b8dd9 231
vpcola 0:f1d3878b8dd9 232 }
vpcola 0:f1d3878b8dd9 233
vpcola 0:f1d3878b8dd9 234
vpcola 0:f1d3878b8dd9 235 /**
vpcola 0:f1d3878b8dd9 236 * @brief Sets how many chip sequence “01” will be used in postamble
vpcola 0:f1d3878b8dd9 237 * @param cPostamble the number of chip sequence.
vpcola 0:f1d3878b8dd9 238 * This parameter is an uint8_t.
vpcola 0:f1d3878b8dd9 239 * @retval None.
vpcola 0:f1d3878b8dd9 240 */
vpcola 0:f1d3878b8dd9 241 void SpiritPktMbusSetPostamble(uint8_t cPostamble)
vpcola 0:f1d3878b8dd9 242 {
vpcola 0:f1d3878b8dd9 243 /* Modifies the MBUS_PSTMBL register value */
vpcola 0:f1d3878b8dd9 244 g_xStatus = SpiritSpiWriteRegisters(MBUS_PSTMBL_BASE, 1, &cPostamble);
vpcola 0:f1d3878b8dd9 245
vpcola 0:f1d3878b8dd9 246 }
vpcola 0:f1d3878b8dd9 247
vpcola 0:f1d3878b8dd9 248
vpcola 0:f1d3878b8dd9 249 /**
vpcola 0:f1d3878b8dd9 250 * @brief Returns how many chip sequence "01" are used in the postamble
vpcola 0:f1d3878b8dd9 251 * @param None.
vpcola 0:f1d3878b8dd9 252 * @retval uint8_t Postamble in number of "01" chip sequences.
vpcola 0:f1d3878b8dd9 253 */
vpcola 0:f1d3878b8dd9 254 uint8_t SpiritPktMbusGetPostamble(void)
vpcola 0:f1d3878b8dd9 255 {
vpcola 0:f1d3878b8dd9 256 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 257
vpcola 0:f1d3878b8dd9 258 /* Reads the MBUS_PSTMBL register */
vpcola 0:f1d3878b8dd9 259 g_xStatus = SpiritSpiReadRegisters(MBUS_PSTMBL_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 260
vpcola 0:f1d3878b8dd9 261 /* Returns value */
vpcola 0:f1d3878b8dd9 262 return tempRegValue;
vpcola 0:f1d3878b8dd9 263
vpcola 0:f1d3878b8dd9 264 }
vpcola 0:f1d3878b8dd9 265
vpcola 0:f1d3878b8dd9 266
vpcola 0:f1d3878b8dd9 267 /**
vpcola 0:f1d3878b8dd9 268 * @brief Sets the MBUS submode used.
vpcola 0:f1d3878b8dd9 269 * @param xMbusSubmode the submode used.
vpcola 0:f1d3878b8dd9 270 * This parameter can be any value of @ref MbusSubmode.
vpcola 0:f1d3878b8dd9 271 * @retval None.
vpcola 0:f1d3878b8dd9 272 */
vpcola 0:f1d3878b8dd9 273 void SpiritPktMbusSetSubmode(MbusSubmode xMbusSubmode)
vpcola 0:f1d3878b8dd9 274 {
vpcola 0:f1d3878b8dd9 275 /* Modifies the MBUS_CTRL register value */
vpcola 0:f1d3878b8dd9 276 g_xStatus = SpiritSpiWriteRegisters(MBUS_CTRL_BASE, 1, (uint8_t*)xMbusSubmode);
vpcola 0:f1d3878b8dd9 277
vpcola 0:f1d3878b8dd9 278 }
vpcola 0:f1d3878b8dd9 279
vpcola 0:f1d3878b8dd9 280
vpcola 0:f1d3878b8dd9 281 /**
vpcola 0:f1d3878b8dd9 282 * @brief Returns the MBUS submode used.
vpcola 0:f1d3878b8dd9 283 * @param None.
vpcola 0:f1d3878b8dd9 284 * @retval MbusSubmode MBUS submode.
vpcola 0:f1d3878b8dd9 285 */
vpcola 0:f1d3878b8dd9 286 MbusSubmode SpiritPktMbusGetSubmode(void)
vpcola 0:f1d3878b8dd9 287 {
vpcola 0:f1d3878b8dd9 288 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 289
vpcola 0:f1d3878b8dd9 290 /* Reads the MBUS_CTRL register value */
vpcola 0:f1d3878b8dd9 291 g_xStatus = SpiritSpiReadRegisters(MBUS_CTRL_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 292
vpcola 0:f1d3878b8dd9 293 /* Returns value */
vpcola 0:f1d3878b8dd9 294 return (MbusSubmode) tempRegValue;
vpcola 0:f1d3878b8dd9 295
vpcola 0:f1d3878b8dd9 296 }
vpcola 0:f1d3878b8dd9 297
vpcola 0:f1d3878b8dd9 298
vpcola 0:f1d3878b8dd9 299 /**
vpcola 0:f1d3878b8dd9 300 * @brief Sets the payload length for SPIRIT MBUS packets.
vpcola 0:f1d3878b8dd9 301 * @param nPayloadLength payload length in bytes.
vpcola 0:f1d3878b8dd9 302 * This parameter is an uint16_t.
vpcola 0:f1d3878b8dd9 303 * @retval None.
vpcola 0:f1d3878b8dd9 304 */
vpcola 0:f1d3878b8dd9 305 void SpiritPktMbusSetPayloadLength(uint16_t nPayloadLength)
vpcola 0:f1d3878b8dd9 306 {
vpcola 0:f1d3878b8dd9 307 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 308
vpcola 0:f1d3878b8dd9 309 /* Computes PCKTLEN0 value from nPayloadLength */
vpcola 0:f1d3878b8dd9 310 tempRegValue[1]=BUILD_PCKTLEN0(nPayloadLength);//(uint8_t)nPayloadLength;
vpcola 0:f1d3878b8dd9 311 /* Computes PCKTLEN1 value from nPayloadLength */
vpcola 0:f1d3878b8dd9 312 tempRegValue[0]=BUILD_PCKTLEN1(nPayloadLength);//(uint8_t)(nPayloadLength>>8);
vpcola 0:f1d3878b8dd9 313
vpcola 0:f1d3878b8dd9 314 /* Writes data on the PCKTLEN1/0 register */
vpcola 0:f1d3878b8dd9 315 g_xStatus = SpiritSpiWriteRegisters(PCKTLEN1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 316
vpcola 0:f1d3878b8dd9 317 }
vpcola 0:f1d3878b8dd9 318
vpcola 0:f1d3878b8dd9 319
vpcola 0:f1d3878b8dd9 320 /**
vpcola 0:f1d3878b8dd9 321 * @brief Returns the payload length for SPIRIT MBUS packets.
vpcola 0:f1d3878b8dd9 322 * @param None.
vpcola 0:f1d3878b8dd9 323 * @retval uint16_t Payload length in bytes.
vpcola 0:f1d3878b8dd9 324 */
vpcola 0:f1d3878b8dd9 325 uint16_t SpiritPktMbusGetPayloadLength(void)
vpcola 0:f1d3878b8dd9 326 {
vpcola 0:f1d3878b8dd9 327 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 328
vpcola 0:f1d3878b8dd9 329 /* Reads the packet length registers */
vpcola 0:f1d3878b8dd9 330 g_xStatus = SpiritSpiReadRegisters(PCKTLEN1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 331
vpcola 0:f1d3878b8dd9 332 /* Returns the packet length */
vpcola 0:f1d3878b8dd9 333 return ((((uint16_t)tempRegValue[0])<<8) + (uint16_t) tempRegValue[1]);
vpcola 0:f1d3878b8dd9 334
vpcola 0:f1d3878b8dd9 335 }
vpcola 0:f1d3878b8dd9 336
vpcola 0:f1d3878b8dd9 337 /**
vpcola 0:f1d3878b8dd9 338 *@}
vpcola 0:f1d3878b8dd9 339 */
vpcola 0:f1d3878b8dd9 340
vpcola 0:f1d3878b8dd9 341 /**
vpcola 0:f1d3878b8dd9 342 *@}
vpcola 0:f1d3878b8dd9 343 */
vpcola 0:f1d3878b8dd9 344
vpcola 0:f1d3878b8dd9 345
vpcola 0:f1d3878b8dd9 346 /**
vpcola 0:f1d3878b8dd9 347 *@}
vpcola 0:f1d3878b8dd9 348 */
vpcola 0:f1d3878b8dd9 349
vpcola 0:f1d3878b8dd9 350
vpcola 0:f1d3878b8dd9 351
vpcola 0:f1d3878b8dd9 352
vpcola 0:f1d3878b8dd9 353
vpcola 0:f1d3878b8dd9 354 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/