OpenCores
URL https://opencores.org/ocsvn/xenie/xenie/trunk

Subversion Repositories xenie

[/] [xenie/] [trunk/] [examples/] [Eth_example/] [mb_fw/] [drivers/] [iic_v3_4/] [src/] [xiic.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 DFC
/******************************************************************************
2
*
3
* Copyright (C) 2002 - 2016 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.c
36
* @addtogroup iic_v3_1
37
* @{
38
*
39
* Contains required functions for the XIic component. See xiic.h for more
40
* information on the driver.
41
*
42
* <pre>
43
* MODIFICATION HISTORY:
44
*
45
* Ver   Who  Date     Changes
46
* ----- --- ------- -----------------------------------------------
47
* 1.01a rfp  10/19/01 release
48
* 1.01c ecm  12/05/02 new rev
49
* 1.01c rmm  05/14/03 Fixed diab compiler warnings relating to asserts.
50
* 1.01d jhl  10/08/03 Added general purpose output feature
51
* 1.02a jvb  12/13/05 Added CfgInitialize(), and made CfgInitialize() take
52
*                     a pointer to a config structure instead of a device id.
53
*                     Moved Initialize() into xiic_sinit.c, and have
54
*                     Initialize() call CfgInitialize() after it retrieved the
55
*                     config structure using the device id. Removed include of
56
*                     xparameters.h along with any dependencies on xparameters.h
57
*                     and the _g.c config table.
58
* 1.02a mta  03/09/06 Added a new function XIic_IsIicBusy() which returns
59
*                       whether IIC Bus is Busy or Free.
60
* 1.13a wgr  03/22/07 Converted to new coding style.
61
* 1.15a ktn  02/17/09 Fixed XIic_GetAddress() to return correct device address.
62
* 1.16a ktn  07/18/09 Updated the notes in XIic_Reset function to clearly
63
*                     indicate that only the Interrupt Registers are reset.
64
* 1.16a ktn  10/16/09 Updated the notes in the XIic_SelfTest() API to mention
65
*                     that the complete IIC core is Reset on giving a software
66
*                     reset to the IIC core. This issue is fixed in the latest
67
*                     version of the IIC core (some previous versions of the
68
*                     core only reset the Interrupt Logic/Registers), please
69
*                     see the Hw specification for further information.
70
* 2.00a ktn  10/22/09 Converted all register accesses to 32 bit access.
71
*                     Some of the macros have been renamed to remove _m from
72
*                     the name see the xiic_i.h and xiic_l.h file for further
73
*                     information (Example XIic_mClearIntr is now
74
*                     XIic_ClearIntr).
75
*                     Some of the macros have been renamed to be consistent,
76
*                     see the xiic_l.h file for further information
77
*                     (Example XIIC_WRITE_IIER is renamed as XIic_WriteIier).
78
*                     The driver has been updated to use the HAL APIs/macros.
79
* 2.07a adk   18/04/13 Updated the code to avoid unused variable warnings
80
*                         when compiling with the -Wextra -Wall flags.
81
*                         Changes done if files xiic.c and xiic_i.h. CR:705001.
82
* 3.2   sk   11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
83
*                     Changed the prototype of XIic_CfgInitialize API.
84
* 3.3   als  06/27/16 XIic_IsIicBusy now static inline in xiic.h.
85
* </pre>
86
*
87
****************************************************************************/
88
 
89
/***************************** Include Files *******************************/
90
 
91
#include "xiic.h"
92
#include "xiic_i.h"
93
 
94
/************************** Constant Definitions ***************************/
95
 
96
 
97
/**************************** Type Definitions *****************************/
98
 
99
 
100
/***************** Macros (Inline Functions) Definitions *******************/
101
 
102
 
103
/************************** Function Prototypes ****************************/
104
 
105
static void XIic_StubStatusHandler(void *CallBackRef, int ErrorCode);
106
 
107
static void XIic_StubHandler(void *CallBackRef, int ByteCount);
108
 
109
/************************** Variable Definitions **************************/
110
 
111
 
112
/*****************************************************************************/
113
/**
114
*
115
* Initializes a specific XIic instance.  The initialization entails:
116
*
117
* - Initialize the driver to allow access to the device registers and
118
*   initialize other subcomponents necessary for the operation of the device.
119
* - Default options to:
120
*        - 7-bit slave addressing
121
*        - Send messages as a slave device
122
*        - Repeated start off
123
*        - General call recognition disabled
124
* - Clear messageing and error statistics
125
*
126
* The XIic_Start() function must be called after this function before the device
127
* is ready to send and receive data on the IIC bus.
128
*
129
* Before XIic_Start() is called, the interrupt control must connect the ISR
130
* routine to the interrupt handler. This is done by the user, and not
131
* XIic_Start() to allow the user to use an interrupt controller of their choice.
132
*
133
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
134
* @param        Config is a reference to a structure containing information
135
*               about a specific IIC device. This function can initialize
136
*               multiple instance objects with the use of multiple calls giving
137
*               different Config information on each call.
138
* @param        EffectiveAddr is the device base address in the virtual memory
139
*               address space. The caller is responsible for keeping the
140
*               address mapping from EffectiveAddr to the device physical base
141
*               address unchanged once this function is invoked. Unexpected
142
*               errors may occur if the address mapping changes after this
143
*               function is called. If address translation is not used, use
144
*               Config->BaseAddress for this parameters, passing the physical
145
*               address instead.
146
*
147
* @return
148
*               - XST_SUCCESS when successful
149
*               - XST_DEVICE_IS_STARTED indicates the device is started
150
*               (i.e. interrupts enabled and messaging is possible). Must stop
151
*               before re-initialization is allowed.
152
*
153
* @note         None.
154
*
155
****************************************************************************/
156
int XIic_CfgInitialize(XIic *InstancePtr, XIic_Config * Config,
157
                           UINTPTR EffectiveAddr)
158
{
159
        /*
160
         * Asserts test the validity of selected input arguments.
161
         */
162
        Xil_AssertNonvoid(InstancePtr != NULL);
163
 
164
        InstancePtr->IsReady = 0;
165
 
166
        /*
167
         * If the device is started, disallow the initialize and return a Status
168
         * indicating it is started.  This allows the user to stop the device
169
         * and reinitialize, but prevents a user from inadvertently
170
         * initializing.
171
         */
172
        if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {
173
                return XST_DEVICE_IS_STARTED;
174
        }
175
 
176
        /*
177
         * Set default values and configuration data, including setting the
178
         * callback handlers to stubs  so the system will not crash should the
179
         * application not assign its own callbacks.
180
         */
181
        InstancePtr->IsStarted = 0;
182
        InstancePtr->BaseAddress = EffectiveAddr;
183
        InstancePtr->RecvHandler = XIic_StubHandler;
184
        InstancePtr->RecvBufferPtr = NULL;
185
        InstancePtr->SendHandler = XIic_StubHandler;
186
        InstancePtr->SendBufferPtr = NULL;
187
        InstancePtr->StatusHandler = XIic_StubStatusHandler;
188
        InstancePtr->Has10BitAddr = Config->Has10BitAddr;
189
        InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
190
        InstancePtr->Options = 0;
191
        InstancePtr->BNBOnly = FALSE;
192
        InstancePtr->GpOutWidth = Config->GpOutWidth;
193
        InstancePtr->IsDynamic = FALSE;
194
        InstancePtr->IsSlaveSetAckOff = FALSE;
195
 
196
        /*
197
         * Reset the device.
198
         */
199
        XIic_Reset(InstancePtr);
200
 
201
        XIic_ClearStats(InstancePtr);
202
 
203
        return XST_SUCCESS;
204
}
205
 
206
/*****************************************************************************/
207
/**
208
*
209
* This function starts the IIC device and driver by enabling the proper
210
* interrupts such that data may be sent and received on the IIC bus.
211
* This function must be called before the functions to send and receive data.
212
*
213
* Before XIic_Start() is called, the interrupt control must connect the ISR
214
* routine to the interrupt handler. This is done by the user, and not
215
* XIic_Start() to allow the user to use an interrupt controller of their choice.
216
*
217
* Start enables:
218
*  - IIC device
219
*  - Interrupts:
220
*        - Addressed as slave to allow messages from another master
221
*        - Arbitration Lost to detect Tx arbitration errors
222
*        - Global IIC interrupt
223
*
224
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
225
*
226
* @return       XST_SUCCESS always.
227
*
228
* @note
229
*
230
* The device interrupt is connected to the interrupt controller, but no
231
* "messaging" interrupts are enabled. Addressed as Slave is enabled to
232
* reception of messages when this devices address is written to the bus.
233
* The correct messaging interrupts are enabled when sending or receiving
234
* via the IicSend() and IicRecv() functions. No action is required
235
* by the user to control any IIC interrupts as the driver completely
236
* manages all 8 interrupts. Start and Stop control the ability
237
* to use the device. Stopping the device completely stops all device
238
* interrupts from the processor.
239
*
240
****************************************************************************/
241
int XIic_Start(XIic *InstancePtr)
242
{
243
        Xil_AssertNonvoid(InstancePtr != NULL);
244
        Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
245
 
246
        /*
247
         * Mask off all interrupts, each is enabled when needed.
248
         */
249
        XIic_WriteIier(InstancePtr->BaseAddress, 0);
250
 
251
        /*
252
         * Clear all interrupts by reading and rewriting exact value back.
253
         * Only those bits set will get written as 1 (writing 1 clears intr).
254
         */
255
        XIic_ClearIntr(InstancePtr->BaseAddress, 0xFFFFFFFF);
256
 
257
        /*
258
         * Enable the device.
259
         */
260
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_CR_REG_OFFSET,
261
                 XIIC_CR_ENABLE_DEVICE_MASK);
262
        /*
263
         * Set Rx FIFO Occupancy depth to throttle at
264
         * first byte(after reset = 0).
265
         */
266
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_RFD_REG_OFFSET, 0);
267
 
