annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_sai.c @ 96:6eec2db15cf8 kittz

Sorry. Now.
author Dmitry Romanov <kitt@bk.ru>
date Mon, 26 Nov 2018 13:45:14 +0300
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_sai.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief SAI HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Serial Audio Interface (SAI) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Initialization/de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + I/O operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 The SAI HAL driver can be used as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 (#) Declare a SAI_HandleTypeDef handle structure.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 (#) Initialize the SAI low level resources by implementing the HAL_SAI_MspInit() API:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (##) Enable the SAI interface clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 (##) SAI pins configuration:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 (+++) Enable the clock for the SAI GPIOs.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 (+++) Configure these SAI pins as alternate function pull-up.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (##) NVIC configuration if you need to use interrupt process (HAL_SAI_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 and HAL_SAI_Receive_IT() APIs):
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+++) Configure the SAI interrupt priority.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 (+++) Enable the NVIC SAI IRQ handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (##) DMA Configuration if you need to use DMA process (HAL_SAI_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 and HAL_SAI_Receive_DMA() APIs):
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 (+++) Declare a DMA handle structure for the Tx/Rx stream.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (+++) Enable the DMAx interface clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 (+++) Configure the DMA Tx/Rx Stream.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 (+++) Associate the initialized DMA handle to the SAI DMA Tx/Rx handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 DMA Tx/Rx Stream.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 (#) Program the SAI Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 using HAL_SAI_Init() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 -@- The specific SAI interrupts (FIFO request and Overrun underrun interrupt)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 will be managed using the macros __SAI_ENABLE_IT() and __SAI_DISABLE_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 inside the transmit and receive process.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 (@) Make sure that either:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 (+@) I2S PLL is configured or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 (+@) SAI PLL is configured or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 (+@) External clock source is configured after setting correctly
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 the define constant EXTERNAL_CLOCK_VALUE in the stm32f4xx_hal_conf.h file.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 (@) In master Tx mode: enabling the audio block immediately generates the bit clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 for the external slaves even if there is no data in the FIFO, However FS signal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 generation is conditioned by the presence of data in the FIFO.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 (@) In master Rx mode: enabling the audio block immediately generates the bit clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 and FS signal for the external slaves.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 (@) It is mandatory to respect the following conditions in order to avoid bad SAI behavior:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 (+@) First bit Offset <= (SLOT size - Data size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 (+@) Data size <= SLOT size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 (+@) Number of SLOT x SLOT size = Frame length
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 (+@) The number of slots should be even when SAI_FS_CHANNEL_IDENTIFICATION is selected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 Three operation modes are available within this driver :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 *** Polling mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 =================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 (+) Send an amount of data in blocking mode using HAL_SAI_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 (+) Receive an amount of data in blocking mode using HAL_SAI_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 *** Interrupt mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 ===================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 (+) Send an amount of data in non blocking mode using HAL_SAI_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 (+) At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 add his own code by customization of function pointer HAL_SAI_TxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 (+) Receive an amount of data in non blocking mode using HAL_SAI_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 (+) At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 add his own code by customization of function pointer HAL_SAI_RxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 (+) In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 add his own code by customization of function pointer HAL_SAI_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 *** DMA mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 ==============================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 (+) Send an amount of data in non blocking mode (DMA) using HAL_SAI_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 (+) At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 add his own code by customization of function pointer HAL_SAI_TxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 (+) Receive an amount of data in non blocking mode (DMA) using HAL_SAI_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 (+) At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 add his own code by customization of function pointer HAL_SAI_RxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 (+) In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 add his own code by customization of function pointer HAL_SAI_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 (+) Pause the DMA Transfer using HAL_SAI_DMAPause()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 (+) Resume the DMA Transfer using HAL_SAI_DMAResume()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 (+) Stop the DMA Transfer using HAL_SAI_DMAStop()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 *** SAI HAL driver macros list ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 =============================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 Below the list of most used macros in USART HAL driver :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 (+) __HAL_SAI_ENABLE: Enable the SAI peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 (+) __HAL_SAI_DISABLE: Disable the SAI peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 (+) __HAL_SAI_ENABLE_IT : Enable the specified SAI interrupts
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 (+) __HAL_SAI_DISABLE_IT : Disable the specified SAI interrupts
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 (+) __HAL_SAI_GET_IT_SOURCE: Check if the specified SAI interrupt source is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 (+) __HAL_SAI_GET_FLAG: Check whether the specified SAI flag is set or not
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 /** @defgroup SAI SAI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 * @brief SAI HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 #ifdef HAL_SAI_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 /* SAI registers Masks */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 #define CR1_CLEAR_MASK ((uint32_t)0xFF07C010)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 #define FRCR_CLEAR_MASK ((uint32_t)0xFFF88000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 #define SLOTR_CLEAR_MASK ((uint32_t)0x0000F020)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 #define SAI_TIMEOUT_VALUE 10
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 static void SAI_DMATxCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 static void SAI_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 static void SAI_DMARxCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 static void SAI_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 static void SAI_DMAError(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 /** @defgroup SAI_Private_Functions SAI Private Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 /** @defgroup SAI_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 [..] This subsection provides a set of functions allowing to initialize and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 de-initialize the SAIx peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 (+) User must implement HAL_SAI_MspInit() function in which he configures
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 (+) Call the function HAL_SAI_Init() to configure the selected device with
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 the selected configuration:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 (++) Mode (Master/slave TX/RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 (++) Protocol
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 (++) Data Size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 (++) MCLK Output
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 (++) Audio frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 (++) FIFO Threshold
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 (++) Frame Config
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 (++) Slot Config
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 (+) Call the function HAL_SAI_DeInit() to restore the default configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 of the selected SAI peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 * @brief Initializes the SAI according to the specified parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 * in the SAI_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 uint32_t tmpclock = 0, tmp2clock = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 /* This variable used to store the VCO Input (value in Hz) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 uint32_t vcoinput = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 /* This variable used to store the SAI_CK_x (value in Hz) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 uint32_t saiclocksource = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 /* Check the SAI handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 if(hsai == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 /* Check the SAI Block parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 assert_param(IS_SAI_BLOCK_PROTOCOL(hsai->Init.Protocol));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 assert_param(IS_SAI_BLOCK_MODE(hsai->Init.AudioMode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 assert_param(IS_SAI_BLOCK_DATASIZE(hsai->Init.DataSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 assert_param(IS_SAI_BLOCK_FIRST_BIT(hsai->Init.FirstBit));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 assert_param(IS_SAI_BLOCK_CLOCK_STROBING(hsai->Init.ClockStrobing));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 assert_param(IS_SAI_BLOCK_SYNCHRO(hsai->Init.Synchro));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 assert_param(IS_SAI_BLOCK_OUTPUT_DRIVE(hsai->Init.OutputDrive));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 assert_param(IS_SAI_BLOCK_NODIVIDER(hsai->Init.NoDivider));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 assert_param(IS_SAI_BLOCK_FIFO_THRESHOLD(hsai->Init.FIFOThreshold));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 assert_param(IS_SAI_AUDIO_FREQUENCY(hsai->Init.AudioFrequency));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 /* Check the SAI Block Frame parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 assert_param(IS_SAI_BLOCK_FRAME_LENGTH(hsai->FrameInit.FrameLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 assert_param(IS_SAI_BLOCK_ACTIVE_FRAME(hsai->FrameInit.ActiveFrameLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 assert_param(IS_SAI_BLOCK_FS_DEFINITION(hsai->FrameInit.FSDefinition));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 assert_param(IS_SAI_BLOCK_FS_POLARITY(hsai->FrameInit.FSPolarity));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 assert_param(IS_SAI_BLOCK_FS_OFFSET(hsai->FrameInit.FSOffset));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 /* Check the SAI Block Slot parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 assert_param(IS_SAI_BLOCK_FIRSTBIT_OFFSET(hsai->SlotInit.FirstBitOffset));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 assert_param(IS_SAI_BLOCK_SLOT_SIZE(hsai->SlotInit.SlotSize));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 assert_param(IS_SAI_BLOCK_SLOT_NUMBER(hsai->SlotInit.SlotNumber));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 assert_param(IS_SAI_SLOT_ACTIVE(hsai->SlotInit.SlotActive));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 if(hsai->State == HAL_SAI_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 HAL_SAI_MspInit(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 hsai->State = HAL_SAI_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 /* Disable the selected SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 __HAL_SAI_DISABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 /* SAI Block Configuration ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 /* SAI Block_x CR1 Configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 /* Get the SAI Block_x CR1 value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 tmpreg = hsai->Instance->CR1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 /* Clear MODE, PRTCFG, DS, LSBFIRST, CKSTR, SYNCEN, OUTDRIV, NODIV, and MCKDIV bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 tmpreg &= CR1_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 /* Configure SAI_Block_x: Audio Protocol, Data Size, first transmitted bit, Clock strobing
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 edge, Synchronization mode, Output drive, Master Divider and FIFO level */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 /* Set PRTCFG bits according to Protocol value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 /* Set DS bits according to DataSize value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 /* Set LSBFIRST bit according to FirstBit value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 /* Set CKSTR bit according to ClockStrobing value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 /* Set SYNCEN bit according to Synchro value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 /* Set OUTDRIV bit according to OutputDrive value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 /* Set NODIV bit according to NoDivider value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 tmpreg |= (uint32_t)(hsai->Init.Protocol |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 hsai->Init.AudioMode |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 hsai->Init.DataSize |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 hsai->Init.FirstBit |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 hsai->Init.ClockStrobing |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 hsai->Init.Synchro |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 hsai->Init.OutputDrive |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 hsai->Init.NoDivider);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 /* Write to SAI_Block_x CR1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 hsai->Instance->CR1 = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 /* SAI Block_x CR2 Configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 /* Get the SAIBlock_x CR2 value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 tmpreg = hsai->Instance->CR2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 /* Clear FTH bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 tmpreg &= ~(SAI_xCR2_FTH);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 /* Configure the FIFO Level */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 /* Set FTH bits according to SAI_FIFOThreshold value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 tmpreg |= (uint32_t)(hsai->Init.FIFOThreshold);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 /* Write to SAI_Block_x CR2 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 hsai->Instance->CR2 = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 /* SAI Block_x Frame Configuration -----------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 /* Get the SAI Block_x FRCR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 tmpreg = hsai->Instance->FRCR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 /* Clear FRL, FSALL, FSDEF, FSPOL, FSOFF bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 tmpreg &= FRCR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 /* Configure SAI_Block_x Frame: Frame Length, Active Frame Length, Frame Synchronization
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 Definition, Frame Synchronization Polarity and Frame Synchronization Polarity */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 /* Set FRL bits according to SAI_FrameLength value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 /* Set FSALL bits according to SAI_ActiveFrameLength value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 /* Set FSDEF bit according to SAI_FSDefinition value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 /* Set FSPOL bit according to SAI_FSPolarity value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 /* Set FSOFF bit according to SAI_FSOffset value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 tmpreg |= (uint32_t)((uint32_t)(hsai->FrameInit.FrameLength - 1) |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 hsai->FrameInit.FSOffset |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 hsai->FrameInit.FSDefinition |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 hsai->FrameInit.FSPolarity |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 (uint32_t)((hsai->FrameInit.ActiveFrameLength - 1) << 8));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 /* Write to SAI_Block_x FRCR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 hsai->Instance->FRCR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 /* SAI Block_x SLOT Configuration ------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 /* Get the SAI Block_x SLOTR value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 tmpreg = hsai->Instance->SLOTR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 /* Clear FBOFF, SLOTSZ, NBSLOT, SLOTEN bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 tmpreg &= SLOTR_CLEAR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 /* Configure SAI_Block_x Slot: First bit offset, Slot size, Number of Slot in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 audio frame and slots activated in audio frame */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 /* Set FBOFF bits according to SAI_FirstBitOffset value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 /* Set SLOTSZ bits according to SAI_SlotSize value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 /* Set NBSLOT bits according to SAI_SlotNumber value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 /* Set SLOTEN bits according to SAI_SlotActive value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 tmpreg |= (uint32_t)(hsai->SlotInit.FirstBitOffset |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 hsai->SlotInit.SlotSize |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 hsai->SlotInit.SlotActive |
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 (uint32_t)((hsai->SlotInit.SlotNumber - 1) << 8));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 /* Write to SAI_Block_x SLOTR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 hsai->Instance->SLOTR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 /* SAI Block_x Clock Configuration -----------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /* Check the Clock parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 assert_param(IS_SAI_CLK_SOURCE(hsai->Init.ClockSource));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 /* SAI Block clock source selection */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 if(hsai->Instance == SAI1_Block_A)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 __HAL_RCC_SAI_BLOCKACLKSOURCE_CONFIG(hsai->Init.ClockSource);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 __HAL_RCC_SAI_BLOCKBCLKSOURCE_CONFIG((uint32_t)(hsai->Init.ClockSource << 2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 /* VCO Input Clock value calculation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 /* In Case the PLL Source is HSI (Internal Clock) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 /* In Case the PLL Source is HSE (External Clock) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 /* SAI_CLK_x : SAI Block Clock configuration for different clock sources selected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 if(hsai->Init.ClockSource == SAI_CLKSOURCE_PLLSAI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 /* Configure the PLLI2S division factor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 saiclocksource = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6))/(tmpreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 tmpreg = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> 8) + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 saiclocksource = saiclocksource/(tmpreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 else if(hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 /* Configure the PLLI2S division factor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 saiclocksource = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6))/(tmpreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 tmpreg = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 saiclocksource = saiclocksource/(tmpreg);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 else /* sConfig->ClockSource == SAI_CLKSource_Ext */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 /* Enable the External Clock selection */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 __HAL_RCC_I2S_CONFIG(RCC_I2SCLKSOURCE_EXT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 saiclocksource = EXTERNAL_CLOCK_VALUE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 /* Configure Master Clock using the following formula :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 MCLK_x = SAI_CK_x / (MCKDIV[3:0] * 2) with MCLK_x = 256 * FS
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 FS = SAI_CK_x / (MCKDIV[3:0] * 2) * 256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 MCKDIV[3:0] = SAI_CK_x / FS * 512 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 if(hsai->Init.NoDivider == SAI_MASTERDIVIDER_ENABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 /* (saiclocksource x 10) to keep Significant digits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 tmpclock = (((saiclocksource * 10) / ((hsai->Init.AudioFrequency) * 512)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 /* Get the result of modulo division */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 tmp2clock = (tmpclock % 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 /* Round result to the nearest integer*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 if (tmp2clock > 8)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 tmpclock = ((tmpclock / 10) + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 tmpclock = (tmpclock / 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 /*Set MCKDIV value in CR1 register*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 hsai->Instance->CR1 |= (tmpclock << 20);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 /* Initialize the error code */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 hsai->ErrorCode = HAL_SAI_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /* Initialize the SAI state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 hsai->State= HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 * @brief DeInitializes the SAI peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 HAL_StatusTypeDef HAL_SAI_DeInit(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 /* Check the SAI handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 if(hsai == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 hsai->State = HAL_SAI_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 HAL_SAI_MspDeInit(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 /* Initialize the error code */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 hsai->ErrorCode = HAL_SAI_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 /* Initialize the SAI state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 hsai->State = HAL_SAI_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 /* Release Lock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 * @brief SAI MSP Init.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 __weak void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 the HAL_SAI_MspInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 * @brief SAI MSP DeInit.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 __weak void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 the HAL_SAI_MspDeInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 /** @defgroup SAI_Exported_Functions_Group2 IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 * @brief Data transfers functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 ##### IO operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 This subsection provides a set of functions allowing to manage the SAI data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 transfers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 (+) There are two modes of transfer:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 (++) Blocking mode : The communication is performed in the polling mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 The status of all data processing is returned by the same function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 after finishing transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 (++) No-Blocking mode : The communication is performed using Interrupts
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 or DMA. These functions return the status of the transfer startup.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 The end of the data processing will be indicated through the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 dedicated SAI IRQ when using Interrupt mode or the DMA IRQ when
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 using DMA mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 (+) Blocking mode functions are :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 (++) HAL_SAI_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 (++) HAL_SAI_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 (++) HAL_SAI_TransmitReceive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 (+) Non Blocking mode functions with Interrupt are :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 (++) HAL_SAI_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 (++) HAL_SAI_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 (++) HAL_SAI_TransmitReceive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 (+) Non Blocking mode functions with DMA are :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 (++) HAL_SAI_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 (++) HAL_SAI_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 (++) HAL_SAI_TransmitReceive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 (+) A set of Transfer Complete Callbacks are provided in non Blocking mode:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 (++) HAL_SAI_TxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 (++) HAL_SAI_RxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 (++) HAL_SAI_ErrorCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 * @brief Transmits an amount of data in blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint16_t* pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 if(hsai->State == HAL_SAI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 hsai->State = HAL_SAI_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 /* Check if the SAI is already enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 /* Enable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 __HAL_SAI_ENABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 /* Wait the FIFO to be empty */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 while(__HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 /* Update error code */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 /* Change the SAI state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 hsai->State = HAL_SAI_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 hsai->Instance->DR = (*pData++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 * @brief Receives an amount of data in blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 * @param Size: Amount of data to be received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 if(hsai->State == HAL_SAI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 hsai->State = HAL_SAI_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 /* Check if the SAI is already enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 /* Enable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 __HAL_SAI_ENABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 /* Receive data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 while(Size > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 /* Wait until RXNE flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 while(__HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 /* Update error code */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 /* Change the SAI state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 hsai->State = HAL_SAI_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 (*pData++) = hsai->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 Size--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 * @brief Transmits an amount of data in no-blocking mode with Interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 if(hsai->State == HAL_SAI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 hsai->pTxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 hsai->TxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 hsai->TxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 hsai->State = HAL_SAI_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 /* Transmit data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 hsai->Instance->DR = (*hsai->pTxBuffPtr++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 hsai->TxXferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 /* Enable FRQ and OVRUDR interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 __HAL_SAI_ENABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 /* Check if the SAI is already enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 /* Enable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 __HAL_SAI_ENABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 else if(hsai->State == HAL_SAI_STATE_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 /* Transmit data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 hsai->Instance->DR = (*hsai->pTxBuffPtr++);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 hsai->TxXferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 if(hsai->TxXferCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 /* Disable FREQ and OVRUDR interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 __HAL_SAI_DISABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 HAL_SAI_TxCpltCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 * @brief Receives an amount of data in no-blocking mode with Interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 * @param Size: Amount of data to be received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 if(hsai->State == HAL_SAI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 hsai->pRxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 hsai->RxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 hsai->RxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 hsai->State = HAL_SAI_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 /* Enable TXE and OVRUDR interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 __HAL_SAI_ENABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 /* Check if the SAI is already enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 /* Enable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 __HAL_SAI_ENABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 else if(hsai->State == HAL_SAI_STATE_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 /* Receive data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 (*hsai->pRxBuffPtr++) = hsai->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 hsai->RxXferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 if(hsai->RxXferCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 /* Disable TXE and OVRUDR interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 __HAL_SAI_DISABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 HAL_SAI_RxCpltCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 * @brief Pauses the audio stream playing from the Media.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 /* Pause the audio file playing by disabling the SAI DMA requests */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 * @brief Resumes the audio stream playing from the Media.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 /* Enable the SAI DMA requests */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 hsai->Instance->CR1 |= SAI_xCR1_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 /* If the SAI peripheral is still not enabled, enable it */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 /* Enable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 __HAL_SAI_ENABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 * @brief Stops the audio stream playing from the Media.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 /* Disable the SAI DMA request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 /* Abort the SAI DMA Tx Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 if(hsai->hdmatx != NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 HAL_DMA_Abort(hsai->hdmatx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 /* Abort the SAI DMA Rx Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 if(hsai->hdmarx != NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 HAL_DMA_Abort(hsai->hdmarx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 /* Disable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 __HAL_SAI_DISABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 * @brief Transmits an amount of data in no-blocking mode with DMA.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 uint32_t *tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 if(hsai->State == HAL_SAI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 hsai->pTxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 hsai->TxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 hsai->TxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 hsai->State = HAL_SAI_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 /* Set the SAI Tx DMA Half transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 hsai->hdmatx->XferHalfCpltCallback = SAI_DMATxHalfCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 /* Set the SAI TxDMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 hsai->hdmatx->XferCpltCallback = SAI_DMATxCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 hsai->hdmatx->XferErrorCallback = SAI_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 /* Enable the Tx DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 tmp = (uint32_t*)&pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 HAL_DMA_Start_IT(hsai->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsai->Instance->DR, hsai->TxXferSize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 /* Check if the SAI is already enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 /* Enable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 __HAL_SAI_ENABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 /* Enable SAI Tx DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 hsai->Instance->CR1 |= SAI_xCR1_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 * @brief Receives an amount of data in no-blocking mode with DMA.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 * @param Size: Amount of data to be received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 uint32_t *tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 if((pData == NULL) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 if(hsai->State == HAL_SAI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 hsai->pRxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 hsai->RxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 hsai->RxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 __HAL_LOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 hsai->State = HAL_SAI_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 /* Set the SAI Rx DMA Half transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 hsai->hdmarx->XferHalfCpltCallback = SAI_DMARxHalfCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 /* Set the SAI Rx DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 hsai->hdmarx->XferCpltCallback = SAI_DMARxCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 hsai->hdmarx->XferErrorCallback = SAI_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 /* Enable the Rx DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 tmp = (uint32_t*)&pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 HAL_DMA_Start_IT(hsai->hdmarx, (uint32_t)&hsai->Instance->DR, *(uint32_t*)tmp, hsai->RxXferSize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 /* Check if the SAI is already enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 /* Enable SAI peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 __HAL_SAI_ENABLE(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 /* Enable SAI Rx DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 hsai->Instance->CR1 |= SAI_xCR1_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 __HAL_UNLOCK(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 * @brief This function handles SAI interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 uint32_t tmp1 = 0, tmp2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 if(hsai->State == HAL_SAI_STATE_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_FREQ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 /* SAI in mode Receiver --------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 HAL_SAI_Receive_IT(hsai, NULL, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_FLAG_OVRUDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_OVRUDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 /* SAI Overrun error interrupt occurred ----------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 /* Change the SAI error code */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 hsai->ErrorCode = HAL_SAI_ERROR_OVR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 /* Clear the SAI Overrun flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 /* Set the SAI state ready to be able to start again the process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 HAL_SAI_ErrorCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 if(hsai->State == HAL_SAI_STATE_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_FREQ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 /* SAI in mode Transmitter -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 HAL_SAI_Transmit_IT(hsai, NULL, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_FLAG_OVRUDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_OVRUDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 /* SAI Underrun error interrupt occurred ---------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 /* Change the SAI error code */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 hsai->ErrorCode = HAL_SAI_ERROR_UDR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 /* Clear the SAI Underrun flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 /* Set the SAI state ready to be able to start again the process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 HAL_SAI_ErrorCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 * @brief Tx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 __weak void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 the HAL_SAI_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 * @brief Tx Transfer Half completed callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 __weak void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 the HAL_SAI_TxHalfCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 * @brief Rx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 __weak void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 the HAL_SAI_RxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 * @brief Rx Transfer half completed callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 __weak void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 the HAL_SAI_RxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 * @brief SAI error callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 __weak void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 the HAL_SAI_ErrorCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 /** @defgroup SAI_Exported_Functions_Group3 Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 * @brief Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 ##### Peripheral State and Errors functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 This subsection permits to get in run-time the status of the peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 and the data flow.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 * @brief Returns the SAI state.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 * @param hsai: pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 * the configuration information for SAI module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 return hsai->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 * @brief Return the SAI error code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 * @param hsai : pointer to a SAI_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 * the configuration information for the specified SAI Block.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 * @retval SAI Error Code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 return hsai->ErrorCode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 * @brief DMA SAI transmit process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 static void SAI_DMATxCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 hsai->TxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 hsai->RxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 /* Disable SAI Tx DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 /* Set timeout: 10 is the max delay to send the remaining data in the SAI FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 /* Wait until FIFO is empty */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 while(__HAL_SAI_GET_FLAG(hsai, SAI_xSR_FLVL) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 if((HAL_GetTick() - tickstart ) > SAI_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 /* Update error code */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 /* Change the SAI state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279 HAL_SAI_ErrorCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 hsai->State= HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 HAL_SAI_TxCpltCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 * @brief DMA SAI transmit process half complete callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 static void SAI_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 HAL_SAI_TxHalfCpltCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 * @brief DMA SAI receive process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 static void SAI_DMARxCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 SAI_HandleTypeDef* hsai = ( SAI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 /* Disable Rx DMA Request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 hsai->RxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 hsai->State = HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 HAL_SAI_RxCpltCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 * @brief DMA SAI receive process half complete callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 static void SAI_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 HAL_SAI_RxHalfCpltCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 * @brief DMA SAI communication error callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 static void SAI_DMAError(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 SAI_HandleTypeDef* hsai = ( SAI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 /* Set the SAI state ready to be able to start again the process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 hsai->State= HAL_SAI_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 HAL_SAI_ErrorCallback(hsai);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 hsai->TxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 hsai->RxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 #endif /* HAL_SAI_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/