STM32L4xx_HAL_Driver  1.14.0
SAI Private Functions

Private functions. More...

Functions

static void SAI_FillFifo (SAI_HandleTypeDef *hsai)
 Fill the fifo. More...
 
static uint32_t SAI_InterruptFlag (const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
 Return the interrupt flag to set according the SAI setup. More...
 
static HAL_StatusTypeDef SAI_InitI2S (SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot)
 Initialize the SAI I2S protocol according to the specified parameters in the SAI_InitTypeDef and create the associated handle. More...
 
static HAL_StatusTypeDef SAI_InitPCM (SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot)
 Initialize the SAI PCM protocol according to the specified parameters in the SAI_InitTypeDef and create the associated handle. More...
 
static HAL_StatusTypeDef SAI_Disable (SAI_HandleTypeDef *hsai)
 Disable the SAI and wait for the disabling. More...
 
static void SAI_Transmit_IT8Bit (SAI_HandleTypeDef *hsai)
 Tx Handler for Transmit in Interrupt mode 8-Bit transfer. More...
 
static void SAI_Transmit_IT16Bit (SAI_HandleTypeDef *hsai)
 Tx Handler for Transmit in Interrupt mode for 16-Bit transfer. More...
 
static void SAI_Transmit_IT32Bit (SAI_HandleTypeDef *hsai)
 Tx Handler for Transmit in Interrupt mode for 32-Bit transfer. More...
 
static void SAI_Receive_IT8Bit (SAI_HandleTypeDef *hsai)
 Rx Handler for Receive in Interrupt mode 8-Bit transfer. More...
 
static void SAI_Receive_IT16Bit (SAI_HandleTypeDef *hsai)
 Rx Handler for Receive in Interrupt mode for 16-Bit transfer. More...
 
static void SAI_Receive_IT32Bit (SAI_HandleTypeDef *hsai)
 Rx Handler for Receive in Interrupt mode for 32-Bit transfer. More...
 
static void SAI_DMATxCplt (DMA_HandleTypeDef *hdma)
 DMA SAI transmit process complete callback. More...
 
static void SAI_DMATxHalfCplt (DMA_HandleTypeDef *hdma)
 DMA SAI transmit process half complete callback. More...
 
static void SAI_DMARxCplt (DMA_HandleTypeDef *hdma)
 DMA SAI receive process complete callback. More...
 
static void SAI_DMARxHalfCplt (DMA_HandleTypeDef *hdma)
 DMA SAI receive process half complete callback. More...
 
static void SAI_DMAError (DMA_HandleTypeDef *hdma)
 DMA SAI communication error callback. More...
 
static void SAI_DMAAbort (DMA_HandleTypeDef *hdma)
 DMA SAI Abort callback. More...
 

Detailed Description

Private functions.

Function Documentation

◆ SAI_Disable()

static HAL_StatusTypeDef SAI_Disable ( SAI_HandleTypeDef hsai)
static

Disable the SAI and wait for the disabling.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2430 of file stm32l4xx_hal_sai.c.

2431 {
2432  register uint32_t count = SAI_DEFAULT_TIMEOUT * (SystemCoreClock / 7U / 1000U);
2433  HAL_StatusTypeDef status = HAL_OK;
2434 
2435  /* Disable the SAI instance */
2436  __HAL_SAI_DISABLE(hsai);
2437 
2438  do
2439  {
2440  /* Check for the Timeout */
2441  if (count == 0U)
2442  {
2443  /* Update error code */
2444  hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT;
2445  status = HAL_TIMEOUT;
2446  break;
2447  }
2448  count--;
2449  }
2450  while ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != 0U);
2451 
2452  return status;
2453 }
SAI_Block_TypeDef * Instance
return HAL_OK

◆ SAI_DMAAbort()

static void SAI_DMAAbort ( DMA_HandleTypeDef hdma)
static

DMA SAI Abort callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2792 of file stm32l4xx_hal_sai.c.

