Skip to content

Commit 7198385

Browse files
authored
Merge pull request #2514 from NXPmicro/Updated_Drivers
Updated FlexCan and SAI SDK drivers
2 parents a35cd7f + 38aeb4c commit 7198385

File tree

12 files changed

+420
-296
lines changed

12 files changed

+420
-296
lines changed

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K22F/drivers/fsl_sai.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ enum _sai_transfer_state
4040
kSAI_Error /*!< Transfer error occured. */
4141
};
4242

43+
/*! @brief Typedef for sai tx interrupt handler. */
44+
typedef void (*sai_tx_isr_t)(I2S_Type *base, sai_handle_t *saiHandle);
45+
46+
/*! @brief Typedef for sai rx interrupt handler. */
47+
typedef void (*sai_rx_isr_t)(I2S_Type *base, sai_handle_t *saiHandle);
48+
4349
/*******************************************************************************
4450
* Prototypes
4551
******************************************************************************/
@@ -98,6 +104,10 @@ static const IRQn_Type s_saiTxIRQ[] = I2S_TX_IRQS;
98104
static const IRQn_Type s_saiRxIRQ[] = I2S_RX_IRQS;
99105
/* Clock name array */
100106
static const clock_ip_name_t s_saiClock[] = SAI_CLOCKS;
107+
/*! @brief Pointer to tx IRQ handler for each instance. */
108+
static sai_tx_isr_t s_saiTxIsr;
109+
/*! @brief Pointer to tx IRQ handler for each instance. */
110+
static sai_rx_isr_t s_saiRxIsr;
101111

102112
/*******************************************************************************
103113
* Code
@@ -231,12 +241,13 @@ void SAI_TxInit(I2S_Type *base, const sai_config_t *config)
231241
CLOCK_EnableClock(s_saiClock[SAI_GetInstance(base)]);
232242

233243
#if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
234-
/* Configure Master clock output enable */
235-
base->MCR = I2S_MCR_MOE(config->mclkOutputEnable);
236-
237244
/* Master clock source setting */
238245
val = (base->MCR & ~I2S_MCR_MICS_MASK);
239246
base->MCR = (val | I2S_MCR_MICS(config->mclkSource));
247+
248+
/* Configure Master clock output enable */
249+
val = (base->MCR & ~I2S_MCR_MOE_MASK);
250+
base->MCR = (val | I2S_MCR_MOE(config->mclkOutputEnable));
240251
#endif /* FSL_FEATURE_SAI_HAS_MCR */
241252

242253
/* Configure audio protocol */
@@ -332,12 +343,13 @@ void SAI_RxInit(I2S_Type *base, const sai_config_t *config)
332343
CLOCK_EnableClock(s_saiClock[SAI_GetInstance(base)]);
333344

334345
#if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR)
335-
/* Configure Master clock output enable */
336-
base->MCR = I2S_MCR_MOE(config->mclkOutputEnable);
337-
338346
/* Master clock source setting */
339347
val = (base->MCR & ~I2S_MCR_MICS_MASK);
340348
base->MCR = (val | I2S_MCR_MICS(config->mclkSource));
349+
350+
/* Configure Master clock output enable */
351+
val = (base->MCR & ~I2S_MCR_MOE_MASK);
352+
base->MCR = (val | I2S_MCR_MOE(config->mclkOutputEnable));
341353
#endif /* FSL_FEATURE_SAI_HAS_MCR */
342354

343355
/* Configure audio protocol */
@@ -663,6 +675,9 @@ void SAI_TransferTxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transf
663675
handle->callback = callback;
664676
handle->userData = userData;
665677

678+
/* Set the isr pointer */
679+
s_saiTxIsr = SAI_TransferTxHandleIRQ;
680+
666681
/* Enable Tx irq */
667682
EnableIRQ(s_saiTxIRQ[SAI_GetInstance(base)]);
668683
}
@@ -676,6 +691,9 @@ void SAI_TransferRxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transf
676691
handle->callback = callback;
677692
handle->userData = userData;
678693

