summaryrefslogtreecommitdiff
path: root/cpu/bf533/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpu/bf533/serial.c')
-rw-r--r--cpu/bf533/serial.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/cpu/bf533/serial.c b/cpu/bf533/serial.c
index 7b43ffd..eb55205 100644
--- a/cpu/bf533/serial.c
+++ b/cpu/bf533/serial.c
@@ -51,22 +51,21 @@
#include <asm/uaccess.h>
#include "bf533_serial.h"
-DECLARE_GLOBAL_DATA_PTR;
-
unsigned long pll_div_fact;
void calc_baud(void)
{
unsigned char i;
- int temp;
+ int temp;
+ u_long sclk = get_sclk();
- for(i = 0; i < sizeof(baud_table)/sizeof(int); i++) {
- temp = CONFIG_SCLK_HZ/(baud_table[i]*8);
- if ( temp && 0x1 == 1 ) {
+ for (i = 0; i < sizeof(baud_table) / sizeof(int); i++) {
+ temp = sclk / (baud_table[i] * 8);
+ if ((temp & 0x1) == 1) {
temp++;
}
- temp = temp/2;
- hw_baud_table[i].dl_high = (temp >> 8)& 0xFF;
+ temp = temp / 2;
+ hw_baud_table[i].dl_high = (temp >> 8) & 0xFF;
hw_baud_table[i].dl_low = (temp) & 0xFF;
}
}
@@ -74,6 +73,7 @@ void calc_baud(void)
void serial_setbrg(void)
{
int i;
+ DECLARE_GLOBAL_DATA_PTR;
calc_baud();
@@ -84,29 +84,29 @@ void serial_setbrg(void)
/* Enable UART */
*pUART_GCTL |= UART_GCTL_UCEN;
- asm("ssync;");
+ __builtin_bfin_ssync();
/* Set DLAB in LCR to Access DLL and DLH */
ACCESS_LATCH;
- asm("ssync;");
+ __builtin_bfin_ssync();
*pUART_DLL = hw_baud_table[i].dl_low;
- asm("ssync;");
+ __builtin_bfin_ssync();
*pUART_DLH = hw_baud_table[i].dl_high;
- asm("ssync;");
+ __builtin_bfin_ssync();
/* Clear DLAB in LCR to Access THR RBR IER */
ACCESS_PORT_IER;
- asm("ssync;");
+ __builtin_bfin_ssync();
/* Enable ERBFI and ELSI interrupts
- * to poll SIC_ISR register*/
+ * to poll SIC_ISR register*/
*pUART_IER = UART_IER_ELSI | UART_IER_ERBFI | UART_IER_ETBEI;
- asm("ssync;");
+ __builtin_bfin_ssync();
/* Set LCR to Word Lengh 8-bit word select */
*pUART_LCR = UART_LCR_WLS8;
- asm("ssync;");
+ __builtin_bfin_ssync();
return;
}
@@ -119,8 +119,7 @@ int serial_init(void)
void serial_putc(const char c)
{
- if ((*pUART_LSR) & UART_LSR_TEMT)
- {
+ if ((*pUART_LSR) & UART_LSR_TEMT) {
if (c == '\n')
serial_putc('\r');
@@ -148,17 +147,16 @@ int serial_getc(void)
int ret;
/* Poll for RX Interrupt */
- while (!((isr_val = *(volatile unsigned long *)SIC_ISR) & IRQ_UART_RX_BIT));
+ while (!((isr_val =
+ *(volatile unsigned long *)SIC_ISR) & IRQ_UART_RX_BIT)) ;
asm("csync;");
uart_lsr_val = *pUART_LSR; /* Clear status bit */
uart_rbr_val = *pUART_RBR; /* getc() */
if (isr_val & IRQ_UART_ERROR_BIT) {
- ret = -1;
- }
- else
- {
+ ret = -1;
+ } else {
ret = uart_rbr_val & 0xff;
}
@@ -180,10 +178,10 @@ static void local_put_char(char ch)
save_and_cli(flags);
/* Poll for TX Interruput */
- while (!((isr_val = *pSIC_ISR) & IRQ_UART_TX_BIT));
+ while (!((isr_val = *pSIC_ISR) & IRQ_UART_TX_BIT)) ;
asm("csync;");
- *pUART_THR = ch; /* putc() */
+ *pUART_THR = ch; /* putc() */
if (isr_val & IRQ_UART_ERROR_BIT) {
printf("?");
@@ -191,5 +189,5 @@ static void local_put_char(char ch)
restore_flags(flags);
- return ;
+ return;
}