-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- single public context for send and receive; no more unbinding to send a message - CAN-FD support - only supports ISO-TP fixed addressing at present - broadly async approach, but sync receive supported for familiarity/compatibility - conformance tests ported from existing implementation
- Loading branch information
1 parent
f46e0f0
commit 95d03fa
Showing
39 changed files
with
3,144 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
# folders generated by west | ||
build | ||
twister-out* | ||
|
||
# editors | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright (c) 2023 Brill Power | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifdef CONFIG_ISOTP_FAST | ||
#include <zephyr/canbus/isotp.h> | ||
|
||
#ifndef ISOTP_MSG_FDF | ||
#define ISOTP_MSG_FDF BIT(3) | ||
#endif | ||
|
||
/* Represents a sender or a receiver in an ISO-TP fixed addressing scheme */ | ||
typedef uint8_t isotp_fast_node_id; | ||
/* ISO-TP message ID, i.e. the CAN ID */ | ||
typedef uint32_t isotp_fast_msg_id; | ||
|
||
/** | ||
* Callback invoked when a message is received. | ||
* @param buffer Pointer to a @ref net_buf. Call @ref net_buf_frags_len to | ||
* obtain the length of the buffer, then @ref net_buf_linearize to copy the | ||
* contents of the buffer into a local buffer. | ||
* @param rem_len At present, this should always be zero. In future, this | ||
* callback may be called repeatedly as a message's packets arrive to reduce | ||
* the need to buffer an entire message in memory before it is dispatched | ||
* to user code. | ||
* @param sender_addr The CAN ID of the message that has been received. | ||
* @param arg The value of @ref recv_cb_arg passed to @ref isotp_fast_bind. | ||
*/ | ||
typedef void (*isotp_fast_recv_callback_t)(struct net_buf *buffer, int rem_len, | ||
isotp_fast_msg_id sender_addr, void *arg); | ||
|
||
/** | ||
* Callback invoked when an error occurs during message receiption. | ||
* @param error The error code. | ||
* @param sender_addr The CAN ID of the sender of the message, if available. | ||
* @param arg The value of @ref recv_cb_arg passed to @ref isotp_fast_bind. | ||
*/ | ||
typedef void (*isotp_fast_recv_error_callback_t)(int8_t error, isotp_fast_msg_id sender_addr, | ||
void *arg); | ||
|
||
/** | ||
* Callback invoked when a message has been sent. | ||
* @param result If non-zero, an error has occurred. | ||
* @param arg The value of @ref sent_cb_arg passed to @ref isotp_fast_send. | ||
*/ | ||
typedef void (*isotp_fast_send_callback_t)(int result, void *arg); | ||
|
||
/** | ||
* Options pertaining to the bound context. | ||
*/ | ||
struct isotp_fast_opts | ||
{ | ||
uint8_t bs; /**< Block size. Number of CF PDUs before next CF is sent */ | ||
uint8_t stmin; /**< Minimum separation time. Min time between frames */ | ||
uint8_t flags; | ||
}; | ||
|
||
/** | ||
* General context object. | ||
*/ | ||
struct isotp_fast_ctx | ||
{ | ||
/* The CAN device to which the context is bound via @ref isotp_fast_bind */ | ||
const struct device *can_dev; | ||
/* Identifies the CAN filter which filters incoming messages */ | ||
int filter_id; | ||
/* Pointer to context options described above */ | ||
const struct isotp_fast_opts *opts; | ||
/* Callback that is invoked when a message is received */ | ||
isotp_fast_recv_callback_t recv_callback; | ||
/* Pointer to user-supplied data to be passed to @ref recv_callback */ | ||
void *recv_cb_arg; | ||
/* Callback that is invoked when a receive error occurs */ | ||
isotp_fast_recv_error_callback_t recv_error_callback; | ||
/* Callback that is invoked when a message is sent */ | ||
isotp_fast_send_callback_t sent_callback; | ||
/* CAN ID of this node, used in both transmission and receipt of messages */ | ||
isotp_fast_msg_id my_addr; | ||
#ifdef CONFIG_ISOTP_FAST_BLOCKING_RECEIVE | ||
sys_slist_t wait_recv_list; | ||
#endif | ||
}; | ||
|
||
/** | ||
* Binds the supplied ISO-TP context to the supplied CAN device. Messages | ||
* addressed to the given address (@ref my_addr) will be delivered to user | ||
* code by invoking the supplied callback, @ref recv_callback. | ||
* | ||
* @param ctx A pointer to the general ISO-TP context | ||
* @param can_dev The CAN device to which the context should be bound | ||
* @param my_addr The address to listen on for incoming messages or to use | ||
* when transmitting messages | ||
* @param opts A pointer to an options structure, @ref isotp_fast_opts | ||
* @param recv_callback A callback that is invoked when a message is received | ||
* @param recv_cb_arg A pointer to data to be supplied to @ref recv_callback | ||
* @param recv_error_callback A callback that is invoked when an error occurs. | ||
* @param sent_callback A callback that is invoked when a message is sent | ||
* | ||
* @returns 0 on success, otherwise an error code < 0. | ||
*/ | ||
int isotp_fast_bind(struct isotp_fast_ctx *ctx, const struct device *can_dev, | ||
const isotp_fast_msg_id my_addr, const struct isotp_fast_opts *opts, | ||
isotp_fast_recv_callback_t recv_callback, void *recv_cb_arg, | ||
isotp_fast_recv_error_callback_t recv_error_callback, | ||
isotp_fast_send_callback_t sent_callback); | ||
|
||
/** | ||
* Unbinds the supplied ISO-TP context. Removes the CAN filter if it was | ||
* successfully set. | ||
* | ||
* @param ctx A pointer to the context to unbind | ||
* | ||
* @returns 0 on success. | ||
*/ | ||
int isotp_fast_unbind(struct isotp_fast_ctx *ctx); | ||
|
||
#ifdef CONFIG_ISOTP_FAST_BLOCKING_RECEIVE | ||
int isotp_fast_recv(struct isotp_fast_ctx *ctx, struct can_filter sender, uint8_t *buf, size_t size, | ||
k_timeout_t timeout); | ||
#endif | ||
|
||
/** | ||
* Send a message to a given recipient. If the message fits within a | ||
* CAN frame, it will be sent synchronously. If not, it will be sent | ||
* asynchronously. | ||
* | ||
* @param ctx The bound context on which the message should be sent | ||
* @param data A pointer to the data containing the message to send | ||
* @param len The length of the data in @ref data | ||
* @param their_id The node ID identifying the recipient. This will be | ||
* combined with the sending address @ref my_addr on @ref ctx to form | ||
* the CAN ID on the message. | ||
* @param sent_cb_arg A pointer to data to be supplied to the callback | ||
* that will be invoked when the message is sent. | ||
* | ||
* @returns 0 on success. | ||
*/ | ||
int isotp_fast_send(struct isotp_fast_ctx *ctx, const uint8_t *data, size_t len, | ||
const isotp_fast_node_id their_id, void *sent_cb_arg); | ||
#endif /* CONFIG_ISOTP_FAST */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
menuconfig ISOTP_FAST | ||
bool "New ISO-TP context" | ||
depends on CAN | ||
depends on ISOTP | ||
select EVENTS | ||
|
||
if ISOTP_FAST | ||
|
||
config ISOTP_FAST_RX_MAX_PACKET_COUNT | ||
int "Max packets for ISO-TP reception" | ||
default 8 | ||
help | ||
Max number of packets expected in a single ISO-TP message. | ||
|
||
config ISOTP_FAST_RX_BUF_COUNT | ||
int "Max number of RX buffers" | ||
default 4 | ||
help | ||
This broadly implies the max number of simultaneous receptions. | ||
|
||
config ISOTP_FAST_TX_BUF_COUNT | ||
int "Max number of TX buffers" | ||
default 4 | ||
help | ||
This broadly implies the max number of simultaneous transmissions. | ||
|
||
config ISOTP_FAST_PER_FRAME_DISPATCH | ||
bool "Per-frame dispatch" | ||
default false | ||
help | ||
Whether to invoke the receive callback on receipt of every frame | ||
|
||
config ISOTP_FAST_BLOCKING_RECEIVE | ||
bool "Blocking receive" | ||
default false | ||
depends on !ISOTP_FAST_PER_FRAME_DISPATCH | ||
help | ||
Whether to make blocking receive functionality available | ||
to ease migration from the old API. | ||
|
||
endif |
Oops, something went wrong.