Example #1
0
void devnet_framedelay(int nframes, int whichifc)
{
    int frame_usecs = (1E6 * nframes * devnet_getmaxfsz(whichifc) * 8)
            / (devnet_getspeed(whichifc) * 1024);

    xudelay(frame_usecs);
}
void
nic_hdlr(int evt)
{
	int	whichifc;
	uchar	src_addr[16+1];
	uchar	rxbuf[MAX_FRAMEBYTES];
	uchar	*tdataptr;
	ulong 	tframelen;
	ulong   rx_frame_size;


        /*      Lower 12 bits of interrupt code specify IFC #   */
        whichifc = evt & 0xFFF;
        rx_frame_size = devnet_getmaxfsz(whichifc);
        devnet_recv(&rxbuf[0], rx_frame_size, whichifc);
	memmove(&src_addr, (uchar *)&rxbuf[0], 16);

	/*	Get payload and length		*/
	tdataptr = (uchar *)&rxbuf[0]+37;

	tframelen = 0;
	tframelen |= rxbuf[32] << 24;
	tframelen |= rxbuf[33] << 16;
	tframelen |= rxbuf[34] << 8;
	tframelen |= rxbuf[35];

	memmove((void *)&fb1, tdataptr, sizeof(fb1));
	sample_flag = 1;

	/*
	print("swradio-lpf [%s] : Just got frame from node [%s], length [%d]\n",\
		NIC_OUI, &src_addr[0], tframelen);
	print("fb1.rpos = [%d], fb1.rlen = [%d]\n", fb1.rpos, fb1.rlen);
	*/


	return;
}
Example #3
0
int devlogicalnoc_xmit_sleep(uchar dst, uchar src_logical_addr, uchar* data,
        int nbytes, unsigned int sleep)
{
    int framesize;
    int i;
    uchar *tptr;
    ulong ifc_shift_offset = (0 & 0xFFF) << 4;
    ulong savedSR;

    //@@printf("in devnet_xmit, sending [%d] bytes to [%s], proto [%d], via ifc [%d]\n", nbytes, dst, proto, whichifc);

    /*  Save SR, then disable intrs:    */
    savedSR = getpsr();
    splhi();

    /*  Save the dst for future use */
    *(NIC_DST + ifc_shift_offset) = dst;

    framesize = devnet_getmaxfsz(0);

    framesize -= 1;//one information byte

    //  Write data
    tptr = data;
    while (nbytes > 0)
    {
        *(NIC_TDR + ifc_shift_offset) = src_logical_addr;//socket information flit

        for (i = 0; i < min(nbytes, framesize); i++)
        {
            *(NIC_TDR + ifc_shift_offset) = *tptr++;
        }
        if (nbytes < framesize)
            devmac_ctl(NIC_NCR_WRITE, NIC_CMD_TRANSMIT, 0);

        //failed to send, do it again
        while ((*(NIC_NSR + ifc_shift_offset)) & 0x1)
        {
            //printf("Failed to send %d \n", dst);
            devmac_ctl(NIC_NCR_WRITE, NIC_CMD_TRANSMIT, 0);
        }

        //printf("sending: n = %d, f = %d %d\n", nbytes, i, dst);
        nbytes -= i;

    }

    //send closing link message
    if (sleep > 0)
    {
        *(NIC_TDR + ifc_shift_offset) = (1 << 7);
        *(NIC_TDR + ifc_shift_offset) = (sleep) & 0xFF;
        *(NIC_TDR + ifc_shift_offset) = (sleep >> 8) & 0xFF;
        *(NIC_TDR + ifc_shift_offset) = (sleep >> 16) & 0xFF;
        *(NIC_TDR + ifc_shift_offset) = (sleep >> 24) & 0xFF;

        devmac_ctl(NIC_NCR_WRITE, NIC_CMD_TRANSMIT, 0);
        //failed to send, do it again
        while ((*(NIC_NSR + ifc_shift_offset)) & 0x1)
        {
            devmac_ctl(NIC_NCR_WRITE, NIC_CMD_TRANSMIT, 0);
        }
    }
Example #4
0
int devnet_xmit(uchar *dst, uchar proto, uchar *data, int nbytes, int whichifc)
{
    int framesize;
    int n = 0, i;
    uchar *tptr;
    ulong ifc_shift_offset = (whichifc & 0xFFF) << 4;
    ulong savedSR;

    //@@printf("in devnet_xmit, sending [%d] bytes to [%s], proto [%d], via ifc [%d]\n", nbytes, dst, proto, whichifc);

    /*	Save SR, then disable intrs:	*/
    savedSR = getpsr();
    splhi();

    /*	Save the dst for future use	*/
    for (i = 0; i < 16; i++)
    {
        *(NIC_DST + ifc_shift_offset + i) = *(dst + i);
    }

    /*	Write 16 byte src_addr	    	*/
    for (i = 0; i < 16; i++)
    {
        *(NIC_TDR + ifc_shift_offset) = *(NIC_OUI + i);
    }
    n += 16;

    /*	Write 16 byte dst_addr	    	*/
    for (i = 0; i < 16; i++)
    {
        *(NIC_TDR + ifc_shift_offset) = *(dst + i);
        //printf("devnet_xmit(), *(dst+i) = [%d]\n", *(dst+i));
    }
    n += 16;

    /*	Write 4 byte payloadlen	    	*/
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 24) & 0xFF;
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 16) & 0xFF;
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 8) & 0xFF;
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 0) & 0xFF;
    n += 4;

    /*	Write 1 byte nexthdr		*/
    *(NIC_TDR + ifc_shift_offset) = proto;
    n += 1;

    /*					*/
    /*	The 32 bit cksum added by hw	*/
    /*	is not counted as part of fsz	*/
    /*					*/
    framesize = devnet_getmaxfsz(whichifc);

    /*	Write data	    	*/
    tptr = data;
    for (i = 0; (i < nbytes) && (n < framesize); i++)
    {
        *(NIC_TDR + ifc_shift_offset) = *tptr++;
        n++;
    }

    /*	if nbytes+header size was more than a frame, recurse	*/
    if (nbytes + 16 + 16 + 4 + 1 > framesize)
    {
        printf(
                "Warning!!! devnet_xmit recursing: nbytes+header = %d, framesize = %d\n",
                nbytes + 16 + 16 + 4 + 1, framesize);
        devnet_xmit(dst, proto, tptr, nbytes - i, whichifc);
    } else
        while (n < framesize)
        {
            /*	Send padding	*/
            *(NIC_TDR + ifc_shift_offset) = 0;
            n++;
        }

    /*	Restore SR	*/
    spldone(savedSR);

    /*					*/
    /*    If frame could'nt be sent, LSB	*/
    /*    of NIC_NSR will be 1, return -1	*/
    /*					*/
    return -((*(NIC_NSR + ifc_shift_offset)) & 0x1);
}