/** Transmit buffer over socket (non blocking). * @param[in] port = port context struct * @param[in] idx = index in tx buffer array * @return socket send result */ int ecx_outframe_red(ecx_portt *port, int idx) { ec_comt *datagramP; ec_etherheadert *ehp; int rval; ehp = (ec_etherheadert *)&(port->txbuf[idx]); /* rewrite MAC source address 1 to primary */ ehp->sa1 = oshw_htons(priMAC[1]); /* transmit over primary socket*/ rval = ecx_outframe(port, idx, 0); if (port->redstate != ECT_RED_NONE) { mtx_lock (port->tx_mutex); ehp = (ec_etherheadert *)&(port->txbuf2); /* use dummy frame for secondary socket transmit (BRD) */ datagramP = (ec_comt*)&(port->txbuf2[ETH_HEADERSIZE]); /* write index to frame */ datagramP->index = idx; /* rewrite MAC source address 1 to secondary */ ehp->sa1 = oshw_htons(secMAC[1]); /* transmit over secondary socket */ //send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0); // OBS! redundant not ACTIVE for BFIN, just added to compile ASSERT (0); bfin_EMAC_send(&(port->txbuf2), port->txbuflength2); mtx_unlock (port->tx_mutex); port->redport->rxbufstat[idx] = EC_BUF_TX; } return rval; }
int ether_post_test(int flags) { uchar buf[64]; int i, value = 0; int length; uint addr; printf("\n--------"); bfin_EMAC_init(NULL, NULL); /* construct the package */ addr = bfin_read_EMAC_ADDRLO(); buf[0] = buf[6] = addr; buf[1] = buf[7] = addr >> 8; buf[2] = buf[8] = addr >> 16; buf[3] = buf[9] = addr >> 24; addr = bfin_read_EMAC_ADDRHI(); buf[4] = buf[10] = addr; buf[5] = buf[11] = addr >> 8; buf[12] = 0x08; /* Type: ARP */ buf[13] = 0x06; buf[14] = 0x00; /* Hardware type: Ethernet */ buf[15] = 0x01; buf[16] = 0x08; /* Protocal type: IP */ buf[17] = 0x00; buf[18] = 0x06; /* Hardware size */ buf[19] = 0x04; /* Protocol size */ buf[20] = 0x00; /* Opcode: request */ buf[21] = 0x01; for (i = 0; i < 42; i++) buf[i + 22] = i; printf("--------Send 64 bytes......\n"); bfin_EMAC_send(NULL, buf, 64); for (i = 0; i < 100; i++) { udelay(10000); if ((rxbuf[rxIdx]->StatusWord & RX_COMP) != 0) { value = 1; break; } } if (value == 0) { printf("--------EMAC can't receive any data\n"); eth_halt(); return -1; } length = rxbuf[rxIdx]->StatusWord & 0x000007FF - 4; for (i = 0; i < length; i++) { if (rxbuf[rxIdx]->FrmData->Dest[i] != buf[i]) { printf("--------EMAC receive error data!\n"); eth_halt(); return -1; } } printf("--------receive %d bytes, matched\n", length); bfin_EMAC_halt(NULL); return 0; }
/** Transmit buffer over socket (non blocking). * @param[in] port = port context struct * @param[in] idx = index in tx buffer array * @param[in] stacknumber = 0=Primary 1=Secondary stack * @return socket send result */ int ecx_outframe(ecx_portt *port, int idx, int stacknumber) { int lp, rval; ec_stackT *stack; if (!stacknumber) { stack = &(port->stack); } else { stack = &(port->redport->stack); } lp = (*stack->txbuflength)[idx]; rval = bfin_EMAC_send((*stack->txbuf)[idx], lp); (*stack->rxbufstat)[idx] = EC_BUF_TX; return rval; }