Easily add all supported connectivity methods to your mbed OS project

Dependencies:   type-yd-driver

Committer:
MACRUM
Date:
Wed Jul 12 10:52:58 2017 +0000
Revision:
0:615f90842ce8
Initial commit

Who changed what in which revision?

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