OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3S811_IAR/] [LuminaryCode/] [uart.c] - Blame information for rev 581

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 jeremybenn
//*****************************************************************************
2
//
3
// uart.c - Driver for the UART.
4
//
5
// Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.
6
//
7
// Software License Agreement
8
//
9
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10
// exclusively on LMI's Stellaris Family of microcontroller products.
11
//
12
// The software is owned by LMI and/or its suppliers, and is protected under
13
// applicable copyright laws.  All rights are reserved.  Any use in violation
14
// of the foregoing restrictions may subject the user to criminal sanctions
15
// under applicable laws, as well as to civil liability for the breach of the
16
// terms and conditions of this license.
17
//
18
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23
//
24
// This is part of revision 991 of the Stellaris Driver Library.
25
//
26
//*****************************************************************************
27
 
28
//*****************************************************************************
29
//
30
//! \addtogroup uart_api
31
//! @{
32
//
33
//*****************************************************************************
34
 
35
#include "../hw_ints.h"
36
#include "../hw_memmap.h"
37
#include "../hw_types.h"
38
#include "../hw_uart.h"
39
#include "debug.h"
40
#include "interrupt.h"
41
#include "sysctl.h"
42
#include "uart.h"
43
 
44
//*****************************************************************************
45
//
46
//! Sets the type of parity.
47
//!
48
//! \param ulBase is the base address of the UART port.
49
//! \param ulParity specifies the type of parity to use.
50
//!
51
//! Sets the type of parity to use for transmitting and expect when receiving.
52
//! The \e ulParity parameter must be one of \b UART_CONFIG_PAR_NONE,
53
//! \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE,
54
//! or \b UART_CONFIG_PAR_ZERO.  The last two allow direct control of the
55
//! parity bit; it will always be either be one or zero based on the mode.
56
//!
57
//! \return None.
58
//
59
//*****************************************************************************
60
#if defined(GROUP_paritymodeset) || defined(BUILD_ALL) || defined(DOXYGEN)
61
void
62
UARTParityModeSet(unsigned long ulBase, unsigned long ulParity)
63
{
64
    //
65
    // Check the arguments.
66
    //
67
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
68
    ASSERT((ulParity == UART_CONFIG_PAR_NONE) ||
69
           (ulParity == UART_CONFIG_PAR_EVEN) ||
70
           (ulParity == UART_CONFIG_PAR_ODD) ||
71
           (ulParity == UART_CONFIG_PAR_ONE) ||
72
           (ulParity == UART_CONFIG_PAR_ZERO));
73
 
74
    //
75
    // Set the parity mode.
76
    //
77
    HWREG(ulBase + UART_O_LCR_H) = ((HWREG(ulBase + UART_O_LCR_H) &
78
                                     ~(UART_LCR_H_SPS | UART_LCR_H_EPS |
79
                                       UART_LCR_H_PEN)) | ulParity);
80
}
81
#endif
82
 
83
//*****************************************************************************
84
//
85
//! Gets the type of parity currently being used.
86
//!
87
//! \param ulBase is the base address of the UART port.
88
//!
89
//! \return The current parity settings, specified as one of
90
//! \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, \b UART_CONFIG_PAR_ODD,
91
//! \b UART_CONFIG_PAR_ONE, or \b UART_CONFIG_PAR_ZERO.
92
//
93
//*****************************************************************************
94
#if defined(GROUP_paritymodeget) || defined(BUILD_ALL) || defined(DOXYGEN)
95
unsigned long
96
UARTParityModeGet(unsigned long ulBase)
97
{
98
    //
99
    // Check the arguments.
100
    //
101
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
102
 
103
    //
104
    // Return the current parity setting.
105
    //
106
    return(HWREG(ulBase + UART_O_LCR_H) &
107
           (UART_LCR_H_SPS | UART_LCR_H_EPS | UART_LCR_H_PEN));
108
}
109
#endif
110
 
