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

📄 testutil.~cp

📁 一个amccs5933芯片的驱动程序开发源程序和部分文档
💻 ~CP
📖 第 1 页 / 共 5 页
字号:
	// Write all ones to the LP byte.  Only the P bit should set.		
	regp->dmactl_v.dmactl_bytes[1] = 0xFF;

	if ((tempc = regp->dmactl_v.dmactl_bytes[1]) != 1)
	{
		errorCnt++;
		printf ("  dmactl LP bits - P bit should be set. Read %02x. Should be 01. Errs=%d\n",
				    tempc,                   errorCnt);
	}

	// Write all zeros to the LP byte.  We should be able to reset the P bit.		
	regp->dmactl_v.dmactl_bytes[1] = 0;

	if ((tempc = regp->dmactl_v.dmactl_bytes[1]) != 0)
	{
		errorCnt++;
		printf ("  dmactl LP bits - P bit should be reset. Read %02x. Should be 00. Errs=%d\n",
					tempc,                   errorCnt);
	}

	regp->dmalbase = SMstart;
	regp->dmasize = DMAlength - 4; // must be reduced by one DWORD
	regp->dmahbase = hostPhys;

	// Check to make sure that the DMA complete bit is not already set 
	//  (not normally required, but part of a resonable test).
	if (regp->hint & DMA_COMPLETE_BIT)
	{	errorCnt++;
		printf ("Error: DMA_COMPLETE_BIT should not be set. Errs=%d\n", errorCnt);
	}

	// Show the time in mSec for the DMA
	LARGE_INTEGER llnHPTimerFreq;	// High Performance Timer: Frequency
	LARGE_INTEGER llnHPT1;			// High Performance Timer: Time 1
	LARGE_INTEGER llnHPT2;			// High Performance Timer: Time 2
	LARGE_INTEGER llnT_uSec;		// Time in microseconds
	QueryPerformanceFrequency(&llnHPTimerFreq);
	QueryPerformanceCounter(&llnHPT1);

	// Write low-order byte of DMACTL to KICK OFF the DMA. 
	regp->dmactl_v.dmactl_bytes[0] = (volatile unsigned char)DMAdir;

	// Wait for the DMA complete bit to be set.
	DWORD timeout = DMAlength * DMAlength;  // Give mucho time to complete.
	while ( ((regp->hint & DMA_COMPLETE_BIT) != DMA_COMPLETE_BIT) && timeout )
		timeout--;							// busy loop while doing DMA

	if (timeout == 0)
	{
		errorCnt++;
		printf ("Error: timed out before DMA_COMPLETE_BIT set (DMA completed). Errs=%d\n", errorCnt);
	}
	else
	{
		if(QueryPerformanceCounter(&llnHPT2))
		{
			llnT_uSec.QuadPart = ( (llnHPT2.QuadPart - llnHPT1.QuadPart) * // Time Delta
				                    ((LONGLONG)1E9/llnHPTimerFreq.QuadPart) ) / 
								   (LONGLONG)1E3; // could divide by 1E9 for Time in Sec
			//printf("DMA_COMPLETE_BIT set (DMA completed) in %3d Sec: %03d mSec: %03d  uSec\n", 
			//	llnT_uSec.LowPart/(LONG)1E6, (llnT_uSec.LowPart/(LONG)1E3)%(1000), (llnT_uSec.LowPart)%(1000));
//			printf("DMA completed in %3d Sec: %03d mSec: %03d  uSec: DMA Rate = %d Mb/Sec\n", 
//				llnT_uSec.LowPart/(LONG)1E6, (llnT_uSec.LowPart/(LONG)1E3)%(1000), 
//				(llnT_uSec.LowPart)%(1000), (1000000/llnT_uSec.LowPart)/(1048576/DMAlength));
		}
	}

	return (errorCnt);

}  // end doDMA()

// testDMAtoTarg
// Test DMA functionality by performing a DMA operation from the Host to the 3042.
// Initialize source buffer.
// Write a pattern to destination (Shared Mem) so the HOST has to actually change it.
// Perform DMA operation using doDMA
// Check the destination buffer.
// Deallocate buffer in host memory.

