dmaWrite.c 2.72 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;

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

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: dmaWrite ramromAddr rdramAddr len, where len is a multiple of 4\n");
	exit (1);
    }
    if (len %4) {
	printf("Usage: dmaWrite ramromAddr rdramAddr len, where len is a multiple of 4\n");
	exit (1);
    }
    
    printf("ramromAddr 0x%x rdramAddr 0x%x len %d\n", 
	ramromAddr, rdramAddr, len);

    printf("dma write of %d bytes from ramromAddr 0x%x to rdramAddr 0x%x\n", 
	len, ramromAddr, rdramAddr);

    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 ( dgDmaWriteMem(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);
}

void
errlog() {
}

char *ideTestName;