OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [lib/] [source/] [neorv32_uart.c] - Diff between revs 51 and 55

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 51 Rev 55
Line 503... Line 503...
          break;
          break;
        case 'x': // 32-bit hexadecimal
        case 'x': // 32-bit hexadecimal
          __neorv32_uart_tohex(va_arg(a, uint32_t), string_buf);
          __neorv32_uart_tohex(va_arg(a, uint32_t), string_buf);
          neorv32_uart0_print(string_buf);
          neorv32_uart0_print(string_buf);
          break;
          break;
        default:
        default: // unsupported format
          return;
          neorv32_uart0_putc('%');
 
          neorv32_uart0_putc(c);
 
          break;
      }
      }
    }
    }
    else {
    else {
      if (c == '\n') {
      if (c == '\n') {
        neorv32_uart0_putc('\r');
        neorv32_uart0_putc('\r');
Line 856... Line 858...
          break;
          break;
        case 'x': // 32-bit hexadecimal
        case 'x': // 32-bit hexadecimal
          __neorv32_uart_tohex(va_arg(a, uint32_t), string_buf);
          __neorv32_uart_tohex(va_arg(a, uint32_t), string_buf);
          neorv32_uart1_print(string_buf);
          neorv32_uart1_print(string_buf);
          break;
          break;
        default:
        default: // unsupported format
          return;
          neorv32_uart1_putc('%');
 
          neorv32_uart1_putc(c);
 
          break;
      }
      }
    }
    }
    else {
    else {
      if (c == '\n') {
      if (c == '\n') {
        neorv32_uart1_putc('\r');
        neorv32_uart1_putc('\r');
Line 962... Line 966...
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Private function for 'neorv32_printf' to convert into hexadecimal.
 * Private function for 'neorv32_printf' to convert into hexadecimal.
 *
 *
 * @param[in] x Unsigned input number.
 * @param[in] x Unsigned input number.
 * @param[in,out] res Pointer for storing the reuslting number string (9 chars).
 * @param[in,out] res Pointer for storing the resulting number string (9 chars).
 **************************************************************************/
 **************************************************************************/
static void __neorv32_uart_tohex(uint32_t x, char *res) {
static void __neorv32_uart_tohex(uint32_t x, char *res) {
 
 
  static const char symbols[] = "0123456789abcdef";
  static const char symbols[] = "0123456789abcdef";
 
 
  int i;
  int i;
  for (i=0; i<8; i++) { // nibble by bibble
  for (i=0; i<8; i++) { // nibble by nibble
    uint32_t num_tmp = x >> (4*i);
    uint32_t num_tmp = x >> (4*i);
    res[7-i] = (char)symbols[num_tmp & 0x0f];
    res[7-i] = (char)symbols[num_tmp & 0x0f];
  }
  }
 
 
  res[8] = '\0'; // terminate result string
  res[8] = '\0'; // terminate result string

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.