whitespace changes Reference: /n/atom/patch/applied/piuartminiws Date: Sun Jan 3 19:32:12 CET 2016 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/bcm/uartmini.c Sun Jan 3 19:32:03 2016 +++ /sys/src/9/bcm/uartmini.c Sun Jan 3 19:32:04 2016 @@ -1,3 +1,7 @@ +/* + * bcm2835 mini uart (UART1) + */ + #include "u.h" #include "../port/lib.h" #include "../port/error.h" @@ -6,10 +10,6 @@ #include "fns.h" #include "io.h" -/* - * bcm2835 mini uart (UART1) - */ - #define GPIOREGS (VIRTIO+0x200000) #define AUXREGS (VIRTIO+0x215000) #define OkLed 16 @@ -41,30 +41,30 @@ /* AUX regs */ enum { - Irq = 0x00>>2, + Irq = 0x00>>2, UartIrq = 1<<0, - Enables = 0x04>>2, + Enables = 0x04>>2, UartEn = 1<<0, - MuIo = 0x40>>2, - MuIer = 0x44>>2, + MuIo = 0x40>>2, + MuIer = 0x44>>2, RxIen = 1<<0, TxIen = 1<<1, - MuIir = 0x48>>2, - MuLcr = 0x4c>>2, + MuIir = 0x48>>2, + MuLcr = 0x4c>>2, Bitsmask= 3<<0, Bits7 = 2<<0, Bits8 = 3<<0, - MuMcr = 0x50>>2, + MuMcr = 0x50>>2, RtsN = 1<<1, - MuLsr = 0x54>>2, + MuLsr = 0x54>>2, TxDone = 1<<6, TxRdy = 1<<5, RxRdy = 1<<0, - MuCntl = 0x60>>2, + MuCntl = 0x60>>2, CtsFlow = 1<<3, TxEn = 1<<1, RxEn = 1<<0, - MuBaud = 0x68>>2, + MuBaud = 0x68>>2, }; extern PhysUart miniphysuart; @@ -129,18 +129,16 @@ { Uart *uart; u32int *ap; - int c; uart = arg; ap = (u32int*)uart->regs; coherence(); - if(0)if((ap[Irq]&UartIrq) == 0){ + if(0 && (ap[Irq] & UartIrq) == 0) return; - } - if(ap[MuLsr]&TxRdy) + if(ap[MuLsr] & TxRdy) uartkick(uart); - if(ap[MuLsr]&RxRdy){ + if(ap[MuLsr] & RxRdy){ if(uart->console){ if(uart->opens == 1) uart->putc = kbdcr2nl; @@ -148,9 +146,8 @@ uart->putc = nil; } do{ - c = ap[MuIo]&0xFF; - uartrecv(uart, c); - }while(ap[MuLsr]&RxRdy); + uartrecv(uart, ap[MuIo] & 0xFF); + }while(ap[MuLsr] & RxRdy); } coherence(); } @@ -181,7 +178,7 @@ ap[MuIir] = 6; ap[MuLcr] = Bits8; ap[MuCntl] = TxEn|RxEn; - ap[MuBaud] = 250000000/(115200*8) - 1; + ap[MuBaud] = uart->freq/(115200*8) - 1; if(ie){ intrenable(IRQaux, interrupt, uart, 0, "uart"); ap[MuIer] = RxIen|TxIen; @@ -208,12 +205,12 @@ if(uart->blocked) return; coherence(); - while(ap[MuLsr]&TxRdy){ + while(ap[MuLsr] & TxRdy){ if(uart->op >= uart->oe && uartstageoutput(uart) == 0) break; ap[MuIo] = *(uart->op++); } - if(ap[MuLsr]&TxDone) + if(ap[MuLsr] & TxDone) ap[MuIer] &= ~TxIen; else ap[MuIer] |= TxIen; @@ -235,7 +232,7 @@ ap = (u32int*)uart->regs; if(uart->freq == 0 || n <= 0) return -1; - ap[MuBaud] = (uart->freq+4*n-1)/(8*n) - 1; + ap[MuBaud] = (uart->freq + 4*n - 1) / (8 * n) - 1; uart->baud = n; return 0; } @@ -257,7 +254,7 @@ default: return -1; } - ap[MuLcr] = (ap[MuLcr]&~Bitsmask) | set; + ap[MuLcr] = (ap[MuLcr] & ~Bitsmask) | set; uart->bits = n; return 0; } @@ -347,10 +344,10 @@ u32int *ap; ap = (u32int*)AUXREGS; - while((ap[MuLsr]&TxRdy) == 0) + while((ap[MuLsr] & TxRdy) == 0) ; ap[MuIo] = c; - while((ap[MuLsr]&TxRdy) == 0) + while((ap[MuLsr] & TxRdy) == 0) ; } @@ -358,13 +355,11 @@ getc(Uart*) { u32int *ap; - int c; ap = (u32int*)AUXREGS; - while((ap[MuLsr]&RxRdy) == 0) + while((ap[MuLsr] & RxRdy) == 0) ; - c = ap[MuIo]&0xFF; - return c; + return ap[MuIo] & 0xFF; } void