#if 0 // original version
//
DWORD testDMAtoTarg(DWORD comemID)
{
	DWORD errorCnt = 0;
	DWORD linPage;
	DWORD physPage;
	
	printf ("Testing DMA to Target...\n");

	// Use comemAllocContigMemL to get a 32K contiguous buffer in host memory.
    DWORD returnCode = comemAllocContigMemL(4, &linPage, &physPage, comemID);
    if (returnCode != NO_ERROR)
	{
		printf("Error Allocating Contiguous Memory\n");
        return(++errorCnt);
	}
	
	DWORD* hostPhys  = (DWORD*)physPage;
	DWORD* hostLin = (DWORD*)linPage;
	DWORD SMstart = 0;
	//DWORD DMAsize  = 0x1000;
	DWORD DMAsize  = 0x4000;
	
	// Initialize source buffer
	printf ("Initializing source at: 0x%08x DMAsize: 0x%x pattern=ADDR_PATTERN\n", hostLin, DMAsize);
	for (DWORD i = 0 ; i < DMAsize/4 ; i++)
		hostLin[i] = i;					// initialize the DMA source area

	// Write a pattern to destination (Shared Mem)  so the HOST has to actually change it.
	initSharedMem (SMstart, DMAsize, FILL_PATTERN, comemID);

	// Perform DMA operation using doDMA
	errorCnt += doDMA ( (DWORD)hostPhys,// hostphys (host-side physical address)
						SMstart,		// shared mem start (first byte of shared mem = address 0)
						DMAsize,		// size of DMA
						0,				// directionTo3042 = 0
						comemID);

	// Check the destination buffer
	errorCnt = checkSharedMem (SMstart, DMAsize, ADDR_PATTERN, comemID);

	// Deallocate buffer in host memory.
	comemDeAllocContigMemL(&linPage, &physPage, comemID);

	return(errorCnt);
}
#endif
// My version -- mem block to PCI-DP shared memory. testing only...
DWORD testDMAtoTarg(DWORD comemID)
{
	DWORD errorCnt = 0;
	DWORD linPage;
	DWORD physPage;
	
	printf ("Siri's version: Testing DMA to Target...\n");

	// Use comemAllocContigMemL to get a 32K contiguous buffer in host memory.
    DWORD returnCode = comemAllocContigMemL(4, &linPage, &physPage, comemID);
    if (returnCode != NO_ERROR)
	{
		printf("Error Allocating Contiguous Memory\n");
        return(++errorCnt);
	}
	
	DWORD* hostPhys  = (DWORD*)physPage;
	DWORD* hostLin = (DWORD*)linPage;
	WORD* memPtr = (WORD*)linPage;
	DWORD SMstart = 0;
	DWORD DMAsize  = BLOCK_SIZE * 2; //size is in bytes: 512 word block * 2 bytes/word = 1024
		
	// Initialize source buffer
	printf ("Initializing source at: 0x%08x DMAsize: 0x%x pattern=ADDR_PATTERN\n", hostLin, DMAsize);
	for (DWORD i = 0; i < DMAsize/4;++i)
	{
		memPtr[i] = (WORD) i;	// initialize the host mem area with the data
	}

	// Write a dummy pattern to PCI-DP so the HOST has to actually change it.
	// NOTE: FILL_PATTERN is 0xAA55AA55
	initSharedMem (SMstart, DMAsize, FILL_PATTERN, comemID);

	// Perform DMA operation using doDMA
	errorCnt += doDMA ( (DWORD)hostPhys,// hostphys (host-side physical address)
						SMstart,		// shared mem start (first byte of shared mem = address 0)
						DMAsize,		// size of DMA
						0,				// 0 == DMA from host to PCI-DP shared mem
						comemID);

	// Check the destination buffer
//	errorCnt = checkSharedMem (SMstart, DMAsize, ADDR_PATTERN, comemID);

	// Deallocate buffer in host memory.
	comemDeAllocContigMemL(&linPage, &physPage, comemID);

	return(errorCnt);
}

// testDMAtoHost
// Test DMA functionality by performing a DMA operation from the 3042 to the Host.
// Use comemAllocContigMemL to get a 32K contiguous buffer in host memory.
// Initialize source buffer (Shared Mem).
// Write a pattern to destination buffer so the HOST has to actually change it.
// Perform DMA operation using doDMA
// Check the destination buffer.
// Deallocate buffer in host memory.
//
// Test version
#if  1
DWORD testDMAtoHost(DWORD comemID)
{
	DWORD linPage;
	DWORD physPage;
	int errorCnt = 0;
	DWORD i;

	printf ("Testing DMA to Host...\n");

	// Use comemAllocContigMemL to get a 32K contiguous buffer in host memory.
    DWORD returnCode = comemAllocContigMemL(4, &linPage, &physPage, comemID);
    if (returnCode != NO_ERROR)
    {
        printf("Error creating BAR pointers.");
		return (returnCode);
    }

	DWORD* hostPhys  = (DWORD*)physPage;
	DWORD* hostLin = (DWORD*)linPage;
	WORD* memPtr = (WORD*)linPage;
	DWORD SMstart = 0;
	DWORD DMAsize  = BLOCK_SIZE * 2; //size is in bytes: 512 word block * 2 bytes/word = 1024

	// Initialize source buffer (Shared Mem)
//	initSharedMem(SMstart, DMAsize, ADDR_PATTERN, comemID);
				
	// Write a pattern to destination buffer so the HOST has to actually change it.
	printf ("Initializing destination buffer at: 0x%08x pattern=0xFEEDBEEF\n", hostLin);
	for (i = 0 ; i < DMAsize/4 ; i++)
		hostLin[i] = 0xFEEDBEEF;		// initialize the DMA destination area

//	for (WORD k = 0 ; k < DMAsize/2 ; k++)
//	{
//		printf ("%03i.\tHost add:%08x\tHost value:%04x\n", k, memPtr + k, memPtr[k]);
//	}
    // Perform DMA operation using doDMA
	errorCnt += doDMA ( (DWORD)hostPhys,// hostphys (host-side physical address)
						SMstart,		// shared mem start (first byte of shared mem = address 0)
						DMAsize,		// size of DMA
						1,				// 1 == DMA from PCI-DP to host memory
						comemID);

	// Check the destination buffer
	for (WORD j = 0 ; j < DMAsize/2 ; j++)
	{
		printf ("%03i.\tHost add:%08x\tHost value:%04x\n", j, memPtr + j, memPtr[j]);
		if (memPtr[j] != j)
		{
			if(errorCnt++ < 8) // only report first 8 errors
			{
				printf ("Error: PCIAddr=%08x LocalAddr=%08x Wrote=%04x Read=%04x\n", 
					memPtr+j, j, j, memPtr[j]);
			}
		}
	}

	// Deallocate buffer in host memory.
	comemDeAllocContigMemL(&linPage, &physPage, comemID);

	return(errorCnt);
}
#endif

/*
DWORD testDMAtoHost(DWORD comemID)
{
	DWORD linPage;
	DWORD physPage;
	int errorCnt = 0;
	DWORD i;

	printf ("Testing DMA to Host...\n");

	// Use comemAllocContigMemL to get a 32K contiguous buffer in host memory.
    DWORD returnCode = comemAllocContigMemL(4, &linPage, &physPage, comemID);
    if (returnCode != NO_ERROR)
    {
        printf("Error creating BAR pointers.");
		return (returnCode);
    }

	DWORD* hostPhys  = (DWORD*)physPage;
	DWORD* hostLin = (DWORD*)linPage;
	DWORD SMstart = 0;
	//DWORD DMAsize  = 0x1000;
	DWORD DMAsize  = 0x4000;

	// Initialize source buffer (Shared Mem)
	initSharedMem(SMstart, DMAsize, ADDR_PATTERN, comemID);
				
	// Write a pattern to destination buffer so the HOST has to actually change it.
	printf ("Initializing destination buffer at: 0x%08x pattern=0xFEEDBEEF\n", hostLin);
	for (i = 0 ; i < DMAsize/4 ; i++)
		hostLin[i] = 0xFEEDBEEF;		// initialize the DMA destination area

    // Perform DMA operation using doDMA
	errorCnt += doDMA ( (DWORD)hostPhys,// hostphys (host-side physical address)
						SMstart,		// shared mem start (first byte of shared mem = address 0)
						DMAsize,		// size of DMA
						1,				// directionToHost = 1
						comemID);

	// Check the destination buffer
	for (i = 0 ; i < DMAsize/4 ; i++)
	{
		if (hostLin[i] != i)
		{
			if(errorCnt++ < 8) // only report first 8 errors
			{
				printf ("Error: PCIAddr=%08x LocalAddr=%08x Wrote=%08x Read=%08x\n", 
					hostLin+i, i, i, hostLin[i]);
			}
		}
	}

	// Deallocate buffer in host memory.
	comemDeAllocContigMemL(&linPage, &physPage, comemID);

	return(errorCnt);
}

*/
// Set up the operation register masks.  The masks are need on the bits that comem lite can
// change internally. A one designates a masked bit.                          1098 7654 3210 9876 5432 1098 7654 3210
//    op_register_mask_memory [ `I2C_COMMAND_REG >> 2 ]                       = 32'b1111_1111_1111_1111_1111_1111_1111_1111;
//    op_register_mask_memory [ `I2C_READ_DATA_REG >> 2 ]                     = 32'b1111_1111_1111_1111_1111_1111_1111_1111;
//    op_register_mask_memory [ `I2C_STATUS_REG >> 2 ]                        = 32'b0000_0000_0000_0000_0000_0000_1110_0001;
//    op_register_mask_memory [ `DMA_CONTROL_REG >> 2 ]                       = 32'b0000_0000_0000_0000_0000_0011_0000_0000;
//    op_register_mask_memory [ `HOST_INTERRUPT_CONTROL_STATUS_REG >> 2 ]     = 32'b0000_0000_1100_0000_0000_0011_1111_1011;
//    op_register_mask_memory [ `LOCAL_INTERRUPT_CONTROL_STATUS_REG >> 2 ]    = 32'b0000_0000_1100_0000_0000_0011_1110_1011;
//
// testOpRegsBits: Basically, do walking 1's test (rotate 1 through all bits).
// After writing bits that are writable, check to make sure everything else is OK.
//
//
DWORD testOpRegsBits(DWORD comemID)
{
	printf ("Testing Op Regs Bits...\n");
	return(0);
}

