1 |
786 |
skrzyp |
#ifndef CYGONCE_DEVS_ETH_PHY_H_
|
2 |
|
|
#define CYGONCE_DEVS_ETH_PHY_H_
|
3 |
|
|
//==========================================================================
|
4 |
|
|
//
|
5 |
|
|
// eth_phy.h
|
6 |
|
|
//
|
7 |
|
|
// User API for ethernet transciever (PHY) support
|
8 |
|
|
//
|
9 |
|
|
//==========================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 2003, 2010 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//==========================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): gthomas
|
45 |
|
|
// Contributors: gthomas
|
46 |
|
|
// Date: 2003-08-01
|
47 |
|
|
// Purpose:
|
48 |
|
|
// Description:
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
#define PHY_BIT_LEVEL_ACCESS_TYPE 0
|
55 |
|
|
#define PHY_REG_LEVEL_ACCESS_TYPE 1
|
56 |
|
|
|
57 |
|
|
// Physical device access - defined by hardware instance
|
58 |
|
|
typedef struct {
|
59 |
|
|
int ops_type; // 0 => bit level, 1 => register level
|
60 |
|
|
bool init_done;
|
61 |
|
|
void (*init)(void);
|
62 |
|
|
void (*reset)(void);
|
63 |
|
|
union {
|
64 |
|
|
struct {
|
65 |
|
|
void (*set_data)(int);
|
66 |
|
|
int (*get_data)(void);
|
67 |
|
|
void (*set_clock)(int);
|
68 |
|
|
void (*set_dir)(int);
|
69 |
|
|
} bit_level_ops;
|
70 |
|
|
struct {
|
71 |
|
|
void (*put_reg)(int reg, int unit, unsigned short data);
|
72 |
|
|
bool (*get_reg)(int reg, int unit, unsigned short *data);
|
73 |
|
|
} reg_level_ops;
|
74 |
|
|
} ops;
|
75 |
|
|
int phy_addr;
|
76 |
|
|
struct _eth_phy_dev_entry *dev; // Chip access functions
|
77 |
|
|
} eth_phy_access_t;
|
78 |
|
|
|
79 |
|
|
#define ETH_PHY_BIT_LEVEL_ACCESS_FUNS(_l,_init,_reset,_set_data,_get_data,_set_clock,_set_dir) \
|
80 |
|
|
static eth_phy_access_t _l = {PHY_BIT_LEVEL_ACCESS_TYPE, false, _init, _reset, \
|
81 |
|
|
{.bit_level_ops = {_set_data, _get_data, _set_clock, _set_dir}}}
|
82 |
|
|
|
83 |
|
|
#define ETH_PHY_REG_LEVEL_ACCESS_FUNS(_l,_init,_reset,_put_reg,_get_reg) \
|
84 |
|
|
static eth_phy_access_t _l = {PHY_REG_LEVEL_ACCESS_TYPE, false, _init, _reset, \
|
85 |
|
|
{.reg_level_ops = {_put_reg, _get_reg}}}
|
86 |
|
|
|
87 |
|
|
#define ETH_PHY_STAT_LINK 0x0001 // Link up/down
|
88 |
|
|
#define ETH_PHY_STAT_100MB 0x0002 // Connection is 100Mb/10Mb
|
89 |
|
|
#define ETH_PHY_STAT_FDX 0x0004 // Connection is full/half duplex
|
90 |
|
|
#define ETH_PHY_STAT_1000MB 0x0008 // Connection is 1Gb
|
91 |
|
|
|
92 |
|
|
externC bool _eth_phy_init(eth_phy_access_t *f);
|
93 |
|
|
externC void _eth_phy_reset(eth_phy_access_t *f);
|
94 |
|
|
externC int _eth_phy_state(eth_phy_access_t *f);
|
95 |
|
|
externC int _eth_phy_cfg(eth_phy_access_t *f, int mode);
|
96 |
|
|
#define ETH_PHY_MODE_DEFAULT 0
|
97 |
|
|
|
98 |
|
|
// Internal routines
|
99 |
|
|
externC void _eth_phy_write(eth_phy_access_t *f, int reg, int unit, unsigned short data);
|
100 |
|
|
externC bool _eth_phy_read(eth_phy_access_t *f, int reg, int unit, unsigned short *val);
|
101 |
|
|
|
102 |
|
|
#endif // CYGONCE_DEVS_ETH_PHY_H_
|
103 |
|
|
// ------------------------------------------------------------------------
|