forked from OpenCyphal/libcanard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
canard_internals.h
154 lines (120 loc) · 5.74 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
/*
* 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(CanardRxState* state,
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 CanardTransferType extractTransferType(uint32_t id);
CANARD_INTERNAL uint16_t extractDataType(uint32_t id);
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);
/// Returns the number of frames enqueued
CANARD_INTERNAL int16_t enqueueTxFrames(CanardInstance* ins,
uint32_t can_id,
uint8_t* transfer_id,
uint16_t crc,
const uint8_t* payload,
uint16_t payload_len);
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,
CanardPoolAllocatorBlock* 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);
#ifdef __cplusplus
}
#endif
#endif