Skip to content

Commit

Permalink
Merge pull request #2514 from NXPmicro/Updated_Drivers
Browse files Browse the repository at this point in the history
Updated FlexCan and SAI SDK drivers
  • Loading branch information
sg- authored Sep 10, 2016
2 parents a35cd7f + 38aeb4c commit 7198385
Show file tree
Hide file tree
Showing 12 changed files with 420 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ enum _sai_transfer_state
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
******************************************************************************/
Expand Down Expand Up @@ -98,6 +104,10 @@ static const IRQn_Type s_saiTxIRQ[] = I2S_TX_IRQS;
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
Expand Down Expand Up @@ -231,12 +241,13 @@ void SAI_TxInit(I2S_Type *base, const sai_config_t *config)
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 */
Expand Down Expand Up @@ -332,12 +343,13 @@ void SAI_RxInit(I2S_Type *base, const sai_config_t *config)
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 */
Expand Down Expand Up @@ -663,6 +675,9 @@ void SAI_TransferTxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transf
handle->callback = callback;
handle->userData = userData;

/* Set the isr pointer */
s_saiTxIsr = SAI_TransferTxHandleIRQ;

/* Enable Tx irq */
EnableIRQ(s_saiTxIRQ[SAI_GetInstance(base)]);
}
Expand All @@ -676,6 +691,9 @@ void SAI_TransferRxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transf
handle->callback = callback;
handle->userData = userData;

/* Set the isr pointer */
s_saiRxIsr = SAI_TransferRxHandleIRQ;

/* Enable Rx irq */
EnableIRQ(s_saiRxIRQ[SAI_GetInstance(base)]);
}
Expand Down Expand Up @@ -1011,24 +1029,24 @@ void I2S0_DriverIRQHandler(void)
{
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*/
Expand All @@ -1037,12 +1055,12 @@ void I2S0_Rx_DriverIRQHandler(void)
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
* @{
*/

/*! @file */

/*******************************************************************************
* Definitions
******************************************************************************/

/*! @name Driver version */
/*@{*/
#define FSL_SAI_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Version 2.1.0 */
#define FSL_SAI_DRIVER_VERSION (MAKE_VERSION(2, 1, 1)) /*!< Version 2.1.1 */
/*@}*/

/*! @brief SAI return status*/
Expand Down Expand Up @@ -168,7 +167,7 @@ typedef enum _sai_fifo_packing
} sai_fifo_packing_t;
#endif /* FSL_FEATURE_SAI_HAS_FIFO_PACKING */

/*! @brief SAI user configure structure */
/*! @brief SAI user configuration structure */
typedef struct _sai_config
{
sai_protocol_t protocol; /*!< Audio bus protocol in SAI */
Expand Down Expand Up @@ -276,7 +275,7 @@ extern "C" {
* because the clock is not enabled.
*
* @param base SAI base pointer
* @param config SAI configure structure.
* @param config SAI configuration structure.
*/
void SAI_TxInit(I2S_Type *base, const sai_config_t *config);

Expand All @@ -292,7 +291,7 @@ void SAI_TxInit(I2S_Type *base, const sai_config_t *config);
* because the clock is not enabled.
*
* @param base SAI base pointer
* @param config SAI configure structure.
* @param config SAI configuration structure.
*/
void SAI_RxInit(I2S_Type *base, const sai_config_t *config);

Expand Down
Loading

0 comments on commit 7198385

Please sign in to comment.