/** * Initialization for EMAC device. * Should be called at the beginning of the program to set up the * network interface. */ void tapdev_init(void) { sEmacd *pEmacd = &gEmacd; Macb *pMacb = &gMacb; uint32_t dwErrCount = 0 ; volatile uint32_t dwDly; /* Reset PHY */ RSTC_SetExtResetLength(RSTC, 13); /* (2^(13+1))/32768 */ RSTC_ExtReset(RSTC); while(RSTC_GetNrstLevel(RSTC) == 0) {} /* Wait for PHY to be ready (CAT811: Max400ms) */ dwDly = BOARD_MCK / 1000 / 3 * 400; while(dwDly--); /* Init EMAC driver structure */ EMACD_Init(pEmacd, EMAC, ID_EMAC, 0, 0); EMACD_InitTransfer(pEmacd, gpRxBuffer, gRxDs, RX_BUFFERS, gpTxBuffer, gTxDs, gTxCbs, TX_BUFFERS); EMAC_SetAddress(gEmacd.pHw, 0, gMacAddress); /* Enable Interrupt */ NVIC_EnableIRQ( EMAC_IRQn ) ; /* Init MACB driver */ MACB_Init(pMacb, pEmacd, BOARD_EMAC_PHY_ADDR); /* PHY initialize */ if (!MACB_InitPhy(pMacb, BOARD_MCK, gEmacPins, PIO_LISTSIZE(gEmacPins))) { printf( "P: PHY Initialize ERROR!\n\r" ) ; return; } /* Auto Negotiate, work in RMII mode */ if (!MACB_AutoNegotiate(pMacb, BOARD_EMAC_MODE_RMII)) { printf( "P: Auto Negotiate ERROR!\n\r" ) ; return; } while ( MACB_GetLinkSpeed( pMacb, 1 ) == 0 ) { dwErrCount++; } printf( "P: Link detected \n\r" ) ; }
//------------------------------------------------------------------------------ /// Application entry point. Configures the DBGU, PIT, TC0, LEDs and buttons /// and makes LED\#1 blink in its infinite loop, using the Wait function. /// \return Unused (ANSI-C compatibility). //------------------------------------------------------------------------------ int main(void) { // DBGU configuration TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK); TRACE_INFO_WP("\n\r"); TRACE_INFO("Getting new Started Project --\n\r"); TRACE_INFO("%s\n\r", BOARD_NAME); TRACE_INFO("Compiled: %s %s --\n\r", __DATE__, __TIME__); //Configure Reset Controller AT91C_BASE_RSTC->RSTC_RMR= 0xa5<<24; // Configure EMAC PINS PIO_Configure(emacRstPins, PIO_LISTSIZE(emacRstPins)); // Execute reset RSTC_SetExtResetLength(0xd); RSTC_ExtReset(); // Wait for end hardware reset while (!RSTC_GetNrstLevel()); TRACE_INFO("init Flash\n\r"); flash_init(); TRACE_INFO("init Timer\n\r"); // Configure timer 0 ticks=0; extern void ISR_Timer0(); AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0); AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF; AT91C_BASE_TC0->TC_SR; AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV5_CLOCK | AT91C_TC_CPCTRG; AT91C_BASE_TC0->TC_RC = 375; AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; AIC_ConfigureIT(AT91C_ID_TC0, AT91C_AIC_PRIOR_LOWEST, ISR_Timer0); AIC_EnableIT(AT91C_ID_TC0); AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // Configure timer 1 extern void ISR_Timer1(); AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC1); AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; //Stop clock AT91C_BASE_TC1->TC_IDR = 0xFFFFFFFF; //Disable Interrupts AT91C_BASE_TC1->TC_SR; //Read Status register AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV4_CLOCK | AT91C_TC_CPCTRG; // Timer1: 2,666us = 48MHz/128 AT91C_BASE_TC1->TC_RC = 0xffff; AT91C_BASE_TC1->TC_IER = AT91C_TC_CPCS; AIC_ConfigureIT(AT91C_ID_TC1, 1, ISR_Timer1); AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; led_init(); TRACE_INFO("init EEprom\n\r"); eeprom_init(); rb_reset(&TTY_Rx_Buffer); rb_reset(&TTY_Tx_Buffer); input_handle_func = analyze_ttydata; LED_OFF(); LED2_OFF(); LED3_OFF(); spi_init(); fht_init(); tx_init(); #ifdef HAS_ETHERNET ethernet_init(); #endif TRACE_INFO("init USB\n\r"); CDCDSerialDriver_Initialize(); USBD_Connect(); wdt_enable(WDTO_2S); fastrf_on=0; display_channel = DISPLAY_USB; TRACE_INFO("init Complete\n\r"); checkFrequency(); // Main loop while (1) { CDC_Task(); Minute_Task(); RfAnalyze_Task(); #ifdef HAS_FASTRF FastRF_Task(); #endif #ifdef HAS_RF_ROUTER rf_router_task(); #endif #ifdef HAS_ASKSIN rf_asksin_task(); #endif #ifdef HAS_MORITZ rf_moritz_task(); #endif #ifdef HAS_RWE rf_rwe_task(); #endif #ifdef HAS_MBUS rf_mbus_task(); #endif #ifdef HAS_MAICO rf_maico_task(); #endif #ifdef HAS_ETHERNET Ethernet_Task(); #endif #ifdef DBGU_UNIT_IN if(DBGU_IsRxReady()){ unsigned char volatile * const ram = (unsigned char *) AT91C_ISRAM; unsigned char x; x=DBGU_GetChar(); switch(x) { case 'd': puts("USB disconnect\n\r"); USBD_Disconnect(); break; case 'c': USBD_Connect(); puts("USB Connect\n\r"); break; case 'r': //Configure Reset Controller AT91C_BASE_RSTC->RSTC_RMR=AT91C_RSTC_URSTEN | 0xa5<<24; break; case 'S': USBD_Disconnect(); my_delay_ms(250); my_delay_ms(250); //Reset *ram = 0xaa; AT91C_BASE_RSTC->RSTC_RCR = AT91C_RSTC_PROCRST | AT91C_RSTC_PERRST | AT91C_RSTC_EXTRST | 0xA5<<24; while (1); break; default: rb_put(&TTY_Tx_Buffer, x); } } #endif if (USBD_GetState() == USBD_STATE_CONFIGURED) { if( USBState == STATE_IDLE ) { CDCDSerialDriver_Read(usbBuffer, DATABUFFERSIZE, (TransferCallback) UsbDataReceived, 0); LED3_ON(); USBState=STATE_RX; } } if( USBState == STATE_SUSPEND ) { TRACE_INFO("suspend !\n\r"); USBState = STATE_IDLE; } if( USBState == STATE_RESUME ) { TRACE_INFO("resume !\n\r"); USBState = STATE_IDLE; } } }