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

Subversion Repositories xenie

[/] [xenie/] [trunk/] [examples/] [Eth_example/] [mb_fw/] [xenie_eth_test_womtd/] [src/] [iic_id_eeprom.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 DFC
/******************************************************************************
2
**
3
** (C) Copyright 2013 DFC Design, s.r.o., Brno, Czech Republic
4
** Author: Marek Kvas (m.kvas@dspfpga.com)
5
**
6
****************************************************************************
7
**
8
** This file is part of Xenia Ethernet Example project.
9
**
10
** Xenia Ethernet Example project is free software: you can
11
** redistribute it and/or modify it under the terms of
12
** the GNU Lesser General Public License as published by the Free
13
** Software Foundation, either version 3 of the License, or
14
** (at your option) any later version.
15
**
16
** Xenia Ethernet Example project is distributed in the hope that
17
** it will be useful, but WITHOUT ANY WARRANTY; without even
18
** the implied warranty of MERCHANTABILITY or FITNESS FOR A
19
** PARTICULAR PURPOSE.  See the GNU Lesser General Public License
20
** for more details.
21
**
22
** You should have received a copy of the GNU Lesser General Public
23
** License along with Xenia Ethernet Example project.  If not,
24
** see <http://www.gnu.org/licenses/>.
25
**
26
*******************************************************************************
27
**
28
** This is driver for MAC EEPROM chip 24AA025E48.
29
**
30
*******************************************************************************
31
*/
32
 
33
#include "iic_id_eeprom.h"
34
#include "iic_wrap.h"
35
 
36
/*
37
 * Initialize context structure.
38
 * No communication with memory is done here.
39
 * Always succeeds - returns zero.
40
 */
41
int iic_id_eeprom_init(struct iic_id_eeprom_dev *dev,
42
                struct iic_wrap_dev *iic_wrap, u8 iic_addr, int iic_op_timeout)
43
{
44
        dev->iic_addr = iic_addr;
45
        dev->iic_wrap = iic_wrap;
46
        dev->iic_op_timeout = iic_op_timeout;
47
        return 0;
48
}
49
 
50
 
51
/*
52
 * Read continuous block of data to
53
 * buffer given by user.
54
 *
55
 * On success, zero is returned. On error,
56
 * negative number is returned.
57
 */
58
int iic_id_eeprom_read(struct iic_id_eeprom_dev *dev, u8 addr,
59
                u8* data, u8 len)
60
{
61
        unsigned res;
62
 
63
        if (len > ID_EEPROM_MAX_SIZE) {
64
                return -1;
65
        }
66
 
67
        /* Write command byte (address) */
68
        res = iic_wrap_send_timeout(dev->iic_wrap, dev->iic_addr,
69
                        &addr, 1, dev->iic_op_timeout);
70
        if (res != 0) {
71
                return res;
72
        }
73
 
74
        /* Read data out */
75
        res = iic_wrap_recv_timeout(dev->iic_wrap, dev->iic_addr, data,
76
                        len, dev->iic_op_timeout);
77
 
78
        return res;
79
}
80
 
81
/*
82
 * Write continuous block of data to
83
 * buffer given by user.
84
 *
85
 * On success, zero is returned. On error,
86
 * negative number is returned.
87
 */
88
int iic_id_eeprom_write(struct iic_id_eeprom_dev *dev, u8 addr, u8* data, u8 len)
89
{
90
        unsigned res;
91
        u8 buf[ID_EEPROM_MAX_SIZE + 1];
92
 
93
        if (len > ID_EEPROM_MAX_SIZE) {
94
                return -1;
95
        }
96
 
97
        buf[0] = addr;
98
        memcpy(buf + 1, data, len);
99
 
100
        /* Write command byte (address) and data*/
101
        res = iic_wrap_send_timeout(dev->iic_wrap, dev->iic_addr, buf, len + 1,
102
                        dev->iic_op_timeout);
103
        return res;
104
}
105
 
106
/*
107
 * Read 48 bit long unique identifier to
108
 * buffer prepared by user.
109
 *
110
 * On success, zero is returned. On error,
111
 * negative number is returned.
112
 */
113
int iic_id_eeprom_getId(struct iic_id_eeprom_dev *dev, u8* id)
114
{
115
        return iic_id_eeprom_read(dev, ID_ADDR, id, 6);
116
}

powered by: WebSVN 2.1.0

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