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

📄 testutil.cpp

📁 The Lite Evaluation/Demonstration Kit is intended to illustrate use of the AN3042. The AN3042 is c
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	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);
}

// 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.
//
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 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)

//  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
//  2. Set I2O Mask Registers for both I2OHIMR AND I2OLISR
//    a. write 0xFFFFFFFF to 0x0034
//    b. write 0xFFFFFFFF to 0x003C
	*(DWORD*)(dwBarBase+0x0034) = 0xFFFFFFFF;
	*(DWORD*)(dwBarBase+0x003C) = 0xFFFFFFFF;
//  3. Clear Interrupt Registers for both HINT and LINT
//    a. write 0x0000FFFF to 0x04E4
//    b. write 0x0000FFFF to 0x04F4
	*(DWORD*)(dwBarBase+ADDR_HINT) = 0x0000FFFF;
	*(DWORD*)(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:
//         HCTL     0x04E0  0x00000001  (for PCI side testing)
//         HINT     0x04E4  0x00000000
//         LINT     0x04F4  0x00000000
//         LBUSCFG  0x04FC  0x00000B50
//         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;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HCTL);
//	printf("HCTL=%08x\n", dwReadMem);
	if(dwReadMem != 0x00000001)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
//	printf("HINT=%08x\n", dwReadMem);
	if(dwReadMem != 0x00000000)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_LINT);
//	printf("LINT=%08x\n", dwReadMem);
	if(dwReadMem != 0x00000000)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_LBUSCFG);
//	printf("LBUSCFG=%08x\n", dwReadMem);
	//if(dwReadMem != 0x00000B50) // This code depends on which bus config selected
	//	returnCode++;

	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OHISR);
//	printf("I2OHISR=%08x\n", dwReadMem);
	if(dwReadMem != 0x00000000)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OHIMR);
//	printf("I2OHIMR=%08x\n", dwReadMem);
	if(dwReadMem != 0xFFFFFFFF)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OLISR);
//	printf("I2OLISR=%08x\n", dwReadMem);
	if(dwReadMem != 0x00000000)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OLIMR);
//	printf("I2OLIMR=%08x\n", dwReadMem);
	if(dwReadMem != 0xFFFFFFFF)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OIBF);
//	printf("I2OIBF=%08x\n", dwReadMem);
	if(dwReadMem != 0xFFFFFFFF)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OOBP);
//	printf("I2OOBP=%08x\n", dwReadMem);
	if(dwReadMem != 0xFFFFFFFF)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OIBP);
//	printf("I2OIBP=%08x\n", dwReadMem);
	if(dwReadMem != 0xFFFFFFFF)
		returnCode++;
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OOBF);
//	printf("I2OOBF=%08x\n", dwReadMem);
	if(dwReadMem != 0xFFFFFFFF)
		returnCode++;

	return(returnCode);
}

//  testRun: Start target code running by releasing reset.
DWORD testRun(DWORD comemID)
{
	DWORD dwBarBase;
	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)

//  0. Set Local Bus Reset State
//    a. For PCI tests, hold Local processor in reset: write 0x00000001 to 0x04E0
//    b. Run by writing a 0 to 0x04E0
	*(DWORD*)(dwBarBase+ADDR_HCTL) = 0x00000003; // Soft Reset
	*(DWORD*)(dwBarBase+ADDR_HCTL) = 0x00000000; // Local processor in run
	//theApp.Out("Running...\n");
	return(0);
}

