]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/uartlite_v3_0/src/xuartlite_sinit.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / uartlite_v3_0 / src / xuartlite_sinit.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2005 - 2014 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 xuartlite_sinit.c
36 *
37 * The implementation of the XUartLite component's static initialzation
38 * functionality.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who  Date     Changes
44 * ----- ---- -------- -----------------------------------------------
45 * 1.01a jvb  10/13/05 First release
46 * 2.00a ktn  10/20/09 Updated to use HAL Processor APIs.
47 * </pre>
48 *
49 *****************************************************************************/
50
51 /***************************** Include Files ********************************/
52
53 #include "xstatus.h"
54 #include "xparameters.h"
55 #include "xuartlite_i.h"
56
57 /************************** Constant Definitions ****************************/
58
59
60 /**************************** Type Definitions ******************************/
61
62
63 /***************** Macros (Inline Functions) Definitions ********************/
64
65
66 /************************** Variable Definitions ****************************/
67
68
69 /************************** Function Prototypes *****************************/
70
71 /****************************************************************************
72 *
73 * Looks up the device configuration based on the unique device ID.  The table
74 * UartliteConfigTable contains the configuration info for each device in the
75 * system.
76 *
77 * @param        DeviceId is the unique device ID to match on.
78 *
79 * @return       A pointer to the configuration data for the device, or
80 *               NULL if no match was found.
81 *
82 * @note         None.
83 *
84 ******************************************************************************/
85 XUartLite_Config *XUartLite_LookupConfig(u16 DeviceId)
86 {
87         XUartLite_Config *CfgPtr = NULL;
88         u32 Index;
89
90         for (Index=0; Index < XPAR_XUARTLITE_NUM_INSTANCES; Index++) {
91                 if (XUartLite_ConfigTable[Index].DeviceId == DeviceId) {
92                         CfgPtr = &XUartLite_ConfigTable[Index];
93                         break;
94                 }
95         }
96
97         return CfgPtr;
98 }
99
100 /****************************************************************************/
101 /**
102 *
103 * Initialize a XUartLite instance.  The receive and transmit FIFOs of the
104 * UART are not flushed, so the user may want to flush them. The hardware
105 * device does not have any way to disable the receiver such that any valid
106 * data may be present in the receive FIFO. This function disables the UART
107 * interrupt. The baudrate and format of the data are fixed in the hardware
108 * at hardware build time.
109 *
110 * @param        InstancePtr is a pointer to the XUartLite instance.
111 * @param        DeviceId is the unique id of the device controlled by this
112 *               XUartLite instance.  Passing in a device id associates the
113 *               generic XUartLite instance to a specific device, as chosen by
114 *               the caller or application developer.
115 *
116 * @return
117 *               - XST_SUCCESS if everything starts up as expected.
118 *               - XST_DEVICE_NOT_FOUND if the device is not found in the
119 *                       configuration table.
120 *
121 * @note         None.
122 *
123 *****************************************************************************/
124 int XUartLite_Initialize(XUartLite *InstancePtr, u16 DeviceId)
125 {
126         XUartLite_Config *ConfigPtr;
127
128         /*
129          * Assert validates the input arguments
130          */
131         Xil_AssertNonvoid(InstancePtr != NULL);
132
133         /*
134          * Lookup the device configuration in the configuration table. Use this
135          * configuration info when initializing this component.
136          */
137         ConfigPtr = XUartLite_LookupConfig(DeviceId);
138
139         if (ConfigPtr == (XUartLite_Config *)NULL) {
140                 return XST_DEVICE_NOT_FOUND;
141         }
142         return XUartLite_CfgInitialize(InstancePtr, ConfigPtr,
143                                         ConfigPtr->RegBaseAddr);
144 }
145