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

Subversion Repositories xenie

[/] [xenie/] [trunk/] [examples/] [Eth_example/] [mb_fw/] [drivers/] [iic_v3_4/] [examples/] [xiic_low_level_tempsensor_example.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 - 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
* @file xiic_low_level_tempsensor_example.c
35
*
36
* This file contains a polled mode design example which uses the Xilinx IIC
37
* device and low-level driver to execise the temperature sensor on the ML300
38
* board. This example only performs read operations (receive) from the IIC
39
* temperature sensor of the platform.
40
*
41
* The XIic_Recv() API is used to receive the data.
42
*
43
* @note
44
*
45
* 7-bit addressing is used to access the tempsensor.
46
*
47
* None
48
* <pre>
49
* MODIFICATION HISTORY:
50
*
51
* Ver   Who  Date        Changes
52
* ----- ---- -------- -----------------------------------------------
53
* 1.00a jhl  10/09/03 Initial Release
54
* 1.00a sv   05/09/05 Minor changes to comply to Doxygen and coding guidelines
55
* 1.00a mta  03/09/06 Minor updates due to changes in the low level driver for
56
*                        supporting repeated start functionality.
57
* 2.00a sdm  09/22/09 Minor modifications as per coding guidelines.
58
*
59
* </pre>
60
*
61
*****************************************************************************/
62
 
63
/***************************** Include Files *********************************/
64
 
65
#include "xparameters.h"
66
#include "xiic_l.h"
67
 
68
/************************** Constant Definitions *****************************/
69
 
70
/*
71
 * The following constants map to the XPAR parameters created in the
72
 * xparameters.h file. They are defined here such that a user can easily
73
 * change all the needed parameters in one place.
74
 */
75
#define IIC_BASE_ADDRESS        XPAR_IIC_0_BASEADDR
76
 
77
 
78
/*
79
 * The following constant defines the address of the IIC
80
 * temperature sensor device on the IIC bus.  Note that since
81
 * the address is only 7 bits, this  constant is the address divided by 2.
82
 */
83
#define TEMP_SENSOR_ONCHIP_ADDRESS  0x18 /* The actual address is 0x30 */
84
#define TEMP_SENSOR_AMBIENT_ADDRESS 0x4B /* The actual address is 0x96 */
85
 
86
 
87
/**************************** Type Definitions *******************************/
88
 
89
 
90
/***************** Macros (Inline Functions) Definitions *********************/
91
 
92
 
93
/************************** Function Prototypes ******************************/
94
 
95
int LowLevelTempSensorExample(u32 IicBaseAddress,
96
                                u8 TempSensorAddress,
97
                                u8 *TemperaturePtr);
98
 
99
/************************** Variable Definitions *****************************/
100
 
101
 
102
/*****************************************************************************/
103
/**
104
*
105
* The purpose of this function is to illustrate how to use the IIC level 0
106
* driver to read the temperature.
107
*
108
* @param        None
109
*
110
* @return       Always 0
111
*
112
* @note
113
*
114
* The main function is returning an integer to prevent compiler warnings.
115
*
116
****************************************************************************/
117
int main(void)
118
{
119
        u8 TemperaturePtr;
120
 
121
        /*
122
         * Run the example, specify the Base Address that is generated in
123
         * xparameters.h
124
         */
125
        LowLevelTempSensorExample(IIC_BASE_ADDRESS,
126
                                        TEMP_SENSOR_ONCHIP_ADDRESS,
127
                                        &TemperaturePtr);
128
        return 0;
129
}
130
 
131
/*****************************************************************************/
132
/**
133
*
134
* The function reads the temperature of the IIC temperature sensor on the
135
* IIC bus using the low-level driver.
136
*
137
* @param        IicBaseAddress is the base address of the device.
138
* @param        TempSensorAddress is the address of the Temperature Sensor device
139
*               on the IIC bus.
140
* @param        TemperaturePtr is the databyte read from the temperature sensor.
141
*
142
* @return       The number of bytes read from the temperature sensor, normally one
143
*               byte if successful.
144
*
145
* @note         None.
146
*
147
****************************************************************************/
148
int LowLevelTempSensorExample(u32 IicBaseAddress,
149
                                u8  TempSensorAddress,
150
                                u8 *TemperaturePtr)
151
{
152
        int ByteCount;
153
 
154
        ByteCount = XIic_Recv(IicBaseAddress, TempSensorAddress,
155
                                TemperaturePtr, 1, XIIC_STOP);
156
 
157
 
158
 
159
        return ByteCount;
160
}

powered by: WebSVN 2.1.0

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