/** * DI CAN context locking */ #ifndef LIBDI_INCLUDE_CAN_REQREP_H_ #define LIBDI_INCLUDE_CAN_REQREP_H_ #include #include #ifdef __cplusplus extern "C" { #endif struct di_can_ctx; struct di_can_msg; /** * Request-reply item */ struct di_can_reqrep_item { uint32_t src_id; /**< Source node id */ uint32_t canid; /**< Reply canid */ di_bsem_t sem; /**< Waiting semaphore */ struct di_can_msg *msg; /**< Message */ }; /** Initialize the reqrep subsystem */ void di_can_reqrep_init(struct di_can_ctx *ctx); /** * Send an request and return an reply * @param reqrep Request message, replaced by reply message when DNOK * @param timeout_ms Time until timeout in milliseconds * @retval DNOK when reply is received and reqrep parameter is replaced by reply, DNE_TIMEOUT otherwise * @note The caller is responsible for freeing the request when failed (!DNOK), and freeing the reply when DNOK */ di_errno_t di_can_reqrep(struct di_can_msg **reqrep, const uint32_t timeout_ms); /** * Send an request and return an reply try multiple times * @param reqrep Request message, replaced by reply message when DNOK * @param timeout_ms Time until timeout in milliseconds * @param retries Maximum number of retries * @retval DNOK when reply is received and reqrep parameter is replaced by reply, DNE_TIMEOUT otherwise */ di_errno_t di_can_reqrep_with_retry(struct di_can_msg **msg, const uint32_t timeout_ms, const size_t retries); /** * Add an reply to the reqrep. The msg state is set to APPLICATION when the reply is added so * it will not be garbage collected by the msg subsystem. * @note It ignores the transaction ID canid field * @return DNOK when added, DNE_NOTFOUND when no outstanding request */ di_errno_t di_can_reqrep_add_reply(struct di_can_ctx *ctx, struct di_can_msg *msg); #ifdef __cplusplus } #endif #endif /* LIBDI_INCLUDE_CAN_REQREP_H_ */