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
|
#ifndef BCPR_HDLC_H
#define BCPR_HDLC_H
#include "bcpr/bcpr.h"
#include <stdint.h>
typedef struct bcpr_hbuf {
unsigned rd, wr;
uint16_t buf[BCPR_HDLC_BUF];
} bcpr_hbuf_t;
typedef struct bcpr_channel {
int tx_delay, tx_tail, slottime, ppersist, fulldup;
} bcpr_channel_t;
typedef struct bcpr_hdlc {
int bitrate;
bcpr_channel_t ch;
bcpr_hbuf_t rx_hbuf;
bcpr_hbuf_t tx_hbuf;
int rx_state;
unsigned bitstream, bitbuf;
int numbits;
int dcd;
int rx_len;
uint8_t *rx_bp;
uint8_t rx_buffer[BCPR_MAXFLEN + 2];
int tx_state;
int numflags;
unsigned tx_bitstream;
int ptt;
int slotcnt;
unsigned tx_bitbuf;
int tx_numbits;
int tx_len;
uint8_t *tx_bp;
uint8_t tx_buffer[BCPR_MAXFLEN + 2];
/* pending KISS payload (without FEND/cmd) queued for TX */
uint8_t pending[BCPR_MAXFLEN];
int pending_len;
int have_pending;
} bcpr_hdlc_t;
void bcpr_hdlc_init(bcpr_hdlc_t *h, int bitrate, const bcpr_channel_t *ch);
void bcpr_hdlc_putbits(bcpr_hdlc_t *h, unsigned bits);
unsigned bcpr_hdlc_getbits(bcpr_hdlc_t *h);
void bcpr_hdlc_receiver(bcpr_hdlc_t *h,
void (*on_frame)(const uint8_t *kiss, int len, void *ud),
void *ud);
void bcpr_hdlc_transmitter(bcpr_hdlc_t *h);
void bcpr_hdlc_arbitrate(bcpr_hdlc_t *h);
int bcpr_hdlc_queue_kiss(bcpr_hdlc_t *h, const uint8_t *kiss, int len);
int bcpr_hdlc_ptt(const bcpr_hdlc_t *h);
/* Force idle TX — drop pending frame and clear keyed state. */
void bcpr_hdlc_abort_tx(bcpr_hdlc_t *h);
#endif
|