/* Calculates a clock divider (
Baud rate calculation:  */
static int usart_set_sync_master_baudrate(volatile avr32_usart_t *usart, unsigned int baudrate, unsigned long pba_hz)
/* Calculates a clock divider (
Baud rate calculation:  */
static int usart_set_sync_master_baudrate(volatile avr32_usart_t *usart, unsigned int baudrate, unsigned long pba_hz)
{
  unsigned int cd = (pba_hz + baudrate / 2) / baudrate;
  if (cd < 1 || cd > (1 << AVR32_USART_BRGR_CD_SIZE) - 1)
    return USART_INVALID_INPUT;
  usart->mr = (usart->mr & ~AVR32_USART_MR_USCLKS_MASK) |
              AVR32_USART_MR_USCLKS_MCK << AVR32_USART_MR_USCLKS_OFFSET |
              AVR32_USART_MR_SYNC_MASK;
  usart->brgr = cd << AVR32_USART_BRGR_CD_OFFSET;
  return USART_SUCCESS;
}