2793 {
2794  SAI_HandleTypeDef *hsai = (SAI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2795 
2796  /* Disable DMA request */
2797  hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
2798 
2799  /* Disable all interrupts and clear all flags */
2800  hsai->Instance->IMR = 0U;
2801  hsai->Instance->CLRFR = 0xFFFFFFFFU;
2802 
2803  if (hsai->ErrorCode != HAL_SAI_ERROR_WCKCFG)
2804  {
2805  /* Disable SAI peripheral */
2806  /* No need to check return value because state will be updated and HAL_SAI_ErrorCallback will be called later */
2807  (void) SAI_Disable(hsai);
2808 
2809  /* Flush the fifo */
2810  SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH);
2811  }
2812  /* Set the SAI state to ready to be able to start again the process */
2813  hsai->State = HAL_SAI_STATE_READY;
2814 
2815  /* Initialize XferCount */
2816  hsai->XferCount = 0U;
2817 
2818  /* SAI error Callback */
2819 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2820  hsai->ErrorCallback(hsai);
2821 #else
2822  HAL_SAI_ErrorCallback(hsai);
2823 #endif
2824 }
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
DMA handle Structure definition.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
SAI error callback.
void(* ErrorCallback)(struct __SAI_HandleTypeDef *hsai)

◆ SAI_DMAError()

static void SAI_DMAError ( DMA_HandleTypeDef hdma)
static

DMA SAI communication error callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2758 of file stm32l4xx_hal_sai.c.

2759 {
2760  SAI_HandleTypeDef *hsai = (SAI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2761 
2762  /* Set SAI error code */
2763  hsai->ErrorCode |= HAL_SAI_ERROR_DMA;
2764 
2765  /* Disable the SAI DMA request */
2766  hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN;
2767 
2768  /* Disable SAI peripheral */
2769  /* No need to check return value because state will be updated and HAL_SAI_ErrorCallback will be called later */
2770  (void) SAI_Disable(hsai);
2771 
2772  /* Set the SAI state ready to be able to start again the process */
2773  hsai->State = HAL_SAI_STATE_READY;
2774 
2775  /* Initialize XferCount */
2776  hsai->XferCount = 0U;
2777 
2778  /* SAI error Callback */
2779 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2780  hsai->ErrorCallback(hsai);
2781 #else
2782  HAL_SAI_ErrorCallback(hsai);
2783 #endif
2784 }
static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai)
Disable the SAI and wait for the disabling.
DMA handle Structure definition.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
SAI error callback.
void(* ErrorCallback)(struct __SAI_HandleTypeDef *hsai)

◆ SAI_DMARxCplt()

static void SAI_DMARxCplt ( DMA_HandleTypeDef hdma)
static

DMA SAI receive process complete callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2713 of file stm32l4xx_hal_sai.c.

