void UartInit(void)
{
	int freq, div;
	extern uint32_t serial_inited;

	ath_sys_frequency();

	freq = ath_uart_freq;

	div = freq / (ATH_CONSOLE_BAUD * 16);

	/* set DIAB bit */
	UART_WRITE(OFS_LINE_CONTROL, 0x80);

	/* set divisor */
	UART_WRITE(OFS_DIVISOR_LSB, (div & 0xff));
	UART_WRITE(OFS_DIVISOR_MSB, (div >> 8) & 0xff);

	// UART16550_WRITE(OFS_DIVISOR_LSB, 0x61);
	// UART16550_WRITE(OFS_DIVISOR_MSB, 0x03);

	/* clear DIAB bit */
	UART_WRITE(OFS_LINE_CONTROL, 0x00);

	/* set data format */
	UART_WRITE(OFS_DATA_FORMAT, 0x3);

	UART_WRITE(OFS_INTR_ENABLE, 0);

	serial_inited = 1;
}
Esempio n. 2
0
void uart_init()
{
     U8 reg;

     /* Map the UART area */
     mm_map_region(UART_VBASE, UART_PBASE, UART_ERPN, 1024, TLB_PERM_SR|TLB_PERM_SW, TLB_ATTR_GUARDED|TLB_ATTR_CACHE_INHIBIT, 0);

     /* Enable DLAB */
     reg = UART_READ(UART0_LCR);
     reg |= UART_LCR_DLAB_ENABLE;
     UART_WRITE(UART0_LCR, reg);

     /* Write divisor values */
     UART_WRITE(UART0_DLL, UART_DLL_9600);
     UART_WRITE(UART0_DLM, UART_DLM_9600);

     /* Disable DLAB */
     reg = UART_READ(UART0_LCR);
     reg &= UART_LCR_DLAB_MASK;
     UART_WRITE(UART0_LCR, reg);

     /* Set serial port parameters */
     reg = UART_READ(UART0_LCR);
     reg |= UART_LCR_8BIT_WORD|UART_LCR_PARITY_ODD;
     UART_WRITE(UART0_LCR, reg);

     uartInitDone = 1;
     INFO("UART initilized");
}
Esempio n. 3
0
/* Used by sbrk(), printf(), etc */
int write(int file, const void *ptr, size_t len)
{
     U32 written = 0;
     U8 *cPtr = (U8 *)ptr;
     
     if( uartInitDone == 0 )
     {
	  errno = EIO;
	  return EERROR;
     }

     /* We only support STDOUT here atm */
     if( file != STDOUT_FILENO )
	  return len;

     if( len <= 0 )
     {
	  errno = EINVAL;
	  return EERROR;
     }

     do {
	  UART_WAIT(UART0_LSR);
	  UART_WRITE(UART0_THR, *cPtr);
	  if(*cPtr =='\n')
	  {
	       UART_WAIT(UART0_LSR);
	       UART_WRITE(UART0_THR, '\r');
	  }
	  cPtr++;
     } while(++written != len);

     return written;
}
Esempio n. 4
0
static int au1x00_kgdb_init(void)
{
	if (UART_READ(UART_MOD_CNTRL)  != (UART_MCR_DTR | UART_MCR_RTS))
		UART_WRITE(UART_MOD_CNTRL, UART_MCR_DTR | UART_MCR_RTS);

	/* disable interrupts */
	UART_WRITE(UART_IER, 0);

	if (!get_au1x00_uart_baud_base())
		cal_r4koff();

	/* set up baud rate */
	{
		u32 divisor;

		/* set divisor */
		divisor = get_au1x00_uart_baud_base() / kgdb_au1x00_baud;
		UART_WRITE(UART_CLK, divisor & 0xffff);
	}

	/* set data format */
	UART_WRITE(UART_LCR, UART_LCR_WLEN8);

	return 0;
}
Esempio n. 5
0
//=========================================================================
//----- (00006738) --------------------------------------------------------
__myevic__ void UART0_Cout( uint8_t c )
{
	UART_WAIT_TX_EMPTY( UART0 );
	UART_WRITE( UART0, c );

	if ( c == '\n' )
	{
		UART_WAIT_TX_EMPTY( UART0 );
		UART_WRITE( UART0, '\r' );
	}
}
Esempio n. 6
0
// Transmitter Interrupt Service Routine
void UART_INTFUNC(UART_USED, TX, no_auto_psv)(void)
{
	int i;
	// Clear Interrupt flag
	UART_CLR_TXFLAG(UART_USED);

	switch (QUEBUF_LEN(TXB)) {
		case 0:  ++U_(UART_USED, txevt);
				 i = U_TXI_END; break;
		case 1:  i = U_TXI_READY; break;
		default: i = U_TXI_EMPTY; // We'll fill FIFO
	} UART_SET_TXI(UART_USED, i);

	while (!QUEBUF_EMPTY(TXB))
	{ // Load TX queue and fill TX FIFO
		if (UART_CAN_WRITE(UART_USED)) {
			_QUEBUF_POP(TXB, i);
			UART_WRITE(UART_USED, i);
		} else break; // FIFO is full
	}

	if (QUEBUF_EMPTY(TXB)) DISPATCH();

#ifdef __MPLAB_SIM // Poll error bits and set ERFLAG
 if (UART_IS_RXERR(UART_USED)) UART_SET_ERFLAG(UART_USED);
#endif // SIM doesn't check receiver errors, but set OERR
}
Esempio n. 7
0
int vtsend_reset(vtsend_t *p)
{
    char buf[2];
    buf[0] = ESC;
    buf[1] = 'c';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 8
0
/*---------------------------------------------------------------------------------------------------------*/
void RS485_SendAddressByte(uint8_t u8data)
{
    /* Set UART parity as MARK and skip baud rate setting */
    UART_SetLine_Config(UART1, 0, UART_WORD_LEN_8, UART_PARITY_MARK, UART_STOP_BIT_1);

    /* Send data */
    UART_WRITE(UART1, u8data);
}
Esempio n. 9
0
void board_putc(int ch)
{
	while ((UART_READ(UART_REG_FLAG) & UART_FLAG_TXFE) == 0);

	UART_WRITE(UART_REG_DATA, ch);

	while ((UART_READ(UART_REG_FLAG) & UART_FLAG_TXFE) == 0);
}
Esempio n. 10
0
int vtsend_cursor_position_restore(vtsend_t *p)
{
    char buf[3];
    buf[0] = ESC;
    buf[1] = '[';
    buf[2] = 'u';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 11
0
void UartPut(u8 byte)
{
	if (!serial_inited) {
		serial_inited = 1;
		UartInit();
	}

	while (((UART_READ(OFS_LINE_STATUS)) & 0x20) == 0x0) ;
	UART_WRITE(OFS_SEND_BUFFER, byte);
}
Esempio n. 12
0
int vtsend_erase_line(vtsend_t *p)
{
    char buf[4];
    buf[0] = ESC;
    buf[1] = '[';
    buf[2] = '2';
    buf[3] = 'K';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 13
0
int vtsend_set_attribute(vtsend_t *p, const int attr)
{
    char buf[5];
    buf[0] = ESC;
    buf[1] = '[';
    buf[2] = '0' + ((attr) / 10);
    buf[3] = '0' + ((attr) % 10);
    buf[4] = 'm';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 14
0
int vtsend_cursor_backward(vtsend_t *p, const int n)
{
    char buf[5];
    buf[0] = ESC;
    buf[1] = '[';
    buf[2] = '0' + (n / 10);
    buf[3] = '0' + (n % 10);
    buf[4] = 'D';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 15
0
int vtsend_set_color_background(vtsend_t *p, const int color)
{
    char buf[5];
    buf[0] = ESC;
    buf[1] = '[';
    buf[2] = '0' + ((40 + color) / 10);
    buf[3] = '0' + ((40 + color) % 10);
    buf[4] = 'm';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 16
0
static void uart_init(void)
{
#if 0
	unsigned int t;

	/* disable uart */
	UART_WRITE(UART_REG_CTRL, 0);

	/* keep current baud rate */
	t = UART_READ(UART_REG_LCRM);
	UART_WRITE(UART_REG_LCRM, t);
	t = UART_READ(UART_REG_LCRL);
	UART_WRITE(UART_REG_LCRL, t);

	/* keep data, stop, and parity bits, but disable FIFO */
	t = UART_READ(UART_REG_LCRH);
	t &= ~(UART_LCRH_FEN);
	UART_WRITE(UART_REG_LCRH, t );

	/* clear error bits */
	UART_WRITE(UART_REG_ECR, 0xFF);

	/* enable uart, and disable interrupts */
	UART_WRITE(UART_REG_CTRL, UART_CTRL_EN);
#endif
}
Esempio n. 17
0
int vtsend_draw_box(
        vtsend_t *p,
        const int x1, const int y1, const int x2, const int y2)
{
    int i;

    vtsend_cursor_position(p, x1, y1);
    for (i = x1; i <= x2; i++) {
        UART_WRITE(p, " ", 1);
    }
    vtsend_cursor_position(p, x1, y2);
    for (i = x1; i <= x2; i++) {
        UART_WRITE(p, " ", 1);
    }
    for (i = y1; i <= y2; i++) {
        vtsend_cursor_position(p, x1, i);
        UART_WRITE(p, " ", 1);
        vtsend_cursor_position(p, x2, i);
        UART_WRITE(p, " ", 1);
    }
    return 0;
}
Esempio n. 18
0
int vtsend_fill_box(
        vtsend_t *p,
        const int x1, const int y1, const int x2, const int y2)
{
    int i, j;
    for (i = y1; i <= y2; i++) {
        vtsend_cursor_position(p, x1, i);
        for (j = x1; j <= x2; j++) {
            UART_WRITE(p, " ", 1);
        }
    }
    return 0;
}
Esempio n. 19
0
int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom)
{
    char buf[8];
    buf[0] = ESC;
    buf[1] = '[';
    buf[2] = '0' + (top / 10);
    buf[3] = '0' + (top % 10);
    buf[4] = ';';
    buf[5] = '0' + (bottom / 10);
    buf[6] = '0' + (bottom % 10);
    buf[7] = 'r';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 20
0
int vtsend_cursor_position(vtsend_t *p, const int column, const int line)
{
    char buf[8];
    buf[0] = ESC;
    buf[1] = '[';
    buf[2] = '0' + (line / 10);
    buf[3] = '0' + (line % 10);
    buf[4] = ';';
    buf[5] = '0' + (column / 10);
    buf[6] = '0' + (column % 10);
    buf[7] = 'H';
    UART_WRITE(p, buf, sizeof(buf));
    return 0;
}
Esempio n. 21
0
int vtsend_set_cursor(vtsend_t *p, const int visible)
{
    if (visible) {
        char buf[6];
        buf[0] = ESC;
        buf[1] = '[';
        buf[2] = '?';
        buf[3] = '2';
        buf[4] = '5';
        buf[5] = 'h';
        UART_WRITE(p, buf, sizeof(buf));
    } else {
        char buf[6];
        buf[0] = ESC;
        buf[1] = '[';
        buf[2] = '?';
        buf[3] = '2';
        buf[4] = '5';
        buf[5] = 'l';
        UART_WRITE(p, buf, sizeof(buf));
    }
    return 0;
}
Esempio n. 22
0
void UART0_IRQHandler(void) {
    uint16_t i = tail_.load(std::memory_order_relaxed);
    if(i == head_.load(std::memory_order_acquire)) {
        if((UART0->FSR & UART_FSR_TE_FLAG_Msk) == 0)
            NVIC_DisableIRQ(UART0_IRQn);
        return;
    }
    while((UART0->FSR & UART_FSR_TX_FULL_Msk) == 0) {
        i = (i + 1) % Tx_BUFFER_SIZE;
        UART_WRITE(UART0, txBuffer_[i]);
        tail_.store(i, std::memory_order_release);
        if(i == head_.load(std::memory_order_acquire)) {
            break;
        }
    }
}
Esempio n. 23
0
/*---------------------------------------------------------------------------------------------------------*/
void UART_TEST_HANDLE()
{
    uint8_t u8InChar = 0xFF;
    uint32_t u32IntSts = UART0->ISR;

    if(u32IntSts & UART_ISR_RDA_INT_Msk)
    {
        printf("\nInput:");

        /* Get all the input characters */
        while(UART_IS_RX_READY(UART0))
        {
            /* Get the character from UART Buffer */
            u8InChar = UART_READ(UART0);

            printf("%c ", u8InChar);

            if(u8InChar == '0')
            {
                g_bWait = FALSE;
            }

            /* Check if buffer full */
            if(g_u32comRbytes < RXBUFSIZE)
            {
                /* Enqueue the character */
                g_u8RecData[g_u32comRtail] = u8InChar;
                g_u32comRtail = (g_u32comRtail == (RXBUFSIZE - 1)) ? 0 : (g_u32comRtail + 1);
                g_u32comRbytes++;
            }
        }
        printf("\nTransmission Test:");
    }

    if(u32IntSts & UART_ISR_THRE_INT_Msk)
    {
        uint16_t tmp;
        tmp = g_u32comRtail;
        if(g_u32comRhead != tmp)
        {
            u8InChar = g_u8RecData[g_u32comRhead];
            UART_WRITE(UART0, u8InChar);
            g_u32comRhead = (g_u32comRhead == (RXBUFSIZE - 1)) ? 0 : (g_u32comRhead + 1);
            g_u32comRbytes--;
        }
    }
}
Esempio n. 24
0
/*---------------------------------------------------------------------------------------------------------*/
void AutoFlow_FunctionTxTest()
{
    uint32_t u32i;

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|     Pin Configure                                         |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  ______                                            _____  |\n");
    printf("| |      |                                          |     | |\n");
    printf("| |Master|--UART1_TXD(PB.3)  <==>  UART1_RXD(PB.2)--|Slave| |\n");
    printf("| |      |--UART1_nCTS(PB.4) <==> UART1_nRTS(PB.8)--|     | |\n");
    printf("| |______|                                          |_____| |\n");
    printf("|                                                           |\n");
    printf("+-----------------------------------------------------------+\n");

    printf("\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|       AutoFlow Function Test (Master)                     |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  Description :                                            |\n");
    printf("|    The sample code needs two boards. One is Master and    |\n");
    printf("|    the other is slave. Master will send 1k bytes data     |\n");
    printf("|    to slave. Slave will check if received data is correct |\n");
    printf("|    after getting 1k bytes data.                           |\n");
    printf("|    Press any key to start...                              |\n");
    printf("+-----------------------------------------------------------+\n");
    GetChar();

    /* Enable RTS and CTS autoflow control */
    UART_EnableFlowCtrl(UART1);

    /* Send 1k bytes data */
    for(u32i = 0; u32i < RXBUFSIZE; u32i++)
    {
        /* Send 1 byte data */
        UART_WRITE(UART1, u32i & 0xFF);

        /* Wait if Tx FIFO is full */
        while(UART_IS_TX_FULL(UART1));
    }

    printf("\n Transmit Done\n");

}
Esempio n. 25
0
void ath_serial_out(int offset, int value)
{
	UART_WRITE(offset, (u8) value);
}
Esempio n. 26
0
void prom_putchar(char c)
{
	UART_WRITE(c, UART01x_DR);
	while ((UART_READ(UART01x_FR) & UART01x_FR_TXFF) != 0)
		;
}
Esempio n. 27
0
/*---------------------------------------------------------------------------------------------------------*/
void AutoFlow_FunctionTest()
{
    uint8_t u8Item;
    uint32_t u32i;
    printf("+-----------------------------------------------------------+\n");
    printf("|     Pin Configure                                         |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  _______                                      _______     |\n");
    printf("| |       |                                    |       |    |\n");  
    printf("| |Master |---TXD0(pin46) <====> RXD0(pin45)---| Slave |    |\n");  
    printf("| |       |---RTS0(pin37) <====> CTS0(pin38)---|       |    |\n");  
    printf("| |_______|---CTS0(pin38) <====> RTS0(pin37)---|_______|    |\n");  
    printf("|                                                           |\n");
    printf("+-----------------------------------------------------------+\n\n");  

    /* Set RTS Trigger Level */
    UART->MCR |= UART_RTS_IS_HIGH_LEV_TRG;
    UART->FCR = (UART->FCR &~ UART_FCR_RTS_TRI_LEV_Msk) | UART_FCR_RTS_TRI_LEV_14BYTES;
    
    /* Enable RTS and CTS autoflow control */
    UART->IER |= UART_IER_AUTO_RTS_EN_Msk | UART_IER_AUTO_CTS_EN_Msk;
    
    printf("+-----------------------------------------------------------+\n");
    printf("|       AutoFlow Function Test                              |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  Description :                                            |\n");
    printf("|    The sample code needs two boards. One is Master and    |\n");
    printf("|    the other is slave. Master will send 1k bytes data     |\n");
    printf("|    to slave.Slave will check if received data is correct  |\n");
    printf("|    after getting 1k bytes data.                           |\n");
    printf("|  Please select Master or Slave test                       |\n");
    printf("|  [0] Master    [1] Slave                                  |\n");
    printf("+-----------------------------------------------------------+\n\n");
    u8Item = getchar();
    
    
    if(u8Item=='0')
    {
        for(u32i=0;u32i<(RXBUFSIZE-1);u32i++)
        {
            UART_WRITE(UART,((u32i+1)&0xFF));

            /* Slave will control RTS pin*/
            while(UART->MCR & UART_MCR_RTS_ST_Msk);
        }
        printf("\n Transmit Done\n");
    }
    else
    {
        g_i32pointer = 0;
    
        /* Enable RDA\RLS\RTO Interrupt  */
        UART_ENABLE_INT(UART, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));

        /* Set RX Trigger Level = 8 */
        UART->FCR = (UART->FCR &~ UART_FCR_RFITL_Msk) | UART_FCR_RFITL_8BYTES;

        /* Set Timeout time 0x3E bit-time */
        UART_SetTimeoutCnt(UART,0x3E);
        
        NVIC_EnableIRQ(UART_IRQn);

        printf("Starting to recevice %d bytes data...\n", RXBUFSIZE);
        
        while(g_i32pointer<(RXBUFSIZE-1))
        {
            printf("%d\r",g_i32pointer);
        }

        /* Compare Data */
        for(u32i=0;u32i!=(RXBUFSIZE-1);u32i++)
        {
            if(g_u8RecData[u32i] != ((u32i+1)&0xFF) )
            {
                printf("Compare Data Failed\n");
                while(1);
            }
        }
        printf("\n Receive OK & Check OK\n");
    }

    NVIC_DisableIRQ(UART_IRQn);

    UART_DISABLE_INT(UART, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
}
Esempio n. 28
0
static void au1x00_kgdb_write_char(int byte)
{
	while (!(UART_READ(UART_LSR) & UART_LSR_TEMT));

	UART_WRITE(UART_TX, byte & 0xff);
}
Esempio n. 29
0
void board_putc(int ch)
{
	while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
	UART_WRITE(UART_TX, ch);
	while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
}
Esempio n. 30
0
void prom_putchar(unsigned char ch)
{
	while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
	UART_WRITE(UART_TX, ch);
	while (((UART_READ(UART_LSR)) & UART_LSR_THRE) == 0);
}