forked from dronecan/libcanard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canard_internals.h
160 lines (123 loc) · 6.11 KB
/
canard_internals.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 UAVCAN Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Contributors: https://github.com/UAVCAN/libcanard/contributors
*/
/*
* This file holds function declarations that expose the library's internal definitions for unit testing.
* It is NOT part of the library's API and should not even be looked at by the user.
*/
#ifndef CANARD_INTERNALS_H
#define CANARD_INTERNALS_H
#include "canard.h"
#ifdef __cplusplus
extern "C" {
#endif
/// This macro is needed only for testing and development. Do not redefine this in production.
#ifndef CANARD_INTERNAL
# define CANARD_INTERNAL static
#endif
CANARD_INTERNAL CanardRxState* traverseRxStates(CanardInstance* ins,
uint32_t transfer_descriptor);
CANARD_INTERNAL CanardRxState* createRxState(CanardPoolAllocator* allocator,
uint32_t transfer_descriptor);
CANARD_INTERNAL CanardRxState* prependRxState(CanardInstance* ins,
uint32_t transfer_descriptor);
CANARD_INTERNAL CanardRxState* findRxState(CanardInstance *ins,
uint32_t transfer_descriptor);
CANARD_INTERNAL int16_t bufferBlockPushBytes(CanardPoolAllocator* allocator,
CanardRxState* state,
const uint8_t* data,
uint8_t data_len);
CANARD_INTERNAL CanardBufferBlock* createBufferBlock(CanardPoolAllocator* allocator);
CANARD_INTERNAL void pushTxQueue(CanardInstance* ins,
CanardTxQueueItem* item);
CANARD_INTERNAL bool isPriorityHigher(uint32_t id,
uint32_t rhs);
CANARD_INTERNAL CanardTxQueueItem* createTxItem(CanardPoolAllocator* allocator);
CANARD_INTERNAL void prepareForNextTransfer(CanardRxState* state);
CANARD_INTERNAL int16_t computeTransferIDForwardDistance(uint8_t a,
uint8_t b);
CANARD_INTERNAL void incrementTransferID(uint8_t* transfer_id);
CANARD_INTERNAL uint64_t releaseStatePayload(CanardInstance* ins,
CanardRxState* rxstate);
CANARD_INTERNAL uint16_t dlcToDataLength(uint16_t dlc);
CANARD_INTERNAL uint16_t dataLengthToDlc(uint16_t data_length);
/// Returns the number of frames enqueued
CANARD_INTERNAL int16_t enqueueTxFrames(CanardInstance* ins,
uint32_t can_id,
uint16_t crc,
CanardTxTransfer* transfer);
CANARD_INTERNAL void copyBitArray(const uint8_t* src,
uint32_t src_offset,
uint32_t src_len,
uint8_t* dst,
uint32_t dst_offset);
/**
* Moves specified bits from the scattered transfer storage to a specified contiguous buffer.
* Returns the number of bits copied, or negated error code.
*/
CANARD_INTERNAL int16_t descatterTransferPayload(const CanardRxTransfer* transfer,
uint32_t bit_offset,
uint8_t bit_length,
void* output);
CANARD_INTERNAL bool isBigEndian(void);
CANARD_INTERNAL void swapByteOrder(void* data, unsigned size);
/*
* Transfer CRC
*/
CANARD_INTERNAL uint16_t crcAddByte(uint16_t crc_val,
uint8_t byte);
CANARD_INTERNAL uint16_t crcAddSignature(uint16_t crc_val,
uint64_t data_type_signature);
CANARD_INTERNAL uint16_t crcAdd(uint16_t crc_val,
const uint8_t* bytes,
size_t len);
/**
* Inits a memory allocator.
*
* @param [in] allocator The memory allocator to initialize.
* @param [in] buf The buffer used by the memory allocator.
* @param [in] buf_len The number of blocks in buf.
*/
CANARD_INTERNAL void initPoolAllocator(CanardPoolAllocator* allocator,
void *buf,
uint16_t buf_len);
/**
* Allocates a block from the given pool allocator.
*/
CANARD_INTERNAL void* allocateBlock(CanardPoolAllocator* allocator);
/**
* Frees a memory block previously returned by canardAllocateBlock.
*/
CANARD_INTERNAL void freeBlock(CanardPoolAllocator* allocator,
void* p);
CANARD_INTERNAL uint16_t calculateCRC(const CanardTxTransfer* transfer_object);
CANARD_INTERNAL CanardBufferBlock *canardBufferFromIdx(CanardPoolAllocator* allocator, canard_buffer_idx_t idx);
CANARD_INTERNAL canard_buffer_idx_t canardBufferToIdx(CanardPoolAllocator* allocator, const CanardBufferBlock *buf);
CANARD_INTERNAL CanardRxState *canardRxFromIdx(CanardPoolAllocator* allocator, canard_buffer_idx_t idx);
CANARD_INTERNAL canard_buffer_idx_t canardRxToIdx(CanardPoolAllocator* allocator, const CanardRxState *rx);
#ifdef __cplusplus
}
#endif
#endif