Index: firmware/App/Drivers/Comm.c =================================================================== diff -u -ra303cd4258157a8fbcbd8af4dd2bbaadec1a736c -r7d4711edd7b40cd3e29f43e766f79a8a09586fe9 --- firmware/App/Drivers/Comm.c (.../Comm.c) (revision a303cd4258157a8fbcbd8af4dd2bbaadec1a736c) +++ firmware/App/Drivers/Comm.c (.../Comm.c) (revision 7d4711edd7b40cd3e29f43e766f79a8a09586fe9) @@ -1,18 +1,19 @@ -/************************************************************************** - * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file Comm.c - * - * @date 28-Oct-2019 - * @author S. Nash - * - * @brief Support for communication. - * - **************************************************************************/ +/************************************************************************** +* +* Copyright (c) 2019-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file Comm.c +* +* @author (last) Sean Nash +* @date (last) 02-Dec-2021 +* +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 +* +***************************************************************************/ #include "can.h" #include "sci.h" @@ -21,156 +22,126 @@ #include "Comm.h" // ********** private definitions ********** + +#define SCI_DMA_TRANSMIT_INT 0x00010000 ///< SCI DMA transmit interrupt mask. +#define SCI_DMA_RECEIVE_INT 0x00060000 ///< SCI DMA receive interrupt mask. +#define DMA_CH_STATUS_BIT(ch) ((U32)1U << (ch)) ///< DMA channel status bit mask. -#define DMA_CH_STATUS_BIT(ch) ((U32)1U << (ch)) +// ********** private data ********** -/************************************************************************* - * @brief setSCI1DMAReceiveInterrupt - * The setSCI1DMAReceiveInterrupt function enables DMA receive interrupts \n - * for the SCI1 peripheral. - * @details - * Inputs : none - * Outputs : DMA receive interrupt is enabled. - * @param none +static volatile BOOL canXmitsInProgress = FALSE; ///< Flag to indicates CAN transmit is in progress. + +/*********************************************************************//** + * @brief + * The signalCANXmitsInitiated function sets the CAN transmits in progress flag. + * @details Inputs: none + * @details Outputs: canXmitsInProgress * @return none *************************************************************************/ -void setSCI1DMAReceiveInterrupt( void ) +void signalCANXmitsInitiated( void ) { - sciREG->SETINT = SCI_DMA_RECEIVE_INT; + canXmitsInProgress = TRUE; } - -/************************************************************************* - * @brief setSCI1DMATransmitInterrupt - * The setSCI1DMATransmitInterrupt function enables DMA transmit interrupts \n - * for the SCI1 peripheral. - * @details - * Inputs : none - * Outputs : DMA transmit interrupt is enabled. - * @param none + +/*********************************************************************//** + * @brief + * The signalCANXmitsCompleted function resets the CAN transmits in progress flag. + * @details Inputs: none + * @details Outputs: canXmitsInProgress * @return none *************************************************************************/ -void setSCI1DMATransmitInterrupt( void ) +void signalCANXmitsCompleted( void ) { - sciREG->SETINT = SCI_DMA_TRANSMIT_INT; + canXmitsInProgress = FALSE; } - -/************************************************************************* - * @brief clearSCI1DMAReceiveInterrupt - * The clearSCI1DMAReceiveInterrupt function disables DMA receive interrupts \n - * for the SCI1 peripheral. - * @details - * Inputs : none - * Outputs : DMA receive interrupt is disabled. - * @param none - * @return none - *************************************************************************/ -void clearSCI1DMAReceiveInterrupt( void ) -{ - sciREG->CLEARINT = SCI_DMA_RECEIVE_INT; -} - -/************************************************************************* - * @brief clearSCI1DMATransmitInterrupt - * The clearSCI1DMATransmitInterrupt function disables DMA transmit interrupts \n - * for the SCI1 peripheral. - * @details - * Inputs : none - * Outputs : DMA transmit interrupt is disabled. - * @param none - * @return none - *************************************************************************/ -void clearSCI1DMATransmitInterrupt( void ) -{ - sciREG->CLEARINT = SCI_DMA_TRANSMIT_INT; -} - -/************************************************************************* - * @brief setSCI2DMAReceiveInterrupt - * The setSCI2DMAReceiveInterrupt function enables DMA receive interrupts \n + +/*********************************************************************//** + * @brief + * The isCAN1TransmitInProgress function determines whether a transmit + * is in progress on the CAN1 peripheral. + * @details Inputs: status registers + * @details Outputs: none + * @return TRUE if a transmit is in progress, FALSE if not + *************************************************************************/ +BOOL isCAN1TransmitInProgress( void ) +{ + BOOL result = ( ( TRUE == canXmitsInProgress ) || ( canREG1->TXRQx[ 0 ] != 0 ) || ( canREG1->TXRQx[ 1 ] != 0 ) ? TRUE : FALSE ); + + return result; +} + +/*********************************************************************//** + * @brief + * The setSCI2DMAReceiveInterrupt function enables DMA receive interrupts * for the SCI2 peripheral. - * @details - * Inputs : none - * Outputs : DMA receive interrupt is enabled. - * @param none + * @details Inputs: none + * @details Outputs: DMA receive interrupt is enabled. * @return none *************************************************************************/ void setSCI2DMAReceiveInterrupt( void ) { scilinREG->SETINT = SCI_DMA_RECEIVE_INT; } - -/************************************************************************* - * @brief setSCI2DMATransmitInterrupt - * The setSCI2DMATransmitInterrupt function enables DMA transmit interrupts \n + +/*********************************************************************//** + * @brief + * The setSCI2DMATransmitInterrupt function enables DMA transmit interrupts * for the SCI2 peripheral. - * @details - * Inputs : none - * Outputs : DMA transmit interrupt is enabled. - * @param none + * @details Inputs: none + * @details Outputs: DMA transmit interrupt is enabled. * @return none *************************************************************************/ void setSCI2DMATransmitInterrupt( void ) { scilinREG->SETINT = SCI_DMA_TRANSMIT_INT; } - -/************************************************************************* - * @brief clearSCI2DMAReceiveInterrupt - * The clearSCI2DMAReceiveInterrupt function disables DMA receive interrupts \n + +/*********************************************************************//** + * @brief + * The clearSCI2DMAReceiveInterrupt function disables DMA receive interrupts * for the SCI2 peripheral. - * @details - * Inputs : none - * Outputs : DMA receive interrupt is disabled. - * @param none + * @details Inputs: none + * @details Outputs: DMA receive interrupt is disabled. * @return none *************************************************************************/ void clearSCI2DMAReceiveInterrupt( void ) { scilinREG->CLEARINT = SCI_DMA_RECEIVE_INT; } - -/************************************************************************* - * @brief clearSCI2DMATransmitInterrupt - * The clearSCI2DMATransmitInterrupt function disables DMA transmit interrupts \n + +/*********************************************************************//** + * @brief + * The clearSCI2DMATransmitInterrupt function disables DMA transmit interrupts * for the SCI2 peripheral. - * @details - * Inputs : none - * Outputs : DMA transmit interrupt is disabled. - * @param none + * @details Inputs: none + * @details Outputs: DMA transmit interrupt is disabled. * @return none *************************************************************************/ void clearSCI2DMATransmitInterrupt( void ) { scilinREG->CLEARINT = SCI_DMA_TRANSMIT_INT; } - -/************************************************************************* - * @brief isSCI1DMATransmitInProgress - * The isSCI2DMATransmitInProgress function determines whether a DMA transmit \n - * is in progress on the SCI1 peripheral. - * @details - * Inputs : status registers - * Outputs : none - * @param none - * @return TRUE if a transmit is in progress, FALSE if not + +/*********************************************************************//** + * @brief + * The clearSCI2CommErrors function clears framing and/or overrun error flags + * for the SCI2 peripheral. + * @details Inputs: none + * @details Outputs: SCI2 error flags cleared. + * @return none *************************************************************************/ -BOOL isSCI1DMATransmitInProgress( void ) +void clearSCI2CommErrors( void ) { - BOOL transmitterBusy = ( ( sciREG->FLR & (U32)SCI_TX_INT ) == 0U ? TRUE : FALSE ); - BOOL dmaTransmitterBusy = ( ( dmaREG->PEND & DMA_CH_STATUS_BIT(DMA_CH3) ) != 0U ? TRUE : FALSE ); - - - return ( ( transmitterBusy == TRUE ) || ( dmaTransmitterBusy == TRUE ) ? TRUE : FALSE ); + sciReceiveByte( scilinREG ); + scilinREG->FLR |= ( SCI_FE_INT | SCI_OE_INT ); } - -/************************************************************************* - * @brief isSCI2DMATransmitInProgress - * The isSCI2DMATransmitInProgress function determines whether a DMA transmit \n + +/*********************************************************************//** + * @brief + * The isSCI2DMATransmitInProgress function determines whether a DMA transmit * is in progress on the SCI2 peripheral. - * @details - * Inputs : status registers - * Outputs : none - * @param none + * @details Inputs: status registers + * @details Outputs: none * @return TRUE if a transmit is in progress, FALSE if not *************************************************************************/ BOOL isSCI2DMATransmitInProgress( void ) @@ -180,21 +151,5 @@ return ( ( transmitterBusy == TRUE ) || ( dmaTransmitterBusy == TRUE ) ? TRUE : FALSE ); } - -/************************************************************************* - * @brief isCAN1TransmitInProgress - * The isCAN1TransmitInProgress function determines whether a transmit \n - * is in progress on the CAN1 peripheral. - * @details - * Inputs : status registers - * Outputs : none - * @param none - * @return TRUE if a transmit is in progress, FALSE if not - *************************************************************************/ -BOOL isCAN1TransmitInProgress( void ) -{ - BOOL result = ( ( canREG1->TXRQx[0] != 0 ) || ( canREG1->TXRQx[1] != 0 ) ? TRUE : FALSE ); - - return result; -} - + +/**@}*/