예제 #1
0
파일: zbus.c 프로젝트: argv/moodlamp-rf
void
zbus_rxstart (void)
{
  if(zbus_txlen > 0){
    return;
  }
//  uart1_puts("acDZRab");
//  PIN_CLEAR(ZBUS_RX_PIN);
  zbus_rxlen = 0;

  uint8_t sreg = SREG; cli();

  /* disable transmitter, enable receiver (and rx interrupt) */
  usart(UCSR,B) = _BV(usart(RXCIE)) | _BV(usart(RXEN));

  /* Default is reciever enabled*/
  PIN_CLEAR(RS485_TX_PIN);
  PIN_CLEAR(RS485_NRX_PIN);

  SREG = sreg;
}
예제 #2
0
파일: zbus.c 프로젝트: simeonfelis/ethersex
static void __zbus_txstart(void) {

  uint8_t sreg = SREG; cli();
  bus_blocked = 3;

  /* enable transmitter and receiver as well as their interrupts */
  usart(UCSR,B) = _BV(usart(TXCIE)) | _BV(usart(TXEN));

  /* Enable transmitter */
  PIN_SET(ZBUS_RXTX_PIN);

  /* reset tx interrupt flag */
  usart(UCSR,A) |= _BV(usart(TXC));

  /* Go! */
  SREG = sreg;

  /* Transmit Start sequence */
  send_escape_data = ZBUS_START;
  usart(UDR) = '\\';

#ifdef HAVE_ZBUS_TX_PIN
  PIN_SET(ZBUS_TX_PIN);
#endif

  return;
}
예제 #3
0
파일: zbus.c 프로젝트: 1234tester/ethersex
void
zbus_rxstart (void)
{
  if (zbus_txlen > 0)
    {
      return;
    }
  zbus_rxlen = 0;

  uint8_t sreg = SREG;
  cli ();

  /* disable transmitter, enable receiver (and rx interrupt) */
  usart (UCSR, B) = _BV (usart (RXCIE)) | _BV (usart (RXEN));

  /* Default is reciever enabled */
#ifdef HAVE_ZBUS_RXTX_PIN
  PIN_CLEAR (ZBUS_RXTX_PIN);
#endif

  SREG = sreg;
}
예제 #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
}
예제 #5
0
파일: yport.c 프로젝트: Wiiilmaa/ethersex
uint8_t
yport_rxstart(uint8_t *data, uint16_t len)
{
  uint16_t diff = yport_send_buffer.len - yport_send_buffer.sent;
  if (diff == 0) {
    /* Copy the data to the send buffer */
    memcpy(yport_send_buffer.data, data, len);
    yport_send_buffer.len = len;
    goto start_sending;
  /* The actual packet can be pushed into the buffer */
  } else if ((diff + len) < YPORT_BUFFER_LEN) {
    memmove(yport_send_buffer.data, yport_send_buffer.data + yport_send_buffer.sent, diff);
    memcpy(yport_send_buffer.data + diff, data, len);
    yport_send_buffer.len = diff + len;
    goto start_sending;
  }
  return 0;
start_sending:
    yport_send_buffer.sent = 1;
    /* Enable the tx interrupt and send the first character */
    usart(UCSR,B) |= _BV(usart(TXCIE));
    usart(UDR) = yport_send_buffer.data[0];
    return 1;
}
예제 #6
0
파일: msr1.c 프로젝트: HansBaechle/ethersex
void
msr1_periodic(void)
{
  new_data.chksum = 0;
  new_data.len = 0;

  if (state == MSR1_REQUEST_C0) {
    state = MSR1_REQUEST_E8;
    usart(UDR) = 0xe8;
    MSR1_DEBUG("sent e8 command\n");
  } else if (state == MSR1_REQUEST_E8) {
    state = MSR1_REQUEST_48;
    usart(UDR) = 0x48;
    MSR1_DEBUG("sent 48 command\n");
  } else if (state == MSR1_REQUEST_48) {
    state = MSR1_REQUEST_50;
    usart(UDR) = 0x50;
    MSR1_DEBUG("sent 50 command\n");
  } else {
    state = MSR1_REQUEST_C0;
    usart(UDR) = 0xc0;
    MSR1_DEBUG("sent c0 command\n");
  }
}
예제 #7
0
파일: debug.c 프로젝트: adlerweb/ethersex
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, OUTPUTLEN);
        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 */
}
예제 #8
0
static void
dc3840_send_uart (uint8_t byte)
{
  while (!(usart(UCSR,A) & _BV(usart(UDRE))));
  usart(UDR) = byte;
}