Exemplo n.º 1
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    PIC32MACEventAck(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, TCPIP_EVENT tcpAckEv)

  Summary:
    Acknowledges and re-enables processed events.

  Description:
    This function acknowledges and re-enables processed events.
    Multiple events can be orr-ed together as they are processed together.
    The events acknowledged by this function should be the events that have been retrieved from the stack
    by calling PIC32MACEventGetPending() or have been passed to the user by the stack using the notification handler
    (PIC32MACEventSetNotifyHandler()) and have been processed and have to be re-enabled.


  Precondition:
   TCPIPInit should have been called.
   tcpEvGroup, tcpAckEv valid values 

  Parameters:
    hMac      - parameter identifying the intended MAC  
    tcpEvGroup  - group of events the acknowledge refers to
    tcpipEvents - the events that the user processed and need to be re-enabled
    
  Returns:
    TCPIP_MAC_EVRES_ACK_OK if events acknowledged
    TCPIP_MAC_EVRES_ACK_NONE if no events to be acknowledged
    an error code otherwise

  Example:
    <code>
    PIC32MACEventAck( hMac, TCPIP_MAC_EVGROUP_ALL, stackNewEvents );
    </code>

  Remarks:   
    All events should be acknowledged, in order to be re-enabled.

    Some events are fatal errors and should not be acknowledged (TCPIP_EV_RX_BUSERR, TCPIP_EV_TX_BUSERR).
    Stack re-initialization is needed under such circumstances.

    Some events are just system/application behavior and they are intended only as simple info (TCPIP_EV_RX_OVFLOW,
    TCPIP_EV_RX_BUFNA, TCPIP_EV_TX_ABORT, TCPIP_EV_RX_ACT, TCPIP_EV_RX_DONE).

    The TCPIP_EV_RX_FWMARK and TCPIP_EV_RX_EWMARK events are part of the normal flow control operation (if auto flow control was enabled).
    They should be enabled alternatively, if needed.

    The events are persistent. They shouldn't be re-enabled unless they have been processed and the condition that generated them was removed.
    Re-enabling them immediately without proper processing will have dramatic effects on system performance.

    Not multi-threaded safe accross different TCPIP_MAC_EVENT_GROUP groups.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT PIC32MACEventAck(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, TCPIP_EVENT tcpAckEv)
{
    int                   ethILev;
    PIC32_EMB_MAC_DCPT*     pMacD = (PIC32_EMB_MAC_DCPT*)hMac;
    PIC32_EV_GROUP_DCPT*  pDcpt = pMacD->mData._pic32_ev_group_dcpt+tcpEvGroup; 

    tcpAckEv &= pDcpt->_TcpGroupEventsMask;

    if(pDcpt->_TcpEnabledEvents != 0)
    {   // already have some active     
        eEthEvents  ethAckEv;

        ethAckEv=_XtlEventsTcp2Eth(tcpAckEv);

        ethILev = SYS_INT_SourceDisable(pMacD->mData._macIntSrc);  // stop ints for a while

        pDcpt->_TcpPendingEvents &= ~tcpAckEv;         // no longer pending

        pDcpt->_EthPendingEvents &= ~ethAckEv;         // no longer pending

        EthEventsClr(ethAckEv);                 // clear the old pending ones
        EthEventsEnableSet(ethAckEv);           // re-enable the ack ones
        
        SYS_INT_SourceRestore(pMacD->mData._macIntSrc, ethILev);   // re-enable
        return TCPIP_MAC_EVRES_ACK_OK;
    }

    return TCPIP_MAC_EVRES_ACK_NONE;
}
Exemplo n.º 2
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    PIC32MACEventSetNotifyEvents(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, TCPIP_EVENT tcpipEvents)

  Summary:
    Adds new events to the list of the enabled ones.

  Description:
     This function sets new enabled events.
     Multiple events can be orr-ed together.
     All events that are set will be added to the notification process. The other events will not ne touched.
     The stack (or stack user) has to catch the events that are notified and process them:
         - The stack should process the TCPIP_EV_RX_PKTPEND, TCPIP_EV_TX_DONE transfer events
         - Process the specific condition and acknowledge them calling PIC32MACEventAck() so that they can be re-enabled.

  Precondition:
   TCPIPInit should have been called.
   tcpEvGroup, tcpSetEv valid values 

  Parameters:
    hMac      - parameter identifying the intended MAC  
    tcpEvGroup  - group of events the notification refers to
    tcpipEvents - events the user of the stack wants to add for notification
    
  Returns:
    TCPIP_MAC_EVRES_OK  if operation succeeded,
    an error code otherwise

  Example:
    <code>
    PIC32MACEventSetNotifyEvents( hMac, TCPIP_MAC_EVGROUP_RX, TCPIP_EV_RX_OVFLOW | TCPIP_EV_RX_BUFNA );
    </code>

  Remarks:
    The event notification system enables the user of the TCPIP stack to call into the stack
    for processing only when there are relevant events rather than being forced to periodically call
    from within a loop.
    
    If the notification events are nill (accross all groups) the interrupt processing will be disabled.
    Otherwise the event notification will be enabled and the interrupts relating to the requested events will be enabled.
    
    Note that once an event has been caught by the stack ISR (and reported if a notification handler is in place)
    it will be disabled until the PIC32MACEventAck() is called.

    Not multi-threaded safe accross different TCPIP_MAC_EVENT_GROUP groups.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT PIC32MACEventSetNotifyEvents(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, TCPIP_EVENT tcpSetEv)
{
    eEthEvents  ethSetEvents;
    PIC32_EMB_MAC_DCPT*     pMacD = (PIC32_EMB_MAC_DCPT*)hMac;
    PIC32_EV_GROUP_DCPT*  pDcpt = pMacD->mData._pic32_ev_group_dcpt+tcpEvGroup; 

    tcpSetEv &= pDcpt->_TcpGroupEventsMask; 
    ethSetEvents = _XtlEventsTcp2Eth(tcpSetEv);
    
    if(pDcpt->_TcpEnabledEvents != 0)
    {   // already have some active     
        SYS_INT_SourceDisable(pMacD->mData._macIntSrc);      // stop ints for a while
    }
    
    pDcpt->_TcpEnabledEvents |= tcpSetEv;        // add more
    pDcpt->_EthEnabledEvents |= ethSetEvents;  
    
    if(pDcpt->_TcpEnabledEvents != 0)
    {
        ethSetEvents &= ~pDcpt->_EthPendingEvents;     // keep just the new un-ack events
        EthEventsClr( ethSetEvents );                       // clear the old pending ones
        EthEventsEnableSet( ethSetEvents );                 // enable the new un-ack ones!
        
        SYS_INT_SourceEnable(pMacD->mData._macIntSrc);       // enable
    }

    return TCPIP_MAC_EVRES_OK;
}
/****************************************************************************
 * Function:        _TcpIpEventAck
 *
 * PreCondition:    TCPIPInit should have been called.
 *
 * Input:           eventFlags - the events that the user processed and need to be re-enabled
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Internal function to acknowledge and re-enable processed events.
 *                  Same as the interface one except it can clear any kind of events passed to it.
 *                  
 *
 * Note:            None
 ******************************************************************************/
