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