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