1 |
4 |
DFC |
/******************************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Copyright (C) 2002 - 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_options.c
|
36 |
|
|
* @addtogroup iic_v3_1
|
37 |
|
|
* @{
|
38 |
|
|
*
|
39 |
|
|
* Contains options functions for the XIic component. This file is not required
|
40 |
|
|
* unless the functions in this file are called.
|
41 |
|
|
*
|
42 |
|
|
* <pre>
|
43 |
|
|
* MODIFICATION HISTORY:
|
44 |
|
|
*
|
45 |
|
|
* Ver Who Date Changes
|
46 |
|
|
* ----- --- ------- -----------------------------------------------
|
47 |
|
|
* 1.01b jhl 3/26/02 repartioned the driver
|
48 |
|
|
* 1.01c ecm 12/05/02 new rev
|
49 |
|
|
* 1.13a wgr 03/22/07 Converted to new coding style.
|
50 |
|
|
* 2.00a ktn 10/22/09 Converted all register accesses to 32 bit access.
|
51 |
|
|
* Updated to use the HAL APIs/macros.
|
52 |
|
|
* </pre>
|
53 |
|
|
*
|
54 |
|
|
****************************************************************************/
|
55 |
|
|
|
56 |
|
|
/***************************** Include Files *******************************/
|
57 |
|
|
|
58 |
|
|
#include "xiic.h"
|
59 |
|
|
#include "xiic_i.h"
|
60 |
|
|
|
61 |
|
|
/************************** Constant Definitions ***************************/
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
/**************************** Type Definitions *****************************/
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
/***************** Macros (Inline Functions) Definitions *******************/
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
/************************** Function Prototypes ****************************/
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
/************************** Variable Definitions **************************/
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
/*****************************************************************************/
|
77 |
|
|
/**
|
78 |
|
|
*
|
79 |
|
|
* This function sets the options for the IIC device driver. The options control
|
80 |
|
|
* how the device behaves relative to the IIC bus. If an option applies to
|
81 |
|
|
* how messages are sent or received on the IIC bus, it must be set prior to
|
82 |
|
|
* calling functions which send or receive data.
|
83 |
|
|
*
|
84 |
|
|
* To set multiple options, the values must be ORed together. To not change
|
85 |
|
|
* existing options, read/modify/write with the current options using
|
86 |
|
|
* XIic_GetOptions().
|
87 |
|
|
*
|
88 |
|
|
* <b>USAGE EXAMPLE:</b>
|
89 |
|
|
*
|
90 |
|
|
* Read/modify/write to enable repeated start:
|
91 |
|
|
* <pre>
|
92 |
|
|
* u8 Options;
|
93 |
|
|
* Options = XIic_GetOptions(&Iic);
|
94 |
|
|
* XIic_SetOptions(&Iic, Options | XII_REPEATED_START_OPTION);
|
95 |
|
|
* </pre>
|
96 |
|
|
*
|
97 |
|
|
* Disabling General Call:
|
98 |
|
|
* <pre>
|
99 |
|
|
* Options = XIic_GetOptions(&Iic);
|
100 |
|
|
* XIic_SetOptions(&Iic, Options &= ~XII_GENERAL_CALL_OPTION);
|
101 |
|
|
* </pre>
|
102 |
|
|
*
|
103 |
|
|
* @param InstancePtr is a pointer to the XIic instance to be worked on.
|
104 |
|
|
* @param NewOptions are the options to be set. See xiic.h for a list of
|
105 |
|
|
* the available options.
|
106 |
|
|
*
|
107 |
|
|
* @return None.
|
108 |
|
|
*
|
109 |
|
|
* @note
|
110 |
|
|
*
|
111 |
|
|
* Sending or receiving messages with repeated start enabled, and then
|
112 |
|
|
* disabling repeated start, will not take effect until another master
|
113 |
|
|
* transaction is completed. i.e. After using repeated start, the bus will
|
114 |
|
|
* continue to be throttled after repeated start is disabled until a master
|
115 |
|
|
* transaction occurs allowing the IIC to release the bus.
|
116 |
|
|
* <br><br>
|
117 |
|
|
* Options enabled will have a 1 in its appropriate bit position.
|
118 |
|
|
*
|
119 |
|
|
****************************************************************************/
|
120 |
|
|
void XIic_SetOptions(XIic *InstancePtr, u32 NewOptions)
|
121 |
|
|
{
|
122 |
|
|
u32 CntlReg;
|
123 |
|
|
|
124 |
|
|
Xil_AssertVoid(InstancePtr != NULL);
|
125 |
|
|
|
126 |
|
|
XIic_IntrGlobalDisable(InstancePtr->BaseAddress);
|
127 |
|
|
|
128 |
|
|
/*
|
129 |
|
|
* Update the options in the instance and get the contents of the
|
130 |
|
|
* control register such that the general call option can be modified.
|
131 |
|
|
*/
|
132 |
|
|
InstancePtr->Options = NewOptions;
|
133 |
|
|
CntlReg = XIic_ReadReg(InstancePtr->BaseAddress, XIIC_CR_REG_OFFSET);
|
134 |
|
|
|
135 |
|
|
/*
|
136 |
|
|
* The general call option is the only option that maps directly to
|
137 |
|
|
* a hardware register feature.
|
138 |
|
|
*/
|
139 |
|
|
if (NewOptions & XII_GENERAL_CALL_OPTION) {
|
140 |
|
|
CntlReg |= XIIC_CR_GENERAL_CALL_MASK;
|
141 |
|
|
} else {
|
142 |
|
|
CntlReg &= ~XIIC_CR_GENERAL_CALL_MASK;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
/*
|
146 |
|
|
* Write the new control register value to the register.
|
147 |
|
|
*/
|
148 |
|
|
XIic_WriteReg(InstancePtr->BaseAddress, XIIC_CR_REG_OFFSET, CntlReg);
|
149 |
|
|
|
150 |
|
|
XIic_IntrGlobalEnable(InstancePtr->BaseAddress);
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
/*****************************************************************************/
|
154 |
|
|
/**
|
155 |
|
|
*
|
156 |
|
|
* This function gets the current options for the IIC device. Options control
|
157 |
|
|
* the how the device behaves on the IIC bus. See SetOptions for more information
|
158 |
|
|
* on options.
|
159 |
|
|
*
|
160 |
|
|
* @param InstancePtr is a pointer to the XIic instance to be worked on.
|
161 |
|
|
*
|
162 |
|
|
* @return The options of the IIC device. See xiic.h for a list of
|
163 |
|
|
* available options.
|
164 |
|
|
*
|
165 |
|
|
* @note
|
166 |
|
|
*
|
167 |
|
|
* Options enabled will have a 1 in its appropriate bit position.
|
168 |
|
|
*
|
169 |
|
|
****************************************************************************/
|
170 |
|
|
u32 XIic_GetOptions(XIic *InstancePtr)
|
171 |
|
|
{
|
172 |
|
|
Xil_AssertNonvoid(InstancePtr != NULL);
|
173 |
|
|
|
174 |
|
|
return InstancePtr->Options;
|
175 |
|
|
}
|
176 |
|
|
/** @} */
|