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

📄 ata_test.c

📁 TI的DM6446的硬件平台搭建的相关例子
💻 C
字号:
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 *
 *  Not for distribution.
 */

/*
 *  ATA Test
 *
 */

/*
 *  Note: With the PLL set to 459 MHz and the default timing settings used
 *        the period in ULTRA DMA mode is about  60%-80% above spec.
 *        The Ultra DMA mode does work properly, but the throughput on writing
 *        to the harddrive will be much slower.
 */

#include "stdio.h"
#include "ata.h"

/*
 *  Note: The variables: ata_prd_table, rx, tx
 *        must be located in a memory space accessible by the ATA DMA.
 *        If the memory location is not in a accessible location, the ATA DMA
 *        cannot function correctly, and does not send or receive data.
 *
 *        The DDR2 and AEMIF are both accessible to the ATA DMA.  More locations
 *        can be found in the DaVinci System's Guide under the Memory map section.
 *        There it is detailed what memory locations can be viewed by all periphearls.
 *
 */

#pragma DATA_SECTION ( ata_prd_table, ".ddr2" );
Uint32 ata_prd_table[2];
#pragma DATA_SECTION ( rx, ".ddr2" );
Uint8 rx[512];
#pragma DATA_SECTION ( tx, ".ddr2" );
Uint8 tx[512];


/*
 *  PRD table is require for all DMA ( Multiword, Ultra ) transfers
 */
Uint32* ata_prd_word0 = &ata_prd_table[0];      // 32-bit memory address
Uint32* ata_prd_word1 = &ata_prd_table[1];      // 16-bit byte count + 1-bit EOT

/*
 *  ID sector holder
 */
Uint8 id[512];

/*
 *  Note: Depending on the harrdrive attached, the harddrive will
 *        take some time to write the data after a DMA write.
 *        The wait below is used to compensate for this.
 */
Uint32 dma_write_wait = 0;

/*
 *  Note: Depending on the speed of the DaVinci PLL1, speed memory
 *        and type of memory for storing sector data, it will take
 *        some time to transfer the data from the ATA FIFOs after
 *        a DMA read.  The wait below is used to compensate for this.
 */
