summaryrefslogtreecommitdiffstats
path: root/libs/printf/ape_putchar.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/printf/ape_putchar.c')
-rw-r--r--libs/printf/ape_putchar.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/libs/printf/ape_putchar.c b/libs/printf/ape_putchar.c
index ea96a89..50fd5df 100644
--- a/libs/printf/ape_putchar.c
+++ b/libs/printf/ape_putchar.c
@@ -43,25 +43,59 @@
////////////////////////////////////////////////////////////////////////////////
#include <printf.h>
-#include <em100_putchar.h>
+#include <ape_console.h>
#include <APE_SHM.h>
+#include <APE_SHM1.h>
-void _putchar(char character)
+static bool reset_ape_console_internal(VOLATILE SHM_t *port)
+{
+ if (port->RcpuWritePointer.r32 > sizeof(port->RcpuPrintfBuffer) ||
+ port->RcpuReadPointer.r32 > sizeof(port->RcpuPrintfBuffer) ||
+ port->RcpuHostReadPointer.r32 > sizeof(port->RcpuPrintfBuffer))
+ {
+ port->RcpuWritePointer.r32 = 0;
+ port->RcpuReadPointer.r32 = 0;
+ port->RcpuHostReadPointer.r32 = 0;
+
+ return true;
+ }
+
+ return false;
+}
+
+bool reset_ape_console(void)
+{
+ bool was_reset = false;
+ was_reset = was_reset || reset_ape_console_internal(&SHM);
+ was_reset = was_reset || reset_ape_console_internal(&SHM1);
+
+ return was_reset;
+}
+
+
+static void ape_putchar(char character, VOLATILE SHM_t *port)
{
- uint32_t write_pointer = SHM.RcpuWritePointer.r32;
+ uint32_t write_pointer = port->RcpuWritePointer.r32;
uint32_t word_pointer = write_pointer / 4;
uint32_t byte_index = write_pointer % 4;
uint32_t byte_mask = 0xFF << (byte_index * 8);
- uint32_t new_word = SHM.RcpuPrintfBuffer[word_pointer].r32 & ~byte_mask;
+ uint32_t new_word = port->RcpuPrintfBuffer[word_pointer].r32 & ~byte_mask;
new_word |= character << (byte_index * 8);
- SHM.RcpuPrintfBuffer[word_pointer].r32 = new_word;
+ port->RcpuPrintfBuffer[word_pointer].r32 = new_word;
write_pointer++;
- if(write_pointer >= sizeof(SHM.RcpuPrintfBuffer))
+ if(write_pointer >= sizeof(port->RcpuPrintfBuffer))
{
write_pointer = 0;
}
- SHM.RcpuWritePointer.r32 = write_pointer;
+ port->RcpuWritePointer.r32 = write_pointer;
+}
+
+
+void _putchar(char character)
+{
+ ape_putchar(character, &SHM);
+ ape_putchar(character, &SHM1);
}
OpenPOWER on IntegriCloud