summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/T-HEAD_CB2201_CDK/csi/csi_driver/include/drv_eth_phy.h
blob: adf4aa0171404c9bde8110ce53a5604082038056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 * Copyright (C) 2016 CSI Project. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _CSI_ETH_PHY_H_
#define _CSI_ETH_PHY_H_

#include "drv_eth.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef void *eth_phy_handle_t;

#define CSI_ETH_PHY_API_VERSION CSI_ETH_VERSION_MAJOR_MINOR(2,1)  /* API version */


#define _CSI_Driver_ETH_PHY_(n)      Driver_ETH_PHY##n
#define  CSI_Driver_ETH_PHY_(n) _CSI_Driver_ETH_PHY_(n)


/****** Ethernet PHY Mode *****/
#define CSI_ETH_PHY_SPEED_Pos            0
#define CSI_ETH_PHY_SPEED_Msk           (3UL                 << CSI_ETH_PHY_SPEED_Pos)
#define CSI_ETH_PHY_SPEED_10M           (CSI_ETH_SPEED_10M   << CSI_ETH_PHY_SPEED_Pos)  ///< 10 Mbps link speed
#define CSI_ETH_PHY_SPEED_100M          (CSI_ETH_SPEED_100M  << CSI_ETH_PHY_SPEED_Pos)  ///< 100 Mbps link speed
#define CSI_ETH_PHY_SPEED_1G            (CSI_ETH_SPEED_1G    << CSI_ETH_PHY_SPEED_Pos)  ///< 1 Gpbs link speed
#define CSI_ETH_PHY_DUPLEX_Pos           2
#define CSI_ETH_PHY_DUPLEX_Msk          (1UL                 << CSI_ETH_PHY_DUPLEX_Pos)
#define CSI_ETH_PHY_DUPLEX_HALF         (CSI_ETH_DUPLEX_HALF << CSI_ETH_PHY_DUPLEX_Pos) ///< Half duplex link
#define CSI_ETH_PHY_DUPLEX_FULL         (CSI_ETH_DUPLEX_FULL << CSI_ETH_PHY_DUPLEX_Pos) ///< Full duplex link
#define CSI_ETH_PHY_AUTO_NEGOTIATE      (1UL << 3)                                      ///< Auto Negotiation mode
#define CSI_ETH_PHY_LOOPBACK            (1UL << 4)                                      ///< Loop-back test mode
#define CSI_ETH_PHY_ISOLATE             (1UL << 5)                                      ///< Isolate PHY from MII/RMII interface

typedef int32_t (*csi_eth_phy_read_t)  (uint8_t phy_addr, uint8_t reg_addr, uint16_t *data); ///< Read Ethernet PHY Register.
typedef int32_t (*csi_eth_phy_write_t) (uint8_t phy_addr, uint8_t reg_addr, uint16_t  data); ///< Write Ethernet PHY Register.

typedef struct {
    csi_eth_phy_read_t  phy_read;
    csi_eth_phy_write_t phy_write;
    eth_link_info_t     link_info;
}eth_phy_priv_t;

// Function documentation
/**
  \brief       Get driver version.
  \param[in]   handle  ethernet phy handle
  \return      driver version
*/
csi_drv_version_t csi_eth_phy_get_version(eth_phy_handle_t handle);

/**
  \brief       Initialize Ethernet PHY Device.
  \param[in]   fn_read   
  \param[in]   fn_write  
  \return      ethernet phy handle
*/
eth_phy_handle_t csi_eth_phy_initialize(csi_eth_phy_read_t fn_read, csi_eth_phy_write_t fn_write);

/**
  \brief       De-initialize Ethernet PHY Device.
  \param[in]   handle  ethernet phy handle
  \return      error code
*/
int32_t csi_eth_phy_uninitialize(eth_phy_handle_t handle);

/**
  \brief       Control Ethernet PHY Device Power.
  \param[in]   handle  ethernet phy handle
  \param[in]   state  Power state
  \return      error code
*/
int32_t csi_eth_phy_power_control(eth_phy_handle_t handle, eth_power_state_t state);

/**
  \brief       Set Ethernet Media Interface.
  \param[in]   handle  ethernet phy handle
  \param[in]   interface  Media Interface type
  \return      error code
*/
int32_t csi_eth_phy_set_interface(eth_phy_handle_t handle, uint32_t interface);

/**
  \brief       Set Ethernet PHY Device Operation mode.
  \param[in]   handle  ethernet phy handle
  \param[in]   mode  Operation Mode
  \return      error code
*/
int32_t csi_eth_phy_set_mode(eth_phy_handle_t handle, uint32_t mode);

/**
  \brief       Get Ethernet PHY Device Link state.
  \param[in]   handle  ethernet phy handle
  \return      current link status \ref eth_link_state_t
*/
eth_link_state_t csi_eth_phy_get_linkstate(eth_phy_handle_t handle);

/**
  \brief       Get Ethernet PHY Device Link information.
  \param[in]   handle  ethernet phy handle
  \return      current link parameters \ref eth_link_info_t
*/
eth_link_info_t csi_eth_phy_get_linkinfo(eth_phy_handle_t handle);

#ifdef __cplusplus
}
#endif

#endif