111
//*****************************************************************************
112
//
113
//! Sets the configuration of a UART.
114
//!
115
//! \param ulBase is the base address of the UART port.
116
//! \param ulBaud is the desired baud rate.
117
//! \param ulConfig is the data format for the port (number of data bits,
118
//! number of stop bits, and parity).
119
//!
120
//! This function will configure the UART for operation in the specified data
121
//! format.  The baud rate is provided in the \e ulBaud parameter and the
122
//! data format in the \e ulConfig parameter.
123
//!
124
//! The \e ulConfig parameter is the logical OR of three values: the number of
125
//! data bits, the number of stop bits, and the parity.  \b UART_CONFIG_WLEN_8,
126
//! \b UART_CONFIG_WLEN_7, \b UART_CONFIG_WLEN_6, and \b UART_CONFIG_WLEN_5
127
//! select from eight to five data bits per byte (respectively).
128
//! \b UART_CONFIG_STOP_ONE and \b UART_CONFIG_STOP_TWO select one or two stop
129
//! bits (respectively).  \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN,
130
//! \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE, and \b UART_CONFIG_PAR_ZERO
131
//! select the parity mode (no parity bit, even parity bit, odd parity bit,
132
//! parity bit always one, and parity bit always zero, respectively).
133
//!
134
//! The baud rate is dependent upon the system clock rate returned by
135
//! SysCtlClockGet(); if it does not return the correct system clock rate then
136
//! the baud rate will be incorrect.
137
//!
138
//! \return None.
139
//
140
//*****************************************************************************
141
#if defined(GROUP_configset) || defined(BUILD_ALL) || defined(DOXYGEN)
142
void
143
UARTConfigSet(unsigned long ulBase, unsigned long ulBaud,
144
              unsigned long ulConfig)
145
{
146
    unsigned long ulUARTClk, ulInt, ulFrac;
147
 
148
    //
149
    // Check the arguments.
150
    //
151
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
152
 
153
    //
154
    // Stop the UART.
155
    //
156
    UARTDisable(ulBase);
157
 
158
    //
159
    // Determine the UART clock rate.
160
    //
161
    ulUARTClk = SysCtlClockGet();
162
 
163
    //
164
    // Compute the fractional baud rate divider.
165
    //
166
    ulInt = ulUARTClk / (16 * ulBaud);
167
    ulFrac = ulUARTClk % (16 * ulBaud);
168
    ulFrac = ((((2 * ulFrac * 4) / ulBaud) + 1) / 2);
169
 
170
    //
171
    // Set the baud rate.
172
    //
173
    HWREG(ulBase + UART_O_IBRD) = ulInt;
174
    HWREG(ulBase + UART_O_FBRD) = ulFrac;
175
 
176
    //
177
    // Set parity, data length, and number of stop bits.
178
    //
179
    HWREG(ulBase + UART_O_LCR_H) = ulConfig;
180
 
181
    //
182
    // Clear the flags register.
183
    //
184
    HWREG(ulBase + UART_O_FR) = 0;
185
 
186
    //
187
    // Start the UART.
188
    //
189
    UARTEnable(ulBase);
190
}
191
#endif
192
 
193
//*****************************************************************************
194
//
195
//! Gets the current configuration of a UART.
196
//!
197
//! \param ulBase is the base address of the UART port.
198
//! \param pulBaud is a pointer to storage for the baud rate.
199
//! \param pulConfig is a pointer to storage for the data format.
200
//!
201
//! The baud rate and data format for the UART is determined.  The returned
202
//! baud rate is the actual baud rate; it may not be the exact baud rate
203
//! requested or an ``official'' baud rate.  The data format returned in
204
//! \e pulConfig is enumerated the same as the \e ulConfig parameter of
205
//! UARTConfigSet().
206
//!
207
//! The baud rate is dependent upon the system clock rate returned by
208
//! SysCtlClockGet(); if it does not return the correct system clock rate then
209
//! the baud rate will be computed incorrectly.
210
//!
211
//! \return None.
212
//
213
//*****************************************************************************
214
#if defined(GROUP_configget) || defined(BUILD_ALL) || defined(DOXYGEN)
215
void
216
UARTConfigGet(unsigned long ulBase, unsigned long *pulBaud,
217
              unsigned long *pulConfig)
218
 
219
{
220
    unsigned long ulInt, ulFrac;
221
 
222
    //
223
    // Check the arguments.
224
    //
225
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
226
 
227
    //
228
    // Compute the baud rate.
229
    //
230
    ulInt = HWREG(ulBase + UART_O_IBRD);
231
    ulFrac = HWREG(ulBase + UART_O_FBRD);
232
    *pulBaud = (SysCtlClockGet() * 4) / ((64 * ulInt) + ulFrac);
233
 
234
    //
235
    // Get the parity, data length, and number of stop bits.
236
    //
237
    *pulConfig = (HWREG(ulBase + UART_O_LCR_H) &
238
                  (UART_LCR_H_SPS | UART_LCR_H_WLEN | UART_LCR_H_STP2 |
239
                   UART_LCR_H_EPS | UART_LCR_H_PEN));
240
}
241
#endif
242
 
243
//*****************************************************************************
244
//
245
//! Enables transmitting and receiving.
246
//!
247
//! \param ulBase is the base address of the UART port.
248
//!
249
//! Sets the UARTEN, TXE, and RXE bits, and enables the transmit and receive
250
//! FIFOs.
251
//!
252
//! \return None.
253
//
254
//*****************************************************************************
255
#if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)
256
void
257
UARTEnable(unsigned long ulBase)
258
{
259
    //
260
    // Check the arguments.
261
    //
262
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
263
 
264
    //
265
    // Enable the FIFO.
266
    //
267
    HWREG(ulBase + UART_O_LCR_H) |= UART_LCR_H_FEN;
268
 
269
    //
270
    // Enable RX, TX, and the UART.
271
    //
272
    HWREG(ulBase + UART_O_CTL) |= (UART_CTL_UARTEN | UART_CTL_TXE |
273
                                   UART_CTL_RXE);
274
}
275
#endif
276
 
277
//*****************************************************************************
278
//
279
//! Disables transmitting and receiving.
280
//!
281
//! \param ulBase is the base address of the UART port.
282
//!
283
//! Clears the UARTEN, TXE, and RXE bits, then waits for the end of
284
//! transmission of the current character, and flushes the transmit FIFO.
285
//!
286
//! \return None.
287
//
288
//*****************************************************************************
289
#if defined(GROUP_disable) || defined(BUILD_ALL) || defined(DOXYGEN)
290
void
291
UARTDisable(unsigned long ulBase)
292
{
293
    //
294
    // Check the arguments.
295
    //
296
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
297
 
298
    //
299
    // Wait for end of TX.
300
    //
301
    while(HWREG(ulBase + UART_O_FR) & UART_FR_BUSY)
302
    {
303
    }
304
 
305
    //
306
    // Disable the FIFO.
307
    //
308
    HWREG(ulBase + UART_O_LCR_H) &= ~(UART_LCR_H_FEN);
309
 
310
    //
311
    // Disable the UART.
312
    //
313
    HWREG(ulBase + UART_O_CTL) &= ~(UART_CTL_UARTEN | UART_CTL_TXE |
314
                                    UART_CTL_RXE);
315
}
316
#endif
317
 
318
//*****************************************************************************
319
//
320
//! Determines if there are any characters in the receive FIFO.
321
//!
322
//! \param ulBase is the base address of the UART port.
323
//!
324
//! This function returns a flag indicating whether or not there is data
325
//! available in the receive FIFO.
326
//!
327
//! \return Returns \b true if there is data in the receive FIFO, and \b false
328
//! if there is no data in the receive FIFO.
329
//
330
//*****************************************************************************
331
#if defined(GROUP_charsavail) || defined(BUILD_ALL) || defined(DOXYGEN)
332
tBoolean
333
UARTCharsAvail(unsigned long ulBase)
334
{
335
    //
336
    // Check the arguments.
337
    //
338
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
339
 
340
    //
341
    // Return the availability of characters.
342
    //
343
    return((HWREG(ulBase + UART_O_FR) & UART_FR_RXFE) ? false : true);
344
}
345
#endif
346
 
347
//*****************************************************************************
348
//
349
//! Determines if there is any space in the transmit FIFO.
350
//!
351
//! \param ulBase is the base address of the UART port.
352
//!
353
//! This function returns a flag indicating whether or not there is space
354
//! available in the transmit FIFO.
355
//!
356
//! \return Returns \b true if there is space available in the transmit FIFO,
357
//! and \b false if there is no space available in the transmit FIFO.
358
//
359
//*****************************************************************************
360
#if defined(GROUP_spaceavail) || defined(BUILD_ALL) || defined(DOXYGEN)
361
tBoolean
362
UARTSpaceAvail(unsigned long ulBase)
363
{
364
    //
365
    // Check the arguments.
366
    //
367
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
368
 
369
    //
370
    // Return the availability of space.
371
    //
372
    return((HWREG(ulBase + UART_O_FR) & UART_FR_TXFF) ? false : true);
373
}
374
#endif
375
 