268
        /*
269
         * Clear and enable the interrupts needed.
270
         */
271
        XIic_ClearEnableIntr(InstancePtr->BaseAddress,
272
                                XIIC_INTR_AAS_MASK | XIIC_INTR_ARB_LOST_MASK);
273
 
274
        InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
275
        InstancePtr->IsDynamic = FALSE;
276
 
277
        /*
278
         * Enable the Global interrupt enable.
279
         */
280
        XIic_IntrGlobalEnable(InstancePtr->BaseAddress);
281
 
282
        return XST_SUCCESS;
283
}
284
 
285
/*****************************************************************************/
286
/**
287
*
288
* This function stops the IIC device and driver such that data is no longer
289
* sent or received on the IIC bus. This function stops the device by
290
* disabling interrupts. This function only disables interrupts within the
291
* device such that the caller is responsible for disconnecting the interrupt
292
* handler of the device from the interrupt source and disabling interrupts
293
* at other levels.
294
*
295
* Due to bus throttling that could hold the bus between messages when using
296
* repeated start option, stop will not occur when the device is actively
297
* sending or receiving data from the IIC bus or the bus is being throttled
298
* by this device, but instead return XST_IIC_BUS_BUSY.
299
*
300
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
301
*
302
* @return
303
*               - XST_SUCCESS indicates all IIC interrupts are disabled.
304
*               No messages can be received or transmitted until XIic_Start()
305
*               is called.
306
*               - XST_IIC_BUS_BUSY indicates this device is currently engaged
307
*               in message traffic and cannot be stopped.
308
*
309
* @note         None.
310
*
311
****************************************************************************/
312
int XIic_Stop(XIic *InstancePtr)
313
{
314
        u32 Status;
315
        u32 CntlReg;
316
 
317
        Xil_AssertNonvoid(InstancePtr != NULL);
318
 
319
        /*
320
         * Disable all interrupts globally.
321
         */
322
        XIic_IntrGlobalDisable(InstancePtr->BaseAddress);
323
 
324
        CntlReg = XIic_ReadReg(InstancePtr->BaseAddress, XIIC_CR_REG_OFFSET);
325
        Status = XIic_ReadReg(InstancePtr->BaseAddress, XIIC_SR_REG_OFFSET);
326
 
327
        if ((CntlReg & XIIC_CR_MSMS_MASK) ||
328
                (Status & XIIC_SR_ADDR_AS_SLAVE_MASK)) {
329
                /*
330
                 * When this device is using the bus
331
                 * - re-enable interrupts to finish current messaging
332
                 * - return bus busy
333
                 */
334
                XIic_IntrGlobalEnable(InstancePtr->BaseAddress);
335
 
336
                return XST_IIC_BUS_BUSY;
337
        }
338
 
339
        InstancePtr->IsStarted = 0;
340
 
341
        return XST_SUCCESS;
342
}
343
 
344
/*****************************************************************************/
345
/**
346
*
347
* Resets the IIC device.
348
*
349
* @param    InstancePtr is a pointer to the XIic instance to be worked on.
350
*
351
* @return       None.
352
*
353
* @note     The complete IIC core is Reset on giving a software reset to
354
*           the IIC core. Some previous versions of the core only reset
355
*           the Interrupt Logic/Registers, please refer to the HW specification
356
*           for futher details about this.
357
*
358
****************************************************************************/
359
void XIic_Reset(XIic *InstancePtr)
360
{
361
        Xil_AssertVoid(InstancePtr != NULL);
362
        Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
363
 
364
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_RESETR_OFFSET,
365
                        XIIC_RESET_MASK);
366
}
367
 
368
/*****************************************************************************/
369
/**
370
*
371
* This function sets the bus addresses. The addresses include the device
372
* address that the device responds to as a slave, or the slave address
373
* to communicate with on the bus.  The IIC device hardware is built to
374
* allow either 7 or 10 bit slave addressing only at build time rather
375
* than at run time. When this device is a master, slave addressing can
376
* be selected at run time to match addressing modes for other bus devices.
377
*
378
* Addresses are represented as hex values with no adjustment for the data
379
* direction bit as the software manages address bit placement.
380
* Example: For a 7 address written to the device of 1010 011X where X is
381
* the transfer direction (send/recv), the address parameter for this function
382
* needs to be 01010011 or 0x53 where the correct bit alllignment will be
383
* handled for 7 as well as 10 bit devices. This is especially important as
384
* the bit placement is not handled the same depending on which options are
385
* used such as repeated start.
386
*
387
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
388
* @param        AddressType indicates which address is being modified, the
389
*               address which this device responds to on the IIC bus as a slave,
390
*               or the slave address to communicate with when this device is a
391
*               master. One of the following values must be contained in
392
*               this argument.
393
* <pre>
394
*   XII_ADDR_TO_SEND_TYPE       Slave being addressed by a this master
395
*   XII_ADDR_TO_RESPOND_TYPE    Address to respond to as a slave device
396
* </pre>
397
*
398
* @param        Address contains the address to be set, 7 bit or 10 bit address.
399
*               A ten bit address must be within the range: 0 - 1023 and a 7 bit
400
*               address must be within the range 0 - 127.
401
*
402
* @return
403
*               - XST_SUCCESS is returned if the address was successfully set.
404
*               - XST_IIC_NO_10_BIT_ADDRESSING indicates only 7 bit addressing
405
*                 supported.
406
*               - XST_INVALID_PARAM indicates an invalid parameter was
407
*                 specified.
408
*
409
* @note
410
*
411
* Upper bits of 10-bit address is written only when current device is built
412
* as a ten bit device.
413
*
414
****************************************************************************/
415
int XIic_SetAddress(XIic *InstancePtr, int AddressType, int Address)
416
{
417
        u32 SendAddr;
418
 
419
        Xil_AssertNonvoid(InstancePtr != NULL);
420
        Xil_AssertNonvoid(Address < 1023);
421
 
422
        /*
423
         * Set address to respond to for this device into address registers.
424
         */
425
        if (AddressType == XII_ADDR_TO_RESPOND_TYPE) {
426
                /*
427
                 * Address in upper 7 bits.
428
                 */
429
                SendAddr = ((Address & 0x007F) << 1);
430
                XIic_WriteReg(InstancePtr->BaseAddress, XIIC_ADR_REG_OFFSET,
431
                                SendAddr);
432
 
433
                if (InstancePtr->Has10BitAddr == TRUE) {
434
                        /*
435
                         * Write upper 3 bits of addr to DTR only when 10 bit
436
                         * option included in design i.e. register exists.
437
                         */
438
                        SendAddr = ((Address & 0x0380) >> 7);
439
                        XIic_WriteReg(InstancePtr->BaseAddress,
440
                                        XIIC_TBA_REG_OFFSET, SendAddr);
441
                }
442
 
443
                return XST_SUCCESS;
444
        }
445
 
446
        /*
447
         * Store address of slave device being read from.
448
         */
449
        if (AddressType == XII_ADDR_TO_SEND_TYPE) {
450
                InstancePtr->AddrOfSlave = Address;
451
                return XST_SUCCESS;
452
        }
453
 
454
        return XST_INVALID_PARAM;
455
}
456
 