Uint32 dma_read_wait  = 0x4000;

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  dma_addr( start, count )                                                *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 dma_addr( Uint32 start, Uint32 count )
{
    Int32 i, j;
    Uint32* buf32;
    Uint32 end = start + count - 1;

    printf( "    DMA Addr test    [%d-%d] sector\n", start, end );

    /* ---------------------------------------------------------------- *
     *  Write Sectors                                                   *
     * ---------------------------------------------------------------- */
    for ( j = start ; j <= end ; j++ )
    {
        buf32 = ( Uint32* )tx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = ( j * ATA_SECTOR_SIZE ) + i;

        ATA_writeSectorDma( ( Uint32 )tx, j, 1, dma_write_wait );
    }

    /* ---------------------------------------------------------------- *
     *  Verify Sectors                                                  *
     * ---------------------------------------------------------------- */
    for ( j = 1 ; j <= 3 ; j++ )
    {
        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = 0;

        ATA_readSectorDma( j, ( Uint32 )rx, 1, dma_read_wait );

        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            if ( *buf32++ != ( j << ATA_SECTOR_SIZE_POW2 ) + i )
                return ( Int16 )( ( j << ATA_SECTOR_SIZE_POW2 ) + i ) | 1;
    }
    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  dma_invaddr( start, count )                                             *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 dma_invaddr( Uint32 start, Uint32 count )
{
    Int32 i, j;
    Uint32* buf32;
    Uint32 end = start + count - 1;

    printf( "    DMA InvAddr test [%d-%d] sector\n", start, end );

    /* ---------------------------------------------------------------- *
     *  Write Sectors                                                   *
     * ---------------------------------------------------------------- */
    for ( j = start ; j <= end ; j++ )
    {
        buf32 = ( Uint32* )tx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = ~( j << ATA_SECTOR_SIZE_POW2 ) + i;

        ATA_writeSectorDma( ( Uint32 )tx, j, 1, dma_write_wait );
    }

    /* ---------------------------------------------------------------- *
     *  Verify Sectors                                                  *
     * ---------------------------------------------------------------- */
    for ( j = start ; j <= end ; j++ )
    {
        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = 0;

        ATA_readSectorDma( j, ( Uint32 )rx, 1, dma_read_wait );

        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            if ( *buf32++ != ~( j << ATA_SECTOR_SIZE_POW2 ) + i )
                return ( Int16 )( ( j << ATA_SECTOR_SIZE_POW2 ) + i ) | 1;
    }
    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  pio_addr( start, count )                                                *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 pio_addr( Uint32 start, Uint32 count )
{
    Int32 i, j;
    Uint32* buf32;
    Uint32 end = start + count - 1;

    printf( "    PIO Addr test    [%d-%d] sector\n", start, end );

    /* ---------------------------------------------------------------- *
     *  Write Sectors                                                   *
     * ---------------------------------------------------------------- */
    for ( j = start ; j <= end ; j++ )
    {
        buf32 = ( Uint32* )tx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = ( j * ATA_SECTOR_SIZE ) + i;

        ATA_writeSector( ( Uint32 )tx, j, 1 );
    }

    /* ---------------------------------------------------------------- *
     *  Verify Sectors                                                  *
     * ---------------------------------------------------------------- */
    for ( j = start ; j <= end ; j++ )
    {
        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = 0;

        ATA_readSector( j, ( Uint32 )rx, 1 );

        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            if ( *buf32++ != ( j << ATA_SECTOR_SIZE_POW2 ) + i )
                return ( Int16 )( ( j << ATA_SECTOR_SIZE_POW2 ) + i ) | 1;
    }
    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  pio_invaddr( start, count )                                             *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 pio_invaddr( Uint32 start, Uint32 count )
{
    Int32 i, j;
    Uint32* buf32;
    Uint32 end = start + count - 1;

    printf( "    PIO InvAddr test [%d-%d] sector\n", start, end );

    /* ---------------------------------------------------------------- *
     *  Write Sectors                                                   *
     * ---------------------------------------------------------------- */
    for ( j = start ; j <= end ; j++ )
    {
        buf32 = ( Uint32* )tx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = ~( j << ATA_SECTOR_SIZE_POW2 ) + i;

        ATA_writeSector( ( Uint32 )tx, j, 1 );
    }

    /* ---------------------------------------------------------------- *
     *  Verify Sectors                                                  *
     * ---------------------------------------------------------------- */
    for ( j = start ; j <= end ; j++ )
    {
        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            *buf32++ = 0;

        ATA_readSector( j, ( Uint32 )rx, 1 );

        buf32 = ( Uint32* )rx;
        for ( i = 0 ; i < ATA_SECTOR_SIZE ; i += 4 )
            if ( *buf32++ != ~( j << ATA_SECTOR_SIZE_POW2 ) + i )
                return ( Int16 )( ( j << ATA_SECTOR_SIZE_POW2 ) + i ) | 1;
    }
    return 0;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  ata_test( )                                                             *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 ata_test( )
{
    Int16 retcode = 0;

   // retcode |= ATA_init( );
	retcode |= ATA_init( );
    retcode |= ATA_identify( id );
    if ( retcode != 0 )
        return 1;

    /* ---------------------------------------------------------------- *
     *  Ultra DMA test                                                  *
     * ---------------------------------------------------------------- */
    retcode |= ATA_changeMode( ULTRA_DMA_MODE_5 );
    retcode |= dma_addr( 1, 3 );
    retcode |= dma_invaddr( 1, 3 );
    if ( retcode != 0 )
        return 2;

    /* ---------------------------------------------------------------- *
     *  Multiword DMA test                                              *
     * ---------------------------------------------------------------- */
    retcode |= ATA_changeMode( MULTIWORD_DMA_MODE_0 );
    retcode |= dma_addr( 1, 3 );
    retcode |= dma_invaddr( 1, 3 );
    if ( retcode != 0 )
        return 3;

    /* ---------------------------------------------------------------- *
     *  PIO test                                                        *
     * ---------------------------------------------------------------- */
    retcode |= ATA_changeMode( PIO_MODE_0 );
    retcode |= pio_addr( 1, 3 );
    retcode |= pio_invaddr( 1, 3 );
    if ( retcode != 0 )
        return 4;

    return 0;
}

⌨️ 快捷键说明

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