Skip to content

Commit

Permalink
sa rev
Browse files Browse the repository at this point in the history
  • Loading branch information
camilo committed Feb 13, 2024
1 parent 9e435a2 commit 41c4817
Show file tree
Hide file tree
Showing 20 changed files with 587 additions and 587 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Built for](https://img.shields.io/badge/built%20for-microcontrollers-lightgrey?logo=WhiteSource)](https://github.com/kmilo17pet/qTools)
[![CodeFactor](https://www.codefactor.io/repository/github/kmilo17pet/qlibs/badge)](https://www.codefactor.io/repository/github/kmilo17pet/qlibs)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/14d566939d2e4d4181088cc1c6666fa3)](https://www.codacy.com/gh/kmilo17pet/qTools/dashboard?utm_source=github.com&utm_medium=referral&utm_content=kmilo17pet/qTools&utm_campaign=Badge_Grade)
[![DeepSource](https://app.deepsource.com/gh/kmilo17pet/qlibs-cpp.svg/?label=code+coverage&show_trend=true&token=v2gmYWIv1qjuUS9q01v_ncon)](https://app.deepsource.com/gh/kmilo17pet/qlibs-cpp/)
[![DeepSource](https://app.deepsource.com/gh/kmilo17pet/qlibs.svg/?label=active+issues&show_trend=true&token=sM8bC9gGb5PdO1ronKdoDhUh)](https://app.deepsource.com/gh/kmilo17pet/qlibs/)
[![documentation](https://github.com/kmilo17pet/qlibs/actions/workflows/doxygen_gen.yml/badge.svg)](https://kmilo17pet.github.io/qlibs/)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/kmilo17pet/qlibs?logo=webpack)](https://github.com/kmilo17pet/qlibs/releases)
[![MISRAC2012](https://img.shields.io/badge/MISRAC2012-Compliant-blue.svg?logo=c)](https://en.wikipedia.org/wiki/MISRA_C)
Expand Down
152 changes: 76 additions & 76 deletions include/qcrc.h

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions include/qffmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,33 @@ extern "C" {
/*! @endcond */

/** @brief The base of natural logarithms ( e ) given as a single-precision floating-point number*/
#define QFFM_E ( 2.7182818284590452354f )
#define QFFM_E ( 2.7182818284590452354F )
/** @brief The base 2 logarithm of e ( log_2 e ) given as a single-precision floating-point number */
#define QFFM_LOG2E ( 1.4426950408889634074f )
#define QFFM_LOG2E ( 1.4426950408889634074F )
/** @brief The base 10 logarithm of e ( log_10 e ) given as a single-precision floating-point number */
#define QFFM_LOG10E ( 0.43429448190325182765f )
#define QFFM_LOG10E ( 0.43429448190325182765F )
/** @brief The natural logarithm of 2 ( ln 2 ) given as a single-precision floating-point number */
#define QFFM_LN2 ( 0.69314718055994530942f )
#define QFFM_LN2 ( 0.69314718055994530942F )
/** @brief The natural logarithm of 10 ( ln 10 ) given as a single-precision floating-point number */
#define QFFM_LN10 ( 2.30258509299404568402f )
#define QFFM_LN10 ( 2.30258509299404568402F )
/** @brief The circumference of a circle with diameter 1, ( π ) given as a single-precision floating-point number */
#define QFFM_PI ( 3.14159265358979323846f )
#define QFFM_PI ( 3.14159265358979323846F )
/** @brief Half of π ( π/2 ) given as a single-precision floating-point number */
#define QFFM_PI_2 ( 1.57079632679489661923f )
#define QFFM_PI_2 ( 1.57079632679489661923F )
/** @brief A quarter of π ( π/4 ) given as a single-precision floating-point number */
#define QFFM_PI_4 ( 0.78539816339744830962f )
#define QFFM_PI_4 ( 0.78539816339744830962F )
/** @brief The inverse of π ( 1/π ) given as a single-precision floating-point number */
#define QFFM_1_PI ( 0.31830988618379067154f )
#define QFFM_1_PI ( 0.31830988618379067154F )
/** @brief Twice the inverse of π ( 2/π ) given as a single-precision floating-point number */
#define QFFM_2_PI ( 0.63661977236758134308f )
#define QFFM_2_PI ( 0.63661977236758134308F )
/** @brief The inverse of the square root of π ( 2/√π ) given as a single-precision floating-point number */
#define QFFM_2_SQRTPI ( 1.12837916709551257390f )
#define QFFM_2_SQRTPI ( 1.12837916709551257390F )
/** @brief The square root of 2 ( √2 ) given as a single-precision floating-point number */
#define QFFM_SQRT2 ( 1.41421356237309504880f )
#define QFFM_SQRT2 ( 1.41421356237309504880F )
/** @brief The inverse of square root of 2 ( 1/√2 ) given as a single-precision floating-point number */
#define QFFM_SQRT1_2 ( 0.70710678118654752440f )
#define QFFM_SQRT1_2 ( 0.70710678118654752440F )
/** @brief The maximum value of a non-infinite single-precision floating-point number */
#define QFFM_MAXFLOAT ( 3.40282347e+38f )
#define QFFM_MAXFLOAT ( 3.40282347e+38F )
/** @brief Positive infinity given as a single-precision floating-point number */
#define QFFM_INFINITY _qFFMath_GetAbnormal( 0 )
/** @brief Not a Number (NaN) given as a single-precision floating-point number */
Expand Down
6 changes: 3 additions & 3 deletions include/qfp16.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ extern "C" {
* @return The literal argument @a x converted to fixed-point(qFP16_t).
*/
#define qFP16_Constant(x) \
( (qFP16_t)( ( (x) >= 0 ) ? ( (x) * 65536.0f + 0.5f ) \
: ( (x) * 65536.0f - 0.5f ) ) ) \
( (qFP16_t)( ( (x) >= 0 ) ? ( (x) * 65536.0F + 0.5F ) \
: ( (x) * 65536.0F - 0.5F ) ) ) \

/**
* @brief A Q16.16 fixed-point settings object
Expand Down Expand Up @@ -101,7 +101,7 @@ extern "C" {
/**
* @brief Select the provided setting instance to perform fixed-point
* operations.
* @param[in] instance A pointer to the fixed-point settings instance. Pass
* @param[in] instance A pointer to the fixed-point settings instance. Pass
* @c NULL to use the default settings.
* @return none.
*/
Expand Down
12 changes: 6 additions & 6 deletions include/qltisys.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ extern "C" {
/**
* @brief Macro to specify that the system is time-discrete
*/
#define QLTISYS_DISCRETE ( -1.0f )
#define QLTISYS_DISCRETE ( -1.0F )

/*cstat -MISRAC2012-Rule-2.3*/

/**
* @brief Type to specify continuos states
* @brief Type to specify continuos states
*/
typedef qNumA_state_t qLTISys_ContinuosX_t;

/**
* @brief Type to specify continuos states
* @brief Type to specify continuos states
*/
typedef float qLTISys_DiscreteX_t;

Expand Down Expand Up @@ -129,7 +129,7 @@ extern "C" {
* polynomial. Coefficients will be normalized internally.
* @param[in,out] x Initial conditions of the system. For a continuos system,
* an array of type qLTISys_ContinuosX_t with n elements.
* For a discrete system, an array of type qLTISys_DiscreteX_t with
* For a discrete system, an array of type qLTISys_DiscreteX_t with
* max(na,nb) elements
* For both cases, the supplied array will be updated on every invocation of
* qLTISys_Excite().
Expand All @@ -138,9 +138,9 @@ extern "C" {
* @note If the system is continuous, pass 0 as argument.
* @param[in] na The order of polynomial @a den. (if system is discrete). For
* continuous system the number of elements of @a num and @a den.
*
*
* example 1: \f$ a_{0}+a_{1}z^{-1}+a_{2}z^{-2}+a_{3}z^{-3}, na = 3 \f$
*
*
* example 2: \f$ \frac{ b_{0}s^{2}+b_{1}s+b_{2} }{ a_{0}s^{2} + a_{1}s + a_{2} }, na = 3 \f$
* @note For continuous systems, size of @a num and @a den should be equal.
* @param[in] dt The time-step of the continuos system. For discrete systems
Expand Down
2 changes: 1 addition & 1 deletion include/qpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern "C" {
/**
* @brief Macro to keep the auto-tuner enabled indefinitely
*/
#define QPID_AUTOTUNING_UNDEFINED ( 0xFFFFFFFEuL )
#define QPID_AUTOTUNING_UNDEFINED ( 0xFFFFFFFEUL )

/**
* @brief A PID controller object
Expand Down
58 changes: 29 additions & 29 deletions qbitfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void qBitField_Write_uint32( qBitField_t *b,
/*============================================================================*/
static uint32_t qBitField_Mask( const size_t index )
{
return (uint32_t)1u << ( index % qBitField_LBit );
return (uint32_t)1U << ( index % qBitField_LBit );
}
/*============================================================================*/
static size_t qBitField_BitSlot( const size_t index )
Expand All @@ -44,7 +44,7 @@ static uint32_t qBitField_BitGet( const qBitField_t * const b,
{
const size_t slot = qBitField_BitSlot( index );

return ( b->field[ slot ] >> ( index % qBitField_LBit ) ) & 1u;
return ( b->field[ slot ] >> ( index % qBitField_LBit ) ) & 1U;
}
/*============================================================================*/
static void qBitField_BitSet( qBitField_t * const b,
Expand Down Expand Up @@ -82,7 +82,7 @@ static uint32_t qBitField_SafeMask( const uint32_t val,
/*============================================================================*/
static size_t qBitField_Offset( const size_t index )
{
return index & (size_t)31u;
return index & (size_t)31U;
}
/*============================================================================*/
static uint32_t qBitField_MaskMerge( const uint32_t w,
Expand All @@ -98,12 +98,12 @@ int qBitField_Setup( qBitField_t * const b,
{
int retValue = 0;

if ( ( NULL != b ) && ( NULL != area ) && ( area_size > 0u ) ) {
if ( ( NULL != b ) && ( NULL != area ) && ( area_size > 0U ) ) {
/*cstat -MISRAC2012-Rule-11.5 -CERT-EXP36-C_b*/
/*cppcheck-suppress misra-c2012-11.5 */
b->field = (uint32_t *)area;
/*cstat +MISRAC2012-Rule-11.5 +CERT-EXP36-C_b*/
b->size = area_size*8u;
b->size = area_size*8U;
b->nSlots = area_size/sizeof(uint32_t);
retValue = 1;
}
Expand All @@ -116,7 +116,7 @@ int qBitField_ClearAll( qBitField_t * const b )
int retValue = 0;

if ( NULL != b ) {
(void)memset( b->field, 0, b->size/8u );
(void)memset( b->field, 0, b->size/8U );
retValue = 1;
}

Expand All @@ -128,7 +128,7 @@ int qBitField_SetAll( qBitField_t * const b )
int retValue = 0;

if ( NULL != b ) {
(void)memset( b->field, 0xFF, b->size/8u );
(void)memset( b->field, 0xFF, b->size/8U );
retValue = 1;
}

Expand Down Expand Up @@ -177,10 +177,10 @@ int qBitField_ToggleBit( qBitField_t * const b,
uint8_t qBitField_ReadBit( const qBitField_t * const b,
const size_t index )
{
uint8_t retValue = 0u;
uint8_t retValue = 0U;

if ( NULL != b ) {
retValue = ( 0u != qBitField_BitGet( b, index ) )? 1u : 0u;
retValue = ( 0U != qBitField_BitGet( b, index ) )? 1U : 0U;
}

return retValue;
Expand All @@ -193,7 +193,7 @@ int qBitField_WriteBit( qBitField_t * const b,
int retValue = 0;

if ( NULL != b ) {
if ( 0u != value ) {
if ( 0U != value ) {
qBitField_BitSet( b, index );
}
else {
Expand All @@ -209,18 +209,18 @@ uint32_t qBitField_ReadUINTn( const qBitField_t * const b,
const size_t index,
size_t xBits )
{
uint32_t retValue = 0u;
uint32_t retValue = 0U;

if ( ( NULL != b ) && ( xBits <= 32u ) ) {
if ( 1u == xBits ) {
if ( ( NULL != b ) && ( xBits <= 32U ) ) {
if ( 1U == xBits ) {
retValue = (uint32_t)qBitField_ReadBit( b, index );
}
else if ( 32u == xBits ) {
else if ( 32U == xBits ) {
retValue = qBitField_Read_uint32( b, index );
}
else {
retValue = qBitField_Read_uint32( b, index );
retValue &= qBitField_SafeMask( 0xFFFFFFFFu, 32u, xBits );
retValue &= qBitField_SafeMask( 0xFFFFFFFFU, 32U, xBits );
}
}

Expand All @@ -234,20 +234,20 @@ int qBitField_WriteUINTn( qBitField_t * const b,
{
int retValue = 0;

if ( ( NULL != b ) && ( xBits <= 32u ) ) {
if ( ( NULL != b ) && ( xBits <= 32U ) ) {
uint32_t w, mask;

if ( 1u == xBits ) {
if ( 1U == xBits ) {
(void)qBitField_WriteBit( b, index, (uint8_t)value );
}
else if ( 32u == xBits ) {
else if ( 32U == xBits ) {
qBitField_Write_uint32( b, index, value );
}
else {
w = qBitField_Read_uint32( b, index );
value &= qBitField_SafeMask( 0xFFFFFFFFu, 32u, xBits );
value &= qBitField_SafeMask( 0xFFFFFFFFU, 32U, xBits );
/*cstat -ATH-overflow*/
mask = (uint32_t)0xFFFFFFFFu << (uint32_t)xBits;
mask = (uint32_t)0xFFFFFFFFU << (uint32_t)xBits;
/*cstat +ATH-overflow*/
qBitField_Write_uint32( b, index, qBitField_MaskMerge( w, value, mask ) );
}
Expand All @@ -260,7 +260,7 @@ int qBitField_WriteUINTn( qBitField_t * const b,
float qBitField_ReadFloat( const qBitField_t * const b,
const size_t index )
{
float retValue = 0.0f;
float retValue = 0.0F;

if ( NULL != b ) {
uint32_t rval;
Expand All @@ -280,7 +280,7 @@ int qBitField_WriteFloat( qBitField_t * const b,
int retValue = 0;

if ( NULL != b ) {
uint32_t fval = 0u;
uint32_t fval = 0U;
/*cppcheck-suppress misra-c2012-21.15 */
(void)memcpy( &fval, &value, sizeof(float) );
qBitField_Write_uint32( b, index, fval );
Expand All @@ -297,7 +297,7 @@ void* qBitField_Dump( const qBitField_t * const b,
void *retValue = NULL;

if ( ( NULL != b ) && ( NULL != dst ) ) {
if ( n <= ( b->size/8u ) ) {
if ( n <= ( b->size/8U ) ) {
retValue = memcpy( dst, (const void*)b->field, n );
}
}
Expand All @@ -314,10 +314,10 @@ static uint32_t qBitField_Read_uint32( const qBitField_t * const b,
slot = qBitField_BitSlot( index );
of = qBitField_Offset( index );
result = b->field[ slot ] >> of;
bits_taken = 32u - of;
if ( ( 0u != of ) && ( ( index + bits_taken ) < b->size ) ) {
bits_taken = 32U - of;
if ( ( 0U != of ) && ( ( index + bits_taken ) < b->size ) ) {
/*cstat -CERT-INT30-C_a -ATH-shift-bounds -MISRAC2012-Rule-12.2 -CERT-INT34-C_b*/
result |= b->field[ slot + 1u ] << (uint32_t)bits_taken;
result |= b->field[ slot + 1U ] << (uint32_t)bits_taken;
/*cstat +CERT-INT30-C_a +ATH-shift-bounds +MISRAC2012-Rule-12.2 +CERT-INT34-C_b*/
}

Expand All @@ -333,14 +333,14 @@ static void qBitField_Write_uint32( qBitField_t *b,

slot = qBitField_BitSlot( index );
of = qBitField_Offset( index );
if ( 0u == of ) {
if ( 0U == of ) {
b->field[ slot ] = value;
}
else {
mask = qBitField_SafeMask( 0xFFFFFFFFu, qBitField_LBit, of );
mask = qBitField_SafeMask( 0xFFFFFFFFU, qBitField_LBit, of );
b->field[ slot ] = ( value << of ) | ( b->field[ slot ] & mask );
if ( ++slot < b->nSlots ) {
b->field[ slot ] = qBitField_SafeMask( value, 32u, of ) |
b->field[ slot ] = qBitField_SafeMask( value, 32U, of ) |
( b->field[ slot ] & ( ~mask ) );
}
}
Expand Down
34 changes: 17 additions & 17 deletions qcrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ static uint32_t qCRCx_Reflect( uint32_t xData,
uint32_t r = 0;
uint8_t xBit;
/*Reflect the data about the center bit*/
for ( xBit= 0u ; xBit < nBits ; ++xBit ) {
for ( xBit= 0U ; xBit < nBits ; ++xBit ) {
/*if the LSB bit is set, set the reflection of it*/
if ( 0u != ( xData & 0x01u ) ) {
if ( 0U != ( xData & 0x01U ) ) {
/*cstat -MISRAC2012-Rule-10.8 -ATH-shift-bounds -MISRAC2012-Rule-12.2 -CERT-INT34-C_b*/
/*cppcheck-suppress misra-c2012-10.8 */
r |= (uint32_t)( 1u << ( ( nBits - 1u ) - xBit ) );
r |= (uint32_t)( 1U << ( ( nBits - 1U ) - xBit ) );
/*cstat +MISRAC2012-Rule-10.8 +ATH-shift-bounds +MISRAC2012-Rule-12.2 +CERT-INT34-C_b*/
}
xData >>= 1u;
xData >>= 1U;
}

return r;
Expand All @@ -39,38 +39,38 @@ uint32_t qCRCx( const qCRC_Mode_t mode,
const uint8_t refOut,
uint32_t xorOut )
{
uint32_t crc = 0u;
uint32_t crc = 0U;
/*cstat -ATH-cmp-unsign-pos*/
if ( ( NULL != pData ) && ( length > 0u ) && ( mode >= QCRC8 ) && ( mode <= QCRC32 ) ) {
if ( ( NULL != pData ) && ( length > 0U ) && ( mode >= QCRC8 ) && ( mode <= QCRC32 ) ) {
/*cstat +ATH-cmp-unsign-pos*/
size_t i;
uint8_t xBit;
const uint32_t widthValues[ 3 ] = { 8uL, 16uL, 32uL };
const uint32_t widthValues[ 3 ] = { 8UL, 16UL, 32UL };
const uint32_t width = widthValues[ mode ];
/*cstat -MISRAC2012-Rule-11.5 -CERT-EXP36-C_b*/
/*cppcheck-suppress misra-c2012-11.5 */
uint8_t const * const msg = pData;
/*cstat +MISRAC2012-Rule-11.5 +CERT-EXP36-C_b*/
const uint32_t wd1 = (uint32_t)width - 8u;
const uint32_t topBit = (uint32_t)1u << ( width - 1u );
const uint32_t bitMask = ( 0xFFFFFFFFu >> ( 32u - width ) );
const uint32_t wd1 = (uint32_t)width - 8U;
const uint32_t topBit = (uint32_t)1U << ( width - 1U );
const uint32_t bitMask = ( 0xFFFFFFFFU >> ( 32U - width ) );
poly &= bitMask;
xorOut &= bitMask;
crc = init;
/*Perform modulo-2 division, a byte at a time. */
for ( i = 0u ; i < length ; ++i ) {
for ( i = 0U ; i < length ; ++i ) {
/*cstat -CERT-INT34-C_a*/
crc ^= ( 0u != refIn ) ?
( qCRCx_Reflect( (uint32_t)msg[ i ], 8u ) << wd1 ) :
crc ^= ( 0U != refIn ) ?
( qCRCx_Reflect( (uint32_t)msg[ i ], 8U ) << wd1 ) :
( (uint32_t)msg[ i ] << wd1 );
/*cstat +CERT-INT34-C_a*/
for ( xBit = 8u ; xBit > 0u ; --xBit ) {
for ( xBit = 8U ; xBit > 0U ; --xBit ) {
/*try to divide the current data bit*/
crc = ( 0u != ( crc & topBit ) ) ? ( ( crc << 1u ) ^ poly )
: ( crc << 1u );
crc = ( 0U != ( crc & topBit ) ) ? ( ( crc << 1U ) ^ poly )
: ( crc << 1U );
}
}
crc = ( 0u != refOut ) ? ( qCRCx_Reflect( crc, (uint8_t)width )^xorOut )
crc = ( 0U != refOut ) ? ( qCRCx_Reflect( crc, (uint8_t)width )^xorOut )
: ( crc^xorOut );
crc &= bitMask;
}
Expand Down
Loading

0 comments on commit 41c4817

Please sign in to comment.