static void _TcpIpEventAck(eTCPIPEvent eventFlags)
{
	if(_TcpEnabledEvents!=0)
	{	// already have some active		
		eEthEvents	ackEvents;

		ackEvents=_XtlEventsTcp2Eth(eventFlags);

		INTEnable(INT_ETHERNET, INT_DISABLED);		// stop ints for a while

		ackEvents&=_TcpPendingEvents;			// keep just the pending ones
		_TcpPendingEvents&=~ackEvents;			// no longer pending


		EthEventsClr(ackEvents);		// clear the old pending ones
		EthEventsEnableSet(ackEvents);		// re-enable the ack ones
		
		INTEnable(INT_ETHERNET, INT_ENABLED);	// re-enable
	}

}
/****************************************************************************
 * Function:        TCPIPEventSetNotifyEvents
 *
 * PreCondition:    TCPIPInit should have been called.
 *
 * Input:           eventFlags - events the user of the stack wants to add for notification 
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function sets new enabled events.
 *                  Multiple events can be orr-ed together.
 *                  All events that are set will be added to the notification process. The other events will not ne touched.
 *                  The stack user has to catch the events that are notified and process them:
 *                   - use them eventually in a call to TCPIPEventProcess(). The stack will process only the normal transfer events
 *                   - process the specific condition and acknowledge them calling TCPIPEventAck() so that they can be re-enabled.
 *
 * Note:            - The event notification system enables the user of the Tcp/Ip stack to call into the stack
 *                    for processing only when there are relevant events rather than being forced to periodically call
 *                    from within a loop.
 *                  - If the notification events are nill the interrupt processing will be disabled.
 *                    Otherwise the event notification will be enabled and the interrupts relating to the requested events will be enabled.
 *                  - Note that once an event has been caught by the stack ISR (and reported to the user if a notification handler is in place)
 *                    it will be disabled until the user calls TCPIPEventProcess()/TCPIPEventAck().
 ******************************************************************************/
void TCPIPEventSetNotifyEvents(eTCPIPEvent eventFlags)
{
	eEthEvents	setEvents;
	
	if(_TcpEnabledEvents!=0)
	{	// already have some active		
		INTEnable(INT_ETHERNET, INT_DISABLED);		// stop ints for a while
	}
	
	setEvents=_XtlEventsTcp2Eth(eventFlags);
	_TcpEnabledEvents|=setEvents;		// add more 
	
	if(_TcpEnabledEvents!=0)
	{
		setEvents&=~_TcpPendingEvents;		// keep just the new un-ack events
		EthEventsClr(setEvents);		// clear the old pending ones
		EthEventsEnableSet(setEvents);		// enable the new un-ack ones!
		
		INTEnable(INT_ETHERNET, INT_ENABLED);	// re-enable
	}
			
}