⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 theapp.c

📁 dsp DM642 pci 详细的开发例程
💻 C
📖 第 1 页 / 共 2 页
字号:
// TheApp.c
//////////////////////////////////////////////////////////////////////////////
////
////  Copyright (c) 2003, Valley Technologies, Inc.
////  All rights reserved.
////
//////////////////////////////////////////////////////////////////////////////
////
////  $Id: TheApp.c,v 1.4 2004/10/16 02:13:53 ebersole Exp $
////
////  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 (TheApp()) is here, along
////  with several supporting routines and the DM642->Host interrupt
////  callback routine.
////
////  Parts of this file are conditionally-compiled in/out, depending on the
////  user-defined constants found in UserDefndConst.h.
////
//////////////////////////////////////////////////////////////////////////////


//############################################################################
//                             Include Files
//############################################################################


//--------------------------------------------------------------------
// The user-defined/specified constants that control conditional 
//   compilation are in the following header file:
//--------------------------------------------------------------------
#include "UserDefndConst.h"

#include <stdio.h>
#include "dm642_lib.h"

#include "Dm642App.h"

//-----------------------------------------------------------------
// _USE_WINEVENTS_ is one of the user-defined constants found in
// "UserDefndConst.h".  Please see that file for more details.
//-----------------------------------------------------------------
#ifdef _USE_WINEVENTS_

#include <winbase.h>

#endif


//############################################################################
//                            Global Variables
//############################################################################


#ifdef _USE_WINEVENTS_

//------------------------------------------
// The name of the Win32 Event to use...
//------------------------------------------
char *g_strIntEventName  = "EvPciInt";

#else

//-----------------------------------------------
// The name of the busy/wait-loop flag to use...
//-----------------------------------------------
BOOL g_fHasPciIntOccured = FALSE;

#endif


//############################################################################
//                           Function Prototypes
//############################################################################


void MyPciInterruptCallback( DM642_HANDLE           hDM642, 
	                         tDM642InterruptStatus *pStatus );


//############################################################################
//                        Static (PRIVATE) Functions
//############################################################################


//////////////////////////////////////////////////////////////////////////////
////
////  Name: _WaitForDspMasterAddrToChange
////
////  Purpose: This routine waits for the DM642's Master Address Register
////           to change.  The routine sleeps for a minimum of one second
////           between each read of the MAddR.
////           The routine has no timeout mechanism; it will loop forever
////           until MAddR changes.
////
////  Input Parameters:
////      hDM642     - Handle of the currently-open DM642 board/card
////      nOrigVal_i - Original value of Master Address Register.
////
////  Output Parameters: none
////
////  Return Value(s):
////      kNoError (0)    - Indicates that the DSP Master Address Register
////                          has changed
////      other val (!=0) - ERROR occured reading the register
////
//////////////////////////////////////////////////////////////////////////////

static int _WaitForDspMasterAddrToChange(DM642_HANDLE hDM642, unsigned nOrigVal_i)
{
    int          nRC;
    unsigned int nDspMa;

    do
    {
        //-----------------------------------------------------------
        // Sleep to allow the Master Address Register to change ...
        //-----------------------------------------------------------
        Sleep(1);

        //-------------------------------------
        // Read the Master Address Register
        //-------------------------------------
        nRC = DM642ReadDSPMem(hDM642, kDSPMasterAddresReg, &nDspMa, 4);
        if (kNoError != nRC)
        {
            printf("ERROR reading DspMA => %d!\n", nRC);
            return (nRC);
        }

        //--------------------------------------------------------------
        // Mask off the lower bits, which are not part of the address.
        //--------------------------------------------------------------
        nDspMa >>= 2;
        nDspMa  &= 0x3fffffff;

        //---------------------------------------------------------
        // Compare the current value vs. the original.
        // If they are different, bail with a SUCCESS indication.
        //---------------------------------------------------------
        if (nDspMa != nOrigVal_i)
        {
            return (kNoError);
        }
    }
    while(1);

}       // END _WaitForDspMasterAddrToChange()

//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
////
////  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(char          *pcBuf_o,
                                   int            nOffs_i,
                                   unsigned char  nInitialPattern_i,
                                   int            nStep_i )
{
    int           i;
    unsigned char nPattern = nInitialPattern_i;


    //----------------------------------------------
    // First, clear out any garbage in the buffer
    //----------------------------------------------
    memset(pcBuf_o, '\0', BUFSIZE);

    //-------------------------------------------------------------
    // Then write the incrementing/stepping pattern to the buffer.
    //-------------------------------------------------------------
    for (i = nOffs_i; i < BUFSIZE; 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(char *pcBufOne_i,
                           char *pcBufTwo_i,
                           int   nOffs_i )
{
    int j;

    for(j = nOffs_i; j < BUFSIZE; j++)
    {
        if (pcBufOne_i[j] != pcBufTwo_i[j])
        {
            printf("ERROR Buffer mismatch at posn %u\n", j);
            return (-1);
        }
    }

    return (0);

}       // END _CompareBuffers()


//############################################################################
//                       Non-Static (PUBLIC) Functions
//############################################################################


//////////////////////////////////////////////////////////////////////////////
////
////  Name: RunApp
////
////  Purpose: This routine implements the main body of the Host-side
////           application described as Exhibit #2.
////
////           Parts of this routine are conditionally-compiled, based
////           on the user-defined constants NLOOPS and _USE_WINEVENTS_.
////           Depending on the values of these constants, it is possible
////           that this routine will intentionally NOT RETURN.
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s):
////      kNoError (0)  - The test ran successfully, and a finite # of times
////      another value - The test failed.
////
//////////////////////////////////////////////////////////////////////////////

int RunApp(DM642_HANDLE hDM642)
{
    //------------------------------------------------------
    // The three local buffers that drive this application
    //------------------------------------------------------
    static char pDataToSend  [BUFSIZE];
    static char pExpectedData[BUFSIZE];
    static char pRecvdData   [BUFSIZE];

#ifdef _USE_WINEVENTS_

    HANDLE        hPciIntEvent = NULL;

#endif

    DMA_HANDLE    hDma;
    int           nStatus      = kNoError;
    unsigned      nIterCnt;
    unsigned      nIterCntEven;
    unsigned      nIterCntOdd;


    //---------------------------------------------
    // Perform a sanity check on the input(s) ...
    //---------------------------------------------
    if (NULL == hDM642)
    {
        printf("ERROR: DM42 Handle is NULL in RunApp()!\n");
        nStatus = -1;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -