void DRV_SPI1_Deinitialize ( void )
{
    /* Disable the interrupts */
    SYS_INT_SourceDisable(INT_SOURCE_SPI_2_TRANSMIT);
    SYS_INT_SourceDisable(INT_SOURCE_SPI_2_RECEIVE);
    SYS_INT_SourceDisable(INT_SOURCE_SPI_2_ERROR);

    /* Disable the SPI Module */
    PLIB_SPI_Disable(SPI_ID_2);

    return;
}
Beispiel #2
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    PIC32MACEventInit(TCPIP_MAC_HANDLE hMac, int intPri, int intSubPri)

  Summary:
    Initializes the ethernet event notification.

  Description:
     This function initializes the ethernet event notification.
     It performs any resource allocation that may be needed.

  Precondition:
     None.

  Parameters:
    hMac      - parameter identifying the intended MAC  
    intPri     - priority of the TCPIP interrupt events
    intSubPri  - sub-priority of the TCPIP interrupt events
    
  Returns:
    TCPIP_MAC_EVRES_OK  if initialization succeeded,
    an error code otherwise

  Example:
    <code>
    PIC32MACEventInit( hMac, 4, 3 );
    </code>

  Remarks:

    Not multi-threaded safe.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT PIC32MACEventInit(TCPIP_MAC_HANDLE hMac, int intPri, int intSubPri)
{
    int grpIx;
    PIC32_EV_GROUP_DCPT*    pDcpt; 
    PIC32_EMB_MAC_DCPT*     pMacD = (PIC32_EMB_MAC_DCPT*)hMac;

    SYS_INT_SourceDisable(pMacD->mData._macIntSrc);      // stop Eth ints
    SYS_INT_SourceStatusClear(pMacD->mData._macIntSrc);
    SYS_INT_PrioritySet(pMacD->mData._macIntSrc, (INT_PRIORITY_LEVEL_1-1)+intPri);
    SYS_INT_SubprioritySet(pMacD->mData._macIntSrc, INT_SUB_PRIORITY_LEVEL_0+intSubPri);
    SYS_INT_DynamicRegister(pMacD->mData._macIntSrc, TcpIpEthIsr, pMacD); 
    
    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++)
    {
        pDcpt->_TcpGroupEventsMask = _pic32_mac_group_ev_mask[grpIx];
        pDcpt->_TcpEnabledEvents = pDcpt->_TcpPendingEvents = TCPIP_EV_NONE;
        pDcpt->_EthEnabledEvents = pDcpt->_EthPendingEvents = 0;
        pDcpt->_TcpNotifyFnc = 0;
        pDcpt++;
    }

    _hEventMac = hMac;    
    return TCPIP_MAC_EVRES_OK;
}
Beispiel #3
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT MRF24W_MACEventClearNotifyEvents(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, 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 remove from notification
    
  Returns:
    TCPIP_MAC_EVRES_OK  if operation succeeded,
    an error code otherwise

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

  Remarks:   
    Globally enable/disable all notifications for now.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT MRF24W_MACEventClearNotifyEvents(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, TCPIP_EVENT tcpClrEv)
{
    SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);      // stop MRF ints
    _mrfGroupDcpt._mrfEnabledEvents = false;
            
    return TCPIP_MAC_EVRES_OK;
}
Beispiel #4
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;
}
Beispiel #5
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;
}
Beispiel #6
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;
}
Beispiel #7
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    MRF24W_MACEventSetNotifyHandler(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, pMacEventF eventHandler, void* hParam)

  Summary:
    Sets a new event notification handler.

  Description:
    This function sets a new event notification handler.
    This is a handler specified by the user of the stack.
    The caller can use the handler to be notified of MAC events.
    Whenever a notification occurs the passed events have to be eventually processed:
    - Stack should process the TCPIP_EV_RX_PKTPEND, TCPIP_EV_TX_DONE  events
    - Process the specific (error) condition
    - Acknowledge the events by calling MRF24W_MACEventAck() so that they can be re-enabled.

  Precondition:
   TCPIPInit should have been called.
   tcpEvGroup valid value 

  Parameters:
    hMac      - parameter identifying the intended MAC  
    tcpEvGroup   - group of events the notification handler refers to
    eventHandler - the event notification handler
    
  Returns:
    TCPIP_MAC_EVRES_OK  if operation succeeded,
    an error code otherwise

  Example:
    <code>
    MRF24W_MACEventSetNotifyHandler( hMac, TCPIP_MAC_EVGROUP_ALL, myEventHandler, myParam );
    </code>

  Remarks:   
    The notification handler will be called from the ISR which detects the corresponding event.
    The event notification handler has to be kept as short as possible and non-blocking.
    Mainly useful for RTOS integration where this handler will wake-up a thread that waits for a MAC event to occur.

    The event notification system also 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 at unknown moments.

    Without a notification handler the stack user can still call MRF24W_MACEventGetPending() to see if processing by the stack needed.

    This is a default way of adding interrupt processing to the stack.
    A separate ISR to catch the Ethernet MAC events and process accordingly
    could be added.

    All the groups specified in the TCPIP_MAC_EVENT_GROUP enumeration is supported.
    However, once a handler for TCPIP_MAC_EVGROUP_ALL is registered all event processing
    will be reported using this global handler.

    Use 0 to remove the handler for a specific event group.

    Not multi-threaded safe accross different TCPIP_MAC_EVENT_GROUP groups.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT MRF24W_MACEventSetNotifyHandler(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, pMacEventF eventHandler, void* hParam)
{
    if(tcpEvGroup != TCPIP_MAC_EVGROUP_ALL)
    {
        return TCPIP_MAC_EVRES_GROUP_ERR;
    }
        
    int rfILev;
    
    if(_mrfGroupDcpt._mrfEnabledEvents)
    {   // already have some active     
        rfILev = SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);      // stop ints for a while

        _mrfGroupDcpt._mrfNotifyFnc = eventHandler;     // set new handler
        _mrfGroupDcpt._mrfNotifyParam = hParam;   
    
        SYS_INT_SourceStatusClear(MRFWB0M_INT_SOURCE);
        SYS_INT_SourceRestore(MRFWB0M_INT_SOURCE, rfILev);   // re-enable
    }
    else
    {
        _mrfGroupDcpt._mrfNotifyFnc = eventHandler;     // set new handler
        _mrfGroupDcpt._mrfNotifyParam = hParam;   
    }
    return TCPIP_MAC_EVRES_OK;
}
void WDRV_SPI_In(uint8_t *const OutBuf, uint16_t OutSize, uint8_t *const InBuf, uint16_t InSize)
{
    bool intEnabled = SYS_INT_SourceDisable(MRF_INT_SOURCE);

    Spi_Read(OutBuf, OutSize, InBuf, InSize);
    if(intEnabled)
        WDRV_INTR_SourceEnable();
}
void WDRV_SPI_Out(uint8_t *const bufOut, uint16_t OutSize)
{
    bool intEnabled = SYS_INT_SourceDisable(MRF_INT_SOURCE);

    Spi_Write(bufOut, OutSize);
    if(intEnabled)
        WDRV_INTR_SourceEnable();
}
Beispiel #10
0
/*******************************************************
 * UART2 Initialize routine. Baud rate is set 9600
 *******************************************************/
