static void ffuart_init(int minor) { console_tbl *console_entry; ffuart_reg_t *ffuart; unsigned int divisor; console_entry = BSP_get_uart_from_minor(minor); if (console_entry == NULL) { return; } ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1; ffuart->lcr |= DLAB; /*Set the Bound*/ ffuart->lcr |= DLAB; divisor = FREQUENCY_UART / (115200*16); ffuart->rbr = divisor & 0xff; ffuart->ier = (divisor >> 8)&0xff; /*Disable FIFO*/ ffuart->iir = 0; ffuart->lcr &=~DLAB; /*Enable UART*/ ffuart->ier = 0x40; ffuart->lcr = EIGHT_BITS_NOPARITY_1STOPBIT; }
/* Set up the UART. */ static void dbgu_init(int minor) { console_tbl *console_entry; at91rm9200_dbgu_regs_t *dbgu; console_entry = BSP_get_uart_from_minor(minor); if (console_entry == NULL) { return; } dbgu = (at91rm9200_dbgu_regs_t *)console_entry->ulCtrlPort1; /* Clear error bits, and reset */ dbgu->cr = (DBGU_CR_RSTSTA | DBGU_CR_RSTTX | DBGU_CR_RSTRX); /* Clear pending interrupts */ dbgu->idr = DBGU_INT_ALL; dbgu->imr = 0; /* Set port to no parity, no loopback */ dbgu->mr = DBGU_MR_PAR_NONE | DBGU_MR_CHMODE_NORM; /* Set the baud rate */ dbgu->brgr = (at91rm9200_get_mck() / 16) / BSP_get_baud(); /* Enable the DBGU */ dbgu->cr = (DBGU_CR_TXEN | DBGU_CR_RXEN); }
/* * Write buffer to UART * * return 1 on success, -1 on error */ static ssize_t dbgu_write(int minor, const char *buf, size_t len) { int i, x; char c; console_tbl *console_entry; at91rm9200_dbgu_regs_t *dbgu; console_entry = BSP_get_uart_from_minor(minor); if (console_entry == NULL) { return -1; } dbgu = (at91rm9200_dbgu_regs_t *)console_entry->ulCtrlPort1; for (i = 0; i < len; i++) { /* Wait for fifo to have room */ while(1) { if (dbgu->sr & DBGU_INT_TXRDY) { break; } } c = (char) buf[i]; dbgu->thr = c; /* the TXRDY flag does not seem to update right away (is this true?) */ /* so we wait a bit before continuing */ for (x = 0; x < 100; x++) { dbg_dly++; /* using a global so this doesn't get optimized out */ } } return 1; }
at91rm9200_usart_regs_t *usart_get_base(int minor) { console_tbl *console_entry; at91rm9200_usart_regs_t *port; console_entry = BSP_get_uart_from_minor(minor); if (console_entry == NULL) return 0; port = (at91rm9200_usart_regs_t *) console_entry->ulCtrlPort1; //printk( "minor=%d entry=%p port=%p\n", minor, console_entry, port ); return port; }
/* * Write buffer to UART * * return 1 on success, -1 on error */ static ssize_t ffuart_write(int minor, const char *buf, size_t len) { size_t i, x; char c; console_tbl *console_entry; ffuart_reg_t *ffuart; console_entry = BSP_get_uart_from_minor(minor); if (console_entry == NULL) { return -1; } ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1; for (i = 0; i < len; i++) { while(1) { if (ffuart->lsr & SEND_EMPTY) { break; } } c = (char) buf[i]; #if ON_SKYEYE != 1 if(c=='\n'){ ffuart->rbr = '\r'; for (x = 0; x < 100; x++) { dbg_dly++; /* using a global so this doesn't get optimized out */ } while(1){ if(ffuart->lsr & SEND_EMPTY){ break; } } } #endif ffuart->rbr = c; /* the TXRDY flag does not seem to update right away (is this true?) */ /* so we wait a bit before continuing */ for (x = 0; x < 100; x++) { dbg_dly++; /* using a global so this doesn't get optimized out */ } } return 1; }
/* * Read one character from UART. * * return -1 if there's no data, otherwise return * the character in lowest 8 bits of returned int. */ static int ffuart_read(int minor) { char c; console_tbl *console_entry; ffuart_reg_t *ffuart; console_entry = BSP_get_uart_from_minor(minor); if (console_entry == NULL) { return -1; } ffuart = (ffuart_reg_t *)console_entry->ulCtrlPort1; if (!(ffuart->lsr & FULL_RECEIVE)) { return -1; } c = ffuart->rbr & 0xff; return c; }
/* * Read one character from UART. * * return -1 if there's no data, otherwise return * the character in lowest 8 bits of returned int. */ static int dbgu_read(int minor) { char c; console_tbl *console_entry; at91rm9200_dbgu_regs_t *dbgu; console_entry = BSP_get_uart_from_minor(minor); if (console_entry == NULL) { return -1; } dbgu = (at91rm9200_dbgu_regs_t *)console_entry->ulCtrlPort1; if (!(dbgu->sr & DBGU_INT_RXRDY)) { return -1; } c = dbgu->rhr & 0xff; return c; }