int _EMAC_SetHashFilter(uint8_t * args) { uint8_t * arg_ptr; uint8_t* dstMAC_addr; FunctionalState NewState; if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; dstMAC_addr = (uint8_t*) strtoul((char *) arg_ptr, NULL, 16); if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1; NewState = (FunctionalState) strtoul((char *) arg_ptr, NULL, 16); EMAC_SetHashFilter(dstMAC_addr, NewState); return 0; }
/***************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { /* Data Packet format */ EMAC_PACKETBUF_Type DataPacket; uint8_t *txptr; uint32_t i = 0; #if TX_ONLY uint32_t j; #endif #if BOUNCE_RX uint8_t *rxptr; #endif #if ENABLE_HASH uint8_t dstAddr[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; #endif /* Initialize system clock */ SystemInit(); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif NVIC_SetPriorityGrouping(4); //sets PRIGROUP to 3:2 (XXX:YY) /* * Init LED */ LED_Init(); /* * Initialize debug via UART */ debug_frmwrk_init(); // Init EMAC Usr_Init_Emac(); #if TX_ONLY EINT0_Init(); txptr = (uint8_t *)gTxBuf; /* pre-format the transmit packets */ PacketGen(txptr); #endif #if ENABLE_HASH EMAC_SetHashFilter(dstAddr, ENABLE); #endif #if BOUNCE_RX /* copy just received data from RX buffer to TX buffer and send out */ txptr = (uint8_t *)gTxBuf; rxptr = (uint8_t *)gRxBuf; #endif #if ENABLE_WOL _DBG_("Enter Sleep mode now..."); /* * On default state, All Multicast frames, All Broadcast frames and Frame that matched * with station address (unicast) are accepted. * To make WoL is possible, enable Rx Magic Packet and RxFilter Enable WOL */ EMAC_SetFilterMode((EMAC_RFC_PFILT_WOL_EN | EMAC_RFC_MAGP_WOL_EN), ENABLE); for (i = 0; i < 5; i++){ LED_Blink(PD_LED_PIN); /* Indicating system is in power down now. */ } // Disable irq interrupt __disable_irq(); /* Currently, support Sleep mode */ /* enter sleep mode */ LPC_SC->PCON = 0x0; /* Sleep Mode*/ __WFI(); // CPU will be suspend here... /* From power down to WOL, the PLL needs to be reconfigured, otherwise, the CCLK will be generated from 4Mhz IRC instead of main OSC 12Mhz */ /* Initialize system clock */ SystemInit(); /* * Initialize debug via UART */ debug_frmwrk_init(); /* * Init LED */ LED_Init(); _DBG_("Wake up from sleep mode"); /* Calling EMACInit() is overkill which also initializes the PHY, the main reason to do that is to make sure the descriptors and descriptor status for both TX and RX are clean and ready to use. It won't go wrong. */ Usr_Init_Emac(); // Re-Enable irq interrupt __enable_irq(); #endif /* endif ENABLE_WOL */ #if BOUNCE_RX while( 1 ) { LED_Blink(BLINK_LED_PIN); if ( PacketReceived == TRUE ) { PacketReceived = FALSE; /* Reverse Source and Destination, then copy the body */ memcpy( (uint8_t *)txptr, (uint8_t *)(rxptr+6), 6); memcpy( (uint8_t *)(txptr+6), (uint8_t *)rxptr, 6); memcpy( (uint8_t *)(txptr+12), (uint8_t *)(rxptr+12), (ReceiveLength - 12)); _DBG_("Send packet"); DataPacket.pbDataBuf = (uint32_t *)txptr; DataPacket.ulDataLen = ReceiveLength; EMAC_WritePacketBuffer(&DataPacket); EMAC_UpdateTxProduceIndex(); } } #endif /* endif BOUNCE_RX */ #if TX_ONLY /* Transmit packets only */ while ( 1 ) { while (Pressed == RESET){ LED_Blink(BLINK_LED_PIN); } Pressed = RESET; txptr = (uint8_t *)gTxBuf; _DBG_("Send packet"); LED_Blink(TX_LED_PIN); DataPacket.pbDataBuf = (uint32_t *)txptr; // Note that there're 4-byte CRC added DataPacket.ulDataLen = TX_PACKET_SIZE + 4; EMAC_WritePacketBuffer(&DataPacket); EMAC_UpdateTxProduceIndex(); for ( j = 0; j < 0x200000; j++ ); /* delay */ } #endif /* endif TX_ONLY */ return 0; }