📄 bf_util.c
字号:
/****************************************************************************
*****************************************************************************
**
** File Name
** ---------
**
** BF_UTIL.C
**
*****************************************************************************
*****************************************************************************
**
** Description
** -----------
**
** Application Buffer Fragment Mapper.
**
*****************************************************************************
*****************************************************************************
**
** Source Change Indices
** ---------------------
**
** Porting: <none>0----<major> Customization: <none>0----<major>
**
*****************************************************************************
*****************************************************************************
** **
** ETHERNET/IP EXAMPLE CODE **
** COPYRIGHT (c) 2000-2005 ODVA (Open DeviceNet Vendor Association) **
** & ControlNet International Ltd. **
** **
** All rights reserved, except as specifically licensed in writing. **
** Use of the Ethernet/IP Example Protocol Software is subject to **
** ODVA's and ControlNet International's Terms of Use Agreement. **
** The following work constitutes example program code and is intended **
** merely to illustrate useful programming techniques. The user is **
** responsible for applying the code correctly. The code is provided **
** AS IS without warranty and is in no way guaranteed to be error-free. **
** **
*****************************************************************************
*****************************************************************************
*/
/****************************************************************************
*****************************************************************************
**
** Change Log
** ----------
**
**
*****************************************************************************
****************************************************************************/
#include "ab_env.h"
#ifdef BUFFER_FRAGMENT_MAPPER
#include "cd.h" /* Communications Device public interfaces */
#include "ad.h" /* Application Data area manager public interfaces */
#include "bf.h" /* Buffer Fragment mapper public interfaces */
#include "bf_util.h" /* Buffer Fragment mapper private secrets */
#include "cd_util.h" /* October,28th 2005, H.F. */
#include "ECInterface.h"
/****************************************************************************
*****************************************************************************
**
** Public Globals
**
*****************************************************************************
****************************************************************************/
GS_MsgQueueType BF_xQid;
/****************************************************************************
*****************************************************************************
**
** Private Globals
**
*****************************************************************************
****************************************************************************/
volatile bf_DataType bf_s;
/****************************************************************************
*****************************************************************************
**
** Public Services
**
*****************************************************************************
****************************************************************************/
/*---------------------------------------------------------------------------
** BF_GetAccessRequest()
**---------------------------------------------------------------------------
*/
BF_AccessTrrblType* BF_GetAccessRequest( AD_AppDataAreaIdType eAppDataAreaId,
UINT32 lMaxCpuTime )
{
volatile bf_AppDataAreaType *psAppDataArea;
/*
** Look up the app memory area.
*/
psAppDataArea = &bf_s.asAppDataAreas[ eAppDataAreaId ];
/*
** If there are no entries, bail.
** If there is an entry, but it's above the cpu time limit, bail.
*/
if( LL_Empty( &psAppDataArea->sAccessRequestList ) )
{
return( NULL );
}
if( LL_FirstEntry( &psAppDataArea->sAccessRequestList )->lCpuTime > lMaxCpuTime )
{
return( NULL );
}
/*
** We have a request in the list that's under the cpu time limit.
*/
return( LL_TakeSingleLinkList( (void *)&psAppDataArea->sAccessRequestList ) );
} /* end of BF_GetAccessRequest() */
/*---------------------------------------------------------------------------
** BF_GetActiveSubList()
**---------------------------------------------------------------------------
*/
StatusType BF_GetActiveSubList( AD_AppDataAreaIdType eAppDataAreaId,
BOOL fCon,
BOOL fFirst,
volatile BF_ActiveEntryType **ppasActiveEntry,
UINT16 *piEntries )
{
volatile bf_AppDataAreaType *psAppDataArea;
volatile BF_ActiveEntryType *psActiveEntry;
volatile bf_ActiveSubListType *psActiveSubList;
UINT16 iLastSubList;
/*
** Look up the details for this AppDataArea.
*/
psAppDataArea = &bf_s.asAppDataAreas[ eAppDataAreaId ];
/*
** Figure out which sublist to grab.
*/
if( fFirst )
{
psAppDataArea->iNextSubList = fCon ? ( BF_NUM_SUB_LISTS / 2 ) : 0;
}
iLastSubList = fCon ? BF_NUM_SUB_LISTS : ( BF_NUM_SUB_LISTS / 2 );
/*
** Now look for a sublist with stuff in it.
*/
while( psAppDataArea->iNextSubList < iLastSubList )
{
psActiveSubList = &( psAppDataArea->asActiveSubList[ psAppDataArea->iNextSubList ] );
if( psActiveSubList->iActiveEntries != 0 )
{
/*
** Found one. Load the starting pointer and entry count.
** Bump the sub-list index for next time.
*/
psActiveEntry = &bf_s.asActiveEntries[ psActiveSubList->iActiveEntry1 ];
*ppasActiveEntry = psActiveEntry;
*piEntries = psActiveSubList->iActiveEntries;
psAppDataArea->iNextSubList++;
return( SUCCESS );
}
/*
** On to the next sub-list.
*/
psAppDataArea->iNextSubList++;
}
/*
** No active sub lists, or we've just run out.
*/
return( FAILURE );
} /* end of BF_GetActiveSubList() */
/*---------------------------------------------------------------------------
** BF_Init()
**---------------------------------------------------------------------------
*/
StatusType BF_Init( UINT16 iOptions )
{
UINT16 i;
UINT16 j;
volatile BF_ActiveEntryType *psActiveEntry;
volatile bf_ActiveSubListType *psActiveSubList;
volatile bf_AppDataAreaType *psAppDataArea;
volatile bf_MappingEntryType *psMappingEntry;
GS_TaskSeedType sSeed;
/*
** Allocate/Create all resources (except for tasks).
*/
if( iOptions & AB_CREATE_RESOURCE )
{
/*
** Create the task's request queue.
*/
BF_xQid = GS_NewMsgQueue();
}
/*
** Initialize all internal data structures.
*/
if( iOptions & AB_INIT_RESOURCE )
{
/*
** Clear out the mapping entry list.
*/
bf_s.iMappingEntries = 0;
psMappingEntry = &bf_s.asMappingEntries[ 0 ];
for( i = 0; i < BF_NUM_MAPPINGS; i++ )
{
psMappingEntry->iClass = 0;
psMappingEntry->iInstance = 0;
psMappingEntry->fCon = FALSE;
psMappingEntry->eAppDataAreaId = AD_NO_APP_DATA_AREA;
psMappingEntry->iAppDataAreaOffset = 0;
psMappingEntry->iMaxMappingSize = 0;
psMappingEntry->iStatusBit = AB_NO_CONN_STATUS_BIT;
psMappingEntry->iStatusStyle = 0;
psMappingEntry->iConfiguredUsers = 0;
psMappingEntry->iActiveUsers = 0;
psMappingEntry->iTransportId = 0;
psMappingEntry->iActiveEntry = BF_NO_MAPPING;
psMappingEntry->iActiveSubList = 0;
psMappingEntry++;
}
/*
** Clear out the active entry list.
*/
bf_s.iActiveEntries = 0;
psActiveEntry = &bf_s.asActiveEntries[ 0 ];
for( i = 0; i < BF_NUM_MAPPINGS; i++ )
{
psActiveEntry->pSource = NULL;
psActiveEntry->pDestination = NULL;
psActiveEntry->iResyncSize = 0;
psActiveEntry->iTranBufOffset = 0;
psActiveEntry->pAddStatus = NULL;
psActiveEntry->iTransportId = 0;
psActiveEntry++;
}
/*
** Clear out the mapping entry list sorted by transport ID.
*/
for( i = 0; i < BF_NUM_MAPPINGS; i++ )
{
bf_s.aiMappingByTransport[ i ] = BF_NO_MAPPING;
}
/*
** Clear out the app memory area list.
*/
psAppDataArea = &bf_s.asAppDataAreas[ 0 ];
for( i = 0; i < AD_NUM_APP_DATA_AREAS; i++ )
{
psAppDataArea->pBaseAddress = NULL;
psAppDataArea->iSize = 0;
psAppDataArea->xMNotifyQueue = GS_NO_QUEUE;
psAppDataArea->iMNotifyBitMsg = 0;
psAppDataArea->xMNotifySemaphore = GS_NO_SEMAPHORE;
psAppDataArea->xSNotifyQueue = GS_NO_QUEUE;
psAppDataArea->iSNotifyBitMsg = 0;
psAppDataArea->xSNotifySemaphore = GS_NO_SEMAPHORE;
psAppDataArea->lCpuTimePerMessage = 0L;
psAppDataArea->lCpuTimePerEntry = 0L;
psAppDataArea->lCpuTimePerByte = 0L;
psAppDataArea->lCpuTimeMaxResync = 1L;
psAppDataArea->lCpuTimeMaxPerSecArea = 1L;
psAppDataArea->lCpuTimeMaxPerSecSystem = 1L;
LL_Init( &psAppDataArea->sAccessRequestList );
psAppDataArea->iNextSubList = 0;
psActiveSubList = &psAppDataArea->asActiveSubList[ 0 ];
for( j = 0; j < BF_NUM_SUB_LISTS; j++ )
{
psActiveSubList->iActiveEntry1 = 0;
psActiveSubList->iActiveEntries = 0;
psActiveSubList->lCpuTimeAreaSubList = 0L;
psActiveSubList++;
}
psAppDataArea++;
}
/*
** Max allowed CPU time for BF/AD activities.
*/
bf_s.lCpuTimeMaxPerSecSystem = 1L;
}
/*
** Create the task & associate it with the message queue created earlier.
*/
if( iOptions & AB_CREATE_TASK )
{
sSeed.pRoutine = bf_Task;
sSeed.pParameter = NULL;
sSeed.pStack = NULL;
sSeed.iStackSize = BF_STACK_SIZE;
sSeed.nPrio = BF_TASK_PRIO;
sSeed.pTaskName = "BF";
GS_AssociateTaskAndQueues( GS_NewTask( &sSeed ), BF_xQid, GS_NO_QUEUE );
}
/*
** Final initialization after tasks are running.
*/
if( iOptions & AB_INIT_TASK )
{
}
return( SUCCESS );
} /* end of BF_Init() */
/*---------------------------------------------------------------------------
** BF_UpdateMapping()
**---------------------------------------------------------------------------
*/
BOOL BF_UpdateMapping( UINT16 iTransportId, void *pTranBuf )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -