OpenCores
URL https://opencores.org/ocsvn/openfire2/openfire2/trunk

Subversion Repositories openfire2

[/] [openfire2/] [trunk/] [sw/] [freertos/] [croutine.c] - Diff between revs 4 and 6

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 6
/*
/*
        FreeRTOS.org V4.2.0 - Copyright (C) 2003-2007 Richard Barry.
        FreeRTOS.org V4.2.0 - Copyright (C) 2003-2007 Richard Barry.
 
 
        This file is part of the FreeRTOS.org distribution.
        This file is part of the FreeRTOS.org distribution.
 
 
        FreeRTOS.org is free software; you can redistribute it and/or modify
        FreeRTOS.org is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
        (at your option) any later version.
 
 
        FreeRTOS.org is distributed in the hope that it will be useful,
        FreeRTOS.org is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
        GNU General Public License for more details.
 
 
        You should have received a copy of the GNU General Public License
        You should have received a copy of the GNU General Public License
        along with FreeRTOS.org; if not, write to the Free Software
        along with FreeRTOS.org; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
        A special exception to the GPL can be applied should you wish to distribute
        A special exception to the GPL can be applied should you wish to distribute
        a combined work that includes FreeRTOS.org, without being obliged to provide
        a combined work that includes FreeRTOS.org, without being obliged to provide
        the source code for any proprietary components.  See the licensing section
        the source code for any proprietary components.  See the licensing section
        of http://www.FreeRTOS.org for full details of how and when the exception
        of http://www.FreeRTOS.org for full details of how and when the exception
        can be applied.
        can be applied.
 
 
        ***************************************************************************
        ***************************************************************************
        See http://www.FreeRTOS.org for documentation, latest information, license
        See http://www.FreeRTOS.org for documentation, latest information, license
        and contact details.  Please ensure to read the configuration and relevant
        and contact details.  Please ensure to read the configuration and relevant
        port sections of the online documentation.
        port sections of the online documentation.
        ***************************************************************************
        ***************************************************************************
*/
*/
 
 
#include "FreeRTOS.h"
#include "FreeRTOS.h"
#include "task.h"
#include "task.h"
#include "croutine.h"
#include "croutine.h"
 
 
/* Lists for ready and blocked co-routines. --------------------*/
/* Lists for ready and blocked co-routines. --------------------*/
static xList pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ];  /*< Prioritised ready co-routines. */
static xList pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ];  /*< Prioritised ready co-routines. */
static xList xDelayedCoRoutineList1;                                                                    /*< Delayed co-routines. */
static xList xDelayedCoRoutineList1;                                                                    /*< Delayed co-routines. */
static xList xDelayedCoRoutineList2;                                                                    /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
static xList xDelayedCoRoutineList2;                                                                    /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
static xList * pxDelayedCoRoutineList;                                                                  /*< Points to the delayed co-routine list currently being used. */
static xList * pxDelayedCoRoutineList;                                                                  /*< Points to the delayed co-routine list currently being used. */
static xList * pxOverflowDelayedCoRoutineList;                                                  /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
static xList * pxOverflowDelayedCoRoutineList;                                                  /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
static xList xPendingReadyList;                                                                                 /*< Holds co-routines that have been readied by an external event.  They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
static xList xPendingReadyList;                                                                                 /*< Holds co-routines that have been readied by an external event.  They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
 
 
/* Other file private variables. --------------------------------*/
/* Other file private variables. --------------------------------*/
corCRCB * pxCurrentCoRoutine = NULL;
corCRCB * pxCurrentCoRoutine = NULL;
static unsigned portBASE_TYPE uxTopCoRoutineReadyPriority = 0;
static unsigned portBASE_TYPE uxTopCoRoutineReadyPriority = 0;
static portTickType xCoRoutineTickCount = 0;
static portTickType xCoRoutineTickCount = 0;
 
 
/* The initial state of the co-routine when it is created. */
/* The initial state of the co-routine when it is created. */
#define corINITIAL_STATE        ( 0 )
#define corINITIAL_STATE        ( 0 )
 
 
/*
/*
 * Place the co-routine represented by pxCRCB into the appropriate ready queue
 * Place the co-routine represented by pxCRCB into the appropriate ready queue
 * for the priority.  It is inserted at the end of the list.
 * for the priority.  It is inserted at the end of the list.
 *
 *
 * This macro accesses the co-routine ready lists and therefore must not be
 * This macro accesses the co-routine ready lists and therefore must not be
 * used from within an ISR.
 * used from within an ISR.
 */
 */
#define prvAddCoRoutineToReadyQueue( pxCRCB )                                                                                                                                           \
#define prvAddCoRoutineToReadyQueue( pxCRCB )                                                                                                                                           \
{                                                                                                                                                                                                                                       \
{                                                                                                                                                                                                                                       \
        if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority )                                                                                                                  \
        if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority )                                                                                                                  \
        {                                                                                                                                                                                                                               \
        {                                                                                                                                                                                                                               \
                uxTopCoRoutineReadyPriority = pxCRCB->uxPriority;                                                                                                                       \
                uxTopCoRoutineReadyPriority = pxCRCB->uxPriority;                                                                                                                       \
        }                                                                                                                                                                                                                               \
        }                                                                                                                                                                                                                               \
        vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) );  \
        vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) );  \
}
}
 
 
/*
/*
 * Utility to ready all the lists used by the scheduler.  This is called
 * Utility to ready all the lists used by the scheduler.  This is called
 * automatically upon the creation of the first co-routine.
 * automatically upon the creation of the first co-routine.
 */
 */
static void prvInitialiseCoRoutineLists( void );
static void prvInitialiseCoRoutineLists( void );
 
 
/*
/*
 * Co-routines that are readied by an interrupt cannot be placed directly into
 * Co-routines that are readied by an interrupt cannot be placed directly into
 * the ready lists (there is no mutual exclusion).  Instead they are placed in
 * the ready lists (there is no mutual exclusion).  Instead they are placed in
 * in the pending ready list in order that they can later be moved to the ready
 * in the pending ready list in order that they can later be moved to the ready
 * list by the co-routine scheduler.
 * list by the co-routine scheduler.
 */
 */
static inline void prvCheckPendingReadyList( void );
static inline void prvCheckPendingReadyList( void );
 
 
/*
/*
 * Macro that looks at the list of co-routines that are currently delayed to
 * Macro that looks at the list of co-routines that are currently delayed to
 * see if any require waking.
 * see if any require waking.
 *
 *
 * Co-routines are stored in the queue in the order of their wake time -
 * Co-routines are stored in the queue in the order of their wake time -
 * meaning once one co-routine has been found whose timer has not expired
 * meaning once one co-routine has been found whose timer has not expired
 * we need not look any further down the list.
 * we need not look any further down the list.
 */
 */
