diff options
Diffstat (limited to 'firmware/target/arm/imx233')
-rw-r--r-- | firmware/target/arm/imx233/uartdbg-imx233.c | 74 | ||||
-rw-r--r-- | firmware/target/arm/imx233/uartdbg-imx233.h | 35 |
2 files changed, 109 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/uartdbg-imx233.c b/firmware/target/arm/imx233/uartdbg-imx233.c new file mode 100644 index 0000000000..077b405f49 --- /dev/null +++ b/firmware/target/arm/imx233/uartdbg-imx233.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2013 by Lorenzo Miori | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "uartdbg-imx233.h" | ||
22 | #include "pinctrl-imx233.h" | ||
23 | #include "clkctrl-imx233.h" | ||
24 | |||
25 | void imx233_uartdbg_init(unsigned long baud) | ||
26 | { | ||
27 | /* Enable UART clock */ | ||
28 | imx233_clkctrl_enable(CLK_UART, true); | ||
29 | /* Configure UART pins */ | ||
30 | imx233_pinctrl_setup_vpin(VPIN_UARTDBG_TX, "uartdbg tx", PINCTRL_DRIVE_4mA, false); | ||
31 | imx233_pinctrl_setup_vpin(VPIN_UARTDBG_RX, "uartdbg rx", PINCTRL_DRIVE_4mA, false); | ||
32 | |||
33 | /* Set baud rate */ | ||
34 | HW_UARTDBG_IBRD = baud >> 16; | ||
35 | HW_UARTDBG_FBRD = baud & 0xFFFF; | ||
36 | |||
37 | /* Set port options (actually needed to set baud rate), 8 bit char, enable FIFO buffer */ | ||
38 | BF_WR(UARTDBG_LCR_H, WLEN, 3); | ||
39 | BF_WR(UARTDBG_LCR_H, FEN, 1); | ||
40 | |||
41 | /* Finally enable UART device, TX enable, RX enable, device enable */ | ||
42 | BF_WR(UARTDBG_CR, TXE, 1); | ||
43 | BF_WR(UARTDBG_CR, RXE, 1); | ||
44 | BF_WR(UARTDBG_CR, UARTEN, 1); | ||
45 | } | ||
46 | |||
47 | void imx233_uartdbg_send(unsigned char data) | ||
48 | { | ||
49 | /* Wait to transmit if TX FIFO buffer is full*/ | ||
50 | while (BF_RD(UARTDBG_FR, TXFF)); | ||
51 | BF_WR(UARTDBG_DR, DATA, data); | ||
52 | } | ||
53 | |||
54 | void uart_tx(const char* data) | ||
55 | { | ||
56 | while (*data != 0) | ||
57 | imx233_uartdbg_send(*data++); | ||
58 | } | ||
59 | |||
60 | unsigned int uart_rx(char* rx_buf, unsigned int len) | ||
61 | { | ||
62 | unsigned int i = 0; | ||
63 | |||
64 | while(i < len) | ||
65 | { | ||
66 | /* Check if the UART Rx Buffer has something into -> RXFE */ | ||
67 | if(!BF_RD(UARTDBG_FR, RXFE)) | ||
68 | { | ||
69 | rx_buf[i] = HW_UARTDBG_DR; | ||
70 | i++; | ||
71 | } | ||
72 | } | ||
73 | return i; | ||
74 | } \ No newline at end of file | ||
diff --git a/firmware/target/arm/imx233/uartdbg-imx233.h b/firmware/target/arm/imx233/uartdbg-imx233.h new file mode 100644 index 0000000000..3ee5175a21 --- /dev/null +++ b/firmware/target/arm/imx233/uartdbg-imx233.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2013 by Lorenzo Miori | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "system.h" | ||
22 | #include "regs/regs-uartdbg.h" | ||
23 | |||
24 | /* This values below are valid with a XCLK of 24MHz */ | ||
25 | #define BAUD_9600 (uint32_t)(156 << 16 | 16) | ||
26 | #define BAUD_19200 (uint32_t)(78 << 16 | 2) | ||
27 | #define BAUD_38400 (uint32_t)(39 << 16 | 4) | ||
28 | #define BAUD_57600 (uint32_t)(26 << 16 | 3) | ||
29 | #define BAUD_115200 (uint32_t)(13 << 16 | 1) | ||
30 | |||
31 | void imx233_uartdbg_init(unsigned long baud); | ||
32 | void imx233_uartdbg_send(unsigned char data); | ||
33 | |||
34 | void uart_tx(const char* data); | ||
35 | unsigned int uart_rx(char* rx_buf, unsigned int len); \ No newline at end of file | ||