📄 mytasks.c
字号:
/// MyTasks.c
//////////////////////////////////////////////////////////////////////////////
////
//// Copyright (c) 2003, Valley Technologies, Inc.
//// All rights reserved.
////
//////////////////////////////////////////////////////////////////////////////
////
//// $Header $
////
//// $ReleaseClass: src $
////
//// Original Author : ebersole
//// Most Recent Contributing $Author: ebersole $
////
//////////////////////////////////////////////////////////////////////////////
////
//// This file contains the main part of the Exhibit #2 Application being
//// shipped to TI. The main processing routine (ProcessTask()) is here,
//// aong with several supporting routines.
////
//// DSP/BIOS 4.90.270 06-11-03 (barracuda-m10)
//// DDK 1.10.00.23 07-02-03 (ddk-b12)
////
//////////////////////////////////////////////////////////////////////////////
//############################################################################
// Include Files
//############################################################################
#include <std.h>
#include <log.h>
#include <buf.h>
#include <gio.h>
#include "Dm642Appcfg.h"
#include "MyGlobals.h"
#include <c64xx_pci.h>
#include <csl.h>
#include <csl_pci.h>
//############################################################################
// (external) Global Variables
//############################################################################
extern tMyPciXferInfo g_oXferInfo;
extern tMyBufInfo g_oBufInfo;
extern Ptr g_pMyGio;
//############################################################################
// Static (PRIVATE) Functions
//############################################################################
//////////////////////////////////////////////////////////////////////////////
////
//// Name: _FillBufferWithPattern
////
//// Purpose: This routine fill the given buffer with an incrementing
//// pattern defined by the nInitialPattern_i and Step inputs.
////
//// Input Parameters:
//// nOffs_i - Offset (in the buffer) to start the fill
//// nInitialPattern_i - Initial value of the 'stepping' pattern
//// nStep_i - Amount to increment the pattern for each
//// loop iteration
////
//// Output Parameters:
//// pcBuf_o - Buffer to fill
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
static void _FillBufferWithPattern(Byte *pcBuf_o,
Int nOffs_i,
Byte nInitialPattern_i,
Int nStep_i )
{
extern tMyBufInfo g_oBufInfo;
int i;
unsigned char nPattern = nInitialPattern_i;
//------------------------------------
// First, clear out the buffer
//------------------------------------
memset(pcBuf_o, '\0', g_oBufInfo.nBufSizeB);
//-------------------------------------------------------------
// Then write the incrementing/stepping pattern to the buffer.
//-------------------------------------------------------------
for (i = nOffs_i; i < g_oBufInfo.nBufSizeB; i++)
{
pcBuf_o[i] = nPattern;
nPattern += nStep_i;
}
} // END _FillBufferWithPattern()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: _CompareBuffers
////
//// Purpose: Compares two equal-sized buffers on a byte-by-byte basis.
////
//// Input Parameters:
//// pcBufOne_i - One of the two buffers to compare
//// pcBufTwo_i - The other of the buffers to compare
//// nOffs_i - The offset (in BOTH buffers) to start the comparison
////
//// Output Parameters: none
////
//// Return Value(s):
//// -1: The buffers DO NOT match
//// 0: The buffers DO match
////
//////////////////////////////////////////////////////////////////////////////
static int _CompareBuffers(Byte *pcBufOne_i,
Byte *pcBufTwo_i,
int nOffs_i )
{
extern tMyBufInfo g_oBufInfo;
int j;
for(j = nOffs_i; j < g_oBufInfo.nBufSizeB; j++)
{
if (pcBufOne_i[j] != pcBufTwo_i[j])
{
LOG_printf(&trace, "ERROR buffer mismatch at posn %u\n", j);
return (-1);
}
}
return (0);
} // END _CompareBuffers()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: _GrabBuffers
////
//// Purpose: Allocates three equal-sized buffers from the global
//// Buffer Pool
////
//// Input Parameters: none
////
//// Output Parameters:
//// pExdD_o - The Expected Data Buffer (pointer)
//// pRecvD_o - The Received Data Buffer (pointer)
//// pSendD_o - The (to) Send Data Buffer (pointer)
////
//// Return Value(s):
//// < 0: One of the buffers FAILED allocation
//// 0: All buffers were allocated SUCCESSFULLY
////
//////////////////////////////////////////////////////////////////////////////
static int _GrabBuffers(Ptr *pExpD_o,
Ptr *pRecvD_o,
Ptr *pSendD_o )
{
extern tMyBufInfo g_oBufInfo;
LOG_printf(&trace, "Grabbing the buffers ...");
//-----------------------------------------------
// Grab the Expected Data buffer from the Pool
//-----------------------------------------------
*pExpD_o = BUF_alloc(g_oBufInfo.hBufPool);
if (NULL == *pExpD_o)
{
LOG_printf(&trace, "ERROR: ProcessTask(): Could not alloc buffer!");
return (-1);
}
//-----------------------------------------------
// Grab the (to) Send Data buffer from the Pool
//-----------------------------------------------
*pSendD_o = BUF_alloc(g_oBufInfo.hBufPool);
if (NULL == *pSendD_o)
{
LOG_printf(&trace, "ERROR: ProcessTask(): Could not alloc buffer!");
return (-2);
}
//-----------------------------------------------
// Grab the Received Data buffer from the Pool
//-----------------------------------------------
*pRecvD_o = BUF_alloc(g_oBufInfo.hBufPool);
if (NULL == *pRecvD_o)
{
LOG_printf(&trace, "ERROR: ProcessTask(): Could not alloc buffer!");
return (-3);
}
return (0);
} // END _GrabBuffers()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: _InitBuffers
////
//// Purpose: Initializes the three buffers allocated from the Buffer Pool.
////
//// Input Parameters: none
////
//// Output Parameters:
//// pExdD_o - The Expected Data Buffer (pointer)
//// pRecvD_o - The Received Data Buffer (pointer)
//// pSendD_o - The Send Data Buffer (pointer)
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
static void _InitBuffers(Ptr pExpD_o,
Ptr pRecvD_o,
Ptr pSendD_o )
{
extern tMyBufInfo g_oBufInfo;
LOG_printf(&trace, "Filling the (local) buffers ...");
//------------------------------------------------------------
// Fill the Expected Data buffer with a pattern of ascending
// even numbers (8 bits -> 0...254 per byte).
// Skip the 1st 4 bytes of the buffer.
//------------------------------------------------------------
if (NULL != pExpD_o)
{
_FillBufferWithPattern(pExpD_o, sizeof(LgUns), 0, 2);
}
//------------------------------------------------------------
// Fill the (to) Send Data buffer with a pattern of ascending
// odd numbers (8 bits -> 1...255 per byte).
// Skip the 1st 4 bytes of the buffer.
//------------------------------------------------------------
if (NULL != pSendD_o)
{
_FillBufferWithPattern(pSendD_o, sizeof(LgUns), 1, 2);
}
//-----------------------------------------------
// Just clear the Received Data buffer
//-----------------------------------------------
if (NULL != pRecvD_o)
{
memset(pRecvD_o, '\0', g_oBufInfo.nBufSizeB);
}
} // END _InitBuffers()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: _ReleaseBuffers
////
//// Purpose: Returns three buffers to the global Buffer Pool
////
//// Input Parameters:
//// pExdD_o - The Expected Data Buffer (pointer)
//// pRecvD_o - The Received Data Buffer (pointer)
//// pSendD_o - The Send Data Buffer (pointer)
////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -