]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/uartps_v3_0/src/xuartps.c
Add in the CORTEX_A53_64-bit_UltraScale_MPSoC demo application (a demo has been inclu...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / uartps_v3_0 / src / xuartps.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2015 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xuartps.c
36 *
37 * This file contains the implementation of the interface functions for XUartPs
38 * driver. Refer to the header file xuartps.h for more detailed information.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who    Date      Changes
44 * ----- ------ -------- ----------------------------------------------
45 * 1.00  drg/jz 01/13/10 First Release
46 * 2.2   hk     06/23/14 SW reset of RX and TX should be done when changing
47 *                       baud rate. CR# 804281.
48 * 3.00  kvn    02/13/15 Modified code for MISRA-C:2012 compliance.
49 * </pre>
50 *
51 *****************************************************************************/
52
53 /***************************** Include Files ********************************/
54
55 #include "xstatus.h"
56 #include "xuartps.h"
57 #include "xil_io.h"
58
59 /************************** Constant Definitions ****************************/
60
61 /* The following constant defines the amount of error that is allowed for
62  * a specified baud rate. This error is the difference between the actual
63  * baud rate that will be generated using the specified clock and the
64  * desired baud rate.
65  */
66 #define XUARTPS_MAX_BAUD_ERROR_RATE              3U     /* max % error allowed */
67
68 /**************************** Type Definitions ******************************/
69
70
71 /***************** Macros (Inline Functions) Definitions ********************/
72
73
74 /************************** Function Prototypes *****************************/
75
76 static void XUartPs_StubHandler(void *CallBackRef, u32 Event,
77                                  u32 ByteCount);
78
79 u32  XUartPs_SendBuffer(XUartPs *InstancePtr);
80
81 u32  XUartPs_ReceiveBuffer(XUartPs *InstancePtr);
82
83 /************************** Variable Definitions ****************************/
84
85 /****************************************************************************/
86 /**
87 *
88 * Initializes a specific XUartPs instance such that it is ready to be used.
89 * The data format of the device is setup for 8 data bits, 1 stop bit, and no
90 * parity by default. The baud rate is set to a default value specified by
91 * Config->DefaultBaudRate if set, otherwise it is set to 19.2K baud. The
92 * receive FIFO threshold is set for 8 bytes. The default operating mode of the
93 * driver is polled mode.
94 *
95 * @param        InstancePtr is a pointer to the XUartPs instance.
96 * @param        Config is a reference to a structure containing information
97 *               about a specific XUartPs driver.
98 * @param        EffectiveAddr is the device base address in the virtual memory
99 *               address space. The caller is responsible for keeping the address
100 *               mapping from EffectiveAddr to the device physical base address
101 *               unchanged once this function is invoked. Unexpected errors may
102 *               occur if the address mapping changes after this function is
103 *               called. If address translation is not used, pass in the physical
104 *               address instead.
105 *
106 * @return
107 *
108 *               - XST_SUCCESS if initialization was successful
109 *               - XST_UART_BAUD_ERROR if the baud rate is not possible because
110 *                 the inputclock frequency is not divisible with an acceptable
111 *                 amount of error
112 *
113 * @note
114 *
115 * The default configuration for the UART after initialization is:
116 *
117 * - 19,200 bps or XPAR_DFT_BAUDRATE if defined
118 * - 8 data bits
119 * - 1 stop bit
120 * - no parity
121 * - FIFO's are enabled with a receive threshold of 8 bytes
122 * - The RX timeout is enabled with a timeout of 1 (4 char times)
123 *
124 *   All interrupts are disabled.
125 *
126 *****************************************************************************/
127 s32 XUartPs_CfgInitialize(XUartPs *InstancePtr,
128                                    XUartPs_Config * Config, u32 EffectiveAddr)
129 {
130         s32 Status;
131         u32 ModeRegister;
132         u32 BaudRate;
133
134         /*
135          * Assert validates the input arguments
136          */
137         Xil_AssertNonvoid(InstancePtr != NULL);
138         Xil_AssertNonvoid(Config != NULL);
139
140         /*
141          * Setup the driver instance using passed in parameters
142          */
143         InstancePtr->Config.BaseAddress = EffectiveAddr;
144         InstancePtr->Config.InputClockHz = Config->InputClockHz;
145         InstancePtr->Config.ModemPinsConnected = Config->ModemPinsConnected;
146
147         /*
148          * Initialize other instance data to default values
149          */
150         InstancePtr->Handler = XUartPs_StubHandler;
151
152         InstancePtr->SendBuffer.NextBytePtr = NULL;
153         InstancePtr->SendBuffer.RemainingBytes = 0U;
154         InstancePtr->SendBuffer.RequestedBytes = 0U;
155
156         InstancePtr->ReceiveBuffer.NextBytePtr = NULL;
157         InstancePtr->ReceiveBuffer.RemainingBytes = 0U;
158         InstancePtr->ReceiveBuffer.RequestedBytes = 0U;
159
160         /*
161          * Flag that the driver instance is ready to use
162          */
163         InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
164
165         /*
166          * Set the default baud rate here, can be changed prior to
167          * starting the device
168          */
169         BaudRate = (u32)XUARTPS_DFT_BAUDRATE;
170         Status = XUartPs_SetBaudRate(InstancePtr, BaudRate);
171         if (Status != (s32)XST_SUCCESS) {
172                 InstancePtr->IsReady = 0U;
173         } else {
174
175                 /*
176                  * Set up the default data format: 8 bit data, 1 stop bit, no
177                  * parity
178                  */
179                 ModeRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
180                                           XUARTPS_MR_OFFSET);
181
182                 /*
183                  * Mask off what's already there
184                  */
185                 ModeRegister &= (~((u32)XUARTPS_MR_CHARLEN_MASK |
186                                                  (u32)XUARTPS_MR_STOPMODE_MASK |
187                                                  (u32)XUARTPS_MR_PARITY_MASK));
188
189                 /*
190                  * Set the register value to the desired data format
191                  */
192                 ModeRegister |= ((u32)XUARTPS_MR_CHARLEN_8_BIT |
193                                                  (u32)XUARTPS_MR_STOPMODE_1_BIT |
194                                                  (u32)XUARTPS_MR_PARITY_NONE);
195
196                 /*
197                  * Write the mode register out
198                  */
199                 XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_MR_OFFSET,
200                                    ModeRegister);
201
202                 /*
203                  * Set the RX FIFO trigger at 8 data bytes.
204                  */
205                 XUartPs_WriteReg(InstancePtr->Config.BaseAddress,
206                                    XUARTPS_RXWM_OFFSET, 0x08U);
207
208                 /*
209                  * Set the RX timeout to 1, which will be 4 character time
210                  */
211                 XUartPs_WriteReg(InstancePtr->Config.BaseAddress,
212                                    XUARTPS_RXTOUT_OFFSET, 0x01U);
213
214                 /*
215                  * Disable all interrupts, polled mode is the default
216                  */
217                 XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IDR_OFFSET,
218                                    XUARTPS_IXR_MASK);
219
220                 Status = XST_SUCCESS;
221         }
222         return Status;
223 }
224
225 /****************************************************************************/
226 /**
227 *
228 * This functions sends the specified buffer using the device in either
229 * polled or interrupt driven mode. This function is non-blocking, if the device
230 * is busy sending data, it will return and indicate zero bytes were sent.
231 * Otherwise, it fills the TX FIFO as much as it can, and return the number of
232 * bytes sent.
233 *
234 * In a polled mode, this function will only send as much data as TX FIFO can
235 * buffer. The application may need to call it repeatedly to send the entire
236 * buffer.
237 *
238 * In interrupt mode, this function will start sending the specified buffer,
239 * then the interrupt handler will continue sending data until the entire
240 * buffer has been sent. A callback function, as specified by the application,
241 * will be called to indicate the completion of sending.
242 *
243 * @param        InstancePtr is a pointer to the XUartPs instance.
244 * @param        BufferPtr is pointer to a buffer of data to be sent.
245 * @param        NumBytes contains the number of bytes to be sent. A value of
246 *               zero will stop a previous send operation that is in progress
247 *               in interrupt mode. Any data that was already put into the
248 *               transmit FIFO will be sent.
249 *
250 * @return       The number of bytes actually sent.
251 *
252 * @note
253 *
254 * The number of bytes is not asserted so that this function may be called with
255 * a value of zero to stop an operation that is already in progress.
256 * <br><br>
257 *
258 *****************************************************************************/
259 u32 XUartPs_Send(XUartPs *InstancePtr, u8 *BufferPtr,
260                            u32 NumBytes)
261 {
262         u32 BytesSent;
263
264         /*
265          * Asserts validate the input arguments
266          */
267         Xil_AssertNonvoid(InstancePtr != NULL);
268         Xil_AssertNonvoid(BufferPtr != NULL);
269         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
270
271         /*
272          * Disable the UART transmit interrupts to allow this call to stop a
273          * previous operation that may be interrupt driven.
274          */
275         XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IDR_OFFSET,
276                                           (XUARTPS_IXR_TXEMPTY | XUARTPS_IXR_TXFULL));
277
278         /*
279          * Setup the buffer parameters
280          */
281         InstancePtr->SendBuffer.RequestedBytes = NumBytes;
282         InstancePtr->SendBuffer.RemainingBytes = NumBytes;
283         InstancePtr->SendBuffer.NextBytePtr = BufferPtr;
284
285         /*
286          * Transmit interrupts will be enabled in XUartPs_SendBuffer(), after
287          * filling the TX FIFO.
288          */
289         BytesSent = XUartPs_SendBuffer(InstancePtr);
290
291         return BytesSent;
292 }
293
294 /****************************************************************************/
295 /**
296 *
297 * This function attempts to receive a specified number of bytes of data
298 * from the device and store it into the specified buffer. This function works
299 * for both polled or interrupt driven modes. It is non-blocking.
300 *
301 * In a polled mode, this function will only receive the data already in the
302 * RX FIFO. The application may need to call it repeatedly to receive the
303 * entire buffer. Polled mode is the default mode of operation for the device.
304 *
305 * In interrupt mode, this function will start the receiving, if not the entire
306 * buffer has been received, the interrupt handler will continue receiving data
307 * until the entire buffer has been received. A callback function, as specified
308 * by the application, will be called to indicate the completion of the
309 * receiving or error conditions.
310 *
311 * @param        InstancePtr is a pointer to the XUartPs instance
312 * @param        BufferPtr is pointer to buffer for data to be received into
313 * @param        NumBytes is the number of bytes to be received. A value of zero
314 *               will stop a previous receive operation that is in progress in
315 *               interrupt mode.
316 *
317 * @return       The number of bytes received.
318 *
319 * @note
320 *
321 * The number of bytes is not asserted so that this function may be called
322 * with a value of zero to stop an operation that is already in progress.
323 *
324 *****************************************************************************/
325 u32 XUartPs_Recv(XUartPs *InstancePtr,
326                           u8 *BufferPtr, u32 NumBytes)
327 {
328         u32 ReceivedCount;
329         u32 ImrRegister;
330
331         /*
332          * Assert validates the input arguments
333          */
334         Xil_AssertNonvoid(InstancePtr != NULL);
335         Xil_AssertNonvoid(BufferPtr != NULL);
336         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
337
338         /*
339          * Disable all the interrupts.
340          * This stops a previous operation that may be interrupt driven
341          */
342         ImrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
343                                   XUARTPS_IMR_OFFSET);
344         XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IDR_OFFSET,
345                 XUARTPS_IXR_MASK);
346
347         /*
348          * Setup the buffer parameters
349          */
350         InstancePtr->ReceiveBuffer.RequestedBytes = NumBytes;
351         InstancePtr->ReceiveBuffer.RemainingBytes = NumBytes;
352         InstancePtr->ReceiveBuffer.NextBytePtr = BufferPtr;
353
354         /*
355          * Receive the data from the device
356          */
357         ReceivedCount = XUartPs_ReceiveBuffer(InstancePtr);
358
359         /*
360          * Restore the interrupt state
361          */
362         XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_IER_OFFSET,
363                 ImrRegister);
364
365         return ReceivedCount;
366 }
367
368 /****************************************************************************/
369 /*
370 *
371 * This function sends a buffer that has been previously specified by setting
372 * up the instance variables of the instance. This function is an internal
373 * function for the XUartPs driver such that it may be called from a shell
374 * function that sets up the buffer or from an interrupt handler.
375 *
376 * This function sends the specified buffer in either polled or interrupt
377 * driven modes. This function is non-blocking.
378 *
379 * In a polled mode, this function only sends as much data as the TX FIFO
380 * can buffer. The application may need to call it repeatedly to send the
381 * entire buffer.
382 *
383 * In interrupt mode, this function starts the sending of the buffer, if not
384 * the entire buffer has been sent, then the interrupt handler continues the
385 * sending until the entire buffer has been sent. A callback function, as
386 * specified by the application, will be called to indicate the completion of
387 * sending.
388 *
389 * @param        InstancePtr is a pointer to the XUartPs instance
390 *
391 * @return       The number of bytes actually sent
392 *
393 * @note         None.
394 *
395 *****************************************************************************/
396 u32 XUartPs_SendBuffer(XUartPs *InstancePtr)
397 {
398         u32 SentCount = 0U;
399         u32 ImrRegister;
400
401         /*
402          * If the TX FIFO is full, send nothing.
403          * Otherwise put bytes into the TX FIFO unil it is full, or all of the
404          * data has been put into the FIFO.
405          */
406         while ((!XUartPs_IsTransmitFull(InstancePtr->Config.BaseAddress)) &&
407                    (InstancePtr->SendBuffer.RemainingBytes > SentCount)) {
408
409                 /*
410                  * Fill the FIFO from the buffer
411                  */
412                 XUartPs_WriteReg(InstancePtr->Config.BaseAddress,
413                                    XUARTPS_FIFO_OFFSET,
414                                    ((u32)InstancePtr->SendBuffer.
415                                    NextBytePtr[SentCount]));
416
417                 /*
418                  * Increment the send count.
419                  */
420                 SentCount++;
421         }
422
423         /*
424          * Update the buffer to reflect the bytes that were sent from it
425          */
426         InstancePtr->SendBuffer.NextBytePtr += SentCount;
427         InstancePtr->SendBuffer.RemainingBytes -= SentCount;
428
429         /*
430          * If interrupts are enabled as indicated by the receive interrupt, then
431          * enable the TX FIFO empty interrupt, so further action can be taken
432          * for this sending.
433          */
434         ImrRegister =
435                 XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
436                                   XUARTPS_IMR_OFFSET);
437         if (((ImrRegister & XUARTPS_IXR_RXFULL) != (u32)0) ||
438                 ((ImrRegister & XUARTPS_IXR_RXEMPTY) != (u32)0)||
439                 ((ImrRegister & XUARTPS_IXR_RXOVR) != (u32)0)) {
440
441                 XUartPs_WriteReg(InstancePtr->Config.BaseAddress,
442                                            XUARTPS_IER_OFFSET,
443                                            ImrRegister | (u32)XUARTPS_IXR_TXEMPTY);
444         }
445
446         return SentCount;
447 }
448
449 /****************************************************************************/
450 /*
451 *
452 * This function receives a buffer that has been previously specified by setting
453 * up the instance variables of the instance. This function is an internal
454 * function, and it may be called from a shell function that sets up the buffer
455 * or from an interrupt handler.
456 *
457 * This function attempts to receive a specified number of bytes from the
458 * device and store it into the specified buffer. This function works for
459 * either polled or interrupt driven modes. It is non-blocking.
460 *
461 * In polled mode, this function only receives as much data as in the RX FIFO.
462 * The application may need to call it repeatedly to receive the entire buffer.
463 * Polled mode is the default mode for the driver.
464 *
465 * In interrupt mode, this function starts the receiving, if not the entire
466 * buffer has been received, the interrupt handler will continue until the
467 * entire buffer has been received. A callback function, as specified by the
468 * application, will be called to indicate the completion of the receiving or
469 * error conditions.
470 *
471 * @param        InstancePtr is a pointer to the XUartPs instance
472 *
473 * @return       The number of bytes received.
474 *
475 * @note         None.
476 *
477 *****************************************************************************/
478 u32 XUartPs_ReceiveBuffer(XUartPs *InstancePtr)
479 {
480         u32 CsrRegister;
481         u32 ReceivedCount = 0U;
482
483         /*
484          * Read the Channel Status Register to determine if there is any data in
485          * the RX FIFO
486          */
487         CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
488                                 XUARTPS_SR_OFFSET);
489
490         /*
491          * Loop until there is no more data in RX FIFO or the specified
492          * number of bytes has been received
493          */
494         while((ReceivedCount < InstancePtr->ReceiveBuffer.RemainingBytes)&&
495                 (((CsrRegister & XUARTPS_SR_RXEMPTY) == (u32)0))){
496
497                 InstancePtr->ReceiveBuffer.NextBytePtr[ReceivedCount] =
498                         XUartPs_ReadReg(InstancePtr->Config.
499                                   BaseAddress,
500                                   XUARTPS_FIFO_OFFSET);
501
502                 ReceivedCount++;
503
504                 CsrRegister = XUartPs_ReadReg(InstancePtr->Config.BaseAddress,
505                                                                 XUARTPS_SR_OFFSET);
506         }
507
508         /*
509          * Update the receive buffer to reflect the number of bytes just
510          * received
511          */
512         if(InstancePtr->ReceiveBuffer.NextBytePtr != NULL){
513                 InstancePtr->ReceiveBuffer.NextBytePtr += ReceivedCount;
514         }
515         InstancePtr->ReceiveBuffer.RemainingBytes -= ReceivedCount;
516
517         return ReceivedCount;
518 }
519
520 /*****************************************************************************/
521 /**
522 *
523 * Sets the baud rate for the device. Checks the input value for
524 * validity and also verifies that the requested rate can be configured to
525 * within the maximum error range specified by XUARTPS_MAX_BAUD_ERROR_RATE.
526 * If the provided rate is not possible, the current setting is unchanged.
527 *
528 * @param        InstancePtr is a pointer to the XUartPs instance
529 * @param        BaudRate to be set
530 *
531 * @return
532 *               - XST_SUCCESS if everything configured as expected
533 *               - XST_UART_BAUD_ERROR if the requested rate is not available
534 *                 because there was too much error
535 *
536 * @note         None.
537 *
538 *****************************************************************************/
539 s32 XUartPs_SetBaudRate(XUartPs *InstancePtr, u32 BaudRate)
540 {
541         u32 IterBAUDDIV;        /* Iterator for available baud divisor values */
542         u32 BRGR_Value;         /* Calculated value for baud rate generator */
543         u32 CalcBaudRate;       /* Calculated baud rate */
544         u32 BaudError;          /* Diff between calculated and requested baud rate */
545         u32 Best_BRGR = 0U;     /* Best value for baud rate generator */
546         u8 Best_BAUDDIV = 0U;   /* Best value for baud divisor */
547         u32 Best_Error = 0xFFFFFFFFU;
548         u32 PercentError;
549         u32 ModeReg;
550         u32 InputClk;
551
552         /*
553          * Asserts validate the input arguments
554          */
555         Xil_AssertNonvoid(InstancePtr != NULL);
556         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
557         Xil_AssertNonvoid(BaudRate <= (u32)XUARTPS_MAX_RATE);
558         Xil_AssertNonvoid(BaudRate >= (u32)XUARTPS_MIN_RATE);
559
560         /*
561          * Make sure the baud rate is not impossilby large.
562          * Fastest possible baud rate is Input Clock / 2.
563          */
564         if ((BaudRate * 2) > InstancePtr->Config.InputClockHz) {
565                 return XST_UART_BAUD_ERROR;
566         }
567         /*
568          * Check whether the input clock is divided by 8
569          */
570         ModeReg = XUartPs_ReadReg( InstancePtr->Config.BaseAddress,
571                                  XUARTPS_MR_OFFSET);
572
573         InputClk = InstancePtr->Config.InputClockHz;
574         if(ModeReg & XUARTPS_MR_CLKSEL) {
575                 InputClk = InstancePtr->Config.InputClockHz / 8;
576         }
577
578         /*
579          * Determine the Baud divider. It can be 4to 254.
580          * Loop through all possible combinations
581          */
582         for (IterBAUDDIV = 4; IterBAUDDIV < 255; IterBAUDDIV++) {
583
584                 /*
585                  * Calculate the value for BRGR register
586                  */
587                 BRGR_Value = InputClk / (BaudRate * (IterBAUDDIV + 1));
588
589                 /*
590                  * Calculate the baud rate from the BRGR value
591                  */
592                 CalcBaudRate = InputClk/ (BRGR_Value * (IterBAUDDIV + 1));
593
594                 /*
595                  * Avoid unsigned integer underflow
596                  */
597                 if (BaudRate > CalcBaudRate) {
598                         BaudError = BaudRate - CalcBaudRate;
599                 }
600                 else {
601                         BaudError = CalcBaudRate - BaudRate;
602                 }
603
604                 /*
605                  * Find the calculated baud rate closest to requested baud rate.
606                  */
607                 if (Best_Error > BaudError) {
608
609                         Best_BRGR = BRGR_Value;
610                         Best_BAUDDIV = IterBAUDDIV;
611                         Best_Error = BaudError;
612                 }
613         }
614
615         /*
616          * Make sure the best error is not too large.
617          */
618         PercentError = (Best_Error * 100) / BaudRate;
619         if (XUARTPS_MAX_BAUD_ERROR_RATE < PercentError) {
620                 return XST_UART_BAUD_ERROR;
621         }
622
623         /*
624          * Disable TX and RX to avoid glitches when setting the baud rate.
625          */
626         XUartPs_DisableUart(InstancePtr);
627
628         XUartPs_WriteReg(InstancePtr->Config.BaseAddress,
629                            XUARTPS_BAUDGEN_OFFSET, Best_BRGR);
630         XUartPs_WriteReg(InstancePtr->Config.BaseAddress,
631                            XUARTPS_BAUDDIV_OFFSET, Best_BAUDDIV);
632
633         /*
634          * RX and TX SW reset
635          */
636         XUartPs_WriteReg(InstancePtr->Config.BaseAddress, XUARTPS_CR_OFFSET,
637                                 XUARTPS_CR_TXRST | XUARTPS_CR_RXRST);
638
639         /*
640          * Enable device
641          */
642         XUartPs_EnableUart(InstancePtr);
643
644         InstancePtr->BaudRate = BaudRate;
645
646         return XST_SUCCESS;
647
648 }
649
650 /****************************************************************************/
651 /**
652 *
653 * This function is a stub handler that is the default handler such that if the
654 * application has not set the handler when interrupts are enabled, this
655 * function will be called.
656 *
657 * @param        CallBackRef is unused by this function.
658 * @param        Event is unused by this function.
659 * @param        ByteCount is unused by this function.
660 *
661 * @return       None.
662 *
663 * @note         None.
664 *
665 *****************************************************************************/
666 static void XUartPs_StubHandler(void *CallBackRef, u32 Event,
667                                  u32 ByteCount)
668 {
669         (void *) CallBackRef;
670         (void) Event;
671         (void) ByteCount;
672         /*
673          * Assert occurs always since this is a stub and should never be called
674          */
675         Xil_AssertVoidAlways();
676 }