summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Markgraf <steve@steve-m.de>2013-01-03 22:44:00 +0100
committerSylvain Munaut <tnt@246tNt.com>2013-01-05 18:38:42 +0100
commit21bc3b8db014b5579eb9dd960feb87f24ea1e857 (patch)
tree63e1cbff820cacc4c5efd1f1640f00557a2f5ca7
parente340681c5bbcb9f904b0058d7f69f80ab2d32cc5 (diff)
fw: introduce per-board uart mapping
Signed-off-by: Steve Markgraf <steve@steve-m.de>
-rw-r--r--src/target/firmware/apps/loader/main.c6
-rw-r--r--src/target/firmware/apps/loader_mtk/main.c6
-rw-r--r--src/target/firmware/board/compal_e86/init.c13
-rwxr-xr-xsrc/target/firmware/board/compal_e88/init.c13
-rw-r--r--src/target/firmware/board/compal_e99/init.c13
-rw-r--r--src/target/firmware/board/gta0x/init.c13
-rw-r--r--src/target/firmware/board/mediatek/uart.c12
-rw-r--r--src/target/firmware/board/mt62xx/init.c8
-rw-r--r--src/target/firmware/board/pirelli_dpl10/init.c18
-rw-r--r--src/target/firmware/board/se_j100/init.c13
-rw-r--r--src/target/firmware/calypso/uart.c12
-rw-r--r--src/target/firmware/comm/sercomm.c15
-rw-r--r--src/target/firmware/comm/sercomm_cons.c3
-rw-r--r--src/target/firmware/include/comm/sercomm.h10
-rw-r--r--src/target/firmware/include/console.h5
-rw-r--r--src/target/firmware/include/uart.h5
-rw-r--r--src/target/firmware/lib/console.c23
17 files changed, 123 insertions, 65 deletions
diff --git a/src/target/firmware/apps/loader/main.c b/src/target/firmware/apps/loader/main.c
index 3cb1333..797f023 100644
--- a/src/target/firmware/apps/loader/main.c
+++ b/src/target/firmware/apps/loader/main.c
@@ -61,12 +61,13 @@ static void key_handler(enum key_codes code, enum key_states state);
static void cmd_handler(uint8_t dlci, struct msgb *msg);
int flag = 0;
+static int sercomm_uart;
static void flush_uart(void)
{
unsigned i;
for (i = 0; i < 500; i++) {
- uart_poll(SERCOMM_UART_NR);
+ uart_poll(sercomm_uart);
delay_ms(1);
}
}
@@ -133,6 +134,7 @@ int main(void)
/* initialize board without interrupts */
board_init(0);
+ sercomm_uart = sercomm_get_uart();
/* Say hi */
puts("\n\nOsmocomBB Loader (revision " GIT_REVISION ")\n");
@@ -172,7 +174,7 @@ int main(void)
/* Wait for events */
while (1) {
keypad_poll();
- uart_poll(SERCOMM_UART_NR);
+ uart_poll(sercomm_uart);
}
/* NOT REACHED */
diff --git a/src/target/firmware/apps/loader_mtk/main.c b/src/target/firmware/apps/loader_mtk/main.c
index d3c974e..43fbb56 100644
--- a/src/target/firmware/apps/loader_mtk/main.c
+++ b/src/target/firmware/apps/loader_mtk/main.c
@@ -56,12 +56,13 @@ const char *hr =
static void cmd_handler(uint8_t dlci, struct msgb *msg);
int flag = 0;
+static int sercomm_uart;
static void flush_uart(void)
{
unsigned i;
for (i = 0; i < 500; i++) {
- uart_poll(SERCOMM_UART_NR);
+ uart_poll(sercomm_uart);
delay_ms(1);
}
}
@@ -112,6 +113,7 @@ static const uint8_t phone_ack[] = { 0x1b, 0xf6, 0x02, 0x00, 0x41, 0x03, 0x42 };
int main(void)
{
board_init(0);
+ sercomm_uart = sercomm_get_uart();
/* Initialize HDLC subsystem */
sercomm_init();
@@ -132,7 +134,7 @@ int main(void)
/* Wait for events */
while (1) {
- uart_poll(SERCOMM_UART_NR);
+ uart_poll(sercomm_uart);
}
}
diff --git a/src/target/firmware/board/compal_e86/init.c b/src/target/firmware/board/compal_e86/init.c
index 1280ddd..336eb43 100644
--- a/src/target/firmware/board/compal_e86/init.c
+++ b/src/target/firmware/board/compal_e86/init.c
@@ -108,14 +108,17 @@ void board_init(int with_irq)
if (with_irq)
irq_init();
- /* initialize MODEM UART to be used for sercomm*/
- uart_init(SERCOMM_UART_NR, with_irq);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
+ sercomm_bind_uart(UART_MODEM);
+ cons_bind_uart(UART_IRDA);
+
+ /* initialize MODEM UART to be used for sercomm */
+ uart_init(UART_MODEM, with_irq);
+ uart_baudrate(UART_MODEM, UART_115200);
/* initialize IRDA UART to be used for old-school console code.
* note: IRDA uart only accessible on C115 and C117 PCB */
- uart_init(CONS_UART_NR, with_irq);
- uart_baudrate(CONS_UART_NR, UART_115200);
+ uart_init(UART_IRDA, with_irq);
+ uart_baudrate(UART_IRDA, UART_115200);
/* Initialize hardware timers */
hwtimer_init();
diff --git a/src/target/firmware/board/compal_e88/init.c b/src/target/firmware/board/compal_e88/init.c
index 12ead87..21a23a1 100755
--- a/src/target/firmware/board/compal_e88/init.c
+++ b/src/target/firmware/board/compal_e88/init.c
@@ -103,14 +103,17 @@ void board_init(int with_irq)
if (with_irq)
irq_init();
- /* initialize MODEM UART to be used for sercomm*/
- uart_init(SERCOMM_UART_NR, with_irq);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
+ sercomm_bind_uart(UART_MODEM);
+ cons_bind_uart(UART_IRDA);
+
+ /* initialize MODEM UART to be used for sercomm */
+ uart_init(UART_MODEM, with_irq);
+ uart_baudrate(UART_MODEM, UART_115200);
/* Initialize IRDA UART to be used for old-school console code.
* note: IRDA uart only accessible on C115 and C117 PCB */
- uart_init(CONS_UART_NR, with_irq);
- uart_baudrate(CONS_UART_NR, UART_115200);
+ uart_init(UART_IRDA, with_irq);
+ uart_baudrate(UART_IRDA, UART_115200);
/* Initialize hardware timers */
hwtimer_init();
diff --git a/src/target/firmware/board/compal_e99/init.c b/src/target/firmware/board/compal_e99/init.c
index 8dab47c..cb8d321 100644
--- a/src/target/firmware/board/compal_e99/init.c
+++ b/src/target/firmware/board/compal_e99/init.c
@@ -108,14 +108,17 @@ void board_init(int with_irq)
if (with_irq)
irq_init();
- /* initialize MODEM UART to be used for sercomm*/
- uart_init(SERCOMM_UART_NR, with_irq);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
+ sercomm_bind_uart(UART_MODEM);
+ cons_bind_uart(UART_IRDA);
+
+ /* initialize MODEM UART to be used for sercomm */
+ uart_init(UART_MODEM, with_irq);
+ uart_baudrate(UART_MODEM, UART_115200);
/* initialize IRDA UART to be used for old-school console code.
* note: IRDA uart only accessible on C115 and C117 PCB */
- uart_init(CONS_UART_NR, with_irq);
- uart_baudrate(CONS_UART_NR, UART_115200);
+ uart_init(UART_IRDA, with_irq);
+ uart_baudrate(UART_IRDA, UART_115200);
/* Initialize hardware timers */
hwtimer_init();
diff --git a/src/target/firmware/board/gta0x/init.c b/src/target/firmware/board/gta0x/init.c
index ef75e7d..8b907e3 100644
--- a/src/target/firmware/board/gta0x/init.c
+++ b/src/target/firmware/board/gta0x/init.c
@@ -101,14 +101,17 @@ void board_init(int with_irq)
if (with_irq)
irq_init();
- /* initialize MODEM UART to be used for sercomm*/
- uart_init(SERCOMM_UART_NR, with_irq);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
+ sercomm_bind_uart(UART_MODEM);
+ cons_bind_uart(UART_IRDA);
+
+ /* initialize MODEM UART to be used for sercomm */
+ uart_init(UART_MODEM, with_irq);
+ uart_baudrate(UART_MODEM, UART_115200);
/* Initialize IRDA UART to be used for old-school console code.
* note: IRDA uart only accessible on C115 and C117 PCB */
- uart_init(CONS_UART_NR, with_irq);
- uart_baudrate(CONS_UART_NR, UART_115200);
+ uart_init(UART_IRDA, with_irq);
+ uart_baudrate(UART_IRDA, UART_115200);
/* Initialize hardware timers */
hwtimer_init();
diff --git a/src/target/firmware/board/mediatek/uart.c b/src/target/firmware/board/mediatek/uart.c
index 8e86b20..f9e3283 100644
--- a/src/target/firmware/board/mediatek/uart.c
+++ b/src/target/firmware/board/mediatek/uart.c
@@ -191,7 +191,7 @@ static uint8_t uart_reg_read(int uart, enum uart_reg reg)
static void uart_irq_handler_cons(__unused int irqnr)
{
- const uint8_t uart = CONS_UART_NR;
+ const uint8_t uart = cons_get_uart();
uint8_t iir;
//uart_putchar_nb(uart, 'U');
@@ -224,7 +224,7 @@ static void uart_irq_handler_cons(__unused int irqnr)
static void uart_irq_handler_sercomm(__unused int irqnr)
{
- const uint8_t uart = SERCOMM_UART_NR;
+ const uint8_t uart = sercomm_get_uart();
uint8_t iir, ch;
//uart_putchar_nb(uart, 'U');
@@ -274,11 +274,13 @@ void uart_init(uint8_t uart, __unused uint8_t interrupts)
/* no interrupts, only polling so far */
uart_reg_write(uart, IER, 0x00);
- if (uart == CONS_UART_NR) {
+ if (uart == cons_get_uart()) {
cons_init();
- } else {
+ } else if (uart == sercomm_get_uart()) {
sercomm_init();
uart_irq_enable(uart, UART_IRQ_RX_CHAR, 1);
+ } else {
+ return;
}
uart_reg_write(uart, AUTOBAUD_EN, 0x00); /* disable AUTOBAUD */
@@ -301,7 +303,7 @@ void uart_init(uint8_t uart, __unused uint8_t interrupts)
}
void uart_poll(uint8_t uart) {
- if(uart == CONS_UART_NR) {
+ if(uart == cons_get_uart()) {
uart_irq_handler_cons(0);
} else {
uart_irq_handler_sercomm(0);
diff --git a/src/target/firmware/board/mt62xx/init.c b/src/target/firmware/board/mt62xx/init.c
index e3daa37..dae38cf 100644
--- a/src/target/firmware/board/mt62xx/init.c
+++ b/src/target/firmware/board/mt62xx/init.c
@@ -133,7 +133,9 @@ void board_init(int with_irq)
pll_init();
memory_init();
- /* Initialize UART without interrupts */
- uart_init(SERCOMM_UART_NR, with_irq);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
+ /* Initialize UART */
+ sercomm_bind_uart(UART_MODEM);
+ cons_bind_uart(UART_IRDA);
+ uart_init(UART_MODEM, with_irq);
+ uart_baudrate(UART_MODEM, UART_115200);
}
diff --git a/src/target/firmware/board/pirelli_dpl10/init.c b/src/target/firmware/board/pirelli_dpl10/init.c
index 629e227..d822b80 100644
--- a/src/target/firmware/board/pirelli_dpl10/init.c
+++ b/src/target/firmware/board/pirelli_dpl10/init.c
@@ -112,14 +112,16 @@ void board_init(int with_irq)
if (with_irq)
irq_init();
- /* initialize MODEM UART to be used for sercomm*/
- uart_init(SERCOMM_UART_NR, with_irq);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
-
- /* Initialize IRDA UART to be used for old-school console code.
- * note: IRDA uart only accessible on C115 and C117 PCB */
- uart_init(CONS_UART_NR, with_irq);
- uart_baudrate(CONS_UART_NR, UART_115200);
+ sercomm_bind_uart(UART_IRDA);
+ cons_bind_uart(UART_MODEM);
+
+ /* initialize IRDA UART to be used for sercomm */
+ uart_init(UART_IRDA, with_irq);
+ uart_baudrate(UART_IRDA, UART_115200);
+
+ /* Initialize MODEM UART to be used for old-school console code. */
+ uart_init(UART_MODEM, with_irq);
+ uart_baudrate(UART_MODEM, UART_115200);
/* Initialize hardware timers */
hwtimer_init();
diff --git a/src/target/firmware/board/se_j100/init.c b/src/target/firmware/board/se_j100/init.c
index 284ff72..402684b 100644
--- a/src/target/firmware/board/se_j100/init.c
+++ b/src/target/firmware/board/se_j100/init.c
@@ -108,14 +108,17 @@ void board_init(int with_irq)
if (with_irq)
irq_init();
- /* initialize MODEM UART to be used for sercomm*/
- uart_init(SERCOMM_UART_NR, with_irq);
- uart_baudrate(SERCOMM_UART_NR, UART_115200);
+ sercomm_bind_uart(UART_MODEM);
+ cons_bind_uart(UART_IRDA);
+
+ /* initialize MODEM UART to be used for sercomm */
+ uart_init(UART_MODEM, with_irq);
+ uart_baudrate(UART_MODEM, UART_115200);
/* initialize IRDA UART to be used for old-school console code.
* note: IRDA uart only accessible on C115 and C117 PCB */
- uart_init(CONS_UART_NR, with_irq);
- uart_baudrate(CONS_UART_NR, UART_115200);
+ uart_init(UART_IRDA, with_irq);
+ uart_baudrate(UART_IRDA, UART_115200);
/* Initialize hardware timers */
hwtimer_init();
diff --git a/src/target/firmware/calypso/uart.c b/src/target/firmware/calypso/uart.c
index bcb56bd..ec587de 100644
--- a/src/target/firmware/calypso/uart.c
+++ b/src/target/firmware/calypso/uart.c
@@ -193,7 +193,7 @@ static uint8_t uart_reg_read(int uart, enum uart_reg reg)
static void uart_irq_handler_cons(__unused enum irq_nr irqnr)
{
- const uint8_t uart = CONS_UART_NR;
+ const uint8_t uart = cons_get_uart();
uint8_t iir;
//uart_putchar_nb(uart, 'U');
@@ -226,7 +226,7 @@ static void uart_irq_handler_cons(__unused enum irq_nr irqnr)
static void uart_irq_handler_sercomm(__unused enum irq_nr irqnr)
{
- const uint8_t uart = SERCOMM_UART_NR;
+ const uint8_t uart = sercomm_get_uart();
uint8_t iir, ch;
//uart_putchar_nb(uart, 'U');
@@ -281,14 +281,14 @@ void uart_init(uint8_t uart, uint8_t interrupts)
uint8_t irq = uart2irq[uart];
uart_reg_write(uart, IER, 0x00);
- if (uart == CONS_UART_NR) {
+ if (uart == cons_get_uart()) {
cons_init();
if(interrupts) {
irq_register_handler(irq, &uart_irq_handler_cons);
irq_config(irq, 0, 0, 0xff);
irq_enable(irq);
}
- } else {
+ } else if (uart == sercomm_get_uart()) {
sercomm_init();
if(interrupts) {
irq_register_handler(irq, &uart_irq_handler_sercomm);
@@ -296,6 +296,8 @@ void uart_init(uint8_t uart, uint8_t interrupts)
irq_enable(irq);
}
uart_irq_enable(uart, UART_IRQ_RX_CHAR, 1);
+ } else {
+ return;
}
#if 0
if (uart == 1) {
@@ -331,7 +333,7 @@ void uart_init(uint8_t uart, uint8_t interrupts)
}
void uart_poll(uint8_t uart) {
- if(uart == CONS_UART_NR) {
+ if(uart == cons_get_uart()) {
uart_irq_handler_cons(0);
} else {
uart_irq_handler_sercomm(0);
diff --git a/src/target/firmware/comm/sercomm.c b/src/target/firmware/comm/sercomm.c
index ddc852c..490e225 100644
--- a/src/target/firmware/comm/sercomm.c
+++ b/src/target/firmware/comm/sercomm.c
@@ -70,6 +70,7 @@ enum rx_state {
static struct {
int initialized;
+ int uart_id;
/* transmit side */
struct {
@@ -90,6 +91,18 @@ static struct {
} sercomm;
+#ifndef HOST_BUILD
+void sercomm_bind_uart(int uart)
+{
+ sercomm.uart_id = uart;
+}
+
+int sercomm_get_uart(void)
+{
+ return sercomm.uart_id;
+}
+#endif
+
void sercomm_init(void)
{
unsigned int i;
@@ -127,7 +140,7 @@ void sercomm_sendmsg(uint8_t dlci, struct msgb *msg)
#ifndef HOST_BUILD
/* tell UART that we have something to send */
- uart_irq_enable(SERCOMM_UART_NR, UART_IRQ_TX_EMPTY, 1);
+ uart_irq_enable(sercomm.uart_id, UART_IRQ_TX_EMPTY, 1);
#endif
}
diff --git a/src/target/firmware/comm/sercomm_cons.c b/src/target/firmware/comm/sercomm_cons.c
index a0dca40..e6b6934 100644
--- a/src/target/firmware/comm/sercomm_cons.c
+++ b/src/target/firmware/comm/sercomm_cons.c
@@ -40,8 +40,9 @@ static struct {
static void raw_puts(const char *s)
{
int i = strlen(s);
+ int uart_id = sercomm_get_uart();
while (i--)
- uart_putchar_wait(SERCOMM_UART_NR, *s++);
+ uart_putchar_wait(uart_id, *s++);
}
#ifdef DEBUG
diff --git a/src/target/firmware/include/comm/sercomm.h b/src/target/firmware/include/comm/sercomm.h
index 54256b5..a474c61 100644
--- a/src/target/firmware/include/comm/sercomm.h
+++ b/src/target/firmware/include/comm/sercomm.h
@@ -1,12 +1,8 @@
#ifndef _SERCOMM_H
#define _SERCOMM_H
-/* SERCOMM layer on UART1 (modem UART) */
-
#include <osmocom/core/msgb.h>
-#define SERCOMM_UART_NR 1
-
#define HDLC_FLAG 0x7E
#define HDLC_ESCAPE 0x7D
@@ -25,6 +21,12 @@ enum sercomm_dlci {
_SC_DLCI_MAX
};
+#ifndef HOST_BUILD
+/* helper functions for target */
+void sercomm_bind_uart(int uart);
+int sercomm_get_uart(void);
+#endif
+
void sercomm_init(void);
int sercomm_initialized(void);
diff --git a/src/target/firmware/include/console.h b/src/target/firmware/include/console.h
index 7146e99..cd27155 100644
--- a/src/target/firmware/include/console.h
+++ b/src/target/firmware/include/console.h
@@ -10,9 +10,8 @@ int cons_puts(const char *s);
int cons_putchar(char c);
int cons_rb_flush(void);
void cons_init(void);
-
-/* We want the console on UART 0 (IRDA UART) */
-#define CONS_UART_NR 0
+void cons_bind_uart(int uart);
+int cons_get_uart(void);
/* Size of the static ring-buffer that we keep for console print messages */
#define CONS_RB_SIZE 4096
diff --git a/src/target/firmware/include/uart.h b/src/target/firmware/include/uart.h
index 81d7a15..870a096 100644
--- a/src/target/firmware/include/uart.h
+++ b/src/target/firmware/include/uart.h
@@ -13,6 +13,11 @@ enum uart_baudrate {
UART_921600,
};
+enum uart_id {
+ UART_IRDA,
+ UART_MODEM,
+};
+
void uart_init(uint8_t uart, uint8_t interrupts);
void uart_putchar_wait(uint8_t uart, int c);
int uart_putchar_nb(uint8_t uart, int c);
diff --git a/src/target/firmware/lib/console.c b/src/target/firmware/lib/console.c
index 7135ae2..6bc8fed 100644
--- a/src/target/firmware/lib/console.c
+++ b/src/target/firmware/lib/console.c
@@ -32,9 +32,20 @@ struct cons {
char *next_inbyte;
char *next_outbyte;
int initialized;
+ int uart_id;
};
static struct cons cons;
+void cons_bind_uart(int uart)
+{
+ cons.uart_id = uart;
+}
+
+int cons_get_uart(void)
+{
+ return cons.uart_id;
+}
+
void cons_init(void)
{
memset(cons.buf, 0, sizeof(cons.buf));
@@ -89,19 +100,19 @@ static void __rb_flush_wait(void)
{
char ch;
while (cons_rb_pull(&ch) >= 0)
- uart_putchar_wait(CONS_UART_NR, ch);
+ uart_putchar_wait(cons.uart_id, ch);
}
/* returns if everything was flushed (1) or if there's more to flush (0) */
static int __rb_flush(void)
{
- while (!uart_tx_busy(CONS_UART_NR)) {
+ while (!uart_tx_busy(cons.uart_id)) {
char ch;
if (cons_rb_pull(&ch) < 0) {
/* no more data to write, disable interest in Tx FIFO interrupts */
return 1;
}
- uart_putchar_nb(CONS_UART_NR, ch);
+ uart_putchar_nb(cons.uart_id, ch);
}
/* if we reach here, UART Tx FIFO is busy again */
@@ -158,7 +169,7 @@ int cons_rb_append(const char *data, int len)
__cons_rb_append(data_cur, len);
/* we want to get Tx FIFO interrupts */
- uart_irq_enable(CONS_UART_NR, UART_IRQ_TX_EMPTY, 1);
+ uart_irq_enable(cons.uart_id, UART_IRQ_TX_EMPTY, 1);
local_irq_restore(flags);
@@ -173,7 +184,7 @@ int cons_puts(const char *s)
/* if the console is not active yet, we need to fall back */
int i = strlen(s);
while (i--)
- uart_putchar_wait(CONS_UART_NR, *s++);
+ uart_putchar_wait(cons.uart_id, *s++);
return i;
}
}
@@ -184,7 +195,7 @@ int cons_putchar(char c)
return cons_rb_append(&c, 1);
else {
/* if the console is not active yet, we need to fall back */
- uart_putchar_wait(CONS_UART_NR, c);
+ uart_putchar_wait(cons.uart_id, c);
return 0;
}
}