694+
/* Set the isr pointer */
695+
s_saiRxIsr = SAI_TransferRxHandleIRQ;
696+
679697
/* Enable Rx irq */
680698
EnableIRQ(s_saiRxIRQ[SAI_GetInstance(base)]);
681699
}
@@ -1011,24 +1029,24 @@ void I2S0_DriverIRQHandler(void)
10111029
{
10121030
if ((s_saiHandle[0][1]) && ((I2S0->RCSR & kSAI_FIFOWarningFlag) || (I2S0->RCSR & kSAI_FIFOErrorFlag)))
10131031
{
1014-
SAI_TransferRxHandleIRQ(I2S0, s_saiHandle[0][1]);
1032+
s_saiRxIsr(I2S0, s_saiHandle[0][1]);
10151033
}
10161034
if ((s_saiHandle[0][0]) && ((I2S0->TCSR & kSAI_FIFOWarningFlag) || (I2S0->TCSR & kSAI_FIFOErrorFlag)))
10171035
{
1018-
SAI_TransferTxHandleIRQ(I2S0, s_saiHandle[0][0]);
1036+
s_saiTxIsr(I2S0, s_saiHandle[0][0]);
10191037
}
10201038
}
10211039
#else
10221040
void I2S0_Tx_DriverIRQHandler(void)
10231041
{
10241042
assert(s_saiHandle[0][0]);
1025-
SAI_TransferTxHandleIRQ(I2S0, s_saiHandle[0][0]);
1043+
s_saiTxIsr(I2S0, s_saiHandle[0][0]);
10261044
}
10271045

10281046
void I2S0_Rx_DriverIRQHandler(void)
10291047
{
10301048
assert(s_saiHandle[0][1]);
1031-
SAI_TransferRxHandleIRQ(I2S0, s_saiHandle[0][1]);
1049+
s_saiRxIsr(I2S0, s_saiHandle[0][1]);
10321050
}
10331051
#endif /* FSL_FEATURE_SAI_INT_SOURCE_NUM */
10341052
#endif /* I2S0*/
@@ -1037,12 +1055,12 @@ void I2S0_Rx_DriverIRQHandler(void)
10371055
void I2S1_Tx_DriverIRQHandler(void)
10381056
{
10391057
assert(s_saiHandle[1][0]);
1040-
SAI_TransferTxHandleIRQ(I2S1, s_saiHandle[1][0]);
1058+
s_saiTxIsr(I2S1, s_saiHandle[1][0]);
10411059
}
10421060

10431061
void I2S1_Rx_DriverIRQHandler(void)
10441062
{
10451063
assert(s_saiHandle[1][1]);
1046-
SAI_TransferRxHandleIRQ(I2S1, s_saiHandle[1][1]);
1064+
s_saiRxIsr(I2S1, s_saiHandle[1][1]);
10471065
}
10481066
#endif

hal/targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/TARGET_K22F/drivers/fsl_sai.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@
3838
* @{
3939
*/
4040

41-
/*! @file */
4241

4342
/*******************************************************************************
4443
* Definitions
4544
******************************************************************************/
4645

4746
/*! @name Driver version */
4847
/*@{*/
49-
#define FSL_SAI_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Version 2.1.0 */
48+
#define FSL_SAI_DRIVER_VERSION (MAKE_VERSION(2, 1, 1)) /*!< Version 2.1.1 */
5049
/*@}*/
5150

5251
/*! @brief SAI return status*/
@@ -168,7 +167,7 @@ typedef enum _sai_fifo_packing
168167
} sai_fifo_packing_t;
169168
#endif /* FSL_FEATURE_SAI_HAS_FIFO_PACKING */
170169

171-
/*! @brief SAI user configure structure */
170+
/*! @brief SAI user configuration structure */
172171
typedef struct _sai_config
173172
{
174173
sai_protocol_t protocol; /*!< Audio bus protocol in SAI */
@@ -276,7 +275,7 @@ extern "C" {
276275
* because the clock is not enabled.
277276
*
278277
* @param base SAI base pointer
279-
* @param config SAI configure structure.
278+
* @param config SAI configuration structure.
280279
*/
281280
void SAI_TxInit(I2S_Type *base, const sai_config_t *config);
282281

@@ -292,7 +291,7 @@ void SAI_TxInit(I2S_Type *base, const sai_config_t *config);
292291
* because the clock is not enabled.
293292
*
294293
* @param base SAI base pointer
295-
* @param config SAI configure structure.
294+
* @param config SAI configuration structure.
296295
*/
297296
void SAI_RxInit(I2S_Type *base, const sai_config_t *config);
298297

0 commit comments

Comments
 (0)