Пример #1
0
//! The main function
int main(int argc, char *argv[])
{
  unsigned int cycle_count;
  volatile  dsp32_t fft32_max;

    // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

    // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

    // Get the actual cycle count
  cycle_count = Get_sys_count();
    // Perform a 64-point complex FFT
  dsp32_trans_realcomplexfft(vect1, vect2, NLOG);
  // Perform the absolute value of a complex vector
  dsp32_vect_complex_abs(fft_real, vect1, SIZE);
  // Retrieves the maximum of a vector
  fft32_max = dsp32_vect_max(fft_real, SIZE);

    // Calculate the number of cycles the FFT took
  cycle_count = Get_sys_count() - cycle_count;

    // Print the number of cycles
  dsp32_debug_printf("Cycle count: %d\n", cycle_count);
    // Print the complex FFT output signal
  dsp32_debug_print_complex_vect(vect1, SIZE);

  while(1);
}
Пример #2
0
//! The main function
int main(int argc, char *argv[])
{
  unsigned int cycle_count;

  // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

  // Get the actual cycle count
  cycle_count = Get_sys_count();

  // Perform a convolution
  dsp32_vect_conv(vect1, vect2, VECT2_SIZE, vect3, VECT3_SIZE);

  // Calculate the number of cycles
  cycle_count = Get_sys_count() - cycle_count;

  // Print the number of cycles
  dsp32_debug_printf("Cycle count: %d\n", cycle_count);
  // Print the  output signal
  dsp32_debug_print_vect(vect1, VECT2_SIZE + VECT3_SIZE - 1);

  while(1);
}
u64 TIME_MEASURING_GetTime (void)
{
static u32 CycelCounter_u32;
static u32 LastTime_u32;
static u32 TimeErrors_u32 = 0;
u32 NewTime_u32;
u32 NewTime1_u32;

    NewTime_u32 = Get_sys_count ();

    if (NewTime_u32 < LastTime_u32)
    {
        NewTime1_u32 = Get_sys_count ();
        if (NewTime1_u32 < LastTime_u32)
        {
            CycelCounter_u32++;
        }
        else
        {
            NewTime_u32 = NewTime1_u32;
            TimeErrors_u32++;   // A CPU bug ?
        }
    }

    LastTime_u32 = NewTime_u32;
    return ((u64) ((u64) CycelCounter_u32 << 32) + (u64) NewTime_u32);
}
Пример #4
0
//! The main function
int main(int argc, char *argv[])
{
  unsigned int cycle_count;

  // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

  // Get the actual cycle count
  cycle_count = Get_sys_count();

  // Perform a 25-taps FIR
  dsp16_filt_iirpart(vect1, vect2, SIZE, num, NUM_SIZE, den, DEN_SIZE, 0, 0);

  // Calculate the number of cycles
  cycle_count = Get_sys_count() - cycle_count;

  // Print the number of cycles
  dsp16_debug_printf("Cycle count: %d\n", cycle_count);

  // Print the  output signal
  dsp16_debug_print_vect(vect1, SIZE - NUM_SIZE + 1);

  while(1);
}
Пример #5
0
//! The main function
int main(int argc, char *argv[])
{
  A_ALIGNED static dsp16_t s_input[N/NB_CUTS];
  int f;
  dsp_resampling_t *resampling;
  dsp16_t *output;
  U32 temp;
  dsp16_resampling_options_t options;

  // Initialize options
  memset(&options, 0, sizeof(options));
  options.coefficients_generation = DSP16_RESAMPLING_OPTIONS_USE_DYNAMIC;
  options.dynamic.coefficients_normalization = true;

  // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

  dsp16_debug_printf("16-bit fixed point signal resampling\n");
  dsp16_debug_printf("Input Fs: %iHz\n", F_INPUT);
  dsp16_debug_printf("Output Fs: %iHz\n", F_OUTPUT);
  dsp16_debug_printf("%i samples to process cut into %i buffers\n", N, NB_CUTS);
  dsp16_debug_printf("Filter order used: %i\n", FILTER_ORDER);

  if (!(resampling = dsp16_resampling_setup(F_INPUT, F_OUTPUT, N/NB_CUTS, FILTER_ORDER, 1, (malloc_fct_t) malloc, &options)))
  {
    dsp16_debug_printf("Unable to allocate enough memory\n");
    return -1;
  }

  if (!(output = (dsp16_t *) malloc(dsp16_resampling_get_output_max_buffer_size(resampling)*sizeof(dsp16_t) + 4)))
  {
    dsp16_debug_printf("Unable to allocate enough memory for the output buffer\n");
    return -1;
  }

  for(f=0; f<NB_CUTS; f++)
  {
    memcpy(s_input, &s[N/NB_CUTS*f], (N/NB_CUTS)*sizeof(dsp16_t));
    temp = Get_sys_count();
    dsp16_resampling_compute(resampling, output, s_input, 0);
    temp = Get_sys_count() - temp;
    dsp16_debug_print_vect(output, dsp16_resampling_get_output_current_buffer_size(resampling));
  }
  dsp16_debug_printf(
    "Cycle count per iteration: %i\n            in total (to compute %i samples): %i\n",
    temp,
    dsp16_resampling_get_output_current_buffer_size(resampling)*NB_CUTS,
    temp*NB_CUTS);

  dsp16_resampling_free(resampling, (free_fct_t) free);

  while(1);
}
/**
 * \brief Function to perform Zero Padding to Vector
 * \param size Pointer to store output Vector Size
 */
int zero_padding(int *size)
{
    int cycle_count;

    *size = VECT1_SIZE;

    cycle_count = Get_sys_count();
    dsp32_vect_zeropad(vect1, VECT1_SIZE, VECT1_SIZE);

    return Get_sys_count() - cycle_count;
}
Пример #7
0
// The main function
int main(int argc, char *argv[])
{
	unsigned int cycle_count, i;
	volatile  dsp32_t fft32_max;
	char *temp = " +";
	char complex_vect_result[SIZE][31];

	/**
	 * \note the call to sysclk_init() will disable all non-vital
	 * peripheral clocks, except for the peripheral clocks explicitly
	 * enabled in conf_clock.h.
	 */
	sysclk_init();

	// Initialize the DSP debug USART module when running in external board
#if BOARD != AVR_SIMULATOR_UC3
	dsp_debug_initialization(FOSC0);
#endif

	// Get the actual cycle count
	cycle_count = Get_sys_count();
	// Perform a 64-point complex FFT
	dsp32_trans_realcomplexfft(vect1, vect2, NLOG);
	// Perform the absolute value of a complex vector
	dsp32_vect_complex_abs(fft_real, vect1, SIZE);
	// Retrieves the maximum of a vector
	fft32_max = dsp32_vect_max(fft_real, SIZE);

	// Calculate the number of cycles the FFT took
	cycle_count = Get_sys_count() - cycle_count;

	// Print the  output signal
	for (i = 0; i < SIZE; i++) {
		if (vect1[i].imag >= 0) {
			temp = " +";
		} else {
			temp = " ";
		}
		dsp32_debug_sprintf(complex_vect_result[i],"%f%s%f", vect1[i].real,
				temp,vect1[i].imag);
	}
	/*
	 * Place a breakpoint here and check ASCII output in complex_vect_result
	 * in Memory Window.
	 * Note: Find the variable address in Watch Window and enter it in
	 * Memory Window
	 */

	while (1) {
		// Intentionally left blank.
	}
}
int zero_padding(int *size)
{
  int cycle_count;

  // Action
  dsp16_debug_printf("vect1 = zeros(vect1)\n");

  *size = VECT1_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_zeropad(vect1, VECT1_SIZE, VECT1_SIZE);

  return Get_sys_count() - cycle_count;
}
/**
 * \brief Function to perform Vector Copy
 * \param size Pointer to store output Vector Size
 */
int copy(int *size)
{
    int cycle_count;

    // Conditions
    CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)

    *size = VECT2_SIZE;

    cycle_count = Get_sys_count();
    dsp32_vect_copy(vect1, vect2, VECT2_SIZE);

    return Get_sys_count() - cycle_count;
}
Пример #10
0
void ushell_cmd_perform_extaccess( bool b_sens_write, Fs_file_segment seg )
{
   uint16_t u16_trans;
   uint32_t u32_tmp, u32_time;
   uint8_t  u8_nb_trans_usb=0;

   fat_cache_flush();
   fat_cache_reset();
   u32_time = Get_sys_count();
   u16_trans=0;
   while( seg.u16_size!=0 )
   {
      if( 0 == (seg.u32_addr % SIZE_OF_EXT_BUFFER) )
      {
         u8_nb_trans_usb = SIZE_OF_EXT_BUFFER;
      }else{
         u8_nb_trans_usb = SIZE_OF_EXT_BUFFER - (seg.u32_addr % SIZE_OF_EXT_BUFFER);  // to align access with usual memory mapping
      }
      if (u8_nb_trans_usb > seg.u16_size)
        u8_nb_trans_usb = seg.u16_size;

      if( b_sens_write )
      {
         if( CTRL_GOOD != host_write_10_extram( seg.u32_addr , u8_ext_buffer, u8_nb_trans_usb )) {
            printf( "Transfer error\r\n");
            return;
         }
      }else{
         if( CTRL_GOOD != host_read_10_extram( seg.u32_addr , u8_ext_buffer, u8_nb_trans_usb )) {
            printf( "Transfer error\r\n");
            return;
         }
      }
      seg.u16_size -= u8_nb_trans_usb;
      u16_trans    += u8_nb_trans_usb;
      seg.u32_addr += u8_nb_trans_usb;
      if( 8000000 < cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz) )
      {
         // Stop access after 8s
         break;
      }
   }
   u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz);
   u32_tmp = ((uint32_t)u16_trans*(1000000/2))/u32_time;
   if( b_sens_write )
      printf( "Transfer rate - WRITE %4luKB/s\r\n", u32_tmp);
   else
      printf( "Transfer rate - READ %4luKB/s\r\n", u32_tmp );
}
/**
 * \brief Function to perform Vector Dot Division
 * \param size Pointer to store output Vector Size
 */
int dot_division(int *size)
{
    int cycle_count;

    // Conditions
    CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
    CHECK_CONDITIONS(VECT2_SIZE == VECT3_SIZE)

    *size = VECT2_SIZE;

    cycle_count = Get_sys_count();
    dsp32_vect_dotdiv(vect1, vect2, vect3, VECT2_SIZE);

    return Get_sys_count() - cycle_count;
}
/**
 * \brief Function to perform Vector Real Multiplication
 * \param size Pointer to store output Vector Size
 */
int real_multiplication(int *size)
{
    int cycle_count;

    // Conditions
    CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
    CHECK_CONDITIONS(VECT3_SIZE > 0)

    *size = VECT2_SIZE;

    cycle_count = Get_sys_count();
    dsp32_vect_realmul(vect1, vect2, VECT2_SIZE, vect3[0]);

    return Get_sys_count() - cycle_count;
}
/**
 * \brief Function to perform Vector Power operation
 * \param size Pointer to store output Vector Size
 */
int power(int *size)
{
    int cycle_count;

    // Conditions
    CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
    CHECK_CONDITIONS(VECT3_SIZE > 0)

    *size = VECT2_SIZE;

    cycle_count = Get_sys_count();
    dsp32_vect_pow(vect1, vect2, VECT2_SIZE, vect3[0]);

    return Get_sys_count() - cycle_count;
}
/**
 * \brief Function to find Vector Maximum
 * \param size Pointer to store output Vector Size
 */
int maximum(int *size)
{
    int cycle_count;

    // Conditions
    CHECK_CONDITIONS(VECT1_SIZE > 0)
    CHECK_CONDITIONS(VECT2_SIZE > 0)

    *size = 1;

    cycle_count = Get_sys_count();
    vect1[0] = dsp32_vect_max(vect2, VECT2_SIZE);

    return Get_sys_count() - cycle_count;
}
/**
 * \brief Function to perform Partial Convolution
 * \param size Pointer to store output Vector Size
 */
int partial_convolution(int *size)
{
    int cycle_count;

    // Conditions
    CHECK_CONDITIONS(VECT1_SIZE >= (VECT2_SIZE - VECT3_SIZE + 4))
    CHECK_CONDITIONS(!(VECT2_SIZE&3) && VECT2_SIZE > 0)
    CHECK_CONDITIONS(VECT3_SIZE >= 8)

    *size = VECT2_SIZE - VECT3_SIZE + 1;

    cycle_count = Get_sys_count();
    // Perform a partial convolution
    dsp32_vect_convpart(vect1, vect2, VECT2_SIZE, vect3, VECT3_SIZE);
    return Get_sys_count() - cycle_count;
}
int copy(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)

  // Action
  dsp16_debug_printf("vect1 = vect2\n");

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_copy(vect1, vect2, VECT2_SIZE);

  return Get_sys_count() - cycle_count;
}
int int_multiplication(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
  CHECK_CONDITIONS(VECT3_SIZE > 0)

  // Action
  dsp16_debug_printf("vect1 = vect2 * %i\n", vect3[0]);

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_intmul(vect1, vect2, VECT2_SIZE, vect3[0]);

  return Get_sys_count() - cycle_count;
}
int power(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
  CHECK_CONDITIONS(VECT3_SIZE > 0)

  // Action
  dsp16_debug_printf("vect1 = vect2 ^ %f\n", vect3[0]);

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_pow(vect1, vect2, VECT2_SIZE, vect3[0]);

  return Get_sys_count() - cycle_count;
}
int maximum(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE > 0)
  CHECK_CONDITIONS(VECT2_SIZE > 0)

  // Action
  dsp16_debug_printf("max(vect2)\n");

  *size = 1;

  cycle_count = Get_sys_count();
  vect1[0] = dsp16_vect_max(vect2, VECT2_SIZE);

  return Get_sys_count() - cycle_count;
}
int dot_division(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
  CHECK_CONDITIONS(VECT2_SIZE == VECT3_SIZE)

  // Action
  dsp16_debug_printf("vect1 = vect2 ./ vect3\n");

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_dotdiv(vect1, vect2, vect3, VECT2_SIZE);

  return Get_sys_count() - cycle_count;
}
/**
 * \brief Function to perform Vector Convolution
 * \param size Pointer to store output Vector Size
 */
