siva surendar / mbed-dev

Fork of mbed-dev by mbed official

Revision:
147:30b64687e01f
Parent:
144:ef7eb2e8f9f7
--- a/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K66F/drivers/fsl_sai.c	Thu Sep 08 15:05:30 2016 +0100
+++ b/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K66F/drivers/fsl_sai.c	Fri Sep 16 16:24:25 2016 +0100
@@ -40,6 +40,12 @@
     kSAI_Error        /*!< Transfer error occured. */
 };
 
+/*! @brief Typedef for sai tx interrupt handler. */
+typedef void (*sai_tx_isr_t)(I2S_Type *base, sai_handle_t *saiHandle);
+
+/*! @brief Typedef for sai rx interrupt handler. */
+typedef void (*sai_rx_isr_t)(I2S_Type *base, sai_handle_t *saiHandle);
+
 /*******************************************************************************
  * Prototypes
  ******************************************************************************/
@@ -98,6 +104,10 @@
 static const IRQn_Type s_saiRxIRQ[] = I2S_RX_IRQS;
 /* Clock name array */
 static const clock_ip_name_t s_saiClock[] = SAI_CLOCKS;
+/*! @brief Pointer to tx IRQ handler for each instance. */
+static sai_tx_isr_t s_saiTxIsr;
+/*! @brief Pointer to tx IRQ handler for each instance. */
+static sai_rx_isr_t s_saiRxIsr;
 
 /*******************************************************************************
  * Code
@@ -231,12 +241,13 @@
     CLOCK_EnableClock(s_saiClock[SAI_GetInstance(base)]);
 
 #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
-    /* Configure Master clock output enable */
-    base->MCR = I2S_MCR_MOE(config->mclkOutputEnable);
-
     /* Master clock source setting */
     val = (base->MCR & ~I2S_MCR_MICS_MASK);
     base->MCR = (val | I2S_MCR_MICS(config->mclkSource));
+
+    /* Configure Master clock output enable */
+    val = (base->MCR & ~I2S_MCR_MOE_MASK);
+    base->MCR = (val | I2S_MCR_MOE(config->mclkOutputEnable));
 #endif /* FSL_FEATURE_SAI_HAS_MCR */
 
     /* Configure audio protocol */
@@ -332,12 +343,13 @@
     CLOCK_EnableClock(s_saiClock[SAI_GetInstance(base)]);
 
 #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
-    /* Configure Master clock output enable */
-    base->MCR = I2S_MCR_MOE(config->mclkOutputEnable);
-
     /* Master clock source setting */
     val = (base->MCR & ~I2S_MCR_MICS_MASK);
     base->MCR = (val | I2S_MCR_MICS(config->mclkSource));
+
+    /* Configure Master clock output enable */
+    val = (base->MCR & ~I2S_MCR_MOE_MASK);
+    base->MCR = (val | I2S_MCR_MOE(config->mclkOutputEnable));
 #endif /* FSL_FEATURE_SAI_HAS_MCR */
 
     /* Configure audio protocol */
@@ -663,6 +675,9 @@
     handle->callback = callback;
     handle->userData = userData;
 
+    /* Set the isr pointer */
+    s_saiTxIsr = SAI_TransferTxHandleIRQ;
+
     /* Enable Tx irq */
     EnableIRQ(s_saiTxIRQ[SAI_GetInstance(base)]);
 }
@@ -676,6 +691,9 @@
     handle->callback = callback;
     handle->userData = userData;
 
+    /* Set the isr pointer */
+    s_saiRxIsr = SAI_TransferRxHandleIRQ;
+
     /* Enable Rx irq */
     EnableIRQ(s_saiRxIRQ[SAI_GetInstance(base)]);
 }
@@ -1011,24 +1029,24 @@
 {
     if ((s_saiHandle[0][1]) && ((I2S0->RCSR & kSAI_FIFOWarningFlag) || (I2S0->RCSR & kSAI_FIFOErrorFlag)))
     {
-        SAI_TransferRxHandleIRQ(I2S0, s_saiHandle[0][1]);
+        s_saiRxIsr(I2S0, s_saiHandle[0][1]);
     }
     if ((s_saiHandle[0][0]) && ((I2S0->TCSR & kSAI_FIFOWarningFlag) || (I2S0->TCSR & kSAI_FIFOErrorFlag)))
     {
-        SAI_TransferTxHandleIRQ(I2S0, s_saiHandle[0][0]);
+        s_saiTxIsr(I2S0, s_saiHandle[0][0]);
     }
 }
 #else
 void I2S0_Tx_DriverIRQHandler(void)
 {
     assert(s_saiHandle[0][0]);
-    SAI_TransferTxHandleIRQ(I2S0, s_saiHandle[0][0]);
+    s_saiTxIsr(I2S0, s_saiHandle[0][0]);
 }
 
 void I2S0_Rx_DriverIRQHandler(void)
 {
     assert(s_saiHandle[0][1]);
-    SAI_TransferRxHandleIRQ(I2S0, s_saiHandle[0][1]);
+    s_saiRxIsr(I2S0, s_saiHandle[0][1]);
 }
 #endif /* FSL_FEATURE_SAI_INT_SOURCE_NUM */
 #endif /* I2S0*/
@@ -1037,12 +1055,12 @@
 void I2S1_Tx_DriverIRQHandler(void)
 {
     assert(s_saiHandle[1][0]);
-    SAI_TransferTxHandleIRQ(I2S1, s_saiHandle[1][0]);
+    s_saiTxIsr(I2S1, s_saiHandle[1][0]);
 }
 
 void I2S1_Rx_DriverIRQHandler(void)
 {
     assert(s_saiHandle[1][1]);
-    SAI_TransferRxHandleIRQ(I2S1, s_saiHandle[1][1]);
+    s_saiRxIsr(I2S1, s_saiHandle[1][1]);
 }
 #endif