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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
//*****************************************************************************
//
// softuart.h - Defines and macros for the SoftUART.
//
// Copyright (c) 2010-2014 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.0.12573 of the Tiva Utility Library.
//
//*****************************************************************************
#ifndef __SOFTUART_H__
#define __SOFTUART_H__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
//! \addtogroup softuart_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! This structure contains the state of a single instance of a SoftUART
//! module.
//
//*****************************************************************************
typedef struct
{
//
//! The address of the callback function that is called to simulate the
//! interrupts that would be produced by a hardware UART implementation.
//! This address can be set via a direct structure access or using the
//! SoftUARTCallbackSet function.
//
void (*pfnIntCallback)(void);
//
//! The address of the GPIO pin to be used for the Tx signal. This member
//! can be set via a direct structure access or using the SoftUARTTxGPIOSet
//! function.
//
uint32_t ui32TxGPIO;
//
//! The address of the GPIO port to be used for the Rx signal. This member
//! can be set via a direct structure access or using the SoftUARTRxGPIOSet
//! function.
//
uint32_t ui32RxGPIOPort;
//
//! The address of the data buffer used for the transmit buffer. This
//! member can be set via a direct structure access or using the
//! SoftUARTTxBufferSet function.
//
uint8_t *pui8TxBuffer;
//
//! The address of the data buffer used for the receive buffer. This
//! member can be set via a direct structure access or using the
//! SoftUARTRxBufferSet function.
//
uint16_t *pui16RxBuffer;
//
//! The length of the transmit buffer. This member can be set via a direct
//! structure access or using the SoftUARTTxBufferSet function.
//
uint16_t ui16TxBufferLen;
//
//! The index into the transmit buffer of the next character to be
//! transmitted. This member should not be accessed or modified by the
//! application.
//
uint16_t ui16TxBufferRead;
//
//! The index into the transmit buffer of the next location to store a
//! character into the buffer. This member should not be accessed or
//! modified by the application.
//
uint16_t ui16TxBufferWrite;
//
//! The transmit buffer level at which the transmit interrupt is asserted.
//! This member should not be accessed or modified by the application.
//
uint16_t ui16TxBufferLevel;
//
//! The length of the receive buffer. This member can be set via a direct
//! structure access or using the SoftUARTRxBufferSet function.
//
uint16_t ui16RxBufferLen;
//
//! The index into the receive buffer of the next character to be read from
//! the buffer. This member should not be accessed or modified by the
//! application.
//
uint16_t ui16RxBufferRead;
//
//! The index into the receive buffer of the lcoation to store the next
//! character received. This member should not be accessed or modified by
//! the application.
//
uint16_t ui16RxBufferWrite;
//
//! The receive buffer level at which the receive interrupt is asserted.
//! This member should not be accessed or modified by the application.
//
uint16_t ui16RxBufferLevel;
//
//! The set of virtual interrupts that are currently asserted. This member
//! should not be accessed or modified by the application.
//
uint16_t ui16IntStatus;
//
//! The set of virtual interrupts that should be sent to the callback
//! function. This member should not be accessed or modified by the
//! application.
//
uint16_t ui16IntMask;
//
//! The configuration of the SoftUART module. This member can be set via
//! the SoftUARTConfigSet and SoftUARTFIFOLevelSet functions.
//
uint16_t ui16Config;
//
//! The flags that control the operation of the SoftUART module. This
//! member should not be be accessed or modified by the application.
//
uint8_t ui8Flags;
//
//! The current state of the SoftUART transmit state machine. This member
//! should not be accessed or modified by the application.
//
uint8_t ui8TxState;
//
//! The value that is written to the Tx pin at the start of the next
//! transmit timer tick. This member should not be accessed or modified
//! by the application.
//
uint8_t ui8TxNext;
//
//! The character that is currently be sent via the Tx pin. This member
//! should not be accessed or modified by the application.
//
uint8_t ui8TxData;
//
//! The GPIO pin to be used for the Rx signal. This member can be set via
//! a direct structure access or using the SoftUARTRxGPIOSet function.
//
uint8_t ui8RxPin;
//
//! The current state of the SoftUART receive state machine. This member
//! should not be accessed or modified by the application.
//
uint8_t ui8RxState;
//
//! The character that is currently being received via the Rx pin. This
//! member should not be accessed or modified by the application.
//
uint8_t ui8RxData;
//
//! The flags that indicate any errors that have occurred during the
//! reception of the current character via the Rx pin. This member should
//! not be accessed or modified by the application.
//
uint8_t ui8RxFlags;
//
//! The receive error status. This member should only be accessed via the
//! SoftUARTRxErrorGet and SoftURATRxErrorClear functions.
//
uint8_t ui8RxStatus;
}
tSoftUART;
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
//*****************************************************************************
//
// Values that can be passed to SoftUARTIntEnable(), SoftUARTIntDisable(), and
// SoftUARTIntClear() as the ui32IntFlags parameter, and returned from
// SoftUARTIntStatus().
//
//*****************************************************************************
#define SOFTUART_INT_EOT 0x800 // End of transmission interrupt
#define SOFTUART_INT_OE 0x400 // Overrun error interrupt
#define SOFTUART_INT_BE 0x200 // Break error interrupt
#define SOFTUART_INT_PE 0x100 // Parity error interrupt
#define SOFTUART_INT_FE 0x080 // Framing error interrupt
#define SOFTUART_INT_RT 0x040 // Receive timeout interrupt
#define SOFTUART_INT_TX 0x020 // Transmit interrupt
#define SOFTUART_INT_RX 0x010 // Receive interrupt
//*****************************************************************************
//
// Values that can be passed to SoftUARTConfigSet() as the ui32Config parameter
// and returned by SoftUARTConfigGet() in the pui32Config parameter.
// Additionally, the UART_CONFIG_PAR_* subset can be passed to
// SoftUARTParityModeSet() as the ui32Parity parameter, and are returned by
// SoftUARTParityModeGet().
//
//*****************************************************************************
#define SOFTUART_CONFIG_WLEN_MASK \
0x00000060 // Mask for extracting word length
#define SOFTUART_CONFIG_WLEN_8 0x00000060 // 8 bit data
#define SOFTUART_CONFIG_WLEN_7 0x00000040 // 7 bit data
#define SOFTUART_CONFIG_WLEN_6 0x00000020 // 6 bit data
#define SOFTUART_CONFIG_WLEN_5 0x00000000 // 5 bit data
#define SOFTUART_CONFIG_STOP_MASK \
0x00000008 // Mask for extracting stop bits
#define SOFTUART_CONFIG_STOP_ONE \
0x00000000 // One stop bit
#define SOFTUART_CONFIG_STOP_TWO \
0x00000008 // Two stop bits
#define SOFTUART_CONFIG_PAR_MASK \
0x00000086 // Mask for extracting parity
#define SOFTUART_CONFIG_PAR_NONE \
0x00000000 // No parity
#define SOFTUART_CONFIG_PAR_EVEN \
0x00000006 // Even parity
#define SOFTUART_CONFIG_PAR_ODD 0x00000002 // Odd parity
#define SOFTUART_CONFIG_PAR_ONE 0x00000082 // Parity bit is one
#define SOFTUART_CONFIG_PAR_ZERO \
0x00000086 // Parity bit is zero
#define SOFTUART_CONFIG_WLEN_S 5
//*****************************************************************************
//
// Values that can be passed to SoftUARTFIFOLevelSet() as the ui32TxLevel
// parameter and returned by SoftUARTFIFOLevelGet() in the pui32TxLevel.
//
//*****************************************************************************
#define SOFTUART_FIFO_TX1_8 0x00000000 // Transmit interrupt at 1/8 Full
#define SOFTUART_FIFO_TX2_8 0x00000001 // Transmit interrupt at 1/4 Full
#define SOFTUART_FIFO_TX4_8 0x00000002 // Transmit interrupt at 1/2 Full
#define SOFTUART_FIFO_TX6_8 0x00000003 // Transmit interrupt at 3/4 Full
#define SOFTUART_FIFO_TX7_8 0x00000004 // Transmit interrupt at 7/8 Full
//*****************************************************************************
//
// Values that can be passed to SoftUARTFIFOLevelSet() as the ui32RxLevel
// parameter and returned by SoftUARTFIFOLevelGet() in the pui32RxLevel.
//
//*****************************************************************************
#define SOFTUART_FIFO_RX1_8 0x00000000 // Receive interrupt at 1/8 Full
#define SOFTUART_FIFO_RX2_8 0x00000008 // Receive interrupt at 1/4 Full
#define SOFTUART_FIFO_RX4_8 0x00000010 // Receive interrupt at 1/2 Full
#define SOFTUART_FIFO_RX6_8 0x00000018 // Receive interrupt at 3/4 Full
#define SOFTUART_FIFO_RX7_8 0x00000020 // Receive interrupt at 7/8 Full
//*****************************************************************************
//
// Values returned from SoftUARTRxErrorGet().
//
//*****************************************************************************
#define SOFTUART_RXERROR_OVERRUN \
0x00000008 // An overrun error occurred
#define SOFTUART_RXERROR_BREAK 0x00000004 // A break was received
#define SOFTUART_RXERROR_PARITY 0x00000002 // A parity error occurred
#define SOFTUART_RXERROR_FRAMING \
0x00000001 // A framing error occurred
//*****************************************************************************
//
// Values returned from SoftUARTRxTick().
//
//*****************************************************************************
#define SOFTUART_RXTIMER_NOP 0 // The timer should continue to run
#define SOFTUART_RXTIMER_END 1 // The timer should be stopped
//*****************************************************************************
//
// API Function prototypes
//
//*****************************************************************************
extern void SoftUARTInit(tSoftUART *psUART);
extern void SoftUARTParityModeSet(tSoftUART *psUART, uint32_t ui32Parity);
extern uint32_t SoftUARTParityModeGet(tSoftUART *psUART);
extern void SoftUARTFIFOLevelSet(tSoftUART *psUART, uint32_t ui32TxLevel,
uint32_t ui32RxLevel);
extern void SoftUARTFIFOLevelGet(tSoftUART *psUART, uint32_t *pui32TxLevel,
uint32_t *pui32RxLevel);
extern void SoftUARTConfigSet(tSoftUART *psUART, uint32_t ui32Config);
extern void SoftUARTConfigGet(tSoftUART *psUART, uint32_t *pui32Config);
extern void SoftUARTEnable(tSoftUART *psUART);
extern void SoftUARTDisable(tSoftUART *psUART);
extern void SoftUARTFIFOEnable(tSoftUART *psUART);
extern void SoftUARTFIFODisable(tSoftUART *psUART);
extern bool SoftUARTCharsAvail(tSoftUART *psUART);
extern bool SoftUARTSpaceAvail(tSoftUART *psUART);
extern int32_t SoftUARTCharGetNonBlocking(tSoftUART *psUART);
extern int32_t SoftUARTCharGet(tSoftUART *psUART);
extern bool SoftUARTCharPutNonBlocking(tSoftUART *psUART,
uint8_t ui8Data);
extern void SoftUARTCharPut(tSoftUART *psUART, uint8_t ui8Data);
extern void SoftUARTBreakCtl(tSoftUART *psUART, bool bBreakState);
extern bool SoftUARTBusy(tSoftUART *psUART);
extern void SoftUARTIntEnable(tSoftUART *psUART, uint32_t ui32IntFlags);
extern void SoftUARTIntDisable(tSoftUART *psUART, uint32_t ui32IntFlags);
extern uint32_t SoftUARTIntStatus(tSoftUART *psUART, bool bMasked);
extern void SoftUARTIntClear(tSoftUART *psUART, uint32_t ui32IntFlags);
extern uint32_t SoftUARTRxErrorGet(tSoftUART *psUART);
extern void SoftUARTRxErrorClear(tSoftUART *psUART);
extern uint32_t SoftUARTRxTick(tSoftUART *psUART, bool bEdgeInt);
extern void SoftUARTTxIntModeSet(tSoftUART *psUART, uint32_t ui32Mode);
extern uint32_t SoftUARTTxIntModeGet(tSoftUART *psUART);
extern void SoftUARTTxTimerTick(tSoftUART *psUART);
extern void SoftUARTCallbackSet(tSoftUART *psUART, void (*pfnCallback)(void));
extern void SoftUARTTxGPIOSet(tSoftUART *psUART, uint32_t ui32Base,
uint8_t ui8Pin);
extern void SoftUARTRxGPIOSet(tSoftUART *psUART, uint32_t ui32Base,
uint8_t ui8Pin);
extern void SoftUARTTxBufferSet(tSoftUART *psUART, uint8_t *pui8TxBuffer,
uint16_t ui16Len);
extern void SoftUARTRxBufferSet(tSoftUART *psUART, uint16_t *pui16RxBuffer,
uint16_t ui16Len);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif // __SOFTUART_H__
|