示例#1
0
//! The main function
int main(int argc, char *argv[])
{
	dsp32_t number, result;
	int cycle_count;
	char sin_result[50], cos_result[50], asin_result[50], acos_result[50],
			rand_result[50], sqrt_result[50], abs_result[50], ln_result[50],
			log2_result[50], log10_result[50], exp_result[50], pow_result[50];
	/**
	 * \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

	number = DSP32_Q(NUMBER_TO_COMPUTE);
	/*
	 * Place a breakpoint on sprintf and check the ASCII output in
	 * %operator%_result in Watch Window or Memory Window.
	 * Note: Edit the variable name in Watch Window and append
	 * "&" at the start and ",s" at the end for displaying string.
	 * Read Watch Window Format Specifiers for more info.
	 */
	// 32-bit fixed point cosine
	cycle_count = Get_sys_count();
	result = dsp32_op_cos(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(cos_result, "cos(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point sine
	cycle_count = Get_sys_count();
	result = dsp32_op_sin(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(sin_result, "sin(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point arc cosine
	cycle_count = Get_sys_count();
	result = dsp32_op_acos(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(acos_result, "acos(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point arc sine
	cycle_count = Get_sys_count();
	result = dsp32_op_asin(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(asin_result, "asin(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point random
	dsp_op_srand(number);
	cycle_count = Get_sys_count();
	result = dsp32_op_rand();
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(rand_result, "rand() %f (%i cycles)\n", result,
			cycle_count);

	// 32-bit fixed point square root
	cycle_count = Get_sys_count();
	result = dsp32_op_sqrt(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(sqrt_result, "sqrt(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point absolute
	cycle_count = Get_sys_count();
	result = dsp32_op_abs(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(abs_result, "abs(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point natural logarithm
	cycle_count = Get_sys_count();
	result = dsp32_op_ln(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(ln_result, "ln(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point binary logarithm
	cycle_count = Get_sys_count();
	result = dsp32_op_log2(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(log2_result, "log2(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point common logarithm
	cycle_count = Get_sys_count();
	result = dsp32_op_log10(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(log10_result, "log10(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point exponential
	cycle_count = Get_sys_count();
	result = dsp32_op_exp(number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(exp_result, "exp(%f) %f (%i cycles)\n", number,
			result, cycle_count);

	// 32-bit fixed point power
	cycle_count = Get_sys_count();
	result = dsp32_op_pow(DSP32_Q(0.), number);
	cycle_count = Get_sys_count() - cycle_count;
	dsp32_debug_sprintf(pow_result, "pow(0.5, %f) %f (%i cycles)\n", number,
			result, cycle_count);

	while (1) {
		// Intentionally left blank.
	}
}
示例#2
0
//! The main function
int main(int argc, char *argv[])
{
  dsp32_t number, result;
  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);

  dsp32_debug_printf("32-bit fixed point operators program test\n");

  dsp32_debug_printf("Type a number: ");
  number = dsp_debug_read_q(DSP32_QA, DSP32_QB);

  dsp32_debug_printf("Number to compute: %f\n", number);

  // 32-bit fixed point cosine
  cycle_count = Get_sys_count();
  result = dsp32_op_cos(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("cos(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point sine
  cycle_count = Get_sys_count();
  result = dsp32_op_sin(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("sin(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point arc cosine
  cycle_count = Get_sys_count();
  result = dsp32_op_acos(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("acos(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point arc sine
  cycle_count = Get_sys_count();
  result = dsp32_op_asin(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("asin(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point random
  dsp_op_srand(number);
  cycle_count = Get_sys_count();
  result = dsp32_op_rand();
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("rand()\t\t\t\t%f\t(%i cycles)\n", result, cycle_count);

  // 32-bit fixed point square root
  cycle_count = Get_sys_count();
  result = dsp32_op_sqrt(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("sqrt(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point absolute
  cycle_count = Get_sys_count();
  result = dsp32_op_abs(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("abs(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point natural logarithm
  cycle_count = Get_sys_count();
  result = dsp32_op_ln(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("ln(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point binary logarithm
  cycle_count = Get_sys_count();
  result = dsp32_op_log2(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("log2(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point common logarithm
  cycle_count = Get_sys_count();
  result = dsp32_op_log10(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("log10(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point exponential
  cycle_count = Get_sys_count();
  result = dsp32_op_exp(number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("exp(%f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  // 32-bit fixed point power
  cycle_count = Get_sys_count();
  result = dsp32_op_pow(DSP32_Q(0.), number);
  cycle_count = Get_sys_count() - cycle_count;
  dsp32_debug_printf("pow(0.5, %f)\t\t%f\t(%i cycles)\n", number, result, cycle_count);

  while(1);
}