📄 mem_copy.c
字号:
{ RETURN_PRINT_ERROR(rc); } BaseBoardType = WildstarConfiguration.BaseInfo.BaseBoardType; /*************************************************************** ** ** ** Set the MClock Frequency ** ** ** ***************************************************************/ rc = WS_MClkSetConfig ( WS_SlotNumber, PROG_OSCILLATOR, clk_freq, 1 ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } printf ( "Successfully Set MCLK to [%2.1f] MHz\n", clk_freq ); /*************************************************************** ** ** ** Set the UClock Frequency ** ** ** ***************************************************************/ rc = WS_UClkSetConfig ( WS_SlotNumber, PROG_OSCILLATOR, uclk_freq ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } printf ( "Successfully set UCLK to [%2.1f] MHz\n", uclk_freq ); /*************************************************************** ** ** ** Program PE1 ** ** ** ***************************************************************/ PartType = XilinxPartType[WildstarConfiguration.BaseInfo.PE_Device[1].dPartType]; PackageType = XilinxPackageType[WildstarConfiguration.BaseInfo.PE_Device[1].dPackageType]; sprintf (FileName , "%s%s%s%spex.x86",PartType, SLASH, PackageType, SLASH ); rc = ProgramPE(WS_SlotNumber, WS_PE1, FileName ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } printf ( "Successfully programmed PE1\n\n" ); /*************************************************************** ** ** ** Start the ARM Test example now that the PEs are all ** ** programmed. ** ** ** ***************************************************************/ printf ( "@@@@ Beginning ARM Test @@@@\n\n" ); printf ( "**** Resetting the PE's ****\n\n" ); rc = WS_WritePeReg( WS_SlotNumber, WS_PE1, PEx_RESET_REG, 1, &Reset ); /*************************************************************** ** ** ** Set the Display ** ** ** ***************************************************************/ /* Currently Can't Update Display Due to Error on Starfire */
//rc = WS_UpdateDisplay ( WS_SlotNumber, "ARM9" ); //if ( rc != WS_SUCCESS ) //{ // RETURN_PRINT_ERROR(rc); //} /***************Connect Host to Memory System*******************/ host_ARM = 0x00000001; rc = WS_WritePeReg( WS_SlotNumber, WS_PE1, PEx_CONTROL_REG, 1, &host_ARM); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } printf( "Host now connected to Memory System.\n" ); /**************Read in the File*********************************/ printf ( "Enter the filename of the Hex Memory File \t" ); scanf("%s", FileName); getchar(); /**************Check to see that filename is valid**************/ while ((memfile = fopen(FileName, "r")) == NULL) { printf ("%s is an invalid filename, please try again.\t", FileName); scanf("%s", FileName); getchar(); } WriteBufferLocalPex = malloc(sizeof(DWORD)*256); ReadBufferLocalPex = malloc(sizeof(DWORD)*256); while (fscanf(memfile, "%s", line) != EOF) { /* Address or 257th DWORD*/ if ((sscanf(line, "@%x", &address) > 0) || (count == 256)) { if (foundat > 0) { /* Send the Data over to the Starfire Board */ printf("Transferring %d DWORDS starting at address 0x%08x\n", count, temp_addr); rc = WriteData(WS_SlotNumber, PENumber, temp_addr, PEx_MEM, WriteBufferLocalPex, count ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } /* Verify that Data was Written to Memory Properly */ rc = ReadData( WS_SlotNumber, PENumber, temp_addr, PEx_MEM, ReadBufferLocalPex, count ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } rc = VerifyData(WriteBufferLocalPex, ReadBufferLocalPex, count, error); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } /* Increment the Total Number of DWORDS Transferred */ total += count; } /* Increment the Number of Address found and reset the Count */ foundat++; count = 0; /* If this section was enterred because the count exceeded 255 then, then this line does not contain an address. The value should then be placed into the DWORD Buffer and the count incremented. */ if (sscanf(line, "@%x", &address) == 0) { temp_addr = temp_addr + 0x100; if (sscanf(line, "%x", &value) > 0) { WriteBufferLocalPex[count] = value; count++; } } else temp_addr = address; } /* Instruction */ else if (sscanf(line, "%x", &value) > 0) { /* If the first Line wasn't an Address, probably want to send the data to address 0x0. */ if (foundat == 0) { printf("First Line should be an Address!\n"); printf("Assuming address 0x0.\n"); temp_addr = 0x0; count = 0; foundat++; } /* Store the DWORD into a Memory Buffer and Increment Count*/ WriteBufferLocalPex[count] = value; count++; } /* Invalid */ else printf("Found Invalid line at %d.\n",total+count); } /* Send the last segment of data to the FPGA's Memory */ if (count > 0) { printf("Transferring %d DWORDS starting at address 0x%08x\n", count, temp_addr); rc = WriteData(WS_SlotNumber, PENumber, temp_addr, PEx_MEM, WriteBufferLocalPex, count ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } /* Verify that Data was Written to Memory Properly */ rc = ReadData( WS_SlotNumber, PENumber, temp_addr, PEx_MEM, ReadBufferLocalPex, count ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } rc = VerifyData(WriteBufferLocalPex, ReadBufferLocalPex, count, error); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } /* Increment the Total Number of DWORDS Transferred */ total += count; count = 0; } /* The Memory File Has Been Completely Transferred */ printf ("%i DWORDS sent to memory.\n", total); printf ("Memory has now been loaded.\n\n"); fclose (memfile); /* Return Allocated Memory to CPU */ free (WriteBufferLocalPex); free (ReadBufferLocalPex); /********Reset the PE to tell the ARM to start*********/ printf ( "Resetting the PE's \n\n" ); rc = WS_WritePeReg( WS_SlotNumber, WS_PE1, PEx_RESET_REG, 1, &Reset ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } /********Time to WAIT for ARM to run the Program********/ printf ( "Waiting for Done Signal From ARM ."); do { printf ("."); rc = WS_ReadPeReg ( WS_SlotNumber, WS_PE1, PEx_STATUS_REG, 1, &StatusWord ); } while ( (StatusWord & 0x1) != 1 ); /***************Connect Host to Memory System*******************/ host_ARM = 0x00000001; rc = WS_WritePeReg( WS_SlotNumber, WS_PE1, PEx_CONTROL_REG, 1, &host_ARM); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } printf( "\n\nHost now connected to Memory System.\n" ); /********Read back Memory Contents to get Results*******/ printf("\nEnter the Number (dec) of DWORDS to display (0 to quit)...\t"); scanf("%u", &temp_addr); while (temp_addr > 0) { printf("Enter the Address (hex) of data to display...\t"); scanf("%x", &address); ReadBufferLocalPex = malloc(temp_addr*sizeof(DWORD)); rc = ReadData( WS_SlotNumber, PENumber, address, PEx_MEM, ReadBufferLocalPex, temp_addr ); for (reading=0; reading < temp_addr; reading++) { printf("Address = %08x\tValue = %08x\n", address+reading, ReadBufferLocalPex[reading]); } free (ReadBufferLocalPex); printf("\nEnter the Number (dec) of DWORDS to display (0 to quit)...\t"); scanf("%u", &temp_addr); } /*************************************************************** ** ** ** Program PE1 with a safe image ** ** ** ***************************************************************/ PartType = XilinxPartType[WildstarConfiguration.BaseInfo.PE_Device[1].dPartType]; PackageType = XilinxPackageType[WildstarConfiguration.BaseInfo.PE_Device[1].dPackageType]; sprintf (FileName , "%s%s%s%ssafe.x86",PartType, SLASH, PackageType, SLASH ); rc = ProgramPE(WS_SlotNumber, WS_PE1, FileName ); if ( rc != WS_SUCCESS ) { RETURN_PRINT_ERROR(rc); } printf ( "Successfully programmed PE1 with a safe image.\n\n" ); if ( rc == WS_SUCCESS) { printf ( "\t\t** SUCCESSFUL**\n"); } /* Close the WS_SlotNumber */ rc = WS_Close( WS_SlotNumber ); return ( (int) rc); } return ( (int) rc);}/*end main()*//********************** Exported Function ************************************ * Function: VerifyData * * Returns: DWORD - return code * Description: Compares two buffers and returns any errors. The maximum * number of errors returned is MAX_ERR_COUNT. *****************************************************************************/WS_RetCodeVerifyData(DWORD ref[], DWORD test[], DWORD size, char *errstr){#define MAX_ERR_COUNT 16 DWORD memCntr, errCount; WS_RetCode rc = WS_SUCCESS; errCount=0; /* Loop counts off in DWORDS. * Mismatches will stop being counted after MAX_ERR_COUNT errors. * Note: compares ref data with test data */ for ( memCntr=0; (memCntr < size) && (errCount < MAX_ERR_COUNT); memCntr++) { if (ref[memCntr] != test[memCntr]) { rc=ERROR_MEMORY_COMPARE_FAILED; if (errCount==0) { printf("ERROR: %s\n", errstr); printf("\t Failure offset:\tDWORD:\tExpected Data:\tActual Data:\n"); } printf("\t 0x%08lx\t\t%i\t0x%08x\t0x%08x\t", memCntr*sizeof(DWORD), memCntr, ref[memCntr], test[memCntr]); printf("\n"); errCount++; } } if ( (errCount!=0) && (errCount<MAX_ERR_COUNT)) { printf("Number of memory errors found: %d.\n\n", errCount); } else if (errCount!=0) { printf("Memory comparison stopped after %d errors.\n\n", MAX_ERR_COUNT); } return(rc);}/******************************* Function ************************************ * Function: WriteData * * Returns: DWORD - return code * Description: Write data to memory *****************************************************************************/WS_RetCodeWriteData(DWORD WS_SlotNumber, DWORD PeNum, DWORD Address, DWORD Port, DWORD DataToWrite[], DWORD NumDWORDSToWrite ){ DWORD StatusWord, memCntr = 0, dDpmOffset, dMemAddress, dNumDwords, dWriteSel, dControlReg1, dControlReg2, dControlReg3; WS_RetCode rc = WS_SUCCESS; dControlReg3 = 1; /* Set initial values of the control register 2 */ dNumDwords = MAX_DWORDS_PER_TRANSFER; dWriteSel = 0; dControlReg2 = (dWriteSel << SHIFT_WRITE_SEL) | dNumDwords; /* if the number of dwords to write is greater than 256 */ if ( NumDWORDSToWrite > MAX_DWORDS_PER_TRANSFER ) { do { /* Set up control register */ dMemAddress = Address + memCntr; dDpmOffset = 0; dControlReg1 = (dDpmOffset << SHIFT_DPM_OFFSET) | dMemAddress; /* Write data to DPM */ rc = WS_WritePeReg( WS_SlotNumber, PeNum, Port + DPM_OFFSET, MAX_DWORDS_PER_TRANSFER, &DataToWrite[memCntr] ); memCntr = memCntr + MAX_DWORDS_PER_TRANSFER; /* Write to the Control Registers */ rc = WS_WritePeReg( WS_SlotNumber, PeNum, Port + CTRL_1_OFFSET, 1, &dControlReg1 ); rc = WS_WritePeReg( WS_SlotNumber, PeNum, Port + CTRL_2_OFFSET, 1, &dControlReg2 ); rc = WS_WritePeReg( WS_SlotNumber, PeNum, Port + CTRL_3_OFFSET, 1, &dControlReg3 ); /* Check to see all data was transferred */ do { rc = WS_ReadPeReg ( WS_SlotNumber, PeNum, Port + STAT_OFFSET, 1, &StatusWord ); } while ( (StatusWord & 0x1) != 1 ); }while (( ( NumDWORDSToWrite - memCntr ) >= MAX_DWORDS_PER_TRANSFER ) && ( rc == WS_SUCCESS )); } /* if the number of dwords to write is less than or equal to 256 */ if (( rc == WS_SUCCESS ) && (( NumDWORDSToWrite - memCntr ) != 0 )) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -