33 #ifdef __BUILD_WITH_EXAMPLE__
34 #include "lpc17xx_libcfg.h"
48 const uint8_t EMAC_clkdiv[] = { 4, 6, 8, 10, 14, 20, 28 };
56 #if defined ( __CC_ARM )
58 #elif defined ( __ICCARM__ )
59 #pragma data_alignment=8
61 #elif defined ( __GNUC__ )
82 static
void rx_descr_init (
void);
83 static
void tx_descr_init (
void);
84 static int32_t write_PHY (uint32_t PhyReg, uint16_t Value);
85 static int32_t read_PHY (uint32_t PhyReg);
87 static
void setEmacAddr(uint8_t abStationAddr[]);
88 static int32_t emac_CRCCalc(uint8_t frame_no_fcs[], int32_t frame_len);
97 static
void rx_descr_init (
void)
103 Rx_Desc[i].
Packet = (uint32_t)&rx_buf[i];
106 Rx_Stat[i].HashCRC = 0;
110 LPC_EMAC->RxDescriptor = (uint32_t)&Rx_Desc[0];
111 LPC_EMAC->RxStatus = (uint32_t)&Rx_Stat[0];
112 LPC_EMAC->RxDescriptorNumber = EMAC_NUM_RX_FRAG - 1;
125 static void tx_descr_init (
void) {
130 Tx_Desc[i].Packet = (uint32_t)&tx_buf[i];
137 LPC_EMAC->TxDescriptor = (uint32_t)&Tx_Desc[0];
138 LPC_EMAC->TxStatus = (uint32_t)&Tx_Stat[0];
139 LPC_EMAC->TxDescriptorNumber = EMAC_NUM_TX_FRAG - 1;
154 static int32_t write_PHY (uint32_t PhyReg, uint16_t Value)
181 static int32_t read_PHY (uint32_t PhyReg)
207 static void setEmacAddr(uint8_t abStationAddr[])
210 LPC_EMAC->SA0 = ((uint32_t)abStationAddr[5] << 8) | (uint32_t)abStationAddr[4];
211 LPC_EMAC->SA1 = ((uint32_t)abStationAddr[3] << 8) | (uint32_t)abStationAddr[2];
212 LPC_EMAC->SA2 = ((uint32_t)abStationAddr[1] << 8) | (uint32_t)abStationAddr[0];
222 static int32_t emac_CRCCalc(uint8_t frame_no_fcs[], int32_t frame_len)
230 for (i = 0; i < frame_len; i++) {
231 byte = *frame_no_fcs++;
232 for (j = 0; j < 2; j++) {
233 if (((crc >> 28) ^ (byte >> 3)) & 0x00000001) {
238 if (((crc >> 29) ^ (byte >> 2)) & 0x00000001) {
243 if (((crc >> 30) ^ (byte >> 1)) & 0x00000001) {
248 if (((crc >> 31) ^ (byte >> 0)) & 0x00000001) {
253 crc = (crc << 4) ^ q3 ^ q2 ^ q1 ^ q0;
290 int32_t regv,tout, tmp;
302 for (tout = 100; tout; tout--);
312 for (tout = 0; tout <
sizeof (EMAC_clkdiv); tout++){
313 if (EMAC_clkdiv[tout] >= tmp)
break;
329 for (tout = 100; tout; tout--);
430 #elif defined(IAR_LPC_1768)
467 int32_t id1, id2, tout, regv;
478 #elif defined(IAR_LPC_1768)
479 if (((id1 << 16) | id2) == EMAC_KSZ8721BL_ID) {
580 #elif defined(IAR_LPC_1768)
644 crc = emac_CRCCalc(dstMAC_addr, 6);
646 crc = (crc >> 23) & 0x3F;
648 pReg = (crc > 31) ? ((uint32_t *)&
LPC_EMAC->HashFilterH) \
649 : ((uint32_t *)&
LPC_EMAC->HashFilterL);
650 tmp = (crc > 31) ? (crc - 32) : crc;
652 (*pReg) |= (1UL << tmp);
654 (*pReg) &= ~(1UL << tmp);
690 LPC_EMAC->RxFilterCtrl |= ulFilterMode;
692 LPC_EMAC->RxFilterCtrl &= ~ulFilterMode;
715 if (
LPC_EMAC->RxFilterWoLStatus & ulWoLMode) {
716 LPC_EMAC->RxFilterWoLClear = ulWoLMode;
739 dp = ((uint8_t *)Tx_Desc[idx].Packet) + Tx_Len[idx];
741 for (len = pDataStruct->
ulDataLen; len; len--) {
766 sp = (uint32_t *)Rx_Desc[idx].
Packet;
769 for (len = (pDataStruct->
ulDataLen + 3) >> 2; len; len--) {
798 LPC_EMAC->IntEnable &= ~(ulIntType);
821 if (
LPC_EMAC->IntStatus & ulIntType) {
862 uint32_t tmp =
LPC_EMAC->TxConsumeIndex -1;
863 if (
LPC_EMAC->TxProduceIndex == tmp) {
894 return (((Rx_Stat[idx].Info) & ulRxStatType) ?
SET :
RESET);
921 uint32_t idx =
LPC_EMAC->RxConsumeIndex;
924 if (++idx == EMAC_NUM_RX_FRAG) idx = 0;
938 uint32_t idx =
LPC_EMAC->TxProduceIndex;