/** * numachip_select_counter - Select Performance Counter */ void numachip_select_pcounter(struct numachip_context *cntxt, uint32_t counterno, uint32_t eventreg, nc_error_t *error) { uint32_t current_counter_val=0; *error = NUMACHIP_ERR_OK; if (counterno > 7) { *error=NUMACHIP_ERR_INVALID_PARAMETER; return; } if (eventreg > 7) { *error=NUMACHIP_ERR_INVALID_PARAMETER; return; } current_counter_val=numachip_read_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER); DEBUG_STATEMENT(printf("Current counterval read 0x%x eventreg 0x%x\n", current_counter_val, eventreg)); DEBUG_STATEMENT(printf("Current (eventreg << (counterno*4)) 0x%x\n", (eventreg << (counterno*4)))); if (current_counter_val & ((eventreg << (counterno*4)))) { DEBUG_STATEMENT(printf("Current (eventreg << (counterno*4)) 0x%x equals current_counterval 0x%x\n", (eventreg << (counterno*4)), current_counter_val)); *error=NUMACHIP_ERR_BUSY; return; } current_counter_val=current_counter_val | ((eventreg << (counterno*4))); numachip_write_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER,current_counter_val); DEBUG_STATEMENT(printf("Current counterval written 0x%x readback 0x%x\n",current_counter_val,numachip_read_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER))); }
void swapOutFrame(int entry1Index) { // clear the definition bit in entry 1 probably just set entry 1 to 0 int entry1, entry2; entry1 = memory[entry1Index]; entry2 = memory[entry1Index + 1]; // if dirty bit is not set and swap exists we are done if (DIRTY(entry1) && PAGED(entry2)) { DEBUG_STATEMENT(DEBUG_MMU,"\nDirty copy of swap write to old page"); // if swap exits swap access page with old write accessPage(SWAPPAGE(entry2), FRAME(entry1), PAGE_OLD_WRITE); } else if (!PAGED(entry2)) { DEBUG_STATEMENT(DEBUG_MMU,"\nNo copy in swap write to new swap"); // if swap doesn't exist then we need to write out to an new write memory[entry1Index + 1] = entry2 = SET_PAGED(nextPage); accessPage(nextPage, FRAME(entry1), PAGE_NEW_WRITE); } if (DEBUG_MMU) { outPTE("\nSwapped Entry - (Pre-clear) ", entry1Index); } memory[entry1Index] = 0; if (DEBUG_MMU) { outPTE("Swapped Entry - ", entry1Index); } return; }
/* *Index: last one available buffer location. */ int TLV_Pack(char tag, char *pData, UINT16 len) { UINT16 index = pIEC61850_9_2->offset; char *SendBuff = pIEC61850_9_2->SendBuff; if (pIEC61850_9_2->offset < 0) { DEBUG_STATEMENT("ASDU和通道配置超过以太网帧长度限制!"); return -1; } if (pData != &SendBuff[index+1])//不是buffer本身,需要copy { index -= len; memcpy(&SendBuff[index+1], pData, len); } /* * 根据ASN.1规则TLV,计算长度,设置长度信息 * len>0x100, 第一字节的高位为1,后面7为表示后面用几个字节表示长度信息 * len>0x100,以此类推 */ if(len>=0x100) { SendBuff[index-2]= 0x82; SendBuff[index-1]= (uint8_t)(len>>8); SendBuff[index] = (uint8_t)(len); index -= 3; }
ADI_ETHER_BUFFER *EtherRecv ( ADI_ETHER_HANDLE const hDevice ) { ADI_ETHER_BUFFER *pack = NULL; int nSelectedDev = 0; if ( hDevice == g_hDev[0] ) { nSelectedDev = 0; } else if( hDevice == g_hDev[1] ) { nSelectedDev = 1; } else { DEBUG_STATEMENT ( " EtherRecv: Can not find the hDev \n\n" ); return NULL; } //一次返回一个 ENTER_CRITICAL_REGION(); DeQueue ( &user_net_config_info[nSelectedDev].rx_completed_q, ( QElem * ) &pack ) ; EXIT_CRITICAL_REGION(); return pack; }
void numachip_all_start_pcounter(struct numachip_context **cntxt, uint32_t num_nodes, uint32_t counterno, uint32_t event, uint32_t mask, nc_error_t *error) { nc_error_t retval = NUMACHIP_ERR_OK; uint32_t node=0; for (node=0; node<num_nodes; node++) { numachip_fullstart_pcounter(cntxt[node],counterno,event,mask, error); if (retval != NUMACHIP_ERR_OK) { fprintf(stderr,"Numachip user API failed retval = 0x%x", *error); return; } } DEBUG_STATEMENT(printf("%d: select is 0x%x mask 0x%x value 0x%llx (%lld) \n", counterno, numachip_get_pcounter_select(cntxt[node],counterno,error), numachip_get_pcounter_mask(cntxt[node],counterno,error), numachip_get_pcounter(cntxt[node],counterno,error), numachip_get_pcounter(cntxt[node],counterno,error))); if (retval != NUMACHIP_ERR_OK) fprintf(stderr,"Numachip user API failed retval = 0x%x",*error); }
void numachip_mask_pcounter(struct numachip_context *cntxt, uint32_t counterno, uint32_t mask, nc_error_t *error) { uint32_t mask_register, mask_value; *error = NUMACHIP_ERR_OK; if (counterno > 7) { *error=NUMACHIP_ERR_INVALID_PARAMETER; return; } /* * We will accept values from 0-7. And translate them in here */ if (mask>7) { *error=NUMACHIP_ERR_INVALID_PARAMETER; return; } //6,5,3,2 if (counterno==7) { DEBUG_STATEMENT(printf("Need to consider H2S_CSR_G3_TIMER_FOR_ECC_COUNTER_7: 0x%x\n",numachip_read_csr(cntxt,H2S_CSR_G3_TIMER_FOR_ECC_COUNTER_7))); numachip_write_csr(cntxt,H2S_CSR_G3_TIMER_FOR_ECC_COUNTER_7,0x0); } mask_register=H2S_CSR_G3_COMPARE_AND_MASK_OF_COUNTER_0 + (0x4*counterno); //TBD: Check that the counter has been cleared? mask_value = 1 << mask ; DEBUG_STATEMENT(printf("1.We program the mask_register to mask value 0x%x\n", mask_value)); //2.We program the mask_register to count 6 - HT-Request with ctag miss (and the counting starts). //We use the same value for compare and mask to only count this event. mask_value= (mask_value << 8) | mask_value; DEBUG_STATEMENT(printf("2.We program the mask_register to count mask value 0x%x was 0x%x\n", mask_value,numachip_get_pcounter_mask(cntxt,counterno,error))); if (numachip_get_pcounter_mask(cntxt,counterno,error) & mask_value) { *error=NUMACHIP_ERR_BUSY; return; } numachip_write_csr(cntxt,mask_register,mask_value); DEBUG_STATEMENT(printf("Mask register at 0x%x is set to 0x%x READBACK: 0x%x\n",mask_register, mask_value,numachip_read_csr(cntxt,mask_register))); }
int EtherSend ( ADI_ETHER_HANDLE const hDevice, ADI_ETHER_BUFFER *tx_frame ) { // int i , nSelectedDev = 0; if ( !hDevice || !tx_frame ) { DEBUG_STATEMENT ( " EtherSend: Input Params IS NULL \n\n" ); return 0; } ADI_ETHER_RESULT eResult = adi_ether_Write ( hDevice, tx_frame ); if ( eResult != ADI_ETHER_RESULT_SUCCESS ) { DEBUG_STATEMENT ( " EtherSend: adi_ether_Write failed \n\n" ); return 0; } return 1; }
/*Stop also clears the mask. Not obvius*/ void numachip_stop_pcounter(struct numachip_context *cntxt, uint32_t counterno, nc_error_t *error) { uint32_t current_counter_val, mask_register; *error = NUMACHIP_ERR_OK; if (counterno > 7) { *error=NUMACHIP_ERR_INVALID_PARAMETER; return; } current_counter_val=numachip_read_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER); current_counter_val=0x77777777 & (~(0x7 << (counterno*4))); DEBUG_STATEMENT(printf("Current counterval to be stopped 0x%x\n",current_counter_val)); numachip_write_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER,current_counter_val); DEBUG_STATEMENT(printf("Select register at 0x%x is set to 0x%x READBACK: 0x%x\n",H2S_CSR_G3_SELECT_COUNTER,current_counter_val,numachip_read_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER))); mask_register=H2S_CSR_G3_COMPARE_AND_MASK_OF_COUNTER_0 + (0x4*counterno); numachip_write_csr(cntxt,mask_register,0); DEBUG_STATEMENT(printf("Mask register at 0x%x is set to 0x%x READBACK: 0x%x\n",mask_register, 0,numachip_read_csr(cntxt,mask_register))); }
/** * numachip_clear_counter - Clear Performance Counter Register */ void numachip_clear_pcounter(struct numachip_context *cntxt, uint32_t counterno, nc_error_t *error) { uint32_t mask_register, perf_reg, current_counter_val; *error = NUMACHIP_ERR_OK; if (counterno > 7) { *error=NUMACHIP_ERR_INVALID_PARAMETER; return; } /* * 1. Clear: First we clear the counter selection, mask-register and the * corresponding performance register. * * Note: We do not care about the previous values in the mask and perf reg, * since we are going to pollute these anyway (in the first version). */ DEBUG_STATEMENT(printf("1. Clear: First we clear the counter select register for counter %d .\n", counterno)); current_counter_val=numachip_read_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER); DEBUG_STATEMENT(printf("Current counter value before to be cleared 0x%x\n",current_counter_val)); DEBUG_STATEMENT(printf("Mask to be used for calculating value 0x%x\n",0x7 << (counterno*4))); current_counter_val=current_counter_val & (~(0x7 << (counterno*4))); DEBUG_STATEMENT(printf("New Current counter value to be cleared 0x%x\n",current_counter_val)); numachip_write_csr(cntxt,H2S_CSR_G3_SELECT_COUNTER,current_counter_val); /* We need to clear the corresponing compare and mask register we are planning to use: * H2S_CSR_G3_COMPARE_AND_MASK_OF_COUNTER_0 (0xFA0 + 0x4*counterno) */ mask_register=H2S_CSR_G3_COMPARE_AND_MASK_OF_COUNTER_0 + (0x4*counterno); numachip_write_csr(cntxt,mask_register,0x0); /* We need to clear the corresponding Performance counter register we plan to use * H2S_CSR_G3_PERFORMANCE_COUNTER_0_40_BIT_UPPER_BITS (0xFC0 + (0x8 */ perf_reg=H2S_CSR_G3_PERFORMANCE_COUNTER_0_40_BIT_UPPER_BITS + (0x8*counterno); numachip_write_csr(cntxt, perf_reg,0x0); perf_reg=H2S_CSR_G3_PERFORMANCE_COUNTER_0_40_BIT_LOWER_BITS + (0x8*counterno); numachip_write_csr(cntxt, perf_reg ,0x0); }
uint64_t numachip_get_pcounter(struct numachip_context *cntxt, uint32_t counterno, nc_error_t *error) { uint32_t perfreg=0; uint64_t counterval=0; *error = NUMACHIP_ERR_OK; if (counterno > 7) { *error=NUMACHIP_ERR_INVALID_PARAMETER; return 0; } perfreg=H2S_CSR_G3_PERFORMANCE_COUNTER_0_40_BIT_UPPER_BITS + (0x8*counterno); counterval= (uint64_t) numachip_read_csr(cntxt,perfreg) << 32; DEBUG_STATEMENT(printf("PERF_REF=0x%x value=0x%Lx \n",perfreg, counterval)); perfreg=H2S_CSR_G3_PERFORMANCE_COUNTER_0_40_BIT_LOWER_BITS + (0x8*counterno); counterval= (uint64_t) counterval | numachip_read_csr(cntxt,perfreg); DEBUG_STATEMENT(printf("PERF_REF=0x%x value=0x%Lx \n", perfreg, counterval)); return counterval; }
GameScreen::GameScreen(int x, int y, int rand_seed) { std::srand(rand_seed); height = x; width = y; running = false; num_squadrons = 0; num_islands = (std::rand() % MAX_ISLANDS) + 1; for(int i = 0; i < num_islands; i++) { //TODO: randoms to sensible values. islands[i] = new Island(Position(std::rand() % height, std::rand() % width), (Team) (std::rand() % (NUM_PLAYERS + 1)), std::rand() , std::rand() % MAX_WEIGHT + 1); DEBUG_STATEMENT(std::cout << "New island: " << *islands[i] << std::endl); } }
Device::Device(WindowId window_id) { device_id_ = NULL; cl_int cl_status = CL_SUCCESS; DEBUG_STATEMENT(std::cout << "Initializing compute::Device" << std::endl); // get the number of platforms cl_uint platform_count = 0; cl_status = clGetPlatformIDs(0, NULL, &platform_count); OclCheckError(cl_status, "clGetPlatformIDs, get platform count"); DEBUG_STATEMENT(std::cout << "found platform(s) " << platform_count << std::endl); if (platform_count == 0) { std::cerr << "could not find any OpenCL platforms" << std::endl; abort(); } // get the list of platforms cl_platform_id *platform_list = new cl_platform_id[platform_count]; cl_status = clGetPlatformIDs(platform_count, platform_list, NULL); OclCheckError(cl_status, "clGetPlatformIDs, get platform list"); cl_platform_id platform_use = NULL; for (cl_uint i = 0; i < platform_count; i++) { char str[128]; size_t ret_size = 0; cl_int status = 0; status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_VENDOR, 128, str, &ret_size); OclCheckError(status, "clGetPlatformInfo"); assert(128 >= ret_size); if (!strcmp("Advanced Micro Devices, Inc.", str) || !strcmp("NVIDIA Corporation", str)) { platform_use = platform_list[i]; } } assert(platform_use); DEBUG_STATEMENT( for (cl_uint i = 0; i < platform_count; i++) { char str[128]; size_t ret_size = 0; cl_int status = 0; status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_PROFILE, 128, str, &ret_size); OclCheckError(status, "clGetPlatformInfo"); assert(128 >= ret_size); std::cout<<"CL_PLATFORM_PROFILE " <<str <<std::endl; status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_VERSION, 128, str, &ret_size); OclCheckError(status, "clGetPlatformInfo"); assert(128 >= ret_size); std::cout<<"CL_PLATFORM_VERSION " <<str <<std::endl; status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_NAME, 128, str, &ret_size); OclCheckError(status, "clGetPlatformInfo"); assert(128 >= ret_size); std::cout<<"CL_PLATFORM_NAME " <<str <<std::endl; status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_VENDOR, 128, str, &ret_size); OclCheckError(status, "clGetPlatformInfo"); assert(128 >= ret_size); std::cout<<"CL_PLATFORM_VENDOR " <<str <<std::endl; status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_EXTENSIONS, 128, str, &ret_size); OclCheckError(status, "clGetPlatformInfo"); assert(128 >= ret_size); std::cout<<"CL_PLATFORM_EXTENSIONS " <<str <<std::endl; } );
void main ( void ) { ADI_ETHER_HANDLE hEthernet; ADI_ETHER_RESULT etherResult; ADI_ETHER_DEV_INIT EtherInitData[MAX_NETWORK_IF] = { { true, &memtable[0] }, { true, &memtable[1] }}; // data-cache,driver memory uint32_t reg_data; int i, nEtherDevUsed; char *ether_stack_block; ADI_GPIO_RESULT gpio_result; uint32_t gpioMaxCallbacks; int nRet; /** * Initialize managed drivers and/or services that have been added to * the project. * @return zero on success */ adi_initComponents(); /** * The default startup code does not include any functionality to allow * core 0 to enable core 1. A convenient way to enable core 1 is to use the * 'adi_core_1_enable' function. */ adi_core_1_enable(); /* Begin adding your custom code here */ g_AuxiTMIsFirstUpdated = 1; /* init CGU first time */ CGU_Init ( MULTIPLIER_SEL, CCLK_SEL, DDRCLK_SEL ); /* CCLK=16.384*iMultiplier /1 Mhz, 16.384*iMultiplier/iDDCLKSel Mhz DDR2 CLK */ #if defined(__DEBUG_FILE__) /* open the debug file */ pDebugFile = fopen(__DEBUG_FILE_NAME__, "w"); if (pDebugFile == 0) { fclose(pDebugFile); return; } #elif defined(__DEBUG_UART__) Init_UART(); #endif Init_PTPAuxin(); /* configures the switches */ #if BF609_EZ_BRD DEBUG_STATEMENT ( "Configuring switches for the ethernet operation \n\n" ); ConfigSoftSwitches(); #endif /* open ethernet device */ nEtherDevUsed = ( user_net_num_ifces > MAX_NETWORK_IF ) ? MAX_NETWORK_IF : user_net_num_ifces; #if BF609_EZ_BRD nEtherDevUsed = 1; #endif DEBUG_STATEMENT ( " init EMAC\n\n" ); for ( i = 0; i < nEtherDevUsed; i++ ) { etherResult = adi_ether_Open ( g_pDevEntry[i], &EtherInitData[i], g_pEthCallBack[i], &hEthernet ); if ( etherResult != ADI_ETHER_RESULT_SUCCESS ) { DEBUG_STATEMENT ( "adi_ether_Open: failed to open ethernet driver\n\n" ); return ; } g_hDev[i] = hEthernet; /* get the mac address */ memcpy ( ( ( ADI_EMAC_DEVICE * ) hEthernet )->MacAddress, user_net_config_info[i].hwaddr, 6 ); /* allocate memory */ ether_stack_block = heap_malloc ( i+1, g_contEthHeapSize[i] ); if ( ether_stack_block == NULL ) { DEBUG_PRINT ( " heap_malloc: in heap %d, failed to allocate memory to the stack \n\n" , i+1); return ; } /* init buf mem */ nRet = InitBuff ( g_contEthHeapSize[i], ether_stack_block, hEthernet, &user_net_config_info[i] ); if( nRet<0 ) { DEBUG_STATEMENT ( " InitBuff: failed to enable Init Buffs\n\n" ); return ; } /* Enable the MAC */ etherResult = adi_ether_EnableMAC ( hEthernet ); if ( etherResult != ADI_ETHER_RESULT_SUCCESS ) { DEBUG_STATEMENT ( " adi_ether_EnableMAC: failed to enable EMAC\n\n" ); return ; } } //enable EMAC INT adi_int_EnableInt ( ( (ADI_EMAC_DEVICE *)g_hDev[0])->Interrupt, true); adi_int_EnableInt ( ( (ADI_EMAC_DEVICE *)g_hDev[1])->Interrupt, true); /* activate rx channel DMA */ enable_rx ( g_hDev[0] ); enable_rx ( g_hDev[1] ); /* activate tx channel DMA */ enable_tx ( g_hDev[0] ); enable_tx ( g_hDev[1] ); //enable emac0 tx,rx enable_emac_tx_rx ( g_hDev[0] ); //enable emac1 tx,rx enable_emac_tx_rx ( g_hDev[1] ); //enable Enable_Time_Stamp_Auxin_Interrupt(); // HandleLoop(); return ; }//main
int getClockFrame(int notme) { int frame; // iterate through rpts (0x2400 - LC3_RPT_END) int maxWrap = 20; for (;maxWrap; cBigHand += 2, cLittleHand = 0) { int i; int rpte1; int upta, upte1; if (cBigHand >= LC3_RPT_END) { DEBUG_STATEMENT(DEBUG_MMU,"\nClock is wrapping"); cBigHand = LC3_RPT; maxWrap--; } rpte1 = memory[cBigHand]; if (DEFINED(rpte1) && REFERENCED(rpte1)) { // clear reference DEBUG_STATEMENT(DEBUG_MMU,"\nclearing ref for rpte"); memory[cBigHand] = rpte1 = CLEAR_REF(rpte1); } else if (DEFINED(rpte1)) { // if one is non-referenced go to the user page table // scout out the upt!! note that this has not been referenced if (DEBUG_MMU) { outPTE("\nRPT entry being checked - ", cBigHand); } upta = (FRAME(rpte1)<<6); for (i = cLittleHand % 64; i < 64;i += 2, cLittleHand = i % 64) { // - iterate over userpage table upte1 = memory[upta + (i)]; if (PINNED(upte1) || FRAME(upte1) == notme) { DEBUG_STATEMENT(DEBUG_MMU,"\nupte1 frame was the notme frame (%x = %x) or pinned", FRAME(upte1), notme); if (DEBUG_MMU) { outPTE("UPT entry being checked - ", upta + i); } continue; } if (DEFINED(upte1) && REFERENCED(upte1)) { // - if entry is referenced un-reference and move on // clear reference DEBUG_STATEMENT(DEBUG_MMU,"\nclearing ref for upte %d", cLittleHand); memory[cBigHand] = rpte1 = SET_PINNED(rpte1); memory[upta + (i)] = upte1 = CLEAR_REF(upte1); } else if (DEFINED(upte1)) { // - otherwise prep it for being put into swap // we can use the frame referenced by upte1 if (DEBUG_MMU) { outPTE("UPT entry being checked - ", upta + 1); } DEBUG_STATEMENT(DEBUG_MMU,"\nUpte1 %x, Upte2 %x", upte1, memory[upta + (i + 1)]); memory[cBigHand] = rpte1 = SET_DIRTY(rpte1); frame = FRAME(upte1); swapOutFrame(upta + i); cLittleHand += 2; DEBUG_STATEMENT(DEBUG_MMU,"\nFound a data frame that can be used! (%d, %x)", frame, frame); return frame; } } cLittleHand = 0; if (!REFERENCED(rpte1) && !PINNED(rpte1) && FRAME(rpte1) != notme) { // if we only replaced or did nothing to upte entries // we can use the frame referenced by rpte1 frame = FRAME(rpte1); DEBUG_STATEMENT(DEBUG_MMU,"\nFound a upt frame that can be used! (%d, %x)", frame, frame); swapOutFrame(cBigHand); cBigHand += 2; return frame; } else { // otherwise remove the pin flag memory[cBigHand] = rpte1 = CLEAR_PINNED(rpte1); } } } // when you get the bottom start at the top again DEBUG_STATEMENT(DEBUG_MMU,"\n No valid frame found notme = %d", notme); if (DEBUG_MMU) { displayTableHierarchy(); } return -1; }
int main(int argc, char **argv) { struct numachip_device **devices; //struct numachip_context *cntxt; struct numachip_context **cntxt; int counter=0, i=0; int num_devices; if (argc<2) { usage(); return(-1); } devices = numachip_get_device_list(&num_devices); DEBUG_STATEMENT(printf("Found %d NumaChip devices\n", num_devices)); if (!devices) return -1; DEBUG_STATEMENT(printf("sizeof(struct numachip_context *) %ld\n", sizeof(struct numachip_context *))); cntxt = malloc(num_devices * sizeof(struct numachip_context *)); for(i=0; i<num_devices; i++) { cntxt[i] = numachip_open_device(devices[i]); } numachip_free_device_list(devices); if (!cntxt[0]) return -1; /* Get the parameters */ for (counter=1; (int)counter<argc; counter++) { if (!strcmp("-dump-scc-csr",argv[counter])) { dump_scc_csr(cntxt[0]); dump_scc_csr(cntxt[1]); continue; } if (!strcmp("-dump-phy-regs",argv[counter])) { phy_regs(cntxt[0]); phy_regs(cntxt[1]); continue; } if (!strcmp("-setup-tracer",argv[counter])) { tracer_setup(*cntxt); continue; } if (!strcmp("-tracer-result",argv[counter])) { tracer_result(*cntxt); continue; } if (!strcmp("-count-start",argv[counter])) { count_api_start(cntxt, num_devices); continue; } if (!strcmp("-count-stop",argv[counter])) { count_api_stop(cntxt, num_devices); continue; } if (!strcmp("-count-rate",argv[counter])) { count_api_stop(cntxt, num_devices); count_api_start(cntxt, num_devices); count_rate(cntxt, num_devices); continue; } } for(i=0; i<num_devices; i++) { close_device(cntxt[i]); } free(cntxt); return 0; }