This repository has been archived on 2026-02-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
can/Inc/mmr_can_util.h
T
Stefano Calabretti ed2a26fbc9 Better parameter handling (#6)
* Add rx event handlers

* Fix compile errors and add constness

* Pass sender id

* Change api interface

* Revert changes

* Add filter fifo

* Add default setup

* Add receive function

* Remove interrupt activation

* Activate RX interrupts

* Merge remote changes

* Add event list constructor

* Fix compilation bug

* Send and receive multiple frames

* Refactor

* Refactor

* Fix compile error

* Use known syntax

* Refactor

* Provide storage

* Add frame end

* Add some documentation

* Turn macros into functions

* Refactor

* Refactor

* Fix compile error

* Use ExtendedIds

* Fix reception bug (fixes #4)

* Add packet headers

* Refactor

Co-authored-by: Riccardo998 <riccardo.storchi98@gmail.com>
2021-12-20 15:12:57 +01:00

42 lines
1.0 KiB
C

#ifndef INC_MMR_CAN_UTIL_H_
#define INC_MMR_CAN_UTIL_H_
#include <stdint.h>
#include <string.h>
#define sizeofarray(array) \
(sizeof(array) / sizeof(*(array)))
#define stringArrayLength(array) \
stringBufferLength((array), sizeofarray(array))
#define stringBufferLength(pbuffer, maxLen) \
strnlen((const char*)(pbuffer), maxLen)
#define min(a, b) ((a) < (b) ? a : b);
#define mask(value, bits) (value & bits)
#define convertTo(resultType, lvalue) (*interpretAs(resultType*, &(lvalue)))
#define interpretAs(resultType, lvalue) ((resultType)(lvalue))
/**
* @brief
* Represents the result of an asynchronous computation
*
* Either
* - Error: the computation resulted in error
* - Pending: the computation is still undergoing
* - Completed: the computation has completed succesfully
* and its results can be read
*
* Asynchronous logig can be easily implemented using State Machines
*/
typedef enum {
MMR_ASYNC_RESULT_ERROR,
MMR_ASYNC_RESULT_PENDING,
MMR_ASYNC_RESULT_COMPLETED,
} MmrAsyncResult;
#endif /* INC_MMR_CAN_UTIL_H_ */