0
|
1 /*
|
|
2 * pl011.c
|
|
3 *
|
|
4 * Created on: Nov 20, 2016
|
|
5 * Author: Mahdi Amiri
|
|
6 */
|
|
7 #include <fvp.h>
|
|
8 #include <types.h>
|
|
9 #include <defs.h>
|
|
10
|
|
11 uint uart_lock; //Mutex lock
|
|
12
|
|
13 void uartinit_fvp(){
|
|
14 /* Enable pl011 interrupts */
|
|
15 *(volatile uint*) FVP_PL011_UARTIMSC = FVP_PL011_UARTIMSC_RXIM;
|
|
16
|
|
17 /* Enable pl011 controller */
|
|
18 *(volatile uint*) FVP_PL011_UARTCR =
|
|
19 *(volatile uint*) FVP_PL011_UARTCR | FVP_PL011_UARTCR_UARTEN | FVP_PL011_UARTCR_TXE | FVP_PL011_UARTCR_RXE;
|
|
20 //outw(UARTCR,inw(UARTCR) | UARTCR_UARTEN | UARTCR_TXE | UARTCR_RXE);
|
|
21 //enable_irq(37,1);
|
|
22 uart_lock=0; // Open Mutex lock
|
|
23 }
|
|
24
|
|
25 void uartputc_fvp(uint c)
|
|
26 {
|
|
27 if(c=='\n') {
|
|
28 /* Wait until the buffer is empty */
|
|
29 while (*(volatile uint*)(FVP_PL011_UARTFR) & (FVP_PL011_UARTFR_TXFF));
|
|
30 //while (inw(UARTFR) & UARTFR_TXFF);
|
|
31 /* Put the character into the register */
|
|
32 *(volatile uint*) FVP_PL011_UARTDR = 0x0d;
|
|
33 //outw(UARTDR , c);
|
|
34 }
|
|
35 while (*(volatile uint*)(FVP_PL011_UARTFR) & (FVP_PL011_UARTFR_TXFF));
|
|
36 *(volatile uint*) FVP_PL011_UARTDR = c;
|
|
37
|
|
38
|
|
39 }
|
|
40
|
|
41 uint uartgetc_fvp()
|
|
42 {
|
|
43 /* Wait until the buffer is empty */
|
|
44 while (*(volatile uint*)(FVP_PL011_UARTFR) & (FVP_PL011_UARTFR_RXFE));
|
|
45 //while (inw(UARTFR) & UARTFR_RXFE);
|
|
46 /* Put the character into the register */
|
|
47 return *(volatile uint*) FVP_PL011_UARTDR;
|
|
48 //outw(UARTDR , c);
|
|
49 }
|