forked from arduino/portentax8-x8h7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx8h7_can.h
120 lines (100 loc) · 3.05 KB
/
x8h7_can.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* X8H7 CAN driver
*/
#ifndef __X8H7_CAN_H
#define __X8H7_CAN_H
/**
* INCLUDES
*/
#include <linux/timer.h>
#include <linux/can/dev.h>
#include <linux/workqueue.h>
/**
* DEFINES
*/
#define X8H7_CAN1_PERIPH 0x03
#define X8H7_CAN2_PERIPH 0x04
#define X8H7_CAN_OC_INIT 0x10
#define X8H7_CAN_OC_DEINIT 0x11
#define X8H7_CAN_OC_BITTIM 0x12
#define X8H7_CAN_OC_SEND 0x01
#define X8H7_CAN_OC_RECV 0x01
#define X8H7_CAN_OC_STS 0x40
#define X8H7_CAN_OC_FLT 0x50
#define X8H7_CAN_STS_INT_TX_COMPLETE 0x01
#define X8H7_CAN_STS_INT_RX 0x02
#define X8H7_CAN_STS_INT_ERR 0x04
#define X8H7_CAN_STS_INT_TX_ABORT_COMPLETE 0x08
#define X8H7_CAN_STS_INT_TX_FIFO_EMPTY 0x10
#define X8H7_CAN_STS_FLG_RX_OVR 0x01 // Receive Buffer Overflow
#define X8H7_CAN_STS_FLG_TX_BO 0x02 // Bus-Off
#define X8H7_CAN_STS_FLG_TX_EP 0x04 // Transmit Error-Passive
#define X8H7_CAN_STS_FLG_RX_EP 0x08 // Receive Error-Passive
#define X8H7_CAN_STS_FLG_TX_WAR 0x10 // Transmit Error Warning
#define X8H7_CAN_STS_FLG_RX_WAR 0x20 // Receive Error Warning
#define X8H7_CAN_STS_FLG_EWARN 0x40 // Error Warning
#define X8H7_CAN_STS_FLG_TX_OVR 0x80 // Transmit Buffer Overflow
#define X8H7_CAN_HEADER_SIZE 5
#define X8H7_CAN_FRAME_MAX_DATA_LEN 8
#define X8H7_STD_FLT_MAX 128
#define X8H7_EXT_FLT_MAX 64
#define X8H7_TX_FIFO_SIZE 32
/**
* TYPEDEFS
*/
union x8h7_can_init_message
{
struct __attribute__((packed))
{
uint32_t baud_rate_prescaler;
uint32_t time_segment_1;
uint32_t time_segment_2;
uint32_t sync_jump_width;
} field;
uint8_t buf[sizeof(uint32_t) /* can_bitrate_Hz */ + sizeof(uint32_t) /* time_segment_1 */ + sizeof(uint32_t) /* time_segment_2 */ + sizeof(uint32_t) /* sync_jump_width */];
};
union x8h7_can_bittiming_message
{
struct __attribute__((packed))
{
uint32_t baud_rate_prescaler;
uint32_t time_segment_1;
uint32_t time_segment_2;
uint32_t sync_jump_width;
} field;
uint8_t buf[sizeof(uint32_t) /* can_bitrate_Hz */ + sizeof(uint32_t) /* time_segment_1 */ + sizeof(uint32_t) /* time_segment_2 */ + sizeof(uint32_t) /* sync_jump_width */];
};
union x8h7_can_filter_message
{
struct __attribute__((packed))
{
uint32_t idx;
uint32_t id;
uint32_t mask;
} field;
uint8_t buf[sizeof(uint32_t) /* idx */ + sizeof(uint32_t) /* id */ + sizeof(uint32_t) /* mask */];
};
union x8h7_can_frame_message
{
struct __attribute__((packed))
{
uint32_t id;
uint8_t len;
uint8_t data[X8H7_CAN_FRAME_MAX_DATA_LEN];
} field;
uint8_t buf[X8H7_CAN_HEADER_SIZE + X8H7_CAN_FRAME_MAX_DATA_LEN];
};
struct x8h7_can_priv {
struct can_priv can;
struct net_device *net;
struct device *dev;
int periph;
int tx_len;
struct workqueue_struct *wq;
struct work_struct work;
union x8h7_can_frame_message tx_frame;
struct can_filter std_flt[X8H7_STD_FLT_MAX];
struct can_filter ext_flt[X8H7_EXT_FLT_MAX];
struct mutex lock;
};
#endif