//  testReset: Reset target and check values to confirm proper reset.
DWORD testReset(DWORD comemID)
{
	DWORD dwBarBase;
//	DWORD volatile * dwpBarBase;
	DWORD linBAR[COMEM_MAX_BARS];
	DWORD returnCode = comemCopyBarPtrL(linBAR, comemID);
	if (returnCode != NO_ERROR)
	{
		printf("Error creating BAR pointers.");
		return(1);
	}
	dwBarBase = linBAR[0]; // Get a pointer to the Shared Memory area (BAR 0)
//	dwpBarBase = (DWORD volatile *) linBAR[0]; // Get a pointer to the Shared Memory area (BAR 0)
//	dwpBarBase = linBAR[0]; // Get a pointer to the Shared Memory area (BAR 0)

//  0. Set Local Bus Reset State
//    a. For PCI tests, hold Local processor in reset: write 0x00000001 to 0x04E0
//  1. Reset FIFO flags
//    a. PCI can do a Soft Reset
	*(DWORD*)(dwBarBase+ADDR_HCTL) = 0x00000003; // Soft Reset
	*(DWORD*)(dwBarBase+ADDR_HCTL) = 0x00000001; // Local processor in reset
//	dwpBarBase[ADDR_HCTL] = 0x00000001;
//  2. Set I2O Mask Registers for both I2OHIMR AND I2OLISR
//    a. write 0xFFFFFFFF to 0x0034
//    b. write 0xFFFFFFFF to 0x003C
//	*(DWORD*)(dwBarBase+0x0034) = 0xFFFFFFFF;  __BBX Soft Reset initializes mask
//	*(DWORD*)(dwBarBase+0x003C) = 0xFFFFFFFF;  __BBX Soft Reset initializes mask
//  2.5 Check DMA Control Arbitration bits, (PI and W not cleared by Soft Reset)
//  3. Clear Interrupt Registers for both HINT and LINT
//    a. write 0x0000FFFF to 0x04E4
//    b. write 0x0000FFFF to 0x04F4
//	dwpBarBase[ADDR_HINT] = 0x0000FFFF;
//	dwpBarBase[ADDR_LINT] = 0x0000FFFF;
	*(DWORD volatile *)(dwBarBase+ADDR_HINT) = 0x0000FFFF;
	*(DWORD volatile *)(dwBarBase+ADDR_LINT) = 0x0000FFFF;
//  4. Confirm reset and constant conditions
//    a. Execute an approximate 1 second pause after the prior writes
//    b. Read and Confirm the following DWORD values:
//         DMACTL   0x04BC  0x0000000X  __BBX Add check for DMA Arb bits[9,8]
//         ARBUTIL  0x04C0  0x00000000  __BBX Update for Rev B
//         HCTL     0x04E0  0x00000001  (for PCI side testing)
//         HINT     0x04E4  0x00000000
//         LINT     0x04F4  0x00000000
//         LBUSCFG  0x04FC  0x00010B50  __BBX Only reset with RST#, not soft reset
//         I2OHISR  0x0030  0x00000000
//         I2OHIMR  0x0034  0xFFFFFFFF
//         I2OLISR  0x0038  0x00000000
//         I2OLIMR  0x003C  0xFFFFFFFF
//         I2OIBF   0x0040  0xFFFFFFFF  (in a read context only)
//         I2OOBP   0x0044  0xFFFFFFFF  (in a read context only)
//         I2OIBP   0x0048  0xFFFFFFFF  (in a read context only)
//         I2OOBF   0x004C  0xFFFFFFFF  (in a read context only)
	//TPMxSleepEx(5000, 0);
	SleepEx(250, 0);

	DWORD dwReadMem;

//  __BBX Add check for DMA Arb bits L and P, bits 9 and 8
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_DMACTL);
	dwReadMem = dwReadMem & 0xFFF

⌨️ 快捷键说明

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