can/isotp: allow changing FC options at runtime
This commit is contained in:
parent
32b00706e3
commit
af66fe101d
@ -91,7 +91,7 @@ int conn_can_isotp_create(conn_can_isotp_t *conn, struct isotp_options *options,
|
|||||||
return 0;
|
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 != NULL);
|
||||||
assert(conn->isotp.opt.tx_id != 0 || conn->isotp.opt.rx_id != 0);
|
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);
|
put_msg(conn, &msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = isotp_bind(&conn->isotp, &entry, conn);
|
ret = isotp_bind(&conn->isotp, &entry, conn, fc_options);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
conn->bound = 1;
|
conn->bound = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,18 +33,6 @@
|
|||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#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
|
#ifndef CAN_ISOTP_MSG_QUEUE_SIZE
|
||||||
#define CAN_ISOTP_MSG_QUEUE_SIZE 64
|
#define CAN_ISOTP_MSG_QUEUE_SIZE 64
|
||||||
#endif
|
#endif
|
||||||
@ -792,7 +780,8 @@ int isotp_send(struct isotp *isotp, const void *buf, int len, int flags)
|
|||||||
return len;
|
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;
|
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->rx, 0, sizeof(struct tpcon));
|
||||||
memset(&isotp->tx, 0, sizeof(struct tpcon));
|
memset(&isotp->tx, 0, sizeof(struct tpcon));
|
||||||
|
|
||||||
isotp->rxfc.bs = CAN_ISOTP_BS;
|
isotp->rxfc.bs = fc_options ? fc_options->bs : CAN_ISOTP_BS;
|
||||||
isotp->rxfc.stmin = CAN_ISOTP_STMIN;
|
isotp->rxfc.stmin = fc_options ? fc_options->stmin : CAN_ISOTP_STMIN;
|
||||||
isotp->rxfc.wftmax = 0;
|
isotp->rxfc.wftmax = 0;
|
||||||
|
|
||||||
isotp->txfc.bs = 0;
|
isotp->txfc.bs = 0;
|
||||||
isotp->txfc.stmin = 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;
|
isotp->entry.ifnum = entry->ifnum;
|
||||||
#ifdef MODULE_CAN_MBOX
|
#ifdef MODULE_CAN_MBOX
|
||||||
|
|||||||
@ -112,10 +112,10 @@ static inline void conn_can_isotp_init_slave(conn_can_isotp_t *master, conn_can_
|
|||||||
* @brief ISOTP connection
|
* @brief ISOTP connection
|
||||||
*/
|
*/
|
||||||
typedef struct conn_can_isotp {
|
typedef struct conn_can_isotp {
|
||||||
struct isotp isotp; /**< ISO-TP connection */
|
struct isotp isotp; /**< ISO-TP connection */
|
||||||
int ifnum; /**< interface number */
|
int ifnum; /**< interface number */
|
||||||
int bound; /**< 1 if connection is bound */
|
int bound; /**< 1 if connection is bound */
|
||||||
mbox_t mbox; /**< mbox */
|
mbox_t mbox; /**< mbox */
|
||||||
/** message queue */
|
/** message queue */
|
||||||
msg_t mbox_queue[CONN_CAN_ISOTP_MBOX_SIZE];
|
msg_t mbox_queue[CONN_CAN_ISOTP_MBOX_SIZE];
|
||||||
} conn_can_isotp_t;
|
} 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
|
* @brief Bind a can isotp connection
|
||||||
*
|
*
|
||||||
* @param[inout] conn ISO-TP 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 0 on success
|
||||||
* @return any other negative number in case of an error
|
* @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
|
* @brief Close can isotp connection socket
|
||||||
|
|||||||
@ -31,6 +31,26 @@ extern "C" {
|
|||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#include "net/gnrc/pktbuf.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
|
* @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 isotp the channel to bind
|
||||||
* @param entry entry identifying the CAN ifnum and the upper layer
|
* @param entry entry identifying the CAN ifnum and the upper layer
|
||||||
* either by its pid or its mailbox
|
* 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
|
* @param arg upper layer private parameter
|
||||||
*
|
*
|
||||||
* @return 0 on success, < 0 on error
|
* @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
|
* @brief Release a bound isotp channel
|
||||||
|
|||||||
@ -227,7 +227,7 @@ static int _bind_isotp(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
ret = conn_can_isotp_create(&conn_isotp[thread_nb], &isotp_opt, ifnum);
|
ret = conn_can_isotp_create(&conn_isotp[thread_nb], &isotp_opt, ifnum);
|
||||||
if (ret == 0) {
|
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) {
|
if (ret < 0) {
|
||||||
puts("Error when binding connection");
|
puts("Error when binding connection");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user