376
//*****************************************************************************
377
//
378
//! Receives a character from the specified port.
379
//!
380
//! \param ulBase is the base address of the UART port.
381
//!
382
//! Gets a character from the receive FIFO for the specified port.
383
//!
384
//! \return Returns the character read from the specified port, cast as a
385
//! \e long.  A \b -1 will be returned if there are no characters present in
386
//! the receive FIFO.  The UARTCharsAvail() function should be called before
387
//! attempting to call this function.
388
//
389
//*****************************************************************************
390
#if defined(GROUP_charnonblockingget) || defined(BUILD_ALL) || defined(DOXYGEN)
391
long
392
UARTCharNonBlockingGet(unsigned long ulBase)
393
{
394
    //
395
    // Check the arguments.
396
    //
397
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
398
 
399
    //
400
    // See if there are any characters in the receive FIFO.
401
    //
402
    if(!(HWREG(ulBase + UART_O_FR) & UART_FR_RXFE))
403
    {
404
        //
405
        // Read and return the next character.
406
        //
407
        return(HWREG(ulBase + UART_O_DR));
408
    }
409
    else
410
    {
411
        //
412
        // There are no characters, so return a failure.
413
        //
414
        return(-1);
415
    }
416
}
417
#endif
418
 
419
//*****************************************************************************
420
//
421
//! Waits for a character from the specified port.
422
//!
423
//! \param ulBase is the base address of the UART port.
424
//!
425
//! Gets a character from the receive FIFO for the specified port.  If there
426
//! are no characters available, this function will wait until a character is
427
//! received before returning.
428
//!
429
//! \return Returns the character read from the specified port, cast as an
430
//! \e int.
431
//
432
//*****************************************************************************
433
#if defined(GROUP_charget) || defined(BUILD_ALL) || defined(DOXYGEN)
434
long
435
UARTCharGet(unsigned long ulBase)
436
{
437
    //
438
    // Check the arguments.
439
    //
440
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
441
 
442
    //
443
    // Wait until a char is available.
444
    //
445
    while(HWREG(ulBase + UART_O_FR) & UART_FR_RXFE)
446
    {
447
    }
448
 
449
    //
450
    // Now get the char.
451
    //
452
    return(HWREG(ulBase + UART_O_DR));
453
}
454
#endif
455
 
456
//*****************************************************************************
457
//
458
//! Sends a character to the specified port.
459
//!
460
//! \param ulBase is the base address of the UART port.
461
//! \param ucData is the character to be transmitted.
462
//!
463
//! Writes the character \e ucData to the transmit FIFO for the specified port.
464
//! This function does not block, so if there is no space available, then a
465
//! \b false is returned, and the application will have to retry the function
466
//! later.
467
//!
468
//! \return Returns \b true if the character was successfully placed in the
469
//! transmit FIFO, and \b false if there was no space available in the transmit
470
//! FIFO.
471
//
472
//*****************************************************************************
473
#if defined(GROUP_charnonblockingput) || defined(BUILD_ALL) || defined(DOXYGEN)
474
tBoolean
475
UARTCharNonBlockingPut(unsigned long ulBase, unsigned char ucData)
476
{
477
    //
478
    // Check the arguments.
479
    //
480
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
481
 
482
    //
483
    // See if there is space in the transmit FIFO.
484
    //
485
    if(!(HWREG(ulBase + UART_O_FR) & UART_FR_TXFF))
486
    {
487
        //
488
        // Write this character to the transmit FIFO.
489
        //
490
        HWREG(ulBase + UART_O_DR) = ucData;
491
 
492
        //
493
        // Success.
494
        //
495
        return(true);
496
    }
497
    else
498
    {
499
        //
500
        // There is no space in the transmit FIFO, so return a failure.
501
        //
502
        return(false);
503
    }
504
}
505
#endif
506
 
507
//*****************************************************************************
508
//
509
//! Waits to send a character from the specified port.
510
//!
511
//! \param ulBase is the base address of the UART port.
512
//! \param ucData is the character to be transmitted.
513
//!
514
//! Sends the character \e ucData to the transmit FIFO for the specified port.
515
//! If there is no space available in the transmit FIFO, this function will
516
//! wait until there is space available before returning.
517
//!
518
//! \return None.
519
//
520
//*****************************************************************************
521
#if defined(GROUP_charput) || defined(BUILD_ALL) || defined(DOXYGEN)
522
void
523
UARTCharPut(unsigned long ulBase, unsigned char ucData)
524
{
525
    //
526
    // Check the arguments.
527
    //
528
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
529
 
530
    //
531
    // Wait until space is available.
532
    //
533
    while(HWREG(ulBase + UART_O_FR) & UART_FR_TXFF)
534
    {
535
    }
536
 
537
    //
538
    // Send the char.
539
    //
540
    HWREG(ulBase + UART_O_DR) = ucData;
541
}
542
#endif
543
 
544
//*****************************************************************************
545
//
546
//! Causes a BREAK to be sent.
547
//!
548
//! \param ulBase is the base address of the UART port.
549
//! \param bBreakState controls the output level.
550
//!
551
//! Calling this function with \e bBreakState set to \b true will assert a
552
//! break condition on the UART.  Calling this function with \e bBreakState set
553
//! to \b false will remove the break condition.  For proper transmission of a
554
//! break command, the break must be asserted for at least two complete frames.
555
//!
556
//! \return None.
557
//
558
//*****************************************************************************
559
#if defined(GROUP_breakctl) || defined(BUILD_ALL) || defined(DOXYGEN)
560
void
561
UARTBreakCtl(unsigned long ulBase, tBoolean bBreakState)
562
{
563
    //
564
    // Check the arguments.
565
    //
566
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
567
 
568
    //
569
    // Set the break condition as requested.
570
    //
571
    HWREG(ulBase + UART_O_LCR_H) =
572
        (bBreakState ?
573
         (HWREG(ulBase + UART_O_LCR_H) | UART_LCR_H_BRK) :
574
         (HWREG(ulBase + UART_O_LCR_H) & ~(UART_LCR_H_BRK)));
575
}
576
#endif
577
 
578
//*****************************************************************************
579
//
580
//! Registers an interrupt handler for a UART interrupt.
581
//!
582
//! \param ulBase is the base address of the UART port.
583
//! \param pfnHandler is a pointer to the function to be called when the
584
//! UART interrupt occurs.
585
//!
586
//! This function does the actual registering of the interrupt handler.  This
587
//! will enable the global interrupt in the interrupt controller; specific UART
588
//! interrupts must be enabled via UARTIntEnable().  It is the interrupt
589
//! handler's responsibility to clear the interrupt source.
590
//!
591
//! \sa IntRegister() for important information about registering interrupt
592
//! handlers.
593
//!
594
//! \return None.
595
//
596
//*****************************************************************************
597
#if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)
598
void
599
UARTIntRegister(unsigned long ulBase, void (*pfnHandler)(void))
600
{
601
    unsigned long ulInt;
602
 
603
    //
604
    // Check the arguments.
605
    //
606
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
607
 
608
    //
609
    // Determine the interrupt number based on the UART port.
610
    //
611
    ulInt = (ulBase == UART0_BASE) ? INT_UART0 : INT_UART1;
612
 
613
    //
614
    // Register the interrupt handler.
615
    //
616
    IntRegister(ulInt, pfnHandler);
617
 
618
    //
619
    // Enable the UART interrupt.
620
    //
621
    IntEnable(ulInt);
622
}
623
#endif
624
 
625
//*****************************************************************************
626
//
627
//! Unregisters an interrupt handler for a UART interrupt.
628
//!
629
//! \param ulBase is the base address of the UART port.
630
//!
631
//! This function does the actual unregistering of the interrupt handler.  It
632
//! will clear the handler to be called when a UART interrupt occurs.  This
633
//! will also mask off the interrupt in the interrupt controller so that the
634
//! interrupt handler no longer is called.
635
//!
636
//! \sa IntRegister() for important information about registering interrupt
637
//! handlers.
638
//!
639
//! \return None.
640
//
641
//*****************************************************************************
642
#if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
643
void
644
UARTIntUnregister(unsigned long ulBase)
645
{
646
    unsigned long ulInt;
647
 
648
    //
649
    // Check the arguments.
650
    //
651
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
652
 
653
    //
654
    // Determine the interrupt number based on the UART port.
655
    //
656
    ulInt = (ulBase == UART0_BASE) ? INT_UART0 : INT_UART1;
657
 
658
    //
659
    // Disable the interrupt.
660
    //
661
    IntDisable(ulInt);
662
 
663
    //
664
    // Unregister the interrupt handler.
665
    //
666
    IntUnregister(ulInt);
667
}
668
#endif
669
 
