//! The main function
int main(int argc, char *argv[])
{
  int cycle_count, size;
  int i;

  // 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 vectors program test\n");

  dsp16_debug_printf("Output vector 1 (size %i)\n", VECT1_SIZE);
  dsp16_debug_printf("Input vector 2 (size %i)\n", VECT2_SIZE);
  dsp16_debug_printf("Input vector 3 (size %i)\n", VECT3_SIZE);

  while(1)
  {
    // Print the menu
    dsp16_debug_printf("***** Menu *****\n");
    for(i=0; i<sizeof(item_menu)/sizeof(s_item_menu); i++)
      dsp16_debug_printf("%i:\t%s\n", i, item_menu[i].title);

    // Prompt
    dsp16_debug_printf("> ");
    i = dsp_debug_read_ui();

    if (i >= 0 && i < sizeof(item_menu)/sizeof(s_item_menu))
    {
      // Print the title
      dsp16_debug_printf("%s\n", item_menu[i].title);

      // Call the function to execute
      cycle_count = item_menu[i].action(&size);

      if (cycle_count != -1)
      {
        // Print the number of cycles
        dsp16_debug_printf("Cycle count: %d\n", cycle_count);
        // Print the result
        dsp16_debug_print_vect(vect1, size);
      }
    }
    else
      dsp16_debug_printf("!Invalid item!\n");

    dsp16_debug_printf("<Press any key to continue>\n");
    dsp_debug_read_fct();
  }
}
Ejemplo n.º 2
0
//! This function is used to get a string.
void dsp_debug_read(char *str, int size, char end_char)
{
  int i = 0;
  char c;

  while(i < size-1)
  {
    c = dsp_debug_read_fct();
    if (c == end_char)
      break;
    str[i++] = c;
  }
  str[i] = '\0';
}
Ejemplo n.º 3
0
//! This function is used to get an unsigned integer
int dsp_debug_read_ui()
{
  int i = 0;
  char c;

  while(1)
  {
    c = dsp_debug_read_fct();
    dsp_debug_buffer[i++] = c;
    if (c < '0' || c > '9')
      break;
  }

  return dsp_debug_parse_int(dsp_debug_buffer);
}
Ejemplo n.º 4
0
//! This function is used to get a Q formatted number
int dsp_debug_read_q(int a, int b)
{
  int i = 0;
  int zeros = 1;
  int q_num;
  char c;
  int integer = 0, decimal = 0, sign = 1;
  int _10log10;
  char data[32], *pdata;
  S64 temp;

  while(i < sizeof(data))
  {
    c = dsp_debug_read_fct();
    data[i++] = c;
    if ((c < '0' || c > '9') && (c != '.' && c != ',' && c != '-'))
      break;
  }
  // Take care of the sign
  pdata = data;
  if (*pdata == '-')
  {
    sign = -1;
    pdata++;
  }

  if ((integer = dsp_debug_parse_int(pdata)) == -1)
    integer = 0;

  // If overflow
  if (integer >= (1 << (a-1)))
  {
    if (sign == 1)
      return DSP_Q_MAX(a, b);
    else
      return DSP_Q_MIN(a, b);
  }

  // Switch to decimal data
  for(i=0; (pdata[i] >= '0' && pdata[i] <= '9') || pdata[i] <= '-'; i++);

  if (pdata[i] == '.' || pdata[i] == ',')
  {
    // Count the number of zeros before the first plain number
    for(; pdata[i+1] == '0'; i++, zeros *= 10);
    if ((decimal = dsp_debug_parse_int(&pdata[i+1])) == -1)
      decimal = 0;
  }

  // decimal/(10^(log10(decimal)+1))
  // Calculation of the integer part of log10
  _10log10 = 1;
  while(_10log10 <= decimal)
    _10log10 *= 10;
  _10log10 *= zeros;

  temp = decimal;
  temp <<= b;
  temp /= _10log10;

  q_num = temp + (integer << b);
  q_num *= sign;

  return q_num;
}