dmaRead.c 2.7 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <bstring.h>

#include <diag.h>
#include <dbg_comm.h>

extern dbg_comm_struct dbg_comm;

int commtype = DG_TINYMON_DMEM;

/*
 * dmaRead tests the ability of dgDmaReadMem() to setup a DMA operation from
 * rdram to ramrom.
 */

void main(int argc, char **argv) {
    unsigned int ramromAddr, rdramAddr, len;
    unsigned int ramromData, rdramData;
    int i, j;
    int ret_len;
    char *buf;

    if (argc == 4) {
	ramromAddr = (int)strtoul (argv[1], (char **)NULL, 0);
	rdramAddr = (int)strtoul (argv[2], (char **)NULL, 0);
	len = (int)strtol (argv[3], (char **)NULL, 0);
    } else {
	printf("Usage: dmaRead ramromAddr rdramAddr len, where len is a multiple of 4\n");
	exit (1);
    }
    if (len %4) {
	printf("Usage: dmaRead ramromAddr rdramAddr len, where len is a multiple of 4\n");
	exit (1);
    }
    
    printf("dma read of %d bytes from rdramAddr 0x%x to ramromAddr 0x%x\n", 
	len, rdramAddr, ramromAddr);

    if ( dgInitComm() ) {
	fprintf(stderr,
	  "%s: unable to initialize communication with target system.\n",
	  argv[0]);
	exit(1);
    }

    /*
     * Initialize ramrom and rdram to known values.
     */
    for (i = 0; i < len; i+=4) {
	dgWriteWord( ramromAddr + i, ~i );
	dgReadWord( ramromAddr + i, &ramromData);
	if (ramromData != ~i) {
	    fprintf(stderr, "ERROR: (init readback): ramrom(0x%x): exp 0x%x, read 0x%x\n",
		ramromAddr + i, ~i, ramromData);
	} else {
	    fprintf(stderr, "INFO: (init readback): ramrom(0x%x): read 0x%x\n",
		ramromAddr + i, ~i, ramromData);
	}

	dgWriteWord( rdramAddr + i, i );
	dgReadWord( rdramAddr + i, &rdramData);
	if (rdramData != i) {
	    fprintf(stderr, "ERROR: (init readback): rdram(0x%x): exp 0x%x, read 0x%x\n",
		rdramAddr + i, i, rdramData);
	} else {
	    fprintf(stderr, "INFO: (init readback): rdram(0x%x): read 0x%x\n",
		rdramAddr + i, rdramData);
	}
    }

    buf = malloc(len);
    if ( dgDmaReadMem(ramromAddr, rdramAddr, len) ) {
	fprintf(stderr,
	  "%s: unable to setup requested dma operation on target system.\n",
	  argv[0]);
	exit(1);
    }
    for (i = 0; i < len; i+=4) {
	dgReadWord( ramromAddr + i, &ramromData);
	dgReadWord( rdramAddr + i, &rdramData);
	if (rdramData != ramromData) {
	    fprintf(stderr, 
    "ERROR: (dma readback): ramrom(0x%x) = 0x%x != rdram(0x%x) = 0x%x\n",
		ramromAddr + i, ramromData, 
		rdramAddr + i, rdramData);
	} else {
	    fprintf(stderr, 
    "INFO: (dma readback): ramrom(0x%x) = 0x%x == rdram(0x%x) = 0x%x\n",
		ramromAddr + i, ramromData, 
		rdramAddr + i, rdramData);
	}
    }
    exit(0);
}

/*
 * stubs to satisify libide.a references required by libdg.a
 */

void
errlog() {
}

char *ideTestName;