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

📄 dm642app.c

📁 基于DDK的DMA启动传输方式,DSP为主端方式
💻 C
字号:
// Dm642App.c
//////////////////////////////////////////////////////////////////////////////
////
////  Copyright (c) 2003, Valley Technologies, Inc.
////  All rights reserved.
////
//////////////////////////////////////////////////////////////////////////////
////
////  $Header $
////
////  $ReleaseClass: src $
////
////  Original Author                 : ebersole
////  Most Recent Contributing $Author: ebersole $
////
//////////////////////////////////////////////////////////////////////////////
////
////  This file contains only one routine: main().
////
////  main() performs necessary init and setup tasks (for the app and
////  DSP/BIOS), then exits and passes control to DSP/BIOS.  See the
////  the Description/Purpose in main()'s comment-header for more info.
////
////  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 <hwi.h>
#include <sem.h>
#include <gio.h>

#include "Dm642Appcfg.h"
#include "MyGlobals.h"

#include <c64xx_pci.h>

#include <csl.h>
#include <csl_pci.h>


//############################################################################
//                                 Constants
//############################################################################


//-------------------------------------------------------
// Could not find any macro to map a Memory region's
//   name to its segment id (to use in BUF_ and MEM_
//   modules).  So we define these manually.
//-------------------------------------------------------
#define kMemSegId_ISRAM   (0)
#define kMemSegId_SDRAM   (1)

#define kPCIMC_CNT_RstVal (0x000)
#define kDspDmaAddr       (0x80000000)


//############################################################################
//                       (external) Global Variables
//############################################################################


extern tMyPciXferInfo g_oXferInfo;
extern tMyBufInfo     g_oBufInfo;

extern Ptr            g_pMyGio;


//############################################################################
//                            Start of Functions
//############################################################################


//////////////////////////////////////////////////////////////////////////////
////
////  Name: main
////
////  Purpose:  The entry point into the program.
////            Performs any necessary pre-application initialization.
////
////            Waits for the Host-Side Application (for Exhibit #2) to
////            place a byte-count/size into the PCIMC register and a
////            physical PCI address into the PCIMA register.  These values
////            are saved into program globals for later use.
////
////            After the above values are read, a buffer pool is created
////            in SDRAM.  The pool consists of 3 buffers, each equal to
////            the length read from the PCIMC register.
////
////            After the buffer pool has been created, the routine uses
////            DSP/BIOS's GIO-module to create and start the DM642's PCI
////            device driver.  This MUST occur in main()!  [ie, before
////            DPS/BIOS actually takes control of the system.
////
////            Finally, main() returns, which passes control to DSP/BIOS.
////
////  Input Parameters:  none
////  Output Parameters: none
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

Void main()
{
    extern tMyPciXferInfo g_oXferInfo;
    extern BUF_Handle     g_hBufferPool;

    PCI_ConfigXfr     oXfrCfg;
    BUF_Attrs         oBufAttrs;

    C64XX_PCI_Attrs   oPciAttrs;
    GIO_Attrs         oGioAttrs;


    //--------------------------------------
    // Initialize the Chip Support Library
    //--------------------------------------
    CSL_init();

    LOG_printf(&trace, "Dm642App Started");

    //------------------------------------------------------------------
    // Print the current (ie, the boot) values of the DSPMA and PCIMC
    //   registers
    //------------------------------------------------------------------

    PCI_xfrGetConfig(&oXfrCfg);

    LOG_printf(&trace, "PCIMA == %04x_%04x",
              (oXfrCfg.dspma >> 16), (MdUns)oXfrCfg.dspma);
    LOG_printf(&trace, "PCIMC == %04x_%04x",
              (oXfrCfg.pcimc >> 16), (MdUns)oXfrCfg.pcimc);
    
    //------------------------------------------------------------------
    // Wait for the Host to set the transfer-byte-count in the PCIMC
    //   register.  The host will have also set the PCIMA register
    //   at about the same time.  These tell the DSP where the Host
    //   wants its DMA data, and how much data it wants at atime
    //------------------------------------------------------------------
    do
    {
        MdUns nPciByteCnt;


        PCI_xfrGetConfig(&oXfrCfg);
    
        nPciByteCnt = (oXfrCfg.pcimc >> 16) & 0xFFFF;
        
        if (kPCIMC_CNT_RstVal != nPciByteCnt)
        {
            LOG_printf(&trace, "PCIMC[CNT] has been set by the Host.");

            g_oXferInfo.nCountB  = nPciByteCnt;
            g_oXferInfo.pPciAddr = (void *)(oXfrCfg.pcima & _PCI_PCIMA_ADDRMA_MASK);

            break;
        }
    }
    while(1);

    //----------------------------------------------------------
    // Creat a pool of three buffers to use.
    // Place the buffer pool in SDRAM ... up above 0x8000_0000
    //----------------------------------------------------------

    LOG_printf(&trace, "Setting up the buffer pool ...");

    g_oBufInfo.nBufSizeB = g_oXferInfo.nCountB;
    oBufAttrs.segid      = kMemSegId_SDRAM;

    g_oBufInfo.hBufPool = BUF_create(3, g_oBufInfo.nBufSizeB, 4, &oBufAttrs);
    if (NULL == g_oBufInfo.hBufPool)
    {
        SYS_abort("ERROR:Creation of buffer pool failed!");
    }

    //------------------------------------------------------------------------
    // Start-up the PCI driver via DSP/BIOS's GIO module.  This manual
    //   start-up MUST take place.  Without it, the main loop in the appl.
    //   will hang waiting on a semaphore.
    //
    // NOTE: we changed the interrupt-handling in the PCI driver to post
    //       to that semaphore.
    //------------------------------------------------------------------------
    
    oPciAttrs.queuePriority = C64XX_PCI_QUEUE_PRIORITY_LOW;
    
    oGioAttrs.nPackets = 1;
    oGioAttrs.timeout  = SYS_FOREVER;

    g_pMyGio = GIO_create("/UsrDevPci", IOM_INOUT, NULL, &oPciAttrs, &oGioAttrs);
    if(NULL == g_pMyGio)
    {
        LOG_printf(&trace, "ERROR!!! GIO_create() => NULL!");
        SYS_abort("GIO_create");
    }

    //---------------------------------
    // fall into DSP/BIOS idle loop
    //---------------------------------
    return;

}       // END main()


//############################################################################
//                             End of Functions
//############################################################################

⌨️ 快捷键说明

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