Set the UART speed to a fixed value when gdbstub is called and restore its
previous value if gdbstub exits.
---
 software/gdbstub/gdbstub.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/software/gdbstub/gdbstub.c b/software/gdbstub/gdbstub.c
index 695d2ea..bf294b7 100644
--- a/software/gdbstub/gdbstub.c
+++ b/software/gdbstub/gdbstub.c
@@ -29,6 +29,8 @@
 #define SUPPORT_Z_CMD 1
 #define SUPPORT_Q_CMD 1
 
+#define GDBSTUB_UART_SPEED 115200
+
 /* see crt0.S */
 extern void clear_bss(void);
 
@@ -671,6 +673,7 @@ static void cmd_query(void)
 void handle_exception(unsigned int *registers)
 {
     unsigned int stat;
+    unsigned int uart_div;
 
     /*
      * make sure break is disabled.
@@ -694,6 +697,10 @@ void handle_exception(unsigned int *registers)
     while(!(CSR_UART_STAT & UART_STAT_THRE));
     stat = CSR_UART_STAT;
 
+    /* save UART divider and set own speed */
+    uart_div = CSR_UART_DIVISOR;
+    CSR_UART_DIVISOR = CSR_FREQUENCY / 16 / GDBSTUB_UART_SPEED;
+
     /* reply to host that an exception has occured */
     if (gdb_connected) {
         cmd_status(registers);
@@ -770,6 +777,9 @@ out:
     /* clear TX event if there was no transmission in progress */
     CSR_UART_STAT = stat & UART_STAT_TX_EVT;
 
+    /* restore UART divider */
+    CSR_UART_DIVISOR = uart_div;
+
     /* reenable break */
     CSR_UART_DEBUG = UART_DEBUG_BREAK_EN;
 }
-- 
1.7.2.5

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to