Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
can.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
23#ifndef CAN_H
24#define CAN_H
25
26#include "std.h"
27#include "mcu_periph/can_arch.h"
28
29#ifndef CAN_FD_MODE
30#define CAN_FD_MODE TRUE
31#endif
32
33#ifdef CAN_FD_MODE
34#define SOCKETCAN_MAX_DLEN 64U
35#else
36#define SOCKETCAN_MAX_DLEN 8U
37#endif
38
39#ifndef CAN_NB_CALLBACKS_MAX
40#define CAN_NB_CALLBACKS_MAX 10
41#endif
42
43// CAN identifier
44// +------+--------------------------------------------------------------+
45// | Bits | Description |
46// +======+==============================================================+
47// | 0-28 | CAN identifier (11/29 bit) |
48// +------+--------------------------------------------------------------+
49// | 29 | Error message frame flag (0 = data frame, 1 = error message) |
50// +------+--------------------------------------------------------------+
51// | 30 | Remote transmission request flag (1 = RTR frame) |
52// +------+--------------------------------------------------------------+
53// | 31 | Frame format flag (0 = standard 11 bit, 1 = extended 29 bit) |
54// +------+--------------------------------------------------------------+
56
57// error flag
58#define CAN_FRAME_ERR (1<<29)
59// remote transmition request
60#define CAN_FRAME_RTR (1<<30)
61// extended identifier
62#define CAN_FRAME_EFF (1<<31)
63
64#define CAN_EID_MASK 0x1FFFFFFF
65#define CAN_SID_MASK 0x7FF
66
67// /* CAN FD specific flags from Linux Kernel (include/uapi/linux/can.h) */
68#define CANFD_BRS 0x01
69#define CANFD_ESI 0x02
70#define CANFD_FDF 0x04
71
79
80// socketaddr_can paparazzi abstraction
82 //sa_family_t can_family;
83 int can_ifindex; // network interface index
84};
85
86typedef void(* can_rx_frame_callback_t)(struct pprzcan_frame* rxframe, struct pprzaddr_can* src_addr, void* user_data);
87
88
95
96#if USE_CAN1
97extern struct can_periph can1;
98#endif
99#if USE_CAN2
100extern struct can_periph can2;
101#endif
102
103void can_init(void);
104
112int can_register_callback(can_rx_frame_callback_t callback, struct pprzaddr_can* src_addr, void* user_data);
113
115
116
119#endif /* CAN_H */
uint32_t timestamp
Definition can.h:76
uint8_t len
Definition can.h:74
int can_ifindex
Definition can.h:83
uint8_t can_dlc_to_len(uint8_t dlc)
Definition can.c:39
void(* can_rx_frame_callback_t)(struct pprzcan_frame *rxframe, struct pprzaddr_can *src_addr, void *user_data)
Definition can.h:86
uint8_t data[SOCKETCAN_MAX_DLEN]
Definition can.h:77
uint32_t socketcan_id_t
Definition can.h:55
#define SOCKETCAN_MAX_DLEN
Definition can.h:34
can_rx_frame_callback_t callbacks[CAN_NB_CALLBACKS_MAX]
Definition can.h:92
#define CAN_NB_CALLBACKS_MAX
Definition can.h:40
int can_register_callback(can_rx_frame_callback_t callback, struct pprzaddr_can *src_addr, void *user_data)
Add a callback on received frames from an interface.
Definition can.c:78
void * arch_struct
Definition can.h:90
uint8_t flags
Definition can.h:75
socketcan_id_t can_id
Definition can.h:73
uint8_t can_len_to_dlc(uint8_t len)
Definition can.c:46
int fd
Definition can.h:91
void can_init(void)
Definition uavcan.c:94
int can_transmit_frame(struct pprzcan_frame *txframe, struct pprzaddr_can *dst_addr)
Definition can_arch.c:137
void * callback_user_data[CAN_NB_CALLBACKS_MAX]
Definition can.h:93
uint16_t foo
Definition main_demo5.c:58
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.