Common function reference
common.h
Defines
ROCKETLIB_VERSION_MAJOR : Rocketlib major release number, shall be the design cycle year.
ROCKETLIB_VERSION_MINOR : Rocketlib minor release number, shall be the RocketCAN protocol version.
ROCKETLIB_VERSION_PATCH : Rocketlib patch release number, shall be the n-th revision of this library that does not involve RocketCAN protocol change.
STATIC_ASSERT(expr, msg)
w_assert(statement) : Assertion.
Works just like standard C assertion, except use can define custom assertion failure handler(see `w_assert_fail`), only active when `W_DEBUG` is definedTypedefs
typedef double float64_t
Enums
enum w_status_t : Standard error code.
*Values:*
enumerator W\_SUCCESS
: Success.
enumerator W\_FAILURE
: Failure, if not one of the more specific case below.
enumerator W\_INVALID\_PARAM
: Illegal function call arguments/parameters.
enumerator W\_IO\_ERROR
: IO error, for example no SD card was plugged in.
enumerator W\_IO\_TIMEOUT
: IO timeout, for example SD card takes too long to respond.
enumerator W\_MATH\_ERROR
: Math error, for example divide by zero.
enumerator W\_OVERFLOW
: Buffer overflow, for example trying to write/push to a full FIFO buffer.
enumerator W\_UNDERFLOW
: Buffer underflow, for example trying to read/pop from an empty FIFO buffer.
enumerator W\_DATA\_FORMAT\_ERROR
: Data format error, for example input is a malformed CAN packet.
enumerator W\_NO\_DATA
: Succeed, but no data available.Functions
void w_assert_fail(const char *file, int line, const char *statement) : Assertion fail handler.
Assertion fail handler, shall be implemented in the firmware, only used if `W_DEBUG` is defined
Parameters:
: - **file** – Path to C source file contains assertion failure
- **line** – C source line number of assertion failure
- **statement** – Statement caused assertion failurecrc8.h
Functions
uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc) : Compute CRC8.
Computes the CRC8 checksum of input data
Parameters:
: - **pdata** – Input data buffer
- **nbytes** – Buffer size in bytes
- **crc** – CRC8 checksum of previous CRC8 calculation if calculating checksum on multiple discontinuous buffers, otherwise 0
Returns:
: Computed CRC8 checksumelectrical.h
Defines
RAIL_12V_MAX_mV
RAIL_12V_MIN_mV
INA180A3_GAIN
low_pass_filter.h
Low-pass filter implementation.
This module provides a low-pass filter implementation for smoothing sensor readings and reducing noise in analog signals. The filter uses an exponential moving average algorithm with configurable response time.
Functions
static inline double sample_freq(double time_diff_ms) : Calculate the sample frequency based on the time difference in milliseconds.
Parameters:
: **time\_diff\_ms** – Time difference between samples in milliseconds
Returns:
: double Sample frequency in Hzstatic inline double low_pass_alpha(double TR, double time_diff_ms) : Calculate the alpha value for the low-pass filter based on the response time.
The alpha value determines the filter’s responsiveness. A higher alpha value results in faster response but less filtering, while a lower alpha value provides more filtering but slower response.
Parameters:
: - **TR** – Response time constant in milliseconds
- **time\_diff\_ms** – Time difference between samples in milliseconds
Returns:
: double Alpha value (0.0 to 1.0) for the low-pass filterw_status_t low_pass_filter_init(double *alpha, double response_time) : Initializes the low-pass filter by calculating and storing the alpha value.
This function calculates the alpha value based on the given response time and stores it in the provided pointer. The alpha value is used in subsequent filter updates.
Parameters:
: - **alpha** – Pointer to store the calculated alpha value
- **response\_time** – Response time constant in milliseconds (must be > 0)
Returns:
: w\_status\_t Returns W\_SUCCESS on success, W\_INVALID\_PARAM if alpha is NULL or response\_time is invalidw_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value) : Updates the low-pass filter with a new value and returns the operation status.
This function applies the low-pass filter algorithm to the new input value using the provided alpha value. The filtered result is stored in low\_pass\_value and updated in-place for the next iteration.
Parameters:
: - **alpha** – Alpha value (0.0 to 1.0) for the low-pass filter
- **new\_input\_value** – New input value to filter
- **low\_pass\_value** – Pointer to the current filtered value (updated in-place)
Returns:
: w\_status\_t Returns W\_SUCCESS on success, W\_INVALID\_PARAM if low\_pass\_value is NULL or alpha is out of valid range (0.0 to 1.0)mathops.h
Functions
static inline uint32_t value_clamp_uint32(uint32_t x, uint32_t low, uint32_t high) : Clamps a 32 bit unsigned integer between a lower and upper bound.
Parameters:
: - **x** – The value to clamp
- **low** – The lower bound, inclusive
- **high** – The upper bound, inclusive
Returns:
: The clamped valuestatic inline int32_t value_clamp_int32(int32_t x, int32_t low, int32_t high) : Clamps a 32 bit signed integer between a lower and upper bound.
Parameters:
: - **x** – The value to clamp
- **low** – The lower bound, inclusive
- **high** – The upper bound, inclusive
Returns:
: The clamped valuestatic inline float32_t value_clamp_float32(float32_t x, float32_t low, float32_t high) : Clamps a 32 bit float between a lower and upper bound.
Parameters:
: - **x** – The value to clamp
- **low** – The lower bound, inclusive
- **high** – The upper bound, inclusive
Returns:
: The clamped value