// testIntFifo: Test interrupt functionality (FIFO Full) using FIFOs
DWORD testIntFifo(DWORD comemID, int FifoSel)
{
	DWORD dwFillPattern = 0x5A5A5A5A;
	int i;
	volatile DWORD dwTestFlagBase;
	volatile DWORD dwBarBase;
	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)
	volatile DWORD dwReadMem;
	DWORD dwExpVal;
	volatile DWORD* pdwFifoPut;
	DWORD* pdwFifoGet;
	DWORD dwIMask; // interrupt mask
	DWORD dwIStat; // interrupt status

	if(FifoSel == ADDR_I2OIBF)
	{
		printf("Test 0x000.  I2O AI FIFO Overflow (IBF FIFO) -- HINT[00] and LINT[00]\n");
		dwTestFlagBase = dwBarBase + (SM_OFFSET*4) + 0x000;
		pdwFifoPut = (DWORD*)(dwBarBase+ADDR_I2OOBP);
		pdwFifoGet = (DWORD*)(dwBarBase+ADDR_I2OIBP);
		//dwIMask = 0x00010000; // need INTA# handler to service interrupt!
		dwIMask = 0x00000000; //NOTE: SHOULD use dwIMask = 0x00010000; 
		dwIStat = 0x00000001;
		//dwIStat = 0x00000000; //NOTE: stat after int is now 0; status cleared by int
	}
	else if(FifoSel == ADDR_I2OOBF)
	{
		printf("Test 0x100.  I2O PCI FIFO Overflow (OBF FIFO) -- HINT[01] and LINT[01]\n");
		dwTestFlagBase = dwBarBase + (SM_OFFSET*4) + 0x100;

		pdwFifoPut = (DWORD*)(dwBarBase+ADDR_I2OIBF);
		pdwFifoGet = (DWORD*)(dwBarBase+ADDR_I2OOBF);
		//dwIMask = 0x00020000; // need INTA# handler to service interrupt!
		dwIMask = 0x00000000; //NOTE: SHOULD use dwIMask = 0x00020000;
		dwIStat = 0x00000002;
		//dwIStat = 0x00000000; //NOTE: stat after int is now 0; status cleared by int
	}
	else
		return(1);


//    0. Run RESET FLOW
	testReset(comemID);
//    1. Write 32 DWORD to I2OxBF, 0x0044 (or I2OOBP, 0x0048)
	for(i=0; i<32; i++)
		*pdwFifoPut = dwFillPattern;
//    2. Read and Confirm HINT and LINT = 0x00000000
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
	if(dwReadMem != 0x00000000)
		printf("ERROR %2d: HINT=%08x\n", ++returnCode, dwReadMem);
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_LINT);
	if(dwReadMem != 0x00000000)
		printf("ERROR %2d: LINT=%08x\n", ++returnCode, dwReadMem);
// *  3. Write 1 DWORD to I2OxBF, 0x0044 (or I2OOBP, 0x0048)
	*(DWORD*)(dwTestFlagBase+(0x3*4)) = dwExpVal = dwIStat; //FLAG (for logic analyzer)
	*pdwFifoPut = dwFillPattern;
	//SleepEx(1000, 0); // NOTE: This delay for test purposes, not normally necessary
//    4. Read and Confirm HINT and LINT = dwExpVal
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
	if(dwReadMem != dwExpVal)
		if((dwReadMem|dwIStat) != dwExpVal) //TPM cannot depend on stat bit being cleared immediately
		printf("ERROR %2d: HINT=%08x dwExpVal=%08x\n", ++returnCode, dwReadMem, dwExpVal);
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_LINT);
	if(dwReadMem != dwExpVal)
		if((dwReadMem|dwIStat) != dwExpVal) //TPM cannot depend on stat bit being cleared immediately
		printf("ERROR %2d: LINT=%08x dwExpVal=%08x\n", ++returnCode, dwReadMem, dwExpVal);
//    5. Observe that INTA# is inactive, (IRQ_OUT# for Local test)
// *  6. Write 0x00010000 to HINT, (LINT for Local test)
	*(DWORD*)(dwTestFlagBase+(0x6*4)) = dwExpVal = (dwIMask | dwIStat); //FLAG
	//*(DWORD*)(dwTestFlagBase+0x6) = dwExpVal = 0x00010000; //FLAG
	//NOTE: Writing 0x00010000 when HINT=0x00000001 caused crash with no interrupt handler
	//NOTE: The status bit is now cleared by the interrupt handler (in comeml.vxd)
	*(DWORD*)(dwBarBase+ADDR_HINT) = dwIMask;
