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_ALIGNED(32) static sGmacTxDescriptor gTxDs[TX_BUFFERS], gDummyTxDs[DUMMY_SIZE];
00071
00072
00073 COMPILER_ALIGNED(32) static fGmacdTransferCallback gTxCbs[TX_BUFFERS], gDummyTxCbs[DUMMY_SIZE];
00074
00075
00076 COMPILER_ALIGNED(32) static sGmacRxDescriptor gRxDs[RX_BUFFERS], gDummyRxDs[DUMMY_SIZE];
00077
00078
00079
00080
00081
00082 COMPILER_ALIGNED(32) static uint8_t pTxBuffer[TX_BUFFERS * BUFFER_SIZE], pTxDummyBuffer[DUMMY_SIZE * DUMMY_BUFF_SIZE];
00083
00084
00085 COMPILER_ALIGNED(32) static uint8_t pRxBuffer[RX_BUFFERS * BUFFER_SIZE], pRxDummyBuffer[DUMMY_SIZE * DUMMY_BUFF_SIZE];
00086
00087
00088 static uint8_t gGMacAddress[6] = {0x00, 0x45, 0x56, 0x78, 0x9a, 0xbc};
00089
00090
00091
00092
00093
00094
00095
00096
00097 void GMAC_Handler(void)
00098 {
00099 GMACD_Handler(&gGmacd, GMAC_QUE_0);
00100 }
00101
00102
00103
00104
00105
00106
00107 void gmac_tapdev_setmac(u8_t *addr)
00108 {
00109 gGMacAddress[0] = addr[0];
00110 gGMacAddress[1] = addr[1];
00111 gGMacAddress[2] = addr[2];
00112 gGMacAddress[3] = addr[3];
00113 gGMacAddress[4] = addr[4];
00114 gGMacAddress[5] = addr[5];
00115 }
00116
00117
00118
00119
00120
00121
00122 void gmac_tapdev_init(void)
00123 {
00124 sGmacd *pGmacd = &gGmacd;
00125 GMacb *pGmacb = &gGmacb;
00126 sGmacInit Que0, Que;
00127
00128
00129
00130 memset(&Que0, 0, sizeof(Que0));
00131 Que0.bIsGem = 1;
00132 Que0.bDmaBurstLength = 4;
00133 Que0.pRxBuffer =pRxBuffer;
00134 Que0.pRxD = gRxDs;
00135 Que0.wRxBufferSize = BUFFER_SIZE;
00136 Que0.wRxSize = RX_BUFFERS;
00137 Que0.pTxBuffer = pTxBuffer;
00138 Que0.pTxD = gTxDs;
00139 Que0.wTxBufferSize = BUFFER_SIZE;
00140 Que0.wTxSize = TX_BUFFERS;
00141 Que0.pTxCb = gTxCbs;
00142
00143
00144
00145 memset(&Que, 0, sizeof(Que));
00146 Que.bIsGem = 1;
00147 Que.bDmaBurstLength = 4;
00148 Que.pRxBuffer =pRxDummyBuffer;
00149 Que.pRxD = gDummyRxDs;
00150 Que.wRxBufferSize = DUMMY_BUFF_SIZE;
00151 Que.wRxSize = DUMMY_SIZE;
00152 Que.pTxBuffer = pTxDummyBuffer;
00153 Que.pTxD = gDummyTxDs;
00154 Que.wTxBufferSize = DUMMY_BUFF_SIZE;
00155 Que.wTxSize = DUMMY_SIZE;
00156 Que.pTxCb = gDummyTxCbs;
00157
00158
00159 GMACD_Init(pGmacd, GMAC, ID_GMAC, GMAC_CAF_ENABLE, GMAC_NBC_DISABLE);
00160 GMACD_InitTransfer(pGmacd, &Que, GMAC_QUE_2);
00161
00162 GMACD_InitTransfer(pGmacd, &Que, GMAC_QUE_1);
00163
00164 GMACD_InitTransfer(pGmacd, &Que0, GMAC_QUE_0);
00165 GMAC_SetAddress(gGmacd.pHw, 0, gGMacAddress);
00166
00167
00168
00169 NVIC_ClearPendingIRQ(GMAC_IRQn);
00170 NVIC_EnableIRQ(GMAC_IRQn);
00171
00172
00173 GMACB_Init(pGmacb, pGmacd, BOARD_GMAC_PHY_ADDR);
00174
00175
00176 if (!GMACB_InitPhy(pGmacb, BOARD_MCK, &gmacResetPin, 1, gmacPins, PIO_LISTSIZE( gmacPins )))
00177 {
00178 printf( "P: PHY Initialize ERROR!\n\r" ) ;
00179 return;
00180 }
00181
00182
00183 if (!GMACB_AutoNegotiate(pGmacb))
00184 {
00185 printf( "P: Auto Negotiate ERROR!\n\r" ) ;
00186 return;
00187 }
00188
00189
00190 printf( "P: Link detected \n\r" ) ;
00191 }
00192
00193
00194
00195
00196 uint32_t gmac_tapdev_read( void )
00197 {
00198 uint32_t pkt_len = 0 ;
00199 if ( GMACD_OK != GMACD_Poll( &gGmacd, (uint8_t*)uip_buf, UIP_CONF_BUFFER_SIZE, &pkt_len, GMAC_QUE_0) )
00200 {
00201 pkt_len = 0 ;
00202 }
00203 return pkt_len ;
00204 }
00205
00206
00207
00208
00209 void gmac_tapdev_send( void )
00210 {
00211 uint8_t gmac_rc ;
00212
00213 gmac_rc = GMACD_Send( &gGmacd, (void*)uip_buf, uip_len, NULL, GMAC_QUE_0) ;
00214 if ( gmac_rc != GMACD_OK )
00215 {
00216 TRACE_ERROR( "E: Send, rc 0x%x\n\r", gmac_rc ) ;
00217 }
00218 }
00219