diff --git a/sys/can/conn/isotp.c b/sys/can/conn/isotp.c index bd3516292f..bd268865ba 100644 --- a/sys/can/conn/isotp.c +++ b/sys/can/conn/isotp.c @@ -91,7 +91,7 @@ int conn_can_isotp_create(conn_can_isotp_t *conn, struct isotp_options *options, return 0; } -int conn_can_isotp_bind(conn_can_isotp_t *conn) +int conn_can_isotp_bind(conn_can_isotp_t *conn, struct isotp_fc_options *fc_options) { assert(conn != NULL); assert(conn->isotp.opt.tx_id != 0 || conn->isotp.opt.rx_id != 0); @@ -126,7 +126,7 @@ int conn_can_isotp_bind(conn_can_isotp_t *conn) put_msg(conn, &msg); } - ret = isotp_bind(&conn->isotp, &entry, conn); + ret = isotp_bind(&conn->isotp, &entry, conn, fc_options); if (!ret) { conn->bound = 1; } diff --git a/sys/can/isotp/isotp.c b/sys/can/isotp/isotp.c index 5ae8a9922c..7499ecf376 100644 --- a/sys/can/isotp/isotp.c +++ b/sys/can/isotp/isotp.c @@ -33,18 +33,6 @@ #define ENABLE_DEBUG (0) #include "debug.h" -#ifndef CAN_ISOTP_BS -#define CAN_ISOTP_BS 10 -#endif - -#ifndef CAN_ISOTP_STMIN -#define CAN_ISOTP_STMIN 5 -#endif - -#ifndef CAN_ISOTP_WFTMAX -#define CAN_ISOTP_WFTMAX 0 -#endif - #ifndef CAN_ISOTP_MSG_QUEUE_SIZE #define CAN_ISOTP_MSG_QUEUE_SIZE 64 #endif @@ -792,7 +780,8 @@ int isotp_send(struct isotp *isotp, const void *buf, int len, int flags) return len; } -int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg) +int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg, + struct isotp_fc_options *fc_options) { int ret; @@ -816,13 +805,13 @@ int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg) memset(&isotp->rx, 0, sizeof(struct tpcon)); memset(&isotp->tx, 0, sizeof(struct tpcon)); - isotp->rxfc.bs = CAN_ISOTP_BS; - isotp->rxfc.stmin = CAN_ISOTP_STMIN; + isotp->rxfc.bs = fc_options ? fc_options->bs : CAN_ISOTP_BS; + isotp->rxfc.stmin = fc_options ? fc_options->stmin : CAN_ISOTP_STMIN; isotp->rxfc.wftmax = 0; isotp->txfc.bs = 0; isotp->txfc.stmin = 0; - isotp->txfc.wftmax = CAN_ISOTP_WFTMAX; + isotp->txfc.wftmax = fc_options ? fc_options->wftmax : CAN_ISOTP_WFTMAX; isotp->entry.ifnum = entry->ifnum; #ifdef MODULE_CAN_MBOX diff --git a/sys/include/can/conn/isotp.h b/sys/include/can/conn/isotp.h index 24fbbba5c3..9a3071e0ac 100644 --- a/sys/include/can/conn/isotp.h +++ b/sys/include/can/conn/isotp.h @@ -112,10 +112,10 @@ static inline void conn_can_isotp_init_slave(conn_can_isotp_t *master, conn_can_ * @brief ISOTP connection */ typedef struct conn_can_isotp { - struct isotp isotp; /**< ISO-TP connection */ - int ifnum; /**< interface number */ - int bound; /**< 1 if connection is bound */ - mbox_t mbox; /**< mbox */ + struct isotp isotp; /**< ISO-TP connection */ + int ifnum; /**< interface number */ + int bound; /**< 1 if connection is bound */ + mbox_t mbox; /**< mbox */ /** message queue */ msg_t mbox_queue[CONN_CAN_ISOTP_MBOX_SIZE]; } conn_can_isotp_t; @@ -137,11 +137,12 @@ int conn_can_isotp_create(conn_can_isotp_t *conn, struct isotp_options *options, * @brief Bind a can isotp connection * * @param[inout] conn ISO-TP connection + * @param[in] fc_options ISO-TP flow control options, can be NULL for default parameters * * @return 0 on success * @return any other negative number in case of an error */ -int conn_can_isotp_bind(conn_can_isotp_t *conn); +int conn_can_isotp_bind(conn_can_isotp_t *conn, struct isotp_fc_options *fc_options); /** * @brief Close can isotp connection socket diff --git a/sys/include/can/isotp.h b/sys/include/can/isotp.h index a02edfc241..4228604b02 100644 --- a/sys/include/can/isotp.h +++ b/sys/include/can/isotp.h @@ -31,6 +31,26 @@ extern "C" { #include "xtimer.h" #include "net/gnrc/pktbuf.h" +#ifndef CAN_ISOTP_BS +/** + * @brief Default Block Size for RX Flow Control frames + */ +#define CAN_ISOTP_BS (10) +#endif + +#ifndef CAN_ISOTP_STMIN +/** + * @brief Default STmin for RX Flow Control frames + */ +#define CAN_ISOTP_STMIN (5) +#endif + +#ifndef CAN_ISOTP_WFTMAX +/** + * @brief Default maximum WFT for TX Flow Control + */ +#define CAN_ISOTP_WFTMAX (1) +#endif /** * @brief The isotp_fc_options struct @@ -160,11 +180,14 @@ int isotp_send(struct isotp *isotp, const void *buf, int len, int flags); * @param isotp the channel to bind * @param entry entry identifying the CAN ifnum and the upper layer * either by its pid or its mailbox + * @param fc_options flow control parameters, bs and stmin for rx, wftmax for tx, + * if NULL, default values will be used * @param arg upper layer private parameter * * @return 0 on success, < 0 on error */ -int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg); +int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg, + struct isotp_fc_options *fc_options); /** * @brief Release a bound isotp channel diff --git a/tests/conn_can/main.c b/tests/conn_can/main.c index 0bce87e1bc..cfe6501357 100644 --- a/tests/conn_can/main.c +++ b/tests/conn_can/main.c @@ -227,7 +227,7 @@ static int _bind_isotp(int argc, char **argv) #endif ret = conn_can_isotp_create(&conn_isotp[thread_nb], &isotp_opt, ifnum); if (ret == 0) { - ret = conn_can_isotp_bind(&conn_isotp[thread_nb]); + ret = conn_can_isotp_bind(&conn_isotp[thread_nb], NULL); } if (ret < 0) { puts("Error when binding connection");