7 term/Microprocessor-Systems-and-Tools/Lab 6/libs/CTS_Layer.c
/***************************************************************************/
/**
 * @brief   Update baseline tracking by averaging several measurements
 * @param   groupOfElements Pointer to Sensor structure to be measured
 * @param   numberOfAverages Number of measurements to be averaged
 * @return  none
 ******************************************************************************/
@brief   Update baseline tracking by averaging several measurements
@param   groupOfElements Pointer to Sensor structure to be measured
@param   numberOfAverages Number of measurements to be averaged
@return  none
@brief Update baseline tracking by averaging several measurements @param groupOfElements Pointer to Sensor structure to be measured @param numberOfAverages Number of measurements to be averaged @return none
void TI_CAPT_Update_Baseline(const struct Sensor* groupOfElements, uint8_t numberOfAverages)
{
	uint8_t i,j;
    #ifndef RAM_FOR_FLASH
	uint16_t *measCnt;
    measCnt = (uint16_t *)malloc(groupOfElements->numElements * sizeof(uint16_t));
    if(measCnt ==0)
    {
        while(1);
    }
    #endif
    for(j=0; j < numberOfAverages; j++)
    {
        for(i=0; i < groupOfElements->numElements; i++)
        {
            TI_CAPT_Raw(groupOfElements, measCnt);
            baseCnt[i+groupOfElements->baseOffset]
                    = measCnt[i]/2 + baseCnt[i+groupOfElements->baseOffset]/2;
        }
    }
    #ifndef RAM_FOR_FLASH
    free(measCnt);
    #endif
}
void TI_CAPT_Update_Baseline ( const struct Sensor * groupOfElements , uint8_t numberOfAverages ) { uint8_t i , j ; #ifndef RAM_FOR_FLASH uint16_t * measCnt ; measCnt = ( uint16_t * ) malloc ( groupOfElements -> numElements * sizeof ( uint16_t ) ) ; if ( measCnt == 0 ) { while ( 1 ) ; } #endif for ( j = 0 ; j < numberOfAverages ; j ++ ) { for ( i = 0 ; i < groupOfElements -> numElements ; i ++ ) { TI_CAPT_Raw ( groupOfElements , measCnt ) ; baseCnt [ i + groupOfElements -> baseOffset ] = measCnt [ i ] / 2 + baseCnt [ i + groupOfElements -> baseOffset ] / 2 ; } } #ifndef RAM_FOR_FLASH free ( measCnt ) ; #endif }
@brief   Update baseline tracking by averaging several measurements
 @param   groupOfElements Pointer to Sensor structure to be measured
 @param   numberOfAverages Number of measurements to be averaged
 @return  none
@brief Update baseline tracking by averaging several measurements @param groupOfElements Pointer to Sensor structure to be measured @param numberOfAverages Number of measurements to be averaged @return none