Example #1
0
/****************************************************************************
 * Function:        TcpIpEthIsr
 *
 * PreCondition:    TCPIPInit, PIC32MACEventSetNotifyEvents should have been called.
 *
 * Input:           p - PIC32 MAC descriptor pointer
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function processes the Ethernet interrupts and reports the events back to the user.
 *
 * Note:            None
 ******************************************************************************/
static void TcpIpEthIsr(void* p)
{
    eEthEvents          currEthEvents, currGroupEvents;
    PIC32_EV_GROUP_DCPT* pDcpt;
    int                 grpIx;
    PIC32_EMB_MAC_DCPT* pMacD = (PIC32_EMB_MAC_DCPT*)p;

    currEthEvents = EthEventsGet();

    // process per group
    pDcpt = pMacD->mData._pic32_ev_group_dcpt;
    for(grpIx = 0; grpIx < sizeof(pMacD->mData._pic32_ev_group_dcpt)/sizeof(*pMacD->mData._pic32_ev_group_dcpt); grpIx++)
    {
        currGroupEvents = currEthEvents & pDcpt->_EthEnabledEvents;     //  keep just the relevant ones
        if(currGroupEvents)
        {
            pDcpt->_EthPendingEvents |= currGroupEvents;                    // add the new events
            pDcpt->_TcpPendingEvents |= _XtlEventsEth2Tcp(currGroupEvents);

            EthEventsEnableClr(currGroupEvents);         // these will get reported; disable them until ack is received back
            EthEventsClr(currGroupEvents);               // acknowledge the ETHC
            if(pDcpt->_TcpNotifyFnc)
            {
                (*pDcpt->_TcpNotifyFnc)(pDcpt->_TcpNotifyParam, pDcpt->_TcpPendingEvents);     // let the user know
            }
        }
        pDcpt++;
    }



    SYS_INT_SourceStatusClear(pMacD->mData._macIntSrc);         // acknowledge the int Controller
}
Example #2
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;
}
Example #3
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT PIC32MACEventClearNotifyEvents(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, TCPIP_EVENT tcpipEvents)

  Summary:
    Removes events from the list of the enabled ones.

  Description:
     This function removes from the enabled events.
     Multiple events can be orr-ed together.
     All events that are set will be removed from the notification process. The other events will not ne touched.


  Precondition:
   TCPIPInit should have been called.
   tcpEvGroup, tcpClrEv 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 remove from notification
    
  Returns:
    TCPIP_MAC_EVRES_OK  if operation succeeded,
    an error code otherwise

  Example:
    <code>
    PIC32MACEventClearNotifyEvents( hMac, TCPIP_MAC_EVGROUP_ALL, TCPIP_EV_RX_OVFLOW | TCPIP_EV_RX_BUFNA );
    </code>

  Remarks:   
    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.
    
    Not multi-threaded safe accross different TCPIP_MAC_EVENT_GROUP groups.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT PIC32MACEventClearNotifyEvents(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, TCPIP_EVENT tcpClrEv)
{
    eEthEvents  ethClrEvents;
    int         ethILev = 0;
    PIC32_EMB_MAC_DCPT*     pMacD = (PIC32_EMB_MAC_DCPT*)hMac;
    PIC32_EV_GROUP_DCPT*  pDcpt = pMacD->mData._pic32_ev_group_dcpt+tcpEvGroup; 

    tcpClrEv &= pDcpt->_TcpGroupEventsMask; 
    
    tcpClrEv &= pDcpt->_TcpEnabledEvents;                  // keep just the enabled ones
    ethClrEvents = _XtlEventsTcp2Eth(tcpClrEv);
    
    if(pDcpt->_TcpEnabledEvents != 0)
    {   // already have some active     
        ethILev = SYS_INT_SourceDisable(pMacD->mData._macIntSrc);      // stop ints for a while
    }

    pDcpt->_TcpEnabledEvents &= ~tcpClrEv;     // clear some of them
    pDcpt->_EthEnabledEvents &= ~ethClrEvents;

    pDcpt->_TcpPendingEvents &= ~tcpClrEv;     // remove them from un-ack list
    pDcpt->_EthPendingEvents &= ~ethClrEvents;

    EthEventsEnableClr(ethClrEvents);   // no longer enabled
    EthEventsClr(ethClrEvents);         // clear the pending ones

    if(pDcpt->_TcpEnabledEvents != 0)
    {
        SYS_INT_SourceRestore(pMacD->mData._macIntSrc, ethILev);   // re-enable
    }

    return TCPIP_MAC_EVRES_OK;
}
Example #4
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:        _TcpIpEthIsr
 *
 * PreCondition:    TCPIPInit, TCPIPEventSetNotifyEvents should have been called.
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function processes the Ethernet interrupts and reports the events back to the user.
 *
 * Note:            None
 ******************************************************************************/
void __attribute__((vector(_ETH_VECTOR), interrupt, nomips16, weak)) _TcpIpEthIsr(void)
{
	eEthEvents	currEvents;

	currEvents=EthEventsGet()&_TcpEnabledEvents;	// keep just those that are relevant
	_TcpPendingEvents|=currEvents;			// add the new events

	EthEventsEnableClr(currEvents);			// these will get reported; disable them until ack is received back
	
	EthEventsClr(currEvents);			// acknowledge the ETHC

	if(_TcpNotifyFnc)
	{
		(*_TcpNotifyFnc)(_XtlEventsEth2Tcp(_TcpPendingEvents));		// let the user know
	}

	INTClearFlag(INT_ETHERNET);			// acknowledge the INTC
}
/****************************************************************************
 * 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
	}
			
}
/****************************************************************************
 * Function:        TCPIPEventClearNotifyEvents
 *
 * PreCondition:    TCPIPInit should have been called.
 *
 * Input:           eventFlags - pointer to the events the user of the stack wants to remove from notification 
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function removes from the enabled events.
 *                  Multiple events can be orr-ed together.
 *                  All events that are set will be removed from the notification process. The other events will not ne touched.
 *
 * Note:            - 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.
 ******************************************************************************/
void TCPIPEventClearNotifyEvents(eTCPIPEvent eventFlags)
{
	eEthEvents	clrEvents;
	
	if(_TcpEnabledEvents!=0)
	{	// already have some active		
		INTEnable(INT_ETHERNET, INT_DISABLED);		// stop ints for a while
	}

	clrEvents=_XtlEventsTcp2Eth(eventFlags);
	clrEvents&=_TcpEnabledEvents;		// keep just the enabled ones
	_TcpEnabledEvents&=~clrEvents;		// clear some of them
	_TcpPendingEvents&=~clrEvents;		// remove them from un-ack list
	
	EthEventsEnableClr(clrEvents);		// no longer enabled
	EthEventsClr(clrEvents);		// clear the pending ones

    if(_TcpEnabledEvents!=0)
	{
		INTEnable(INT_ETHERNET, INT_ENABLED);	// re-enable
	}

}