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