/*********************************************************************
 * Function:        BOOL UDPGet(BYTE *v)
 *
 * PreCondition:    UDPInit() is already called     AND
 *                  UDPIsGetReady(s) == TRUE
 *
 * Input:           v       - Buffer to receive UDP data byte
 *
 * Output:          TRUE    if a data byte was read
 *                  FALSE   if no data byte was read or available
 *
 * Side Effects:    None
 *
 * Overview:        None
 *
 * Note:            This function fetches data from an active UDP
 *                  socket as set by UDPIsGetReady() call.
 ********************************************************************/
BOOL UDPGet(BYTE *v)
{
    // CALLER MUST MAKE SURE THAT THERE IS ENOUGH DATA BYTE IN BUFFER
    // BEFORE CALLING THIS FUNCTION.
    // USE UDPIsGetReady() TO CONFIRM.

    if ( UDPSocketInfo[activeUDPSocket].RxCount == 0 )
        return FALSE;

    // If if this very first read to packet, set MAC Rx Pointer to
    // beginig of UDP data area.
    if ( UDPSocketInfo[activeUDPSocket].Flags.bFirstRead )
    {
        UDPSocketInfo[activeUDPSocket].Flags.bFirstRead = FALSE;
        UDPSetRxBuffer(0);
    }

    *v = MACGet();

    UDPSocketInfo[activeUDPSocket].RxCount--;

    if ( UDPSocketInfo[activeUDPSocket].RxCount == 0 )
    {
        MACDiscardRx();
    }

    return TRUE;
}
Exemple #2
0
/*****************************************************************************
  Function:
	BOOL UDPGet(BYTE *v)

  Summary:
	Reads a byte from the currently active socket.
	
  Description:
	This function reads a single byte from the currently active UDP socket, 
	while decrementing the remaining buffer length.  UDPIsGetReady should be 
	used before calling this function to specify the currently active socket.

  Precondition:
	UDPIsGetReady() was previously called to specify the current socket.

  Parameters:
	v - The buffer to receive the data being read.

  Return Values:
  	TRUE - A byte was successfully read
  	FALSE - No data remained in the read buffer
  ***************************************************************************/
BOOL UDPGet(BYTE *v)
{
	// Make sure that there is data to return
    if((wGetOffset >= UDPRxCount) || (SocketWithRxData != activeUDPSocket))
        return FALSE;

    *v = MACGet();
    wGetOffset++;

    return TRUE;
}
Exemple #3
0
/*****************************************************************************
  Function:
    bool UDPGet(uint8_t *v)

  Summary:
    Reads a byte from the currently active socket.

  Description:
    This function reads a single byte from the currently active UDP socket,
    while decrementing the remaining buffer length.  UDPIsGetReady should be
    used before calling this function to specify the currently active socket.

  Precondition:
    UDPIsGetReady() was previously called to specify the current socket.

  Parameters:
    v - The buffer to receive the data being read.

  Return Values:
    true - A byte was successfully read
    false - No data remained in the read buffer
  ***************************************************************************/
bool UDPGet(uint8_t *v)
{
    // Make sure that there is data to return
    if((wGetOffset >= UDPRxCount) || (SocketWithRxData != activeUDPSocket))
        return false;

    *v = MACGet();
    wGetOffset++;

    return true;
}
Exemple #4
0
WORD    MACGetArray(BYTE *val, WORD len)
{
    /*
     * This function does not verify requested bytes against available
     * bytes in current packet.  Higher level logic must always validate
     * packet and fetch data according to packet header.
     */

    while( len-- )
        *val++ = MACGet();
    return len;
}
Exemple #5
0
/******************************************************************************
 * Function:        void MACMemCopyAsync(PTR_BASE destAddr, PTR_BASE sourceAddr, WORD len)
 *
 * PreCondition:    None
 *
 * Input:           destAddr:	Destination address in the Ethernet memory to
 *								copy to.  If (PTR_BASE)-1 is specified, the 
 *								current EWRPT value will be used instead.
 *					sourceAddr:	Source address to read from.  If (PTR_BASE)-1 is
 *                              specified, the current ERDPT value will be used
 *                              instead.
 *					len:		Number of bytes to copy
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Bytes are asynchrnously transfered within the buffer.  Call
 *					MACIsMemCopyDone() to see when the transfer is complete.
 *
 * Note:            If a prior transfer is already in progress prior to
 *					calling this function, this function will block until it
 *					can start this transfer.
 *****************************************************************************/
void MACMemCopyAsync(PTR_BASE destAddr, PTR_BASE sourceAddr, WORD len) {
    WORD_VAL ReadSave, WriteSave;
    BOOL UpdateWritePointer = FALSE;
    BOOL UpdateReadPointer = FALSE;

    if (destAddr == (PTR_BASE) - 1) {
        UpdateWritePointer = TRUE;
        destAddr = EWRPT;
    }
    if (sourceAddr == (PTR_BASE) - 1) {
        UpdateReadPointer = TRUE;
        sourceAddr = ERDPT;
    }

    // Handle special conditions where len == 0 or len == 1
    // The DMA module is not capable of handling those corner cases
    if (len <= 1u) {
        ReadSave.Val = ERDPT;
        WriteSave.Val = EWRPT;
        ERDPT = sourceAddr;
        EWRPT = destAddr;
        while (len--)
            MACPut(MACGet());
        if (!UpdateReadPointer) {
            ERDPT = ReadSave.Val;
        }
        if (!UpdateWritePointer) {
            EWRPT = WriteSave.Val;
        }
    } else {
        if (UpdateWritePointer) {
            WriteSave.Val = destAddr + len;
            EWRPT = WriteSave.Val;
        }
        len += sourceAddr - 1;
        while (ECON1bits.DMAST);
        EDMAST = sourceAddr;
        EDMADST = destAddr;
        if ((sourceAddr <= RXSTOP) && (len > RXSTOP)) //&& (sourceAddr >= RXSTART))
            len -= RXSIZE;
        EDMAND = len;
        ECON1bits.CSUMEN = 0;
        ECON1bits.DMAST = 1;
        while (ECON1bits.DMAST); // DMA requires that you must not access EDATA while DMA active

        if (UpdateReadPointer) {
            len++;
            if ((sourceAddr <= RXSTOP) && (len > RXSTOP)) //&& (sourceAddr >= RXSTART))
                len -= RXSIZE;
            ERDPT = len;
        }
    }
}