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 
9 #pragma once
10 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include <stdatomic.h>
27 
28 #include "can/common.h"
29 #include "can/can.h"
30 #include "msg.h"
31 #ifdef MODULE_CAN_MBOX
32 #include "mbox.h"
33 #endif
34 
40 typedef struct {
43  int handle;
45 } can_pkt_t;
46 
52 void can_pkt_init(void);
53 
66 can_pkt_t *can_pkt_alloc_tx(int ifnum, const can_frame_t *frame, kernel_pid_t tx_pid);
67 
76 can_pkt_t *can_pkt_alloc_rx(int ifnum, const can_frame_t *frame);
77 
78 #if defined(MODULE_CAN_MBOX) || defined(DOXYGEN)
91 can_pkt_t *can_pkt_alloc_mbox_tx(int ifnum, const can_frame_t *frame, mbox_t *mbox);
92 #endif
93 
101 
113 can_rx_data_t *can_pkt_alloc_rx_data(void *data, size_t len, void *arg);
114 
121 
131 void *can_pkt_buf_alloc(size_t size);
132 
139 void can_pkt_buf_free(void *data, size_t size);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
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 * can_pkt_alloc_rx(int ifnum, const can_frame_t *frame)
Allocate an incoming CAN packet.
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_t * can_pkt_alloc_mbox_tx(int ifnum, const can_frame_t *frame, mbox_t *mbox)
Allocate a CAN packet for a mbox to transmit.
void can_pkt_buf_free(void *data, size_t size)
Free the data allocated by can_pkt_buf_alloc()
void * can_pkt_buf_alloc(size_t size)
Allocate size bytes and return the pointer.
void can_pkt_init(void)
Initialize the CAN packet module.
void can_pkt_free(can_pkt_t *pkt)
Free a CAN packet.
can_pkt_t * can_pkt_alloc_tx(int ifnum, const can_frame_t *frame, kernel_pid_t tx_pid)
Allocate a CAN packet to transmit.
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:138
Mailbox API.
Type with the same alignment and size as atomic_uint
Controller Area Network frame.
Definition: can.h:100
A CAN packet.
Definition: pkt.h:40
int handle
handle (for tx frames
Definition: pkt.h:43
can_frame_t frame
CAN Frame.
Definition: pkt.h:44
can_reg_entry_t entry
entry containing ifnum and upper layer info
Definition: pkt.h:41
atomic_uint ref_count
Reference counter (for rx frames)
Definition: pkt.h:42
registry entry
Definition: common.h:155
Received data structure.
Definition: common.h:134
Mailbox struct definition.
Definition: mbox.h:40
Definitions high-level CAN interface.
Definitions of high-level CAN interface.