summaryrefslogtreecommitdiffstats
path: root/stage1/main.c
diff options
context:
space:
mode:
authorEvan Lojewski <github@meklort.com>2020-02-17 20:47:13 -0700
committerGitHub <noreply@github.com>2020-02-17 20:47:13 -0700
commit23b478f335cd622049ad17f1f7ca4f0641200705 (patch)
tree2243e00ad65259233171f3fbc97eb898c806af3e /stage1/main.c
parentd2419a287fc52929c351fb7fed54bae323fedc54 (diff)
downloadbcm5719-ortega-23b478f335cd622049ad17f1f7ca4f0641200705.tar.gz
bcm5719-ortega-23b478f335cd622049ad17f1f7ca4f0641200705.zip
printf: Remove nvm access from the ape as it triggers a race condition when the rx cpu is restarted. (#35)
Rather than print directly, the APE now using the host debug console only for printf. The RX cpu (function 0 only) uses the debug console and forwards it over SPI when new data is available.
Diffstat (limited to 'stage1/main.c')
-rw-r--r--stage1/main.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/stage1/main.c b/stage1/main.c
index 2330730..5aea0b6 100644
--- a/stage1/main.c
+++ b/stage1/main.c
@@ -85,6 +85,41 @@ void init_once(void)
SHM.RcpuSegLength.r32 = 0x34;
}
+void handle_printf()
+{
+ uint32_t buffer_size = sizeof(SHM.RcpuPrintfBuffer)/sizeof(SHM.RcpuPrintfBuffer[0]) * sizeof(uint32_t);
+
+ if (SHM.RcpuWritePointer.r32 > buffer_size ||
+ SHM.RcpuReadPointer.r32 > buffer_size ||
+ SHM.RcpuHostReadPointer.r32 > buffer_size)
+ {
+ // Print buffer has not been initialized. Exit out.
+ return;
+ }
+
+ for(;;)
+ {
+ uint32_t cached_pointer = SHM.RcpuReadPointer.r32;
+ if(cached_pointer != SHM.RcpuWritePointer.r32)
+ {
+ if(cached_pointer >= buffer_size)
+ {
+ cached_pointer = 0;
+ }
+
+ uint32_t word_pointer = cached_pointer / 4;
+ uint32_t byte_index = cached_pointer % 4;
+ char character = (uint8_t)(SHM.RcpuPrintfBuffer[word_pointer].r32 >> (byte_index * 8));
+
+ em100_putchar(character);
+
+ SHM.RcpuReadPointer.r32 = ++cached_pointer;
+ }
+ }
+
+}
+
+
int main()
{
#if CXX_SIMULATOR
@@ -175,13 +210,25 @@ int main()
#else
- RegDEVICERxRiscMode_t mode;
- mode.r32 = 0;
- mode.bits.Halt = 1;
- for(;;)
+ if(0 == DEVICE.Status.bits.FunctionNumber)
+ {
+ for(;;)
+ {
+ // Handle printf from the APE.
+ handle_printf();
+ }
+ }
+ else
{
- // Halt the CPU since we aren't doing anything.
- DEVICE.RxRiscMode.r32 = mode.r32;;
+ RegDEVICERxRiscMode_t mode;
+ mode.r32 = 0;
+ mode.bits.Halt = 1;
+
+ for(;;)
+ {
+ // Halt the CPU since we aren't doing anything.
+ // DEVICE.RxRiscMode.r32 = mode.r32;;
+ }
}
#endif
}
OpenPOWER on IntegriCloud