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