Exemplo n.º 1
0
int noinline
debug_uart_put(char d, FILE * stream)
{
  if (d == '\n')
    debug_uart_put('\r', stream);

  /* replace escape sequences */
  if (d == 0x1b)
    d = '^';

#ifdef S1D15G10_SUPPORT
  lcd_putch(d);
#endif /* S1D15G10_SUPPORT */
#ifdef SOFT_UART_SUPPORT
  soft_uart_putchar(d);
#else /* SOFT_UART_SUPPORT */
  while (!(usart(UCSR, A) & _BV(usart(UDRE))));

  #if (HAVE_RS485TE_USART0 == 1 || HAVE_RS485TE_USART1 == 1)
  /* enable usart transmit complete interrupt */
  usart(UCSR,B) |= _BV(usart(TXCIE));
    #if (USE_USART == 0)
  PIN_SET(RS485TE_USART0);  // enable RS485 transmitter for usart 0
    #elif (USE_USART == 1)
  PIN_SET(RS485TE_USART1);  // enable RS485 transmitter for usart 1
    #endif
  #endif  /* HAVE_RS485TE_USART0 == 1 || HAVE_RS485TE_USART1 == 1 */

  usart(UDR) = d;
#endif /* SOFT_UART_SUPPORT */
  return 0;
}
Exemplo n.º 2
0
int noinline
debug_uart_put(char d, FILE * stream)
{
  if (d == '\n')
    debug_uart_put('\r', stream);

  /* replace escape sequences */
  if (d == 0x1b)
    d = '^';

  #ifdef S1D15G10_SUPPORT
    lcd_putch(d);
  #endif /* S1D15G10_SUPPORT */

  #ifdef SOFT_UART_SUPPORT
    soft_uart_putchar(d);
  #else /* SOFT_UART_SUPPORT */
    while (!(usart(UCSR, A) & _BV(usart(UDRE))));

    #if RS485_HAVE_TE
      /* enable interrupt usart transmit complete */
      usart(UCSR,B) |= _BV(usart(TXCIE));
      RS485_ENABLE_TX;
    #endif  /* RS485_HAVE_TE */

    usart(UDR) = d;
  #endif /* SOFT_UART_SUPPORT */

  return 0;
}
Exemplo n.º 3
0
void
debug_process_uart (void)
{
#if defined(ECMD_PARSER_SUPPORT) && !defined(SOFT_UART_SUPPORT)
#define LEN 60
#define OUTPUTLEN 40

    static char buf[LEN+1];
    static char *ptr = buf;

    if (usart(UCSR,A) & _BV(usart(RXC))) {
        char data = usart(UDR);

        if (data == '\n' || data == '\r') {
            char *output = malloc(OUTPUTLEN);

            if (output == NULL)
                debug_printf("malloc() failed!\n");

            *ptr = '\0';
            printf_P(PSTR("\n"));

#ifdef DEBUG_ECMD
            debug_printf("parsing command '%s'\n", buf);
#endif
            int l;

            do {
                l = ecmd_parse_command(buf, output, LEN);
                if (is_ECMD_FINAL(l) || is_ECMD_AGAIN(l)) {
                    output[is_ECMD_AGAIN(l) ? ECMD_AGAIN(l) : l] = 0;
                    printf_P(PSTR("%s\n"), output);
                }
            } while (is_ECMD_AGAIN(l));
            free(output);
            ptr = buf;
        } else {
            debug_uart_put(data, stdout);
            if (data == '\b') {if (ptr > &buf[0]) ptr--;}
            else
            {
                if (ptr < &buf[LEN-1])
                    *ptr++ = data;
                else
                    debug_printf("not enough space for storing '%c'\n", data);
            }
        }
    }
#endif  /* ECMD_PARSER_SUPPORT && !SOFT_UART_SUPPORT*/
}
Exemplo n.º 4
0
int noinline
debug_uart_put (char d, FILE *stream)
{
    if (d == '\n')
	debug_uart_put('\r', stream);

    if (d == 0x1b)
	d = '^';		/* replace escape sequences. */

#ifdef S1D15G10_SUPPORT
    lcd_putch(d);
#endif
#ifdef SOFT_UART_SUPPORT
    soft_uart_putchar(d);
    return 0;
#else
    while (!(usart(UCSR,A) & _BV(usart(UDRE))));
    usart(UDR) = d;

    return 0;
#endif
}