00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "board.h"
00035
00036 #include "uip.h"
00037 #include "uip_arp.h"
00038 #include "string.h"
00039 #include "gmac_tapdev.h"
00040
00041
00042
00043
00044 #define TX_BUFFERS 32
00045 #define RX_BUFFERS 32
00046 #define BUFFER_SIZE 1536
00047 #define DUMMY_SIZE 2
00048 #define DUMMY_BUFF_SIZE 512
00049
00050
00051 #define GMAC_CAF_DISABLE 0
00052 #define GMAC_CAF_ENABLE 1
00053 #define GMAC_NBC_DISABLE 0
00054 #define GMAC_NBC_ENABLE 1
00055
00056
00057
00058
00059
00060 static const Pin gmacPins[] = {BOARD_GMAC_RUN_PINS};
00061 static const Pin gmacResetPin = BOARD_GMAC_RESET_PIN;
00062
00063
00064 COMPILER_ALIGNED(32) static sGmacd gGmacd;
00065
00066
00067 COMPILER_ALIGNED(32) static GMacb gGmacb;
00068
00069
00070 COMPILER_SECTION(".ram_nocache")
00071 COMPILER_ALIGNED(32) static sGmacTxDescriptor gTxDs[TX_BUFFERS], gDummyTxDs[DUMMY_SIZE];
00072
00073
00074 COMPILER_ALIGNED(32) static fGmacdTransferCallback gTxCbs[TX_BUFFERS], gDummyTxCbs[DUMMY_SIZE];
00075
00076
00077 COMPILER_SECTION(".ram_nocache")
00078 COMPILER_ALIGNED(32) static sGmacRxDescriptor gRxDs[RX_BUFFERS], gDummyRxDs[DUMMY_SIZE];
00079
00080
00081
00082
00083
00084 COMPILER_ALIGNED(32) static uint8_t pTxBuffer[TX_BUFFERS * BUFFER_SIZE], pTxDummyBuffer[DUMMY_SIZE * DUMMY_BUFF_SIZE];
00085
00086
00087 COMPILER_ALIGNED(32) static uint8_t pRxBuffer[RX_BUFFERS * BUFFER_SIZE], pRxDummyBuffer[DUMMY_SIZE * DUMMY_BUFF_SIZE];
00088
00089
00090 static uint8_t gGMacAddress[6] = {0x00, 0x45, 0x56, 0x78, 0x9a, 0xbc};
00091
00092
00093
00094
00095
00096
00097
00098
00099 void GMAC_Handler(void)
00100 {
00101 GMACD_Handler(&gGmacd, GMAC_QUE_0);
00102 }
00103
00104
00105
00106
00107
00108
00109 void gmac_tapdev_setmac(u8_t *addr)
00110 {
00111 gGMacAddress[0] = addr[0];
00112 gGMacAddress[1] = addr[1];
00113 gGMacAddress[2] = addr[2];
00114 gGMacAddress[3] = addr[3];
00115 gGMacAddress[4] = addr[4];
00116 gGMacAddress[5] = addr[5];
00117 }
00118
00119
00120
00121
00122
00123
00124 void gmac_tapdev_init(void)
00125 {
00126 sGmacd *pGmacd = &gGmacd;
00127 GMacb *pGmacb = &gGmacb;
00128 sGmacInit Que0, Que;
00129
00130
00131
00132 memset(&Que0, 0, sizeof(Que0));
00133 Que0.bIsGem = 1;
00134 Que0.bDmaBurstLength = 4;
00135 Que0.pRxBuffer =pRxBuffer;
00136 Que0.pRxD = gRxDs;
00137 Que0.wRxBufferSize = BUFFER_SIZE;
00138 Que0.wRxSize = RX_BUFFERS;
00139 Que0.pTxBuffer = pTxBuffer;
00140 Que0.pTxD = gTxDs;
00141 Que0.wTxBufferSize = BUFFER_SIZE;
00142 Que0.wTxSize = TX_BUFFERS;
00143 Que0.pTxCb = gTxCbs;
00144
00145
00146
00147 memset(&Que, 0, sizeof(Que));
00148 Que.bIsGem = 1;
00149 Que.bDmaBurstLength = 4;
00150 Que.pRxBuffer =pRxDummyBuffer;
00151 Que.pRxD = gDummyRxDs;
00152 Que.wRxBufferSize = DUMMY_BUFF_SIZE;
00153 Que.wRxSize = DUMMY_SIZE;
00154 Que.pTxBuffer = pTxDummyBuffer;
00155 Que.pTxD = gDummyTxDs;
00156 Que.wTxBufferSize = DUMMY_BUFF_SIZE;
00157 Que.wTxSize = DUMMY_SIZE;
00158 Que.pTxCb = gDummyTxCbs;
00159
00160
00161 GMACD_Init(pGmacd, GMAC, ID_GMAC, GMAC_CAF_ENABLE, GMAC_NBC_DISABLE);
00162 GMACD_InitTransfer(pGmacd, &Que, GMAC_QUE_2);
00163
00164 GMACD_InitTransfer(pGmacd, &Que, GMAC_QUE_1);
00165
00166 GMACD_InitTransfer(pGmacd, &Que0, GMAC_QUE_0);
00167 GMAC_SetAddress(gGmacd.pHw, 0, gGMacAddress);
00168
00169
00170
00171 NVIC_ClearPendingIRQ(GMAC_IRQn);
00172 NVIC_EnableIRQ(GMAC_IRQn);
00173
00174
00175 GMACB_Init(pGmacb, pGmacd, BOARD_GMAC_PHY_ADDR);
00176
00177
00178 if (!GMACB_InitPhy(pGmacb, BOARD_MCK, &gmacResetPin, 1, gmacPins, PIO_LISTSIZE( gmacPins )))
00179 {
00180 printf( "P: PHY Initialize ERROR!\n\r" ) ;
00181 return;
00182 }
00183
00184
00185 if (!GMACB_AutoNegotiate(pGmacb))
00186 {
00187 printf( "P: Auto Negotiate ERROR!\n\r" ) ;
00188 return;
00189 }
00190
00191
00192 printf( "P: Link detected \n\r" ) ;
00193 }
00194
00195
00196
00197
00198 uint32_t gmac_tapdev_read( void )
00199 {
00200 uint32_t pkt_len = 0 ;
00201 if ( GMACD_OK != GMACD_Poll( &gGmacd, (uint8_t*)uip_buf, UIP_CONF_BUFFER_SIZE, &pkt_len, GMAC_QUE_0) )
00202 {
00203 pkt_len = 0 ;
00204 }
00205 return pkt_len ;
00206 }
00207
00208
00209
00210
00211 void gmac_tapdev_send( void )
00212 {
00213 uint8_t gmac_rc ;
00214
00215 gmac_rc = GMACD_Send( &gGmacd, (void*)uip_buf, uip_len, NULL, GMAC_QUE_0) ;
00216 if ( gmac_rc != GMACD_OK )
00217 {
00218 TRACE_ERROR( "E: Send, rc 0x%x\n\r", gmac_rc ) ;
00219 }
00220 }
00221