int convolution(int *size)
{
    int cycle_count;
    // Conditions
    CHECK_CONDITIONS(VECT1_SIZE >= (VECT2_SIZE + VECT3_SIZE - 1))
    CHECK_CONDITIONS(VECT2_SIZE >= 8)
    CHECK_CONDITIONS(VECT3_SIZE >= 8)
    if (VECT2_SIZE > VECT3_SIZE)
        CHECK_CONDITIONS(VECT1_SIZE >= (VECT2_SIZE + 2*VECT3_SIZE - 2))
        else
            CHECK_CONDITIONS(VECT1_SIZE >= (VECT3_SIZE + 2*VECT2_SIZE - 2))

            *size = VECT2_SIZE + VECT3_SIZE - 1;

    cycle_count = Get_sys_count();
    // Perform a convolution
    dsp32_vect_conv(vect1, vect2, VECT2_SIZE, vect3, VECT3_SIZE);
    return Get_sys_count() - cycle_count;
}
Пример #22
0
//! The main function
int main(int argc, char *argv[])
{
  unsigned int cycle_count;
  int i;
  short predicted_value, step_index;
  int diff;
  dsp16_t ratio;

  // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

  // Get the actual cycle count
  cycle_count = Get_sys_count();

  predicted_value = 0;
  step_index = 0;
  // Encode
  dsp_adpcm_ima_encode(cbuf, sbuf, NSAMPLES, &step_index, &predicted_value);

  predicted_value = 0;
  step_index = 0;
  // Decode
  dsp_adpcm_ima_decode(new_sbuf, cbuf, NSAMPLES, &step_index, &predicted_value);

  // Calculate the number of cycles
  cycle_count = Get_sys_count() - cycle_count;

  // Error calculation
  diff = 0;
  for(i=0; i<NSAMPLES; i++)
    diff += ((new_sbuf[i]-sbuf[i]) > 0)?(new_sbuf[i]-sbuf[i]):(sbuf[i]-new_sbuf[i]);
  ratio = DSP16_Q((diff/NSAMPLES)/(((float) (1 << 15))));

  // Print the number of cycles
  dsp16_debug_printf("Cycle count: %d\n", cycle_count);
  // Print the error average
  dsp16_debug_printf("Error average ratio: %f\n", ratio);

  while(1);
}
Пример #23
0
//! The main function
int main(int argc, char *argv[])
{
	unsigned int cycle_count, i;
	char fir_vect_result[SIZE][15];

	/**
	 * \note the call to sysclk_init() will disable all non-vital
	 * peripheral clocks, except for the peripheral clocks explicitly
	 * enabled in conf_clock.h.
	 */
	sysclk_init();

	// Initialize the DSP debug USART module when running in external board
#if BOARD != AVR_SIMULATOR_UC3
	dsp_debug_initialization(FOSC0);
#endif

	// Get the actual cycle count
	cycle_count = Get_sys_count();

	// Perform a 25-taps FIR
	dsp32_filt_fir(y, x, SIZE, fir_coef, FIR_COEF_SIZE);

	// Calculate the number of cycles
	cycle_count = Get_sys_count() - cycle_count;

	// Print the  output signal
	for (i = 0; i < SIZE; i++) {
		dsp32_debug_sprintf(fir_vect_result[i],"%f", y[i]);
	}
	/*
	 * Place a breakpoint here and check the ASCII output in fir_vect_result
	 * in Memory Window.
	 * Note: Find the variable address in Watch Window and enter it in
	 * Memory Window
	 */

	while (1) {
		// Intentionally left blank.
	}
}
Пример #24
0
//! The main function
int main(int argc, char *argv[])
{
  dsp32_t vect1[SIZE];
  int cycle_count;
  int frequency, sample_rate;
  dsp32_t phase, amplitude;

  // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

  // 1 KHz
  frequency = 1000;
  // 10 KHz
  sample_rate = 100000;
  // phase = PI/2
  phase = DSP32_Q(0.5);
  // amplitude
  amplitude = DSP32_Q(1.);

  dsp32_debug_printf("32-bit signal generation program test\n");

  // Compute the signal to generate
  switch(SIGNAL_TO_USE)
  {
  // Sinusoidal
  case SIGNAL_SIN:
    dsp32_debug_printf("Sine\n");
    dsp32_debug_printf("Frequency: %d, Fs: %d, Phase: %f\n", frequency, sample_rate, phase);
    cycle_count = Get_sys_count();
    dsp32_gen_sin(vect1, SIZE, frequency, sample_rate, phase);
    cycle_count = Get_sys_count() - cycle_count;
    break;
  // Cosinusoidal
  case SIGNAL_COS:
    dsp32_debug_printf("Cosine\n");
    dsp32_debug_printf("Frequency: %d, Fs: %d, Phase: %f\n", frequency, sample_rate, phase);
    cycle_count = Get_sys_count();
    dsp32_gen_cos(vect1, SIZE, frequency, sample_rate, phase);
    cycle_count = Get_sys_count() - cycle_count;
    break;
  // Noise
  case SIGNAL_NOISE:
    dsp32_debug_printf("Noise\n");
    dsp32_debug_printf("Amplitude: %d\n", amplitude);
    cycle_count = Get_sys_count();
    dsp32_gen_noise(vect1, SIZE, amplitude);
    cycle_count = Get_sys_count() - cycle_count;
    break;
  }

  // Print the number of cycles
  dsp32_debug_printf("Cycle count: %d\n", cycle_count);
  // Print the signal
  dsp32_debug_print_vect(vect1, SIZE);

  while(1);
}
Пример #25
0
void ushell_cmd_perform_transfer( Fs_file_segment seg_src, Fs_file_segment seg_dest )
{
   uint8_t id_trans_memtomem;
   Ctrl_status status_stream;
   uint16_t u16_i, u16_trans_max;
   uint32_t u32_tmp, u32_time;

   u16_trans_max = ( seg_src.u16_size < seg_dest.u16_size )?  seg_src.u16_size : seg_dest.u16_size;
   for( u16_i=2; u16_i<=u16_trans_max; u16_i*=10 )
   {
      u32_time = Get_sys_count();
      id_trans_memtomem = stream_mem_to_mem( seg_src.u8_lun , seg_src.u32_addr , seg_dest.u8_lun , seg_dest.u32_addr , u16_i );
      if( ID_STREAM_ERR == id_trans_memtomem )
      {
         printf( "Transfer error\r\n");
         return;
      }
      while(1)
      {
         status_stream = stream_state( id_trans_memtomem );
         if( CTRL_BUSY == status_stream ) continue;
         if( CTRL_GOOD == status_stream ) break;
         if( CTRL_FAIL == status_stream ) {
            printf( "Transfer error\r\n");
            return;
         }
      }
      u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz );
      u32_tmp = ((uint32_t)u16_i*(1000000/2))/u32_time;
      printf( "Transfer rate %4luKB/s - stream size %4iKB\r\n", u32_tmp, u16_i/2 );
      if( (8000000) < u32_time )
      {
         // The test time must be inferior at 8s
         break;
      }
   }
}
Пример #26
0
void ushell_cmd_perform_access( bool b_sens_write, Fs_file_segment seg )
{
   uint16_t u16_trans;
   uint32_t u32_tmp, u32_time;

   fat_cache_flush();
   fat_cache_reset();
   u32_time = Get_sys_count();
   for( u16_trans=0; u16_trans<seg.u16_size; u16_trans++ )
   {
      if( b_sens_write )
      {
         if( CTRL_GOOD != ram_2_memory( seg.u8_lun , seg.u32_addr , fs_g_sector )) {
            printf( "Transfer error\r\n");
            return;
         }
      }else{
         if( CTRL_GOOD != memory_2_ram( seg.u8_lun , seg.u32_addr , fs_g_sector )) {
            printf( "Transfer error\r\n");
            return;
         }
      }
      seg.u32_addr++;
      if( 8000000 < cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz) )
      {
         // Stop access after 8s
         break;
      }
   }
   u32_time = cpu_cy_2_us(Get_sys_count()-u32_time, g_u32_ushell_pba_hz);
   u32_tmp = ((uint32_t)u16_trans*(1000000/2))/u32_time;
   if( b_sens_write )
      printf( "Transfer rate - WRITE %4luKB/s\r\n", u32_tmp );
   else
      printf( "Transfer rate - READ %4luKB/s\r\n", u32_tmp );
}
Пример #27
0
/// Emulation of Arduino's millis() functionality on AVR32
/// \bug doesn't handle cycle counter wraparound very well
long millis(void)
{
    static long count = 0;
    static long milliseconds = 0;
    // Read CPU cycle counter and convert to millisecond difference
    long newcount = Get_sys_count();
    if (newcount < count) // cycle counter has wrapped since last update.
    {
        milliseconds += cpu_cy_2_ms(newcount, FCPU_HZ);
    }
    else
    {
        milliseconds += cpu_cy_2_ms(newcount - count, FCPU_HZ);
    }
    count = newcount;
    return milliseconds;
}
Пример #28
0
/**
* start timer 
*/
void Timer::start() 
{
	if (timerState == TIMER_STOP)
	{
		long long elapTime = 0;
		unsigned int countReg = 0;

		timerState = TIMER_START;

		AVR32_ENTER_CRITICAL_REGION(); // disable interrupts
		countReg = Get_sys_count();
		Set_sys_compare(countReg + 10); // the next timer irq will occur before leaving this function
		AVR32_LEAVE_CRITICAL_REGION();  // enable interrupts, if have been enabled before AVR32_ENTER_CRITICAL_REGION

		elapTime = 1000000000/(CPU_CLK/1000000);
		elapTime *= (countReg + 10);
		elapTime /= 1000000;

		nanoTime += elapTime;
	}
}
//Initialize LCD display
void init_disp (void)
{
	static const gpio_map_t DIP204_SPI_GPIO_MAP =
	{
		{DIP204_SPI_SCK_PIN,  DIP204_SPI_SCK_FUNCTION },  // SPI Clock.
		{DIP204_SPI_MISO_PIN, DIP204_SPI_MISO_FUNCTION},  // MISO.
		{DIP204_SPI_MOSI_PIN, DIP204_SPI_MOSI_FUNCTION},  // MOSI.
		{DIP204_SPI_NPCS_PIN, DIP204_SPI_NPCS_FUNCTION}   // Chip Select NPCS.
	};
	

	// add the spi options driver structure for the LCD DIP204
	spi_options_t spiOptions =
	{
		.reg          = DIP204_SPI_NPCS,
		.baudrate     = 1000000,
		.bits         = 8,
		.spck_delay   = 0,
		.trans_delay  = 0,
		.stay_act     = 1,
		.spi_mode     = 0,
		.modfdis      = 1
	};

	// Assign I/Os to SPI
	gpio_enable_module(DIP204_SPI_GPIO_MAP,
	sizeof(DIP204_SPI_GPIO_MAP) / sizeof(DIP204_SPI_GPIO_MAP[0]));

	// Initialize as master
	spi_initMaster(DIP204_SPI, &spiOptions);

	// Set selection mode: variable_ps, pcs_decode, delay
	spi_selectionMode(DIP204_SPI, 0, 0, 0);

	// Enable SPI
	spi_enable(DIP204_SPI);

	// setup chip registers
	spi_setupChipReg(DIP204_SPI, &spiOptions, FOSC0);
	
	// initialize LCD
	dip204_init(backlight_IO, true);
	
	dip204_hide_cursor();
}


int main (void)
{		
	// Switch the CPU main clock to oscillator 0
	pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);	
	
	board_init();
	init_disp(); 


	U32 x = 12345678;
	U32 y = 87654321;
	U64 z =0;
	
	F32 a = 1234.5678;
	F32 b = 8765.4321;
	F32 c = 0;
	
	U32 calc_time_z = 0;
	U32 calc_time_c = 0;
	
	U32 cnt_1 = 0;
	U32 cnt_2 = 0;
	U32 cnt_3 = 0;
	U32 cnt_res_z = 0; 
	U32 cnt_res_c = 0; 
	
	char cycl_str_z[9];
	char cycl_str_c[9];
	char result[19];	
	char cycl_c[9];
	char cycl_z[9];
	
	//Calculation:
	
	//Cycle count 1
	cnt_1 = Get_sys_count();
	
	//Calculation part 1:
	z = x*y;
	
	//Cycle count 2
	cnt_2 = Get_sys_count();
	
	//Calculation part 2:
	c = a*b;
	
	//Cycle count 3
	cnt_3 = Get_sys_count();
	
	//Cycle count result
	cnt_res_z = cnt_2 - cnt_1 ;
	cnt_res_c = cnt_3 - cnt_2 ;
	
	//Use cycle count result to find calculation time
	calc_time_c = (cnt_res_c * 1000000 + FOSC0 - 1) / FOSC0;
	calc_time_z = (cnt_res_z * 1000000 + FOSC0 - 1) / FOSC0;
	
	//Compose strings for display output
	sprintf(result, "%f", c);
	sprintf(cycl_str_z, "%lu", calc_time_z);
	sprintf(cycl_str_c, "%lu", calc_time_c);
	sprintf(cycl_c, "%lu", cnt_res_c);
	sprintf(cycl_z, "%lu", cnt_res_z);
	
	//Display calculation time, cycles and multiplication result on monitor
	dip204_clear_display();

	dip204_set_cursor_position(1,1);
	dip204_write_string("x*y=z");
	dip204_set_cursor_position(1,2);
	dip204_write_string("Time:");
	dip204_set_cursor_position(7,2);
	dip204_write_string(cycl_str_z);
	dip204_set_cursor_position(1,3);
	dip204_write_string("Cycles:");
	dip204_set_cursor_position(9,3);
	dip204_write_string(cycl_z);

	dip204_set_cursor_position(11,1);
	dip204_write_string("a*b=c");
	dip204_set_cursor_position(11,2);
	dip204_write_string("Time:");
	dip204_set_cursor_position(17,2);
	dip204_write_string(cycl_str_c);
	dip204_set_cursor_position(11,3);
	dip204_write_string("Cycles:");
	dip204_set_cursor_position(19,3);
	dip204_write_string(cycl_c);

	while (1)
	{
		
	}
} 
Пример #30
0
{
	/* Count the number of times this IRQ handler is called */
	number_of_compares++;

	/*
	 * Inform the main program that it may display a message saying
	 * that the COUNT&COMPARE interrupt occurred.
	 */
	compare_isr_fired = true;

	/*
	 * Clear any pending interrupt by writing to the COMPARE register, in
	 * the same go also schedule the next COUNT and COMPARE match
	 * interrupt.
	 */
	Set_sys_compare(Get_sys_count() + delay_clock_cycles);
}

/**
 * \brief Application main loop.
 *
 * Main function sets the COMPARE register and enables the interrupt for
 * COMPARE match. On every COMPARE match interrupt, a message is displayed and
 * LEDS are switched ON alternatively.
 */
int main(void)
{
	uint32_t compare_value;
	uint32_t temp;
#if BOARD != STK600_RCUC3L4
	uint8_t  active_led_map = 0x01;