commit dadad59143bb6c8287b65d2841583f60f221fcc3 Author: Mohamed Salem Date: Mon Apr 13 03:51:33 2026 +0200 Initial: STD_TYPES shared type definitions diff --git a/inc/STD_TYPES.h b/inc/STD_TYPES.h new file mode 100644 index 0000000..f9f6ff3 --- /dev/null +++ b/inc/STD_TYPES.h @@ -0,0 +1,288 @@ +/****************************************************************************** + * File: STD_TYPES.h + * Component: STD_TYPES + * Description: Standard type definitions used across all components. + * Provides project-wide fixed-width integer typedefs, boolean + * types, and common return/status codes so that every module + * speaks the same "type language". + * + * Layer: Library (shared by all layers) + *****************************************************************************/ + +#ifndef STD_TYPES_H +#define STD_TYPES_H + +/* Standard type definitions will go here */ + +/* ************************************************************************** */ +/* ********************** PUBLIC TYPE DEFINITIONS **************************** */ +/* ************************************************************************** */ + +/** + * @addtogroup 1-LIB_TYP_Types + * @ingroup LIB_TYP + * @{ + */ + +/* ************************************************************************** */ +/* ************************ BASIC INTEGER TYPES ****************************** */ +/* ************************************************************************** */ + +/** + * @brief 8-bit unsigned integer type + * @details Size: 1 Byte, Range: [0 : 255] + */ +typedef unsigned char u8; +#define STD_u8MIN_VALUE ((u8)0) /**< Minimum value for u8 type */ +#define STD_u8MAX_VALUE ((u8)0xFF) /**< Maximum value for u8 type */ + +/** + * @brief 16-bit unsigned integer type + * @details Size: 2 Bytes, Range: [0 : 65535] + */ +typedef unsigned short int u16; +#define STD_u16MIN_VALUE ((u16)0) /**< Minimum value for u16 type */ +#define STD_u16MAX_VALUE ((u16)0xFFFFU) /**< Maximum value for u16 type */ + +/** + * @brief 32-bit unsigned integer type + * @details Size: 4 Bytes, Range: [0 : 4,294,967,295] + */ +typedef unsigned long int u32; +#define STD_u32MIN_VALUE ((u32)0) /**< Minimum value for u32 type */ +#define STD_u32MAX_VALUE ((u32)0xFFFFFFFFU) /**< Maximum value for u32 type */ + +/** + * @brief 64-bit unsigned integer type + * @details Size: 8 Bytes, Range: [0 : 18,446,744,073,709,551,615] + */ +typedef unsigned long long u64; +#define STD_u64MIN_VALUE ((u64)0) /**< Minimum value for u64 type */ +#define STD_u64MAX_VALUE ((u64)0xFFFFFFFFFFFFFFFFULL) /**< Maximum value for u64 type */ + +/** + * @brief 8-bit signed integer type + * @details Size: 1 Byte, Range: [-128 : 127] + */ +typedef signed char s8; +#define STD_s8MIN_VALUE ((s8)-128) /**< Minimum value for s8 type */ +#define STD_s8MAX_VALUE ((s8)127) /**< Maximum value for s8 type */ + +/** + * @brief 16-bit signed integer type + * @details Size: 2 Bytes, Range: [-32,768 : 32,767] + */ +typedef signed short int s16; +#define STD_s16MIN_VALUE ((s16)-32768) /**< Minimum value for s16 type */ +#define STD_s16MAX_VALUE ((s16)32767) /**< Maximum value for s16 type */ + +/** + * @brief 32-bit signed integer type + * @details Size: 4 Bytes, Range: [-2,147,483,648 : 2,147,483,647] + */ +typedef signed long int s32; +#define STD_s32MIN_VALUE ((s32)-2147483648) /**< Minimum value for s32 type */ +#define STD_s32MAX_VALUE ((s32)2147483647) /**< Maximum value for s32 type */ + +/** + * @brief 64-bit signed integer type + * @details Size: 8 Bytes, Range: [-9,223,372,036,854,775,808 : 9,223,372,036,854,775,807] + */ +typedef signed long long s64; +#define STD_s64MIN_VALUE ((s64)-9223372036854775807LL - 1LL) /**< Minimum value for s64 type */ +#define STD_s64MAX_VALUE ((s64)9223372036854775807LL) /**< Maximum value for s64 type */ + +/* ************************************************************************** */ +/* ************************* RESULT TYPES *********************************** */ +/* ************************************************************************** */ + +/** + * @brief Standard Result Type + * + * Enumeration for function return values indicating operation status + */ +typedef enum +{ + STD_OK = 0U, /**< Operation completed successfully */ + STD_INDEX_OUT_OF_RANGE_ERROR, /**< Array index out of bounds */ + STD_NULL_POINTER_ERROR, /**< Null pointer detected */ + STD_NOK /**< Operation failed */ +} STD_tenuResult; + +/* ************************************************************************** */ +/* ************************ CALLBACK TYPES ********************************** */ +/* ************************************************************************** */ + +/** + * @brief Callback Function Type + * @details Type definition for void callback functions + */ +typedef void (*STD_tpfCallbackFunc)(void); + +/** + * @brief Initialization Function Type + * @details Type definition for initialization functions returning STD_tenuResult + */ +typedef STD_tenuResult (*STD_tpfInitFunc)(void); + +/* ************************************************************************** */ +/* ************************ BOOLEAN AND STATE TYPES ************************* */ +/* ************************************************************************** */ + +/** + * @brief Boolean Type + * @details Standard boolean enumeration + */ +typedef enum +{ + STD_FALSE, /**< False value */ + STD_TRUE /**< True value */ +} STD_tBool; + +/** + * @brief State Type + * @details Standard state enumeration + */ +typedef enum +{ + STD_IDLE, /**< Idle state */ + STD_BUSY /**< Busy state */ +} STD_tenuState; + +/** + * @brief Compare State Type + * @details Type for comparison results + */ +typedef u8 STD_tu8CMPstate; + +/** @} */ // end of 1-LIB_TYP_Types group + + +/* ************************************************************************** */ +/* ************************* UTILITY MACROS ********************************* */ +/* ************************************************************************** */ + +/** + * @addtogroup 2-LIB_TYP_Macros + * @ingroup LIB_TYP + * @{ + */ + +/** @brief Null pointer definition */ +#define STD_NULL ((void *)0) + +/** + * @brief Constant qualifier macro + * @details Removes const qualifier in unit test builds + */ +#ifdef UTD +# define STD_CONST +#else +# define STD_CONST const +#endif + +/** + * @brief Static qualifier macro + * @details Removes static qualifier in unit test builds + */ +#ifdef UTD +# define STD_STATIC +#else +# define STD_STATIC static +#endif + +/** + * @brief Inline function macro + * @details Controls function inlining based on build type + */ +#ifdef UTD +# define STD_INLINE +#else +# define STD_INLINE __attribute__((always_inline)) inline +#endif + +/** + * @brief Interrupt function macro + * @details Marks functions as interrupts in non-test builds + */ +#ifdef UTD +# define STD_INTERRUPT +#else +# define STD_INTERRUPT __attribute__((interrupt)) +#endif + +/** + * @brief Non-inlined interrupt function macro + * @details Marks functions as non-inlined interrupts in non-test builds. This prevents + * the compiler from inlining interrupt service routines, which can be important + * for debugging and maintaining consistent interrupt latency. + */ +#ifdef UTD +# define STD_INTERRUPT_NO_INLINE +#else +# define STD_INTERRUPT_NO_INLINE __attribute__((interrupt, noinline)) +#endif + +/** + * @brief Weak symbol macro + * @details Marks symbols as weak in non-test builds + */ +#ifdef UTD +# define STD_WEAK +#else +# define STD_WEAK __attribute__((weak)) +#endif + +/** + * @brief Packed structure macro + * @details Forces packed memory layout + */ +#define STD_PACKED __attribute__((packed)) + +/** + * @brief 2-byte alignment macro + * @details Forces 2-byte alignment for structures and variables. + * Required for MLX16 architecture DMA buffers and optimal performance. + */ +#define STD_ALIGNED_2BYTE __attribute__((aligned(2))) + +/** + * @brief Switch case fallthrough macro + * @details Explicitly indicates intentional fallthrough in switch statements. + * Suppresses compiler warnings about implicit fallthrough between cases. + * Use this when you intentionally omit a break statement. + * @note Only available in GCC 7 and later + */ +#if __GNUC__ >= 7 +#define STD_FALLTHROUGH __attribute__((fallthrough)) +#else +#define STD_FALLTHROUGH +#endif + +/** + * @brief Static assertion macro + * @details Provides compile-time assertions for configuration validation. + * This macro abstracts the compiler-specific static assert mechanism + * allowing for easy portability across different compilers. + * + * @param condition The condition to assert (must be compile-time constant) + * @param message The error message to display if assertion fails + * + * @note For C11 compliant compilers, uses _Static_assert. + * For older compilers, falls back to a compatible implementation. + */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) + /* C11 and later: use standard _Static_assert */ + #define STD_STATIC_ASSERT(condition, message) _Static_assert(condition, message) +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) + /* GCC 4.6+: use _Static_assert extension */ + #define STD_STATIC_ASSERT(condition, message) _Static_assert(condition, message) +#else + /* Fallback for older compilers: use array size trick */ + #define STD_STATIC_ASSERT(condition, message) \ + typedef char static_assertion_##__LINE__[(condition) ? 1 : -1] +#endif + +/** @} */ // end of 2-LIB_TYP_Macros group + +#endif /* STD_TYPES_H */