Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
uavcan.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Freek van Tienen <freek.v.tienen@gmail.com>
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 */
26#ifndef MODULES_UAVCAN_ARCH_H
27#define MODULES_UAVCAN_ARCH_H
28
29#include <canard.h>
30#include <string.h>
31#include "mcu_periph/can.h"
34#include "utils/kv_store.h"
35
36
37#ifndef UAVCAN_TX_FIFO_SIZE
38#define UAVCAN_TX_FIFO_SIZE 1024
39#endif
40
41#define UAVCAN_TID_STORE_CAPACITY 30
42
45#ifndef UAVCAN_RX_QUEUE_SIZE
46#define UAVCAN_RX_QUEUE_SIZE 64
47#endif
48
50 CanardCANFrame frame;
52};
53
55#define UAVCAN_RX_BUFFER_SIZE (UAVCAN_RX_QUEUE_SIZE * (sizeof(struct uavcan_rx_frame) + 2) + 3)
56
87
89typedef void (*uavcan_callback)(struct uavcan_iface_t *iface, CanardRxTransfer *transfer);
90
99
101#if UAVCAN_USE_CAN1
102extern struct uavcan_iface_t uavcan1;
103#endif
104#if UAVCAN_USE_CAN2
105extern struct uavcan_iface_t uavcan2;
106#endif
107
109void uavcan_init(void);
110void uavcan_rx_event(void);
111void uavcan_reporting(void);
112void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_event *ev, uavcan_callback cb);
113void uavcan_transfer(struct uavcan_iface_t *iface, CanardTxTransfer* transfer);
114void uavcan_request(struct uavcan_iface_t *iface, uint8_t destination_node_id, CanardTxTransfer* transfer);
115void uavcan_broadcast(struct uavcan_iface_t *iface, uint64_t data_type_signature, uint16_t data_type_id,
116 uint8_t priority, const void *payload, uint16_t payload_len);
117void uavcan_response(struct uavcan_iface_t *iface, uint8_t destination_node_id, CanardTxTransfer* transfer);
118
119#endif /* MODULES_UAVCAN_ARCH_H */
thread_t * pprz_thread_t
This is a general purpose circular buffer for storing variable lenght buffers in a FIFO order.
abi_event ev
Definition rssi.c:45
struct pprzBSem pprz_bsem_t
Definition threads.h:22
struct pprzMutex pprz_mutex_t
Definition threads.h:21
uint32_t timestamp
Reception time (us).
Definition uavcan.h:51
pprz_mutex_t tx_mutex
Definition uavcan.h:62
pprz_mutex_t rx_mutex
Definition uavcan.h:61
uint8_t transfer_ids_values[UAVCAN_TID_STORE_CAPACITY]
Definition uavcan.h:77
void(* uavcan_callback)(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
Generic uavcan callback definition.
Definition uavcan.h:89
#define UAVCAN_RX_BUFFER_SIZE
A frame is a record of the framed ring buffer: 2 bytes length, and 3 bytes margin for the buffer.
Definition uavcan.h:55
uint32_t can_baudrate
Definition uavcan.h:59
void uavcan_init(void)
uavcan interfaces
Definition uavcan.c:257
bool initialized
Definition uavcan.h:85
uint8_t rx_queue_buf[UAVCAN_RX_BUFFER_SIZE]
Definition uavcan.h:82
void uavcan_transfer(struct uavcan_iface_t *iface, CanardTxTransfer *transfer)
Definition uavcan.c:300
uint32_t transfer_ids_keys[UAVCAN_TID_STORE_CAPACITY]
Definition uavcan.h:76
uint16_t rx_overflows
Frames dropped because the queue was full.
Definition uavcan.h:83
struct framed_ring_buffer rx_queue
Received frames, from the CAN receive thread to the main thread.
Definition uavcan.h:81
struct pprzaddr_can can_net
Definition uavcan.h:58
uint16_t data_type_id
Definition uavcan.h:93
pprz_bsem_t bsem
Definition uavcan.h:65
void uavcan_request(struct uavcan_iface_t *iface, uint8_t destination_node_id, CanardTxTransfer *transfer)
Definition uavcan.c:321
void uavcan_broadcast(struct uavcan_iface_t *iface, uint64_t data_type_signature, uint16_t data_type_id, uint8_t priority, const void *payload, uint16_t payload_len)
Legacy function Broadcast an uavcan message to a specific interface.
Definition uavcan.c:345
CanardCANFrame frame
Definition uavcan.h:50
kv_store_t transfer_ids_store
Definition uavcan.h:79
#define UAVCAN_TID_STORE_CAPACITY
Definition uavcan.h:41
uint8_t transfer_ids_used[UAVCAN_TID_STORE_CAPACITY]
Definition uavcan.h:78
void uavcan_reporting(void)
struct uavcan_event_t * next
Definition uavcan.h:96
void uavcan_rx_event(void)
Handle the received frames of all interfaces (main thread).
Definition uavcan.c:244
pprz_thread_t thread_tx
Definition uavcan.h:63
uint16_t nb_errors
Definition uavcan.h:73
void uavcan_response(struct uavcan_iface_t *iface, uint8_t destination_node_id, CanardTxTransfer *transfer)
Definition uavcan.c:364
uavcan_callback cb
Definition uavcan.h:95
uint8_t node_id
Definition uavcan.h:67
uint64_t data_type_signature
Definition uavcan.h:94
struct uavcan_event_t uavcan_event
Definition uavcan.h:98
void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_event *ev, uavcan_callback cb)
Bind to a receiving message from uavcan.
Definition uavcan.c:272
CanardInstance canard
Definition uavcan.h:68
uint8_t canard_memory_pool[1024 *2]
Definition uavcan.h:69
Main uavcan event structure for registering/calling callbacks.
Definition uavcan.h:92
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned long long uint64_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
int transfer(const Mat *from, const image_t *to)