예제 #1
0
int _EMAC_SetFilterMode(uint8_t * args)
{
	uint8_t * arg_ptr;
	uint32_t ulFilterMode;
	FunctionalState NewState;

	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	ulFilterMode = (uint32_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_SetFilterMode(ulFilterMode, NewState);
	return 0;
}
예제 #2
0
파일: app.c 프로젝트: strahlex/LPC_Ethernet
int main (void)
{
    OS_ERR   os_err;
#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_ERR  cpu_err;
#endif

    BSP_PreInit();                                 /* initialize basic board support routines */

#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_NameSet((CPU_CHAR *)CSP_DEV_NAME,
                (CPU_ERR  *)&cpu_err);
#endif

    Mem_Init();                                       /* Initialize memory management  module */

    OSInit(&os_err);                                                        /* Init uC/OS-III */

//    Debug_printf(Debug_Level_1, "Starting init");
#if 0
    /* Enable Timer0 Interrupt.*/
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_TMR_00,
                   (CPU_FNCT_PTR  )App_TMR0_IntHandler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_TMR_00);

    /* Enable Timer1 Interrupt.*/
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_TMR_01,
                   (CPU_FNCT_PTR  )App_TMR1_IntHandler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_TMR_01);

    /* Enable Timer2 Interrupt.*/
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_TMR_02,
                   (CPU_FNCT_PTR  )App_TMR2_IntHandler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_TMR_02);
    
    CSP_TmrInit();
    CSP_TmrCfg (CSP_TMR_NBR_00,TIMER_FREQ);
    CSP_TmrCfg (CSP_TMR_NBR_01,TIMER_FREQ);
    CSP_TmrCfg (CSP_TMR_NBR_02,TIMER_FREQ);
#endif

#if 0
    // Init the Ethernet PHY
    EMAC_PinCfg();
    emacConfigStruct.Mode = EMAC_MODE_100M_FULL;
    emacConfigStruct.pbEMAC_Addr = EthernetLinkLayer_macAddress();
    OS_EMAC_Init(EthernetLinkLayer_rxSemaphore());
    EMAC_Init(&emacConfigStruct);
    EMAC_SetFilterMode(EMAC_RFC_UCAST_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_BCAST_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_MCAST_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_PERFECT_EN, ENABLE);
    EMAC_SetFilterMode(EMAC_RFC_MAGP_WOL_EN, DISABLE);
    EMAC_SetFilterMode(EMAC_RFC_PFILT_WOL_EN, DISABLE);
    
    // Init the Ethernt interrupt vecotrs
    CSP_IntVectReg((CSP_DEV_NBR   )CSP_INT_CTRL_NBR_MAIN,
                   (CSP_DEV_NBR   )CSP_INT_SRC_NBR_ETHER_00,
                   (CPU_FNCT_PTR  )CSP_IntETH_Handler,
                   (void         *)0);
    CSP_IntEn(CSP_INT_CTRL_NBR_MAIN, CSP_INT_SRC_NBR_ETHER_00);
    
    EthernetLinkLayer_setMacAddress(macAddress);
    Ip_initialize();
    Ip_setIPv4Address(ipv4Address);
#endif

#if 0
    USBInit();                                               /* USB Initialization */
    /* register descriptors */
    USBRegisterDescriptors(abDescriptors);                   /* USB Descriptor Initialization */

    /* register endpoint handlers */
    USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn);           /* register BulkIn Handler for EP */
    USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut);         /* register BulkOut Handler for EP */
    USBHwRegisterEPIntHandler(INT_IN_EP, NULL);

    USBHwEPConfig(BULK_IN_EP, MAX_PACKET_SIZE);   /* Configure Packet Size for outgoing Transfer */
    USBHwEPConfig(BULK_OUT_EP, MAX_PACKET_SIZE);  /* Configure Packet Size for incoming Transfer */

    /* enable bulk-in interrupts on NAKs */
    USBHwNakIntEnable(INACK_BI);
#endif
    //Cb_initialize(&cncQueueBuffer, CNC_QUEUE_BUFFER_SIZE, sizeof(QueueItem), (void*)&cncQueueBufferData);
    
//    Debug_printf(Debug_Level_1, "Init finished");

    if(os_err != OS_ERR_NONE)
        for(;;);

    OSTaskCreate((OS_TCB      *)&App_TaskStartTCB,                  /* Create the Start Task */
                 (CPU_CHAR    *)"Start",
                 (OS_TASK_PTR  )App_TaskStart,
                 (void        *)0,
                 (OS_PRIO      )4,
                 (CPU_STK     *)App_TaskStartStk,
                 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE_LIMIT,
                 (CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
                 (OS_MSG_QTY   )0u,
                 (OS_TICK      )0u,
                 (void        *)0,
                 (OS_OPT       )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR      *)&os_err);

    OSStart(&os_err);                                                   /* Start Multitasking */
    if(os_err != OS_ERR_NONE)                                         /* shall never get here */
        for(;;);
    return (0);
}
예제 #3
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;
}