Changeset c39148d in rtems


Ignore:
Timestamp:
Jun 14, 2012, 12:27:58 PM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
7329f55
Parents:
c34bb0d
git-author:
Sebastian Huber <sebastian.huber@…> (06/14/12 12:27:58)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/15/12 13:59:32)
Message:

libchip: Add support for NS16550 with FDR

Location:
c/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/lpc24xx/console/console-config.c

    rc34bb0d rc39148d  
    9494    {
    9595      .sDeviceName = "/dev/ttyS0",
    96       .deviceType = SERIAL_NS16550,
     96      .deviceType = SERIAL_NS16550_WITH_FDR,
    9797      .pDeviceFns = &ns16550_fns,
    9898      .deviceProbe = NULL,
     
    115115    {
    116116      .sDeviceName = "/dev/ttyS1",
    117       .deviceType = SERIAL_NS16550,
     117      .deviceType = SERIAL_NS16550_WITH_FDR,
    118118      .pDeviceFns = &ns16550_fns,
    119119      .deviceProbe = lpc24xx_uart_probe_1,
     
    136136    {
    137137      .sDeviceName = "/dev/ttyS2",
    138       .deviceType = SERIAL_NS16550,
     138      .deviceType = SERIAL_NS16550_WITH_FDR,
    139139      .pDeviceFns = &ns16550_fns,
    140140      .deviceProbe = lpc24xx_uart_probe_2,
     
    157157    {
    158158      .sDeviceName = "/dev/ttyS3",
    159       .deviceType = SERIAL_NS16550,
     159      .deviceType = SERIAL_NS16550_WITH_FDR,
    160160      .pDeviceFns = &ns16550_fns,
    161161      .deviceProbe = lpc24xx_uart_probe_3,
  • c/src/libchip/serial/ns16550.c

    rc34bb0d rc39148d  
    9696};
    9797
     98static uint32_t NS16550_GetBaudDivisor(const console_tbl *c, uint32_t baud)
     99{
     100  uint32_t clock = c->ulClock;
     101  uint32_t baudDivisor = (clock != 0 ? clock : 115200) / (baud * 16);
     102
     103  if (c->deviceType == SERIAL_NS16550_WITH_FDR) {
     104    uint32_t fractionalDivider = 0x10;
     105    uint32_t err = baud;
     106    uint32_t mulVal;
     107    uint32_t divAddVal;
     108
     109    clock /= 16 * baudDivisor;
     110    for (mulVal = 1; mulVal < 16; ++mulVal) {
     111      for (divAddVal = 0; divAddVal < mulVal; ++divAddVal) {
     112        uint32_t actual = (mulVal * clock) / (mulVal + divAddVal);
     113        uint32_t newErr = actual > baud ? actual - baud : baud - actual;
     114
     115        if (newErr < err) {
     116          err = newErr;
     117          fractionalDivider = (mulVal << 4) | divAddVal;
     118        }
     119      }
     120    }
     121
     122    (*c->setRegister)(
     123      c->ulCtrlPort1,
     124      NS16550_FRACTIONAL_DIVIDER,
     125      fractionalDivider
     126    );
     127  }
     128
     129  return baudDivisor;
     130}
     131
    98132/*
    99133 *  ns16550_init
     
    134168  /* Set the divisor latch and set the baud rate. */
    135169
    136   ulBaudDivisor = NS16550_Baud(
    137     (uint32_t) c->ulClock,
    138     (uint32_t) ((uintptr_t)c->pDeviceParams)
    139   );
     170  ulBaudDivisor = NS16550_GetBaudDivisor(c, (uintptr_t) c->pDeviceParams);
    140171  ucDataByte = SP_LINE_DLAB;
    141172  (*setReg)(pNS16550, NS16550_LINE_CONTROL, ucDataByte);
     
    414445  getRegister_f           getReg;
    415446  uint32_t                Irql;
    416 
    417   pNS16550 = Console_Port_Tbl[minor]->ulCtrlPort1;
    418   setReg   = Console_Port_Tbl[minor]->setRegister;
    419   getReg   = Console_Port_Tbl[minor]->getRegister;
     447  const console_tbl      *c = Console_Port_Tbl [minor];
     448
     449  pNS16550 = c->ulCtrlPort1;
     450  setReg   = c->setRegister;
     451  getReg   = c->getRegister;
    420452
    421453  /*
     
    423455   */
    424456
    425   baud_requested = t->c_cflag & CBAUD;
    426   if (!baud_requested)
    427     baud_requested = B9600;              /* default to 9600 baud */
    428 
    429   ulBaudDivisor = NS16550_Baud(
    430     (uint32_t) Console_Port_Tbl[minor]->ulClock,
    431     rtems_termios_baud_to_number(baud_requested)
    432   );
     457  baud_requested = rtems_termios_baud_to_number(t->c_cflag);
     458  ulBaudDivisor = NS16550_GetBaudDivisor(c, baud_requested);
    433459
    434460  ucLineControl = 0;
  • c/src/libchip/serial/ns16550_p.h

    rc34bb0d rc39148d  
    5050#define NS16550_MODEM_STATUS     6
    5151#define NS16550_SCRATCH_PAD      7
     52#define NS16550_FRACTIONAL_DIVIDER 10
    5253
    5354/*
     
    105106#define SEVEN_BITS 0x2                  /* seven bits per character */
    106107#define EIGHT_BITS 0x3                  /* eight bits per character */
    107 
    108 /*
    109  * Line speed divisor definition.
    110  */
    111 
    112 #define NS16550_Baud(_clock, _baud_rate) \
    113   ((((_clock) == 0) ? 115200 : (_clock))/(_baud_rate*16))
    114108
    115109/*
  • c/src/libchip/serial/serial.h

    rc34bb0d rc39148d  
    105105  SERIAL_MC68681,              /* Motorola MC68681 or Exar 88681 */
    106106  SERIAL_NS16550,              /* National Semiconductor NS16550 */
     107  SERIAL_NS16550_WITH_FDR,     /* National Semiconductor NS16550
     108                                  with Fractional Divider Register (FDR) */
    107109  SERIAL_Z85C30,               /* Zilog Z85C30 */
    108110  SERIAL_CUSTOM                /* BSP specific driver */
Note: See TracChangeset for help on using the changeset viewer.