Esempio n. 1
0
int main()
{
  msg_t *m = (msg_t *) 0x4000;
  uint64_t d64;
  uint32_t d32;
  uint16_t d16;
  uint8_t  d8;
  unsigned int dt;
  void *da, *dua, *dc;
  for (unsigned int row = 0; row < E_ROWS; row++) {
    for (unsigned int col = 0; col < E_COLS; col++) {
      if (row == 0 && col == 0) continue;
      unsigned int tcore = row * E_COLS + col;

      da = e_get_global_address(row, col, (void *) MEM_ALINEADA);
      dua = e_get_global_address(row, col, (void *) MEM_NO_ALINEADA);
      dc = e_get_global_address(row, col, (void *) MEM_A_CABALLO);

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d64, da, sizeof(d64));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].t64 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d32, da, sizeof(d32));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].t32 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d16, da, sizeof(d16));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].t16 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d8, da, sizeof(d8));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].t8 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d64, dua, sizeof(d64));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].ua64 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d32, dua, sizeof(d32));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].ua32 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d16, dua, sizeof(d16));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].ua16 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d8, dua, sizeof(d8));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].ua8 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d64, dua, sizeof(d64));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].c64 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d32, dc, sizeof(d32));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].c32 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d16, dc, sizeof(d16));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].c16 = (dt - DUMMY_WAIT) / (double) VECES;

      e_dma_wait(E_DMA_1);
      e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
      e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
      for (int i = 0; i < VECES; i++)
        e_dma_copy(&d8, dc, sizeof(d8));
      e_dma_wait(E_DMA_1);
      e_wait(E_CTIMER_1, DUMMY_WAIT);
      e_ctimer_stop(E_CTIMER_0);
      dt = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);
      m->ticks[tcore].c8 = (dt - DUMMY_WAIT) / (double) VECES;
    }
  }
  m->finalizado = E_TRUE;

  return 0;
}
Esempio n. 2
0
void main(){

 e_ctimer_set(E_CTIMER_0, E_CTIMER_CLK, E_CTIMER_MAX); 
 e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);

	init();

	// wait for the go (which means actors are connected)
	while(Mailbox.pGo[me.corenum] == 0);


timerValue = e_ctimer_get(E_CTIMER_0);
Mailbox.pTimer0[me.corenum] = E_CTIMER_MAX - timerValue;
e_ctimer_stop(E_CTIMER_0);

  // Timer functions 1
  e_ctimer_set(E_CTIMER_1, E_CTIMER_CLK, E_CTIMER_MAX);
  e_ctimer_start(E_CTIMER_1, E_CTIMER_CLK);

	int j = 0;	
	int signed_counter = 0;

	// Run until there is no input left
	while(j < IN_BUFFER_SIZE)
	{
		//action read_signed
		if(clip.count < 0){

			//clip.sflag = port_read(&SIGNED);
			clip.sflag = Mailbox.pSignedBuffer[signed_counter++];
			clip.count = 63;
		} // end of action read_signed
		else { // action limit


			int i = port_read(&I);	


			if(i > 255){
#if 0
			  port_write(&O, 255); j++;
#endif

#if 1
Mailbox.pOutputBuffer[j] = 255; j++;
#endif
// j++;
			}
			else if(clip.sflag == 0 && i < 0){
#if 0
			  port_write(&O, 0); j++;
#endif

#if 1
Mailbox.pOutputBuffer[j] = 0; j++;
#endif
//j++;
			}
			else if(i < -255){
#if 0
			  port_write(&O, -255); j++;
#endif

#if 1
Mailbox.pOutputBuffer[j] = -255; j++;
#endif
//j++;
			}
			else{
#if 0
			  port_write(&O, i); j++;
#endif

#if 1
Mailbox.pOutputBuffer[j] = i; j++;
#endif
//j++;
			}

			clip.count = clip.count - 1;	
		}
		
	}

	timerValue = e_ctimer_get(E_CTIMER_1);
	Mailbox.pTimer1[me.corenum] = E_CTIMER_MAX - timerValue;
#if 1
	*Mailbox.pOutputReady = 1;
#endif
	
	e_ctimer_stop(E_CTIMER_1);
}
Esempio n. 3
0
static uint64_t platform_clock(void)
{
    static mach_timebase_info_data_t tb_info = {
        .numer = 0,
        .denom = 0,
    };
    uint64_t abs_time, nanosec;

    abs_time = mach_absolute_time();
    if (tb_info.denom == 0) {
        (void) mach_timebase_info(&tb_info);
    }
    nanosec = abs_time;
    nanosec /= tb_info.denom;
    nanosec *= tb_info.numer;

    return nanosec;
}
#elif defined(HAVE_E_LIB_H)
static uint64_t platform_clock(void)
{
    // Assuming 600MHz clock 10^9 / (600 * 10^6)
    const float factor = 1.6666666666666666666f;

    static uint64_t clock = 0;
    uint64_t diff, nanosec;

    static bool initialized = false;

    if (!initialized) {
        e_ctimer_stop(E_CTIMER_0);
        e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
        e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
        initialized = true;
        return 0;
    }

    /* Clock will drift here */
    diff = E_CTIMER_MAX - e_ctimer_get(E_CTIMER_0);

    e_ctimer_stop(E_CTIMER_0);
    e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX);
    e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);

    clock += diff;

    nanosec = (uint64_t) ((float) clock * factor);

    return nanosec;
}
#else
#error "No timing function"
#endif

static void platform_print_duration(uint64_t start,
                                    uint64_t end)
{
    if (end < start)
        bench_printf("%" PRIu64, 0xffffffffffffffffUL);
    else
        bench_printf("%" PRIu64, end - start);
}

/* end of platform specific section */

struct item_data
{
    uint64_t start;
    uint64_t end;
};
int main(void)
{
	e_coreid_t coreid;
	unsigned int i;
	unsigned int num;
	unsigned int time_p;
	unsigned int time_c;
	unsigned int time_compare;
	float volatile af;
	float volatile bf;
	float volatile cf;
	float volatile df;
	float ref;	
	unsigned int temp;

	float volatile in_sin;
	float volatile in_cos;
	float volatile in_sqt;
	float volatile in_ceil;
	float volatile in_log;
	float re_f0, re_f1, re_f2, re_f3, re_f4, re_f5;

	af = 3.5f;
	bf = 2.8f;	
	cf = 8.0f;
	df = 3.0f;
	in_sin = (float) pi;
	in_sin = in_sin / 6 ;
	in_cos = (float) pi;
	in_cos = in_cos / 3 ;
	in_sqt = 0.25f;
	in_ceil = 2.5f;
	in_log = 100.0f;

	// Who am I? Query the CoreID from hardware.
	coreid = e_get_coreid();
	sprintf(outbuf, "");

	// Get time waste on functions
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);
	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
	time_compare = time_p - time_c ;

	// Addition
	// E_CTIMER0
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);
		
		ref = bf + af ;

	
	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if (!((ref > 6.299f)&&(ref < 6.301f)))
	{
		sprintf(outbuf, "\n Addition is wrong!\n");
	}else
	{
		sprintf(outbuf , "\nE_CTIMER0: The clock cycle of addition is %d.\n", temp);
	}
	
	// Subtraction
	// E_CTIMER0
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);
		
		ref =  af - bf;

	
	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if ( !((ref > 0.699f)&&(ref < 0.701f)))
	{
		sprintf(outbuf+strlen(outbuf), "\n Subtraction is wrong!\n");
	}else
	{
		sprintf(outbuf+strlen(outbuf) , "\n E_CTIMER0: The clock cycle of subtraction is %d.\n", temp);
	}

	// Mul
	//E_CTIMER0
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);
		
		ref = af * bf;
	
	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;


	if (!((ref > 9.799f)&&(ref < 9.801f)))
	{
		sprintf(outbuf+strlen(outbuf), "\n Multiplication is wrong!\n");
	}else
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of multiplication is %d.\n", temp);
	}

	// Div
	//E_CTIMER0
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);
	
		ref = ( af / bf);
	
	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if (!((ref > 1.2499f)&&(ref < 1.2501f)))
	{
		sprintf(outbuf+strlen(outbuf), "\n Division is wrong!\n");
	}else
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of division is %d.\n", temp);
	}

	// Mod
	// E_CTIMER0
	e_ctimer_set(E_CTIMER_0,  E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);
	
		ref = fmodf(cf,df);

	
	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if (!((ref > 1.99f)&&(ref < 2.01f)))
	{
		sprintf(outbuf+strlen(outbuf), "\n Mod is wrong!\n");
	}else
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of mod is %d.\n", temp);
	}
	
	// Sin
	// E_CTIMER0
	e_ctimer_set(E_CTIMER_0,  E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);	
		 
	re_f0 = sinf(in_sin);

	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if ( (re_f0 > 0.499) && (re_f0 < 0.501) )
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of sin is %d.\n", temp);		
	}else
	{
		sprintf(outbuf+strlen(outbuf), "\n Sin is wrong!\n");
	}
	
	// Cos
	// E_CTIMER0
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);	
		 
	re_f1 = cosf(in_cos);

	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;
	
	if (  (re_f1 > 0.499) && (re_f1 < 0.501))
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of cos is %d.\n", temp);
	}else
	{
		sprintf(outbuf+strlen(outbuf), "\n Cos is wrong!\n");
	}
	

	// Sqrt
	e_ctimer_set(E_CTIMER_0,  E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);	
		 
	re_f2 = sqrtf(in_sqt);

	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if ( (re_f2 > 0.499) && (re_f2 < 0.501) )
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of sqrt is %d.\n", temp);		
	}else
	{
		sprintf(outbuf+strlen(outbuf), "\n Sqrt is wrong!\n");
	}
	
	// Ceil
	e_ctimer_set(E_CTIMER_0,  E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);	
		 
	re_f3 = ceilf(in_ceil);

	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if ( (re_f3 > 2.99) && (re_f3 < 3.01) )
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of ceil is %d.\n", temp);		
	}else
	{
		sprintf(outbuf+strlen(outbuf), "\n Ceil is wrong!\n");
	}

	// Floor
	e_ctimer_set(E_CTIMER_0,  E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);	
		 
	re_f5 = floorf(in_ceil);

	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if ( (re_f5 > 1.99f) && (re_f5 < 2.01f)  )
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of floor is %d.\n", temp);
	}else
	{
		sprintf(outbuf+strlen(outbuf), "\n Floor is wrong!\n");
	}
	

	// Log10
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);	
		 
	re_f4 = log10f(in_log);

	time_c = e_ctimer_get(E_CTIMER_0);
	e_ctimer_stop(E_CTIMER_0);
			
	temp = time_p - time_c - time_compare;

	if ( (re_f4 > 1.99f) && (re_f4 < 2.01f) )
	{
		sprintf(outbuf+strlen(outbuf) , "\nE_CTIMER0: The clock cycle of log10 is %d.\n", temp);
	}else
	{
		sprintf(outbuf+strlen(outbuf), "\n Log10 is wrong!\n");
	}

	
	return EXIT_SUCCESS;

}
Esempio n. 5
0
void main()
{

// Configure the timers
 e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX); 

 // Start the timer (countdown from 0xFFFFFFFF)
 e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);

	init();
	int i = 0;
	int a, b;
	int w0, w1;

	// Wait until we get the go message from the host
	while(Mailbox.pGo[me.corenum] == 0); 

timerValue = e_ctimer_get(E_CTIMER_0);
 Mailbox.pTimer0[me.corenum] = E_CTIMER_MAX - timerValue;
e_ctimer_stop(E_CTIMER_0);

e_ctimer_set(E_CTIMER_1, E_CTIMER_MAX); 
e_ctimer_start(E_CTIMER_1, E_CTIMER_CLK);

	while(i < (IN_BUFFER_SIZE * 2))
	{
		w0 = ww0;
		w1 = ww1;

		index0 = (index0 + 1) & 3;

		ww0 = W0[index0];
		ww1 = W1[index0];

		a = port_read(&X);
		b = port_read(&X);

#if 1
		port_write(&Y, a * w0); i++;
		port_write(&Y, a * w1); i++;
		port_write(&Y, b * w0); i++;
		port_write(&Y, b * w1); i++;
#endif

#if 0
		Mailbox.pOutputBuffer[i] = a * w0; i++;
		Mailbox.pOutputBuffer[i] = a * w1; i++;
		Mailbox.pOutputBuffer[i] = b * w0; i++;
		Mailbox.pOutputBuffer[i] = b * w1; i++;
#endif

	}

#if 0
*Mailbox.pOutputReady = 8;
#endif

// Get timer value, find the elapsed time and stop 
timerValue = e_ctimer_get(E_CTIMER_1);
Mailbox.pTimer1[me.corenum] = E_CTIMER_MAX - timerValue;
e_ctimer_stop(E_CTIMER_1);
}
Esempio n. 6
0
static uint32_t get_clock(void) {
	return ((uint32_t) (E_CTIMER_MAX-e_ctimer_get(E_CTIMER_0)));
}
int main(void)
{
	unsigned time_c, time_p;
	unsigned time;
	unsigned tran,k,i,j,q,h,m,n;
	unsigned *box;
	unsigned *n_row, *n_col, *p;
	unsigned *neighbour_n;
	unsigned *neighbour_s;
	unsigned *neighbour_w;
	unsigned *neighbour_e;
	unsigned *master;
	
	// Define the mailbox
	master = (unsigned *)0x2000;
	box = (unsigned *) 0x5000;
	n_row = (unsigned *)0x6000;
	n_col = (unsigned *)0x6004;
	tran = 2048;
	p =(unsigned *) 0x2000;

	// Get the neighbour global address
	e_neighbor_id(E_NEXT_CORE, E_ROW_WRAP, n_row, n_col);
	neighbour_e = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;
	
	e_neighbor_id(E_PREV_CORE, E_ROW_WRAP, n_row, n_col);
	neighbour_w = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;
	
	e_neighbor_id(E_NEXT_CORE, E_COL_WRAP, n_row, n_col);
	neighbour_s = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;
	
	e_neighbor_id(E_PREV_CORE, E_COL_WRAP, n_row, n_col);
	neighbour_n = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;	
	
	// Test the writing bandwidth	
	// Initialize master and slave
	for(i=0; i<tran; i++)
	{
		master[i] = 0xdeadbeef;
		neighbour_e[i] = 0x00000000;
		neighbour_w[i] = 0x00000000;
		neighbour_s[i] = 0x00000000;
		neighbour_n[i] = 0x00000000;
	}
			
	
	// Set the ctimer
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	
	// Start the ctimer and select the time type
	time_p = e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	
	// Write to all neighbour cores
	e_dma_copy(neighbour_e, master, 0x2000);	
	e_dma_copy(neighbour_w, master, 0x2000);
	e_dma_copy(neighbour_s, master, 0x2000);
	e_dma_copy(neighbour_n, master, 0x2000);
		
	// Get the time now
	time_c = e_ctimer_get(E_CTIMER_0);	
		
	time = time_p - time_c;
		
	// Output the result
	box[0] = time;	

	// Test the reading bandwidth
	// Initialize master and slave
	for(i=0; i<tran; i++)
	{
		master[i] = 0x00000000;
		neighbour_e[i] = 0xdeadbee1;
		neighbour_w[i] = 0xdeadbee2;
		neighbour_s[i] = 0xdeadbee3;
		neighbour_n[i] = 0xdeadbee4;
	}
			
	
	// Set the ctimer
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	
	// Start the ctimer and select the time type
	time_p = e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	
	// Read from all neighbour cores
	e_dma_copy(master, neighbour_e, 0x2000);	
	e_dma_copy(master, neighbour_w, 0x2000);
	e_dma_copy(master, neighbour_s, 0x2000);
	e_dma_copy(master, neighbour_n, 0x2000);
		
	// Get the time now
	time_c = e_ctimer_get(E_CTIMER_0);	
		
	time = time_p - time_c;
		
	// Output the result
	box[1] = time;	
	return 0;
}
int main(void)
{
    unsigned mesh_reg;
    unsigned mesh_reg_modify;
    unsigned time_c, time_p;
    unsigned time;
    unsigned time_c1, time_p1;
    unsigned time1;
    unsigned i,j,q,m,n,k;
    unsigned *commander;
    unsigned *counter;
    unsigned *mailbox,*mode;
    unsigned *n_row, *n_col;
    unsigned *neighbour0, *neighbour1, *neighbour2, *neighbour3, *p;

    commander = (unsigned *)0x5100;
    counter = (unsigned *)0x5300;
    mailbox = (unsigned *)0x6000;
    mode = (unsigned *)0x5400;
    n_row = (unsigned *)0x5008;
    n_col = (unsigned *)0x500c;
    p = (unsigned *)0x5100;

    // Broadcast to neighbours
    e_neighbor_id(E_PREV_CORE, E_ROW_WRAP, n_row, n_col);
    neighbour0 = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;

    e_neighbor_id(E_NEXT_CORE, E_ROW_WRAP, n_row, n_col);
    neighbour1 = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;

    e_neighbor_id(E_PREV_CORE, E_COL_WRAP, n_row, n_col);
    neighbour2 = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;

    e_neighbor_id(E_NEXT_CORE, E_COL_WRAP, n_row, n_col);
    neighbour3 = (unsigned *) e_get_global_address(*n_row, *n_col, p) ;

    // Get core information
    k = e_group_config.core_row * e_group_config.group_cols + e_group_config.core_col;

    while(1)
    {
        // Clear the counter of finishing transfering
        for(m=0; m<(e_group_config.group_rows*e_group_config.group_cols); m++)
        {
            counter[m] = 0;
        }

        // Initialize the commander and counter
        counter[k] = 1;

        //Clear the mode box
        mode[0] = 0xdeadbeef;

        // Clear the start commander
        commander[0] = 0x00000000;

        // Wait for the mesh event
        while(mode[0] == 0xdeadbeef)
        {};

        q = mode[0];

        mesh_reg = e_reg_read(E_REG_MESH_CONFIG);
        mesh_reg_modify = mesh_reg & 0xffffff0f;
        mesh_reg_modify = mesh_reg_modify |mesh_type[1][q];
        e_reg_write(E_REG_MESH_CONFIG, mesh_reg_modify);

        // Set the ctimer
        e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;

        // Waiting for the signal to start transfering
        while(commander[0] != 0xdeadbeef)
        {};

        // Start the ctimer and select the time type
        time_p = e_ctimer_start(E_CTIMER_0, E_CTIMER_MESH_0);

        // Broadcast to all the other neighbours
        neighbour0[0] = 0xdeadbeef;
        neighbour1[0] = 0xdeadbeef;
        neighbour2[0] = 0xdeadbeef;
        neighbour3[0] = 0xdeadbeef;


        while((counter[0]&counter[1]&counter[2]&counter[3]&counter[4]&counter[5]&counter[6]
                &counter[7]&counter[8]&counter[9]&counter[10]&counter[11]&counter[12]&counter[13]
                &counter[14]&counter[15]) == 0) {};

        time_c = e_ctimer_get(E_CTIMER_0);

        time = time_p - time_c;
        mailbox[(*mode)] = time;

        // Load the original value to E_REG_MESH_CONFIG system register
        e_reg_write(E_REG_MESH_CONFIG, mesh_reg);

        if(mode[0] == 12)
        {
            break;
        }
    }
    return 0;
}
Esempio n. 9
0
void main(){

// Configure the timers
 e_ctimer_set(E_CTIMER_0, E_CTIMER_CLK, E_CTIMER_MAX); 

 // Start the timer (countdown from 0xFFFFFFFF)
 e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);

	init();

	int i = 0;

	// wait for the go (which means actors are connected)
	while(Mailbox.pGo[me.corenum] == 0);

timerValue = e_ctimer_get(E_CTIMER_0);
Mailbox.pTimer0[me.corenum] = E_CTIMER_MAX - timerValue;
e_ctimer_stop(E_CTIMER_0);

e_ctimer_set(E_CTIMER_1, E_CTIMER_CLK, E_CTIMER_MAX); 
e_ctimer_start(E_CTIMER_1, E_CTIMER_CLK);

	while(i < IN_BUFFER_SIZE)
	{
		int a, b, c, d, x2, x3, x4, x5, x6h, x6l, x7h, x7l;

		// action a0
		a = port_read(&X);
		b = port_read(&X);
		c = port_read(&X);
		d = port_read(&X);

		x4 = c;
		x5 = d;
#if 1
		port_write(&Y, a); i++;
		port_write(&Y, b); i++;
		// end of action a0
#endif

#if 0
		//DEBUG
		Mailbox.pOutputBuffer[i] = a; i++;
		Mailbox.pOutputBuffer[i] = b; i++;

#endif
		// action a1
		x2 = port_read(&X);
		a = port_read(&X);
		x3 = port_read(&X);
		b = port_read(&X);
	
		int ah = a >> 8;
		int bh = b >> 8;
		int al = a & 255;
		int bl = b & 255;

		x6h = 181 * (ah + bh);
		x7h = 181 * (ah - bh);
		x6l = 181 * (al + bl) + 128;
		x7l = 181 * (al - bl) + 128;

#if 1
		port_write(&Y, x2); i++;	
		port_write(&Y, x3); i++;
		// end of action a1
#endif

#if 0
		//DEBUG
		Mailbox.pOutputBuffer[i] = x2; i++;
		Mailbox.pOutputBuffer[i] = x3; i++;

#endif

#if 1
		// action a2
		port_write(&Y, x4); i++;
		port_write(&Y, x5); i++;
		port_write(&Y, x6h + (x6l >> 8)); i++;
		port_write(&Y, x7h + (x7l >> 8)); i++;

		// end of action a2
#endif

#if 0
		//DEBUG
		Mailbox.pOutputBuffer[i] = x4; i++;
		Mailbox.pOutputBuffer[i] = x5; i++;
		Mailbox.pOutputBuffer[i] = x6h + (x6l >> 8); i++;
		Mailbox.pOutputBuffer[i] = x7h + (x7l >> 8); i++;

#endif
	}

// Get timer value, find the elapsed time and stop 
timerValue = e_ctimer_get(E_CTIMER_1);
Mailbox.pTimer1[me.corenum] = E_CTIMER_MAX - timerValue;
e_ctimer_stop(E_CTIMER_1);
}