static void rza1_phy_task(void *arg) { struct netif *netif = (struct netif*)arg; s32_t connect_sts = 0; /* 0: disconnect, 1:connect */ s32_t link_sts; s32_t link_mode_new = NEGO_FAIL; s32_t link_mode_old = NEGO_FAIL; while (1) { link_sts = ethernet_link(); if (link_sts == 1) { link_mode_new = ethernetext_chk_link_mode(); if (link_mode_new != link_mode_old) { if (connect_sts == 1) { tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1); } if (link_mode_new != NEGO_FAIL) { ethernetext_set_link_mode(link_mode_new); tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1); connect_sts = 1; } } } else { if (connect_sts != 0) { tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1); link_mode_new = NEGO_FAIL; connect_sts = 0; } } link_mode_old = link_mode_new; osDelay(PHY_TASK_WAIT); } }
static NyLPC_TBool start(const struct NyLPC_TEthAddr* i_eth_addr,NyLPC_TiEthernetDevice_onEvent i_handler,void* i_param) { int i; //ISRw割り込み設定 NyLPC_cIsr_setEnetISR(emacIsrHandler); _event_handler=i_handler; _event_param=i_param; /* Set the Ethernet MAC Address registers */ LPC_EMAC->SA0 = (((uint32_t)(i_eth_addr->addr[0])) << 8 ) | i_eth_addr->addr[1]; LPC_EMAC->SA1 = (((uint32_t)(i_eth_addr->addr[2])) << 8 ) | i_eth_addr->addr[3]; LPC_EMAC->SA2 = (((uint32_t)(i_eth_addr->addr[4])) << 8 ) | i_eth_addr->addr[5]; //TXメモリマネージャの準備 NyLPC_cEthernetMM_initialize(ETH_TX_BUF_BASE); /* Initialize Tx and Rx DMA Descriptors */ prevRxDescriptor(); prevTxDescriptor(); //wait for link up for(i=0;i<5;i++){ if(ethernet_link()!=0){ break; } NyLPC_cThread_sleep(emacWAIT_FOR_LINK_TO_ESTABLISH_MS); } //setup Link ethernet_set_link(-1, 0); LPC_EMAC->RxFilterCtrl = RFC_UCAST_EN | RFC_MCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN; /* Receive Broadcast, Perfect Match Packets */ //Ethernetの割込み開始設定 NyLPC_cIsr_enterCritical(); { LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; /* Enable EMAC interrupts. */ LPC_EMAC->IntClear = 0xFFFF; /* Reset all interrupts */ LPC_EMAC->Command |= (CR_RX_EN | CR_TX_EN); /* Enable receive and transmit mode of MAC Ethernet core */ LPC_EMAC->MAC1 |= MAC1_REC_EN; NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY ); NVIC_EnableIRQ( ENET_IRQn ); } NyLPC_cIsr_exitCritical(); return NyLPC_TBool_TRUE; }
int ethernet_send() { #if NEW_LOGIC if(tx_produce_offset < 0) { // no buffer active return -1; } // ensure there is a link if(!ethernet_link()) { return -2; } // we have been writing in to a buffer, so finalise it int size = tx_produce_offset; int index = LPC_EMAC->TxProduceIndex; txdesc[index].Ctrl = (tx_produce_offset-1) | (TCTRL_INT | TCTRL_LAST); // Increment ProduceIndex to allow it to be sent // We can only do this if the next slot is free int next = rinc(index, NUM_TX_FRAG); while(next == LPC_EMAC->TxConsumeIndex) { for(int i=0; i<1000; i++) { __NOP(); } } LPC_EMAC->TxProduceIndex = next; tx_produce_offset = -1; return size; #else int s = send_size; txdesc[send_idx].Ctrl = (send_doff-1) | (TCTRL_INT | TCTRL_LAST); send_idx = rinc(send_idx, NUM_TX_FRAG); LPC_EMAC->TxProduceIndex = send_idx; send_doff = 0; send_idx = -1; send_size = 0; return s; #endif }