static inline void prvCheckDelayedList( void );
static inline void prvCheckDelayedList( void );
 
 
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
 
 
signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex )
signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex )
{
{
signed portBASE_TYPE xReturn;
signed portBASE_TYPE xReturn;
corCRCB *pxCoRoutine;
corCRCB *pxCoRoutine;
 
 
        /* Allocate the memory that will store the co-routine control block. */
        /* Allocate the memory that will store the co-routine control block. */
        pxCoRoutine = ( corCRCB * ) pvPortMalloc( sizeof( corCRCB ) );
        pxCoRoutine = ( corCRCB * ) pvPortMalloc( sizeof( corCRCB ) );
        if( pxCoRoutine )
        if( pxCoRoutine )
        {
        {
                /* If pxCurrentCoRoutine is NULL then this is the first co-routine to
                /* If pxCurrentCoRoutine is NULL then this is the first co-routine to
                be created and the co-routine data structures need initialising. */
                be created and the co-routine data structures need initialising. */
                if( pxCurrentCoRoutine == NULL )
                if( pxCurrentCoRoutine == NULL )
                {
                {
                        pxCurrentCoRoutine = pxCoRoutine;
                        pxCurrentCoRoutine = pxCoRoutine;
                        prvInitialiseCoRoutineLists();
                        prvInitialiseCoRoutineLists();
                }
                }
 
 
                /* Check the priority is within limits. */
                /* Check the priority is within limits. */
                if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES )
                if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES )
                {
                {
                        uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1;
                        uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1;
                }
                }
 
 
                /* Fill out the co-routine control block from the function parameters. */
                /* Fill out the co-routine control block from the function parameters. */
                pxCoRoutine->uxState = corINITIAL_STATE;
                pxCoRoutine->uxState = corINITIAL_STATE;
                pxCoRoutine->uxPriority = uxPriority;
                pxCoRoutine->uxPriority = uxPriority;
                pxCoRoutine->uxIndex = uxIndex;
                pxCoRoutine->uxIndex = uxIndex;
                pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode;
                pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode;
 
 
                /* Initialise all the other co-routine control block parameters. */
                /* Initialise all the other co-routine control block parameters. */
                vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );
                vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );
                vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );
                vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );
 
 
                /* Set the co-routine control block as a link back from the xListItem.
                /* Set the co-routine control block as a link back from the xListItem.
                This is so we can get back to the containing CRCB from a generic item
                This is so we can get back to the containing CRCB from a generic item
                in a list. */
                in a list. */
                listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );
                listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );
                listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );
                listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );
 
 
                /* Event lists are always in priority order. */
                /* Event lists are always in priority order. */
                listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );
                listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );
 
 
                /* Now the co-routine has been initialised it can be added to the ready
                /* Now the co-routine has been initialised it can be added to the ready
                list at the correct priority. */
                list at the correct priority. */
                prvAddCoRoutineToReadyQueue( pxCoRoutine );
                prvAddCoRoutineToReadyQueue( pxCoRoutine );
 
 
                xReturn = pdPASS;
                xReturn = pdPASS;
        }
        }
        else
        else
        {
        {
                xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
                xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
        }
        }
 
 
        return xReturn;
        return xReturn;
}
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
 
 
void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList )
void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList )
{
{
portTickType xTimeToWake;
portTickType xTimeToWake;
 
 
        /* Calculate the time to wake - this may overflow but this is
        /* Calculate the time to wake - this may overflow but this is
        not a problem. */
        not a problem. */
        xTimeToWake = xCoRoutineTickCount + xTicksToDelay;
        xTimeToWake = xCoRoutineTickCount + xTicksToDelay;
 
 
        /* We must remove ourselves from the ready list before adding
        /* We must remove ourselves from the ready list before adding
        ourselves to the blocked list as the same list item is used for
        ourselves to the blocked list as the same list item is used for
        both lists. */
        both lists. */
        vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
        vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
 
 
        /* The list item will be inserted in wake time order. */
        /* The list item will be inserted in wake time order. */
        listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );
        listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );
 
 
        if( xTimeToWake < xCoRoutineTickCount )
        if( xTimeToWake < xCoRoutineTickCount )
        {
        {
                /* Wake time has overflowed.  Place this item in the
                /* Wake time has overflowed.  Place this item in the
                overflow list. */
                overflow list. */
                vListInsert( ( xList * ) pxOverflowDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
                vListInsert( ( xList * ) pxOverflowDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
        }
        }
        else
        else
        {
        {
                /* The wake time has not overflowed, so we can use the
                /* The wake time has not overflowed, so we can use the
                current block list. */
                current block list. */
                vListInsert( ( xList * ) pxDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
                vListInsert( ( xList * ) pxDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
        }
        }
 
 
        if( pxEventList )
        if( pxEventList )
        {
        {
                /* Also add the co-routine to an event list.  If this is done then the
                /* Also add the co-routine to an event list.  If this is done then the
                function must be called with interrupts disabled. */
                function must be called with interrupts disabled. */
                vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) );
                vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) );
        }
        }
}
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
 
 
static inline void prvCheckPendingReadyList( void )
static inline void prvCheckPendingReadyList( void )
{
{
        /* Are there any co-routines waiting to get moved to the ready list?  These
        /* Are there any co-routines waiting to get moved to the ready list?  These
        are co-routines that have been readied by an ISR.  The ISR cannot access
        are co-routines that have been readied by an ISR.  The ISR cannot access
        the     ready lists itself. */
        the     ready lists itself. */
        while( !listLIST_IS_EMPTY( &xPendingReadyList ) )
        while( !listLIST_IS_EMPTY( &xPendingReadyList ) )
        {
        {
                corCRCB *pxUnblockedCRCB;
                corCRCB *pxUnblockedCRCB;
 
 
                /* The pending ready list can be accessed by an ISR. */
                /* The pending ready list can be accessed by an ISR. */
                portDISABLE_INTERRUPTS();
                portDISABLE_INTERRUPTS();
                {
                {
                        pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyList) );
                        pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyList) );
                        vListRemove( &( pxUnblockedCRCB->xEventListItem ) );
                        vListRemove( &( pxUnblockedCRCB->xEventListItem ) );
                }
                }
                portENABLE_INTERRUPTS();
                portENABLE_INTERRUPTS();
 
 
                vListRemove( &( pxUnblockedCRCB->xGenericListItem ) );
                vListRemove( &( pxUnblockedCRCB->xGenericListItem ) );
                prvAddCoRoutineToReadyQueue( pxUnblockedCRCB );
                prvAddCoRoutineToReadyQueue( pxUnblockedCRCB );
        }
        }
}
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
 
 
static inline void prvCheckDelayedList( void )
static inline void prvCheckDelayedList( void )
{
{
static portTickType xLastTickCount, xPassedTicks;
static portTickType xLastTickCount, xPassedTicks;
corCRCB *pxCRCB;
corCRCB *pxCRCB;
 
 
        xPassedTicks = xTaskGetTickCount() - xLastTickCount;
        xPassedTicks = xTaskGetTickCount() - xLastTickCount;
        while( xPassedTicks )
        while( xPassedTicks )
        {
        {
                xCoRoutineTickCount++;
                xCoRoutineTickCount++;
                xPassedTicks--;
                xPassedTicks--;
 
 
                /* If the tick count has overflowed we need to swap the ready lists. */
                /* If the tick count has overflowed we need to swap the ready lists. */
                if( xCoRoutineTickCount == 0 )
                if( xCoRoutineTickCount == 0 )
                {
                {
                        xList * pxTemp;
                        xList * pxTemp;
 
 
                        /* Tick count has overflowed so we need to swap the delay lists.  If there are
                        /* Tick count has overflowed so we need to swap the delay lists.  If there are
                        any items in pxDelayedCoRoutineList here then there is an error! */
                        any items in pxDelayedCoRoutineList here then there is an error! */
                        pxTemp = pxDelayedCoRoutineList;
                        pxTemp = pxDelayedCoRoutineList;
                        pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList;
                        pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList;
                        pxOverflowDelayedCoRoutineList = pxTemp;
                        pxOverflowDelayedCoRoutineList = pxTemp;
                }
                }
 
 
                /* See if this tick has made a timeout expire. */
                /* See if this tick has made a timeout expire. */
                while( ( pxCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ) ) != NULL )
                while( ( pxCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ) ) != NULL )
                {
                {
                        if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )
                        if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )
                        {
                        {
                                /* Timeout not yet expired. */
                                /* Timeout not yet expired. */
                                break;
                                break;
                        }
                        }
 
 
                        portDISABLE_INTERRUPTS();
                        portDISABLE_INTERRUPTS();
                        {
                        {
                                /* The event could have occurred just before this critical
                                /* The event could have occurred just before this critical
                                section.  If this is the case then the generic list item will
                                section.  If this is the case then the generic list item will
                                have been moved to the pending ready list and the following
                                have been moved to the pending ready list and the following
                                line is still valid.  Also the pvContainer parameter will have
                                line is still valid.  Also the pvContainer parameter will have
                                been set to NULL so the following lines are also valid. */
                                been set to NULL so the following lines are also valid. */
                                vListRemove( &( pxCRCB->xGenericListItem ) );
                                vListRemove( &( pxCRCB->xGenericListItem ) );
 
 
                                /* Is the co-routine waiting on an event also? */
                                /* Is the co-routine waiting on an event also? */
                                if( pxCRCB->xEventListItem.pvContainer )
                                if( pxCRCB->xEventListItem.pvContainer )
                                {
                                {
                                        vListRemove( &( pxCRCB->xEventListItem ) );
                                        vListRemove( &( pxCRCB->xEventListItem ) );
                                }
                                }
                        }
                        }
                        portENABLE_INTERRUPTS();
                        portENABLE_INTERRUPTS();
 
 
                        prvAddCoRoutineToReadyQueue( pxCRCB );
                        prvAddCoRoutineToReadyQueue( pxCRCB );
                }
                }
        }
        }
 
 
        xLastTickCount = xCoRoutineTickCount;
        xLastTickCount = xCoRoutineTickCount;
}
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
 
 
void vCoRoutineSchedule( void )
void vCoRoutineSchedule( void )
{
{
        /* See if any co-routines readied by events need moving to the ready lists. */
        /* See if any co-routines readied by events need moving to the ready lists. */
        prvCheckPendingReadyList();
        prvCheckPendingReadyList();
 
 
        /* See if any delayed co-routines have timed out. */
        /* See if any delayed co-routines have timed out. */
        prvCheckDelayedList();
        prvCheckDelayedList();
 
 
        /* Find the highest priority queue that contains ready co-routines. */
        /* Find the highest priority queue that contains ready co-routines. */
        while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
        while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
        {
        {
                if( uxTopCoRoutineReadyPriority == 0 )
                if( uxTopCoRoutineReadyPriority == 0 )
                {
                {
                        /* No more co-routines to check. */
                        /* No more co-routines to check. */
                        return;
                        return;
                }
                }
                --uxTopCoRoutineReadyPriority;
                --uxTopCoRoutineReadyPriority;
        }
        }
 
 
        /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines
        /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines
         of the same priority get an equal share of the processor time. */
         of the same priority get an equal share of the processor time. */
        listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) );
        listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) );
 
 
        /* Call the co-routine. */
        /* Call the co-routine. */
        ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex );
        ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex );
 
 
        return;
        return;
}
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
 
 
static void prvInitialiseCoRoutineLists( void )
static void prvInitialiseCoRoutineLists( void )
{
{
unsigned portBASE_TYPE uxPriority;
unsigned portBASE_TYPE uxPriority;
 
 
        for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )
        for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )
        {
        {
                vListInitialise( ( xList * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );
                vListInitialise( ( xList * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );
        }
        }
 
 
        vListInitialise( ( xList * ) &xDelayedCoRoutineList1 );
        vListInitialise( ( xList * ) &xDelayedCoRoutineList1 );
        vListInitialise( ( xList * ) &xDelayedCoRoutineList2 );
        vListInitialise( ( xList * ) &xDelayedCoRoutineList2 );
        vListInitialise( ( xList * ) &xPendingReadyList );
        vListInitialise( ( xList * ) &xPendingReadyList );
 
 
        /* Start with pxDelayedCoRoutineList using list1 and the
        /* Start with pxDelayedCoRoutineList using list1 and the
        pxOverflowDelayedCoRoutineList using list2. */
        pxOverflowDelayedCoRoutineList using list2. */
        pxDelayedCoRoutineList = &xDelayedCoRoutineList1;
        pxDelayedCoRoutineList = &xDelayedCoRoutineList1;
        pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2;
        pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2;
}
}
/*-----------------------------------------------------------*/
/*-----------------------------------------------------------*/
 
 
signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList )
signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList )
{
{
corCRCB *pxUnblockedCRCB;
corCRCB *pxUnblockedCRCB;
signed portBASE_TYPE xReturn;
signed portBASE_TYPE xReturn;
 
 
        /* This function is called from within an interrupt.  It can only access
        /* This function is called from within an interrupt.  It can only access
        event lists and the pending ready list. */
        event lists and the pending ready list. */
        pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
        pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
        vListRemove( &( pxUnblockedCRCB->xEventListItem ) );
        vListRemove( &( pxUnblockedCRCB->xEventListItem ) );
        vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxUnblockedCRCB->xEventListItem ) );
        vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxUnblockedCRCB->xEventListItem ) );
 
 
        if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )
        if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )
        {
        {
                xReturn = pdTRUE;
                xReturn = pdTRUE;
        }
        }
        else
        else
        {
        {
                xReturn = pdFALSE;
                xReturn = pdFALSE;
        }
        }
 
 
        return xReturn;
        return xReturn;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.