Macros Utility Header
Macros Utility
Section titled “Macros Utility”Path: src/modbus/macros.h
Revision History: Initial documentation
A comprehensive collection of utility macros for ESP-32 development. This header provides macro definitions for commonly used operations in embedded systems programming, avoiding the use of the standard library. It includes macros for type manipulation, bit operations, mathematical functions, array handling, compile-time optimizations, and more.
Requirements
Section titled “Requirements”- ESP-32 platform
- C17 compliant compiler
- No standard library dependencies
Provides
Section titled “Provides”- Incrementation/Decrementation:
INC_X
,DEC_X
,INCREMENT
,DECREMENT
- Compiler Optimizations:
FORCE_INLINE
,_UNUSED
,NOOP
- Argument Counting/Testing:
NUM_ARGS
,TWO_ARGS
- String Helpers:
CAT
,_CAT
- Conditional Compilation:
ENABLED
,DISABLED
,ANY
,ALL
,NONE
- Bit Manipulation:
__BV
,TEST
,SBI
,CBI
,SET_BIT_TO
- Math Operations:
WITHIN
,RADIANS
,DEGREES
,NEAR_ZERO
- Time Helpers:
PENDING
,ELAPSED
,HOUR_MS
,MIN_MS
- Array Initialization:
ARRAY_N
,ARRAY_1
throughARRAY_6
- C++11 Template Utilities: Min/Max templates, SFINAE helpers
Features
Section titled “Features”- Preprocessor macros for common calculations and operations
- Bit manipulation utilities
- Compile-time optimizations
- Safe type conversion helpers
- Template-based compile-time checks
- Time management utilities
- Array initialization helpers
- Conditional execution based on feature flags
Dependencies
Section titled “Dependencies”Behavior
Section titled “Behavior”The macros in this header provide utility functions that are used throughout the codebase. They do not have state or flow by themselves but enable cleaner, more efficient code.
Performance
Section titled “Performance”- Consider separating into multiple headers for faster compilation
- Add pre-processor optimization for frequently used macro combinations
Security
Section titled “Security”- No direct security concerns as these are compile-time macros
- Ensure macros don’t introduce unintended behaviors when used with user input
Compliance
Section titled “Compliance”- Compatible with C17 standard
- Designed for ESP-32 and industrial Modbus applications
- No use of standard library functions
Recommendations
Section titled “Recommendations”- Group related macros when using in implementation files
- Use the ENABLED/DISABLED macros for feature toggling
- Prefer the template-based MIN/MAX over macro versions when in C++ code
- Consider the resource constraints of ESP-32 when using complex macro expansions