2714 {
2715  SAI_HandleTypeDef *hsai = (SAI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2716 
2717  if (hdma->Init.Mode != DMA_CIRCULAR)
2718  {
2719  /* Disable Rx DMA Request */
2720  hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN);
2721  hsai->XferCount = 0;
2722 
2723  /* Stop the interrupts error handling */
2724  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA));
2725 
2726  hsai->State = HAL_SAI_STATE_READY;
2727  }
2728 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2729  hsai->RxCpltCallback(hsai);
2730 #else
2731  HAL_SAI_RxCpltCallback(hsai);
2732 #endif
2733 }
DMA handle Structure definition.
void(* RxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
DMA_InitTypeDef Init
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer completed callback.

◆ SAI_DMARxHalfCplt()

static void SAI_DMARxHalfCplt ( DMA_HandleTypeDef hdma)
static

DMA SAI receive process half complete callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2741 of file stm32l4xx_hal_sai.c.

2742 {
2743  SAI_HandleTypeDef *hsai = (SAI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2744 
2745 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2746  hsai->RxHalfCpltCallback(hsai);
2747 #else
2749 #endif
2750 }
DMA handle Structure definition.
void(* RxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer half completed callback.

◆ SAI_DMATxCplt()

static void SAI_DMATxCplt ( DMA_HandleTypeDef hdma)
static

DMA SAI transmit process complete callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2667 of file stm32l4xx_hal_sai.c.

2668 {
2669  SAI_HandleTypeDef *hsai = (SAI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2670 
2671  if (hdma->Init.Mode != DMA_CIRCULAR)
2672  {
2673  hsai->XferCount = 0;
2674 
2675  /* Disable SAI Tx DMA Request */
2676  hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN);
2677 
2678  /* Stop the interrupts error handling */
2679  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA));
2680 
2681  hsai->State = HAL_SAI_STATE_READY;
2682  }
2683 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2684  hsai->TxCpltCallback(hsai);
2685 #else
2686  HAL_SAI_TxCpltCallback(hsai);
2687 #endif
2688 }
void(* TxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
DMA handle Structure definition.
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
DMA_InitTypeDef Init
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer completed callback.

◆ SAI_DMATxHalfCplt()

static void SAI_DMATxHalfCplt ( DMA_HandleTypeDef hdma)
static

DMA SAI transmit process half complete callback.

Parameters
hdmapointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2696 of file stm32l4xx_hal_sai.c.

2697 {
2698  SAI_HandleTypeDef *hsai = (SAI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2699 
2700 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2701  hsai->TxHalfCpltCallback(hsai);
2702 #else
2704 #endif
2705 }
DMA handle Structure definition.
void(* TxHalfCpltCallback)(struct __SAI_HandleTypeDef *hsai)
void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer Half completed callback.

◆ SAI_FillFifo()

static void SAI_FillFifo ( SAI_HandleTypeDef hsai)
static

Fill the fifo.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2354 of file stm32l4xx_hal_sai.c.

2355 {
2356  uint32_t temp;
2357 
2358  /* fill the fifo with data before to enabled the SAI */
2359  while (((hsai->Instance->SR & SAI_xSR_FLVL) != SAI_FIFOSTATUS_FULL) && (hsai->XferCount > 0U))
2360  {
2361  if ((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING))
2362  {
2363  hsai->Instance->DR = *hsai->pBuffPtr;
2364  hsai->pBuffPtr++;
2365  }
2366  else if (hsai->Init.DataSize <= SAI_DATASIZE_16)
2367  {
2368  temp = (uint32_t)(*hsai->pBuffPtr);
2369  hsai->pBuffPtr++;
2370  temp |= ((uint32_t)(*hsai->pBuffPtr) << 8);
2371  hsai->pBuffPtr++;
2372  hsai->Instance->DR = temp;
2373  }
2374  else
2375  {
2376  temp = (uint32_t)(*hsai->pBuffPtr);
2377  hsai->pBuffPtr++;
2378  temp |= ((uint32_t)(*hsai->pBuffPtr) << 8);
2379  hsai->pBuffPtr++;
2380  temp |= ((uint32_t)(*hsai->pBuffPtr) << 16);
2381  hsai->pBuffPtr++;
2382  temp |= ((uint32_t)(*hsai->pBuffPtr) << 24);
2383  hsai->pBuffPtr++;
2384  hsai->Instance->DR = temp;
2385  }
2386  hsai->XferCount--;
2387  }
2388 }
SAI_Block_TypeDef * Instance
SAI_InitTypeDef Init

◆ SAI_InitI2S()

static HAL_StatusTypeDef SAI_InitI2S ( SAI_HandleTypeDef hsai,
uint32_t  protocol,
uint32_t  datasize,
uint32_t  nbslot 
)
static

Initialize the SAI I2S protocol according to the specified parameters in the SAI_InitTypeDef and create the associated handle.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
protocolone of the supported protocol.
datasizeone of the supported datasize SAI protocol data size.
nbslotnumber of slot minimum value is 2 and max is 16. the value must be a multiple of 2.
Return values
HALstatus

Definition at line 2182 of file stm32l4xx_hal_sai.c.

2183 {
2184  HAL_StatusTypeDef status = HAL_OK;
2185 
2186  hsai->Init.Protocol = SAI_FREE_PROTOCOL;
2187  hsai->Init.FirstBit = SAI_FIRSTBIT_MSB;
2188  /* Compute ClockStrobing according AudioMode */
2189  if ((hsai->Init.AudioMode == SAI_MODEMASTER_TX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX))
2190  {
2191  /* Transmit */
2192  hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
2193  }
2194  else
2195  {
2196  /* Receive */
2197  hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;
2198  }
2199  hsai->FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION;
2200  hsai->SlotInit.SlotActive = SAI_SLOTACTIVE_ALL;
2201  hsai->SlotInit.FirstBitOffset = 0;
2202  hsai->SlotInit.SlotNumber = nbslot;
2203 
2204  /* in IS2 the number of slot must be even */
2205  if ((nbslot & 0x1U) != 0U)
2206  {
2207  return HAL_ERROR;
2208  }
2209 
2210  switch (protocol)
2211  {
2212  case SAI_I2S_STANDARD :
2213  hsai->FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
2214  hsai->FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
2215  break;
2216  case SAI_I2S_MSBJUSTIFIED :
2217  case SAI_I2S_LSBJUSTIFIED :
2218  hsai->FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH;
2219  hsai->FrameInit.FSOffset = SAI_FS_FIRSTBIT;
2220  break;
2221  default :
2222  status = HAL_ERROR;
2223  break;
2224  }
2225 
2226  /* Frame definition */
2227  switch (datasize)
2228  {
2229  case SAI_PROTOCOL_DATASIZE_16BIT:
2230  hsai->Init.DataSize = SAI_DATASIZE_16;
2231  hsai->FrameInit.FrameLength = 32U * (nbslot / 2U);
2232  hsai->FrameInit.ActiveFrameLength = 16U * (nbslot / 2U);
2233  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_16B;
2234  break;
2235  case SAI_PROTOCOL_DATASIZE_16BITEXTENDED :
2236  hsai->Init.DataSize = SAI_DATASIZE_16;
2237  hsai->FrameInit.FrameLength = 64U * (nbslot / 2U);
2238  hsai->FrameInit.ActiveFrameLength = 32U * (nbslot / 2U);
2239  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B;
2240  break;
2241  case SAI_PROTOCOL_DATASIZE_24BIT:
2242  hsai->Init.DataSize = SAI_DATASIZE_24;
2243  hsai->FrameInit.FrameLength = 64U * (nbslot / 2U);
2244  hsai->FrameInit.ActiveFrameLength = 32U * (nbslot / 2U);
2245  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B;
2246  break;
2247  case SAI_PROTOCOL_DATASIZE_32BIT:
2248  hsai->Init.DataSize = SAI_DATASIZE_32;
2249  hsai->FrameInit.FrameLength = 64U * (nbslot / 2U);
2250  hsai->FrameInit.ActiveFrameLength = 32U * (nbslot / 2U);
2251  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B;
2252  break;
2253  default :
2254  status = HAL_ERROR;
2255  break;
2256  }
2257  if (protocol == SAI_I2S_LSBJUSTIFIED)
2258  {
2259  if (datasize == SAI_PROTOCOL_DATASIZE_16BITEXTENDED)
2260  {
2261  hsai->SlotInit.FirstBitOffset = 16;
2262  }
2263  if (datasize == SAI_PROTOCOL_DATASIZE_24BIT)
2264  {
2265  hsai->SlotInit.FirstBitOffset = 8;
2266  }
2267  }
2268  return status;
2269 }
return HAL_OK
SAI_InitTypeDef Init
SAI_SlotInitTypeDef SlotInit
SAI_FrameInitTypeDef FrameInit

◆ SAI_InitPCM()

static HAL_StatusTypeDef SAI_InitPCM ( SAI_HandleTypeDef hsai,
uint32_t  protocol,
uint32_t  datasize,
uint32_t  nbslot 
)
static

Initialize the SAI PCM protocol according to the specified parameters in the SAI_InitTypeDef and create the associated handle.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
protocolone of the supported protocol
datasizeone of the supported datasize SAI protocol data size
nbslotnumber of slot minimum value is 1 and the max is 16.
Return values
HALstatus

Definition at line 2281 of file stm32l4xx_hal_sai.c.

2282 {
2283  HAL_StatusTypeDef status = HAL_OK;
2284 
2285  hsai->Init.Protocol = SAI_FREE_PROTOCOL;
2286  hsai->Init.FirstBit = SAI_FIRSTBIT_MSB;
2287  /* Compute ClockStrobing according AudioMode */
2288  if ((hsai->Init.AudioMode == SAI_MODEMASTER_TX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX))
2289  {
2290  /* Transmit */
2291  hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;
2292  }
2293  else
2294  {
2295  /* Receive */
2296  hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
2297  }
2298  hsai->FrameInit.FSDefinition = SAI_FS_STARTFRAME;
2299  hsai->FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH;
2300  hsai->FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
2301  hsai->SlotInit.FirstBitOffset = 0;
2302  hsai->SlotInit.SlotNumber = nbslot;
2303  hsai->SlotInit.SlotActive = SAI_SLOTACTIVE_ALL;
2304 
2305  switch (protocol)
2306  {
2307  case SAI_PCM_SHORT :
2308  hsai->FrameInit.ActiveFrameLength = 1;
2309  break;
2310  case SAI_PCM_LONG :
2311  hsai->FrameInit.ActiveFrameLength = 13;
2312  break;
2313  default :
2314  status = HAL_ERROR;
2315  break;
2316  }
2317 
2318  switch (datasize)
2319  {
2320  case SAI_PROTOCOL_DATASIZE_16BIT:
2321  hsai->Init.DataSize = SAI_DATASIZE_16;
2322  hsai->FrameInit.FrameLength = 16U * nbslot;
2323  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_16B;
2324  break;
2325  case SAI_PROTOCOL_DATASIZE_16BITEXTENDED :
2326  hsai->Init.DataSize = SAI_DATASIZE_16;
2327  hsai->FrameInit.FrameLength = 32U * nbslot;
2328  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B;
2329  break;
2330  case SAI_PROTOCOL_DATASIZE_24BIT :
2331  hsai->Init.DataSize = SAI_DATASIZE_24;
2332  hsai->FrameInit.FrameLength = 32U * nbslot;
2333  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B;
2334  break;
2335  case SAI_PROTOCOL_DATASIZE_32BIT:
2336  hsai->Init.DataSize = SAI_DATASIZE_32;
2337  hsai->FrameInit.FrameLength = 32U * nbslot;
2338  hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B;
2339  break;
2340  default :
2341  status = HAL_ERROR;
2342  break;
2343  }
2344 
2345  return status;
2346 }
return HAL_OK
SAI_InitTypeDef Init
SAI_SlotInitTypeDef SlotInit
SAI_FrameInitTypeDef FrameInit

◆ SAI_InterruptFlag()

static uint32_t SAI_InterruptFlag ( const SAI_HandleTypeDef hsai,
SAI_ModeTypedef  mode 
)
static

Return the interrupt flag to set according the SAI setup.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
modeSAI_MODE_DMA or SAI_MODE_IT
Return values
thelist of the IT flag to enable

Definition at line 2397 of file stm32l4xx_hal_sai.c.

2398 {
2399  uint32_t tmpIT = SAI_IT_OVRUDR;
2400 
2401  if (mode == SAI_MODE_IT)
2402  {
2403  tmpIT |= SAI_IT_FREQ;
2404  }
2405 
2406  if ((hsai->Init.Protocol == SAI_AC97_PROTOCOL) &&
2407  ((hsai->Init.AudioMode == SAI_MODESLAVE_RX) || (hsai->Init.AudioMode == SAI_MODEMASTER_RX)))
2408  {
2409  tmpIT |= SAI_IT_CNRDY;
2410  }
2411 
2412  if ((hsai->Init.AudioMode == SAI_MODESLAVE_RX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX))
2413  {
2414  tmpIT |= SAI_IT_AFSDET | SAI_IT_LFSDET;
2415  }
2416  else
2417  {
2418  /* hsai has been configured in master mode */
2419  tmpIT |= SAI_IT_WCKCFG;
2420  }
2421  return tmpIT;
2422 }
SAI_InitTypeDef Init

◆ SAI_Receive_IT16Bit()

static void SAI_Receive_IT16Bit ( SAI_HandleTypeDef hsai)
static

Rx Handler for Receive in Interrupt mode for 16-Bit transfer.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2591 of file stm32l4xx_hal_sai.c.

2592 {
2593  uint32_t temp;
2594 
2595  /* Receive data */
2596  temp = hsai->Instance->DR;
2597  *hsai->pBuffPtr = (uint8_t)temp;
2598  hsai->pBuffPtr++;
2599  *hsai->pBuffPtr = (uint8_t)(temp >> 8);
2600  hsai->pBuffPtr++;
2601  hsai->XferCount--;
2602 
2603  /* Check end of the transfer */
2604  if (hsai->XferCount == 0U)
2605  {
2606  /* Disable TXE and OVRUDR interrupts */
2607  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
2608 
2609  /* Clear the SAI Overrun flag */
2610  __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR);
2611 
2612  hsai->State = HAL_SAI_STATE_READY;
2613 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2614  hsai->RxCpltCallback(hsai);
2615 #else
2616  HAL_SAI_RxCpltCallback(hsai);
2617 #endif
2618  }
2619 }
void(* RxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer completed callback.

◆ SAI_Receive_IT32Bit()

static void SAI_Receive_IT32Bit ( SAI_HandleTypeDef hsai)
static

Rx Handler for Receive in Interrupt mode for 32-Bit transfer.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2627 of file stm32l4xx_hal_sai.c.

2628 {
2629  uint32_t temp;
2630 
2631  /* Receive data */
2632  temp = hsai->Instance->DR;
2633  *hsai->pBuffPtr = (uint8_t)temp;
2634  hsai->pBuffPtr++;
2635  *hsai->pBuffPtr = (uint8_t)(temp >> 8);
2636  hsai->pBuffPtr++;
2637  *hsai->pBuffPtr = (uint8_t)(temp >> 16);
2638  hsai->pBuffPtr++;
2639  *hsai->pBuffPtr = (uint8_t)(temp >> 24);
2640  hsai->pBuffPtr++;
2641  hsai->XferCount--;
2642 
2643  /* Check end of the transfer */
2644  if (hsai->XferCount == 0U)
2645  {
2646  /* Disable TXE and OVRUDR interrupts */
2647  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
2648 
2649  /* Clear the SAI Overrun flag */
2650  __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR);
2651 
2652  hsai->State = HAL_SAI_STATE_READY;
2653 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2654  hsai->RxCpltCallback(hsai);
2655 #else
2656  HAL_SAI_RxCpltCallback(hsai);
2657 #endif
2658  }
2659 }
void(* RxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer completed callback.

◆ SAI_Receive_IT8Bit()

static void SAI_Receive_IT8Bit ( SAI_HandleTypeDef hsai)
static

Rx Handler for Receive in Interrupt mode 8-Bit transfer.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2560 of file stm32l4xx_hal_sai.c.

2561 {
2562  /* Receive data */
2563  *hsai->pBuffPtr = (uint8_t)hsai->Instance->DR;
2564  hsai->pBuffPtr++;
2565  hsai->XferCount--;
2566 
2567  /* Check end of the transfer */
2568  if (hsai->XferCount == 0U)
2569  {
2570  /* Disable TXE and OVRUDR interrupts */
2571  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
2572 
2573  /* Clear the SAI Overrun flag */
2574  __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR);
2575 
2576  hsai->State = HAL_SAI_STATE_READY;
2577 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2578  hsai->RxCpltCallback(hsai);
2579 #else
2580  HAL_SAI_RxCpltCallback(hsai);
2581 #endif
2582  }
2583 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
void(* RxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Rx Transfer completed callback.

◆ SAI_Transmit_IT16Bit()

static void SAI_Transmit_IT16Bit ( SAI_HandleTypeDef hsai)
static

Tx Handler for Transmit in Interrupt mode for 16-Bit transfer.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2490 of file stm32l4xx_hal_sai.c.

2491 {
2492  if (hsai->XferCount == 0U)
2493  {
2494  /* Handle the end of the transmission */
2495  /* Disable FREQ and OVRUDR interrupts */
2496  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
2497  hsai->State = HAL_SAI_STATE_READY;
2498 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2499  hsai->TxCpltCallback(hsai);
2500 #else
2501  HAL_SAI_TxCpltCallback(hsai);
2502 #endif
2503  }
2504  else
2505  {
2506  /* Write data on DR register */
2507  uint32_t temp;
2508  temp = (uint32_t)(*hsai->pBuffPtr);
2509  hsai->pBuffPtr++;
2510  temp |= ((uint32_t)(*hsai->pBuffPtr) << 8);
2511  hsai->pBuffPtr++;
2512  hsai->Instance->DR = temp;
2513  hsai->XferCount--;
2514  }
2515 }
void(* TxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer completed callback.

◆ SAI_Transmit_IT32Bit()

static void SAI_Transmit_IT32Bit ( SAI_HandleTypeDef hsai)
static

Tx Handler for Transmit in Interrupt mode for 32-Bit transfer.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2523 of file stm32l4xx_hal_sai.c.

2524 {
2525  if (hsai->XferCount == 0U)
2526  {
2527  /* Handle the end of the transmission */
2528  /* Disable FREQ and OVRUDR interrupts */
2529  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
2530  hsai->State = HAL_SAI_STATE_READY;
2531 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2532  hsai->TxCpltCallback(hsai);
2533 #else
2534  HAL_SAI_TxCpltCallback(hsai);
2535 #endif
2536  }
2537  else
2538  {
2539  /* Write data on DR register */
2540  uint32_t temp;
2541  temp = (uint32_t)(*hsai->pBuffPtr);
2542  hsai->pBuffPtr++;
2543  temp |= ((uint32_t)(*hsai->pBuffPtr) << 8);
2544  hsai->pBuffPtr++;
2545  temp |= ((uint32_t)(*hsai->pBuffPtr) << 16);
2546  hsai->pBuffPtr++;
2547  temp |= ((uint32_t)(*hsai->pBuffPtr) << 24);
2548  hsai->pBuffPtr++;
2549  hsai->Instance->DR = temp;
2550  hsai->XferCount--;
2551  }
2552 }
void(* TxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer completed callback.

◆ SAI_Transmit_IT8Bit()

static void SAI_Transmit_IT8Bit ( SAI_HandleTypeDef hsai)
static

Tx Handler for Transmit in Interrupt mode 8-Bit transfer.

Parameters
hsaipointer to a SAI_HandleTypeDef structure that contains the configuration information for SAI module.
Return values
None

Definition at line 2461 of file stm32l4xx_hal_sai.c.

2462 {
2463  if (hsai->XferCount == 0U)
2464  {
2465  /* Handle the end of the transmission */
2466  /* Disable FREQ and OVRUDR interrupts */
2467  __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT));
2468  hsai->State = HAL_SAI_STATE_READY;
2469 #if (USE_HAL_SAI_REGISTER_CALLBACKS == 1)
2470  hsai->TxCpltCallback(hsai);
2471 #else
2472  HAL_SAI_TxCpltCallback(hsai);
2473 #endif
2474  }
2475  else
2476  {
2477  /* Write data on DR register */
2478  hsai->Instance->DR = *hsai->pBuffPtr;
2479  hsai->pBuffPtr++;
2480  hsai->XferCount--;
2481  }
2482 }
void(* TxCpltCallback)(struct __SAI_HandleTypeDef *hsai)
static uint32_t SAI_InterruptFlag(const SAI_HandleTypeDef *hsai, SAI_ModeTypedef mode)
Return the interrupt flag to set according the SAI setup.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer completed callback.