sarmfsw: SMFSW Toolbox (desinged for ARM / compatible with other 8b/16b/32b platforms) 4.0rc
SMFSW collection of miscellaneous functions \& macros (desinged for ARM / compatible with other 8b/16b/32b platforms)
Loading...
Searching...
No Matches
arm_inlines_average.h File Reference

Averaging inlines. More...

This graph shows which files directly or indirectly include this file:

Macros

#define RESTRICTED_AVERAGE(typ_t, sum_t)
 Get average value of tab excluding most extreme values.
 

Functions

BYTE RestrictedAverage_BYTE (volatile const BYTE pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (BYTE)
 
WORD RestrictedAverage_WORD (volatile const WORD pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (WORD)
 
DWORD RestrictedAverage_DWORD (volatile const DWORD pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (DWORD)
 
SBYTE RestrictedAverage_SBYTE (volatile const SBYTE pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (SBYTE)
 
SWORD RestrictedAverage_SWORD (volatile const SWORD pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (SWORD)
 
SDWORD RestrictedAverage_SDWORD (volatile const SDWORD pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (SDWORD)
 
float RestrictedAverage_float (volatile const float pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (float)
 
double RestrictedAverage_double (volatile const double pArray[], const uint8_t nb)
 Get average value of tab excluding most extreme values (double)
 

Detailed Description

Averaging inlines.

Author
SMFSW

Macro Definition Documentation

◆ RESTRICTED_AVERAGE

#define RESTRICTED_AVERAGE ( typ_t,
sum_t )
Value:
__INLINE typ_t RestrictedAverage_##typ_t(volatile const typ_t pArray[], const uint8_t nb) \
{ \
const typ_t n = (typ_t) nb - (typ_t) 2; \
typ_t average = (typ_t) 0; \
\
if (nb > 2U) \
{ \
/* Array copy (memcpy not used as copy by byte and pTab may be volatile) */ \
typ_t array[nb]; \
for (uintCPU_t i = 0 ; i < nb ; i++) { array[i] = pArray[i]; } \
\
/* Sum and min/max recording */ \
sum_t min_val = pArray[0]; \
sum_t max_val = pArray[0]; \
sum_t sum = (typ_t) 0; \
for (uintCPU_t i = 0 ; i < nb ; i++) \
{ \
sum += array[i]; \
if (array[i] > max_val) { max_val = array[i]; } \
if (array[i] < min_val) { min_val = array[i]; } \
} \
\
/* Averaging */ \
sum -= min_val + max_val; \
sum /= n; \
average = (typ_t) sum; \
} \
\
return average; \
}
#define __INLINE
inline attribute alias
Definition arm_keywords.h:82
unsigned int uintCPU_t
Unsigned integer typedef.
Definition arm_typedefs.h:63

Get average value of tab excluding most extreme values.

MISRA C:2012 Deviations
Function scope deviation granted for:
Rule-20.10 - Advisory: # and ## preprocessor operators (misra-c2012-20.10)
Local legitimate use derogation authorized for:
Rule-18.8 - Required: Var-length array types (misra-c2012-18.8)
Justification: pArray is used as array, makes sense to declare it in the same manner.
Justification: copy array needs to have a size and is always used in conjunction with nb.
Rule-20.7 - Required: Enclosed macro parameters expansion (misra-c2012-20.7)
Justification: typ_t parameter would always be used as cast and wouldn't catenate name.
Rule-20.12 - Required: macro parameter operand to # or ## (misra-c2012-20.12)
Justification: compliant use.

Function Documentation

◆ RestrictedAverage_BYTE()

BYTE RestrictedAverage_BYTE ( volatile const BYTE pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (BYTE)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (not dangerous for BYTEs). Disabling interruptions before calling function can overcome this behavior if needed (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to BYTEs array
[in]nb- Number of array elements
Returns
Average value (BYTE)

◆ RestrictedAverage_double()

double RestrictedAverage_double ( volatile const double pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (double)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (which can lead to corrupted results). Disabling interruptions before calling function can overcome this behavior (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to doubles array
[in]nb- Number of array elements
Returns
Average value (double)

◆ RestrictedAverage_DWORD()

DWORD RestrictedAverage_DWORD ( volatile const DWORD pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (DWORD)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (which can lead to corrupted results for 8b and 16b MCU). Disabling interruptions before calling function can overcome this behavior if needed (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to DWORDs array
[in]nb- Number of array elements
Returns
Average value (DWORD)

◆ RestrictedAverage_float()

float RestrictedAverage_float ( volatile const float pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (float)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (which can lead to corrupted results). Disabling interruptions before calling function can overcome this behavior (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to floats array
[in]nb- Number of array elements
Returns
Average value (float)

◆ RestrictedAverage_SBYTE()

SBYTE RestrictedAverage_SBYTE ( volatile const SBYTE pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (SBYTE)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (not dangerous for SBYTEs). Disabling interruptions before calling function can overcome this behavior if needed (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to SBYTEs array
[in]nb- Number of array elements
Returns
Average value (SBYTE)

◆ RestrictedAverage_SDWORD()

SDWORD RestrictedAverage_SDWORD ( volatile const SDWORD pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (SDWORD)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (which can lead to corrupted results for 8b and 16b MCU). Disabling interruptions before calling function can overcome this behavior if needed (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to SDWORDs array
[in]nb- Number of array elements
Returns
Average value (SDWORD)

◆ RestrictedAverage_SWORD()

SWORD RestrictedAverage_SWORD ( volatile const SWORD pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (SWORD)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (which can lead to corrupted results for 8b MCU). Disabling interruptions before calling function can overcome this behavior if needed (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to SWORDs array
[in]nb- Number of array elements
Returns
Average value (SWORD)

◆ RestrictedAverage_WORD()

WORD RestrictedAverage_WORD ( volatile const WORD pArray[],
const uint8_t nb )
inline

Get average value of tab excluding most extreme values (WORD)

Warning
If pArray is volatile array: A new value may be written in the tab (by interrupt for example) while copying it (which can lead to corrupted results for 8b MCU). Disabling interruptions before calling function can overcome this behavior if needed (not forgetting to re-enable interrupts afterwards).
Parameters
[in]pArray- Pointer to WORDs array
[in]nb- Number of array elements
Returns
Average value (WORD)