Exemplo n.º 1
0
//! at start enable cache
void cyg_user_start(void){

   
#ifdef USE_CACHE
    printf( "enabling data cache for external ram\n" );
     XCache_EnableDCache( 0xF0000000 );
#else
    printf( "data cache disabled\n" );
    XCache_DisableDCache(  );
#endif   

}
void
enable_caches()
{
#ifdef __PPC__
    XCache_EnableICache(CACHEABLE_REGION_MASK);
    XCache_EnableDCache(CACHEABLE_REGION_MASK);
#elif __MICROBLAZE__
#ifdef XPAR_MICROBLAZE_USE_ICACHE
    microblaze_invalidate_icache();
    microblaze_enable_icache();
#endif
#ifdef XPAR_MICROBLAZE_USE_DCACHE
    microblaze_invalidate_dcache();
    microblaze_enable_dcache();
#endif
#endif
}
Exemplo n.º 3
0
int main (void) {


   XCache_EnableICache(0x80000001);
   XCache_EnableDCache(0x80000000);

   /* Initialize RS232 - Set baudrate and number of stop bits */
   XUartNs550_SetBaud(XPAR_RS232_BASEADDR, XPAR_XUARTNS550_CLOCK_HZ, 9600);
   XUartNs550_mSetLineControlReg(XPAR_RS232_BASEADDR, XUN_LCR_8_DATA_BITS);
   print("-- Entering main() --\r\n");

   /* 
    * MemoryTest routine will not be run for the memory at 
    * 0x81000000 (FLASH_8Mx16)
    * because it is a read-only memory
    */


   /* 
    * MemoryTest routine will not be run for the memory at 
    * 0x00000000 (DDR_SDRAM_1)
    * because it is being used to hold a part of this application program
    */


   /* 
    * MemoryTest routine will not be run for the memory at 
    * 0xfffff000 (plb_bram_if_cntlr_1)
    * because it is being used to hold a part of this application program
    */


   print("-- Exiting main() --\r\n");
   XCache_DisableDCache();
   XCache_DisableICache();
   return 0;
}
Exemplo n.º 4
0
/**
   sample sw thread

    @param data: input data for sw thread
*/
void sampling_sw_thread (cyg_addrword_t data){

  //unsigned int thread_number = (unsigned int) data;
    int from, to;
    int done;
    int i;
    int new_message = FALSE;
    int message = 1;
    int message_to_deliver = FALSE;
    timing_t time_start_s = 0, time_stop_s = 0, time_sampling_sw = 0;
    int number_of_measurements_s = 0;
    
    while (42) {

      // 1) if there is no message to delivered, check for new message
      while (message_to_deliver == FALSE && new_message == FALSE){

            message = (int) cyg_mbox_get( mb_sampling_handle[0] );
            if (message > 0 && message <= number_of_blocks){
 
	      //printf("\n[Sampling Thread No. %d] Nachricht %d erhalten", (int) thread_number, message);
	          new_message = TRUE;
		  time_start_s = gettime();
            }
      }

 #ifdef USE_CACHE  
       XCache_EnableDCache( 0xF0000000 );
#endif     

      // 2) if a new message has arrived, sample the particles
      while (new_message == TRUE){

	  new_message = FALSE;

    	  from = (message - 1) * block_size;
          to   = from + block_size - 1;
          if ((N - 1) < to)
	       to = N - 1; 
      
          // sample particles
          for (i=from; i<=to; i++){
          
                  // predict particle
                  prediction (&particles[i]);
          }

          message_to_deliver = TRUE;
      }

#ifdef USE_CACHE  
       XCache_EnableDCache( 0xF0000000 );
#endif
  
      time_stop_s = gettime();
    
      // 3) if a message should be delivered, deliver it
      while ( message_to_deliver == TRUE){

            done = cyg_mbox_tryput( mb_sampling_done_handle[0], ( void * ) message );
           if (done > 0){
	     //printf("\n[Sampling Thread No. %d] Nachricht %d geschickt", (int) thread_number, message);
              message_to_deliver = FALSE;
              time_sampling_sw = calc_timediff( time_start_s, time_stop_s );
              number_of_measurements_s++;
              //diag_printf("\nSampling SW: %d, \tmessage %d, \ttime: %d", number_of_measurements_s, message, time_sampling_sw);
           }
      }
          
   }
}
Exemplo n.º 5
0
/**
   observation sw thread

    @param data: input data for sw thread
*/
void observation_sw_thread (cyg_addrword_t data){


  //unsigned int thread_number = (unsigned int) data;
    int from, to;
    int done;
    int i;
    int new_message = FALSE;
    int message = 1;
    int message_to_deliver = FALSE;
    int number_of_measurements_o = 0;
    //int sum_of_measurements_o = 0;
    //int average_of_measurements_o = 0;
    timing_t time_start_o = 0, time_stop_o = 0, time_observation_sw = 0;
    
    while (42) {

      // 1) if there is no message to delivered, check for new message
      while (message_to_deliver == FALSE && new_message == FALSE){

            message = (int) cyg_mbox_get( mb_sampling_done_handle[0] );
            if (message > 0 && message <= (N/block_size)){
                 
	          new_message = TRUE;
                  time_start_o = gettime();      
                  //printf("\n[Observation Thread No. %d] Nachricht %d erhalten", (int) thread_number, message);
                  //diag_printf("\n[Observation] Nachricht %d erhalten", message);
            }
      }


      // 2) if a new message has arrived, sample the particles
      new_message = FALSE;

      from = (message - 1) * block_size;
      to   = from + block_size - 1;
      if ((N - 1) < to)
	       to = N - 1; 

#ifdef USE_CACHE  
       XCache_EnableDCache( 0xF0000000 );
#endif

      //printf("\nOBSERVATION");
      
      // extract observations
      for (i=from; i<=to; i++){
          
            extract_observation(&particles[i], &observations[i]);
      }

      message_to_deliver = TRUE;


#ifdef USE_CACHE  
       XCache_EnableDCache( 0xF0000000 );
#endif
  
      time_stop_o = gettime();

      // 3) if a message should be delivered, deliver it
      while ( message_to_deliver == TRUE){

           done = cyg_mbox_tryput( mb_importance_handle[0], ( void * ) message );
              
           if (done > 0){
  
              message_to_deliver = FALSE;
              time_observation_sw = calc_timediff( time_start_o, time_stop_o );
              number_of_measurements_o++;
              //sum_of_measurements_o += time_observation_sw;
              //average_of_measurements_o = sum_of_measurements_o / number_of_measurements_o;
              //diag_printf("\nObservation SW: %d, \tmessage %d, \ttime: %d", 
              //         number_of_measurements_o, (message-1), time_observation_sw);
              //printf("\n[Observation Thread No. %d] Nachricht %d geschickt", (int) thread_number, message);
           }
      }
      
          
   }
}
Exemplo n.º 6
0
int main (void) {


   XCache_EnableICache(0x00000001);
   XCache_EnableDCache(0x00000001);
	
   XCache_DisableDCache();
   XCache_DisableICache();

   xil_printf("\r\n-- Entering main() --\r\n");
	
	/************************ SDRAM SelfTest **************************/
	xil_printf("Performing SelfTest of SDRAM controller...\r\n");
	
	int iteration = 0;
	while(1)
	{
		xil_printf("*Iteration %d\r\n", iteration++);
	int Status;
	int i;
	volatile a;
	volatile b;
	int TotalErrors;
	Xuint8 dcm_psen, dcm_psincdec, dcm_done;
	
	mySDRAMConfig = XMpmc_LookupConfig(XPAR_MPMC_0_DEVICE_ID);
	if(mySDRAMConfig == NULL)
	{
		xil_printf("Could not find SDRAM based on dev id\r\n");
		return XST_FAILURE;
	}
	else {
		xil_printf("Got SDRAM config\r\n");
	}
	Status = XMpmc_CfgInitialize(&mySDRAM,mySDRAMConfig, XPAR_MPMC_0_MPMC_BASEADDR);
	if(Status != XST_SUCCESS) {
		xil_printf("Initialization Failed!\r\n");
		return XST_FAILURE;
	}
	else {
		xil_printf("Initialization Complete!\r\n");
	}
	Status = XMpmc_SelfTest(&mySDRAM);
	if(Status != XST_SUCCESS) {
		xil_printf("SelfTest Failed!\r\n");
		return XST_FAILURE;
	}
	else {
		xil_printf("SelfTest Complete!\r\n");
	}
	
	
	/***************** START CALIBRATION ***************/
	Status = MpmcCalibrationExample(XPAR_MPMC_0_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	/***************** END CALIBRATION *****************/
	
	TotalErrors = MpmcMemTestExample(XPAR_MPMC_0_DEVICE_ID);

	if (TotalErrors) {
		xil_printf("\r\n### Program finished with errors ###\r\n");
	} else {
		xil_printf("\r\n### Program finished successfully ###\r\n");
	}
	
	
	ENABLE_ICACHE();
	ENABLE_DCACHE();
	
	Xuint32 memSize = XPAR_MPMC_0_MPMC_HIGHADDR - XPAR_MPMC_0_MPMC_BASEADDR + 1; //get correct SDRAM size
	Xuint32* myAddress = (Xuint32*)XPAR_MPMC_0_MPMC_BASEADDR;
	
	xil_printf("\r\nStarting Wade's special Test...\r\n");
	char wadeSuccess = RunAllMemoryTests(myAddress, memSize);
	
	if (wadeSuccess){
		xil_printf("Wade's test PASSED!");
	}
	else{
		xil_printf("Wade's test FAILED!");
	}	
	
	xil_printf("Total Errors: %d\r\n", TotalErrors);
	}
}
Exemplo n.º 7
0
/**
    get new measurement
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !!!!!  U S E R    F U N C T I O N  !!!!!
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

*/
void get_new_measurement(void){

		int i, j, k, l;
		int16 re, im;
		
		//unsigned char byte_buffer[1];
		//int counter = 0;
		// fill measurement buffer with next bytes of audio input file

		// (a) shift old values
		//memcpy(&measurement[MEASUREMENT_BUFFER/2], &measurement[0], (MEASUREMENT_BUFFER/2));
		// (b) get new sound data
		//receive_sound_frame(measurement, (MEASUREMENT_BUFFER/2));		
		
		#ifndef STORE_AUDIO
			receive_sound_frame(measurement, MEASUREMENT_BUFFER);
			//printf("\nload next frame");
		#else
			memcpy(measurement, &sound_frames[current_audio_frame*MEASUREMENT_BUFFER], MEASUREMENT_BUFFER);
			current_audio_frame++;
			if (MAX_FRAMES <= current_audio_frame)
			{
				//printf("\nload %d frames", MAX_FRAMES);
				current_audio_frame = 0;
				// load first frames
				for(i=0; i<MAX_FRAMES-1; i++)
				{
					receive_sound_frame(&sound_frames[i*MEASUREMENT_BUFFER],
						MEASUREMENT_BUFFER);		
 				}
			}
		#endif
		memcpy(output, measurement, MEASUREMENT_BUFFER);

		event_found = FALSE;
		// spectral center (sc)
		//complex_number sc, sc_old;
		//sc_old.re = 0; sc_old.im = 0; sc.re = 0; sc.im = 0;

		// find first two beats
		//printf("\ninterval min: %ld ", interval_min);
		//for(i=0;i<NUM_INITIAL_BEATS;i++) printf("\n%d. initial beat: %ld", i, initial_beats[i]);
		if (initial_phase == TRUE )
		{
			//printf("\ninitial phase");
			int16 samples[OBSERVATION_LENGTH];
			//observation obs;
			complex_number obs[OBSERVATION_LENGTH];

			int max_amplitude = 0, max_frequency = 0, current_amplitude;
			int max_amplitude_total = 0, max_frequency_total = 0;
			int16 max_sample_value = 0, max_sample_value_total = 0;
			long int position = 0;

			event_found = FALSE;

			// check current measurement frame
			for (i=0; i<MEASUREMENT_BUFFER/(OBSERVATION_LENGTH); i++)
			{

				memcpy(samples, &measurement[i*OBSERVATION_LENGTH], (OBSERVATION_LENGTH*sizeof(int16)));

				//change Little Endian <-> Big Endian
				max_sample_value = 0;
				for (j=0; j<OBSERVATION_LENGTH; j++)
				{
					samples[j] = ntohl(samples[j]);
					if (ABS(samples[j]) > max_sample_value)
					{
						max_sample_value = ABS(samples[j]);
					}
				}

				for (j=0; j<OBSERVATION_LENGTH; j++)
				{
					obs[j].re = 111;
					obs[j].im = 222;				
				}

				#ifdef USE_CACHE
					XCache_EnableDCache( 0xF0000000 );
				#endif 

				// fft
				//fft_analysis_try (samples, OBSERVATION_LENGTH, obs, sample_rate);
				// -a: send message: sample address (input)
				while (cyg_mbox_tryput( *mb_fft_start_handle, (void *) samples ) == 0)
				{
				}

				// -b: send message: observations address (output)
				while (cyg_mbox_tryput( *mb_fft_start_handle, (void *) obs ) == 0)
				{
				}

				// -c: receive message (fft done)
				while (cyg_mbox_get( *mb_fft_done_handle ) == 0)
				{
				}

				#ifdef USE_CACHE
					XCache_EnableDCache( 0xF0000000 );
				#endif

				
				// find spectral center (sc)
				/*sc.re = 32000; sc.im = 32000; 
				for (j=1;j<((OBSERVATION_LENGTH/2)-1);j++)
				{
				}*/

 

				// max amplitude, frequency
				//for (j=0; j<OBSERVATION_LENGTH; j++)
				/*printf("\n\nSAMPLES\n");
				for (j=0; j<OBSERVATION_LENGTH; j++)
				{
					printf("\n%d", samples[j]);
				}

				printf("\n\nFFT RESULTS\n");*/
				for (j=0; j<OBSERVATION_LENGTH; j++)
				{

					
					// i. calculate current amplitude
					re = (int16) obs[j].re;
					im = (int16) obs[j].im;
					current_amplitude = (re*re) + (im*im);
					current_amplitude = sqrt(current_amplitude);

					// ii. max amplitude
					if (current_amplitude > max_amplitude)
					{

						max_amplitude = current_amplitude;
						// calculate max frequency
						max_frequency = j*(sample_rate/2);
						max_frequency /= (OBSERVATION_LENGTH);
					}
					//printf("\n%d", current_amplitude);
				}

				//printf("\nmax frequency %d, \tmax amplitude: %d", max_frequency, max_amplitude);

				// likelihood for 'beat' (frequency > 100 => amplitude)
				if (max_frequency>100 && max_frequency<5000 && max_amplitude_total<max_amplitude)//<5000
				{
					max_amplitude_total = max_amplitude;
					max_frequency_total = max_frequency;
					max_sample_value_total = max_sample_value;
					position = interval_min + i*OBSERVATION_LENGTH - (OBSERVATION_LENGTH/2);
				}
			}

			//printf("\n!!!!!!!max frequency %d, \tmax amplitude: %d", max_frequency_total, max_amplitude_total);

			// analyse if event was found
			if (max_frequency_total>100 && max_amplitude_total>50 && 
				max_frequency_total<5000 && max_sample_value_total>5000){

				//printf("\nEVENT FOUND at position %ld", position);
				event_found = TRUE;
				event_position = position;
				event_salience = max_amplitude_total;
			}

			// init particle filter if needed;
			
			if (event_found == TRUE) // new beat
			{

				int beat_ind = 0;
				while (initial_beats[beat_ind]>0 && beat_ind<(NUM_INITIAL_BEATS-1))
				{
					beat_ind++;
				}	
				
				// 'beat_ind' is the current initial beat
				initial_beats[beat_ind] = event_position;
				if ((beat_ind>0 && initial_beats[beat_ind] - initial_beats[beat_ind-1] < bytespersecond/5))
				{
					event_found = FALSE;
					initial_beats[beat_ind] = 0;
					return;
				}
				//printf("\n%d. beat at position: %ld", beat_ind, event_position);

				// if last initial beat found: extract hypothesises
				if (beat_ind == (NUM_INITIAL_BEATS-1))
				{					

					// if last initial beat => initialize particles with extracted hypothesis
					// number of possibilities to create hypothesis for beats 
					// mathematical reasoning to calcualate the number of possibilities
					int num_hypothesis = (NUM_INITIAL_BEATS*NUM_INITIAL_BEATS)
						- (((NUM_INITIAL_BEATS+1)*NUM_INITIAL_BEATS)/2);

					// generic algorithm to calcualte all possibilities for tempo hypothesises
					// i: current initial beat
					// j: other initial beats before current initial beat
					// k: current hypothesis [0,...,num_hypothesis-1]
					// l: current particle position: (N/num_hypothesis) particles per hypothesis
					k = 0;
					for (i=NUM_INITIAL_BEATS-1; i>=0;i--)
					{
						
						for (j=i-1; j>=0;j--)
						{

							for(l=(k*N)/num_hypothesis; l<MIN((((k+1)*N)/num_hypothesis),N);l++)
							{
								// init particle according to hypothesis
								particles[l].tempo = (int)initial_beats[i] 
									- initial_beats[j];
								if((5*particles[l].tempo)<bytespersecond)
								{
									//printf("\ndifference short, set to default value");
									particles[l].tempo = bytespersecond/5;
								}
								particles[l].last_beat = initial_beats[i];
								particles[l].next_beat = initial_beats[i] 
									+ particles[l].tempo;
								particles[l].w		= 100;
								particles[l].likelihood	= 100;
							}
							//printf("\n%d. hypothesis: tempo = %d,\tlast beat: %ld", 
							//	(k+1),(int)(initial_beats[i]-initial_beats[j]),
							//	initial_beats[i]);
							k++;
						}
					}		
				}

				/*if (first_beat_pos <= 0)
				{
				
					first_beat_pos = event_position;
					printf("\n1st beat at position: %ld", first_beat_pos);

				}
				else
				{
				
					if (second_beat_pos <= 0 && (event_position - first_beat_pos > (bytespersecond/5)))
					{
	
						second_beat_pos = event_position;
						printf("\n2nd beat at position: %ld (init particles, tempo: %ld)", 
							second_beat_pos, (second_beat_pos -
							first_beat_pos));
						
						// init particles
						for (i=0; i<N; i++)
						{

							particles[i].tempo = second_beat_pos - first_beat_pos;	
							particles[i].last_beat = second_beat_pos;
							particles[i].next_beat = second_beat_pos 
									+ particles[i].tempo;
							particles[i].last_event_time	= second_beat_pos;
							particles[i].w			= PF_GRANULARITY/N;
							particles[i].likelihood		= 100;
						}
					}
				}*/
				//last_event_found = TRUE;
			}
			/*else
			{
				last_event_found = FALSE;
			}*/

		}

		//int16 sample_value = 0;
	
		// make short-time Fourier transformation for the incoming sound data
		/*fft_analysis (measurement, (MEASUREMENT_BUFFER/2), fft_window, sample_rate);
		// real, and imaginary component

		// debug: find max frequency
		double amplitude_max = 0; int max_freq = 0;
		for(i = 0; i < (sample_rate/(2*FREQUENCY_HOPPING)); i++){

			if (amplitude_max < fft_window[i]){

				max_freq  = i*FREQUENCY_HOPPING;
				amplitude_max = fft_window[i];
			}
		}

		event_found = FALSE;
		// extract events
		if (max_freq > 100 && amplitude_max > 60){
			//if (last_event_found == FALSE){

				printf("\nevent found!!!!!!!!!!!");
				// event found
				event_found = TRUE;
				event_position = interval_min + (MEASUREMENT_BUFFER/4);
				event_salience = amplitude_max;
			//}
		} 
		else
		{
			
			last_event_found = FALSE;
		}


		// init particle filter if needed;
		if (first_beat_pos <= 0 || second_beat_pos <= 0 ){ // init still needed

			
			if (event_found == TRUE && last_event_found == FALSE){ // new beat

				if (first_beat_pos <= 0){
				
					first_beat_pos = event_position;
					printf("\n1st beat at position: %d", (int)(first_beat_pos/10000));

				} else {
				
					if (second_beat_pos <= 0){
	
						second_beat_pos = event_position;
						printf("\n2nd beat at position: %d (init particles, tempo: %d)", 
							(int)(second_beat_pos/10000), (int)((second_beat_pos -
							first_beat_pos)/10000));
						// init particles
						for (i=0; i<N; i++){

							particles[i].tempo		= second_beat_pos - first_beat_pos;
							particles[i].last_beat 		= second_beat_pos;
							particles[i].next_beat 		= second_beat_pos 
									+ particles[i].tempo;
							particles[i].last_event_time	= second_beat_pos;
							particles[i].w			= PF_GRANULARITY/N;
							particles[i].likelihood		= 100;
						}
					}
				}
			}
		}

		if (event_found == TRUE) {last_event_found = TRUE; }
		*/

 		// calculate 'energy' in buffer
		//int16 output_value = max_ind;
		//for(i = 0; i < MEASUREMENT_BUFFER/2; i++) memcpy(&output[2*i], &output_value, 2);

		/*
		// debug: print sample values to screen
		for(i = 0; i < MEASUREMENT_BUFFER/2; i++){
			
			double result = fft_window[i];
			memcpy(&sample_value, &measurement[2*i], 2);
			if (interval_min > bytespersecond && interval_min < bytespersecond+1000)
				printf("\n%f", 1.0*sample_value);
			//if (i>0) result *= 8;
			if (result > 32767){printf("\nFFT value to high ( < 32768), but it is %f", result); result = 32767;}
			if (result<-32768){printf("\nFFT value to high ( >= -32768), but it is %f", result); result=-32768;}
			sample_value = (signed short int)result;
			//printf("\n sample value: %d", sample_value);
			//memcpy(&measurement[2*i], &sample_value, 2);			
			//printf("\nA[%d] = %d", i, sample_value]);
		}*/


		// TRY START: CHANGE CHANGE CHANGE
		/*event_found = FALSE;
		long int energy = 0;
		char current_sample[2];

		// calculate 'energy' in buffer
		int16 max_value = 0;

		for (i=0; i<MEASUREMENT_BUFFER/2; i++){
	
			current_sample[1] = measurement[(2*i) + 1]; 
			current_sample[0] = measurement[(i*2)];
			memcpy(&sample_value, current_sample, 2);

			if (ABS(sample_value) > max_value) max_value = ABS(sample_value);

			energy += (sample_value * sample_value);			
		}

		max_amplitude = max_value;

		// adjust energy change
		long int value = sqrt(sqrt(energy-last_energy));// / 2;
                //long int value = (energy-last_energy)/80000;
		sample_value = value;

		if (value > 32767){

			sample_value = 32768;
			printf("\nenergy change too high (%d > 32767)", value);
		} else if (value < -32768) {

			sample_value = -32768;
			printf("\nenergy change too high (%d < -32768)", value);
		}

		if (max_value < 15000 || sample_value == 0) {

			sample_value = 0;
			last_event_found = FALSE;
			//energy = 0;
		} else {

			if (last_event_found == FALSE){

				event_found = TRUE;
				last_event_found = TRUE;
				event_position = interval_min + (MEASUREMENT_BUFFER/2);
				event_salience = ABS(sample_value);
			
				//printf("\nEvent found: position = %d, salience = %d", event_position, event_salience);
                         }
			
		}

		last_energy = energy;*/

		// debug: write energy into file
		/*for (i=0; i<MEASUREMENT_BUFFER/2; i++){
		
			memcpy(current_sample, &sample_value, 2);
			measurement[(2*i) + 1] = current_sample[0]; 
			measurement[(i*2)] = current_sample[1];
		}*/

		// TRY TRY TRY
		//fft_calc(measurement, MEASUREMENT_BUFFER/2);

		// TRY END: CHANGE CHANGE CHANGE

		/*
		char current_sample[2];
		int16 sample_value;
		long int left_max = 0, right_max=0; int s;
		event_found = FALSE;

		// calcualte left sum
		for (s=0; s<MEASUREMENT_BUFFER/4; s++){
		
			current_sample[0] = measurement[(2*s) + 1]; 
			current_sample[1] = measurement[(2*s)];
			memcpy(&sample_value, current_sample, 2);
			
			if (ABS(sample_value) > left_max)
				
				left_max = ABS(sample_value);
		}

		// calculate right sum
		for (s=MEASUREMENT_BUFFER/4; s<MEASUREMENT_BUFFER/2; s++){
		
			current_sample[0] = measurement[(2*s) + 1]; 
			current_sample[1] = measurement[(2*s)];
			memcpy(&sample_value, current_sample, 2);
			
			if (ABS(sample_value) > right_max)
				
				right_max = ABS(sample_value);
		}
		
		if ((left_max > 0) && (((4.0 * right_max) / (1.0 * left_max)) > 4.5) && ((right_max + left_max) > 40000)){
			event_found = TRUE;
			event_position = interval_min + (MEASUREMENT_BUFFER/2);
			if (left_max > 0)
				event_salience = (4*right_max) / left_max;
			else
				event_salience = 2;
			
			printf("\nEvent found: position = %d, salience = %d", event_position, event_salience);
		}
		

	}*/

	//for (i=0; i<MEASUREMENT_BUFFER; i++) fwrite(&measurement[i],1,(BUFFSIZE-1),outputstream);

}
Exemplo n.º 8
0
int main( int argc, char *argv[] )
{

    unsigned int i, start_count = 0, done_count = 0;
    timing_t t_start = 0, t_stop = 0, t_gen = 0, t_sort = 0, t_merge =
        0, t_check = 0;
    unsigned int *addr;
    unsigned int dummy;
    int retval;

    printf( "-------------------------------------------------------\n"
            "ReconOS hardware multithreading case study (sort)\n"
            "(c) Computer Engineering Group, University of Paderborn\n\n"
            "eCos/POSIX, multi-threaded hardware version (" __FILE__ ")\n"
            "Compiled on " __DATE__ ", " __TIME__ ".\n"
            "-------------------------------------------------------\n\n" );

#ifdef USE_CACHE
    printf( "enabling data cache for external ram\n" );
    XCache_EnableDCache( 0x80000000 );
#else
    printf( "data cache disabled\n" );
    XCache_DisableDCache(  );
#endif

    data = buf_a;

    //----------------------------------
    //-- GENERATE DATA
    //----------------------------------
    printf( "Generating data..." );
    t_start = gettime(  );
    generate_data( data, SIZE );
    t_stop = gettime(  );
    t_gen = calc_timediff_ms( t_start, t_stop );
    printf( "done\n" );

#ifdef USE_CACHE
    // flush cache contents - the hardware can only read from main memory
    // TODO: storing could be more efficient
    printf( "Flushing cache..." );
    XCache_EnableDCache( 0x80000000 );
    printf( "done\n" );
#endif

    //----------------------------------
    //-- SORT DATA
    //----------------------------------
    // create mail boxes for 'start' and 'complete' messages
    mb_start_attr.mq_flags   = mb_done_attr.mq_flags   = 0;
    mb_start_attr.mq_maxmsg  = mb_done_attr.mq_maxmsg  = 10;
    mb_start_attr.mq_msgsize = mb_done_attr.mq_msgsize = 4;
    mb_start_attr.mq_curmsgs = mb_done_attr.mq_curmsgs = 0;

    // unlink mailboxes, if they exist
    retval = mq_unlink("/mb_start");
    if (retval != 0 && errno != ENOENT) {    // we don't care if it doesn't exist
        diag_printf("unable to unlink mb_start");
    }
    retval = mq_unlink("/mb_done");
    if (retval != 0 && errno != ENOENT) {    // we don't care if it doesn't exist
        diag_printf("unable to unlink mb_done");
    }

    // open/create mailboxes
    mb_start = mq_open("/mb_start",
            O_RDWR | O_CREAT, S_IRWXU | S_IRWXG,
            &mb_start_attr);
    if (mb_start == (mqd_t)-1) {
        diag_printf("unable to create mb_start");
    }
    mb_done = mq_open("/mb_done",
            O_RDWR | O_CREAT, S_IRWXU | S_IRWXG,
            &mb_done_attr);
    if (mb_done == (mqd_t)-1) {
        diag_printf("unable to create mb_done");
    }

    // create sorting sowftware threads
    for ( i = 0; i < MT_HW_NUM_SW_THREADS; i++ ) {
        pthread_attr_init(&thread_sorter_attr[i]);
        pthread_create(&thread_sorter[i],
                &thread_sorter_attr[i],
                sort8k_entry_posix, (void*)i);
    }

    // create sorting hardware thread
    pthread_attr_init(&hwthread_sorter_attr);
    pthread_attr_setstacksize(&hwthread_sorter_attr, STACK_SIZE);
    rthread_attr_init(&hwthread_sorter_hwattr);
    rthread_attr_setslotnum(&hwthread_sorter_hwattr, 0);
    rthread_attr_setresources(&hwthread_sorter_hwattr, hwthread_sorter_resources, 2);
    rthread_create(&hwthread_sorter, &hwthread_sorter_attr, &hwthread_sorter_hwattr, (void*)0);

    printf( "Sorting data..." );
    i = 0;

    t_start = gettime(  );

    // put 9 messages into mb_start
    while ( start_count < 9 ) {
        addr = &data[i];
        if ( mq_send( mb_start, ( void * ) &addr, sizeof(addr), 0 ) == 0 ) {
            start_count++;
            i += N;
        } else {                                                          
            perror("while sending to mq_send");
            break;
        }
    }

    t_stop = gettime(  );
    t_sort += calc_timediff_ms( t_start, t_stop );

    while ( done_count < SIZE / N ) {
        t_start = gettime(  );
        // if we have something to distribute,
        // put one into the start mailbox
        if ( start_count < SIZE / N ) {
            addr = &data[i];
            if ( mq_send( mb_start, ( void * ) &addr, sizeof(addr), 0 ) == 0 ) {
                start_count++;
                i += N;
            } else {                                                          
                perror("while sending to mq_send");
                break;
            }
        }
        // see whether anybody's done
        if ( mq_receive( mb_done, (void*)&dummy, sizeof(dummy), 0 ) == sizeof(dummy) ) {
            done_count++;
        } else {
            perror( "while receiving from mq_done" );
            break;
        }
        t_stop = gettime(  );
        t_sort += calc_timediff_ms( t_start, t_stop );
    }
    printf( "done\n" );

#ifdef USE_CACHE
    // flush cache contents
    // TODO: invalidating would suffice
    printf( "Flushing cache..." );
    XCache_EnableDCache( 0x80000000 );
    printf( "done\n" );
#endif


    //----------------------------------
    //-- MERGE DATA
    //----------------------------------
    printf( "Merging data..." );
    t_start = gettime(  );
    data = recursive_merge( data, buf_b, SIZE, N, simple_merge );
    t_stop = gettime(  );
    t_merge = calc_timediff_ms( t_start, t_stop );
    printf( "done\n" );

    //----------------------------------
    //-- CHECK DATA
    //----------------------------------
    printf( "Checking sorted data..." );
    t_start = gettime(  );
    if ( check_data( data, SIZE ) != 0 )
        printf( "CHECK FAILED!\n" );
    else
        printf( "check successful.\n" );
    t_stop = gettime(  );
    t_check = calc_timediff_ms( t_start, t_stop );

    printf( "\nRunning times (size: %d words):\n"
            "\tGenerate data: %d ms\n"
            "\tSort data    : %d ms\n"
            "\tMerge data   : %d ms\n"
            "\tCheck data   : %d ms\n"
            "\nTotal computation time (sort & merge): %d ms\n",
            SIZE, t_gen, t_sort, t_merge, t_check, t_sort + t_merge );


    return 0;

}
Exemplo n.º 9
0
void enable_caches()
{
    XCache_EnableICache(0x80000000);
    XCache_EnableDCache(0x80000000);
}
Exemplo n.º 10
0
/**
*
* This function gets the calibration value.
*
* @param	InstancePtr is a pointer to an XMpmc instance to be worked on.
*
* @return	XST_SUCCESS if the DCM Phase shift decrement is completed
*		else XST_FAILURE.
*
* @note		None.
*
*****************************************************************************/
int MpmcGetCalibrate(XMpmc *InstancePtr, u32 MemoryStartAddr,
			MpmcCalibReturnValue *CalibStatus)
{
	int Count;
	MpmcCalibValue LocalCalibValue;
	int ValidCount;
	u32 RegValue;
	u8 Toggle = 0;
	u32 Status;

	LocalCalibValue.FoundValid = FALSE;
	RegValue = MPMC_RDEN_DELAY_MIN_VAL;

	/*
	 * Get the initial value from the register.
	 */
	LocalCalibValue.OrigTapValue = XMpmc_GetStaticPhyReg(InstancePtr) &
						XMPMC_SPIR_DCM_TAP_VALUE_MASK;
	if (LocalCalibValue.OrigTapValue > MPMC_MAX_TAPS) {
		LocalCalibValue.OrigTapValue =
				LocalCalibValue.OrigTapValue - 0x100;
	}

	/*
	 * Try to find valid calibration settings.
	 */
	while (LocalCalibValue.FoundValid == FALSE) {

		LocalCalibValue.MinValue = MPMC_MAX_TAPS - 1;
		LocalCalibValue.MaxValue = MPMC_MIN_TAPS + 1;

		/*
		 * Reset DCM to minimum value
		 */
		Status = MpmcResetDcmPhaseShift(InstancePtr);
		if (Status != XST_SUCCESS) {
			return XST_FAILURE;
		}


		/*
		 * Read the memory and check that data versus the expected
		 * value.
		 *
		 * If the value matches, read the current calibration value.
		 * Repeat this to ensure that this is not on a transition.
		 * If the value is incorrect in any of these increments, the
		 * value must be re-established.
		 *
		 * If the value at 0 does match then we are probably in a case
		 * where the window is a wrap case.  This means that we are
		 * looking for the upper bound not the lower bound.
		 */
		ValidCount = 0;
		for (Count = MPMC_MIN_TAPS; Count < MPMC_MAX_TAPS; Count++) {

			MpmcWriteTestPattern(MemoryStartAddr, Toggle);


			if (MpmcCheckPattern(MemoryStartAddr, Toggle) !=
						XST_SUCCESS) {

				/*
				 * Found invalid calibration setting.
				 */
				if (ValidCount > MPMC_EDGE_TAPS) {
					LocalCalibValue.MaxValue = Count;
				}
				ValidCount = 0;
			} else {

				/*
				 * Found valid calibration setting
				 * Check to make sure that cache reads work.
				 */

#ifdef __MICROBLAZE__
#if XPAR_MICROBLAZE_0_USE_DCACHE
				/*
				 * Initialize and Enable the data cache.
				 */
				microblaze_init_dcache_range(0,
					XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);
				microblaze_enable_dcache();
#endif
#endif

#ifdef __PPC__
				/*
				 * Enable the Dcache for all memory regions
				 * except the boot region of the PPC.
				 */
				XCache_InvalidateDCacheLine(MemoryStartAddr);
				XCache_EnableDCache(0xFFFFFFFE);

#endif
				Status = MpmcCheckPattern(MemoryStartAddr,
								Toggle);

				/*
				 * Disable and reinitialize the data cache.
				 */
#ifdef __MICROBLAZE__
#if XPAR_MICROBLAZE_0_USE_DCACHE
				microblaze_disable_dcache();
				microblaze_init_dcache_range(0,
					XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);
#endif
#endif

#ifdef __PPC__
				XCache_DisableDCache();
				XCache_InvalidateDCacheLine(MemoryStartAddr);
#endif


				if (Status != XST_SUCCESS) {
					/*
					 * Found invalid calibration setting
					 */
					if (ValidCount > MPMC_EDGE_TAPS) {
						LocalCalibValue.MaxValue =
								Count;
					}
					ValidCount = 0;
				} else {
					/*
					 * Found valid calibration setting
					 */
					if (ValidCount == MPMC_EDGE_TAPS) {
						LocalCalibValue.MinValue =
							Count - MPMC_EDGE_TAPS;
						LocalCalibValue.MaxValue =
									Count;
					}
					else if (ValidCount > MPMC_EDGE_TAPS) {
						LocalCalibValue.MaxValue =
									Count;
					}
					ValidCount++;
					if (ValidCount>MPMC_EDGE_TAPS) {
						LocalCalibValue.FoundValid =
								TRUE;
					}
				}
			}

			Status = MpmcIncDcmPhaseShift(InstancePtr, RegValue);
			if (Status != XST_SUCCESS) {
				return XST_FAILURE;
			}

			if (Toggle == 0) {
				Toggle = 1;
			} else {
				Toggle = 0;
			}
		}

		if ((LocalCalibValue.FoundValid == FALSE) &&
			(((RegValue & XMPMC_SPIR_RDEN_DELAY_MASK)
					!= MPMC_RDEN_DELAY_MAX_VAL) ||
			((RegValue & XMPMC_SPIR_RDDATA_CLK_SEL_MASK) !=
					XMPMC_SPIR_RDDATA_CLK_SEL_MASK) ||
			((RegValue & XMPMC_SPIR_RDDATA_SWAP_RISE_MASK) !=
					XMPMC_SPIR_RDDATA_SWAP_RISE_MASK))){
			if ((RegValue & XMPMC_SPIR_RDEN_DELAY_MASK) !=
					MPMC_RDEN_DELAY_MAX_VAL) {
				RegValue = RegValue + MPMC_RDEN_DELAY_INC;
			}
			else if ((RegValue & XMPMC_SPIR_RDDATA_CLK_SEL_MASK) !=
					XMPMC_SPIR_RDDATA_CLK_SEL_MASK) {
				RegValue =
					(RegValue |
					XMPMC_SPIR_RDEN_DELAY_MASK) -
					XMPMC_SPIR_RDEN_DELAY_MASK +
					MPMC_RDEN_DELAY_MIN_VAL +
					XMPMC_SPIR_RDDATA_CLK_SEL_MASK;
			}
			else if ((RegValue & XMPMC_SPIR_RDDATA_SWAP_RISE_MASK)
			!=
					XMPMC_SPIR_RDDATA_SWAP_RISE_MASK) {
				RegValue =
					(RegValue |
					XMPMC_SPIR_RDEN_DELAY_MASK) -
					XMPMC_SPIR_RDEN_DELAY_MASK +
					MPMC_RDEN_DELAY_MIN_VAL -
					XMPMC_SPIR_RDDATA_CLK_SEL_MASK +
					XMPMC_SPIR_RDDATA_SWAP_RISE_MASK;
			}
		} else if (LocalCalibValue.FoundValid == FALSE) {
			xil_printf("\r\n ERROR: Could not calibrate.\r\n");
				return XST_FAILURE;
		}
	}

	CalibStatus->FoundValid = LocalCalibValue.FoundValid;
	CalibStatus->MinValue = LocalCalibValue.MinValue;
	CalibStatus->MaxValue = LocalCalibValue.MaxValue;
	CalibStatus->RegValue = RegValue;

	if (LocalCalibValue.MaxValue >= LocalCalibValue.MinValue) {
		CalibStatus->CalibTapValue = (LocalCalibValue.MinValue +
						LocalCalibValue.MaxValue)/2;
	} else {
		CalibStatus->CalibTapValue = (LocalCalibValue.MinValue +
					LocalCalibValue.MaxValue +
					MPMC_NUMBER_TAPS)/2;

		if (CalibStatus->CalibTapValue > MPMC_MAX_TAPS) {
			CalibStatus->CalibTapValue =
				(CalibStatus->CalibTapValue - MPMC_NUMBER_TAPS);
		}
	}

	return XST_SUCCESS;
}
Exemplo n.º 11
0
int main( int argc, char *argv[] )
{

    unsigned int i, start_count = 0, done_count = 0, j;
    timing_t t_start = 0, t_stop = 0, t_gen = 0, t_sort = 0, t_merge =
                                       0, t_check = 0, t_tmp;

    printf( "-------------------------------------------------------\n"
            "ReconOS hardware multithreading case study (sort)\n"
            "(c) Computer Engineering Group, University of Paderborn\n\n"
            "eCos, single-threaded hardware version (" __FILE__ ")\n"
            "Compiled on " __DATE__ ", " __TIME__ ".\n"
            "-------------------------------------------------------\n\n" );

#ifdef USE_CACHE
    printf( "enabling data cache for external ram\n" );
    XCache_EnableDCache( 0x80000000 );
#else
    printf( "data cache disabled\n" );
    XCache_DisableDCache(  );
#endif

    data = buf_a;

    //----------------------------------
    //-- GENERATE DATA
    //----------------------------------
    printf( "Generating data..." );
    t_start = gettime(  );
    generate_data( data, SIZE );
    t_stop = gettime(  );
    t_gen = calc_timediff_ms( t_start, t_stop );
    printf( "done\n" );

#ifdef USE_CACHE
    // flush cache contents - the hardware can only read from main memory
    // TODO: storing could be more efficient
    printf( "Flushing cache..." );
    XCache_EnableDCache( 0x80000000 );
    printf( "done\n" );
#endif

    //----------------------------------
    //-- SORT DATA
    //----------------------------------
    // create mail boxes for 'start' and 'complete' messages
    cyg_mbox_create( &mb_start_handle, &mb_start );
    cyg_mbox_create( &mb_done_handle, &mb_done );
    // create sorting thread
    reconos_hwthread_create( 16,                                               // priority
                             0,                                                // entry data (not needed)
                             "MT_HW_SORT",                                     // thread name
                             hwthread_sorter_stack,                            // stack
                             STACK_SIZE,                                       // stack size
                             &hwthread_sorter_handle,                          // thread handle
                             &hwthread_sorter,                                 // thread object
                             (void*)UPBHWR_OSIF_0_BASEADDR,
                             XPAR_OPB_INTC_0_OSIF_0_INTERRUPT_INTR+1,
                             //                         ( void * ) XPAR_PLB_RECONOS_SLOT_0_BASEADDR,      // base address
                             //                         XPAR_OPB_INTC_0_PLB_RECONOS_SLOT_0_INTERRUPT_INTR + 1,     // interrupt
                             hwthread_sorter_resources,                        // resource array
                             2,                                                 // number of resources
                             0xFFFFFFFF, 0xFFFFFFFF
                           );
    cyg_thread_resume( hwthread_sorter_handle );

    printf( "Sorting data..." );
    i = 0;
    while ( done_count < SIZE / N ) {
        t_start = gettime(  );
        // if we have something to distribute,
        // put as many as possile into the start mailbox
        while ( start_count < SIZE / N ) {
            if ( cyg_mbox_tryput( mb_start_handle, ( void * ) &data[i] ) ==
                    true ) {
                start_count++;
                i += N;
            } else {                                                           // mailbox full
                break;
            }
        }
        t_stop = gettime(  );
        t_sort += calc_timediff_ms( t_start, t_stop );
        // see whether anybody's done
        t_start = gettime(  );
        if ( ( t_tmp = ( timing_t ) cyg_mbox_get( mb_done_handle ) ) != 0 ) {
            done_count++;
        } else {
            printf( "cyg_mbox_get returned NULL!\n" );
        }
        t_stop = gettime(  );
        t_sort += calc_timediff_ms( t_start, t_stop );
    }
    printf( "done\n" );


#ifdef USE_CACHE
    // flush cache contents
    // TODO: invalidating would suffice
    printf( "Flushing cache..." );
    XCache_EnableDCache( 0x80000000 );
    printf( "done\n" );
#endif


    //----------------------------------
    //-- MERGE DATA
    //----------------------------------
    printf( "Merging data..." );
    t_start = gettime(  );
    data = recursive_merge( data, buf_b, SIZE, N, simple_merge );
    t_stop = gettime(  );
    t_merge = calc_timediff_ms( t_start, t_stop );
    printf( "done\n" );

    //----------------------------------
    //-- CHECK DATA
    //----------------------------------
    printf( "Checking sorted data..." );
    t_start = gettime(  );
    if ( check_data( data, SIZE ) != 0 )
        printf( "CHECK FAILED!\n" );
    else
        printf( "check successful.\n" );
    t_stop = gettime(  );
    t_check = calc_timediff_ms( t_start, t_stop );

    printf( "\nRunning times (size: %d words):\n"
            "\tGenerate data: %d ms\n"
            "\tSort data    : %d ms\n"
            "\tMerge data   : %d ms\n"
            "\tCheck data   : %d ms\n"
            "\nTotal computation time (sort & merge): %d ms\n",
            SIZE, t_gen, t_sort, t_merge, t_check, t_sort + t_merge );


    return 0;

}
Exemplo n.º 12
0
/******************************************************************************
* Name:        main
* Description: Program entry point
* 
* Returns:     int   - returns 0 if no errors
******************************************************************************/
int main() {

   /* declare a network interface and network addresses */
   struct netif *netif, server_netif;  
   struct ip_addr ipaddr, netmask, gw;

   /* specify a unique MAC address for the board */
   #ifdef XPAR_CPU_PPC440_CORE_CLOCK_FREQ_HZ    /* set MAC on ML507 board */
   unsigned char mac_ethernet_address[] = {0x00, 0x0a, 0x35, 0x01, 0xC9, 0x76};
   #else                                        /* set MAC on ML410 board */
   unsigned char mac_ethernet_address[] = {0x00, 0x0a, 0x35, 0x01, 0x9A, 0xFE};
   #endif

   /* set the network interface pointer */
   netif = &server_netif;

   /* enable caches */
   XCache_EnableICache( INSTR_CACHE );
   XCache_EnableDCache( DATA_CACHE );

   /* setup interrupts */
   setup_interrupts();

   /* initliaze network addresses to be used */
   IP4_ADDR( &ipaddr,  192, 168,  1, 15 );
   IP4_ADDR( &netmask, 255, 255, 255, 0 );
   IP4_ADDR( &gw,      192, 168,  1,  1 );

   /* print the application header and IP settings */
   print_app_header();
   print_ip_settings(&ipaddr, &netmask, &gw);

   /* initialize lwip */
   lwip_init();

   /* add network interface to the netif_list, and set it as default */
   if( !xemac_add( netif, &ipaddr, &netmask, &gw,
                   mac_ethernet_address, EMAC_BASEADDR ) ) {
      xil_printf( "Error adding N/W interface\n\r" );
      return -1;
   }
   netif_set_default( netif );

   /* now enable interrupts */
   enable_interrupts();

   /* specify that the network if is up */
   netif_set_up( netif );

   /* start the application */
   start_application();
   
   /* print debug header if debug mode set */
   #ifdef QMFIR_DEBUG
   debug_menu();
	while( 1) {
		qmfir_debug();
	}
   #endif   

   /* receive and process packets */
   while( 1 ) {
      xemacif_input( netif );
   }

   /* disable caches */
   XCache_DisableDCache();
   XCache_DisableICache();

   return 0;

} /* main */
Exemplo n.º 13
0
int main (void) {


   XCache_EnableICache(0x80000001);
   XCache_EnableDCache(0x80000001);

   /* Initialize RS232 - Set baudrate and number of stop bits */
   XUartNs550_SetBaud(XPAR_RS232_BASEADDR, XPAR_XUARTNS550_CLOCK_HZ, 9600);
   XUartNs550_mSetLineControlReg(XPAR_RS232_BASEADDR, XUN_LCR_8_DATA_BITS);
   print("-- Entering main() --\r\n");

   /* 
    * MemoryTest routine will not be run for the memory at 
    * 0xffff0000 (xps_bram_if_cntlr_1)
    * because it is being used to hold a part of this application program
    */


   /* 
    * MemoryTest routine will not be run for the memory at 
    * 0x86000000 (FLASH_8Mx16)
    * because it is a read-only memory
    */


   /* Testing Memory (DDR2_SDRAM_16Mx32)*/
   {
      XStatus status;

      print("Starting MemoryTest for DDR2_SDRAM_16Mx32:\r\n");
      print("  Running 32-bit test...");
      status = XUtil_MemoryTest32((Xuint32*)XPAR_DDR2_SDRAM_16MX32_MEM_BASEADDR, 1024, 0xAAAA5555, XUT_ALLMEMTESTS);
      if (status == XST_SUCCESS) {
         print("PASSED!\r\n");
      }
      else {
         print("FAILED!\r\n");
      }
      print("  Running 16-bit test...");
      status = XUtil_MemoryTest16((Xuint16*)XPAR_DDR2_SDRAM_16MX32_MEM_BASEADDR, 2048, 0xAA55, XUT_ALLMEMTESTS);
      if (status == XST_SUCCESS) {
         print("PASSED!\r\n");
      }
      else {
         print("FAILED!\r\n");
      }
      print("  Running 8-bit test...");
      status = XUtil_MemoryTest8((Xuint8*)XPAR_DDR2_SDRAM_16MX32_MEM_BASEADDR, 4096, 0xA5, XUT_ALLMEMTESTS);
      if (status == XST_SUCCESS) {
         print("PASSED!\r\n");
      }
      else {
         print("FAILED!\r\n");
      }
   }

   print("-- Exiting main() --\r\n");
   XCache_DisableDCache();
   XCache_DisableICache();
   return 0;
}
Exemplo n.º 14
0
/**
   preResampling sw thread. Waits for all importance_done messages, normalizes the particle weights,
   calls iteration_done function and finally sends messages to the resampling message box.
*/
void preResampling_thread (cyg_addrword_t data){

  int message = 1;
  int i, done;
  int message_delivered = FALSE;
  int * messages = (int *) malloc(sizeof(int)*(number_of_blocks));
  //int * messages = (int *) malloc(sizeof(int)*N);
  timing_t time_start = 0, time_stop = 0, time_particle_filter = 0;
  int number_of_measurements = 0;
  timing_t t_start = 0, t_stop = 0, t_result_1 = 0, t_result;

  for (i=0; i<number_of_blocks; i++){
     
       messages[i] = FALSE;
  }


  while (42){

      // 1) check, if all messages are received to message box
      //    If this is not true, get the next message
      while (!all_messages_received(messages, number_of_blocks) ){

          message = (int) cyg_mbox_get( mb_importance_done_handle[0] );

          if (message > 0){
  
              messages[message-1] = TRUE;
	  }
      }
      //printf("\n[Resampling Switch] alle Nachrichten erhalten");

      t_start = gettime();

      // set messages back to 'not received'
      for (i=0; i<number_of_blocks; i++){
     
           messages[i] = FALSE;
      }

#ifdef USE_CACHE
      XCache_EnableDCache( 0xF0000000 );
#endif


#ifdef OBSERVATION_DEBUG             
            // debug: check, if observation is correct
            i = 0;     
            observation * obs1 = &observations[i];
            observation obs2;
            extract_observation(&particles[i], &obs2);            

            if (obs1->no_tracking_needed != obs2.no_tracking_needed)
            {
                  diag_printf("\nparticle[%d] \tno_tracking_needed - hw=%d sw=%d", 
                          i, obs1->no_tracking_needed, obs2.no_tracking_needed);
                  diag_printf("\nparticle[%d] \told_likelihood - hw=%d sw=%d", 
                          i, obs1->old_likelihood, obs2.old_likelihood);
            } 
            else if (obs1->no_tracking_needed == FALSE)
            {
                  int j;
                  for(j=0;j<OBSERVATION_LENGTH;j++)
                  {
                       if ((ABS(obs2.fft[j].re-obs1->fft[j].re)>1)||(ABS(obs2.fft[j].im-obs1->fft[j].im)>1))
                       {
                             diag_printf("\nobservation[%d].fft[%d].re - hw=%d sw=%d",
                                i,j,(int)obs1->fft[j].re,(int)obs2.fft[j].re);
                             diag_printf("\nobservation[%d].fft[%d].im - hw=%d sw=%d",
                                i,j,(int)obs1->fft[j].im,(int)obs2.fft[j].im);
                       }                  
                  }
            }
            // debug end
#endif


#ifdef IMPORTANCE_DEBUG2
      // TODO: remove debug
      // debug: check if likelihood is calculated correctly
      int sw_likelihood, difference;
      for (i=0; i<N; i++){
          
          if (observations[i].no_tracking_needed == FALSE) {
		//printf("\nreceived hw results. get sw results");
                sw_likelihood = likelihood(&particles[i], &observations[i], NULL);
                // difference between likelihood calculated in sw and likelihood calculated in hw
                difference = particles[i].w - sw_likelihood;
                //if (difference > 1 || difference < -1) 
                diag_printf("\nlikelihood[%d]: sw = %d; hw = %d", i, sw_likelihood, particles[i].w);
         }
      }  
      // debug end
      if (particles[i].w <= 0) particles[i].w = 1;
#endif

      // 2) calls iteration_done user function
      iteration_done(particles, observations, ref_data, N);

      // 3) normalize particle weights 
      normalize_particle_weights();

      t_stop = gettime();
      t_result_1 = calc_timediff(t_start, t_stop);
      //printf("\nNormalize weights + iteration done: %d", t_result_1);;

      // calculate time for one particle filter loop
      time_stop = gettime();
      time_particle_filter = calc_timediff( time_start, time_stop );
      if (number_of_measurements > 0)
	 //printf("\n%d \t%d", number_of_measurements, time_particle_filter);
         printf("\n%d", time_particle_filter);
	 //diag_printf("\n%d \t%d", number_of_measurements, time_particle_filter);
      time_start = gettime();
      number_of_measurements++;

      t_start = gettime();
      

      // 4) calculate Resampling Function U
      calculate_resampling_function();

      t_stop = gettime();
      t_result = calc_timediff(t_start, t_stop);
      t_result += t_result_1;
      //printf("\nPreresampling: %d", t_result);


#ifdef USE_CACHE 
       XCache_EnableDCache( 0xF0000000 );
#endif
   
      

      // 5) send all messages to sw/hw message box
      for (message=1; message<=number_of_blocks; message++){

           
	   message_delivered = FALSE;
	   while (message_delivered == FALSE){

		done = cyg_mbox_tryput( mb_resampling_handle[0], ( void * ) message );

	     if (done > 0){
	         //diag_printf("\n[Resampling Switch] Nachricht %d an Reampling weitergeleitet", message);
                  message_delivered = TRUE;   
             }
	      
	  }
      } 
          
      //printf("\n[Sampling Switch] alle Nachrichten geschickt");   
  }
} 
Exemplo n.º 15
0
///
/// Application entry function. Sets up data strctures and threads.
///
void cyg_user_start()
{
    struct udp_connection *con;
//    cyg_sem_t *sem_array[8];
    reconos_res_t sem_array_laplace[8];
    reconos_res_t sem_array_display[8];
    int i;

#if defined(USE_DCACHE)
    // enable caches for DRAM
    XCache_EnableDCache(0x80000000);
#endif

    diag_printf("Hello embedded world!\n"
                "This is " __FILE__ " (ReconOS), built " __DATE__ ", "
                __TIME__ "\n");

    // initialize hardware
    diag_printf("Initializing hardware...\n");
    init();

    // initialize image buffers
    diag_printf("Initializing image buffers...\n");
    for (i = 0; i < 2; i++) {
		byte_buffer_init(&input_buffer[i], WIDTH, HEIGHT);                            // one image + four lines (???)
		byte_buffer_fill(&input_buffer[i], 0);
		byte_buffer_init(&laplace_buffer[i], WIDTH, HEIGHT);                          // one image
		byte_buffer_fill(&laplace_buffer[i], 0);
    }

    // initialize fake output image buffer
    output_buffer[0].width = WIDTH;                                               // irrelevant
    output_buffer[0].height = HEIGHT;                                             // irrelevant
    output_buffer[0].data = fb_info.fb;                                           // this points to the VGA frame buffer
    // NOTE: the semaphores of this buffer are not used and therefore not initialized

    diag_printf
        ("Buffer addresses: input: 0x%08X, laplace: 0x%08X, output: 0x%08X\n",
         input_buffer[0].data, laplace_buffer[0].data, output_buffer[0].data);

    // set up UDP connection        
    diag_printf("Setting up UDP networking...\n");
    con = udp_connection_create(inet_addr("192.168.1.2"));

    // initialize thread info structures
    diag_printf("Initializing thread info structures...\n");
    buffer_thread_info_init(&input_thread_info, 2,  NULL, input_buffer);/*, NULL,
                            &laplace_rdy, NULL, &input_new);*/
    buffer_thread_info_init(&laplace_thread_info, 2, input_buffer,
                            laplace_buffer);/*, &laplace_rdy, &display_rdy,
                            &input_new, &laplace_new);*/
    buffer_thread_info_init(&display_thread_info, 2, laplace_buffer,
                            output_buffer);/*, &display_rdy, NULL,
                            &laplace_new, NULL);*/

    // initialize semaphores        
/*    diag_printf("Initializing semaphores...\n");
    cyg_semaphore_init(&input_new, 0);
    cyg_semaphore_init(&laplace_rdy, 1);
    cyg_semaphore_init(&laplace_new, 0);
    cyg_semaphore_init(&display_rdy, 1);*/

    // pass connection info to input thread 
    input_thread_info.data = (cyg_addrword_t) con;

    diag_printf("Creating threads...");

    // create input thread
    diag_printf("input...");
    cyg_thread_create(16,                                                      // scheduling info (eg pri)  
                      entry_buffer_recv,                                       // entry point function     
                      (cyg_addrword_t) & input_thread_info,                    // entry data                
                      "INPUT THREAD",                                          // optional thread name      
                      input_stack,                                             // stack base                
                      MYTHREAD_STACK_SIZE,                                     // stack size,       
                      &input_handle,                                           // returned thread handle    
                      &input_thread                                            // put thread here           
        );

#if !defined(USE_HW_LAPLACE)
    // create laplace software thread
    diag_printf("laplace_sw...");
    cyg_thread_create(16,                                                      // scheduling info (eg pri)  
                      entry_buffer_laplace,                                    // entry point function      
                      (cyg_addrword_t) & laplace_thread_info,                  // entry data
                      "LAPLACE THREAD (SW)",                                   // optional thread name     
                      laplace_stack,                                           // stack base               
                      MYTHREAD_STACK_SIZE,                                     // stack size,      
                      &laplace_handle,                                         // returned thread handle 
                      &laplace_thread                                          // put thread here       
        );
#else
    // create laplace hardware thread
    diag_printf("laplace_hw...");
    fill_sem_array(sem_array_laplace, &laplace_thread_info);
    rthread_attr_init(&laplace_hwthread_attr);
    rthread_attr_setslotnum(&laplace_hwthread_attr, 0);
    rthread_attr_setresources(&laplace_hwthread_attr, sem_array_laplace, 8);
    reconos_hwthread_create(16,                                                // scheduling info (eg pri)  
                            &laplace_hwthread_attr,                            // hw thread attributes
                            shm_init(&laplace_thread_info),                    // init data
                            "LAPLACE_THREAD (HW)",                             // optional thread name      
                            laplace_stack,                                     // stack base                
                            MYTHREAD_STACK_SIZE,                               // stack size,           
                            &laplace_handle,                                   // returned thread handle    
                            &laplace_hwthread);                                // put thread here       
#endif

#if !defined(USE_HW_DISPLAY)
    // create display software thread
    diag_printf("display_sw...");
    cyg_thread_create(16,                                                      // scheduling info (eg pri)  
                      entry_buffer_display,                                    // entry point function     
                      (cyg_addrword_t) & display_thread_info,                  // entry data
                      "DISPLAY THREAD",                                        // optional thread name      
                      display_stack,                                           // stack base               
                      MYTHREAD_STACK_SIZE,                                     // stack size,       
                      &display_handle,                                         // returned thread handle
                      &display_thread                                          // put thread here       
        );
#else
    // create display hardware thread
    diag_printf("display_hw...");
    fill_sem_array(sem_array_display, &display_thread_info);
    rthread_attr_init(&display_hwthread_attr);
    rthread_attr_setslotnum(&display_hwthread_attr, 0);
    rthread_attr_setresources(&display_hwthread_attr, sem_array_display, 8);
    reconos_hwthread_create(16,                                                // scheduling info (eg pri)  
                            &display_hwthread_attr,                            // hw thread attributes
                            shm_init(&display_thread_info),                    // init data
                            "DISPLAY_THREAD (HW)",                             // optional thread name      
                            display_stack,                                     // stack base                
                            MYTHREAD_STACK_SIZE,                               // stack size,           
                            &display_handle,                                   // returned thread handle    
                            &display_hwthread,                                 // put thread here       
                            (void *) XPAR_PLB_RECONOS_SLOT_1_BASEADDR, XPAR_OPB_INTC_0_PLB_RECONOS_SLOT_1_INTERRUPT_INTR + 1,   // associated interrupt vector
                            shm_init(&display_thread_info), SHM_SIZE,
                            sem_array, 8);
#endif

    diag_printf("\nStarting threads...\n");

    cyg_thread_resume(input_handle);
    cyg_thread_resume(laplace_handle);
    cyg_thread_resume(display_handle);

    diag_printf("end of main()\n");

}