Sergey Pastor / 1

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ksz8041.h Source File

ksz8041.h

Go to the documentation of this file.
00001 /**
00002  * @file ksz8041.h
00003  * @brief KSZ8041 Ethernet PHY transceiver
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _KSZ8041_H
00030 #define _KSZ8041_H
00031 
00032 //Dependencies
00033 #include "core/nic.h"
00034 
00035 //PHY address
00036 #ifndef KSZ8041_PHY_ADDR
00037    #define KSZ8041_PHY_ADDR 1
00038 #elif (KSZ8041_PHY_ADDR < 0 || KSZ8041_PHY_ADDR > 31)
00039    #error KSZ8041_PHY_ADDR parameter is not valid
00040 #endif
00041 
00042 //KSZ8041 registers
00043 #define KSZ8041_PHY_REG_BMCR           0x00
00044 #define KSZ8041_PHY_REG_BMSR           0x01
00045 #define KSZ8041_PHY_REG_PHYIDR1        0x02
00046 #define KSZ8041_PHY_REG_PHYIDR2        0x03
00047 #define KSZ8041_PHY_REG_ANAR           0x04
00048 #define KSZ8041_PHY_REG_ANLPAR         0x05
00049 #define KSZ8041_PHY_REG_ANER           0x06
00050 #define KSZ8041_PHY_REG_ANNPTR         0x07
00051 #define KSZ8041_PHY_REG_LPNPAR         0x08
00052 #define KSZ8041_PHY_REG_MIICON         0x14
00053 #define KSZ8041_PHY_REG_RXERCTR        0x15
00054 #define KSZ8041_PHY_REG_ICSR           0x1B
00055 #define KSZ8041_PHY_REG_PHYCON1        0x1E
00056 #define KSZ8041_PHY_REG_PHYCON2        0x1F
00057 
00058 //BMCR register
00059 #define BMCR_RESET                     (1 << 15)
00060 #define BMCR_LOOPBACK                  (1 << 14)
00061 #define BMCR_SPEED_SEL                 (1 << 13)
00062 #define BMCR_AN_EN                     (1 << 12)
00063 #define BMCR_POWER_DOWN                (1 << 11)
00064 #define BMCR_ISOLATE                   (1 << 10)
00065 #define BMCR_RESTART_AN                (1 << 9)
00066 #define BMCR_DUPLEX_MODE               (1 << 8)
00067 #define BMCR_COL_TEST                  (1 << 7)
00068 #define BMCR_TX_DIS                    (1 << 0)
00069 
00070 //BMSR register
00071 #define BMSR_100BT4                    (1 << 15)
00072 #define BMSR_100BTX_FD                 (1 << 14)
00073 #define BMSR_100BTX                    (1 << 13)
00074 #define BMSR_10BT_FD                   (1 << 12)
00075 #define BMSR_10BT                      (1 << 11)
00076 #define BMSR_NO_PREAMBLE               (1 << 6)
00077 #define BMSR_AN_COMPLETE               (1 << 5)
00078 #define BMSR_REMOTE_FAULT              (1 << 4)
00079 #define BMSR_AN_ABLE                   (1 << 3)
00080 #define BMSR_LINK_STATUS               (1 << 2)
00081 #define BMSR_JABBER_DETECT             (1 << 1)
00082 #define BMSR_EXTENDED_CAP              (1 << 0)
00083 
00084 //ANAR register
00085 #define ANAR_NEXT_PAGE                 (1 << 15)
00086 #define ANAR_REMOTE_FAULT              (1 << 13)
00087 #define ANAR_PAUSE1                    (1 << 11)
00088 #define ANAR_PAUSE0                    (1 << 10)
00089 #define ANAR_100BT4                    (1 << 9)
00090 #define ANAR_100BTX_FD                 (1 << 8)
00091 #define ANAR_100BTX                    (1 << 7)
00092 #define ANAR_10BT_FD                   (1 << 6)
00093 #define ANAR_10BT                      (1 << 5)
00094 #define ANAR_SELECTOR4                 (1 << 4)
00095 #define ANAR_SELECTOR3                 (1 << 3)
00096 #define ANAR_SELECTOR2                 (1 << 2)
00097 #define ANAR_SELECTOR1                 (1 << 1)
00098 #define ANAR_SELECTOR0                 (1 << 0)
00099 
00100 //ANLPAR register
00101 #define ANLPAR_NEXT_PAGE               (1 << 15)
00102 #define ANLPAR_LP_ACK                  (1 << 14)
00103 #define ANLPAR_REMOTE_FAULT            (1 << 13)
00104 #define ANLPAR_PAUSE1                  (1 << 11)
00105 #define ANLPAR_PAUSE0                  (1 << 10)
00106 #define ANLPAR_100BT4                  (1 << 9)
00107 #define ANLPAR_100BTX_FD               (1 << 8)
00108 #define ANLPAR_100BTX                  (1 << 7)
00109 #define ANLPAR_10BT_FD                 (1 << 6)
00110 #define ANLPAR_10BT                    (1 << 5)
00111 #define ANLPAR_SELECTOR4               (1 << 4)
00112 #define ANLPAR_SELECTOR3               (1 << 3)
00113 #define ANLPAR_SELECTOR2               (1 << 2)
00114 #define ANLPAR_SELECTOR1               (1 << 1)
00115 #define ANLPAR_SELECTOR0               (1 << 0)
00116 
00117 //ANER register
00118 #define ANER_PAR_DET_FAULT             (1 << 4)
00119 #define ANER_LP_NEXT_PAGE_ABLE         (1 << 3)
00120 #define ANER_NEXT_PAGE_ABLE            (1 << 2)
00121 #define ANER_PAGE_RECEIVED             (1 << 1)
00122 #define ANER_LP_AN_ABLE                (1 << 0)
00123 
00124 //ANNPTR register
00125 #define ANNPTR_NEXT_PAGE               (1 << 15)
00126 #define ANNPTR_MSG_PAGE                (1 << 13)
00127 #define ANNPTR_ACK2                    (1 << 12)
00128 #define ANNPTR_TOGGLE                  (1 << 11)
00129 #define ANNPTR_MESSAGE10               (1 << 10)
00130 #define ANNPTR_MESSAGE9                (1 << 9)
00131 #define ANNPTR_MESSAGE8                (1 << 8)
00132 #define ANNPTR_MESSAGE7                (1 << 7)
00133 #define ANNPTR_MESSAGE6                (1 << 6)
00134 #define ANNPTR_MESSAGE5                (1 << 5)
00135 #define ANNPTR_MESSAGE4                (1 << 4)
00136 #define ANNPTR_MESSAGE3                (1 << 3)
00137 #define ANNPTR_MESSAGE2                (1 << 2)
00138 #define ANNPTR_MESSAGE1                (1 << 1)
00139 #define ANNPTR_MESSAGE0                (1 << 0)
00140 
00141 //LPNPAR register
00142 #define LPNPAR_NEXT_PAGE               (1 << 15)
00143 #define LPNPAR_ACK                     (1 << 14)
00144 #define LPNPAR_MSG_PAGE                (1 << 13)
00145 #define LPNPAR_ACK2                    (1 << 12)
00146 #define LPNPAR_TOGGLE                  (1 << 11)
00147 #define LPNPAR_MESSAGE10               (1 << 10)
00148 #define LPNPAR_MESSAGE9                (1 << 9)
00149 #define LPNPAR_MESSAGE8                (1 << 8)
00150 #define LPNPAR_MESSAGE7                (1 << 7)
00151 #define LPNPAR_MESSAGE6                (1 << 6)
00152 #define LPNPAR_MESSAGE5                (1 << 5)
00153 #define LPNPAR_MESSAGE4                (1 << 4)
00154 #define LPNPAR_MESSAGE3                (1 << 3)
00155 #define LPNPAR_MESSAGE2                (1 << 2)
00156 #define LPNPAR_MESSAGE1                (1 << 1)
00157 #define LPNPAR_MESSAGE0                (1 << 0)
00158 
00159 //MIICON register
00160 #define MIICON_100BTX_PREAMBLE_RESTORE (1 << 7)
00161 #define MIICON_10BT_PREAMBLE_RESTORE   (1 << 6)
00162 
00163 //ICSR register
00164 #define ICSR_JABBER_IE                 (1 << 15)
00165 #define ICSR_RECEIVE_ERROR_IE          (1 << 14)
00166 #define ICSR_PAGE_RECEIVED_IE          (1 << 13)
00167 #define ICSR_PAR_DET_FAULT_IE          (1 << 12)
00168 #define ICSR_LP_ACK_IE                 (1 << 11)
00169 #define ICSR_LINK_DOWN_IE              (1 << 10)
00170 #define ICSR_REMOTE_FAULT_IE           (1 << 9)
00171 #define ICSR_LINK_UP_IE                (1 << 8)
00172 #define ICSR_JABBER_IF                 (1 << 7)
00173 #define ICSR_RECEIVE_ERROR_IF          (1 << 6)
00174 #define ICSR_PAGE_RECEIVED_IF          (1 << 5)
00175 #define ICSR_PAR_DET_FAULT_IF          (1 << 4)
00176 #define ICSR_LP_ACK_IF                 (1 << 3)
00177 #define ICSR_LINK_DOWN_IF              (1 << 2)
00178 #define ICSR_REMOTE_FAULT_IF           (1 << 1)
00179 #define ICSR_LINK_UP_IF                (1 << 0)
00180 
00181 //PHYCON1 register
00182 #define PHYCON1_LED_MODE1              (1 << 15)
00183 #define PHYCON1_LED_MODE0              (1 << 14)
00184 #define PHYCON1_POLARITY               (1 << 13)
00185 #define PHYCON1_MDIX_STATE             (1 << 11)
00186 #define PHYCON1_REMOTE_LOOPBACK        (1 << 7)
00187 
00188 //PHYCON2 register
00189 #define PHYCON2_HP_MDIX             (1 << 15)
00190 #define PHYCON2_MDIX_SEL            (1 << 14)
00191 #define PHYCON2_PAIR_SWAP_DIS       (1 << 13)
00192 #define PHYCON2_ENERGY_DETECT       (1 << 12)
00193 #define PHYCON2_FORCE_LINK          (1 << 11)
00194 #define PHYCON2_POWER_SAVING        (1 << 10)
00195 #define PHYCON2_INT_LEVEL           (1 << 9)
00196 #define PHYCON2_JABBER_EN           (1 << 8)
00197 #define PHYCON2_AN_COMPLETE         (1 << 7)
00198 #define PHYCON2_PHY_ISOLATE         (1 << 5)
00199 #define PHYCON2_OP_MODE2            (1 << 4)
00200 #define PHYCON2_OP_MODE1            (1 << 3)
00201 #define PHYCON2_OP_MODE0            (1 << 2)
00202 #define PHYCON2_SQE_TEST_EN         (1 << 1)
00203 #define PHYCON2_SCRAMBLER_DIS       (1 << 0)
00204 
00205 //Operation mode indication
00206 #define PHYCON2_OP_MODE_MASK        (7 << 2)
00207 #define PHYCON2_OP_MODE_AN          (0 << 2)
00208 #define PHYCON2_OP_MODE_10BT        (1 << 2)
00209 #define PHYCON2_OP_MODE_100BTX      (2 << 2)
00210 #define PHYCON2_OP_MODE_10BT_FD     (5 << 2)
00211 #define PHYCON2_OP_MODE_100BTX_FD   (6 << 2)
00212 
00213 //KSZ8041 Ethernet PHY driver
00214 extern const PhyDriver ksz8041PhyDriver;
00215 
00216 //KSZ8041 related functions
00217 error_t ksz8041Init(NetInterface *interface);
00218 
00219 void ksz8041Tick(NetInterface *interface);
00220 
00221 void ksz8041EnableIrq(NetInterface *interface);
00222 void ksz8041DisableIrq(NetInterface *interface);
00223 
00224 void ksz8041EventHandler(NetInterface *interface);
00225 
00226 void ksz8041WritePhyReg(NetInterface *interface, uint8_t address, uint16_t data);
00227 uint16_t ksz8041ReadPhyReg(NetInterface *interface, uint8_t address);
00228 
00229 void ksz8041DumpPhyReg(NetInterface *interface);
00230 
00231 #endif
00232