src/app/host-serial/libftdi/ftdi.c
static int ftdi_convert_baudrate(int baudrate, struct ftdi_context *ftdi,
                                 unsigned short *value, unsigned short *index)
{
    int best_baud;
    unsigned long encoded_divisor;

    if (baudrate <= 0)
    {
        // Return error
        return -1;
    }

#define H_CLK 120000000
#define C_CLK  48000000
    if ((ftdi->type == TYPE_2232H) || (ftdi->type == TYPE_4232H) || (ftdi->type == TYPE_232H))
    {
        if(baudrate*10 > H_CLK /0x3fff)
        {
            /* On H Devices, use 12 000 000 Baudrate when possible
               We have a 14 bit divisor, a 1 bit divisor switch (10 or 16)
               three fractional bits and a 120 MHz clock
               Assume AN_120 "Sub-integer divisors between 0 and 2 are not allowed" holds for
               DIV/10 CLK too, so /1, /1.5 and /2 can be handled the same*/
            best_baud = ftdi_to_clkbits(baudrate, H_CLK, 10, &encoded_divisor);
            encoded_divisor |= 0x20000; /* switch on CLK/10*/
        }
        else
            best_baud = ftdi_to_clkbits(baudrate, C_CLK, 16, &encoded_divisor);
    }
    else if ((ftdi->type == TYPE_BM) || (ftdi->type == TYPE_2232C) || (ftdi->type == TYPE_R ))
    {
        best_baud = ftdi_to_clkbits(baudrate, C_CLK, 16, &encoded_divisor);
    }
    else
    {
        best_baud = ftdi_to_clkbits_AM(baudrate, &encoded_divisor);
    }
    // Split into "value" and "index" values
    *value = (unsigned short)(encoded_divisor & 0xFFFF);
    if (ftdi->type == TYPE_2232H || ftdi->type == TYPE_4232H || ftdi->type == TYPE_232H)
    {
        *index = (unsigned short)(encoded_divisor >> 8);
        *index &= 0xFF00;
        *index |= ftdi->index;
    }
    else
        *index = (unsigned short)(encoded_divisor >> 16);

    // Return the nearest baud rate
    return best_baud;
}
/**
    ftdi_convert_baudrate returns nearest supported baud rate to that requested.
    Function is only used internally
    \internal
*/
ftdi_convert_baudrate returns nearest supported baud rate to that requested.
Function is only used internally
\internal
ftdi_convert_baudrate returns nearest supported baud rate to that requested . Function is only used internally \ internal
static int ftdi_convert_baudrate(int baudrate, struct ftdi_context *ftdi,
                                 unsigned short *value, unsigned short *index)
{
    int best_baud;
    unsigned long encoded_divisor;
    if (baudrate <= 0)
    {
        return -1;
    }
#define H_CLK 120000000
#define C_CLK  48000000
    if ((ftdi->type == TYPE_2232H) || (ftdi->type == TYPE_4232H) || (ftdi->type == TYPE_232H))
    {
        if(baudrate*10 > H_CLK /0x3fff)
        {
            best_baud = ftdi_to_clkbits(baudrate, H_CLK, 10, &encoded_divisor);
            encoded_divisor |= 0x20000; 
        }
        else
            best_baud = ftdi_to_clkbits(baudrate, C_CLK, 16, &encoded_divisor);
    }
    else if ((ftdi->type == TYPE_BM) || (ftdi->type == TYPE_2232C) || (ftdi->type == TYPE_R ))
    {
        best_baud = ftdi_to_clkbits(baudrate, C_CLK, 16, &encoded_divisor);
    }
    else
    {
        best_baud = ftdi_to_clkbits_AM(baudrate, &encoded_divisor);
    }
    *value = (unsigned short)(encoded_divisor & 0xFFFF);
    if (ftdi->type == TYPE_2232H || ftdi->type == TYPE_4232H || ftdi->type == TYPE_232H)
    {
        *index = (unsigned short)(encoded_divisor >> 8);
        *index &= 0xFF00;
        *index |= ftdi->index;
    }
    else
        *index = (unsigned short)(encoded_divisor >> 16);
    return best_baud;
}
static int ftdi_convert_baudrate ( int baudrate , struct ftdi_context * ftdi , unsigned short * value , unsigned short * index ) { int best_baud ; unsigned long encoded_divisor ; if ( baudrate <= 0 ) { return -1 ; } #define H_CLK  120000000 #define C_CLK   48000000 if ( ( ftdi -> type == TYPE_2232H ) || ( ftdi -> type == TYPE_4232H ) || ( ftdi -> type == TYPE_232H ) ) { if ( baudrate * 10 > H_CLK / 0x3fff ) { best_baud = ftdi_to_clkbits ( baudrate , H_CLK , 10 , & encoded_divisor ) ; encoded_divisor |= 0x20000 ; } else best_baud = ftdi_to_clkbits ( baudrate , C_CLK , 16 , & encoded_divisor ) ; } else if ( ( ftdi -> type == TYPE_BM ) || ( ftdi -> type == TYPE_2232C ) || ( ftdi -> type == TYPE_R ) ) { best_baud = ftdi_to_clkbits ( baudrate , C_CLK , 16 , & encoded_divisor ) ; } else { best_baud = ftdi_to_clkbits_AM ( baudrate , & encoded_divisor ) ; } * value = ( unsigned short ) ( encoded_divisor & 0xFFFF ) ; if ( ftdi -> type == TYPE_2232H || ftdi -> type == TYPE_4232H || ftdi -> type == TYPE_232H ) { * index = ( unsigned short ) ( encoded_divisor >> 8 ) ; * index &= 0xFF00 ; * index |= ftdi -> index ; } else * index = ( unsigned short ) ( encoded_divisor >> 16 ) ; return best_baud ; }
ftdi_convert_baudrate returns nearest supported baud rate to that requested.
ftdi_convert_baudrate returns nearest supported baud rate to that requested .
// Return error /* On H Devices, use 12 000 000 Baudrate when possible
               We have a 14 bit divisor, a 1 bit divisor switch (10 or 16)
               three fractional bits and a 120 MHz clock
               Assume AN_120 "Sub-integer divisors between 0 and 2 are not allowed" holds for
               DIV/10 CLK too, so /1, /1.5 and /2 can be handled the same*/ /* switch on CLK/10*/ // Split into "value" and "index" values // Return the nearest baud rate