int usart_send_address(volatile avr32_usart_t *usart, int address)
{
  // Check if USART is in multidrop / RS485 mode.
  if (!usart_mode_is_multidrop(usart)) return USART_MODE_FAULT;

  // Prepare to send an address.
  usart->cr |= AVR32_USART_CR_SENDA_MASK;

  // Write the address to TX.
  usart_bw_write_char(usart, address);

  return USART_SUCCESS;
}
Beispiel #2
0
static rt_size_t rt_serial_write (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
    rt_uint8_t *ptr;
    rt_err_t err_code;
    struct avr32_serial_device *uart;

    err_code = RT_EOK;
    ptr = (rt_uint8_t *)buffer;
    uart = (struct avr32_serial_device *)dev->user_data;

    if (dev->flag & RT_DEVICE_FLAG_INT_TX)
    {
        /* interrupt mode Tx, does not support */
        RT_ASSERT(0);
    }
    else
    {
        /* polling mode */
        if (dev->flag & RT_DEVICE_FLAG_STREAM)
        {
            /* stream mode */
            while (size)
            {
                usart_putchar(uart->uart_device, (int) *ptr);

                ++ptr;
                --size;
            }
        }
        else
        {
            /* write data directly */
            while (size)
            {
                usart_bw_write_char(uart->uart_device, (int) *ptr);

                ++ptr;
                --size;
            }
        }
    }

    /* set error code */
    rt_set_errno(err_code);

    return (rt_uint32_t)ptr - (rt_uint32_t)buffer;
}