JunMo Hong / stm-spirit1-rf-driver_for_cubebite

Fork of EV-COG-AD3029LZ by JunMo Hong

Committer:
Wolfgang Betz
Date:
Tue Nov 22 11:40:10 2016 +0100
Revision:
34:edda6a7238ec
Child:
67:93bec0baf1de
Perform re-naming

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 34:edda6a7238ec 1 /**
Wolfgang Betz 34:edda6a7238ec 2 ******************************************************************************
Wolfgang Betz 34:edda6a7238ec 3 * @file SPIRIT_Timer.h
Wolfgang Betz 34:edda6a7238ec 4 * @author VMA division - AMS
Wolfgang Betz 34:edda6a7238ec 5 * @version 3.2.2
Wolfgang Betz 34:edda6a7238ec 6 * @date 08-July-2015
Wolfgang Betz 34:edda6a7238ec 7 * @brief Configuration and management of SPIRIT timers.
Wolfgang Betz 34:edda6a7238ec 8 * @details
Wolfgang Betz 34:edda6a7238ec 9 *
Wolfgang Betz 34:edda6a7238ec 10 * This module provides API to configure the Spirit timing mechanisms.
Wolfgang Betz 34:edda6a7238ec 11 * They allow the user to set the timer registers using raw values or
Wolfgang Betz 34:edda6a7238ec 12 * compute them since the desired timer value is expressed in ms.
Wolfgang Betz 34:edda6a7238ec 13 * Moreover the management of the Spirit LDCR mode can be done using
Wolfgang Betz 34:edda6a7238ec 14 * these API.
Wolfgang Betz 34:edda6a7238ec 15 *
Wolfgang Betz 34:edda6a7238ec 16 * <b>Example:</b>
Wolfgang Betz 34:edda6a7238ec 17 * @code
Wolfgang Betz 34:edda6a7238ec 18 * ...
Wolfgang Betz 34:edda6a7238ec 19 *
Wolfgang Betz 34:edda6a7238ec 20 * SpiritTimerSetRxTimeoutMs(50.0);
Wolfgang Betz 34:edda6a7238ec 21 * SpiritTimerSetWakeUpTimerMs(150.0);
Wolfgang Betz 34:edda6a7238ec 22 *
Wolfgang Betz 34:edda6a7238ec 23 * // IRQ configuration for RX_TIMEOUT and WAKEUP_TIMEOUT
Wolfgang Betz 34:edda6a7238ec 24 * ...
Wolfgang Betz 34:edda6a7238ec 25 *
Wolfgang Betz 34:edda6a7238ec 26 * SpiritTimerLdcrMode(S_ENABLE);
Wolfgang Betz 34:edda6a7238ec 27 *
Wolfgang Betz 34:edda6a7238ec 28 * ...
Wolfgang Betz 34:edda6a7238ec 29 *
Wolfgang Betz 34:edda6a7238ec 30 * @endcode
Wolfgang Betz 34:edda6a7238ec 31 *
Wolfgang Betz 34:edda6a7238ec 32 *
Wolfgang Betz 34:edda6a7238ec 33 * @attention
Wolfgang Betz 34:edda6a7238ec 34 *
Wolfgang Betz 34:edda6a7238ec 35 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Wolfgang Betz 34:edda6a7238ec 36 *
Wolfgang Betz 34:edda6a7238ec 37 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 34:edda6a7238ec 38 * are permitted provided that the following conditions are met:
Wolfgang Betz 34:edda6a7238ec 39 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 34:edda6a7238ec 40 * this list of conditions and the following disclaimer.
Wolfgang Betz 34:edda6a7238ec 41 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 34:edda6a7238ec 42 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 34:edda6a7238ec 43 * and/or other materials provided with the distribution.
Wolfgang Betz 34:edda6a7238ec 44 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 34:edda6a7238ec 45 * may be used to endorse or promote products derived from this software
Wolfgang Betz 34:edda6a7238ec 46 * without specific prior written permission.
Wolfgang Betz 34:edda6a7238ec 47 *
Wolfgang Betz 34:edda6a7238ec 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 34:edda6a7238ec 49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 34:edda6a7238ec 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 34:edda6a7238ec 51 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 34:edda6a7238ec 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 34:edda6a7238ec 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 34:edda6a7238ec 54 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 34:edda6a7238ec 55 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 34:edda6a7238ec 56 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 34:edda6a7238ec 57 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 34:edda6a7238ec 58 *
Wolfgang Betz 34:edda6a7238ec 59 ******************************************************************************
Wolfgang Betz 34:edda6a7238ec 60 */
Wolfgang Betz 34:edda6a7238ec 61
Wolfgang Betz 34:edda6a7238ec 62 /* Define to prevent recursive inclusion -------------------------------------*/
Wolfgang Betz 34:edda6a7238ec 63 #ifndef __SPIRIT1_TIMER_H
Wolfgang Betz 34:edda6a7238ec 64 #define __SPIRIT1_TIMER_H
Wolfgang Betz 34:edda6a7238ec 65
Wolfgang Betz 34:edda6a7238ec 66
Wolfgang Betz 34:edda6a7238ec 67 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 34:edda6a7238ec 68
Wolfgang Betz 34:edda6a7238ec 69 #include "SPIRIT_Regs.h"
Wolfgang Betz 34:edda6a7238ec 70 #include "SPIRIT_Types.h"
Wolfgang Betz 34:edda6a7238ec 71
Wolfgang Betz 34:edda6a7238ec 72
Wolfgang Betz 34:edda6a7238ec 73 #ifdef __cplusplus
Wolfgang Betz 34:edda6a7238ec 74 extern "C" {
Wolfgang Betz 34:edda6a7238ec 75 #endif
Wolfgang Betz 34:edda6a7238ec 76
Wolfgang Betz 34:edda6a7238ec 77
Wolfgang Betz 34:edda6a7238ec 78 /**
Wolfgang Betz 34:edda6a7238ec 79 * @addtogroup SPIRIT_Libraries
Wolfgang Betz 34:edda6a7238ec 80 * @{
Wolfgang Betz 34:edda6a7238ec 81 */
Wolfgang Betz 34:edda6a7238ec 82
Wolfgang Betz 34:edda6a7238ec 83
Wolfgang Betz 34:edda6a7238ec 84 /**
Wolfgang Betz 34:edda6a7238ec 85 * @defgroup SPIRIT_Timer Timer
Wolfgang Betz 34:edda6a7238ec 86 * @brief Configuration and management of SPIRIT Timers.
Wolfgang Betz 34:edda6a7238ec 87 * @details See the file <i>@ref SPIRIT_Timer.h</i> for more details.
Wolfgang Betz 34:edda6a7238ec 88 * @{
Wolfgang Betz 34:edda6a7238ec 89 */
Wolfgang Betz 34:edda6a7238ec 90
Wolfgang Betz 34:edda6a7238ec 91
Wolfgang Betz 34:edda6a7238ec 92 /**
Wolfgang Betz 34:edda6a7238ec 93 * @defgroup Timer_Exported_Types Timer Exported Types
Wolfgang Betz 34:edda6a7238ec 94 * @{
Wolfgang Betz 34:edda6a7238ec 95 */
Wolfgang Betz 34:edda6a7238ec 96
Wolfgang Betz 34:edda6a7238ec 97 /**
Wolfgang Betz 34:edda6a7238ec 98 * @brief All the possible RX timeout stop conditions enumeration.
Wolfgang Betz 34:edda6a7238ec 99 */
Wolfgang Betz 34:edda6a7238ec 100 typedef enum{
Wolfgang Betz 34:edda6a7238ec 101
Wolfgang Betz 34:edda6a7238ec 102 NO_TIMEOUT_STOP = 0x00, /*!< Timeout never stopped */
Wolfgang Betz 34:edda6a7238ec 103 TIMEOUT_ALWAYS_STOPPED = 0x08, /*!< Timeout always stopped (default) */
Wolfgang Betz 34:edda6a7238ec 104 RSSI_ABOVE_THRESHOLD = 0x04, /*!< Timeout stopped on RSSI above threshold */
Wolfgang Betz 34:edda6a7238ec 105 SQI_ABOVE_THRESHOLD = 0x02, /*!< Timeout stopped on SQI above threshold */
Wolfgang Betz 34:edda6a7238ec 106 PQI_ABOVE_THRESHOLD = 0x01, /*!< Timeout stopped on PQI above threshold */
Wolfgang Betz 34:edda6a7238ec 107 RSSI_AND_SQI_ABOVE_THRESHOLD = 0x06, /*!< Timeout stopped on both RSSI and SQI above threshold */
Wolfgang Betz 34:edda6a7238ec 108 RSSI_AND_PQI_ABOVE_THRESHOLD = 0x05, /*!< Timeout stopped on both RSSI and PQI above threshold */
Wolfgang Betz 34:edda6a7238ec 109 SQI_AND_PQI_ABOVE_THRESHOLD = 0x03, /*!< Timeout stopped on both SQI and PQI above threshold */
Wolfgang Betz 34:edda6a7238ec 110 ALL_ABOVE_THRESHOLD = 0x07, /*!< Timeout stopped only if RSSI, SQI and PQI are above threshold */
Wolfgang Betz 34:edda6a7238ec 111 RSSI_OR_SQI_ABOVE_THRESHOLD = 0x0E, /*!< Timeout stopped if one between RSSI or SQI are above threshold */
Wolfgang Betz 34:edda6a7238ec 112 RSSI_OR_PQI_ABOVE_THRESHOLD = 0x0D, /*!< Timeout stopped if one between RSSI or PQI are above threshold */
Wolfgang Betz 34:edda6a7238ec 113 SQI_OR_PQI_ABOVE_THRESHOLD = 0x0B, /*!< Timeout stopped if one between SQI or PQI are above threshold */
Wolfgang Betz 34:edda6a7238ec 114 ANY_ABOVE_THRESHOLD = 0x0F /*!< Timeout stopped if one among RSSI, SQI or SQI are above threshold */
Wolfgang Betz 34:edda6a7238ec 115
Wolfgang Betz 34:edda6a7238ec 116 } RxTimeoutStopCondition;
Wolfgang Betz 34:edda6a7238ec 117
Wolfgang Betz 34:edda6a7238ec 118
Wolfgang Betz 34:edda6a7238ec 119 #define IS_RX_TIMEOUT_STOP_CONDITION(COND) ( COND == NO_TIMEOUT_STOP || \
Wolfgang Betz 34:edda6a7238ec 120 COND == TIMEOUT_ALWAYS_STOPPED || \
Wolfgang Betz 34:edda6a7238ec 121 COND == RSSI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 122 COND == SQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 123 COND == PQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 124 COND == RSSI_AND_SQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 125 COND == RSSI_AND_PQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 126 COND == SQI_AND_PQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 127 COND == ALL_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 128 COND == RSSI_OR_SQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 129 COND == RSSI_OR_PQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 130 COND == SQI_OR_PQI_ABOVE_THRESHOLD || \
Wolfgang Betz 34:edda6a7238ec 131 COND == ANY_ABOVE_THRESHOLD )
Wolfgang Betz 34:edda6a7238ec 132
Wolfgang Betz 34:edda6a7238ec 133
Wolfgang Betz 34:edda6a7238ec 134
Wolfgang Betz 34:edda6a7238ec 135 /**
Wolfgang Betz 34:edda6a7238ec 136 * @}
Wolfgang Betz 34:edda6a7238ec 137 */
Wolfgang Betz 34:edda6a7238ec 138
Wolfgang Betz 34:edda6a7238ec 139
Wolfgang Betz 34:edda6a7238ec 140 /**
Wolfgang Betz 34:edda6a7238ec 141 * @defgroup Timer_Exported_Constants Timer Exported Constants
Wolfgang Betz 34:edda6a7238ec 142 * @{
Wolfgang Betz 34:edda6a7238ec 143 */
Wolfgang Betz 34:edda6a7238ec 144
Wolfgang Betz 34:edda6a7238ec 145 /**
Wolfgang Betz 34:edda6a7238ec 146 * @brief It represents the Time Step for RX_Timeout timer in case of 24 MHz Crystal, expressed in us.
Wolfgang Betz 34:edda6a7238ec 147 * It is equal to 1210/(24*10^6). With this time step it is possible to fix the RX_Timeout to
Wolfgang Betz 34:edda6a7238ec 148 * a minimum value of 50.417us to a maximum value of about 3.278 s.
Wolfgang Betz 34:edda6a7238ec 149 * Remember that it is possible to have infinite RX_Timeout writing 0 in the RX_Timeout_Counter and/or RX_Timeout_Prescaler registers.
Wolfgang Betz 34:edda6a7238ec 150 */
Wolfgang Betz 34:edda6a7238ec 151 #define RX_TCLK_24MHz 50.417f
Wolfgang Betz 34:edda6a7238ec 152 #define IS_RX_TIMEOUT_24MHz(TIMEOUT) (TIMEOUT*1000)>=RX_TCLK_24MHz
Wolfgang Betz 34:edda6a7238ec 153
Wolfgang Betz 34:edda6a7238ec 154 /**
Wolfgang Betz 34:edda6a7238ec 155 * @brief It represents the Time Step for RX_Timeout timer in case of 26 MHz Crystal, expressed in us.
Wolfgang Betz 34:edda6a7238ec 156 * It is equal to 1210/(26*10^6). With this time step it is possible to fix the RX_Timeout to
Wolfgang Betz 34:edda6a7238ec 157 * a minimum value of 46.538us to a maximum value of about 3.026 s.
Wolfgang Betz 34:edda6a7238ec 158 * Remember that it is possible to have infinite RX_Timeout writing 0 in the RX_Timeout_Counter register.
Wolfgang Betz 34:edda6a7238ec 159 */
Wolfgang Betz 34:edda6a7238ec 160 #define RX_TCLK_26MHz 46.538f
Wolfgang Betz 34:edda6a7238ec 161 #define IS_RX_TIMEOUT_26MHz(TIMEOUT) (TIMEOUT*1000)>=RX_TCLK_26MHz
Wolfgang Betz 34:edda6a7238ec 162
Wolfgang Betz 34:edda6a7238ec 163 /**
Wolfgang Betz 34:edda6a7238ec 164 * @brief It represents the Time Step for RX_Wakeup timer expressed in us. This timer is based on RCO (about 34.7 kHZ).
Wolfgang Betz 34:edda6a7238ec 165 * With this time step it is possible to fix the Wakeup_Timeout to a minimum value of 28.818us to a maximum
Wolfgang Betz 34:edda6a7238ec 166 * value of about 1.888 s.
Wolfgang Betz 34:edda6a7238ec 167 */
Wolfgang Betz 34:edda6a7238ec 168 #define WAKEUP_TCLK 28.818f
Wolfgang Betz 34:edda6a7238ec 169 #define IS_WKUP_TIMEOUT(TIMEOUT) (TIMEOUT*1000)>=WAKEUP_TCLK
Wolfgang Betz 34:edda6a7238ec 170
Wolfgang Betz 34:edda6a7238ec 171
Wolfgang Betz 34:edda6a7238ec 172
Wolfgang Betz 34:edda6a7238ec 173 /**
Wolfgang Betz 34:edda6a7238ec 174 * @}
Wolfgang Betz 34:edda6a7238ec 175 */
Wolfgang Betz 34:edda6a7238ec 176
Wolfgang Betz 34:edda6a7238ec 177
Wolfgang Betz 34:edda6a7238ec 178 /**
Wolfgang Betz 34:edda6a7238ec 179 * @defgroup Timer_Exported_Macros Timer Exported Macros
Wolfgang Betz 34:edda6a7238ec 180 * @{
Wolfgang Betz 34:edda6a7238ec 181 */
Wolfgang Betz 34:edda6a7238ec 182
Wolfgang Betz 34:edda6a7238ec 183 #define SET_INFINITE_RX_TIMEOUT() SpiritTimerSetRxTimeoutCounter(0)
Wolfgang Betz 34:edda6a7238ec 184
Wolfgang Betz 34:edda6a7238ec 185 /**
Wolfgang Betz 34:edda6a7238ec 186 * @}
Wolfgang Betz 34:edda6a7238ec 187 */
Wolfgang Betz 34:edda6a7238ec 188
Wolfgang Betz 34:edda6a7238ec 189
Wolfgang Betz 34:edda6a7238ec 190 /**
Wolfgang Betz 34:edda6a7238ec 191 * @defgroup Timer_Exported_Functions Timer Exported Functions
Wolfgang Betz 34:edda6a7238ec 192 * @{
Wolfgang Betz 34:edda6a7238ec 193 */
Wolfgang Betz 34:edda6a7238ec 194
Wolfgang Betz 34:edda6a7238ec 195 void SpiritTimerLdcrMode(SpiritFunctionalState xNewState);
Wolfgang Betz 34:edda6a7238ec 196 void SpiritTimerLdcrAutoReload(SpiritFunctionalState xNewState);
Wolfgang Betz 34:edda6a7238ec 197 SpiritFunctionalState SpiritTimerLdcrGetAutoReload(void);
Wolfgang Betz 34:edda6a7238ec 198 void SpiritTimerSetRxTimeout(uint8_t cCounter , uint8_t cPrescaler);
Wolfgang Betz 34:edda6a7238ec 199 void SpiritTimerSetRxTimeoutMs(float fDesiredMsec);
Wolfgang Betz 34:edda6a7238ec 200 void SpiritTimerSetRxTimeoutCounter(uint8_t cCounter);
Wolfgang Betz 34:edda6a7238ec 201 void SpiritTimerSetRxTimeoutPrescaler(uint8_t cPrescaler);
Wolfgang Betz 34:edda6a7238ec 202 void SpiritTimerGetRxTimeout(float* pfTimeoutMsec, uint8_t* pcCounter , uint8_t* pcPrescaler);
Wolfgang Betz 34:edda6a7238ec 203 void SpiritTimerSetWakeUpTimer(uint8_t cCounter , uint8_t cPrescaler);
Wolfgang Betz 34:edda6a7238ec 204 void SpiritTimerSetWakeUpTimerMs(float fDesiredMsec);
Wolfgang Betz 34:edda6a7238ec 205 void SpiritTimerSetWakeUpTimerCounter(uint8_t cCounter);
Wolfgang Betz 34:edda6a7238ec 206 void SpiritTimerSetWakeUpTimerPrescaler(uint8_t cPrescaler);
Wolfgang Betz 34:edda6a7238ec 207 void SpiritTimerSetWakeUpTimerReloadMs(float fDesiredMsec);
Wolfgang Betz 34:edda6a7238ec 208 void SpiritTimerGetWakeUpTimer(float* pfWakeUpMsec, uint8_t* pcCounter , uint8_t* pcPrescaler);
Wolfgang Betz 34:edda6a7238ec 209 void SpiritTimerSetWakeUpTimerReload(uint8_t cCounter , uint8_t cPrescaler);
Wolfgang Betz 34:edda6a7238ec 210 void SpiritTimerSetWakeUpTimerReloadCounter(uint8_t cCounter);
Wolfgang Betz 34:edda6a7238ec 211 void SpiritTimerSetWakeUpTimerReloadPrescaler(uint8_t cPrescaler);
Wolfgang Betz 34:edda6a7238ec 212 void SpiritTimerGetWakeUpTimerReload(float* pfWakeUpReloadMsec, uint8_t* pcCounter , uint8_t* pcPrescaler);
Wolfgang Betz 34:edda6a7238ec 213 void SpiritTimerComputeWakeUpValues(float fDesiredMsec , uint8_t* pcCounter , uint8_t* pcPrescaler);
Wolfgang Betz 34:edda6a7238ec 214 void SpiritTimerComputeRxTimeoutValues(float fDesiredMsec , uint8_t* pcCounter , uint8_t* pcPrescaler);
Wolfgang Betz 34:edda6a7238ec 215 void SpiritTimerSetRxTimeoutStopCondition(RxTimeoutStopCondition xStopCondition);
Wolfgang Betz 34:edda6a7238ec 216 void SpiritTimerReloadStrobe(void);
Wolfgang Betz 34:edda6a7238ec 217 uint16_t SpiritTimerGetRcoFrequency(void);
Wolfgang Betz 34:edda6a7238ec 218
Wolfgang Betz 34:edda6a7238ec 219 /**
Wolfgang Betz 34:edda6a7238ec 220 * @}
Wolfgang Betz 34:edda6a7238ec 221 */
Wolfgang Betz 34:edda6a7238ec 222
Wolfgang Betz 34:edda6a7238ec 223 /**
Wolfgang Betz 34:edda6a7238ec 224 * @}
Wolfgang Betz 34:edda6a7238ec 225 */
Wolfgang Betz 34:edda6a7238ec 226
Wolfgang Betz 34:edda6a7238ec 227
Wolfgang Betz 34:edda6a7238ec 228 /**
Wolfgang Betz 34:edda6a7238ec 229 * @}
Wolfgang Betz 34:edda6a7238ec 230 */
Wolfgang Betz 34:edda6a7238ec 231
Wolfgang Betz 34:edda6a7238ec 232 #ifdef __cplusplus
Wolfgang Betz 34:edda6a7238ec 233 }
Wolfgang Betz 34:edda6a7238ec 234 #endif
Wolfgang Betz 34:edda6a7238ec 235
Wolfgang Betz 34:edda6a7238ec 236 #endif
Wolfgang Betz 34:edda6a7238ec 237
Wolfgang Betz 34:edda6a7238ec 238 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
Wolfgang Betz 34:edda6a7238ec 239