void APP_UART2Initialize(void)
{
    /* Initialize the UART2 on Explorer 16 board */
    U2MODE = 0x8000;
    U2STA = 0x1400;
    U2BRG = 520;
    appData.isUARTTransmitBusy = false;
    SYS_INT_SourceDisable(INT_SOURCE_USART_2_TRANSMIT);
    SYS_INT_SourceEnable(INT_SOURCE_USART_2_RECEIVE);
}
/*******************************************************************************
  Function:
    TCPIP_MAC_RES    MRF24W_MACEventDeInit(TCPIP_MAC_HANDLE hMac )

  Summary:
    De-initializes the Ethernet event notification.

  Description:
     This function de-initializes the Ethernet event notification.
     It performs any resource clean-up that may be needed.

  Precondition:
     None.

  Parameters:
    hMac      - parameter identifying the intended MAC

  Returns:
    TCPIP_MAC_RES_OK  always

  Example:
    <code>
    MRF24W_MACEventDeInit( hMac );
    </code>

  Remarks:

    Not multi-threaded safe.
 *******************************************************************************/
TCPIP_MAC_RES MRF24W_MACEventDeInit(MRF24W_MAC_DCPT *pDcpt)
{
    SYS_INT_SourceDisable(MRF_INT_SOURCE); // stop MRF ints
    SYS_INT_SourceStatusClear(MRF_INT_SOURCE);

    s_mrfGroupDcpt.mrfNotifyFnc     = 0;
    s_mrfGroupDcpt.mrfEnabledEvents = false;
    s_mrfGroupDcpt.mrfPendingEvents = 0;

    return TCPIP_MAC_RES_OK;
}
static void WifiAsyncClearEventPending(uint8_t event)
{
    bool intEnabled = SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);

    g_asyncTaskFlags &= ~event;

    if(intEnabled)
    {
        DRV_WIFI_INT_SourceEnable();
    }
}
/****************************************************************************
 * Function:        DRV_EXTPHY_IntInit
 *
 * PreCondition:    EthInit and EthPhyInit should have been called.
 *
 * Input:         hClientObj - A valid open-instance handle, returned from the driver's open routine
 *                  src - interrupt source
 *                  intPri - intrrupt priority
 *                  intSubPri - Interuupt Sub Priority
 *
 * Output:         none
 *
 *
 * Side Effects:    None
 *
 * Overview:       Initialize External Interrupt 3.	One can take this as reference for their WOL 
 *                      Interrupt.
 *
 * Note:            None
 *****************************************************************************/
void DRV_EXTPHY_IntInit(DRV_HANDLE hClientObj,INT_SOURCE src,int intPri, int intSubPri)
{
	// set up the External Interrupt 3 with a prioirty of 5 and 1 sub-priority    

    SYS_INT_SourceDisable(src);      // stop Eth ints
    SYS_INT_SourceStatusClear(src);
    SYS_INT_VectorPrioritySet(src, intPri);
    SYS_INT_VectorSubprioritySet(src, intSubPri);

    SYS_INT_SourceEnable(src);

}
void WDRV_SPI_In(uint8_t * const OutBuf, uint16_t OutSize, uint8_t * const InBuf, uint16_t InSize)
{
    bool intEnabled = SYS_INT_SourceDisable(MRF_INT_SOURCE);

    WDRV_DISABLE_INTR();
    CS_Assert();
    IspSpi_TxAndRx(OutBuf, OutSize, InBuf, InSize);
    CS_Deassert();
    WDRV_ENABLE_INTR();
    if(intEnabled)
        WDRV_INTR_SourceEnable();
}
Beispiel #15
0
bool SYS_INT_SourceRestore(INT_SOURCE src)
{
    bool isEnabled;

    isEnabled = SYS_INT_SourceDisable(src);

    if(isEnabled)
    {   
        SYS_INT_SourceEnable(src);
    }

    return isEnabled;
}
void WDRV_SPI_Out(uint8_t * const bufOut, uint16_t OutSize)
{
    uint8_t rxBuf[4];
    bool intEnabled = SYS_INT_SourceDisable(MRF_INT_SOURCE);

    WDRV_DISABLE_INTR();
    CS_Assert();
    IspSpi_TxAndRx(bufOut, OutSize, rxBuf, 0);
    CS_Deassert();
    WDRV_ENABLE_INTR();
    if(intEnabled)
        WDRV_INTR_SourceEnable();
}
Beispiel #17
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    MRF24W_MACEventDeInit(TCPIP_MAC_HANDLE hMac )

  Summary:
    De-initializes the ethernet event notification.

  Description:
     This function de-initializes the ethernet event notification.
     It performs any resource clean-up that may be needed.

  Precondition:
     None.

  Parameters:
    hMac      - parameter identifying the intended MAC  
    
  Returns:
    TCPIP_MAC_EVRES_OK  always

  Example:
    <code>
    MRF24W_MACEventDeInit( hMac );
    </code>

  Remarks:

    Not multi-threaded safe.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT MRF24W_MACEventDeInit(TCPIP_MAC_HANDLE hMac)
{


    SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);      // stop MRF ints
    SYS_INT_SourceStatusClear(MRFWB0M_INT_SOURCE);
    SYS_INT_DynamicRegister(MRFWB0M_INT_SOURCE, 0, 0); 

    _mrfGroupDcpt._mrfNotifyFnc = 0;
    _mrfGroupDcpt._mrfEnabledEvents = false;
    _mrfGroupDcpt._mrfPendingEvents = 0;

    return TCPIP_MAC_EVRES_OK;
}
/*******************************************************************************
  Function:
    bool    _MRF24W_MACEventSetMask(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT tcpipEvents, bool enable)

  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_MAC_EV_RX_DONE, TCPIP_MAC_EV_TX_DONE transfer events
         - Process the specific condition and acknowledge them calling _MRF24W_MACEventAcknowledge() so that they can be re-enabled.

  Precondition:
   TCPIPInit should have been called.

  Parameters:
    hMac      - parameter identifying the intended MAC
    tcpipEvents - events the user of the stack wants to add for notification
    enable      - boolean to enable/disable the event notification

  Returns:
    true  if operation succeeded,
    false code otherwise

  Example:
    <code>
    _MRF24W_MACEventSetMask( hMac, TCPIP_MAC_EV_RX_OVFLOW | TCPIP_MAC_EV_RX_BUFNA, true );
    </code>

  Remarks:
    Globally enable/disable all notifications for now.

 *******************************************************************************/
bool _MRF24W_MACEventSetMask(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT macEvents, bool enable)
{
    if (enable)
    {
        s_mrfGroupDcpt.mrfEnabledEvents = true;
        SYS_INT_SourceEnable(MRF_INT_SOURCE); // start MRF ints
    }
    else
    {
        SYS_INT_SourceDisable(MRF_INT_SOURCE); // stop MRF ints
        s_mrfGroupDcpt.mrfEnabledEvents = false;
    }

    return true;
}
/*******************************************************************************
 * Function:        DRV_WIFI_MRF24W_ISR
 *
 * PreCondition:    TCPIPInit, _MRF24W_MACEventSetMask should have been called.
 *
 * Input:           p - unused
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function processes the Ethernet interrupts and reports the events back to the user.
 *
 * Note:            None
 *******************************************************************************/
void DRV_WIFI_MRF24W_ISR(SYS_MODULE_OBJ index)
{
    if (s_mrfGroupDcpt.mrfEnabledEvents )
    {
        s_mrfGroupDcpt.mrfPendingEvents = TCPIP_MAC_EV_TX_DONE;
        if (s_mrfGroupDcpt.mrfNotifyFnc)
        {
            (*s_mrfGroupDcpt.mrfNotifyFnc)(s_mrfGroupDcpt.mrfPendingEvents, s_mrfGroupDcpt.mrfNotifyParam);
        }
    }

    SYS_INT_SourceDisable(MRF_INT_SOURCE); // disable further interrupts
    SYS_INT_SourceStatusClear(MRF_INT_SOURCE); // acknowledge the int Controller

    /* invoke MRF handler */
    DRV_WIFI_INT_Handle();
}
Beispiel #20
0
/****************************************************************************
 * Function:        MRF24W_ISR
 *
 * PreCondition:    TCPIPInit, MRF24W_MACEventSetNotifyEvents should have been called.
 *
 * Input:           p - unused
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function processes the Ethernet interrupts and reports the events back to the user.
 *
 * Note:            None
 ******************************************************************************/
void MRF24W_ISR(void* p)
{
    
    if(_mrfGroupDcpt._mrfEnabledEvents )
    {
        _mrfGroupDcpt._mrfPendingEvents = TCPIP_EV_RX_PKTPEND|TCPIP_EV_TX_DONE;
        if(_mrfGroupDcpt._mrfNotifyFnc)
        {
            (*_mrfGroupDcpt._mrfNotifyFnc)(_mrfGroupDcpt._mrfNotifyParam, _mrfGroupDcpt._mrfPendingEvents);  
        }
        
    }
    
    SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);        // disable further interrupts
    SYS_INT_SourceStatusClear(MRFWB0M_INT_SOURCE);      // acknowledge the int Controller

    /* invoke MRF handler */
    WFEintHandler();
}
Beispiel #21
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    MRF24W_MACEventInit(TCPIP_MAC_HANDLE hMac, int intPri, int intSubPri)

  Summary:
    Initializes the ethernet event notification.

  Description:
     This function initializes the ethernet event notification.
     It performs any resource allocation that may be needed.

  Precondition:
     None.

  Parameters:
    hMac      - parameter identifying the intended MAC  
    intPri     - priority of the TCPIP interrupt events
    intSubPri  - sub-priority of the TCPIP interrupt events
    
  Returns:
    TCPIP_MAC_EVRES_OK  if initialization succeeded,
    an error code otherwise

  Example:
    <code>
    MRF24W_MACEventInit( hMac, 4, 3 );
    </code>

  Remarks:

    Not multi-threaded safe.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT MRF24W_MACEventInit(TCPIP_MAC_HANDLE hMac, int intPri, int intSubPri)
{
    SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);      // stop MRF ints
    SYS_INT_SourceStatusClear(MRFWB0M_INT_SOURCE);
    SYS_INT_PrioritySet(MRFWB0M_INT_SOURCE, (INT_PRIORITY_LEVEL_1-1)+intPri);
#if defined (__C32__)
    SYS_INT_SubprioritySet(MRFWB0M_INT_SOURCE, INT_SUB_PRIORITY_LEVEL_0+intSubPri);
#endif
    SYS_INT_DynamicRegister(MRFWB0M_INT_SOURCE, MRF24W_ISR, 0); 
    
    _mrfGroupDcpt._mrfNotifyFnc = 0;
    _mrfGroupDcpt._mrfEnabledEvents = false;
    _mrfGroupDcpt._mrfPendingEvents = 0;

    _mrfUsrEvent.trafficEvents = _mrfUsrEvent.mgmtEvents = 0;
    _mrfUsrEvent.trafficEventInfo = _mrfUsrEvent.mgmtEventInfo =0;


    return TCPIP_MAC_EVRES_OK;
}
static void LAN8740WOLIsr(void *p)
{
    DRV_HANDLE hClientObj = (DRV_HANDLE)p;

    eWOL_WAKEUP_FRAME wuframe = REMOTE_WAKEUP_FRAME;
    //eWOL_WAKEUP_FRAME wuframe = MAGIC_PKT_RECEIVED;
    // eWOL_WAKEUP_FRAME wuframe = BROADCAST_FRAME_RCVD;    
    //eWOL_WAKEUP_FRAME wuframe = PERFECT_DA_FRAME;
    bool wol_status;
    wol_status = DRV_EXTPHY_WOLWakeUpFrameRXStatusGet(hClientObj,wuframe);
   
    INT_SOURCE src = DRV_ETHPHY_INTERRUPT_SOURCE;

    LEDstate ^= SYS_USERIO_LED_ASSERTED;
    SYS_USERIO_SetLED(SYS_USERIO_LED_1, LEDstate);
    DRV_EXTPHY_WOLInterruptMaskSet(hClientObj,WOL_INT_DISABLED);
    // clear the WOL wake up frame
    DRV_EXTPHY_WOLWakeUpFrameClear(hClientObj,wuframe);
    SYS_INT_SourceDisable(src);
}
Beispiel #23
0
/****************************************************************************
 * Function:        DRV_EXTPHY_IntInit
 *
 * PreCondition:    EthInit and EthPhyInit should have been called.
 *
 * Input:         hClientObj - A valid open-instance handle, returned from the driver's open routine
 *                  src - interrupt source
 *                  intPri - intrrupt priority
 *                  intSubPri - Interuupt Sub Priority
 *
 * Output:         none
 *
 *
 * Side Effects:    None
 *
 * Overview:       Initialize External Interrupt 3.	One can take this as refreence for their WOL 
 *                      Interrupt.
 *
 * Note:            None
 *****************************************************************************/
static void DRV_EXTPHY_IntInit(DRV_HANDLE hClientObj,SYS_INT_SOURCE src,int intPri, int intSubPri)
{
	// set up the External Interrupt 3 with a prioirty of 5 and 1 sub-priority    

    SYS_INT_SourceDisable(src);      // stop Eth ints
    SYS_INT_SourceStatusClear(src);
    
#if defined (HARMONY_INT)
    SYS_INT_VectorPrioritySet(src, intPri);
    SYS_INT_VectorSubprioritySet(src, intSubPri);
#else
    SYS_INT_PrioritySet(src, intPri);
    SYS_INT_SubprioritySet(src, intSubPri);
    SYS_INT_DynamicRegister(src, LAN8740WOLIsr, (void*)&hClientObj);
#endif
    
    SYS_INT_SourceEnable(src);


}
Beispiel #24
0
/*******************************************************************************
  Function:
    TCPIP_MAC_RES    MRF24W_MACEventInit(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EventF eventF, const void* eventParam, int intPri, int intSubPri)

  Summary:
    Initializes the ethernet event notification.

  Description:
     This function initializes the ethernet event notification.
     It performs any resource allocation that may be needed.

  Precondition:
     None.

  Parameters:
    hMac      - parameter identifying the intended MAC  
    intPri     - priority of the TCPIP interrupt events
    intSubPri  - sub-priority of the TCPIP interrupt events
    
  Returns:
    TCPIP_MAC_RES_OK  if initialization succeeded,
    an error code otherwise

  Example:
    <code>
    MRF24W_MACEventInit( hMac, 4, 3 );
    </code>

  Remarks:

    Not multi-threaded safe.
*****************************************************************************/
TCPIP_MAC_RES MRF24W_MACEventInit(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EventF eventF, const void* eventParam, int intPri, int intSubPri)
{

#if 0  //todo: jian. you should fix this
    SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);      // stop MRF ints
    SYS_INT_SourceStatusClear(MRFWB0M_INT_SOURCE);
    SYS_INT_PrioritySet(MRFWB0M_INT_SOURCE, (INT_PRIORITY_LEVEL_1-1)+intPri);
    SYS_INT_SubprioritySet(MRFWB0M_INT_SOURCE, INT_SUB_PRIORITY_LEVEL_0+intSubPri);
