Esempio n. 1
0
void print_unicode_string(char* str, u32 len) {
  u32 i; // byte index
  print_dbg("\r\n");
  for(i=0; i<len; i++) {
    print_dbg_char(str[i]);
  }
}
Esempio n. 2
0
void serial_process(s32 data) {
    // process_serial_t serial_decode = &serial_decode_dummy;
    u16 c = (u16)data;

    while(serial_read_pos != c) {
        //////////////////
        //// TEST: loopback
        print_dbg_char(serial_buffer[serial_read_pos]);
        serial_read_pos++;
        if(serial_read_pos == SERIAL_BUFFER_SIZE) serial_read_pos = 0;
    }

    // testing///
    // serial_send_start(2);
    // serial_send_byte(10);
    // serial_send_end();

    // ///////////////////
    /*
        // DONE: implement proper framing, ie: http://eli.thegreenplace.net/2009/08/12/framing-in-serial-communications/
        // code 27 is escape
        if(c == 27 && escape == 0) escape = 1;
        // check for null, indicating complete packet
        else if(c == 0 && escape == 0) {
          if(serial_buffer[0] >= eComNumCommands) {		// check for garbage command
          	print_dbg("bad serial command.");
          	serial_write_pos++;
          } else {
          	serial_decode = serialFuncs[serial_buffer[serial_read_pos]];			// first byte is index
          	(*serial_decode)(serial_read_pos);			// do the thing according to command index
          	serial_write_pos++;
          	if(serial_write_pos == SERIAL_BUFFER_SIZE) serial_write_pos = 0;	// wrap
          	serial_read_pos = serial_write_pos;			// start of next packet
          }
          // normal data copy
        } else {
          serial_buffer[serial_write_pos] = c;
          serial_write_pos++;
          if(serial_write_pos == SERIAL_BUFFER_SIZE) serial_write_pos = 0;
          escape = 0;
        }
      }*/
}
Esempio n. 3
0
/*! \brief Sets the SDRAM Controller up, initializes the SDRAM found on the
 *         board and tests it.
 */
int main(void)
{
  unsigned long sdram_size, progress_inc, i, j, tmp, noErrors = 0;
  volatile unsigned long *sdram = SDRAM;

  // Switch to external oscillator 0.
  pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

  // Initialize the debug USART module.
  init_dbg_rs232(FOSC0);

  // Calculate SDRAM size in words (32 bits).
  sdram_size = SDRAM_SIZE >> 2;
  print_dbg("\x0CSDRAM size: ");
  print_dbg_ulong(SDRAM_SIZE >> 20);
  print_dbg(" MB\r\n");

  // Initialize the external SDRAM chip.
  sdramc_init(FOSC0);
  print_dbg("SDRAM initialized\r\n");

  // Determine the increment of SDRAM word address requiring an update of the
  // printed progression status.
  progress_inc = (sdram_size + 50) / 100;

  // Fill the SDRAM with the test pattern.
  for (i = 0, j = 0; i < sdram_size; i++)
  {
    if (i == j * progress_inc)
    {
      LED_Toggle(LED_SDRAM_WRITE);
      print_dbg("\rFilling SDRAM with test pattern: ");
      print_dbg_ulong(j++);
      print_dbg_char('%');
    }
    sdram[i] = i;
  }
  LED_Off(LED_SDRAM_WRITE);
  print_dbg("\rSDRAM filled with test pattern       \r\n");

  // Recover the test pattern from the SDRAM and verify it.
  for (i = 0, j = 0; i < sdram_size; i++)
  {
    if (i == j * progress_inc)
    {
      LED_Toggle(LED_SDRAM_READ);
      print_dbg("\rRecovering test pattern from SDRAM: ");
      print_dbg_ulong(j++);
      print_dbg_char('%');
    }
    tmp = sdram[i];
    if (tmp != i)
    {
      noErrors++;
    }
  }
  LED_Off(LED_SDRAM_READ);
  print_dbg("\rSDRAM tested: ");
  print_dbg_ulong(noErrors);
  print_dbg(" corrupted word(s)       \r\n");
  if (noErrors)
  {
    LED_Off(LED_SDRAM_ERRORS);
    while (1)
    {
      LED_Toggle(LED_SDRAM_ERRORS);
      cpu_delay_ms(200, FOSC0);   // Fast blink means errors.
    }
  }
  else
  {
    LED_Off(LED_SDRAM_OK);
    while (1)
    {
      LED_Toggle(LED_SDRAM_OK);
      cpu_delay_ms(1000, FOSC0);  // Slow blink means OK.
    }
  }
}