/* Calculate a clock divider for the USART synchronous master modes to generate a baudrate as close as possible to the baudrate set point.  */
static uint32_t usart_set_sync_master_baudrate(Usart *p_usart, uint32_t baudrate, uint32_t ul_mck)
/* Calculate a clock divider for the USART synchronous master modes to generate a baudrate as close as possible to the baudrate set point.  */
static uint32_t usart_set_sync_master_baudrate(Usart *p_usart, uint32_t baudrate, uint32_t ul_mck)
{
	uint32_t cd;
	cd = (ul_mck + baudrate / 2) / baudrate;
	if (cd < MIN_CD_VALUE || cd > MAX_CD_VALUE) {
		return 1;
	}
	p_usart->US_BRGR = cd << US_BRGR_CD_Pos;
	p_usart->US_MR = (p_usart->US_MR & ~US_MR_USCLKS_Msk) |
			US_MR_USCLKS_MCK | US_MR_SYNC;
	return 0;
}