Index: firmware/App/Drivers/InternalADC.c =================================================================== diff -u -rf7e3018ec6ab762fe08efb42b21fb2ca970174b0 -r8e7158d8231435496fcf1d5649e51babf859ccc7 --- firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision f7e3018ec6ab762fe08efb42b21fb2ca970174b0) +++ firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision 8e7158d8231435496fcf1d5649e51babf859ccc7) @@ -1,29 +1,37 @@ -/************************************************************************** - * - * 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 InternalADC.c - * - * @date 08-Nov-2019 - * @author S. Nash - * - * @brief Driver for the internal ADC peripheral. - * - **************************************************************************/ +/************************************************************************** +* +* Copyright (c) 2019-2021 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 InternalADC.c +* +* @author (last) Sean Nash +* @date (last) 24-Sep-2020 +* +* @author (original) Sean Nash +* @date (original) 08-Nov-2019 +* +***************************************************************************/ -#include "adc.h" - +#include "adc.h" + +#include "CPLD.h" #include "InternalADC.h" +/** + * @addtogroup InternalADC + * @{ + */ + // ********** private definitions ********** -#define MAX_ADC_CHANNELS 24 // ADC supports up to 24 channels -#define SIZE_OF_ROLLING_AVG 16 // samples in rolling average calculations -#define ROLLING_AVG_SHIFT_DIVIDER 4 // rolling average shift divider - +#define MAX_ADC_CHANNELS 24 ///< ADC supports up to 24 channels. +#define SIZE_OF_ROLLING_AVG 16 ///< samples in rolling average calculations. +#define ROLLING_AVG_SHIFT_DIVIDER 4 ///< rolling average shift divider. + +/// Mapping from enumerated used ADC channel to processor channel ID. const INT_ADC_CHANNEL_T adcChannelNum2ChannelId[ MAX_ADC_CHANNELS ] = { INT_ADC_DIAL_IN_PUMP_SPEED, // 0 @@ -54,25 +62,21 @@ // ********** private data ********** -static adcData_t adcRawReadings[ NUM_OF_INT_ADC_CHANNELS ]; // buffer holds latest adc channel readings -static U32 adcRawReadingsCount = 0; // readings count for raw readings buffer +static adcData_t adcRawReadings[ NUM_OF_INT_ADC_CHANNELS ]; ///< Buffer holds latest adc channel readings. +static U32 adcRawReadingsCount = 0; ///< Readings count for raw readings buffer. -static U16 adcReadings[ NUM_OF_INT_ADC_CHANNELS ][ SIZE_OF_ROLLING_AVG ]; // holds samples for each channel for a rolling average -static U32 adcReadingsIdx[ NUM_OF_INT_ADC_CHANNELS ]; // index for next reading in each rolling average array -static U32 adcReadingsTotals[ NUM_OF_INT_ADC_CHANNELS ]; // rolling total for each channel - used to calc average -static U32 adcReadingsAvgs[ NUM_OF_INT_ADC_CHANNELS ]; // rolling average for each channel +static U16 adcReadings[ NUM_OF_INT_ADC_CHANNELS ][ SIZE_OF_ROLLING_AVG ]; ///< Holds samples for each channel for a rolling average. +static U32 adcReadingsIdx[ NUM_OF_INT_ADC_CHANNELS ]; ///< Index for next reading in each rolling average array. +static U32 adcReadingsTotals[ NUM_OF_INT_ADC_CHANNELS ]; ///< Rolling total for each channel - used to calc average. +static U32 adcReadingsAvgs[ NUM_OF_INT_ADC_CHANNELS ]; ///< Rolling average for each channel. // ********** private function prototypes ********** - - -/************************************************************************* - * @brief initInternalADC +/*********************************************************************//** + * @brief * The initInternalADC function initializes the InternalADC module. - * @details - * Inputs : none - * Outputs : InternalADC module is initialized. - * @param none + * @details Inputs: none + * @details Outputs: InternalADC module is initialized. * @return none *************************************************************************/ void initInternalADC( void ) @@ -98,34 +102,30 @@ adcEnableNotification( adcREG1, adcGROUP1 ); } -/************************************************************************* - * @brief adcNotification - * The adcNotification function handles an ADC conversion complete interrupt. \n +/*********************************************************************//** + * @brief + * The adcNotification function handles an ADC conversion complete interrupt. * All channel readings in the FIFO are retrieved. - * @details - * Inputs : ADC FIFO - * Outputs : adcRawReadingsCount, adcRawReadings[] - * @param adc : pointer to the ADC1 controller - * @param group : ADC channel group ID + * @details Inputs: ADC FIFO + * @details Outputs: adcRawReadingsCount, adcRawReadings[] + * @param adc pointer to the ADC1 controller + * @param group ADC channel group ID * @return none *************************************************************************/ void adcNotification( adcBASE_t *adc, uint32 group ) { - if ( adcGROUP1 == group ) + if ( adcGROUP1 == group ) { adcRawReadingsCount = adcGetData( adcREG1, adcGROUP1, adcRawReadings ); } } -/************************************************************************* - * @brief execInternalADC - * The execInternalADC function processes the last set of raw ADC channel \n +/*********************************************************************//** + * @brief + * The execInternalADC function processes the last set of raw ADC channel * readings and kicks off the next conversion of ADC channels. - * @details - * Inputs : adcRawReadingsCount, adcRawReadings[] - * Outputs : adcReadings[][], adcReadingsIdx[], adcReadingsTotals[], adcReadingsAvgs[] - * @param adc : pointer to the ADC1 controller - * @param group : ADC channel group ID + * @details Inputs: adcRawReadingsCount, adcRawReadings[] + * @details Outputs: adcReadings[][], adcReadingsIdx[], adcReadingsTotals[], adcReadingsAvgs[] * @return none *************************************************************************/ void execInternalADC( void ) @@ -148,21 +148,20 @@ } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_DATA_OVERRUN, adcRawReadingsCount ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_DATA_OVERRUN, adcRawReadingsCount ) } // start an adc channel group conversion adcStartConversion( adcREG1, adcGROUP1 ); } -/************************************************************************* - * @brief getIntADCReading - * The getIntADCReading function gets the latest average reading for a given \n +/*********************************************************************//** + * @brief + * The getIntADCReading function gets the latest average reading for a given * channel. - * @details - * Inputs : adcReadingsAvgs[] - * Outputs : none - * @param channel : adc channel to retrieve a reading for + * @details Inputs: adcReadingsAvgs[] + * @details Outputs: none + * @param channel adc channel to retrieve a reading for * @return average reading for the given channel *************************************************************************/ U16 getIntADCReading( INT_ADC_CHANNEL_T channel ) @@ -175,9 +174,10 @@ } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_INVALID_CHANNEL_REQUESTED, channel ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_INVALID_CHANNEL_REQUESTED, channel ) } return result; } +/**@}*/