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
|
//*****************************************************************************
//
// softuart.h - Defines and macros for the SoftUART.
//
// Copyright (c) 2010-2012 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 9453 of the Stellaris Firmware Development Package.
//
//*****************************************************************************
#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.
//
unsigned long ulTxGPIO;
//
//! 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.
//
unsigned long ulRxGPIOPort;
//
//! 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.
//
unsigned char *pucTxBuffer;
//
//! 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.
//
unsigned short *pusRxBuffer;
//
//! The length of the transmit buffer. This member can be set via a direct
//! structure access or using the SoftUARTTxBufferSet function.
//
unsigned short usTxBufferLen;
//
//! The index into the transmit buffer of the next character to be
//! transmitted. This member should not be accessed or modified by the
//! application.
//
unsigned short usTxBufferRead;
//
//! 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.
//
unsigned short usTxBufferWrite;
//
//! The transmit buffer level at which the transmit interrupt is asserted.
//! This member should not be accessed or modified by the application.
//
unsigned short usTxBufferLevel;
//
//! The length of the receive buffer. This member can be set via a direct
//! structure access or using the SoftUARTRxBufferSet function.
//
unsigned short usRxBufferLen;
//
//! 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.
//
unsigned short usRxBufferRead;
//
//! 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.
//
unsigned short usRxBufferWrite;
//
//! The receive buffer level at which the receive interrupt is asserted.
//! This member should not be accessed or modified by the application.
//
unsigned short usRxBufferLevel;
//
//! The set of virtual interrupts that are currently asserted. This member
//! should not be accessed or modified by the application.
//
unsigned short usIntStatus;
//
//! The set of virtual interrupts that should be sent to the callback
//! function. This member should not be accessed or modified by the
//! application.
//
unsigned short usIntMask;
//
//! The configuration of the SoftUART module. This member can be set via
//! the SoftUARTConfigSet and SoftUARTFIFOLevelSet functions.
//
unsigned short usConfig;
//
//! The flags that control the operation of the SoftUART module. This
//! member should not be be accessed or modified by the application.
//
unsigned char ucFlags;
//
//! The current state of the SoftUART transmit state machine. This member
//! should not be accessed or modified by the application.
//
unsigned char ucTxState;
//
//! 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.
//
unsigned char ucTxNext;
//
//! The character that is currently be sent via the Tx pin. This member
//! should not be accessed or modified by the application.
//
unsigned char ucTxData;
//
//! 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.
//
unsigned char ucRxPin;
//
//! The current state of the SoftUART receive state machine. This member
//! should not be accessed or modified by the application.
//
unsigned char ucRxState;
//
//! The character that is currently being received via the Rx pin. This
//! member should not be accessed or modified by the application.
//
unsigned char ucRxData;
//
//! 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.
//
unsigned char ucRxFlags;
//
//! The receive error status. This member should only be accessed via the
//! SoftUARTRxErrorGet and SoftURATRxErrorClear functions.
//
unsigned char ucRxStatus;
}
tSoftUART;
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
//*****************************************************************************
//
// Values that can be passed to SoftUARTIntEnable, SoftUARTIntDisable, and
// SoftUARTIntClear as the ulIntFlags 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 ulConfig parameter and
// returned by SoftUARTConfigGet in the pulConfig parameter. Additionally, the
// UART_CONFIG_PAR_* subset can be passed to SoftUARTParityModeSet as the
// ulParity 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 ulTxLevel parameter
// and returned by SoftUARTFIFOLevelGet in the pulTxLevel.
//
//*****************************************************************************
#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 ulRxLevel parameter
// and returned by SoftUARTFIFOLevelGet in the pulRxLevel.
//
//*****************************************************************************
#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 *pUART);
extern void SoftUARTParityModeSet(tSoftUART *pUART, unsigned long ulParity);
extern unsigned long SoftUARTParityModeGet(tSoftUART *pUART);
extern void SoftUARTFIFOLevelSet(tSoftUART *pUART, unsigned long ulTxLevel,
unsigned long ulRxLevel);
extern void SoftUARTFIFOLevelGet(tSoftUART *pUART, unsigned long *pulTxLevel,
unsigned long *pulRxLevel);
extern void SoftUARTConfigSet(tSoftUART *pUART, unsigned long ulConfig);
extern void SoftUARTConfigGet(tSoftUART *pUART, unsigned long *pulConfig);
extern void SoftUARTEnable(tSoftUART *pUART);
extern void SoftUARTDisable(tSoftUART *pUART);
extern void SoftUARTFIFOEnable(tSoftUART *pUART);
extern void SoftUARTFIFODisable(tSoftUART *pUART);
extern tBoolean SoftUARTCharsAvail(tSoftUART *pUART);
extern tBoolean SoftUARTSpaceAvail(tSoftUART *pUART);
extern long SoftUARTCharGetNonBlocking(tSoftUART *pUART);
extern long SoftUARTCharGet(tSoftUART *pUART);
extern tBoolean SoftUARTCharPutNonBlocking(tSoftUART *pUART,
unsigned char ucData);
extern void SoftUARTCharPut(tSoftUART *pUART, unsigned char ucData);
extern void SoftUARTBreakCtl(tSoftUART *pUART, tBoolean bBreakState);
extern tBoolean SoftUARTBusy(tSoftUART *pUART);
extern void SoftUARTIntEnable(tSoftUART *pUART, unsigned long ulIntFlags);
extern void SoftUARTIntDisable(tSoftUART *pUART, unsigned long ulIntFlags);
extern unsigned long SoftUARTIntStatus(tSoftUART *pUART, tBoolean bMasked);
extern void SoftUARTIntClear(tSoftUART *pUART, unsigned long ulIntFlags);
extern unsigned long SoftUARTRxErrorGet(tSoftUART *pUART);
extern void SoftUARTRxErrorClear(tSoftUART *pUART);
extern unsigned long SoftUARTRxTick(tSoftUART *pUART, tBoolean bEdgeInt);
extern void SoftUARTTxIntModeSet(tSoftUART *pUART, unsigned long ulMode);
extern unsigned long SoftUARTTxIntModeGet(tSoftUART *pUART);
extern void SoftUARTTxTimerTick(tSoftUART *pUART);
extern void SoftUARTCallbackSet(tSoftUART *pUART, void (*pfnCallback)(void));
extern void SoftUARTTxGPIOSet(tSoftUART *pUART, unsigned long ulBase,
unsigned char ucPin);
extern void SoftUARTRxGPIOSet(tSoftUART *pUART, unsigned long ulBase,
unsigned char ucPin);
extern void SoftUARTTxBufferSet(tSoftUART *pUART, unsigned char *pucTxBuffer,
unsigned short usLen);
extern void SoftUARTRxBufferSet(tSoftUART *pUART, unsigned short *pusRxBuffer,
unsigned short usLen);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif // __SOFTUART_H__
|