/**
*
* This function is used to override the driver's default sleep functionality.
* For MicroBlaze systems, the XDpRxSs_WaitUs driver function's default behavior
* is to use the MB_Sleep function from microblaze_sleep.h, which is implemented
* in software and only has millisecond accuracy. For this reason, using a
* hardware timer is preferable. For ARM/Zynq SoC systems, the SoC's timer is
* used - XDpRxSs_WaitUs will ignore this custom timer handler.
*
* @param	InstancePtr is a pointer to the XDpRxSs core instance.
* @param	MicroSeconds is the number of microseconds to delay/sleep for.
*
* @return	None.
*
* @note		Use the XDpRxSs_SetUserTimerHandler driver function to set this
*		function as the handler for when the XDpRxSs_WaitUs driver
*		function is called.
*
******************************************************************************/
void DpRxSs_CustomWaitUs(void *InstancePtr, u32 MicroSeconds)
{
	XDpRxSs *DpRxSsPtr = (XDpRxSs *)InstancePtr;
	u32 TimerVal;

	XTmrCtr_Start(DpRxSsPtr->DpPtr->UserTimerPtr, 0);

	/* Wait specified number of useconds. */
	do {
		TimerVal = XTmrCtr_GetValue(DpRxSsPtr->DpPtr->UserTimerPtr, 0);
	} while (TimerVal < (MicroSeconds *
			(DpRxSsPtr->DpPtr->Config.SAxiClkHz / 1000000)));

	XTmrCtr_Stop(DpRxSsPtr->DpPtr->UserTimerPtr, 0);
}
Example #2
0
int main (void)
{
    float u[n*n], v[n*n], u0[n*n], v0[n*n];
    float x, y, x0, y_0, f, r, U[2], V[2], s, t;
    int i, j, i0, j_0, i1, j_1,m;
    int k;
    float visc=1.25;
    float dt=2.36;
    int start,end;
    
    xil_printf("----------------------- START ------------------------ ! \n\r");
    int MASK_LENGTH= 10;//(int) ceil((log(BUFFER_SIZE))/log(2));
    int MASK = ((1 << MASK_LENGTH)-1);

    //-- Flag Initializations
    for (i=0; i<BUFFER_SIZE; i++)
    {
        flag1[i]=0;
        flag2[i]=0;
        flag3[i]=0;
    }
    

    XTmrCtr timer;
    XTmrCtr_Initialize(&timer, XPAR_XPS_TIMER_0_DEVICE_ID);

    XTmrCtr_Reset(&timer, TIMER_COUNTER_0);
    start = XTmrCtr_GetValue(&timer, TIMER_COUNTER_0);

    // Start timer
    XTmrCtr_Start(&timer, TIMER_COUNTER_0);

    //------- LOOP FOR IMAGES -------
    for (k=0; k < Number_of_Images; k++)  // loop for Images 
    {
	  consumer_index = ci; // for nested loop can be i*n+j

        while (consumer_index<SIZE_floid)
        {

            
            if (read_from_fifo ==1)
            {
                getfsl(fifo_index,0);
                if (fifo_index!=999999999) 
                {    						
                    getfsl(fifo_data,0);
                    getfsl(fifo_data2,0);
                    xil_printf("READ %d FROM FIFO \t",fifo_index);
                    
                    if (consumer_index == fifo_index && fifo_index!=999999999)
                    {   
                        // consume the data directly				
                        consumer_data = fifo_data;
                        consumer_data2 = fifo_data2;
                        xil_printf("»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» %d DIRECTLY CONSUMED !\n\r",consumer_index);
                        
                        consumer_index=consumer_index+1;//ci;
								consumer_done=1;
                        read_from_fifo=1;
                        //-- The rest of consumer's computing stage here   : output: consumer_index
                        u0[i+(n+2)*j] = consumer_data;  // u[i+n*j]
                        v0[i+(n+2)*j] = consumer_data2;  // v[i+n*j]
                        y = j<=n/2 ? j : j-n;
                        r = x*x+y*y;
                        if ( r==0.0 ) continue;
                        f = exp(-r*dt*visc);
                        U[0] = u0[i +(n+2)*j]; 
                        V[0] = v0[i +(n+2)*j];
                        U[1] = u0[i+1+(n+2)*j]; 
                        V[1] = v0[i+1+(n+2)*j];
                        u0[i +(n+2)*j] = f*( (1-x*x/r)*U[0] -x*y/r *V[0] );
                        u0[i+1+(n+2)*j] = f*( (1-x*x/r)*U[1] -x*y/r *V[1] );
                        v0[i+ (n+2)*j] = f*( -y*x/r *U[0] + (1-y*y/r)*V[0] );
                        v0[i+1+(n+2)*j] = f*( -y*x/r *U[1] + (1-y*y/r)*V[1] );
                        
                        
                    }

                }
						else  if (fifo_index==999999999)
							{
							xil_printf("==PRODUCER STOPPED AND consumer_index IS %d!\n\r",consumer_index);
							read_from_fifo=0; 
							//consumer_index++;
							}  
				}			
               
                    // compute the hash
                    consumer_hash_index = consumer_index & MASK;   // here index is not refreshing
                    fifo_hash_index = fifo_index & MASK;
                    
                    // Load from memory
                    if (flag1[consumer_hash_index]==1 && index1[consumer_hash_index]==consumer_index)
                    {
                        flag1[consumer_hash_index]=0;
                        consumer_data= data1[consumer_hash_index];

                        xil_printf("========== LOAD consumer_index %d from T1 ================!\n\r",consumer_index);
								consumer_index++;
								consumer_done=1;
                        //-- The rest of consumer's computing stage here : output: consumer_index
                        u0[i+(n+2)*j] = consumer_data;  // u[i+n*j]
                        v0[i+(n+2)*j] = consumer_data2;  // v[i+n*j]
                        y = j<=n/2 ? j : j-n;
                        r = x*x+y*y;
                        if ( r==0.0 ) continue;
                        f = exp(-r*dt*visc);
                        U[0] = u0[i +(n+2)*j]; 
                        V[0] = v0[i +(n+2)*j];
                        U[1] = u0[i+1+(n+2)*j]; 
                        V[1] = v0[i+1+(n+2)*j];
                        u0[i +(n+2)*j] = f*( (1-x*x/r)*U[0] -x*y/r *V[0] );
                        u0[i+1+(n+2)*j] = f*( (1-x*x/r)*U[1] -x*y/r *V[1] );
                        v0[i+ (n+2)*j] = f*( -y*x/r *U[0] + (1-y*y/r)*V[0] );
                        v0[i+1+(n+2)*j] = f*( -y*x/r *U[1] + (1-y*y/r)*V[1] );
								

								if (fifo_index!=999999999) 
									read_from_fifo=1;
							

                    }
                    else if (flag2[consumer_hash_index]==1 && index2[consumer_hash_index]==consumer_index)
                    {
                        flag2[consumer_hash_index]=0;
                        consumer_data= data2[consumer_hash_index];
                       consumer_index++;
                        read_from_fifo=1;
                        consumer_done=1;
                        xil_printf("=================== LOAD consumer_index %d from T2 ================!\n\r",consumer_index);
                        //-- The rest of consumer's computing stage here  : output: consumer_index
                        u0[i+(n+2)*j] = consumer_data;  // u[i+n*j]
                        v0[i+(n+2)*j] = consumer_data2;  // v[i+n*j]
                        y = j<=n/2 ? j : j-n;
                        r = x*x+y*y;
                        if ( r==0.0 ) continue;
                        f = exp(-r*dt*visc);
                        U[0] = u0[i +(n+2)*j]; 
                        V[0] = v0[i +(n+2)*j];
                        U[1] = u0[i+1+(n+2)*j]; 
                        V[1] = v0[i+1+(n+2)*j];
                        u0[i +(n+2)*j] = f*( (1-x*x/r)*U[0] -x*y/r *V[0] );
                        u0[i+1+(n+2)*j] = f*( (1-x*x/r)*U[1] -x*y/r *V[1] );
                        v0[i+ (n+2)*j] = f*( -y*x/r *U[0] + (1-y*y/r)*V[0] );
                        v0[i+1+(n+2)*j] = f*( -y*x/r *U[1] + (1-y*y/r)*V[1] );

                    }
                    else if (flag3[consumer_hash_index]==1 && index3[consumer_hash_index]==consumer_index)
                    {
                        flag3[consumer_hash_index]=0;
                        consumer_data= data3[consumer_hash_index];
                        consumer_index++;
                        read_from_fifo=1;
                        consumer_done=1;
								consumer_done=1;
                        xil_printf("=================== LOAD consumer_index %d from T3 ================!\n\r",consumer_index);
                        //-- The rest of consumer's computing stage here : output: consumer_index
                        u0[i+(n+2)*j] = consumer_data;  // u[i+n*j]
                        v0[i+(n+2)*j] = consumer_data2;  // v[i+n*j]
                        y = j<=n/2 ? j : j-n;
                        r = x*x+y*y;
                        if ( r==0.0 ) continue;
                        f = exp(-r*dt*visc);
                        U[0] = u0[i +(n+2)*j]; 
                        V[0] = v0[i +(n+2)*j];
                        U[1] = u0[i+1+(n+2)*j]; 
                        V[1] = v0[i+1+(n+2)*j];
                        u0[i +(n+2)*j] = f*( (1-x*x/r)*U[0] -x*y/r *V[0] );
                        u0[i+1+(n+2)*j] = f*( (1-x*x/r)*U[1] -x*y/r *V[1] );
                        v0[i+ (n+2)*j] = f*( -y*x/r *U[0] + (1-y*y/r)*V[0] );
                        v0[i+1+(n+2)*j] = f*( -y*x/r *U[1] + (1-y*y/r)*V[1] );
								

                    }
                    // Store in memory
                    else if (read_from_fifo ==1 && consumer_done==0) 
                    {
							 
                        if (flag1[fifo_hash_index]==0 && fifo_index!=999999999)
                        {
                            data1[fifo_hash_index] =fifo_data; 
                            index1[fifo_hash_index] =fifo_index;
                            flag1[fifo_hash_index]=1;
                            read_from_fifo=1;									 
                            xil_printf("»»»»»»»»»»»»»»»»»%d STORED in T1 \n\r",fifo_index);
                        }
                        else if (flag2[fifo_hash_index]==0 && fifo_index!=999999999)
                        {
                            data2[fifo_hash_index] =fifo_data;
                            index2[fifo_hash_index] =fifo_index;						  
                            flag2[fifo_hash_index]=1;
                            read_from_fifo=1;
                            xil_printf("»»»»»»»»»»»»»»»»»%d STORED in T2 \n\r",fifo_index);
                        }
                        else if (flag3[fifo_hash_index]==0 && fifo_index!=999999999)
                        {
                            data3[fifo_hash_index] =fifo_data;
                            index3[fifo_hash_index] =fifo_index;
                            flag3[fifo_hash_index]=1;
                            read_from_fifo=1;
                            xil_printf("»»»»»»»»»»»»»»»»»%d STORED in T3 \n\r",fifo_index);
                        }
                        else
                        read_from_fifo=0;
							
                        
                    } // Store in memory						  
						  else
						  {
							xil_printf("ERROR ! Index %d cannot be found !!!!\n\r",consumer_index);
							consumer_done=0;
							consumer_index++;
							}
                
            
        }
    }
    xil_printf ("consumer_index =%d \t ci=%d \n\r",consumer_index,ci);
    end = XTmrCtr_GetValue(&timer, TIMER_COUNTER_0);
    XTmrCtr_Stop(&timer, TIMER_COUNTER_0);
    xil_printf("Timer Start value = %d    Timer end value = %d \r\n", start, end-start);
    return 0;
}
Example #3
0
u32 getTimerValue(u8 TmrCtrNumber) {
	return XTmrCtr_GetValue(&timer, TmrCtrNumber);
}
void * foo_thread(void * arg) 
{

  



   data * package = (data *) arg;
   Hint * dataA = package->dataA;
   Hint * dataB = package->dataB;
   Hint * dataC = package->dataC; 
  
   Hint * brama = (Hint *) BRAMA;
   Hint * bramb = (Hint *) BRAMB;
   Hint * bramc = (Hint *) BRAMC;
   
   
   int e,Status;
   int time = package->time;
   XTmrCtr * mytimer =package->timer;

  
   XAxiCdma mydma;
   #ifndef HETERO_COMPILATION
      Status= XAxiCdma_Initialize(&mydma, XPAR_PERIPHERALS_CENTRAL_DMA_DEVICE_ID);    
   #else
      Status= XAxiCdma_Initialize(&mydma,XPAR_GROUP_0_SLAVE_0_LOCAL_DMA_DEVICE_ID);     
   #endif
    if (Status != XST_SUCCESS) {
         putnum(0xdeadbeef);
         return XST_FAILURE;
    }   
   XAxiCdma_IntrDisable(&mydma, XAXICDMA_XR_IRQ_ALL_MASK);
  

   XTmrCtr_Reset(mytimer,1); 
  
   

  
//sending the data ********************************************** 
 /*for (e = 0; e < package->vector_size; e++) {
         brama[e] = dataA[e];
         bramb[e] = dataB[e];   }  
*/
	Status = XAxiCdma_Transfer(&mydma, (u32) package->dataA , (u32) BRAMA, package->vector_size *4, NULL, NULL);
	Status = XAxiCdma_Transfer(&mydma, (u32) package->dataB , (u32) BRAMB, package->vector_size *4, NULL, NULL);
	
	
  //computation
// for (e = 0; e < package->vector_size; e++)     bramc[e] = brama[e] + bramb[e];

/*
   int cmd =1; //1=> means add, 2=> means subtraction
   int start =0;
   int end =  package->vector_size ;
	putfslx( cmd, 0, FSL_DEFAULT);
	putfslx( end, 0, FSL_DEFAULT);
	putfslx( start, 0, FSL_DEFAULT);
	getfslx(cmd, 0, FSL_DEFAULT); 
*/

     putfslx((0 << 30) | (SIZE << 15) | 0, 0, FSL_DEFAULT);
	  getfslx(e, 0, FSL_DEFAULT);

 
 //sending the data back to dram **********************************************   
    Status = XAxiCdma_Transfer(&mydma, (u32) BRAMC , (u32) package->dataC, package->vector_size *4, NULL, NULL);
    
   // for (e = 0; e < package->vector_size; e++)         dataC[e] = bramc[e];
    
    
    package->time= XTmrCtr_GetValue(mytimer,1);  
    return (void *) 0;
}
int main(int argc, char *argv[]) 
{
   
  

   xil_printf("\r\n-----Begin Program-----\r\n"); 
   
  
//===============================================================================
   //Initilizing Data
//===============================================================================   
   data package;
   package.vector_size = SIZE;
   package.dataA = (int *) malloc(sizeof(int) * package.vector_size);
   package.dataB = (int *) malloc(sizeof(int) * package.vector_size);
   package.dataC = (int *) malloc(sizeof(int) * package.vector_size);  
   
  // xil_printf (" %08x  ,  %08x  , %08x  , \r\n", package.dataA,package.dataB,package.dataC);

   assert(package.dataA != NULL);
   assert(package.dataB != NULL);
   assert(package.dataC != NULL);
 
   int e;
 
   Hint * dataA = package.dataA;
   Hint * dataB = package.dataB;
   Hint * dataC = package.dataC; 
   
 // for (e = 0; e < package.vector_size; e++)       xil_printf("%d %d %d\r\n", dataA[e], dataB[e], dataC[e]);
   
   
//===============================================================================
	//Peripherals instantiation
//===============================================================================
   XTmrCtr mytimer;
   int Status= XTmrCtr_Initialize(&mytimer, XPAR_PERIPHERALS_AXI_TIMER_0_DEVICE_ID);
   if (Status != XST_SUCCESS) {
      xil_printf("Timer initialization failed \r\n");
		return XST_FAILURE;
		}
   XTmrCtr_SetResetValue(&mytimer, 0, 0);
   XTmrCtr_Start(&mytimer,0);
   XTmrCtr_SetResetValue(&mytimer, 1, 0);
   XTmrCtr_Start(&mytimer,1);
   package.timer= &mytimer;
   
   
   
//===============================================================================
	//Creating and joining on thread
//===============================================================================
   hthread_t tid;
   hthread_attr_t attr;
   hthread_attr_init(&attr);   

int i;   
for ( i=0; i <NUM_AVAILABLE_HETERO_CPUS ; i++)
{   
   for (e = 0; e < package.vector_size; e++)
   {
      dataA[e] = rand() %1000;
      dataB[e] = rand()%1000;
      dataC[e] = 10;
   }
   
   XTmrCtr_Reset(&mytimer,0);   

   thread_create ( &tid, &attr , foo_thread_FUNC_ID , (void * )&package, i+2, 0);
   
  
   int ret;
   if( hthread_join(tid, (void *) &ret))
   {
      xil_printf("Error joining child thread\r\n");
      while(1);
   }
   if (ret !=XST_SUCCESS){
      xil_printf("Thread returned XST_FAILURE\r\n");
      while(1);
   }



       int time= XTmrCtr_GetValue(&mytimer,0);
   xil_printf("Total exe_time  on Slave %d : %d us\r\n", i, (time)/100 );
   xil_printf("Net exe_time of the body of the thread: %d us\r\n",  (package.time)/100 );
   

//===============================================================================
	//Check to see if the result were right?
//=============================================================================== 
   for (e = 0; e < 5; e++)        xil_printf("%d %d %d\r\n", dataA[e], dataB[e], dataC[e]);
 
      for (e = 0; e < package.vector_size; e++)
    {
            if (dataC[e]!= dataA[e]+ dataB[e])
            {
                 xil_printf("Error at location %d \r\n", e);
                 while (1);
            }
    
    }
 }  
   
   
   xil_printf("FINISH\r\n");
   return 0;
}
Example #6
0
void Timer_Start(u8 id)
{
	s_log[id].start_time = XTmrCtr_GetValue(&xtmrctr, 0);
}
Example #7
0
void Timer(u8* String)
{
	s_log[counter].time =XTmrCtr_GetValue(&xtmrctr, 0);
	memcpy(s_log[counter++].msg, String, strlen((char*)String));
}