fix LPC812 PWM
Fork of mbed-dev by
targets/cmsis/TARGET_STM/TARGET_STM32F7/stm32f7xx_hal_sai_ex.c@0:9b334a45a8ff, 2015-10-01 (annotated)
- Committer:
- bogdanm
- Date:
- Thu Oct 01 15:25:22 2015 +0300
- Revision:
- 0:9b334a45a8ff
- Child:
- 83:a036322b8637
Initial commit on mbed-dev
Replaces mbed-src (now inactive)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /** |
bogdanm | 0:9b334a45a8ff | 2 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 3 | * @file stm32f7xx_hal_sai_ex.c |
bogdanm | 0:9b334a45a8ff | 4 | * @author MCD Application Team |
bogdanm | 0:9b334a45a8ff | 5 | * @version V1.0.1 |
bogdanm | 0:9b334a45a8ff | 6 | * @date 25-June-2015 |
bogdanm | 0:9b334a45a8ff | 7 | * @brief SAI Extension HAL module driver. |
bogdanm | 0:9b334a45a8ff | 8 | * This file provides firmware functions to manage the following |
bogdanm | 0:9b334a45a8ff | 9 | * functionalities of SAI extension peripheral: |
bogdanm | 0:9b334a45a8ff | 10 | * + Extension features functions |
bogdanm | 0:9b334a45a8ff | 11 | * |
bogdanm | 0:9b334a45a8ff | 12 | @verbatim |
bogdanm | 0:9b334a45a8ff | 13 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 14 | ##### SAI peripheral extension features ##### |
bogdanm | 0:9b334a45a8ff | 15 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 16 | |
bogdanm | 0:9b334a45a8ff | 17 | ##### How to use this driver ##### |
bogdanm | 0:9b334a45a8ff | 18 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 19 | [..] This driver provides functions to manage several sources to clock SAI |
bogdanm | 0:9b334a45a8ff | 20 | |
bogdanm | 0:9b334a45a8ff | 21 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 22 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 23 | * @attention |
bogdanm | 0:9b334a45a8ff | 24 | * |
bogdanm | 0:9b334a45a8ff | 25 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
bogdanm | 0:9b334a45a8ff | 26 | * |
bogdanm | 0:9b334a45a8ff | 27 | * Redistribution and use in source and binary forms, with or without modification, |
bogdanm | 0:9b334a45a8ff | 28 | * are permitted provided that the following conditions are met: |
bogdanm | 0:9b334a45a8ff | 29 | * 1. Redistributions of source code must retain the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 30 | * this list of conditions and the following disclaimer. |
bogdanm | 0:9b334a45a8ff | 31 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 32 | * this list of conditions and the following disclaimer in the documentation |
bogdanm | 0:9b334a45a8ff | 33 | * and/or other materials provided with the distribution. |
bogdanm | 0:9b334a45a8ff | 34 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
bogdanm | 0:9b334a45a8ff | 35 | * may be used to endorse or promote products derived from this software |
bogdanm | 0:9b334a45a8ff | 36 | * without specific prior written permission. |
bogdanm | 0:9b334a45a8ff | 37 | * |
bogdanm | 0:9b334a45a8ff | 38 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
bogdanm | 0:9b334a45a8ff | 39 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
bogdanm | 0:9b334a45a8ff | 40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bogdanm | 0:9b334a45a8ff | 41 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
bogdanm | 0:9b334a45a8ff | 42 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
bogdanm | 0:9b334a45a8ff | 43 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
bogdanm | 0:9b334a45a8ff | 44 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
bogdanm | 0:9b334a45a8ff | 45 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
bogdanm | 0:9b334a45a8ff | 46 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
bogdanm | 0:9b334a45a8ff | 47 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bogdanm | 0:9b334a45a8ff | 48 | * |
bogdanm | 0:9b334a45a8ff | 49 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 50 | */ |
bogdanm | 0:9b334a45a8ff | 51 | |
bogdanm | 0:9b334a45a8ff | 52 | /* Includes ------------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 53 | #include "stm32f7xx_hal.h" |
bogdanm | 0:9b334a45a8ff | 54 | |
bogdanm | 0:9b334a45a8ff | 55 | /** @addtogroup STM32F7xx_HAL_Driver |
bogdanm | 0:9b334a45a8ff | 56 | * @{ |
bogdanm | 0:9b334a45a8ff | 57 | */ |
bogdanm | 0:9b334a45a8ff | 58 | |
bogdanm | 0:9b334a45a8ff | 59 | /** @defgroup SAIEx SAIEx |
bogdanm | 0:9b334a45a8ff | 60 | * @brief SAI Extension HAL module driver |
bogdanm | 0:9b334a45a8ff | 61 | * @{ |
bogdanm | 0:9b334a45a8ff | 62 | */ |
bogdanm | 0:9b334a45a8ff | 63 | |
bogdanm | 0:9b334a45a8ff | 64 | #ifdef HAL_SAI_MODULE_ENABLED |
bogdanm | 0:9b334a45a8ff | 65 | |
bogdanm | 0:9b334a45a8ff | 66 | /* Private typedef -----------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 67 | /* Private define ------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 68 | /* SAI registers Masks */ |
bogdanm | 0:9b334a45a8ff | 69 | /* Private macro -------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 70 | /* Private variables ---------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 71 | /* Private function prototypes -----------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 72 | /* Private functions ---------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 73 | |
bogdanm | 0:9b334a45a8ff | 74 | /** @defgroup SAI_Private_Functions SAI Private Functions |
bogdanm | 0:9b334a45a8ff | 75 | * @{ |
bogdanm | 0:9b334a45a8ff | 76 | */ |
bogdanm | 0:9b334a45a8ff | 77 | /** |
bogdanm | 0:9b334a45a8ff | 78 | * @} |
bogdanm | 0:9b334a45a8ff | 79 | */ |
bogdanm | 0:9b334a45a8ff | 80 | |
bogdanm | 0:9b334a45a8ff | 81 | /* Exported functions --------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 82 | /** @defgroup SAIEx_Exported_Functions SAI Extended Exported Functions |
bogdanm | 0:9b334a45a8ff | 83 | * @{ |
bogdanm | 0:9b334a45a8ff | 84 | */ |
bogdanm | 0:9b334a45a8ff | 85 | |
bogdanm | 0:9b334a45a8ff | 86 | /** @defgroup SAIEx_Exported_Functions_Group1 Extension features functions |
bogdanm | 0:9b334a45a8ff | 87 | * @brief Extension features functions |
bogdanm | 0:9b334a45a8ff | 88 | * |
bogdanm | 0:9b334a45a8ff | 89 | @verbatim |
bogdanm | 0:9b334a45a8ff | 90 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 91 | ##### Extension features Functions ##### |
bogdanm | 0:9b334a45a8ff | 92 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 93 | [..] |
bogdanm | 0:9b334a45a8ff | 94 | This subsection provides a set of functions allowing to manage the possible |
bogdanm | 0:9b334a45a8ff | 95 | SAI clock sources. |
bogdanm | 0:9b334a45a8ff | 96 | |
bogdanm | 0:9b334a45a8ff | 97 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 98 | * @{ |
bogdanm | 0:9b334a45a8ff | 99 | */ |
bogdanm | 0:9b334a45a8ff | 100 | |
bogdanm | 0:9b334a45a8ff | 101 | /** |
bogdanm | 0:9b334a45a8ff | 102 | * @brief Configure SAI Block synchronization mode |
bogdanm | 0:9b334a45a8ff | 103 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 104 | * the configuration information for SAI module. |
bogdanm | 0:9b334a45a8ff | 105 | * @retval SAI Clock Input |
bogdanm | 0:9b334a45a8ff | 106 | */ |
bogdanm | 0:9b334a45a8ff | 107 | void SAI_BlockSynchroConfig(SAI_HandleTypeDef *hsai) |
bogdanm | 0:9b334a45a8ff | 108 | { |
bogdanm | 0:9b334a45a8ff | 109 | uint32_t tmpregisterGCR = 0; |
bogdanm | 0:9b334a45a8ff | 110 | |
bogdanm | 0:9b334a45a8ff | 111 | /* This setting must be done with both audio block (A & B) disabled */ |
bogdanm | 0:9b334a45a8ff | 112 | switch(hsai->Init.SynchroExt) |
bogdanm | 0:9b334a45a8ff | 113 | { |
bogdanm | 0:9b334a45a8ff | 114 | case SAI_SYNCEXT_DISABLE : |
bogdanm | 0:9b334a45a8ff | 115 | tmpregisterGCR = 0; |
bogdanm | 0:9b334a45a8ff | 116 | break; |
bogdanm | 0:9b334a45a8ff | 117 | case SAI_SYNCEXT_IN_ENABLE : |
bogdanm | 0:9b334a45a8ff | 118 | tmpregisterGCR = SAI_GCR_SYNCIN_0; |
bogdanm | 0:9b334a45a8ff | 119 | break; |
bogdanm | 0:9b334a45a8ff | 120 | case SAI_SYNCEXT_OUTBLOCKA_ENABLE : |
bogdanm | 0:9b334a45a8ff | 121 | tmpregisterGCR = SAI_GCR_SYNCOUT_0; |
bogdanm | 0:9b334a45a8ff | 122 | break; |
bogdanm | 0:9b334a45a8ff | 123 | case SAI_SYNCEXT_OUTBLOCKB_ENABLE : |
bogdanm | 0:9b334a45a8ff | 124 | tmpregisterGCR = SAI_GCR_SYNCOUT_1; |
bogdanm | 0:9b334a45a8ff | 125 | break; |
bogdanm | 0:9b334a45a8ff | 126 | default : |
bogdanm | 0:9b334a45a8ff | 127 | break; |
bogdanm | 0:9b334a45a8ff | 128 | } |
bogdanm | 0:9b334a45a8ff | 129 | |
bogdanm | 0:9b334a45a8ff | 130 | if((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B)) |
bogdanm | 0:9b334a45a8ff | 131 | { |
bogdanm | 0:9b334a45a8ff | 132 | SAI1->GCR = tmpregisterGCR; |
bogdanm | 0:9b334a45a8ff | 133 | } |
bogdanm | 0:9b334a45a8ff | 134 | else |
bogdanm | 0:9b334a45a8ff | 135 | { |
bogdanm | 0:9b334a45a8ff | 136 | SAI2->GCR = tmpregisterGCR; |
bogdanm | 0:9b334a45a8ff | 137 | } |
bogdanm | 0:9b334a45a8ff | 138 | } |
bogdanm | 0:9b334a45a8ff | 139 | /** |
bogdanm | 0:9b334a45a8ff | 140 | * @brief Get SAI Input Clock based on SAI source clock selection |
bogdanm | 0:9b334a45a8ff | 141 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 142 | * the configuration information for SAI module. |
bogdanm | 0:9b334a45a8ff | 143 | * @retval SAI Clock Input |
bogdanm | 0:9b334a45a8ff | 144 | */ |
bogdanm | 0:9b334a45a8ff | 145 | uint32_t SAI_GetInputClock(SAI_HandleTypeDef *hsai) |
bogdanm | 0:9b334a45a8ff | 146 | { |
bogdanm | 0:9b334a45a8ff | 147 | /* This variable used to store the SAI_CK_x (value in Hz) */ |
bogdanm | 0:9b334a45a8ff | 148 | uint32_t saiclocksource = 0; |
bogdanm | 0:9b334a45a8ff | 149 | |
bogdanm | 0:9b334a45a8ff | 150 | if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B)) |
bogdanm | 0:9b334a45a8ff | 151 | { |
bogdanm | 0:9b334a45a8ff | 152 | saiclocksource = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI1); |
bogdanm | 0:9b334a45a8ff | 153 | } |
bogdanm | 0:9b334a45a8ff | 154 | else /* SAI2_Block_A || SAI2_Block_B*/ |
bogdanm | 0:9b334a45a8ff | 155 | { |
bogdanm | 0:9b334a45a8ff | 156 | saiclocksource = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI2); |
bogdanm | 0:9b334a45a8ff | 157 | } |
bogdanm | 0:9b334a45a8ff | 158 | /* the return result is the value of SAI clock */ |
bogdanm | 0:9b334a45a8ff | 159 | return saiclocksource; |
bogdanm | 0:9b334a45a8ff | 160 | } |
bogdanm | 0:9b334a45a8ff | 161 | |
bogdanm | 0:9b334a45a8ff | 162 | /** |
bogdanm | 0:9b334a45a8ff | 163 | * @} |
bogdanm | 0:9b334a45a8ff | 164 | */ |
bogdanm | 0:9b334a45a8ff | 165 | |
bogdanm | 0:9b334a45a8ff | 166 | /** |
bogdanm | 0:9b334a45a8ff | 167 | * @} |
bogdanm | 0:9b334a45a8ff | 168 | */ |
bogdanm | 0:9b334a45a8ff | 169 | |
bogdanm | 0:9b334a45a8ff | 170 | #endif /* HAL_SAI_MODULE_ENABLED */ |
bogdanm | 0:9b334a45a8ff | 171 | /** |
bogdanm | 0:9b334a45a8ff | 172 | * @} |
bogdanm | 0:9b334a45a8ff | 173 | */ |
bogdanm | 0:9b334a45a8ff | 174 | |
bogdanm | 0:9b334a45a8ff | 175 | /** |
bogdanm | 0:9b334a45a8ff | 176 | * @} |
bogdanm | 0:9b334a45a8ff | 177 | */ |
bogdanm | 0:9b334a45a8ff | 178 | |
bogdanm | 0:9b334a45a8ff | 179 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |