Loading...
Searching...
No Matches
can.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 OTA keys S.A.
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
26#ifndef CAN_CAN_H
27#define CAN_CAN_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <stdint.h>
34
35#if defined(__linux__)
36
37#include <linux/can.h>
38#include <libsocketcan.h>
39
40#else
41
45#define CAN_MAX_DLEN (8)
46
51/* special address description flags for the CAN_ID */
52#define CAN_EFF_FLAG (0x80000000U)
53#define CAN_RTR_FLAG (0x40000000U)
54#define CAN_ERR_FLAG (0x20000000U)
56/* valid bits in CAN ID for frame formats */
57#define CAN_SFF_MASK (0x000007FFU)
58#define CAN_EFF_MASK (0x1FFFFFFFU)
59#define CAN_ERR_MASK (0x1FFFFFFFU)
74
83typedef uint32_t canid_t;
84
88struct can_frame {
90 uint8_t can_dlc;
91 uint8_t __pad;
92 uint8_t __res0;
93 uint8_t __res1;
95 uint8_t data[CAN_MAX_DLEN] __attribute__((aligned(8)));
96};
97
104#if (MODULE_CAN_RX_MAILBOX)
105 uint8_t target_mailbox;
106#endif
107};
108
117 uint32_t bitrate;
118 uint32_t sample_point;
119 uint32_t tq;
120 uint32_t prop_seg;
121 uint32_t phase_seg1;
122 uint32_t phase_seg2;
123 uint32_t sjw;
124 uint32_t brp;
125};
126
133 uint32_t tseg1_min;
134 uint32_t tseg1_max;
135 uint32_t tseg2_min;
136 uint32_t tseg2_max;
137 uint32_t sjw_max;
138 uint32_t brp_min;
139 uint32_t brp_max;
140 uint32_t brp_inc;
141};
142
143#endif /* defined(__linux__) */
144
145#ifdef __cplusplus
146}
147#endif
148
149#endif /* CAN_CAN_H */
150
can_state
CAN operational and error states.
Definition can.h:65
uint32_t canid_t
Controller Area Network Identifier structure.
Definition can.h:83
#define CAN_MAX_DLEN
Max data length for a CAN frame.
Definition can.h:45
@ CAN_STATE_ERROR_ACTIVE
RX/TX error count < 96.
Definition can.h:66
@ CAN_STATE_ERROR_WARNING
RX/TX error count < 128.
Definition can.h:67
@ CAN_STATE_SLEEPING
Device is sleeping.
Definition can.h:71
@ CAN_STATE_STOPPED
Device is stopped.
Definition can.h:70
@ CAN_STATE_BUS_OFF
RX/TX error count >= 256.
Definition can.h:69
@ CAN_STATE_ERROR_PASSIVE
RX/TX error count < 256.
Definition can.h:68
CAN hardware-dependent bit-timing constant.
Definition can.h:132
uint32_t brp_min
Bit-rate prescaler, min value.
Definition can.h:138
uint32_t tseg1_min
Time segment 1 = prop_seg + phase_seg1, min value.
Definition can.h:133
uint32_t brp_max
Bit-rate prescaler, max value.
Definition can.h:139
uint32_t tseg1_max
Time segment 1, max value.
Definition can.h:134
uint32_t tseg2_min
Time segment 2 = phase_seg2, min value.
Definition can.h:135
uint32_t brp_inc
Bit-rate prescaler, increment.
Definition can.h:140
uint32_t tseg2_max
Time segment 2, max value.
Definition can.h:136
uint32_t sjw_max
Synchronisation jump width.
Definition can.h:137
CAN bit-timing parameters.
Definition can.h:116
uint32_t tq
Time quanta (TQ) in nanoseconds.
Definition can.h:119
uint32_t sample_point
Sample point in one-tenth of a percent.
Definition can.h:118
uint32_t phase_seg1
Phase buffer segment 1 in TQs.
Definition can.h:121
uint32_t bitrate
Bit-rate in bits/second.
Definition can.h:117
uint32_t brp
Bit-rate prescaler.
Definition can.h:124
uint32_t phase_seg2
Phase buffer segment 2 in TQs.
Definition can.h:122
uint32_t sjw
Synchronisation jump width in TQs.
Definition can.h:123
uint32_t prop_seg
Propagation segment in TQs.
Definition can.h:120
Controller Area Network filter.
Definition can.h:101
canid_t can_mask
Mask.
Definition can.h:103
canid_t can_id
CAN ID.
Definition can.h:102
Controller Area Network frame.
Definition can.h:88
uint8_t __pad
padding
Definition can.h:91
uint8_t __res1
reserved / padding
Definition can.h:93
uint8_t can_dlc
frame payload length in byte (0 .
Definition can.h:90
uint8_t __res0
reserved / padding
Definition can.h:92
uint8_t data[CAN_MAX_DLEN]
Frame data.
Definition can.h:95
canid_t can_id
32 bit CAN_ID + EFF/RTR/ERR flags
Definition can.h:89