1 |
4 |
DFC |
/******************************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Copyright (C) 2005 - 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 xiic_sinit.c
|
36 |
|
|
* @addtogroup iic_v3_1
|
37 |
|
|
* @{
|
38 |
|
|
*
|
39 |
|
|
* The implementation of the Xiic component's static initialzation functionality.
|
40 |
|
|
*
|
41 |
|
|
* <pre>
|
42 |
|
|
* MODIFICATION HISTORY:
|
43 |
|
|
*
|
44 |
|
|
* Ver Who Date Changes
|
45 |
|
|
* ----- --- ------- -----------------------------------------------
|
46 |
|
|
* 1.02a jvb 10/13/05 release
|
47 |
|
|
* 1.13a wgr 03/22/07 Converted to new coding style.
|
48 |
|
|
* 2.00a ktn 10/22/09 Converted all register accesses to 32 bit access.
|
49 |
|
|
* Updated to use the HAL APIs/macros.
|
50 |
|
|
* Some of the macros have been renamed to remove _m from
|
51 |
|
|
* the name and some of the macros have been renamed to be
|
52 |
|
|
* consistent, see the xiic_i.h and xiic_l.h files for further
|
53 |
|
|
* information
|
54 |
|
|
* </pre>
|
55 |
|
|
*
|
56 |
|
|
****************************************************************************/
|
57 |
|
|
|
58 |
|
|
/***************************** Include Files *******************************/
|
59 |
|
|
|
60 |
|
|
#include "xstatus.h"
|
61 |
|
|
#include "xparameters.h"
|
62 |
|
|
#include "xiic_i.h"
|
63 |
|
|
|
64 |
|
|
/************************** Constant Definitions ***************************/
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
/**************************** Type Definitions *****************************/
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
/***************** Macros (Inline Functions) Definitions *******************/
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
/************************** Function Prototypes ****************************/
|
74 |
|
|
|
75 |
|
|
/************************** Variable Definitions **************************/
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
/*****************************************************************************/
|
79 |
|
|
/**
|
80 |
|
|
*
|
81 |
|
|
* Looks up the device configuration based on the unique device ID. The table
|
82 |
|
|
* IicConfigTable contains the configuration info for each device in the system.
|
83 |
|
|
*
|
84 |
|
|
* @param DeviceId is the unique device ID to look for
|
85 |
|
|
*
|
86 |
|
|
* @return A pointer to the configuration data of the device,
|
87 |
|
|
* or NULL if no match is found.
|
88 |
|
|
*
|
89 |
|
|
* @note None.
|
90 |
|
|
*
|
91 |
|
|
******************************************************************************/
|
92 |
|
|
XIic_Config *XIic_LookupConfig(u16 DeviceId)
|
93 |
|
|
{
|
94 |
|
|
XIic_Config *CfgPtr = NULL;
|
95 |
|
|
u32 Index;
|
96 |
|
|
|
97 |
|
|
for (Index = 0; Index < XPAR_XIIC_NUM_INSTANCES; Index++) {
|
98 |
|
|
if (XIic_ConfigTable[Index].DeviceId == DeviceId) {
|
99 |
|
|
CfgPtr = &XIic_ConfigTable[Index];
|
100 |
|
|
break;
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
return CfgPtr;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
/*****************************************************************************/
|
108 |
|
|
/**
|
109 |
|
|
*
|
110 |
|
|
* Initializes a specific XIic instance. The initialization entails:
|
111 |
|
|
*
|
112 |
|
|
* - Check the device has an entry in the configuration table.
|
113 |
|
|
* - Initialize the driver to allow access to the device registers and
|
114 |
|
|
* initialize other subcomponents necessary for the operation of the device.
|
115 |
|
|
* - Default options to:
|
116 |
|
|
* - 7-bit slave addressing
|
117 |
|
|
* - Send messages as a slave device
|
118 |
|
|
* - Repeated start off
|
119 |
|
|
* - General call recognition disabled
|
120 |
|
|
* - Clear messageing and error statistics
|
121 |
|
|
*
|
122 |
|
|
* The XIic_Start() function must be called after this function before the device
|
123 |
|
|
* is ready to send and receive data on the IIC bus.
|
124 |
|
|
*
|
125 |
|
|
* Before XIic_Start() is called, the interrupt control must connect the ISR
|
126 |
|
|
* routine to the interrupt handler. This is done by the user, and not
|
127 |
|
|
* XIic_Start() to allow the user to use an interrupt controller of their choice.
|
128 |
|
|
*
|
129 |
|
|
* @param InstancePtr is a pointer to the XIic instance to be worked on.
|
130 |
|
|
* @param DeviceId is the unique id of the device controlled by this XIic
|
131 |
|
|
* instance. Passing in a device id associates the generic XIic
|
132 |
|
|
* instance to a specific device, as chosen by the caller or
|
133 |
|
|
* application developer.
|
134 |
|
|
*
|
135 |
|
|
* @return
|
136 |
|
|
* - XST_SUCCESS when successful
|
137 |
|
|
* - XST_DEVICE_NOT_FOUND indicates the given device id isn't found
|
138 |
|
|
* - XST_DEVICE_IS_STARTED indicates the device is started
|
139 |
|
|
* (i.e. interrupts enabled and messaging is possible).
|
140 |
|
|
* Must stop before re-initialization is allowed.
|
141 |
|
|
*
|
142 |
|
|
* @note None.
|
143 |
|
|
*
|
144 |
|
|
****************************************************************************/
|
145 |
|
|
int XIic_Initialize(XIic *InstancePtr, u16 DeviceId)
|
146 |
|
|
{
|
147 |
|
|
XIic_Config *ConfigPtr; /* Pointer to configuration data */
|
148 |
|
|
|
149 |
|
|
/*
|
150 |
|
|
* Asserts test the validity of selected input arguments.
|
151 |
|
|
*/
|
152 |
|
|
Xil_AssertNonvoid(InstancePtr != NULL);
|
153 |
|
|
|
154 |
|
|
/*
|
155 |
|
|
* Lookup the device configuration in the temporary CROM table. Use this
|
156 |
|
|
* configuration info down below when initializing this component.
|
157 |
|
|
*/
|
158 |
|
|
ConfigPtr = XIic_LookupConfig(DeviceId);
|
159 |
|
|
if (ConfigPtr == NULL) {
|
160 |
|
|
return XST_DEVICE_NOT_FOUND;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
return XIic_CfgInitialize(InstancePtr, ConfigPtr,
|
164 |
|
|
ConfigPtr->BaseAddress);
|
165 |
|
|
}
|
166 |
|
|
/** @} */
|