pkt.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2018 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 
20 #ifndef CAN_PKT_H
21 #define CAN_PKT_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <stdatomic.h>
28 
29 #include "can/common.h"
30 #include "can/can.h"
31 #include "msg.h"
32 #ifdef MODULE_CAN_MBOX
33 #include "mbox.h"
34 #endif
35 
41 typedef struct {
44  int handle;
45  struct can_frame frame;
46 } can_pkt_t;
47 
53 void can_pkt_init(void);
54 
67 can_pkt_t *can_pkt_alloc_tx(int ifnum, const struct can_frame *frame, kernel_pid_t tx_pid);
68 
77 can_pkt_t *can_pkt_alloc_rx(int ifnum, const struct can_frame *frame);
78 
79 #if defined(MODULE_CAN_MBOX) || defined(DOXYGEN)
80 
92 can_pkt_t *can_pkt_alloc_mbox_tx(int ifnum, const struct can_frame *frame, mbox_t *mbox);
93 #endif
94 
101 void can_pkt_free(can_pkt_t *pkt);
102 
114 can_rx_data_t *can_pkt_alloc_rx_data(void *data, size_t len, void *arg);
115 
122 
132 void *can_pkt_buf_alloc(size_t size);
133 
140 void can_pkt_buf_free(void *data, size_t size);
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif /* CAN_PKT_H */
147 
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
can_pkt_t::entry
can_reg_entry_t entry
entry containing ifnum and upper layer info
Definition: pkt.h:42
can_rx_data
Received data structure.
Definition: common.h:122
can.h
Definitions high-level CAN interface.
msg.h
Messaging API for inter process communication.
common.h
Definitions of high-level CAN interface.
can_pkt_free_rx_data
void can_pkt_free_rx_data(can_rx_data_t *data)
Free rx data previously allocated by can_pkt_alloc_rx_data()
can_pkt_t::ref_count
atomic_uint ref_count
Reference counter (for rx frames)
Definition: pkt.h:43
mbox_t
Mailbox struct definition.
Definition: mbox.h:41
mbox.h
Mailbox API.
can_frame
Controller Area Network frame.
Definition: can.h:88
can_pkt_free
void can_pkt_free(can_pkt_t *pkt)
Free a CAN packet.
can_pkt_alloc_tx
can_pkt_t * can_pkt_alloc_tx(int ifnum, const struct can_frame *frame, kernel_pid_t tx_pid)
Allocate a CAN packet to transmit.
can_pkt_t
A CAN packet.
Definition: pkt.h:41
atomic_uint
Type with the same alignment and size as atomic_uint
Definition: c11_atomics_compat.hpp:130
can_pkt_buf_free
void can_pkt_buf_free(void *data, size_t size)
Free the data allocated by can_pkt_buf_alloc()
can_pkt_init
void can_pkt_init(void)
Initialize the CAN packet module.
can_pkt_buf_alloc
void * can_pkt_buf_alloc(size_t size)
Allocate size bytes and return the pointer.
can_reg_entry
registry entry
Definition: common.h:143
can_frame::data
uint8_t data[CAN_MAX_DLEN]
Frame data.
Definition: can.h:95
can_pkt_t::handle
int handle
handle (for tx frames
Definition: pkt.h:44
can_pkt_alloc_rx_data
can_rx_data_t * can_pkt_alloc_rx_data(void *data, size_t len, void *arg)
Allocate a can_rx_data_t and initialize it with gieven parameters.
can_pkt_alloc_mbox_tx
can_pkt_t * can_pkt_alloc_mbox_tx(int ifnum, const struct can_frame *frame, mbox_t *mbox)
Allocate a CAN packet for a mbox to transmit.
can_pkt_alloc_rx
can_pkt_t * can_pkt_alloc_rx(int ifnum, const struct can_frame *frame)
Allocate an incoming CAN packet.