Easily add all supported connectivity methods to your mbed OS project
stm-spirit1-rf-driver/source/libs/spirit1/SPIRIT1_Library/Src/SPIRIT_Timer.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_Timer.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 timers. |
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_Timer.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 | |
MACRUM | 0:615f90842ce8 | 46 | |
MACRUM | 0:615f90842ce8 | 47 | /** |
MACRUM | 0:615f90842ce8 | 48 | * @addtogroup SPIRIT_Libraries |
MACRUM | 0:615f90842ce8 | 49 | * @{ |
MACRUM | 0:615f90842ce8 | 50 | */ |
MACRUM | 0:615f90842ce8 | 51 | |
MACRUM | 0:615f90842ce8 | 52 | |
MACRUM | 0:615f90842ce8 | 53 | /** |
MACRUM | 0:615f90842ce8 | 54 | * @addtogroup SPIRIT_Timer |
MACRUM | 0:615f90842ce8 | 55 | * @{ |
MACRUM | 0:615f90842ce8 | 56 | */ |
MACRUM | 0:615f90842ce8 | 57 | |
MACRUM | 0:615f90842ce8 | 58 | |
MACRUM | 0:615f90842ce8 | 59 | /** |
MACRUM | 0:615f90842ce8 | 60 | * @defgroup Timer_Private_TypesDefinitions Timer Private Types Definitions |
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 | |
MACRUM | 0:615f90842ce8 | 68 | |
MACRUM | 0:615f90842ce8 | 69 | /** |
MACRUM | 0:615f90842ce8 | 70 | * @defgroup Timer_Private_Defines Timer Private Defines |
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 | |
MACRUM | 0:615f90842ce8 | 78 | |
MACRUM | 0:615f90842ce8 | 79 | /** |
MACRUM | 0:615f90842ce8 | 80 | * @defgroup Timer_Private_Macros Timer Private Macros |
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 | */ |
MACRUM | 0:615f90842ce8 | 88 | |
MACRUM | 0:615f90842ce8 | 89 | |
MACRUM | 0:615f90842ce8 | 90 | /** |
MACRUM | 0:615f90842ce8 | 91 | * @defgroup Timer_Private_Variables Timer Private Variables |
MACRUM | 0:615f90842ce8 | 92 | * @{ |
MACRUM | 0:615f90842ce8 | 93 | */ |
MACRUM | 0:615f90842ce8 | 94 | |
MACRUM | 0:615f90842ce8 | 95 | /** |
MACRUM | 0:615f90842ce8 | 96 | *@} |
MACRUM | 0:615f90842ce8 | 97 | */ |
MACRUM | 0:615f90842ce8 | 98 | |
MACRUM | 0:615f90842ce8 | 99 | |
MACRUM | 0:615f90842ce8 | 100 | /** |
MACRUM | 0:615f90842ce8 | 101 | * @defgroup Timer_Private_FunctionPrototypes Timer Private Function Prototypes |
MACRUM | 0:615f90842ce8 | 102 | * @{ |
MACRUM | 0:615f90842ce8 | 103 | */ |
MACRUM | 0:615f90842ce8 | 104 | |
MACRUM | 0:615f90842ce8 | 105 | /** |
MACRUM | 0:615f90842ce8 | 106 | *@} |
MACRUM | 0:615f90842ce8 | 107 | */ |
MACRUM | 0:615f90842ce8 | 108 | |
MACRUM | 0:615f90842ce8 | 109 | |
MACRUM | 0:615f90842ce8 | 110 | /** |
MACRUM | 0:615f90842ce8 | 111 | * @defgroup Timer_Private_Functions Timer Private Functions |
MACRUM | 0:615f90842ce8 | 112 | * @{ |
MACRUM | 0:615f90842ce8 | 113 | */ |
MACRUM | 0:615f90842ce8 | 114 | |
MACRUM | 0:615f90842ce8 | 115 | /** |
MACRUM | 0:615f90842ce8 | 116 | * @brief Enables or Disables the LDCR mode. |
MACRUM | 0:615f90842ce8 | 117 | * @param xNewState new state for LDCR mode. |
MACRUM | 0:615f90842ce8 | 118 | * This parameter can be: S_ENABLE or S_DISABLE. |
MACRUM | 0:615f90842ce8 | 119 | * @retval None. |
MACRUM | 0:615f90842ce8 | 120 | */ |
MACRUM | 0:615f90842ce8 | 121 | void SpiritTimerLdcrMode(SpiritFunctionalState xNewState) |
MACRUM | 0:615f90842ce8 | 122 | { |
MACRUM | 0:615f90842ce8 | 123 | uint8_t tempRegValue; |
MACRUM | 0:615f90842ce8 | 124 | |
MACRUM | 0:615f90842ce8 | 125 | /* Reads the register value */ |
MACRUM | 0:615f90842ce8 | 126 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue); |
MACRUM | 0:615f90842ce8 | 127 | |
MACRUM | 0:615f90842ce8 | 128 | /* Mask the read value to enable or disable the LDC mode */ |
MACRUM | 0:615f90842ce8 | 129 | if(xNewState==S_ENABLE) |
MACRUM | 0:615f90842ce8 | 130 | { |
MACRUM | 0:615f90842ce8 | 131 | tempRegValue |= PROTOCOL2_LDC_MODE_MASK; |
MACRUM | 0:615f90842ce8 | 132 | } |
MACRUM | 0:615f90842ce8 | 133 | else |
MACRUM | 0:615f90842ce8 | 134 | { |
MACRUM | 0:615f90842ce8 | 135 | tempRegValue &= ~PROTOCOL2_LDC_MODE_MASK; |
MACRUM | 0:615f90842ce8 | 136 | } |
MACRUM | 0:615f90842ce8 | 137 | |
MACRUM | 0:615f90842ce8 | 138 | /* Writes the register to Enable or Disable the LDCR mode */ |
MACRUM | 0:615f90842ce8 | 139 | g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue); |
MACRUM | 0:615f90842ce8 | 140 | |
MACRUM | 0:615f90842ce8 | 141 | } |
MACRUM | 0:615f90842ce8 | 142 | |
MACRUM | 0:615f90842ce8 | 143 | |
MACRUM | 0:615f90842ce8 | 144 | /** |
MACRUM | 0:615f90842ce8 | 145 | * @brief Enables or Disables the LDCR timer reloading with the value stored in the LDCR_RELOAD registers. |
MACRUM | 0:615f90842ce8 | 146 | * @param xNewState new state for LDCR reloading. |
MACRUM | 0:615f90842ce8 | 147 | * This parameter can be: S_ENABLE or S_DISABLE. |
MACRUM | 0:615f90842ce8 | 148 | * @retval None. |
MACRUM | 0:615f90842ce8 | 149 | */ |
MACRUM | 0:615f90842ce8 | 150 | void SpiritTimerLdcrAutoReload(SpiritFunctionalState xNewState) |
MACRUM | 0:615f90842ce8 | 151 | { |
MACRUM | 0:615f90842ce8 | 152 | uint8_t tempRegValue; |
MACRUM | 0:615f90842ce8 | 153 | |
MACRUM | 0:615f90842ce8 | 154 | /* Reads the register value */ |
MACRUM | 0:615f90842ce8 | 155 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
MACRUM | 0:615f90842ce8 | 156 | |
MACRUM | 0:615f90842ce8 | 157 | /* Mask te read value to enable or disable the reload on sync mode */ |
MACRUM | 0:615f90842ce8 | 158 | if(xNewState==S_ENABLE) |
MACRUM | 0:615f90842ce8 | 159 | { |
MACRUM | 0:615f90842ce8 | 160 | tempRegValue |= PROTOCOL1_LDC_RELOAD_ON_SYNC_MASK; |
MACRUM | 0:615f90842ce8 | 161 | } |
MACRUM | 0:615f90842ce8 | 162 | else |
MACRUM | 0:615f90842ce8 | 163 | { |
MACRUM | 0:615f90842ce8 | 164 | tempRegValue &= ~PROTOCOL1_LDC_RELOAD_ON_SYNC_MASK; |
MACRUM | 0:615f90842ce8 | 165 | } |
MACRUM | 0:615f90842ce8 | 166 | |
MACRUM | 0:615f90842ce8 | 167 | /* Writes the register to Enable or Disable the Auto Reload */ |
MACRUM | 0:615f90842ce8 | 168 | g_xStatus = SpiritSpiWriteRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
MACRUM | 0:615f90842ce8 | 169 | |
MACRUM | 0:615f90842ce8 | 170 | } |
MACRUM | 0:615f90842ce8 | 171 | |
MACRUM | 0:615f90842ce8 | 172 | |
MACRUM | 0:615f90842ce8 | 173 | /** |
MACRUM | 0:615f90842ce8 | 174 | * @brief Returns the LDCR timer reload bit. |
MACRUM | 0:615f90842ce8 | 175 | * @param None. |
MACRUM | 0:615f90842ce8 | 176 | * @retval SpiritFunctionalState: value of the reload bit. |
MACRUM | 0:615f90842ce8 | 177 | */ |
MACRUM | 0:615f90842ce8 | 178 | SpiritFunctionalState SpiritTimerLdcrGetAutoReload(void) |
MACRUM | 0:615f90842ce8 | 179 | { |
MACRUM | 0:615f90842ce8 | 180 | uint8_t tempRegValue; |
MACRUM | 0:615f90842ce8 | 181 | |
MACRUM | 0:615f90842ce8 | 182 | /* Reads the register value */ |
MACRUM | 0:615f90842ce8 | 183 | g_xStatus = SpiritSpiReadRegisters(PROTOCOL1_BASE, 1, &tempRegValue); |
MACRUM | 0:615f90842ce8 | 184 | |
MACRUM | 0:615f90842ce8 | 185 | return (SpiritFunctionalState)(tempRegValue & 0x80); |
MACRUM | 0:615f90842ce8 | 186 | |
MACRUM | 0:615f90842ce8 | 187 | } |
MACRUM | 0:615f90842ce8 | 188 | |
MACRUM | 0:615f90842ce8 | 189 | /** |
MACRUM | 0:615f90842ce8 | 190 | * @brief Sets the RX timeout timer initialization registers with the values of COUNTER and PRESCALER according to the formula: Trx=PRESCALER*COUNTER*Tck. |
MACRUM | 0:615f90842ce8 | 191 | * Remember that it is possible to have infinite RX_Timeout writing 0 in the RX_Timeout_Counter and/or RX_Timeout_Prescaler registers. |
MACRUM | 0:615f90842ce8 | 192 | * @param cCounter value for the timer counter. |
MACRUM | 0:615f90842ce8 | 193 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 194 | * @param cPrescaler value for the timer prescaler. |
MACRUM | 0:615f90842ce8 | 195 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 196 | * @retval None. |
MACRUM | 0:615f90842ce8 | 197 | */ |
MACRUM | 0:615f90842ce8 | 198 | void SpiritTimerSetRxTimeout(uint8_t cCounter , uint8_t cPrescaler) |
MACRUM | 0:615f90842ce8 | 199 | { |
MACRUM | 0:615f90842ce8 | 200 | uint8_t tempRegValue[2]={cPrescaler,cCounter}; |
MACRUM | 0:615f90842ce8 | 201 | |
MACRUM | 0:615f90842ce8 | 202 | /* Writes the prescaler and counter value for RX timeout in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 203 | g_xStatus = SpiritSpiWriteRegisters(TIMERS5_RX_TIMEOUT_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 204 | |
MACRUM | 0:615f90842ce8 | 205 | } |
MACRUM | 0:615f90842ce8 | 206 | |
MACRUM | 0:615f90842ce8 | 207 | |
MACRUM | 0:615f90842ce8 | 208 | /** |
MACRUM | 0:615f90842ce8 | 209 | * @brief Sets the RX timeout timer counter and prescaler from the desired value in ms. it is possible to fix the RX_Timeout to |
MACRUM | 0:615f90842ce8 | 210 | * a minimum value of 50.417us to a maximum value of about 3.28 s. |
MACRUM | 0:615f90842ce8 | 211 | * @param fDesiredMsec desired timer value. |
MACRUM | 0:615f90842ce8 | 212 | * This parameter must be a float. |
MACRUM | 0:615f90842ce8 | 213 | * @retval None |
MACRUM | 0:615f90842ce8 | 214 | */ |
MACRUM | 0:615f90842ce8 | 215 | |
MACRUM | 0:615f90842ce8 | 216 | void SpiritTimerSetRxTimeoutMs(float fDesiredMsec) |
MACRUM | 0:615f90842ce8 | 217 | { |
MACRUM | 0:615f90842ce8 | 218 | uint8_t tempRegValue[2]; |
MACRUM | 0:615f90842ce8 | 219 | |
MACRUM | 0:615f90842ce8 | 220 | /* Computes the counter and prescaler value */ |
MACRUM | 0:615f90842ce8 | 221 | SpiritTimerComputeRxTimeoutValues(fDesiredMsec , &tempRegValue[1] , &tempRegValue[0]); |
MACRUM | 0:615f90842ce8 | 222 | |
MACRUM | 0:615f90842ce8 | 223 | /* Writes the prescaler and counter value for RX timeout in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 224 | g_xStatus = SpiritSpiWriteRegisters(TIMERS5_RX_TIMEOUT_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 225 | |
MACRUM | 0:615f90842ce8 | 226 | } |
MACRUM | 0:615f90842ce8 | 227 | |
MACRUM | 0:615f90842ce8 | 228 | |
MACRUM | 0:615f90842ce8 | 229 | /** |
MACRUM | 0:615f90842ce8 | 230 | * @brief Sets the RX timeout timer counter. If it is equal to 0 the timeout is infinite. |
MACRUM | 0:615f90842ce8 | 231 | * @param cCounter value for the timer counter. |
MACRUM | 0:615f90842ce8 | 232 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 233 | * @retval None. |
MACRUM | 0:615f90842ce8 | 234 | */ |
MACRUM | 0:615f90842ce8 | 235 | void SpiritTimerSetRxTimeoutCounter(uint8_t cCounter) |
MACRUM | 0:615f90842ce8 | 236 | { |
MACRUM | 0:615f90842ce8 | 237 | /* Writes the counter value for RX timeout in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 238 | g_xStatus = SpiritSpiWriteRegisters(TIMERS4_RX_TIMEOUT_COUNTER_BASE, 1, &cCounter); |
MACRUM | 0:615f90842ce8 | 239 | |
MACRUM | 0:615f90842ce8 | 240 | } |
MACRUM | 0:615f90842ce8 | 241 | |
MACRUM | 0:615f90842ce8 | 242 | |
MACRUM | 0:615f90842ce8 | 243 | /** |
MACRUM | 0:615f90842ce8 | 244 | * @brief Sets the RX timeout timer prescaler. If it is equal to 0 the timeout is infinite. |
MACRUM | 0:615f90842ce8 | 245 | * @param cPrescaler value for the timer prescaler. |
MACRUM | 0:615f90842ce8 | 246 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 247 | * @retval None |
MACRUM | 0:615f90842ce8 | 248 | */ |
MACRUM | 0:615f90842ce8 | 249 | void SpiritTimerSetRxTimeoutPrescaler(uint8_t cPrescaler) |
MACRUM | 0:615f90842ce8 | 250 | { |
MACRUM | 0:615f90842ce8 | 251 | /* Writes the prescaler value for RX timeout in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 252 | g_xStatus = SpiritSpiWriteRegisters(TIMERS5_RX_TIMEOUT_PRESCALER_BASE, 1, &cPrescaler); |
MACRUM | 0:615f90842ce8 | 253 | |
MACRUM | 0:615f90842ce8 | 254 | } |
MACRUM | 0:615f90842ce8 | 255 | |
MACRUM | 0:615f90842ce8 | 256 | |
MACRUM | 0:615f90842ce8 | 257 | /** |
MACRUM | 0:615f90842ce8 | 258 | * @brief Returns the RX timeout timer. |
MACRUM | 0:615f90842ce8 | 259 | * @param pfTimeoutMsec pointer to the variable in which the timeout expressed in milliseconds has to be stored. |
MACRUM | 0:615f90842ce8 | 260 | * If the returned value is 0, it means that the RX_Timeout is infinite. |
MACRUM | 0:615f90842ce8 | 261 | * This parameter must be a float*. |
MACRUM | 0:615f90842ce8 | 262 | * @param pcCounter pointer to the variable in which the timer counter has to be stored. |
MACRUM | 0:615f90842ce8 | 263 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 264 | * @param pcPrescaler pointer to the variable in which the timer prescaler has to be stored. |
MACRUM | 0:615f90842ce8 | 265 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 266 | * @retval None. |
MACRUM | 0:615f90842ce8 | 267 | */ |
MACRUM | 0:615f90842ce8 | 268 | void SpiritTimerGetRxTimeout(float* pfTimeoutMsec, uint8_t* pcCounter , uint8_t* pcPrescaler) |
MACRUM | 0:615f90842ce8 | 269 | { |
MACRUM | 0:615f90842ce8 | 270 | uint8_t tempRegValue[2]; |
MACRUM | 0:615f90842ce8 | 271 | |
MACRUM | 0:615f90842ce8 | 272 | /* Reads the RX timeout registers value */ |
MACRUM | 0:615f90842ce8 | 273 | g_xStatus = SpiritSpiReadRegisters(TIMERS5_RX_TIMEOUT_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 274 | |
MACRUM | 0:615f90842ce8 | 275 | /* Returns values */ |
MACRUM | 0:615f90842ce8 | 276 | (*pcPrescaler) = tempRegValue[0]; |
MACRUM | 0:615f90842ce8 | 277 | (*pcCounter) = tempRegValue[1]; |
MACRUM | 0:615f90842ce8 | 278 | |
MACRUM | 0:615f90842ce8 | 279 | float nXtalFrequency = (float)SpiritRadioGetXtalFrequency(); |
MACRUM | 0:615f90842ce8 | 280 | if(nXtalFrequency>DOUBLE_XTAL_THR) { |
MACRUM | 0:615f90842ce8 | 281 | nXtalFrequency /= 2.0; |
MACRUM | 0:615f90842ce8 | 282 | } |
MACRUM | 0:615f90842ce8 | 283 | nXtalFrequency /= 1000.0; |
MACRUM | 0:615f90842ce8 | 284 | *pfTimeoutMsec = (float)((tempRegValue[0]+1)*tempRegValue[1]*(1210.0/nXtalFrequency)); |
MACRUM | 0:615f90842ce8 | 285 | |
MACRUM | 0:615f90842ce8 | 286 | |
MACRUM | 0:615f90842ce8 | 287 | } |
MACRUM | 0:615f90842ce8 | 288 | |
MACRUM | 0:615f90842ce8 | 289 | |
MACRUM | 0:615f90842ce8 | 290 | /** |
MACRUM | 0:615f90842ce8 | 291 | * @brief Sets the LDCR wake up timer initialization registers with the values of |
MACRUM | 0:615f90842ce8 | 292 | * COUNTER and PRESCALER according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where |
MACRUM | 0:615f90842ce8 | 293 | * Tck = 28.818 us. The minimum vale of the wakeup timeout is 28.818us (PRESCALER and |
MACRUM | 0:615f90842ce8 | 294 | * COUNTER equals to 0) and the maximum value is about 1.89 s (PRESCALER anc COUNTER equals |
MACRUM | 0:615f90842ce8 | 295 | * to 255). |
MACRUM | 0:615f90842ce8 | 296 | * @param cCounter value for the timer counter. |
MACRUM | 0:615f90842ce8 | 297 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 298 | * @param cPrescaler value for the timer prescaler. |
MACRUM | 0:615f90842ce8 | 299 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 300 | * @retval None. |
MACRUM | 0:615f90842ce8 | 301 | */ |
MACRUM | 0:615f90842ce8 | 302 | void SpiritTimerSetWakeUpTimer(uint8_t cCounter , uint8_t cPrescaler) |
MACRUM | 0:615f90842ce8 | 303 | { |
MACRUM | 0:615f90842ce8 | 304 | uint8_t tempRegValue[2]={cPrescaler,cCounter}; |
MACRUM | 0:615f90842ce8 | 305 | |
MACRUM | 0:615f90842ce8 | 306 | /* Writes the counter and prescaler value of wake-up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 307 | g_xStatus = SpiritSpiWriteRegisters(TIMERS3_LDC_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 308 | |
MACRUM | 0:615f90842ce8 | 309 | } |
MACRUM | 0:615f90842ce8 | 310 | |
MACRUM | 0:615f90842ce8 | 311 | |
MACRUM | 0:615f90842ce8 | 312 | /** |
MACRUM | 0:615f90842ce8 | 313 | * @brief Sets the LDCR wake up timer counter and prescaler from the desired value in ms, |
MACRUM | 0:615f90842ce8 | 314 | * according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us. |
MACRUM | 0:615f90842ce8 | 315 | * The minimum vale of the wakeup timeout is 28.818us (PRESCALER and COUNTER equals to 0) |
MACRUM | 0:615f90842ce8 | 316 | * and the maximum value is about 1.89 s (PRESCALER anc COUNTER equals to 255). |
MACRUM | 0:615f90842ce8 | 317 | * @param fDesiredMsec desired timer value. |
MACRUM | 0:615f90842ce8 | 318 | * This parameter must be a float. |
MACRUM | 0:615f90842ce8 | 319 | * @retval None. |
MACRUM | 0:615f90842ce8 | 320 | */ |
MACRUM | 0:615f90842ce8 | 321 | void SpiritTimerSetWakeUpTimerMs(float fDesiredMsec) |
MACRUM | 0:615f90842ce8 | 322 | { |
MACRUM | 0:615f90842ce8 | 323 | uint8_t tempRegValue[2]; |
MACRUM | 0:615f90842ce8 | 324 | |
MACRUM | 0:615f90842ce8 | 325 | /* Computes counter and prescaler */ |
MACRUM | 0:615f90842ce8 | 326 | SpiritTimerComputeWakeUpValues(fDesiredMsec , &tempRegValue[1] , &tempRegValue[0]); |
MACRUM | 0:615f90842ce8 | 327 | |
MACRUM | 0:615f90842ce8 | 328 | /* Writes the counter and prescaler value of wake-up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 329 | g_xStatus = SpiritSpiWriteRegisters(TIMERS3_LDC_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 330 | |
MACRUM | 0:615f90842ce8 | 331 | } |
MACRUM | 0:615f90842ce8 | 332 | |
MACRUM | 0:615f90842ce8 | 333 | |
MACRUM | 0:615f90842ce8 | 334 | /** |
MACRUM | 0:615f90842ce8 | 335 | * @brief Sets the LDCR wake up timer counter. Remember that this value is incresead by one in the Twu calculation. |
MACRUM | 0:615f90842ce8 | 336 | * Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us |
MACRUM | 0:615f90842ce8 | 337 | * @param cCounter value for the timer counter. |
MACRUM | 0:615f90842ce8 | 338 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 339 | * @retval None. |
MACRUM | 0:615f90842ce8 | 340 | */ |
MACRUM | 0:615f90842ce8 | 341 | void SpiritTimerSetWakeUpTimerCounter(uint8_t cCounter) |
MACRUM | 0:615f90842ce8 | 342 | { |
MACRUM | 0:615f90842ce8 | 343 | /* Writes the counter value for Wake_Up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 344 | g_xStatus = SpiritSpiWriteRegisters(TIMERS2_LDC_COUNTER_BASE, 1, &cCounter); |
MACRUM | 0:615f90842ce8 | 345 | |
MACRUM | 0:615f90842ce8 | 346 | } |
MACRUM | 0:615f90842ce8 | 347 | |
MACRUM | 0:615f90842ce8 | 348 | |
MACRUM | 0:615f90842ce8 | 349 | /** |
MACRUM | 0:615f90842ce8 | 350 | * @brief Sets the LDCR wake up timer prescaler. Remember that this value is incresead by one in the Twu calculation. |
MACRUM | 0:615f90842ce8 | 351 | * Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us |
MACRUM | 0:615f90842ce8 | 352 | * @param cPrescaler value for the timer prescaler. |
MACRUM | 0:615f90842ce8 | 353 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 354 | * @retval None. |
MACRUM | 0:615f90842ce8 | 355 | */ |
MACRUM | 0:615f90842ce8 | 356 | void SpiritTimerSetWakeUpTimerPrescaler(uint8_t cPrescaler) |
MACRUM | 0:615f90842ce8 | 357 | { |
MACRUM | 0:615f90842ce8 | 358 | /* Writes the prescaler value for Wake_Up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 359 | g_xStatus = SpiritSpiWriteRegisters(TIMERS3_LDC_PRESCALER_BASE, 1, &cPrescaler); |
MACRUM | 0:615f90842ce8 | 360 | |
MACRUM | 0:615f90842ce8 | 361 | } |
MACRUM | 0:615f90842ce8 | 362 | |
MACRUM | 0:615f90842ce8 | 363 | |
MACRUM | 0:615f90842ce8 | 364 | /** |
MACRUM | 0:615f90842ce8 | 365 | * @brief Returns the LDCR wake up timer, according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us. |
MACRUM | 0:615f90842ce8 | 366 | * @param pfWakeUpMsec pointer to the variable in which the wake-up time expressed in milliseconds has to be stored. |
MACRUM | 0:615f90842ce8 | 367 | * This parameter must be a float*. |
MACRUM | 0:615f90842ce8 | 368 | * @param pcCounter pointer to the variable in which the timer counter has to be stored. |
MACRUM | 0:615f90842ce8 | 369 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 370 | * @param pcPrescaler pointer to the variable in which the timer prescaler has to be stored. |
MACRUM | 0:615f90842ce8 | 371 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 372 | * @retval None. |
MACRUM | 0:615f90842ce8 | 373 | */ |
MACRUM | 0:615f90842ce8 | 374 | void SpiritTimerGetWakeUpTimer(float* pfWakeUpMsec, uint8_t* pcCounter , uint8_t* pcPrescaler) |
MACRUM | 0:615f90842ce8 | 375 | { |
MACRUM | 0:615f90842ce8 | 376 | uint8_t tempRegValue[2]; |
MACRUM | 0:615f90842ce8 | 377 | //uint32_t xtal=SpiritRadioGetXtalFrequency(); |
MACRUM | 0:615f90842ce8 | 378 | float rco_freq; |
MACRUM | 0:615f90842ce8 | 379 | |
MACRUM | 0:615f90842ce8 | 380 | rco_freq=(float)SpiritTimerGetRcoFrequency(); |
MACRUM | 0:615f90842ce8 | 381 | |
MACRUM | 0:615f90842ce8 | 382 | /* Reads the Wake_Up timer registers value */ |
MACRUM | 0:615f90842ce8 | 383 | g_xStatus = SpiritSpiReadRegisters(TIMERS3_LDC_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 384 | |
MACRUM | 0:615f90842ce8 | 385 | /* Returns values */ |
MACRUM | 0:615f90842ce8 | 386 | (*pcPrescaler)=tempRegValue[0]; |
MACRUM | 0:615f90842ce8 | 387 | (*pcCounter)=tempRegValue[1]; |
MACRUM | 0:615f90842ce8 | 388 | *pfWakeUpMsec = (float)((((*pcPrescaler)+1)*((*pcCounter)+1)*(1000.0/rco_freq))); |
MACRUM | 0:615f90842ce8 | 389 | |
MACRUM | 0:615f90842ce8 | 390 | } |
MACRUM | 0:615f90842ce8 | 391 | |
MACRUM | 0:615f90842ce8 | 392 | |
MACRUM | 0:615f90842ce8 | 393 | /** |
MACRUM | 0:615f90842ce8 | 394 | * @brief Sets the LDCR wake up timer reloading registers with the values of |
MACRUM | 0:615f90842ce8 | 395 | * COUNTER and PRESCALER according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where |
MACRUM | 0:615f90842ce8 | 396 | * Tck = 28.818 us. The minimum vale of the wakeup timeout is 28.818us (PRESCALER and |
MACRUM | 0:615f90842ce8 | 397 | * COUNTER equals to 0) and the maximum value is about 1.89 s (PRESCALER anc COUNTER equals |
MACRUM | 0:615f90842ce8 | 398 | * to 255). |
MACRUM | 0:615f90842ce8 | 399 | * @param cCounter reload value for the timer counter. |
MACRUM | 0:615f90842ce8 | 400 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 401 | * @param cPrescaler reload value for the timer prescaler. |
MACRUM | 0:615f90842ce8 | 402 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 403 | * @retval None. |
MACRUM | 0:615f90842ce8 | 404 | */ |
MACRUM | 0:615f90842ce8 | 405 | void SpiritTimerSetWakeUpTimerReload(uint8_t cCounter , uint8_t cPrescaler) |
MACRUM | 0:615f90842ce8 | 406 | { |
MACRUM | 0:615f90842ce8 | 407 | uint8_t tempRegValue[2]={cPrescaler,cCounter}; |
MACRUM | 0:615f90842ce8 | 408 | |
MACRUM | 0:615f90842ce8 | 409 | /* Writes the counter and prescaler value of reload wake-up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 410 | g_xStatus = SpiritSpiWriteRegisters(TIMERS1_LDC_RELOAD_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 411 | |
MACRUM | 0:615f90842ce8 | 412 | } |
MACRUM | 0:615f90842ce8 | 413 | |
MACRUM | 0:615f90842ce8 | 414 | |
MACRUM | 0:615f90842ce8 | 415 | /** |
MACRUM | 0:615f90842ce8 | 416 | * @brief Sets the LDCR wake up reload timer counter and prescaler from the desired value in ms, |
MACRUM | 0:615f90842ce8 | 417 | * according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us. |
MACRUM | 0:615f90842ce8 | 418 | * The minimum vale of the wakeup timeout is 28.818us (PRESCALER and COUNTER equals to 0) |
MACRUM | 0:615f90842ce8 | 419 | * and the maximum value is about 1.89 s (PRESCALER anc COUNTER equals to 255). |
MACRUM | 0:615f90842ce8 | 420 | * @param fDesiredMsec desired timer value. |
MACRUM | 0:615f90842ce8 | 421 | * This parameter must be a float. |
MACRUM | 0:615f90842ce8 | 422 | * @retval None. |
MACRUM | 0:615f90842ce8 | 423 | */ |
MACRUM | 0:615f90842ce8 | 424 | void SpiritTimerSetWakeUpTimerReloadMs(float fDesiredMsec) |
MACRUM | 0:615f90842ce8 | 425 | { |
MACRUM | 0:615f90842ce8 | 426 | uint8_t tempRegValue[2]; |
MACRUM | 0:615f90842ce8 | 427 | |
MACRUM | 0:615f90842ce8 | 428 | /* Computes counter and prescaler */ |
MACRUM | 0:615f90842ce8 | 429 | SpiritTimerComputeWakeUpValues(fDesiredMsec , &tempRegValue[1] , &tempRegValue[0]); |
MACRUM | 0:615f90842ce8 | 430 | |
MACRUM | 0:615f90842ce8 | 431 | /* Writes the counter and prescaler value of reload wake-up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 432 | g_xStatus = SpiritSpiWriteRegisters(TIMERS1_LDC_RELOAD_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 433 | |
MACRUM | 0:615f90842ce8 | 434 | } |
MACRUM | 0:615f90842ce8 | 435 | |
MACRUM | 0:615f90842ce8 | 436 | |
MACRUM | 0:615f90842ce8 | 437 | /** |
MACRUM | 0:615f90842ce8 | 438 | * @brief Sets the LDCR wake up timer reload counter. Remember that this value is incresead by one in the Twu calculation. |
MACRUM | 0:615f90842ce8 | 439 | * Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us |
MACRUM | 0:615f90842ce8 | 440 | * @param cCounter value for the timer counter. |
MACRUM | 0:615f90842ce8 | 441 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 442 | * @retval None |
MACRUM | 0:615f90842ce8 | 443 | */ |
MACRUM | 0:615f90842ce8 | 444 | void SpiritTimerSetWakeUpTimerReloadCounter(uint8_t cCounter) |
MACRUM | 0:615f90842ce8 | 445 | { |
MACRUM | 0:615f90842ce8 | 446 | /* Writes the counter value for reload Wake_Up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 447 | g_xStatus = SpiritSpiWriteRegisters(TIMERS0_LDC_RELOAD_COUNTER_BASE, 1, &cCounter); |
MACRUM | 0:615f90842ce8 | 448 | |
MACRUM | 0:615f90842ce8 | 449 | } |
MACRUM | 0:615f90842ce8 | 450 | |
MACRUM | 0:615f90842ce8 | 451 | |
MACRUM | 0:615f90842ce8 | 452 | /** |
MACRUM | 0:615f90842ce8 | 453 | * @brief Sets the LDCR wake up timer reload prescaler. Remember that this value is incresead by one in the Twu calculation. |
MACRUM | 0:615f90842ce8 | 454 | * Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us |
MACRUM | 0:615f90842ce8 | 455 | * @param cPrescaler value for the timer prescaler. |
MACRUM | 0:615f90842ce8 | 456 | * This parameter must be an uint8_t. |
MACRUM | 0:615f90842ce8 | 457 | * @retval None |
MACRUM | 0:615f90842ce8 | 458 | */ |
MACRUM | 0:615f90842ce8 | 459 | void SpiritTimerSetWakeUpTimerReloadPrescaler(uint8_t cPrescaler) |
MACRUM | 0:615f90842ce8 | 460 | { |
MACRUM | 0:615f90842ce8 | 461 | /* Writes the prescaler value for reload Wake_Up timer in the corresponding register */ |
MACRUM | 0:615f90842ce8 | 462 | g_xStatus = SpiritSpiWriteRegisters(TIMERS1_LDC_RELOAD_PRESCALER_BASE, 1, &cPrescaler); |
MACRUM | 0:615f90842ce8 | 463 | |
MACRUM | 0:615f90842ce8 | 464 | } |
MACRUM | 0:615f90842ce8 | 465 | |
MACRUM | 0:615f90842ce8 | 466 | |
MACRUM | 0:615f90842ce8 | 467 | /** |
MACRUM | 0:615f90842ce8 | 468 | * @brief Returns the LDCR wake up reload timer, according to the formula: Twu=(PRESCALER +1)*(COUNTER+1)*Tck, where Tck = 28.818 us. |
MACRUM | 0:615f90842ce8 | 469 | * @param pfWakeUpReloadMsec pointer to the variable in which the wake-up reload time expressed in milliseconds has to be stored. |
MACRUM | 0:615f90842ce8 | 470 | * This parameter must be a float*. |
MACRUM | 0:615f90842ce8 | 471 | * @param pcCounter pointer to the variable in which the timer counter has to be stored. |
MACRUM | 0:615f90842ce8 | 472 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 473 | * @param pcPrescaler pointer to the variable in which the timer prescaler has to be stored. |
MACRUM | 0:615f90842ce8 | 474 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 475 | * @retval None. |
MACRUM | 0:615f90842ce8 | 476 | */ |
MACRUM | 0:615f90842ce8 | 477 | void SpiritTimerGetWakeUpTimerReload(float* pfWakeUpReloadMsec, uint8_t* pcCounter , uint8_t* pcPrescaler) |
MACRUM | 0:615f90842ce8 | 478 | { |
MACRUM | 0:615f90842ce8 | 479 | uint8_t tempRegValue[2]; |
MACRUM | 0:615f90842ce8 | 480 | //uint32_t xtal=SpiritRadioGetXtalFrequency(); |
MACRUM | 0:615f90842ce8 | 481 | float rco_freq; |
MACRUM | 0:615f90842ce8 | 482 | |
MACRUM | 0:615f90842ce8 | 483 | rco_freq=(float)SpiritTimerGetRcoFrequency(); |
MACRUM | 0:615f90842ce8 | 484 | |
MACRUM | 0:615f90842ce8 | 485 | /* Reads the reload Wake_Up timer registers value */ |
MACRUM | 0:615f90842ce8 | 486 | g_xStatus = SpiritSpiReadRegisters(TIMERS1_LDC_RELOAD_PRESCALER_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 487 | |
MACRUM | 0:615f90842ce8 | 488 | /* Returns values */ |
MACRUM | 0:615f90842ce8 | 489 | (*pcPrescaler)=tempRegValue[0]; |
MACRUM | 0:615f90842ce8 | 490 | (*pcCounter)=tempRegValue[1]; |
MACRUM | 0:615f90842ce8 | 491 | *pfWakeUpReloadMsec = (float)((((*pcPrescaler)+1)*((*pcCounter)+1)*(1000.0/rco_freq))); |
MACRUM | 0:615f90842ce8 | 492 | |
MACRUM | 0:615f90842ce8 | 493 | } |
MACRUM | 0:615f90842ce8 | 494 | |
MACRUM | 0:615f90842ce8 | 495 | /** |
MACRUM | 0:615f90842ce8 | 496 | * @brief Computes and returns the RCO frequency. |
MACRUM | 0:615f90842ce8 | 497 | * This frequency depends on the xtal frequency and the XTAL bit in register 0x01. |
MACRUM | 0:615f90842ce8 | 498 | * @retval RCO frequency in Hz as an uint16_t. |
MACRUM | 0:615f90842ce8 | 499 | */ |
MACRUM | 0:615f90842ce8 | 500 | uint16_t SpiritTimerGetRcoFrequency(void) |
MACRUM | 0:615f90842ce8 | 501 | { |
MACRUM | 0:615f90842ce8 | 502 | uint16_t rco_freq=34700; |
MACRUM | 0:615f90842ce8 | 503 | uint32_t xtal=SpiritRadioGetXtalFrequency(); |
MACRUM | 0:615f90842ce8 | 504 | |
MACRUM | 0:615f90842ce8 | 505 | if(xtal>30000000) xtal/=2; |
MACRUM | 0:615f90842ce8 | 506 | |
MACRUM | 0:615f90842ce8 | 507 | if(xtal==25000000) |
MACRUM | 0:615f90842ce8 | 508 | { |
MACRUM | 0:615f90842ce8 | 509 | uint8_t xtal_flag; |
MACRUM | 0:615f90842ce8 | 510 | SpiritSpiReadRegisters(0x01, 1, &xtal_flag); |
MACRUM | 0:615f90842ce8 | 511 | xtal_flag=(xtal_flag&0x40); |
MACRUM | 0:615f90842ce8 | 512 | |
MACRUM | 0:615f90842ce8 | 513 | if(xtal_flag==0) |
MACRUM | 0:615f90842ce8 | 514 | { |
MACRUM | 0:615f90842ce8 | 515 | rco_freq=36100; |
MACRUM | 0:615f90842ce8 | 516 | } |
MACRUM | 0:615f90842ce8 | 517 | else |
MACRUM | 0:615f90842ce8 | 518 | { |
MACRUM | 0:615f90842ce8 | 519 | rco_freq=33300; |
MACRUM | 0:615f90842ce8 | 520 | } |
MACRUM | 0:615f90842ce8 | 521 | } |
MACRUM | 0:615f90842ce8 | 522 | |
MACRUM | 0:615f90842ce8 | 523 | return rco_freq; |
MACRUM | 0:615f90842ce8 | 524 | } |
MACRUM | 0:615f90842ce8 | 525 | |
MACRUM | 0:615f90842ce8 | 526 | /** |
MACRUM | 0:615f90842ce8 | 527 | * @brief Computes the values of the wakeup timer counter and prescaler from the user time expressed in millisecond. |
MACRUM | 0:615f90842ce8 | 528 | * The prescaler and the counter values are computed maintaining the prescaler value as |
MACRUM | 0:615f90842ce8 | 529 | * small as possible in order to obtain the best resolution, and in the meantime minimizing the error. |
MACRUM | 0:615f90842ce8 | 530 | * @param fDesiredMsec desired wakeup timeout in millisecs. |
MACRUM | 0:615f90842ce8 | 531 | * This parameter must be a float. Since the counter and prescaler are 8 bit registers the maximum |
MACRUM | 0:615f90842ce8 | 532 | * reachable value is maxTime = fTclk x 256 x 256. |
MACRUM | 0:615f90842ce8 | 533 | * @param pcCounter pointer to the variable in which the value for the wakeup timer counter has to be stored. |
MACRUM | 0:615f90842ce8 | 534 | * This parameter must be a uint8_t*. |
MACRUM | 0:615f90842ce8 | 535 | * @param pcPrescaler pointer to the variable in which the value for the wakeup timer prescaler has to be stored. |
MACRUM | 0:615f90842ce8 | 536 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 537 | * @retval None |
MACRUM | 0:615f90842ce8 | 538 | */ |
MACRUM | 0:615f90842ce8 | 539 | void SpiritTimerComputeWakeUpValues(float fDesiredMsec , uint8_t* pcCounter , uint8_t* pcPrescaler) |
MACRUM | 0:615f90842ce8 | 540 | { |
MACRUM | 0:615f90842ce8 | 541 | float rco_freq,err; |
MACRUM | 0:615f90842ce8 | 542 | uint32_t n; |
MACRUM | 0:615f90842ce8 | 543 | |
MACRUM | 0:615f90842ce8 | 544 | rco_freq=((float)SpiritTimerGetRcoFrequency())/1000; |
MACRUM | 0:615f90842ce8 | 545 | |
MACRUM | 0:615f90842ce8 | 546 | /* N cycles in the time base of the timer: |
MACRUM | 0:615f90842ce8 | 547 | - clock of the timer is RCO frequency |
MACRUM | 0:615f90842ce8 | 548 | - divide times 1000 more because we have an input in ms (variable rco_freq is already this frequency divided by 1000) |
MACRUM | 0:615f90842ce8 | 549 | */ |
MACRUM | 0:615f90842ce8 | 550 | n=(uint32_t)(fDesiredMsec*rco_freq); |
MACRUM | 0:615f90842ce8 | 551 | |
MACRUM | 0:615f90842ce8 | 552 | /* check if it is possible to reach that target with prescaler and counter of spirit1 */ |
MACRUM | 0:615f90842ce8 | 553 | if(n/0xFF>0xFD) |
MACRUM | 0:615f90842ce8 | 554 | { |
MACRUM | 0:615f90842ce8 | 555 | /* if not return the maximum possible value */ |
MACRUM | 0:615f90842ce8 | 556 | (*pcCounter) = 0xFF; |
MACRUM | 0:615f90842ce8 | 557 | (*pcPrescaler) = 0xFF; |
MACRUM | 0:615f90842ce8 | 558 | return; |
MACRUM | 0:615f90842ce8 | 559 | } |
MACRUM | 0:615f90842ce8 | 560 | |
MACRUM | 0:615f90842ce8 | 561 | /* prescaler is really 2 as min value */ |
MACRUM | 0:615f90842ce8 | 562 | (*pcPrescaler)=(n/0xFF)+2; |
MACRUM | 0:615f90842ce8 | 563 | (*pcCounter) = n / (*pcPrescaler); |
MACRUM | 0:615f90842ce8 | 564 | |
MACRUM | 0:615f90842ce8 | 565 | /* check if the error is minimum */ |
MACRUM | 0:615f90842ce8 | 566 | err=S_ABS((float)(*pcCounter)*(*pcPrescaler)/rco_freq-fDesiredMsec); |
MACRUM | 0:615f90842ce8 | 567 | |
MACRUM | 0:615f90842ce8 | 568 | if((*pcCounter)<=254) |
MACRUM | 0:615f90842ce8 | 569 | { |
MACRUM | 0:615f90842ce8 | 570 | if(S_ABS((float)((*pcCounter)+1)*(*pcPrescaler)/rco_freq-fDesiredMsec)<err) |
MACRUM | 0:615f90842ce8 | 571 | (*pcCounter)=(*pcCounter)+1; |
MACRUM | 0:615f90842ce8 | 572 | } |
MACRUM | 0:615f90842ce8 | 573 | |
MACRUM | 0:615f90842ce8 | 574 | /* decrement prescaler and counter according to the logic of this timer in spirit1 */ |
MACRUM | 0:615f90842ce8 | 575 | (*pcPrescaler)--; |
MACRUM | 0:615f90842ce8 | 576 | if((*pcCounter)>1) |
MACRUM | 0:615f90842ce8 | 577 | (*pcCounter)--; |
MACRUM | 0:615f90842ce8 | 578 | else |
MACRUM | 0:615f90842ce8 | 579 | (*pcCounter)=1; |
MACRUM | 0:615f90842ce8 | 580 | } |
MACRUM | 0:615f90842ce8 | 581 | |
MACRUM | 0:615f90842ce8 | 582 | |
MACRUM | 0:615f90842ce8 | 583 | /** |
MACRUM | 0:615f90842ce8 | 584 | * @brief Computes the values of the rx_timeout timer counter and prescaler from the user time expressed in millisecond. |
MACRUM | 0:615f90842ce8 | 585 | * The prescaler and the counter values are computed maintaining the prescaler value as |
MACRUM | 0:615f90842ce8 | 586 | * small as possible in order to obtain the best resolution, and in the meantime minimizing the error. |
MACRUM | 0:615f90842ce8 | 587 | * @param fDesiredMsec desired rx_timeout in millisecs. |
MACRUM | 0:615f90842ce8 | 588 | * This parameter must be a float. Since the counter and prescaler are 8 bit registers the maximum |
MACRUM | 0:615f90842ce8 | 589 | * reachable value is maxTime = fTclk x 255 x 255. |
MACRUM | 0:615f90842ce8 | 590 | * @param pcCounter pointer to the variable in which the value for the rx_timeout counter has to be stored. |
MACRUM | 0:615f90842ce8 | 591 | * This parameter must be a uint8_t*. |
MACRUM | 0:615f90842ce8 | 592 | * @param pcPrescaler pointer to the variable in which the value for the rx_timeout prescaler has to be stored. |
MACRUM | 0:615f90842ce8 | 593 | * This parameter must be an uint8_t*. |
MACRUM | 0:615f90842ce8 | 594 | * @retval None |
MACRUM | 0:615f90842ce8 | 595 | */ |
MACRUM | 0:615f90842ce8 | 596 | void SpiritTimerComputeRxTimeoutValues(float fDesiredMsec , uint8_t* pcCounter , uint8_t* pcPrescaler) |
MACRUM | 0:615f90842ce8 | 597 | { |
MACRUM | 0:615f90842ce8 | 598 | uint32_t nXtalFrequency = SpiritRadioGetXtalFrequency(); |
MACRUM | 0:615f90842ce8 | 599 | uint32_t n; |
MACRUM | 0:615f90842ce8 | 600 | float err; |
MACRUM | 0:615f90842ce8 | 601 | |
MACRUM | 0:615f90842ce8 | 602 | /* if xtal is doubled divide it by 2 */ |
MACRUM | 0:615f90842ce8 | 603 | if(nXtalFrequency>DOUBLE_XTAL_THR) { |
MACRUM | 0:615f90842ce8 | 604 | nXtalFrequency >>= 1; |
MACRUM | 0:615f90842ce8 | 605 | } |
MACRUM | 0:615f90842ce8 | 606 | |
MACRUM | 0:615f90842ce8 | 607 | /* N cycles in the time base of the timer: |
MACRUM | 0:615f90842ce8 | 608 | - clock of the timer is xtal/1210 |
MACRUM | 0:615f90842ce8 | 609 | - divide times 1000 more because we have an input in ms |
MACRUM | 0:615f90842ce8 | 610 | */ |
MACRUM | 0:615f90842ce8 | 611 | n=(uint32_t)(fDesiredMsec*nXtalFrequency/1210000); |
MACRUM | 0:615f90842ce8 | 612 | |
MACRUM | 0:615f90842ce8 | 613 | /* check if it is possible to reach that target with prescaler and counter of spirit1 */ |
MACRUM | 0:615f90842ce8 | 614 | if(n/0xFF>0xFD) |
MACRUM | 0:615f90842ce8 | 615 | { |
MACRUM | 0:615f90842ce8 | 616 | /* if not return the maximum possible value */ |
MACRUM | 0:615f90842ce8 | 617 | (*pcCounter) = 0xFF; |
MACRUM | 0:615f90842ce8 | 618 | (*pcPrescaler) = 0xFF; |
MACRUM | 0:615f90842ce8 | 619 | return; |
MACRUM | 0:615f90842ce8 | 620 | } |
MACRUM | 0:615f90842ce8 | 621 | |
MACRUM | 0:615f90842ce8 | 622 | /* prescaler is really 2 as min value */ |
MACRUM | 0:615f90842ce8 | 623 | (*pcPrescaler)=(n/0xFF)+2; |
MACRUM | 0:615f90842ce8 | 624 | (*pcCounter) = n / (*pcPrescaler); |
MACRUM | 0:615f90842ce8 | 625 | |
MACRUM | 0:615f90842ce8 | 626 | /* check if the error is minimum */ |
MACRUM | 0:615f90842ce8 | 627 | err=S_ABS((float)(*pcCounter)*(*pcPrescaler)*1210000/nXtalFrequency-fDesiredMsec); |
MACRUM | 0:615f90842ce8 | 628 | |
MACRUM | 0:615f90842ce8 | 629 | if((*pcCounter)<=254) |
MACRUM | 0:615f90842ce8 | 630 | { |
MACRUM | 0:615f90842ce8 | 631 | if(S_ABS((float)((*pcCounter)+1)*(*pcPrescaler)*1210000/nXtalFrequency-fDesiredMsec)<err) |
MACRUM | 0:615f90842ce8 | 632 | (*pcCounter)=(*pcCounter)+1; |
MACRUM | 0:615f90842ce8 | 633 | } |
MACRUM | 0:615f90842ce8 | 634 | |
MACRUM | 0:615f90842ce8 | 635 | /* decrement prescaler and counter according to the logic of this timer in spirit1 */ |
MACRUM | 0:615f90842ce8 | 636 | (*pcPrescaler)--; |
MACRUM | 0:615f90842ce8 | 637 | if((*pcCounter)>1) |
MACRUM | 0:615f90842ce8 | 638 | (*pcCounter)--; |
MACRUM | 0:615f90842ce8 | 639 | else |
MACRUM | 0:615f90842ce8 | 640 | (*pcCounter)=1; |
MACRUM | 0:615f90842ce8 | 641 | } |
MACRUM | 0:615f90842ce8 | 642 | |
MACRUM | 0:615f90842ce8 | 643 | |
MACRUM | 0:615f90842ce8 | 644 | /** |
MACRUM | 0:615f90842ce8 | 645 | * @brief Sets the RX timeout stop conditions. |
MACRUM | 0:615f90842ce8 | 646 | * @param xStopCondition new stop condition. |
MACRUM | 0:615f90842ce8 | 647 | * This parameter can be any value of @ref RxTimeoutStopCondition. |
MACRUM | 0:615f90842ce8 | 648 | * @retval None |
MACRUM | 0:615f90842ce8 | 649 | */ |
MACRUM | 0:615f90842ce8 | 650 | void SpiritTimerSetRxTimeoutStopCondition(RxTimeoutStopCondition xStopCondition) |
MACRUM | 0:615f90842ce8 | 651 | { |
MACRUM | 0:615f90842ce8 | 652 | uint8_t tempRegValue[2]; |
MACRUM | 0:615f90842ce8 | 653 | |
MACRUM | 0:615f90842ce8 | 654 | /* Check the parameters */ |
MACRUM | 0:615f90842ce8 | 655 | s_assert_param(IS_RX_TIMEOUT_STOP_CONDITION(xStopCondition)); |
MACRUM | 0:615f90842ce8 | 656 | |
MACRUM | 0:615f90842ce8 | 657 | /* Reads value on the PKT_FLT_OPTIONS and PROTOCOL2 register */ |
MACRUM | 0:615f90842ce8 | 658 | g_xStatus = SpiritSpiReadRegisters(PCKT_FLT_OPTIONS_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 659 | |
MACRUM | 0:615f90842ce8 | 660 | tempRegValue[0] &= 0xBF; |
MACRUM | 0:615f90842ce8 | 661 | tempRegValue[0] |= ((xStopCondition & 0x08) << 3); |
MACRUM | 0:615f90842ce8 | 662 | |
MACRUM | 0:615f90842ce8 | 663 | tempRegValue[1] &= 0x1F; |
MACRUM | 0:615f90842ce8 | 664 | tempRegValue[1] |= (xStopCondition << 5); |
MACRUM | 0:615f90842ce8 | 665 | |
MACRUM | 0:615f90842ce8 | 666 | /* Writes value on the PKT_FLT_OPTIONS and PROTOCOL2 register */ |
MACRUM | 0:615f90842ce8 | 667 | g_xStatus = SpiritSpiWriteRegisters(PCKT_FLT_OPTIONS_BASE, 2, tempRegValue); |
MACRUM | 0:615f90842ce8 | 668 | |
MACRUM | 0:615f90842ce8 | 669 | } |
MACRUM | 0:615f90842ce8 | 670 | |
MACRUM | 0:615f90842ce8 | 671 | /** |
MACRUM | 0:615f90842ce8 | 672 | * @brief Sends the LDC_RELOAD command to SPIRIT. Reload the LDC timer with the value stored in the LDC_PRESCALER / COUNTER registers. |
MACRUM | 0:615f90842ce8 | 673 | * @param None. |
MACRUM | 0:615f90842ce8 | 674 | * @retval None |
MACRUM | 0:615f90842ce8 | 675 | */ |
MACRUM | 0:615f90842ce8 | 676 | void SpiritTimerReloadStrobe(void) |
MACRUM | 0:615f90842ce8 | 677 | { |
MACRUM | 0:615f90842ce8 | 678 | /* Sends the CMD_LDC_RELOAD command */ |
MACRUM | 0:615f90842ce8 | 679 | g_xStatus = SpiritSpiCommandStrobes(COMMAND_LDC_RELOAD); |
MACRUM | 0:615f90842ce8 | 680 | |
MACRUM | 0:615f90842ce8 | 681 | } |
MACRUM | 0:615f90842ce8 | 682 | |
MACRUM | 0:615f90842ce8 | 683 | |
MACRUM | 0:615f90842ce8 | 684 | /** |
MACRUM | 0:615f90842ce8 | 685 | *@} |
MACRUM | 0:615f90842ce8 | 686 | */ |
MACRUM | 0:615f90842ce8 | 687 | |
MACRUM | 0:615f90842ce8 | 688 | |
MACRUM | 0:615f90842ce8 | 689 | /** |
MACRUM | 0:615f90842ce8 | 690 | *@} |
MACRUM | 0:615f90842ce8 | 691 | */ |
MACRUM | 0:615f90842ce8 | 692 | |
MACRUM | 0:615f90842ce8 | 693 | |
MACRUM | 0:615f90842ce8 | 694 | /** |
MACRUM | 0:615f90842ce8 | 695 | *@} |
MACRUM | 0:615f90842ce8 | 696 | */ |
MACRUM | 0:615f90842ce8 | 697 | |
MACRUM | 0:615f90842ce8 | 698 | |
MACRUM | 0:615f90842ce8 | 699 | |
MACRUM | 0:615f90842ce8 | 700 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |