void main(void) { PHY_init_t phy_params; LINK_init_t link_params; WDTCONbits.SWDTEN = 0; LOG_init(); D_G printf("Main started\n"); phy_params.bitrate = DATA_RATE_66; phy_params.band = BAND_863; phy_params.channel = 28; phy_params.power = TX_POWER_13_DB; phy_params.cca_noise_treshold = 30; PHY_init(phy_params); D_G printf("PHY inicialized\n"); link_params.tx_max_retries = 0; link_params.rx_data_commit_timeout = 64; LINK_init(link_params); ds_prepare(); for (uint8_t i = 0; i < 12; i++) { LED0 = ~LED0; delay_ms(50); } fitp_init(); /* GLOBAL_STORAGE.edid[0] = 0xED; //E GLOBAL_STORAGE.edid[1] = 0x00; //d GLOBAL_STORAGE.edid[2] = 0x00; //i GLOBAL_STORAGE.edid[3] = 0x01; //d GLOBAL_STORAGE.nid[0]=0x4e; //N GLOBAL_STORAGE.nid[1]=0x69; //i GLOBAL_STORAGE.nid[2]=0x64; //d GLOBAL_STORAGE.nid[3]=0x3c; //: */ GLOBAL_STORAGE.sleepy_device = true; euid_load(); // load euid from eeprom refresh_load_eeprom(); accel_int = false; while (1) { if (accel_int) { HW_ReInit(); if (sendValues()) { D_G printf("Send values success\n"); LED1 = 1; delay_ms(1000); LED1 = 0; } else if (fitp_join()){ D_G printf("Join success\n"); LED1 = 1; delay_ms(1000); LED1 = 0; } else { // cannot send data and even join fails D_G printf("Send value and join failed\n"); LED0 = 1; delay_ms(1000); LED0 = 0; } accel_int = false; } if (fitp_joined()){ ds_prepare(); HW_DeInit(); StartTimer(2); goSleep(); if (accel_int) { continue; } //LED1 = 1; HW_ReInit(); sendValues(); } HW_DeInit(); if(GLOBAL_STORAGE.refresh_time < 3) { GLOBAL_STORAGE.refresh_time = 3; // if too short time save_refresh_eeprom(GLOBAL_STORAGE.refresh_time); //save refresh time on eeprom } StartTimer(GLOBAL_STORAGE.refresh_time - 2); // -2 because ds_prepare takes up to 2seconds //LED1 = 0; goSleep(); } }
/** * Starts MAC controller * * @param MAC interface descriptor * @return error code */ err_t MAC_init( struct netif *netif ) { err_t res; #if SPEED_10BASET uint16 mymrdata; //temp variable for MII read data //uint16 reg0; #endif mcf5xxxfec_if_t *fecif = mem_malloc( sizeof( mcf5xxxfec_if_t ) ); if( fecif != NULL ) { /* Global copy used in ISR. */ fecif_g = fecif; fecif->self = ( struct eth_addr * )&netif->hwaddr[0]; fecif->netif = netif; fecif->tx_sem = NULL; fecif->rx_sem = NULL; if( ( fecif->tx_sem = sys_sem_new( 1 ) ) == NULL ) { res = ERR_MEM; } else if( ( fecif->rx_sem = sys_mult_sem_new/*sys_sem_new*/( 0 ) ) == NULL ) { res = ERR_MEM; } else if( sys_thread_new("FEC", MAC_Rx_Task, (void *)fecif, FEC_RX_STACK_SPACE, FEC_TASK_PRIORITY) == NULL ) { res = ERR_MEM; } else { netif->state = fecif; netif->name[0] = 'C'; netif->name[1] = 'F'; netif->hwaddr_len = ETH_ADDR_LEN; netif->mtu = MCF_FEC_MTU; netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; netif->output = MAC_Send; netif->linkoutput = MAC_output_raw; NBUF_init( ); MAC_GetMacAddress(fecif->self ); MAC_Reset( fecif ); #if PHY_ON_CHIP PHY_init(); #endif #if 0 /*FSL:reset the PHY: quick fix*/ while(!MII_write(FEC_PHY0, PHY_REG_CR, 0x8000)) ; //Force reset mymrdata = 0; do { // read if link is up MII_read(FEC_PHY0, PHY_REG_SR, &mymrdata); }while( !(mymrdata&PHY_R1_LS) ); #endif #if SPEED_10BASET while(!(MII_read(FEC_PHY0, PHY_REG_SR, &mymrdata))) ; // read PHY AN Ad register if ((mymrdata & PHY_R1_LS)==1) { //gotlink =1; goto exit; } else { while(!MII_write(FEC_PHY0, PHY_REG_CR, /*mymrdata|*/0x0200)) ; //Force re-negotiation } exit: asm(nop); #endif FEC_SetRxCallback(MAC_ISR); MAC_Enable( fecif ); etharp_init( ); sys_timeout( ARP_TMR_INTERVAL, arp_timer, NULL ); res = ERR_OK; } if( res != ERR_OK ) { /*FSL:change free(fecif) order; from top to bottom*/ //free( fecif ); if( fecif->tx_sem != NULL ) { mem_free( fecif->tx_sem ); } if( fecif->rx_sem != NULL ) { mem_free( fecif->rx_sem ); } mem_free( fecif ); } }