Vergil Cola
/
MQTTGateway2
Fork of my original MQTTGateway
easy-connect/stm-spirit1-rf-driver/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_PktMbus.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_PktMbus.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 MBUS 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_PktMbus.h" |
vpcola | 0:a1734fe1ec4b | 41 | #include "SPIRIT_Radio.h" |
vpcola | 0:a1734fe1ec4b | 42 | #include "MCU_Interface.h" |
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_PktMbus |
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 PktMbus_Private_TypesDefinitions Pkt MBUS 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 PktMbus_Private_Defines Pkt MBUS 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 PktMbus_Private_Macros Pkt MBUS 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 PktMbus_Private_Variables Pkt MBUS 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 PktMbus_Private_FunctionPrototypes Pkt MBUS 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 PktMbus_Private_Functions Pkt MBUS 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 MBUS packet according to the specified parameters in the PktMbusInit struct. |
vpcola | 0:a1734fe1ec4b | 114 | * @param pxPktMbusInit pointer to a PktMbusInit structure that contains the configuration information for the specified SPIRIT MBUS PACKET FORMAT. |
vpcola | 0:a1734fe1ec4b | 115 | * This parameter is a pointer to @ref PktMbusInit. |
vpcola | 0:a1734fe1ec4b | 116 | * @retval None. |
vpcola | 0:a1734fe1ec4b | 117 | */ |
vpcola | 0:a1734fe1ec4b | 118 | void SpiritPktMbusInit(PktMbusInit* pxPktMbusInit) |
vpcola | 0:a1734fe1ec4b | 119 | { |
vpcola | 0:a1734fe1ec4b | 120 | uint8_t tempRegValue[3]; |
vpcola | 0:a1734fe1ec4b | 121 | |
vpcola | 0:a1734fe1ec4b | 122 | /* Check the parameters */ |
vpcola | 0:a1734fe1ec4b | 123 | s_assert_param(IS_MBUS_SUBMODE(pxPktMbusInit->xMbusSubmode)); |
vpcola | 0:a1734fe1ec4b | 124 | |
vpcola | 0:a1734fe1ec4b | 125 | /* Packet format config */ |
vpcola | 0:a1734fe1ec4b | 126 | SpiritPktMbusSetFormat(); |
vpcola | 0:a1734fe1ec4b | 127 | SpiritPktCommonFilterOnCrc(S_DISABLE); |
vpcola | 0:a1734fe1ec4b | 128 | SpiritRadioCsBlanking(S_ENABLE); |
vpcola | 0:a1734fe1ec4b | 129 | |
vpcola | 0:a1734fe1ec4b | 130 | /* Preamble, postamble and submode config */ |
vpcola | 0:a1734fe1ec4b | 131 | tempRegValue[0] = pxPktMbusInit->cPreambleLength; |
vpcola | 0:a1734fe1ec4b | 132 | tempRegValue[1] = pxPktMbusInit->cPostambleLength; |
vpcola | 0:a1734fe1ec4b | 133 | tempRegValue[2] = (uint8_t) pxPktMbusInit->xMbusSubmode; |
vpcola | 0:a1734fe1ec4b | 134 | |
vpcola | 0:a1734fe1ec4b | 135 | /* Writes the new values on the MBUS_PRMBL registers */ |
vpcola | 0:a1734fe1ec4b | 136 | g_xStatus = SpiritSpiWriteRegisters(MBUS_PRMBL_BASE, 3, tempRegValue); |
vpcola | 0:a1734fe1ec4b | 137 | |
vpcola | 0:a1734fe1ec4b | 138 | } |
vpcola | 0:a1734fe1ec4b | 139 | |
vpcola | 0:a1734fe1ec4b | 140 | /** |
vpcola | 0:a1734fe1ec4b | 141 | * @brief Returns the SPIRIT MBUS packet structure according to the specified parameters in the registers. |
vpcola | 0:a1734fe1ec4b | 142 | * @param pxPktMbusInit MBUS packet init structure. |
vpcola | 0:a1734fe1ec4b | 143 | * This parameter is a pointer to @ref PktMbusInit. |
vpcola | 0:a1734fe1ec4b | 144 | * @retval None. |
vpcola | 0:a1734fe1ec4b | 145 | */ |
vpcola | 0:a1734fe1ec4b | 146 | void SpiritPktMbusGetInfo(PktMbusInit* pxPktMbusInit) |
vpcola | 0:a1734fe1ec4b | 147 | { |
vpcola | 0:a1734fe1ec4b | 148 | uint8_t tempRegValue[3]; |
vpcola | 0:a1734fe1ec4b | 149 | |
vpcola | 0:a1734fe1ec4b | 150 | /* Reads the MBUS regs value */ |
vpcola | 0:a1734fe1ec4b | 151 | g_xStatus = SpiritSpiReadRegisters(MBUS_PRMBL_BASE, 3, tempRegValue); |
vpcola | 0:a1734fe1ec4b | 152 | |
vpcola | 0:a1734fe1ec4b | 153 | /* Fit the structure */ |
vpcola | 0:a1734fe1ec4b | 154 | pxPktMbusInit->cPreambleLength = tempRegValue[0]; |
vpcola | 0:a1734fe1ec4b | 155 | pxPktMbusInit->cPostambleLength = tempRegValue[1]; |
vpcola | 0:a1734fe1ec4b | 156 | pxPktMbusInit->xMbusSubmode = (MbusSubmode) (tempRegValue[2]&0x0E); |
vpcola | 0:a1734fe1ec4b | 157 | |
vpcola | 0:a1734fe1ec4b | 158 | } |
vpcola | 0:a1734fe1ec4b | 159 | |
vpcola | 0:a1734fe1ec4b | 160 | |
vpcola | 0:a1734fe1ec4b | 161 | /** |
vpcola | 0:a1734fe1ec4b | 162 | * @brief Configures the MBUS packet format as the one used by SPIRIT. |
vpcola | 0:a1734fe1ec4b | 163 | * @param None. |
vpcola | 0:a1734fe1ec4b | 164 | * @retval None. |
vpcola | 0:a1734fe1ec4b | 165 | */ |
vpcola | 0:a1734fe1ec4b | 166 | void SpiritPktMbusSetFormat(void) |
vpcola | 0:a1734fe1ec4b | 167 | { |
vpcola | 0:a1734fe1ec4b | 168 | uint8_t tempRegValue; |
vpcola | 0:a1734fe1ec4b | 169 | |
vpcola | 0:a1734fe1ec4b | 170 | /* Reads the PCKTCTRL3 register value */ |
vpcola | 0:a1734fe1ec4b | 171 | g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 172 | |
vpcola | 0:a1734fe1ec4b | 173 | /* Sets format bits. Also set to 0 the direct RX mode bits */ |
vpcola | 0:a1734fe1ec4b | 174 | tempRegValue &= 0x0F; |
vpcola | 0:a1734fe1ec4b | 175 | tempRegValue |= ((uint8_t)PCKTCTRL3_PCKT_FRMT_MBUS); |
vpcola | 0:a1734fe1ec4b | 176 | |
vpcola | 0:a1734fe1ec4b | 177 | /* Writes value on the PCKTCTRL3 register */ |
vpcola | 0:a1734fe1ec4b | 178 | g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL3_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 179 | |
vpcola | 0:a1734fe1ec4b | 180 | /* Reads the PCKTCTRL1 register value */ |
vpcola | 0:a1734fe1ec4b | 181 | g_xStatus = SpiritSpiReadRegisters(PCKTCTRL1_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 182 | |
vpcola | 0:a1734fe1ec4b | 183 | /* Build the new value. Set to 0 the direct TX mode bits */ |
vpcola | 0:a1734fe1ec4b | 184 | tempRegValue &= 0xF3; |
vpcola | 0:a1734fe1ec4b | 185 | |
vpcola | 0:a1734fe1ec4b | 186 | /* Writes the value on the PCKTCTRL1 register */ |
vpcola | 0:a1734fe1ec4b | 187 | g_xStatus = SpiritSpiWriteRegisters(PCKTCTRL1_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 188 | |
vpcola | 0:a1734fe1ec4b | 189 | /* Reads the PROTOCOL1 register */ |
vpcola | 0:a1734fe1ec4b | 190 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 191 | |
vpcola | 0:a1734fe1ec4b | 192 | /* Mask a reserved bit */ |
vpcola | 0:a1734fe1ec4b | 193 | tempRegValue &= ~0x20; |
vpcola | 0:a1734fe1ec4b | 194 | |
vpcola | 0:a1734fe1ec4b | 195 | /* Writes the value on the PROTOCOL1 register */ |
vpcola | 0:a1734fe1ec4b | 196 | g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 197 | |
vpcola | 0:a1734fe1ec4b | 198 | } |
vpcola | 0:a1734fe1ec4b | 199 | |
vpcola | 0:a1734fe1ec4b | 200 | |
vpcola | 0:a1734fe1ec4b | 201 | /** |
vpcola | 0:a1734fe1ec4b | 202 | * @brief Sets how many chip sequence 01 shall be added in the preamble |
vpcola | 0:a1734fe1ec4b | 203 | * respect to the minimum value as defined according to the specified sub-mode. |
vpcola | 0:a1734fe1ec4b | 204 | * @param cPreamble the number of chip sequence. |
vpcola | 0:a1734fe1ec4b | 205 | * This parameter is an uint8_t. |
vpcola | 0:a1734fe1ec4b | 206 | * @retval None. |
vpcola | 0:a1734fe1ec4b | 207 | */ |
vpcola | 0:a1734fe1ec4b | 208 | void SpiritPktMbusSetPreamble(uint8_t cPreamble) |
vpcola | 0:a1734fe1ec4b | 209 | { |
vpcola | 0:a1734fe1ec4b | 210 | /* Modifies the MBUS_PRMBL register value */ |
vpcola | 0:a1734fe1ec4b | 211 | g_xStatus = SpiritSpiWriteRegisters(MBUS_PRMBL_BASE, 1, &cPreamble); |
vpcola | 0:a1734fe1ec4b | 212 | |
vpcola | 0:a1734fe1ec4b | 213 | } |
vpcola | 0:a1734fe1ec4b | 214 | |
vpcola | 0:a1734fe1ec4b | 215 | |
vpcola | 0:a1734fe1ec4b | 216 | /** |
vpcola | 0:a1734fe1ec4b | 217 | * @brief Returns how many chip sequence "01" are added in the preamble |
vpcola | 0:a1734fe1ec4b | 218 | * respect to the minimum value as defined according to the specified sub-mode. |
vpcola | 0:a1734fe1ec4b | 219 | * @param None. |
vpcola | 0:a1734fe1ec4b | 220 | * @retval uint8_t Preable in number of "01" chip sequences. |
vpcola | 0:a1734fe1ec4b | 221 | */ |
vpcola | 0:a1734fe1ec4b | 222 | uint8_t SpiritPktMbusGetPreamble(void) |
vpcola | 0:a1734fe1ec4b | 223 | { |
vpcola | 0:a1734fe1ec4b | 224 | uint8_t tempRegValue; |
vpcola | 0:a1734fe1ec4b | 225 | |
vpcola | 0:a1734fe1ec4b | 226 | /* Modifies the MBUS_PRMBL register value */ |
vpcola | 0:a1734fe1ec4b | 227 | g_xStatus = SpiritSpiReadRegisters(MBUS_PRMBL_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 228 | |
vpcola | 0:a1734fe1ec4b | 229 | /* Return value */ |
vpcola | 0:a1734fe1ec4b | 230 | return tempRegValue; |
vpcola | 0:a1734fe1ec4b | 231 | |
vpcola | 0:a1734fe1ec4b | 232 | } |
vpcola | 0:a1734fe1ec4b | 233 | |
vpcola | 0:a1734fe1ec4b | 234 | |
vpcola | 0:a1734fe1ec4b | 235 | /** |
vpcola | 0:a1734fe1ec4b | 236 | * @brief Sets how many chip sequence 01 will be used in postamble |
vpcola | 0:a1734fe1ec4b | 237 | * @param cPostamble the number of chip sequence. |
vpcola | 0:a1734fe1ec4b | 238 | * This parameter is an uint8_t. |
vpcola | 0:a1734fe1ec4b | 239 | * @retval None. |
vpcola | 0:a1734fe1ec4b | 240 | */ |
vpcola | 0:a1734fe1ec4b | 241 | void SpiritPktMbusSetPostamble(uint8_t cPostamble) |
vpcola | 0:a1734fe1ec4b | 242 | { |
vpcola | 0:a1734fe1ec4b | 243 | /* Modifies the MBUS_PSTMBL register value */ |
vpcola | 0:a1734fe1ec4b | 244 | g_xStatus = SpiritSpiWriteRegisters(MBUS_PSTMBL_BASE, 1, &cPostamble); |
vpcola | 0:a1734fe1ec4b | 245 | |
vpcola | 0:a1734fe1ec4b | 246 | } |
vpcola | 0:a1734fe1ec4b | 247 | |
vpcola | 0:a1734fe1ec4b | 248 | |
vpcola | 0:a1734fe1ec4b | 249 | /** |
vpcola | 0:a1734fe1ec4b | 250 | * @brief Returns how many chip sequence "01" are used in the postamble |
vpcola | 0:a1734fe1ec4b | 251 | * @param None. |
vpcola | 0:a1734fe1ec4b | 252 | * @retval uint8_t Postamble in number of "01" chip sequences. |
vpcola | 0:a1734fe1ec4b | 253 | */ |
vpcola | 0:a1734fe1ec4b | 254 | uint8_t SpiritPktMbusGetPostamble(void) |
vpcola | 0:a1734fe1ec4b | 255 | { |
vpcola | 0:a1734fe1ec4b | 256 | uint8_t tempRegValue; |
vpcola | 0:a1734fe1ec4b | 257 | |
vpcola | 0:a1734fe1ec4b | 258 | /* Reads the MBUS_PSTMBL register */ |
vpcola | 0:a1734fe1ec4b | 259 | g_xStatus = SpiritSpiReadRegisters(MBUS_PSTMBL_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 260 | |
vpcola | 0:a1734fe1ec4b | 261 | /* Returns value */ |
vpcola | 0:a1734fe1ec4b | 262 | return tempRegValue; |
vpcola | 0:a1734fe1ec4b | 263 | |
vpcola | 0:a1734fe1ec4b | 264 | } |
vpcola | 0:a1734fe1ec4b | 265 | |
vpcola | 0:a1734fe1ec4b | 266 | |
vpcola | 0:a1734fe1ec4b | 267 | /** |
vpcola | 0:a1734fe1ec4b | 268 | * @brief Sets the MBUS submode used. |
vpcola | 0:a1734fe1ec4b | 269 | * @param xMbusSubmode the submode used. |
vpcola | 0:a1734fe1ec4b | 270 | * This parameter can be any value of @ref MbusSubmode. |
vpcola | 0:a1734fe1ec4b | 271 | * @retval None. |
vpcola | 0:a1734fe1ec4b | 272 | */ |
vpcola | 0:a1734fe1ec4b | 273 | void SpiritPktMbusSetSubmode(MbusSubmode xMbusSubmode) |
vpcola | 0:a1734fe1ec4b | 274 | { |
vpcola | 0:a1734fe1ec4b | 275 | /* Modifies the MBUS_CTRL register value */ |
vpcola | 0:a1734fe1ec4b | 276 | g_xStatus = SpiritSpiWriteRegisters(MBUS_CTRL_BASE, 1, (uint8_t*)xMbusSubmode); |
vpcola | 0:a1734fe1ec4b | 277 | |
vpcola | 0:a1734fe1ec4b | 278 | } |
vpcola | 0:a1734fe1ec4b | 279 | |
vpcola | 0:a1734fe1ec4b | 280 | |
vpcola | 0:a1734fe1ec4b | 281 | /** |
vpcola | 0:a1734fe1ec4b | 282 | * @brief Returns the MBUS submode used. |
vpcola | 0:a1734fe1ec4b | 283 | * @param None. |
vpcola | 0:a1734fe1ec4b | 284 | * @retval MbusSubmode MBUS submode. |
vpcola | 0:a1734fe1ec4b | 285 | */ |
vpcola | 0:a1734fe1ec4b | 286 | MbusSubmode SpiritPktMbusGetSubmode(void) |
vpcola | 0:a1734fe1ec4b | 287 | { |
vpcola | 0:a1734fe1ec4b | 288 | uint8_t tempRegValue; |
vpcola | 0:a1734fe1ec4b | 289 | |
vpcola | 0:a1734fe1ec4b | 290 | /* Reads the MBUS_CTRL register value */ |
vpcola | 0:a1734fe1ec4b | 291 | g_xStatus = SpiritSpiReadRegisters(MBUS_CTRL_BASE, 1, &tempRegValue); |
vpcola | 0:a1734fe1ec4b | 292 | |
vpcola | 0:a1734fe1ec4b | 293 | /* Returns value */ |
vpcola | 0:a1734fe1ec4b | 294 | return (MbusSubmode) tempRegValue; |
vpcola | 0:a1734fe1ec4b | 295 | |
vpcola | 0:a1734fe1ec4b | 296 | } |
vpcola | 0:a1734fe1ec4b | 297 | |
vpcola | 0:a1734fe1ec4b | 298 | |
vpcola | 0:a1734fe1ec4b | 299 | /** |
vpcola | 0:a1734fe1ec4b | 300 | * @brief Sets the payload length for SPIRIT MBUS packets. |
vpcola | 0:a1734fe1ec4b | 301 | * @param nPayloadLength payload length in bytes. |
vpcola | 0:a1734fe1ec4b | 302 | * This parameter is an uint16_t. |
vpcola | 0:a1734fe1ec4b | 303 | * @retval None. |
vpcola | 0:a1734fe1ec4b | 304 | */ |
vpcola | 0:a1734fe1ec4b | 305 | void SpiritPktMbusSetPayloadLength(uint16_t nPayloadLength) |
vpcola | 0:a1734fe1ec4b | 306 | { |
vpcola | 0:a1734fe1ec4b | 307 | uint8_t tempRegValue[2]; |
vpcola | 0:a1734fe1ec4b | 308 | |
vpcola | 0:a1734fe1ec4b | 309 | /* Computes PCKTLEN0 value from nPayloadLength */ |
vpcola | 0:a1734fe1ec4b | 310 | tempRegValue[1]=BUILD_PCKTLEN0(nPayloadLength);//(uint8_t)nPayloadLength; |
vpcola | 0:a1734fe1ec4b | 311 | /* Computes PCKTLEN1 value from nPayloadLength */ |
vpcola | 0:a1734fe1ec4b | 312 | tempRegValue[0]=BUILD_PCKTLEN1(nPayloadLength);//(uint8_t)(nPayloadLength>>8); |
vpcola | 0:a1734fe1ec4b | 313 | |
vpcola | 0:a1734fe1ec4b | 314 | /* Writes data on the PCKTLEN1/0 register */ |
vpcola | 0:a1734fe1ec4b | 315 | g_xStatus = SpiritSpiWriteRegisters(PCKTLEN1_BASE, 2, tempRegValue); |
vpcola | 0:a1734fe1ec4b | 316 | |
vpcola | 0:a1734fe1ec4b | 317 | } |
vpcola | 0:a1734fe1ec4b | 318 | |
vpcola | 0:a1734fe1ec4b | 319 | |
vpcola | 0:a1734fe1ec4b | 320 | /** |
vpcola | 0:a1734fe1ec4b | 321 | * @brief Returns the payload length for SPIRIT MBUS packets. |
vpcola | 0:a1734fe1ec4b | 322 | * @param None. |
vpcola | 0:a1734fe1ec4b | 323 | * @retval uint16_t Payload length in bytes. |
vpcola | 0:a1734fe1ec4b | 324 | */ |
vpcola | 0:a1734fe1ec4b | 325 | uint16_t SpiritPktMbusGetPayloadLength(void) |
vpcola | 0:a1734fe1ec4b | 326 | { |
vpcola | 0:a1734fe1ec4b | 327 | uint8_t tempRegValue[2]; |
vpcola | 0:a1734fe1ec4b | 328 | |
vpcola | 0:a1734fe1ec4b | 329 | /* Reads the packet length registers */ |
vpcola | 0:a1734fe1ec4b | 330 | g_xStatus = SpiritSpiReadRegisters(PCKTLEN1_BASE, 2, tempRegValue); |
vpcola | 0:a1734fe1ec4b | 331 | |
vpcola | 0:a1734fe1ec4b | 332 | /* Returns the packet length */ |
vpcola | 0:a1734fe1ec4b | 333 | return ((((uint16_t)tempRegValue[0])<<8) + (uint16_t) tempRegValue[1]); |
vpcola | 0:a1734fe1ec4b | 334 | |
vpcola | 0:a1734fe1ec4b | 335 | } |
vpcola | 0:a1734fe1ec4b | 336 | |
vpcola | 0:a1734fe1ec4b | 337 | /** |
vpcola | 0:a1734fe1ec4b | 338 | *@} |
vpcola | 0:a1734fe1ec4b | 339 | */ |
vpcola | 0:a1734fe1ec4b | 340 | |
vpcola | 0:a1734fe1ec4b | 341 | /** |
vpcola | 0:a1734fe1ec4b | 342 | *@} |
vpcola | 0:a1734fe1ec4b | 343 | */ |
vpcola | 0:a1734fe1ec4b | 344 | |
vpcola | 0:a1734fe1ec4b | 345 | |
vpcola | 0:a1734fe1ec4b | 346 | /** |
vpcola | 0:a1734fe1ec4b | 347 | *@} |
vpcola | 0:a1734fe1ec4b | 348 | */ |
vpcola | 0:a1734fe1ec4b | 349 | |
vpcola | 0:a1734fe1ec4b | 350 | |
vpcola | 0:a1734fe1ec4b | 351 | |
vpcola | 0:a1734fe1ec4b | 352 | |
vpcola | 0:a1734fe1ec4b | 353 | |
vpcola | 0:a1734fe1ec4b | 354 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |