Exemplo n.º 1
0
/*****************************************************************************
 * FUNCTION: WFProcess
 *
 * RETURNS:  None
 *
 * PARAMS:   None
 *
 *  NOTES:   This function is called from WFProcess.  It does the following:
 *             1) checks for and processes MRF24W external interrupt events
 *             2) checks for and processes received management messages from the MRF24W
 *             3) maintains the PS-Poll state (if applicable)
 *           
 *****************************************************************************/
void WFProcess(void)
{
    #if defined(__18CXX)
        static UINT16 len;
    #else
        UINT16 len;
    #endif
    
    //----------------------------------------------------------
    // if there is a MRF24W External interrupt (EINT) to process
    //----------------------------------------------------------
    if (g_ExIntNeedsServicing == TRUE)
    {
        g_ExIntNeedsServicing = FALSE;
        ProcessInterruptServiceResult();
    }
    //----------------------------------------
    // else if there is management msg to read
    //----------------------------------------
    else if (g_MgmtReadMsgReady == TRUE)
    {
        RawGetMgmtRxBuffer(&len);

        // handle received managment message
        g_MgmtReadMsgReady = FALSE;
        ProcessMgmtRxMsg();

        // reenable interrupts
        WF_EintEnable();

    }
}
Exemplo n.º 2
0
/*****************************************************************************
 * FUNCTION: WFProcess
 *
 * RETURNS:  None
 *
 * PARAMS:   None
 *
 *  NOTES:   This function is called from WFProcess.  It does the following:
 *             1) checks for and processes MRF24WB0M external interrupt events
 *             2) checks for and processes received management messages from the MRF24WB0M
 *             3) maintains the PS-Poll state (if applicable)
 *           
 *****************************************************************************/
void WFProcess(void)
{
    UINT16 len;

    //----------------------------------------------------------
    // if there is a MRF24WB0M External interrupt (EINT) to process
    //----------------------------------------------------------
    if (g_ExIntNeedsServicing == TRUE)
    {
        g_ExIntNeedsServicing = FALSE;
        ProcessInterruptServiceResult();
    }
    //----------------------------------------
    // else if there is management msg to read
    //----------------------------------------
    else if (g_MgmtReadMsgReady == TRUE)
    {
        /* Ensure the MRF24WB0M is awake (only applies if PS-Poll was enabled) */
        EnsureWFisAwake();

        //-----------------------------
        // process management read
        //-----------------------------
        // if the Raw Rx buffer is available, or only has the scratch mounted, then mount it so
        // we can process received Mgmt message.  Otherwise, stay in this state and keep checking
        // until we can mount the Raw Rx buffer and get the management message.  Once the Raw Rx
        // is acquired, rx data packets are held off until we finish processing mgmt message.
        if ( RawGetMgmtRxBuffer(&len) )
        {
            // handle received managment message
            g_MgmtReadMsgReady = FALSE;
            ProcessMgmtRxMsg();

            // reenable interrupts
            WF_EintEnable();
        }
    }
    //-----------------------------------
    // else no EINT or Mgmt Rx to process
    //-----------------------------------
    else
    {
#if defined (WF_USE_POWER_SAVE_FUNCTIONS)
        /* if PS-Poll mode was enabled by application and was previously deactivated by WF driver */
        if (WFisPsPollEnabled() && !WFIsPsPollActive() )
        {
            /* reactivate PS-Poll mode on MRF24WB0M (allow MRF24WB0M to sleep) */
            WFConfigureLowPowerMode(WF_LOW_POWER_MODE_ON);
        }    
#endif                
    }
}
Exemplo n.º 3
0
/*****************************************************************************
 * FUNCTION: WFProcess
 *
 * RETURNS:  None
 *
 * PARAMS:   None
 *
 *  NOTES:   This function is called from WFProcess.  It does the following:
 *             1) checks for and processes MRF24W external interrupt events
 *             2) checks for and processes received management messages from the MRF24W
 *             3) maintains the PS-Poll state (if applicable)
 *
 *****************************************************************************/
void WFProcess(void)
{
    #if defined(__XC8)
        static uint16_t len;
    #else
        uint16_t len;
    #endif

    //----------------------------------------------------------
    // if there is a MRF24W External interrupt (EINT) to process
    //----------------------------------------------------------
    if (g_ExIntNeedsServicing == true)
    {
        g_ExIntNeedsServicing = false;
        ProcessInterruptServiceResult();
    }
    //----------------------------------------
    // else if there is management msg to read
    //----------------------------------------
    else if (g_MgmtReadMsgReady == true)
    {
        //-----------------------------
        // process management read
        //-----------------------------
        // if the Raw Rx buffer is available, or only has the scratch mounted, then mount it so
        // we can process received Mgmt message.  Otherwise, stay in this state and keep checking
        // until we can mount the Raw Rx buffer and get the management message.  Once the Raw Rx
        // is acquired, rx data packets are held off until we finish processing mgmt message.
        if ( RawGetMgmtRxBuffer(&len) )
        {
            // handle received managment message
            g_MgmtReadMsgReady = false;
            ProcessMgmtRxMsg();

            // reenable interrupts
            WF_EintEnable();
        }
    }
}
Exemplo n.º 4
0
/*****************************************************************************
 * FUNCTION: WFProcess
 *
 * RETURNS:  None
 *
 * PARAMS:   None
 *
 *  NOTES:   This function is called from WFProcess.  It does the following:
 *             1) checks for and processes MRF24WB0M external interrupt events
 *             2) checks for and processes received management messages from the MRF24WB0M
 *             3) maintains the PS-Poll state (if applicable)
 *           
 *****************************************************************************/
