1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

can/isotp: allow changing FC options at runtime

This commit is contained in:
Vincent Dupont 2019-08-06 16:20:05 +02:00
parent 32b00706e3
commit af66fe101d
5 changed files with 38 additions and 25 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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");