NetBurner 3.5.8
PDF Version
Toggle main menu visibility
serinternal.h
1
/*NB_REVISION*/
2
3
/*NB_COPYRIGHT*/
4
5
#ifndef _NB_SER_INTERNAL
6
#define _NB_SER_INTERNAL
7
#include <buffers.h>
8
12
#define UART_INIT (0x0001)
/* UART is initialized */
13
14
#define UART_TX_EMPTY (0x0002)
/* UART Tx buffer is empty */
15
16
#define UART_SENT_STOP (0x0004)
/* UART has sent XOFF */
17
18
#define UART_RX_STOP (0x0008)
/* UART has received XOFF */
19
20
#define UART_FLOW_TX \
21
(0x0010)
/* UART must respond to received \
22
flow control */
23
24
#define UART_FLOW_RX \
25
(0x0020)
/* UART is allowed to send flow \
26
control */
27
28
#define UART_FLOW_NEED_TOSTOP (0x0040)
/* UART needs to send XOFF */
29
30
#define UART_FLOW_NEED_TOSTART (0x0080)
/* UART needs to send XON */
31
32
#define UART_RS485_TX_MODE \
33
(0x0100)
/* UART is in RS-485 HD/FD mode \
34
(not used) */
35
36
#define UART_MULTI_MODE (0x0200)
/* UART is in multi-drop mode */
37
38
#define UART_FLOW_TXRTSCTS \
39
(0x0400)
/* UART has TxCTS hardware flow \
40
control enabled */
41
42
#define UART_FLOW_TX485FD \
43
(0x0800)
/* UART is in RS-485 full-duplex \
44
mode */
45
46
#define UART_FLOW_TX485HD \
47
(0x1000)
/* UART is in RS-485 half-duplex \
48
mode */
49
50
#define UART_FLOW_RXRTSCTS \
51
(0x2000)
/* UART has RxRTS hardware flow \
52
control enabled */
53
54
#define UART_RS422_MODE (0x4000)
/* UART is in RS-422 mode */
55
56
#define UART_TX_LAST_BIT \
57
(0x8000)
/* UART has transmitted the last \
58
stop bit of the last byte */
59
63
#define XON (0x11)
64
#define XOFF (0x13)
65
71
#define UART_XOFF_LIMIT (100)
72
#define UART_XON_LIMIT (200)
73
74
typedef
int(GetNextCharFunc)(
int
uartnum);
75
typedef
void(PutNextCharFunc)(
int
uartnum, uint8_t c);
76
77
int
BaseGetChar(
int
num);
78
void
BasePutChar(
int
num, uint8_t c);
79
80
enum
dataBits_t
81
{
82
DATA_BITS_5 = 0,
83
DATA_BITS_6 = 1,
84
DATA_BITS_7 = 2,
85
DATA_BITS_8 = 3,
86
DATA_BITS_9 = 4,
87
DATA_BITS_10 = 5,
88
DATA_BITS_11 = 6,
89
DATA_BITS_12 = 7,
90
};
91
92
constexpr
inline
uint8_t GetBitCount(dataBits_t bits)
93
{
94
return
bits + 5;
95
}
96
97
//#define SERIAL_USE_RING_BUFFER
98
#ifdef SERIAL_USE_RING_BUFFER
99
class
serRingBuf
100
{
101
uint8_t *buf;
102
uint16_t siz;
103
uint16_t used;
104
uint16_t wr;
105
uint16_t rd;
106
static
int
idx;
107
108
int
put(uint8_t d)
volatile
;
109
int
get(uint8_t *d)
volatile
;
110
111
public
:
112
void
Init(uint8_t max_buffers, uint8_t fromisr = 1);
113
void
Reset(uint8_t max_buffers);
114
int
WriteData(uint8_t *d,
int
len)
volatile
;
115
int
ReadData(uint8_t *d,
int
len)
volatile
;
116
uint8_t PeekData();
117
bool
Full();
118
bool
Empty();
119
120
uint16_t SpaceAvail();
121
inline
void
SetMaxChunkLen(uint32_t maxStorage) {
return
; }
122
inline
void
SetStartOffset(uint32_t offset) {
return
; }
123
inline
void
SetMaxBuffers(uint8_t max_buffers) {
return
; }
124
inline
uint32_t GetMaxBuffers() {
return
1; }
125
inline
uint32_t GetMaxChunkLen() {
return
siz; }
126
inline
uint32_t GetStartOffset() {
return
0; }
127
inline
uint32_t GetMinimumFullSize(
int
maxSegments = -1) {
return
siz; }
128
};
129
130
typedef
serRingBuf serialBuf_t;
131
#else
132
typedef
fifo_buffer_storage
serialBuf_t;
133
#endif
134
135
struct
UartDataRec
136
{
137
serialBuf_t m_FifoRead;
138
serialBuf_t m_FifoWrite;
139
GetNextCharFunc *m_pGetCharFunc;
140
PutNextCharFunc *m_pPutCharFunc;
141
int
m_UartState;
142
uint8_t m_Errors;
143
dataBits_t m_dataBits : 3;
144
};
145
146
extern
UartDataRec UartData[];
147
148
void
WakeTx(
int
x);
149
150
#endif
/* _NB_SER_INTERNAL */
fifo_buffer_storage
FIFO buffer storage using linked pool buffers.
Definition
buffers.h:443
nbrtos
include
serinternal.h
Generated by
1.18.0