Skip to content

Commit e121ea2

Browse files
wysmancarlescufi
authored andcommitted
canbus: isotp: Allow to override ISOTP_FIXED_ADDR_* constants
This patch allow to use isotp use_fixed_addr feature with CAN identifier which not match SAE J1939 format. Signed-off-by: William MARTIN <[email protected]>
1 parent 47f14d6 commit e121ea2

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

include/zephyr/canbus/isotp.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,25 @@
104104
*/
105105

106106
/** Position of fixed source address (SA) */
107-
#define ISOTP_FIXED_ADDR_SA_POS (0U)
107+
#define ISOTP_FIXED_ADDR_SA_POS (CONFIG_ISOTP_FIXED_ADDR_SA_POS)
108108

109109
/** Mask to obtain fixed source address (SA) */
110-
#define ISOTP_FIXED_ADDR_SA_MASK (0xFF << ISOTP_FIXED_ADDR_SA_POS)
110+
#define ISOTP_FIXED_ADDR_SA_MASK (CONFIG_ISOTP_FIXED_ADDR_SA_MASK)
111111

112112
/** Position of fixed target address (TA) */
113-
#define ISOTP_FIXED_ADDR_TA_POS (8U)
113+
#define ISOTP_FIXED_ADDR_TA_POS (CONFIG_ISOTP_FIXED_ADDR_TA_POS)
114114

115115
/** Mask to obtain fixed target address (TA) */
116-
#define ISOTP_FIXED_ADDR_TA_MASK (0xFF << ISOTP_FIXED_ADDR_TA_POS)
116+
#define ISOTP_FIXED_ADDR_TA_MASK (CONFIG_ISOTP_FIXED_ADDR_TA_MASK)
117117

118118
/** Position of priority in fixed addressing mode */
119-
#define ISOTP_FIXED_ADDR_PRIO_POS (26U)
119+
#define ISOTP_FIXED_ADDR_PRIO_POS (CONFIG_ISOTP_FIXED_ADDR_PRIO_POS)
120120

121121
/** Mask for priority in fixed addressing mode */
122-
#define ISOTP_FIXED_ADDR_PRIO_MASK (0x7 << ISOTP_FIXED_ADDR_PRIO_POS)
122+
#define ISOTP_FIXED_ADDR_PRIO_MASK (CONFIG_ISOTP_FIXED_ADDR_PRIO_MASK)
123123

124124
/* CAN filter RX mask to match any priority and source address (SA) */
125-
#define ISOTP_FIXED_ADDR_RX_MASK (0x03FFFF00)
125+
#define ISOTP_FIXED_ADDR_RX_MASK (CONFIG_ISOTP_FIXED_ADDR_RX_MASK)
126126

127127
#ifdef __cplusplus
128128
extern "C" {

subsys/canbus/isotp/Kconfig

+54
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,58 @@ config ISOTP_TX_CONTEXT_BUF_COUNT
129129
This defines the size of the memory slab where the buffers are
130130
allocated from.
131131

132+
config ISOTP_CUSTOM_FIXED_ADDR
133+
bool "Use fixed address not compatible with SAE J1939"
134+
default n
135+
help
136+
This option allow to use an alternative CAN frame id format.
137+
If not set ISO-TP fixed addressing use SAE J1939 standard.
138+
139+
menu "Fixed address definition"
140+
visible if ISOTP_CUSTOM_FIXED_ADDR
141+
142+
config ISOTP_FIXED_ADDR_SA_POS
143+
int "Position of fixed source address (SA)"
144+
default 0
145+
help
146+
Source address position in bits.
147+
148+
config ISOTP_FIXED_ADDR_SA_MASK
149+
hex "Mask to obtain fixed source address (SA)"
150+
default 0xFF
151+
help
152+
Source address mask.
153+
154+
config ISOTP_FIXED_ADDR_TA_POS
155+
int "Position of fixed target address (TA)"
156+
default 8
157+
help
158+
Target address position in bits.
159+
160+
config ISOTP_FIXED_ADDR_TA_MASK
161+
hex "Mask to obtain fixed target address (TA)"
162+
default 0xFF00
163+
help
164+
Target address mask.
165+
166+
config ISOTP_FIXED_ADDR_PRIO_POS
167+
int "Position of priority in fixed addressing mode"
168+
default 26
169+
help
170+
Priority address position in bits.
171+
172+
config ISOTP_FIXED_ADDR_PRIO_MASK
173+
hex "Mask for priority in fixed addressing mode"
174+
default 0x1C000000
175+
help
176+
Priority address mask.
177+
178+
config ISOTP_FIXED_ADDR_RX_MASK
179+
hex "CAN filter RX mask to match any priority and source address (SA)"
180+
default 0x03FFFF00
181+
help
182+
CAN filter RX mask
183+
184+
endmenu
185+
132186
endif # ISOTP

subsys/canbus/isotp/isotp.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,10 @@ static void process_ff_sf(struct isotp_recv_ctx *ctx, struct can_frame *frame)
395395
ctx->tx_addr.ext_id &= ~(ISOTP_FIXED_ADDR_TA_MASK);
396396
ctx->tx_addr.ext_id |= rx_sa << ISOTP_FIXED_ADDR_TA_POS;
397397
/* use same priority for TX as in received message */
398-
ctx->tx_addr.ext_id &= ~(ISOTP_FIXED_ADDR_PRIO_MASK);
399-
ctx->tx_addr.ext_id |= frame->id & ISOTP_FIXED_ADDR_PRIO_MASK;
398+
if (ISOTP_FIXED_ADDR_PRIO_MASK) {
399+
ctx->tx_addr.ext_id &= ~(ISOTP_FIXED_ADDR_PRIO_MASK);
400+
ctx->tx_addr.ext_id |= frame->id & ISOTP_FIXED_ADDR_PRIO_MASK;
401+
}
400402
}
401403

402404
switch (frame->data[index] & ISOTP_PCI_TYPE_MASK) {

0 commit comments

Comments
 (0)