670
//*****************************************************************************
671
//
672
//! Enables individual UART interrupt sources.
673
//!
674
//! \param ulBase is the base address of the UART port.
675
//! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
676
//!
677
//! Enables the indicated UART interrupt sources.  Only the sources that are
678
//! enabled can be reflected to the processor interrupt; disabled sources have
679
//! no effect on the processor.
680
//!
681
//! The parameter \e ulIntFlags is the logical OR of any of the following:
682
//!
683
//! - UART_INT_OE - Overrun Error interrupt
684
//! - UART_INT_BE - Break Error interrupt
685
//! - UART_INT_PE - Parity Error interrupt
686
//! - UART_INT_FE - Framing Error interrupt
687
//! - UART_INT_RT - Receive Timeout interrupt
688
//! - UART_INT_TX - Transmit interrupt
689
//! - UART_INT_RX - Receive interrupt
690
//!
691
//! \return None.
692
//
693
//*****************************************************************************
694
#if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)
695
void
696
UARTIntEnable(unsigned long ulBase, unsigned long ulIntFlags)
697
{
698
    //
699
    // Check the arguments.
700
    //
701
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
702
 
703
    //
704
    // Enable the specified interrupts.
705
    //
706
    HWREG(ulBase + UART_O_IM) |= ulIntFlags;
707
}
708
#endif
709
 
710
//*****************************************************************************
711
//
712
//! Disables individual UART interrupt sources.
713
//!
714
//! \param ulBase is the base address of the UART port.
715
//! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
716
//!
717
//! Disables the indicated UART interrupt sources.  Only the sources that are
718
//! enabled can be reflected to the processor interrupt; disabled sources have
719
//! no effect on the processor.
720
//!
721
//! The parameter \e ulIntFlags has the same definition as the same parameter
722
//! to UARTIntEnable().
723
//!
724
//! \return None.
725
//
726
//*****************************************************************************
727
#if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
728
void
729
UARTIntDisable(unsigned long ulBase, unsigned long ulIntFlags)
730
{
731
    //
732
    // Check the arguments.
733
    //
734
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
735
 
736
    //
737
    // Disable the specified interrupts.
738
    //
739
    HWREG(ulBase + UART_O_IM) &= ~(ulIntFlags);
740
}
741
#endif
742
 
743
//*****************************************************************************
744
//
745
//! Gets the current interrupt status.
746
//!
747
//! \param ulBase is the base address of the UART port.
748
//! \param bMasked is false if the raw interrupt status is required and true
749
//! if the masked interrupt status is required.
750
//!
751
//! This returns the interrupt status for the specified UART.  Either the raw
752
//! interrupt status or the status of interrupts that are allowed to reflect to
753
//! the processor can be returned.
754
//!
755
//! \return The current interrupt status, enumerated as a bit field of
756
//! values described in UARTIntEnable().
757
//
758
//*****************************************************************************
759
#if defined(GROUP_intstatus) || defined(BUILD_ALL) || defined(DOXYGEN)
760
unsigned long
761
UARTIntStatus(unsigned long ulBase, tBoolean bMasked)
762
{
763
    //
764
    // Check the arguments.
765
    //
766
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
767
 
768
    //
769
    // Return either the interrupt status or the raw interrupt status as
770
    // requested.
771
    //
772
    if(bMasked)
773
    {
774
        return(HWREG(ulBase + UART_O_MIS));
775
    }
776
    else
777
    {
778
        return(HWREG(ulBase + UART_O_RIS));
779
    }
780
}
781
#endif
782
 
783
//*****************************************************************************
784
//
785
//! Clears UART interrupt sources.
786
//!
787
//! \param ulBase is the base address of the UART port.
788
//! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
789
//!
790
//! The specified UART interrupt sources are cleared, so that they no longer
791
//! assert.  This must be done in the interrupt handler to keep it from being
792
//! called again immediately upon exit.
793
//!
794
//! The parameter \e ulIntFlags has the same definition as the same parameter
795
//! to UARTIntEnable().
796
//!
797
//! \return None.
798
//
799
//*****************************************************************************
800
#if defined(GROUP_intclear) || defined(BUILD_ALL) || defined(DOXYGEN)
801
void
802
UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags)
803
{
804
    //
805
    // Check the arguments.
806
    //
807
    ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE));
808
 
809
    //
810
    // Clear the requested interrupt sources.
811
    //
812
    HWREG(ulBase + UART_O_ICR) = ulIntFlags;
813
}
814
#endif
815
 
816
//*****************************************************************************
817
//
818
// Close the Doxygen group.
819
//! @}
820
//
821
//*****************************************************************************

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.