457
/*****************************************************************************/
458
/**
459
*
460
* This function gets the addresses for the IIC device driver. The addresses
461
* include the device address that the device responds to as a slave, or the
462
* slave address to communicate with on the bus. The address returned has the
463
* same format whether 7 or 10 bits.
464
*
465
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
466
* @param        AddressType indicates which address, the address which this
467
*               responds to on the IIC bus as a slave, or the slave address to
468
*               communicate with when this device is a master. One of the
469
*               following values must be contained in this argument.
470
* <pre>
471
*   XII_ADDR_TO_SEND_TYPE       Slave being addressed as a master
472
*   XII_ADDR_TO_RESPOND_TYPE    Slave address to respond to as a slave
473
* </pre>
474
*  If neither of the two valid arguments are used, the function returns
475
*  the address of the slave device
476
*
477
* @return       The address retrieved.
478
*
479
* @note         None.
480
*
481
****************************************************************************/
482
u16 XIic_GetAddress(XIic *InstancePtr, int AddressType)
483
{
484
        u8  LowAddr;
485
        u16 HighAddr = 0;
486
 
487
        Xil_AssertNonvoid(InstancePtr != NULL);
488
 
489
        /*
490
         * Return this device's address.
491
         */
492
        if (AddressType == XII_ADDR_TO_RESPOND_TYPE) {
493
 
494
                LowAddr = (u8) XIic_ReadReg(InstancePtr->BaseAddress,
495
                                             XIIC_ADR_REG_OFFSET);
496
 
497
                if (InstancePtr->Has10BitAddr == TRUE) {
498
                        HighAddr = (u16) XIic_ReadReg(InstancePtr->BaseAddress,
499
                                                        XIIC_TBA_REG_OFFSET);
500
                }
501
                return ((HighAddr << 8) | (u16) LowAddr);
502
        }
503
 
504
        /*
505
         * Otherwise return address of slave device on the IIC bus.
506
         */
507
        return InstancePtr->AddrOfSlave;
508
}
509
 
510
/*****************************************************************************/
511
/**
512
*
513
* This function sets the contents of the General Purpose Output register
514
* for the IIC device driver. Note that the number of bits in this register is
515
* parameterizable in the hardware such that it may not exist.  This function
516
* checks to ensure that it does exist to prevent bus errors, but does not
517
* ensure that the number of bits in the register are sufficient for the
518
* value being written (won't cause a bus error).
519
*
520
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
521
* @param        OutputValue contains the value to be written to the register.
522
*
523
* @return
524
*               - XST_SUCCESS if the given data is written to the GPO register.
525
*               - XST_NO_FEATURE if the hardware is configured such that this
526
*               register does not contain any bits to read or write.
527
*
528
* @note         None.
529
*
530
****************************************************************************/
531
int XIic_SetGpOutput(XIic *InstancePtr, u8 OutputValue)
532
{
533
        Xil_AssertNonvoid(InstancePtr != NULL);
534
 
535
        /*
536
         * If the general purpose output register is implemented by the hardware
537
         * then write the specified value to it, otherwise indicate an error.
538
         */
539
        if (InstancePtr->GpOutWidth > 0) {
540
                XIic_WriteReg(InstancePtr->BaseAddress, XIIC_GPO_REG_OFFSET,
541
                                OutputValue);
542
                return XST_SUCCESS;
543
        } else {
544
                return XST_NO_FEATURE;
545
        }
546
}
547
 
548
/*****************************************************************************/
549
/**
550
*
551
* This function gets the contents of the General Purpose Output register
552
* for the IIC device driver. Note that the number of bits in this register is
553
* parameterizable in the hardware such that it may not exist. This function
554
* checks to ensure that it does exist to prevent bus errors.
555
*
556
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
557
* @param        OutputValuePtr contains the value which was read from the
558
*               register.
559
*
560
* @return
561
*               - XST_SUCCESS if the given data is read from the GPO register.
562
*               - XST_NO_FEATURE if the hardware is configured such that this
563
*               register does not contain any bits to read or write.
564
*
565
* The OutputValuePtr is also an output as it contains the value read.
566
*
567
* @note         None.
568
*
569
****************************************************************************/
570
int XIic_GetGpOutput(XIic *InstancePtr, u8 *OutputValuePtr)
571
{
572
        Xil_AssertNonvoid(InstancePtr != NULL);
573
        Xil_AssertNonvoid(OutputValuePtr != NULL);
574
 
575
        /*
576
         * If the general purpose output register is implemented by the hardware
577
         * then read the value from it, otherwise indicate an error.
578
         */
579
        if (InstancePtr->GpOutWidth > 0) {
580
                *OutputValuePtr = XIic_ReadReg(InstancePtr->BaseAddress,
581
                                                XIIC_GPO_REG_OFFSET);
582
                return XST_SUCCESS;
583
        } else {
584
                return XST_NO_FEATURE;
585
        }
586
}
587
 
588
/*****************************************************************************/
589
/**
590
*
591
* A function to determine if the device is currently addressed as a slave.
592
*
593
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
594
*
595
* @return
596
*               - TRUE if the device is addressed as slave.
597
*               - FALSE if the device is NOT addressed as slave.
598
*
599
* @note         None.
600
*
601
****************************************************************************/
602
u32 XIic_IsSlave(XIic *InstancePtr)
603
{
604
        Xil_AssertNonvoid(InstancePtr != NULL);
605
 
606
        if ((XIic_ReadReg(InstancePtr->BaseAddress, XIIC_SR_REG_OFFSET) &
607
                 XIIC_SR_ADDR_AS_SLAVE_MASK) == 0) {
608
                return FALSE;
609
        }
610
        return TRUE;
611
}
612
 
613
/*****************************************************************************/
614
/**
615
*
616
* Sets the receive callback function, the receive handler, which the driver
617
* calls when it finishes receiving data. The number of bytes used to signal
618
* when the receive is complete is the number of bytes set in the XIic_Recv
619
* function.
620
*
621
* The handler executes in an interrupt context such that it must minimize
622
* the amount of processing performed such as transferring data to a thread
623
* context.
624
*
625
* The number of bytes received is passed to the handler as an argument.
626
*
627
* @param        InstancePtr is a pointer to the XIic instance to be worked on.
628
* @param        CallBackRef is the upper layer callback reference passed back
629
*               when the callback function is invoked.
630
* @param        FuncPtr is the pointer to the callback function.
631
*
632
* @return       None.
633
*
634
* @note         The handler is called within interrupt context .
635
*
636
****************************************************************************/
637
void XIic_SetRecvHandler(XIic *InstancePtr, void *CallBackRef,
638
                         XIic_Handler FuncPtr)
639
{
640
        Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
641
        Xil_AssertVoid(InstancePtr != NULL);
642
        Xil_AssertVoid(FuncPtr != NULL);
643
 
644
        InstancePtr->RecvHandler = FuncPtr;
645
        InstancePtr->RecvCallBackRef = CallBackRef;
646
}
647
 
648
/*****************************************************************************/
649
/**
650
*
651
* Sets the send callback function, the send handler, which the driver calls when
652
* it receives confirmation of sent data. The handler executes in an interrupt
653
* context such that it must minimize the amount of processing performed such
654
* as transferring data to a thread context.
655
*
656
* @param        InstancePtr the pointer to the XIic instance to be worked on.
657
* @param        CallBackRef the upper layer callback reference passed back when
658
*               the callback function is invoked.
659
* @param        FuncPtr the pointer to the callback function.
660
*
661
* @return       None.
662
*
663
* @note         The handler is called within interrupt context .
664
*
665
****************************************************************************/
666
void XIic_SetSendHandler(XIic *InstancePtr, void *CallBackRef,
667
                         XIic_Handler FuncPtr)
668
{
669
        Xil_AssertVoid(InstancePtr != NULL);
670
        Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
671
        Xil_AssertVoid(FuncPtr != NULL);
672
 
673
        InstancePtr->SendHandler = FuncPtr;
674
        InstancePtr->SendCallBackRef = CallBackRef;
675
}
676
 
677
/*****************************************************************************/
678
/**
679
*
680
* Sets the status callback function, the status handler, which the driver calls
681
* when it encounters conditions which are not data related. The handler
682
* executes in an interrupt context such that it must minimize the amount of
683
* processing performed such as transferring data to a thread context. The
684
* status events that can be returned are described in xiic.h.
685
*
686
* @param        InstancePtr points to the XIic instance to be worked on.
687
* @param        CallBackRef is the upper layer callback reference passed back
688
*               when the callback function is invoked.
689
* @param        FuncPtr is the pointer to the callback function.
690
*
691
* @return       None.
692
*
693
* @note         The handler is called within interrupt context .
694
*
695
****************************************************************************/
696
void XIic_SetStatusHandler(XIic *InstancePtr, void *CallBackRef,
697
                           XIic_StatusHandler FuncPtr)
698
{
699
        Xil_AssertVoid(InstancePtr != NULL);
700
        Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
701
        Xil_AssertVoid(FuncPtr != NULL);
702
 
703
        InstancePtr->StatusHandler = FuncPtr;
704
        InstancePtr->StatusCallBackRef = CallBackRef;
705
}
706
 
707
/*****************************************************************************
708
*
709
* This is a stub for the send and recv callbacks. The stub is here in case the
710
* upper layers forget to set the handlers.
711
*
712
* @param        CallBackRef is a pointer to the upper layer callback reference
713
* @param        ByteCount is the number of bytes sent or received
714
*
715
* @return       None.
716
*
717
* @note         None.
718
*
719
******************************************************************************/
720
static void XIic_StubHandler(void *CallBackRef, int ByteCount)
721
{
722
        (void) ByteCount;
723
        (void) CallBackRef;
724
        Xil_AssertVoidAlways();
725
}
726
 
727
/*****************************************************************************
728
*
729
* This is a stub for the asynchronous error callback. The stub is here in case
730
* the upper layers forget to set the handler.
731
*
732
* @param        CallBackRef is a pointer to the upper layer callback reference.
733
* @param        ErrorCode is the Xilinx error code, indicating the cause of
734
*               the error.
735
*
736
* @return       None.
737
*
738
* @note         None.
739
*
740
******************************************************************************/
741
static void XIic_StubStatusHandler(void *CallBackRef, int ErrorCode)
742
{
743
        (void) ErrorCode;
744
        (void) CallBackRef;
745
        Xil_AssertVoidAlways();
746
}
747
/** @} */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.