void WFProcess(void)
{
    UINT16 len;

    //----------------------------------------------------------
    // if there is a MRF24WB0M External interrupt (EINT) to process
    //----------------------------------------------------------
    if (g_ExIntNeedsServicing == TRUE)
    {
        g_ExIntNeedsServicing = FALSE;
        ProcessInterruptServiceResult();
    }
    //----------------------------------------
    // else if there is management msg to read
    //----------------------------------------
    else if (g_MgmtReadMsgReady == TRUE)
    {
        /* Ensure the MRF24WB0M is awake (only applies if PS-Poll was enabled) */
        EnsureWFisAwake();

        //-----------------------------
        // process management read
        //-----------------------------
        // if the Raw Rx buffer is available, or only has the scratch mounted, then mount it so
        // we can process received Mgmt message.  Otherwise, stay in this state and keep checking
        // until we can mount the Raw Rx buffer and get the management message.  Once the Raw Rx
        // is acquired, rx data packets are held off until we finish processing mgmt message.
        if ( RawGetMgmtRxBuffer(&len) )
        {
            // handle received managment message
            g_MgmtReadMsgReady = FALSE;
            ProcessMgmtRxMsg();

            // reenable interrupts
            WF_EintEnable();
        }
    }
  
}
Exemplo n.º 5
0
/*****************************************************************************
 * FUNCTION: ZGPrvComStateMachine
 *
 * RETURNS: N/A
 *
 * PARAMS:
 *      N/A
 *
 *
 *  NOTES: Represents the State machine for the COM layer of the ZG Driver.
 *      The responsibility of the COM layer is to schedule SPI operations
 *      and act as a receiver of interrupt notifications from the G2100.
 *      Essentially read and write fifo operations are submitted from the
 *      MAC layer 1 at a time and separately an interrupt can be received
 *      from the G2100 the meaning of which needs to be determined.  The
 *      State machine initially starts in the idle state and waits for one
 *      of these 2 events with priority going to the interrupt event however
 *      once an operation is started in cannot be pre-empted.  Interrupt
 *      processing requires reading and writing several chip registers to
 *      learn the meaning of the interrupt and clear the interrupt.  With
 *      the results being routed to the MAC layer for further processing.
 *      Fifo operation is either a read or write operation which involves
 *      several SPI steps that must be scheduled
 *****************************************************************************/
 tZGVoidReturn ZGPrvComStateMachine(tZGVoidInput)
{
    tZGU8 bLoop = 0;
    tZGU16 len;
    tZGBool res;

    do
    {
        if(COMCXT.state == kComStIdle)
        {
            //-----------------------------------------
            // if there is an EINT interrupt to process
            //-----------------------------------------
            if(COMCXT.bIntServiceReq == kZGBoolTrue)
            {
                COMCXT.bIntServiceReq = kZGBoolFalse;
                COMCXT.state = kComStIntService;
            }
            //--------------------------------------------
            // if there is management msg to read or write
            //--------------------------------------------
            else if(COMCXT.bRdWtReady == kZGBoolTrue)
            {
                /* if the chip is in low power mode then it must first be
                 * brought out of low power before attempting a write
                 * operation. */
                if(COMCXT.bLowPowerModeActive)
                {
                    ChangeLowPowerMode(kZGBoolFalse);
                }

                COMCXT.state = (RWCXT.dir == kZGDirWrite)? kComStWriteOperation : kComStReadOperation;

                //----------------------------
                // if doing a management write
                //----------------------------
                if (RWCXT.dir == kZGDirWrite)
                {
                    res = ZGSendRAWManagementFrame(RWCXT.len);
                    if (res == kZGBoolFalse)
                    {
                        ZGErrorHandler((ROM char *)"Mgmt Send Failed");
                    }    
                    COMCXT.bRdWtReady = kZGBoolFalse;
                    ZGPrvMacOpComplete();
                    COMCXT.state = kComStIdle;

                }
                //-----------------------------
                // else doing a management read
                //-----------------------------
                else
                {
                    // if the Raw Rx buffer is available, or only has the scratch mounted, then mount it so
                    // we can process received Mgmt message.  Otherwise, stay in this state and keep checking
                    // until we can mount the Raw Rx buffer and get the management message.  Once the Raw Rx
                    // is acquired, rx data packets are held off until we finish processing mgmt message.
                    if ( ZGRawGetMgmtRxBuffer(&len) )
                    {
                        // handle received managment message
                        COMCXT.bRdWtReady = kZGBoolFalse;
                        ZGPrvMacOpComplete();
                        COMCXT.state = kComStIdle;
                        // reenable interrupts
                        zgHALEintEnable();
                    }
                }
            }
            //-------------------------------------------------------------
            // else no manangement tx or rx to do, so check for other stuff
            //-------------------------------------------------------------
            else
            {
                bLoop = 0;

                /* manage low power control of g2100 */
                if(COMCXT.bLowPowerModeDesired == kZGBoolTrue &&
                    COMCXT.bLowPowerModeActive == kZGBoolFalse &&
                    MACCXT.bMgmtTxMsgReady == kZGBoolTrue)
                {
                    ChangeLowPowerMode(kZGBoolTrue);
                }
            }
        }
        //--------------------------
        // else COMCXT.state != IDLE
        //--------------------------
        else
        {
                bLoop = 1;
                switch(COMCXT.state)
                {

                case kComStIntService: /* use spi to determine device interrupt reason */
                    ProcessInterruptServiceResult();
                    break;

                case kComStReadOperation: /* spi fifo read operation in progress */
                    COMCXT.state = kComStReadWaitFifoDone;
                    ZGPrvMacOpComplete();
                    break;

                case kComStWriteOperation: /* spi fifo write operation in progress */
                    COMCXT.state = kComStWriteWaitFifoDone;
                    ZGPrvMacOpComplete();
                    break;

                case kComStReadWaitFifoDone:
                    COMCXT.state = kComStIdle;
                    break;

                case kComStWriteWaitFifoDone: /* complete the fifo operation */
                    COMCXT.state = kComStIdle;
                    break;
                }
            }
    } while(bLoop);
}