#endif
    SYS_INT_DynamicRegister(MRFWB0M_INT_SOURCE, MRF24W_ISR, 0); 
    
    _mrfGroupDcpt._mrfNotifyFnc = eventF;     // set new handler
    _mrfGroupDcpt._mrfNotifyParam = eventParam;   
    _mrfGroupDcpt._mrfEnabledEvents = false;
    _mrfGroupDcpt._mrfPendingEvents = 0;

    _mrfUsrEvent.trafficEvents = _mrfUsrEvent.mgmtEvents = 0;
    _mrfUsrEvent.trafficEventInfo = _mrfUsrEvent.mgmtEventInfo =0;

 
    return TCPIP_MAC_RES_OK;
}
Beispiel #25
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    PIC32MACEventDeInit(TCPIP_MAC_HANDLE hMac )

  Summary:
    De-initializes the ethernet event notification.

  Description:
     This function de-initializes the ethernet event notification.
     It performs any resource clean-up that may be needed.

  Precondition:
     None.

  Parameters:
    hMac      - parameter identifying the intended MAC  
    
  Returns:
    TCPIP_MAC_EVRES_OK  always

  Example:
    <code>
    PIC32MACEventDeInit( hMac );
    </code>

  Remarks:

    Not multi-threaded safe.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT PIC32MACEventDeInit(TCPIP_MAC_HANDLE hMac)
{
    int grpIx;
    PIC32_EV_GROUP_DCPT*  pDcpt; 
    PIC32_EMB_MAC_DCPT*     pMacD = (PIC32_EMB_MAC_DCPT*)hMac;


    SYS_INT_SourceDisable(pMacD->mData._macIntSrc);      // stop Eth ints
    SYS_INT_SourceStatusClear(pMacD->mData._macIntSrc);
    SYS_INT_DynamicRegister(pMacD->mData._macIntSrc, 0, 0); 

    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++)
    {
        pDcpt->_TcpNotifyFnc = 0;
        pDcpt->_TcpEnabledEvents = pDcpt->_TcpPendingEvents = TCPIP_EV_NONE;
        pDcpt->_EthEnabledEvents = pDcpt->_EthPendingEvents = 0;
        pDcpt++;
    }

    _hEventMac = 0;
    return TCPIP_MAC_EVRES_OK;
}
Beispiel #26
0
/*******************************************************************************
  Function:
    TCPIP_MAC_EVENT_RESULT    PIC32MACEventSetNotifyHandler(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, pMacEventF eventHandler, void* hParam)

  Summary:
    Sets a new event notification handler.

  Description:
    This function sets a new event notification handler.
    This is a handler specified by the user of the stack.
    The caller can use the handler to be notified of MAC events.
    Whenever a notification occurs the passed events have to be eventually processed:
    - Stack should process the TCPIP_EV_RX_PKTPEND, TCPIP_EV_TX_DONE  events
    - Process the specific (error) condition
    - Acknowledge the events by calling PIC32MACEventAck() so that they can be re-enabled.

  Precondition:
   TCPIPInit should have been called.
   tcpEvGroup valid value 

  Parameters:
    hMac      - parameter identifying the intended MAC  
    tcpEvGroup   - group of events the notification handler refers to
    eventHandler - the event notification handler
    
  Returns:
    TCPIP_MAC_EVRES_OK  if operation succeeded,
    an error code otherwise

  Example:
    <code>
    PIC32MACEventSetNotifyHandler( hMac, TCPIP_MAC_EVGROUP_ALL, myEventHandler, myParam );
    </code>

  Remarks:   
    The notification handler will be called from the ISR which detects the corresponding event.
    The event notification handler has to be kept as short as possible and non-blocking.
    Mainly useful for RTOS integration where this handler will wake-up a thread that waits for a MAC event to occur.

    The event notification system also 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 at unknown moments.

    Without a notification handler the stack user can still call PIC32MACEventGetPending() to see if processing by the stack needed.

    This is a default way of adding interrupt processing to the stack.
    A separate ISR to catch the Ethernet MAC events and process accordingly
    could be added.

    All the groups specified in the TCPIP_MAC_EVENT_GROUP enumeration is supported.
    However, once a handler for TCPIP_MAC_EVGROUP_ALL is registered all event processing
    will be reported using this global handler.

    Use 0 to remove the handler for a specific event group.

    Not multi-threaded safe accross different TCPIP_MAC_EVENT_GROUP groups.
*****************************************************************************/
TCPIP_MAC_EVENT_RESULT PIC32MACEventSetNotifyHandler(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_EVENT_GROUP tcpEvGroup, pMacEventF eventHandler, void* hParam)
{
    int                   ethILev;
    PIC32_EMB_MAC_DCPT*     pMacD = (PIC32_EMB_MAC_DCPT*)hMac;
    PIC32_EV_GROUP_DCPT*  pDcpt = pMacD->mData._pic32_ev_group_dcpt+tcpEvGroup; 
    
    if(pDcpt->_TcpEnabledEvents != 0)
    {   // already have some active     
        ethILev = SYS_INT_SourceDisable(pMacD->mData._macIntSrc);      // stop ints for a while

        pDcpt->_TcpNotifyFnc = eventHandler;     // set new handler
        pDcpt->_TcpNotifyParam = hParam;
    
        SYS_INT_SourceStatusClear(pMacD->mData._macIntSrc);
        SYS_INT_SourceRestore(pMacD->mData._macIntSrc, ethILev);   // re-enable
    }
    else
    {
        pDcpt->_TcpNotifyFnc = eventHandler;     // set new handler
        pDcpt->_TcpNotifyParam = hParam;
    }
    return TCPIP_MAC_EVRES_OK;
}
Beispiel #27
0
void APP_Initialize ( void )
{
    appData.deviceHandle = USB_DEVICE_HANDLE_INVALID;
    appData.isConfigured = false;

    /* Initialize the keycode array */
    appData.key = USB_HID_KEYBOARD_KEYPAD_KEYBOARD_A;
    appData.keyCodeArray.keyCode[0] = USB_HID_KEYBOARD_KEYPAD_RESERVED_NO_EVENT_INDICATED;
    appData.keyCodeArray.keyCode[1] = USB_HID_KEYBOARD_KEYPAD_RESERVED_NO_EVENT_INDICATED;
    appData.keyCodeArray.keyCode[2] = USB_HID_KEYBOARD_KEYPAD_RESERVED_NO_EVENT_INDICATED;
    appData.keyCodeArray.keyCode[3] = USB_HID_KEYBOARD_KEYPAD_RESERVED_NO_EVENT_INDICATED;
    appData.keyCodeArray.keyCode[4] = USB_HID_KEYBOARD_KEYPAD_RESERVED_NO_EVENT_INDICATED;
    appData.keyCodeArray.keyCode[5] = USB_HID_KEYBOARD_KEYPAD_RESERVED_NO_EVENT_INDICATED;
    
    /* Initialize the modifier keys */
    appData.keyboardModifierKeys.modifierkeys = 0;

    /* Initialise the led state */
    appData.keyboardOutputReport.data = 0;

    /* Intialize the switch state */
    appData.isSwitchPressed = false;
    appData.ignoreSwitchPress = false;

    /* Initialize the HID instance index.  */
    appData.hidInstance = 0;

    /* Initialize tracking variables */
    appData.isReportReceived = false;
    appData.isReportSentComplete = true;

    /* Initialize the application state*/
    appData.state = APP_STATE_INIT;

    SYS_INT_SourceDisable(INT_SOURCE_TIMER_CORE);

}
static void IP101GRWOLIsr(void *p)
{
   DRV_HANDLE hClientObj = (DRV_HANDLE)p;
   eWOL_STATE wol_status;
   wol_status = check_wol_status(hClientObj);
   
   INT_SOURCE src = DRV_ETHPHY_INTERRUPT_SOURCE;
   
   LEDstate ^= SYS_USERIO_LED_ASSERTED;
   SYS_USERIO_SetLED(SYS_USERIO_LED_1, LEDstate);

   switch(wol_status)
   {
        case WOL_SLEEPING:
        case WOL_RDY4SLP:
        {
            manual_set_wol(hClientObj); // change the state of PHY from Normal mode to sleep mode
            break;
        }
        case WOL_WAKEUP: 
        {
            set_wol(hClientObj,IP101GR_WOL_DISABLE,WOL_MODE_MASTER,WOL_TIMER_30SEC);
            break;
        }
        case WOL_RDY4WAKE:
        {
            manual_set_wol(hClientObj); // change the state of PHY from Sleep mode to Wakeup mode
            set_wol(hClientObj,IP101GR_WOL_DISABLE,WOL_MODE_SLAVE,WOL_TIMER_30SEC);
            break;
        }
        case WOL_NORMAL:

        break;        
   }
   SYS_INT_SourceDisable(src);
}
Beispiel #29
0
void IspSpiDMA_Rx(uint8_t *pbuf,uint16_t length)
{
    unsigned char  txTrash[3000];

    bool intEnabled = SYS_INT_SourceDisable(MRFWB0M_INT_SOURCE);


    IEC1CLR=0x00030000; // disable DMA channel 0&1 interrupts
    IFS1CLR=0x00030000; // clear existing DMA channel 0&1 interrupt flag


    PLIB_DMA_Enable(0); // DMACONSET=0x00008000; // enable the DMA controller


    PLIB_DMA_ChannelXPrioritySelect(0,DMA_CHANNEL_0, DMA_CHANNEL_PRIORITY_3);//DCH0CONSET = 0x3; // channel off, pri 3, no chaining
    PLIB_DMA_ChannelXChainDisable(0,DMA_CHANNEL_0);
    PLIB_DMA_ChannelXPrioritySelect(0,DMA_CHANNEL_1, DMA_CHANNEL_PRIORITY_2);//    DCH1CONSET = 0x03;//0x62;
    PLIB_DMA_ChannelXChainEnable(0,DMA_CHANNEL_1);

    DCH0ECONCLR=0xFFFFFFFF; // no start or stop irq?s, no pattern match
    DCH1ECONCLR=0xFFFFFFFF; // no start or stop irq?s, no pattern match

    // program the transfer
    PLIB_DMA_ChannelXSourceStartAddressSet     (0,DMA_CHANNEL_0, ((unsigned long int)txTrash) & 0x1FFFFFFFL);
    PLIB_DMA_ChannelXDestinationStartAddressSet(0,DMA_CHANNEL_1, ((unsigned long int)pbuf)     & 0x1FFFFFFFL);

    if( MRF24W_SPI_CHN == 1)
    {
        PLIB_DMA_ChannelXDestinationStartAddressSet(0,DMA_CHANNEL_0, ((unsigned long int)&SPI1BUF) & 0x1FFFFFFFL);
        PLIB_DMA_ChannelXSourceStartAddressSet     (0,DMA_CHANNEL_1, ((unsigned long int)&SPI1BUF) & 0x1FFFFFFFL);
    }
    else if( MRF24W_SPI_CHN == 2)
    {
        PLIB_DMA_ChannelXDestinationStartAddressSet(0,DMA_CHANNEL_0, ((unsigned long int)&SPI2BUF) & 0x1FFFFFFFL);
        PLIB_DMA_ChannelXSourceStartAddressSet       (0,DMA_CHANNEL_1, ((unsigned long int)&SPI2BUF) & 0x1FFFFFFFL);
    }

    PLIB_DMA_ChannelXSourceSizeSet     (0,DMA_CHANNEL_0,length);
    PLIB_DMA_ChannelXDestinationSizeSet(0,DMA_CHANNEL_0,1     );
    PLIB_DMA_ChannelXCellSizeSet       (0,DMA_CHANNEL_0,1     );

    PLIB_DMA_ChannelXSourceSizeSet     (0,DMA_CHANNEL_1,1);
    PLIB_DMA_ChannelXDestinationSizeSet(0,DMA_CHANNEL_1,length);
    PLIB_DMA_ChannelXCellSizeSet       (0,DMA_CHANNEL_1,1     );


    DCH0INTCLR=0x00ff00ff; // clear existing events, disable all interrupts
    DCH1INTCLR=0x00ff00ff; // clear existing events, disable all interrupts

    // initiate a transfer
    PLIB_DMA_ChannelXStartIRQSet(0, DMA_CHANNEL_0, DMA_TRIGGER_SPI_1_TRANSMIT);
    PLIB_DMA_ChannelXTriggerEnable(0, DMA_CHANNEL_0, DMA_CHANNEL_TRIGGER_TRANSFER_START);

    PLIB_DMA_ChannelXStartIRQSet(0, DMA_CHANNEL_1, DMA_TRIGGER_SPI_1_RECEIVE);
    PLIB_DMA_ChannelXTriggerEnable(0, DMA_CHANNEL_1, DMA_CHANNEL_TRIGGER_TRANSFER_START);


    PLIB_DMA_ChannelXEnable(0,DMA_CHANNEL_0);
    PLIB_DMA_ChannelXEnable(0,DMA_CHANNEL_1);

//      DCH0ECONSET=0x00000080; // set CFORCE to 1
    // do something else
    // poll to see that the transfer was done
    while(true)
    {
        register int pollCnt; // use a poll counter.
        // continuously polling the DMA controller in a tight
        // loop would affect the performance of the DMA transfer
        int dma0Flags=DCH0INT;
        int dma1Flags = DCH1INT;
        if((dma0Flags&0xb)&&(dma1Flags&0xb))
        {   // one of CHERIF (DCHxINT<0>), CHTAIF (DCHxINT<1>)
            // or CHBCIF (DCHxINT<3>) flags set
            break;    // transfer completed
        }
        pollCnt=length<<1; // use an adjusted value here
        while(pollCnt--); // wait before reading again the DMA controller
    }


    PLIB_DMA_Disable(0);

    if(intEnabled)
    {
        DRV_WIFI_INT_SourceEnable();
    }
}
int32_t DRV_SPI_ISRMasterEBM8BitTasks ( struct DRV_SPI_DRIVER_OBJECT * pDrvInstance )    
{
    bool continueLoop;
    
    /* Disable the interrupts */
    SYS_INT_SourceDisable(pDrvInstance->rxInterruptSource);
    SYS_INT_SourceDisable(pDrvInstance->txInterruptSource);
    SYS_INT_SourceDisable(pDrvInstance->errInterruptSource);
    do {
        
        DRV_SPI_JOB_OBJECT * currentJob = pDrvInstance->currentJob;
        SPI_MODULE_ID spiId = pDrvInstance->spiId;
        /* Check for a new task */
        if (pDrvInstance->currentJob == NULL)
        {
            if (DRV_SPI_SYS_QUEUE_Dequeue(pDrvInstance->queue, (void *)&(pDrvInstance->currentJob)) != DRV_SPI_SYS_QUEUE_SUCCESS)
            {
                SYS_ASSERT(false, "\r\nSPI Driver: Error in dequeing.");
                return 0;       
            }
            if (pDrvInstance->currentJob == NULL)
            {
                pDrvInstance->txEnabled = false;
                return 0;
            }
            currentJob = pDrvInstance->currentJob;

            pDrvInstance->symbolsInProgress = 0;

            /* Call the operation starting function pointer.  This can be used to modify the slave select lines */
            DRV_SPI_CLIENT_OBJECT * pClient = (DRV_SPI_CLIENT_OBJECT*)currentJob->pClient;
            if (pClient->operationStarting != NULL)
            {
                (*pClient->operationStarting)(DRV_SPI_BUFFER_EVENT_PROCESSING, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
            }
            /* Check the baud rate.  If its different set the new baud rate*/
            if (pClient->baudRate != pDrvInstance->currentBaudRate)
            {
                PLIB_SPI_BaudRateSet( spiId , SYS_CLK_PeripheralFrequencyGet(pDrvInstance->spiClk), pClient->baudRate );
                pDrvInstance->currentBaudRate = pClient->baudRate;
            }
            
            /* List the new job as processing*/
            currentJob->status = DRV_SPI_BUFFER_EVENT_PROCESSING;
            if (currentJob->dataLeftToTx +currentJob->dummyLeftToTx > PLIB_SPI_RX_8BIT_FIFO_SIZE(spiId))
            {
                PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_TRANSMIT_BUFFER_IS_1HALF_EMPTY_OR_MORE);
                PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_RECEIVE_BUFFER_IS_1HALF_FULL_OR_MORE);
            }
            /* Flush out the Receive buffer */
            PLIB_SPI_BufferClear(spiId);
        }

        /* Set up DMA Receive job.  This is done here to ensure that the RX job is ready to receive when TXing starts*/
        if ((pDrvInstance->rxDmaThreshold != 0) && (currentJob->dataLeftToRx > pDrvInstance->rxDmaThreshold))
        {
            PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_RECEIVE_BUFFER_IS_NOT_EMPTY);
            uint8_t * ptr = &(currentJob->rxBuffer[currentJob->dataRxed]);
            uint32_t len = MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, DRV_SPI_DMA_TXFER_SIZE), currentJob->dataLeftToRx);
            void * spiPtr = PLIB_SPI_BufferAddressGet(spiId);
            currentJob->rxDMAProgressStage = DRV_SPI_DMA_DATA_INPROGRESS;
            currentJob->dataLeftToRx -= len;
            currentJob->dataRxed += len;
            pDrvInstance->rxEnabled = false;
            SYS_DMA_ChannelTransferAdd(pDrvInstance->rxDmaChannelHandle, spiPtr, 1, ptr, len, 1);
        }
        else if ((currentJob->rxDMAProgressStage == DRV_SPI_DMA_NONE) && (currentJob->dataLeftToRx == 0) && (pDrvInstance->rxDmaThreshold != 0) && (currentJob->dummyLeftToRx > pDrvInstance->rxDmaThreshold))
        {
            PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_RECEIVE_BUFFER_IS_NOT_EMPTY);
            uint8_t * ptr = sDrvSpiRxDummy;
            uint32_t len = MIN(MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, DRV_SPI_DMA_DUMMY_BUFFER_SIZE), DRV_SPI_DMA_TXFER_SIZE), currentJob->dummyLeftToRx);
            void * spiPtr = PLIB_SPI_BufferAddressGet(spiId);
            currentJob->rxDMAProgressStage = DRV_SPI_DMA_DUMMY_INPROGRESS;
            currentJob->dummyLeftToRx -= len;
            pDrvInstance->rxEnabled = false;
            SYS_DMA_ChannelTransferAdd(pDrvInstance->rxDmaChannelHandle, spiPtr, 1, ptr, len, 1);
        }       
        /* Set up the DMA Transmit job here.  This is done after the RX job to help prevent buffer overruns.*/
        if ((pDrvInstance->txDmaThreshold != 0) && (currentJob->dataLeftToTx > pDrvInstance->txDmaThreshold))
        {
            PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_TRANSMIT_BUFFER_IS_1HALF_EMPTY_OR_MORE);
            uint8_t * ptr = &(currentJob->txBuffer[currentJob->dataTxed]);
            uint32_t len = MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, DRV_SPI_DMA_TXFER_SIZE), currentJob->dataLeftToTx);
            void * spiPtr = PLIB_SPI_BufferAddressGet(pDrvInstance->spiId);
            currentJob->txDMAProgressStage = DRV_SPI_DMA_DATA_INPROGRESS;
            currentJob->dataLeftToTx -= len;
            currentJob->dataTxed += len;
            pDrvInstance->txEnabled = false;
            SYS_DMA_ChannelTransferAdd(pDrvInstance->txDmaChannelHandle, ptr, len, spiPtr, 1, 1);

        }
        else if ((currentJob->txDMAProgressStage == DRV_SPI_DMA_NONE) && (currentJob->dataLeftToTx == 0) && (pDrvInstance->txDmaThreshold != 0) && (currentJob->dummyLeftToTx > pDrvInstance->txDmaThreshold))
        {
            PLIB_SPI_FIFOInterruptModeSelect(spiId, SPI_FIFO_INTERRUPT_WHEN_TRANSMIT_BUFFER_IS_1HALF_EMPTY_OR_MORE);
            uint8_t * ptr = sDrvSpiTxDummy;
            uint32_t len = MIN(MIN(MIN(PLIB_DMA_MAX_TRF_SIZE, DRV_SPI_DMA_DUMMY_BUFFER_SIZE), DRV_SPI_DMA_TXFER_SIZE), currentJob->dummyLeftToTx);
            void * spiPtr = PLIB_SPI_BufferAddressGet(pDrvInstance->spiId);
            currentJob->txDMAProgressStage = DRV_SPI_DMA_DUMMY_INPROGRESS;
            currentJob->dummyLeftToTx -= len;
            pDrvInstance->txEnabled = false;
            SYS_DMA_ChannelTransferAdd(pDrvInstance->txDmaChannelHandle, ptr, len, spiPtr, 1, 1);
        }
        bool rxDMAInProgress = (currentJob->rxDMAProgressStage == DRV_SPI_DMA_DATA_INPROGRESS) || (currentJob->rxDMAProgressStage == DRV_SPI_DMA_DUMMY_INPROGRESS);
        bool txDMAInProgress = (currentJob->txDMAProgressStage == DRV_SPI_DMA_DATA_INPROGRESS) || (currentJob->txDMAProgressStage == DRV_SPI_DMA_DUMMY_INPROGRESS);
                
        continueLoop = false;
        /* Execute the sub tasks */

        DRV_SPI_ISRErrorTasks(pDrvInstance);
        
        /* Figure out how many bytes are left to be received */
        size_t bytesLeft = currentJob->dataLeftToRx + currentJob->dummyLeftToRx;
        // Check to see if we have any data left to receive and update the bytes left.

        if ((bytesLeft != 0) && !rxDMAInProgress)
        {
            DRV_SPI_MasterEBMReceive8BitISR(pDrvInstance);
            bytesLeft = currentJob->dataLeftToRx + currentJob->dummyLeftToRx;
        }
        
        if 
            (!txDMAInProgress &&
            (currentJob->dataLeftToTx +currentJob->dummyLeftToTx != 0)
            )
        {
            DRV_SPI_MasterEBMSend8BitISR(pDrvInstance);
        }
        
        if ((bytesLeft == 0) && !rxDMAInProgress && !txDMAInProgress)
        {
                    // Disable the interrupt, or more correctly don't re-enable it later*/
                    pDrvInstance->rxEnabled = false;
                    /* Job is complete*/
                    currentJob->status = DRV_SPI_BUFFER_EVENT_COMPLETE;
                    /* Call the job complete call back*/
                    if (currentJob->completeCB != NULL)
                    {
                        (*currentJob->completeCB)(DRV_SPI_BUFFER_EVENT_COMPLETE, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
                    }
                    /* Call the operation complete call back.  This is different than the
                       job complete callback.  This can be used to modify the Slave Select line.
                       The job complete callback can be used to free a client that is blocked 
                       waiting for complete*/
                    DRV_SPI_CLIENT_OBJECT * pClient = (DRV_SPI_CLIENT_OBJECT*)currentJob->pClient;
                    if (pClient->operationEnded != NULL)
                    {
                        (*pClient->operationEnded)(DRV_SPI_BUFFER_EVENT_COMPLETE, (DRV_SPI_BUFFER_HANDLE)currentJob, currentJob->context);
                    }
                    /* Return the job back to the free queue*/
                    if (DRV_SPI_SYS_QUEUE_FreeElement(pDrvInstance->queue, currentJob) != DRV_SPI_SYS_QUEUE_SUCCESS)
                    {
                        SYS_ASSERT(false, "\r\nSPI Driver: Queue free element error.");
                        return 0;
                    }
                    /* Clean up */
                    pDrvInstance->currentJob = NULL;
                    if (!DRV_SPI_SYS_QUEUE_IsEmpty(pDrvInstance->queue))
                    {
                        continueLoop = true;    
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
        else if (rxDMAInProgress)
        {
            // DMA is in progress
            // Wipe out the symbols in Progress
            pDrvInstance->rxEnabled = false;
            pDrvInstance->symbolsInProgress = 0;
        }

    
        /* Check to see if the interrupts would fire again if so just go back into 
           the loop instead of suffering the interrupt latency of exiting and re-entering*/
        if (pDrvInstance->currentJob != NULL)
        {   
            /* Clear the Interrupts */
            SYS_INT_SourceStatusClear(pDrvInstance->rxInterruptSource);
            SYS_INT_SourceStatusClear(pDrvInstance->txInterruptSource);
            SYS_INT_SourceStatusClear(pDrvInstance->errInterruptSource);
            /* Interrupts should immediately become active again if they're in a fired condition */
            if (((pDrvInstance->rxEnabled) && SYS_INT_SourceStatusGet(pDrvInstance->rxInterruptSource)) ||
                ((pDrvInstance->txEnabled) && SYS_INT_SourceStatusGet(pDrvInstance->txInterruptSource)) ||
                (SYS_INT_SourceStatusGet(pDrvInstance->errInterruptSource)))
            {
                /* Interrupt would fire again anyway so we should just go back to the start*/
                continueLoop = true;
                continue;                            
            }
            /* If we're here then we know that the interrupt should not be firing again so we can exit cleanly*/
            /* Clear the interrupts now that we're done*/
            /* Re-enable the interrupts*/
            if (pDrvInstance->rxEnabled)
            {
                SYS_INT_SourceEnable(pDrvInstance->rxInterruptSource);
            }
            if (pDrvInstance->txEnabled)
            {
                SYS_INT_SourceEnable(pDrvInstance->txInterruptSource);
            }
            return 0;            
        }
    
    } while(continueLoop);
    /* if we're here it means that we have no more jobs in the queue, tx and rx interrupts will be re-enabled by the BufferAdd* functions*/
    SYS_INT_SourceStatusClear(pDrvInstance->rxInterruptSource);
    SYS_INT_SourceStatusClear(pDrvInstance->txInterruptSource);
    return 0;
}