//    7. Read and Confirm HINT = 0x00010002, (LINT for Local test)
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
	if(dwReadMem != dwExpVal)
		if((dwReadMem|dwIStat) != dwExpVal) //TPM cannot depend on stat bit being cleared immediately
		printf("ERROR %2d: HINT=%08x dwExpVal=%08x\n", ++returnCode, dwReadMem, dwExpVal);
//    8. Observe that INTA# goes active, (IRQ_OUT# for Local test)
// *  9. Write 0x00010002 to HINT, (LINT for Local test)
	*(DWORD*)(dwTestFlagBase+(0x9*4)) = dwExpVal = dwIMask; //FLAG
	*(DWORD*)(dwBarBase+ADDR_HINT) = (dwIMask | dwIStat); //clear int stat
//   10. Read and Confirm HINT = 0x00010000, (LINT for Local test)
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
	if(dwReadMem != dwExpVal)
		if((dwReadMem|dwIStat) != dwExpVal) //TPM cannot depend on stat bit being cleared immediately
		printf("ERROR %2d: HINT=%08x dwExpVal=%08x\n", ++returnCode, dwReadMem, dwExpVal);
//   11. Observe that INTA# goes inactive, (IRQ_OUT# for Local test)
// *  C. Write 1 DWORD to I2OIBF, 0x0044 (or I2OOBP, 0x0048)
	*(DWORD*)(dwTestFlagBase+(0xC*4)) = dwExpVal = (dwIMask | dwIStat); //FLAG
	//*(DWORD*)(dwTestFlagBase+0xC) = dwExpVal = 0x00010001; //FLAG
	//*(DWORD*)(dwBarBase+ADDR_I2OIBF) = 0xFFFFFFFF;
	*pdwFifoPut = dwFillPattern;
//   12. Read and Confirm HINT = 0x00010002, (LINT for Local test)
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
	if(dwReadMem != dwExpVal)
		if((dwReadMem|dwIStat) != dwExpVal) //TPM cannot depend on stat bit being cleared immediately
		printf("ERROR %2d: HINT=%08x dwExpVal=%08x\n", ++returnCode, dwReadMem, dwExpVal);
//   13. Observe that INTA# goes active, (IRQ_OUT# for Local test)
//   14. Read 4 DWORD from ADDR_I2OOBF, 0x004c (or I2OIBP, 0x0040)
	for(i=0; i<32; i++)
	{ // pop all values out of fifo and confirm contents
		dwReadMem = *pdwFifoGet;
		dwExpVal = dwFillPattern;
		if(dwReadMem != dwExpVal)
			printf("ERROR %2d: FifoRead=%08x dwExpVal=%08x\n", ++returnCode, dwReadMem, dwExpVal);
	}
		//dwReadMem = *(DWORD*)(dwBarBase+ADDR_I2OOBF);
//   15. Observe that INTA# is active, (IRQ_OUT# for Local test)
// * 16. Read and Confirm HINT = 0x00010002, (LINT for Local test)
	*(DWORD*)(dwTestFlagBase+(0x11*4)) = dwExpVal = (dwIMask | dwIStat); //FLAG
	dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
	if(dwReadMem != dwExpVal)
		if((dwReadMem|dwIStat) != dwExpVal) //TPM cannot depend on stat bit being cleared immediately
		printf("ERROR %2d: HINT=%08x dwExpVal=%08x\n", ++returnCode, dwReadMem, dwExpVal);

	//dwReadMem = *(DWORD*)(dwBarBase+ADDR_HINT);
	//printf("HINT=%08x\n", dwReadMem);
	*(DWORD*)(dwBarBase+ADDR_HINT) = dwIStat; //clear int stat and mask (TPM)
	//dwReadMem = *(DWORD

⌨️ 快捷键说明

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