|
70 | 70 | #define TRANSPORT_PROTOCOL
|
71 | 71 | #endif
|
72 | 72 |
|
73 |
| -#ifndef MAX_PAYLOAD |
74 |
| -#define MAX_PAYLOAD (255U) |
| 73 | +// Number of bytes needed for a frame with a given payload length, excluding stuff bytes |
| 74 | +// 3 header bytes, ID/control byte, length byte, seq byte, 4 byte CRC, EOF byte |
| 75 | +#define MIN_OVERHEAD 11 |
| 76 | + |
| 77 | +#if defined(MAX_PAYLOAD) |
| 78 | +// for backwards compatibility |
| 79 | +#define MIN_MAX_PAYLOAD MAX_PAYLOAD |
| 80 | +#endif |
| 81 | + |
| 82 | +#ifdef MIN_MAX_PAYLOAD |
| 83 | +#define MIN_MAX_PACKET_SIZE (MIN_MAX_PAYLOAD + MIN_OVERHEAD) |
| 84 | +#elif defined(MIN_MAX_PACKET_SIZE) |
| 85 | +#if (MIN_MAX_PACKET_SIZE < MIN_OVERHEAD) |
| 86 | +#error "MIN_MAX_PACKET_SIZE must be greater than MIN_OVERHEAD" |
| 87 | +#endif |
| 88 | +#define MIN_MAX_PAYLOAD (MIN_MAX_PACKET_SIZE - MIN_OVERHEAD) |
| 89 | +#else |
| 90 | +#define MIN_MAX_PAYLOAD 255 |
| 91 | +#define MIN_MAX_PACKET_SIZE (MIN_MAX_PAYLOAD + MIN_OVERHEAD) |
| 92 | +#endif |
| 93 | + |
| 94 | +#if (MIN_MAX_PAYLOAD > 255) |
| 95 | +#error "MIN frame payloads can be no bigger than 255 bytes" |
75 | 96 | #endif
|
76 | 97 |
|
77 | 98 | // Powers of two for FIFO management. Default is 16 frames in the FIFO, total of 1024 bytes for frame data
|
|
85 | 106 | #define TRANSPORT_FIFO_MAX_FRAMES (1U << TRANSPORT_FIFO_SIZE_FRAMES_BITS)
|
86 | 107 | #define TRANSPORT_FIFO_MAX_FRAME_DATA (1U << TRANSPORT_FIFO_SIZE_FRAME_DATA_BITS)
|
87 | 108 |
|
88 |
| -#if (MAX_PAYLOAD > 255) |
89 |
| -#error "MIN frame payloads can be no bigger than 255 bytes" |
90 |
| -#endif |
91 |
| - |
92 | 109 | // Indices into the frames FIFO are uint8_t and so can't have more than 256 frames in a FIFO
|
93 | 110 | #if (TRANSPORT_FIFO_MAX_FRAMES > 256)
|
94 | 111 | #error "Transport FIFO frames cannot exceed 256"
|
@@ -143,7 +160,7 @@ struct min_context {
|
143 | 160 | #ifdef TRANSPORT_PROTOCOL
|
144 | 161 | struct transport_fifo transport_fifo; // T-MIN queue of outgoing frames
|
145 | 162 | #endif
|
146 |
| - uint8_t rx_frame_payload_buf[MAX_PAYLOAD]; // Payload received so far |
| 163 | + uint8_t rx_frame_payload_buf[MIN_MAX_PAYLOAD]; // Payload received so far |
147 | 164 | uint32_t rx_frame_checksum; // Checksum received over the wire
|
148 | 165 | struct crc32_context rx_checksum; // Calculated checksum for receiving frame
|
149 | 166 | struct crc32_context tx_checksum; // Calculated checksum for sending frame
|
|
0 commit comments