src.dualinventive.com/fw/dncm/libdi/include/di/can/callback.h

77 lines
1.9 KiB
C

/**
* @ingroup can
* @defgroup can_callback Messaging callbacks
* @brief DI CAN messaging callbacks
* @date Feb 10, 2016
* @author jjacobs
* @copyright 2016 Dual Inventive Technology Centre B.V.
*
* DI CAN messaging callbacks
* @{
*/
#ifndef LIBDI_INCLUDE_DI_CAN_CALLBACK_H_
#define LIBDI_INCLUDE_DI_CAN_CALLBACK_H_
#include <stdlib.h>
#include <stdint.h>
#include <di/types.h>
struct di_can_ctx;
struct di_can_msg;
struct di_can_frame_rx;
struct di_can_frame_tx;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Create CAN ID for a callback item
* @param msgtype enum #di_can_msgtype
* @param transfertype enum #di_can_transfertype
* @param datatype enum #di_can_raw_dtypes, enum #di_rpc_types or enum #di_can_net_dtypes
*/
#define DI_CAN_CALLBACK_CANID(msgtype, transfertype, datatype) \
(((msgtype) << DI_CAN_CANID_OFFSET_MSGTYPE) | \
((datatype) << DI_CAN_CANID_OFFSET_DATATYPE) | \
((transfertype) << DI_CAN_CANID_OFFSET_TRANSFERTYPE))
/**
* CAN message callback item
*/
struct di_can_callback {
uint32_t canid;
void (*callback)(const struct di_can_msg *msg, struct di_can_ctx *ctx);
};
/**
* Initialize callbacks
*/
di_errno_t di_can_callback_init(struct di_can_ctx *ctx, const struct di_can_callback *list, size_t size);
/**
* Set send callback
*/
void di_can_callback_set_send(struct di_can_ctx *ctx, di_errno_t (*callback)(const struct di_can_frame_tx *frame));
/**
* Set receive callback
*/
void di_can_callback_set_recv(struct di_can_ctx *ctx, di_errno_t (*callback)(struct di_can_frame_rx *frame));
/**
* Execute callbacks when on all ready messages
* @param ctx CAN context
* @param msg CAN message
* @return DNOK when callback is executed or DNE_OPDENIED when callback is registered
*/
di_errno_t di_can_callback_execute(struct di_can_ctx *ctx, const struct di_can_msg *msg);
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* LIBDI_INCLUDE_DI_CAN_CALLBACK_H_ */