diff options
Diffstat (limited to 'ape/main.c')
-rw-r--r-- | ape/main.c | 127 |
1 files changed, 96 insertions, 31 deletions
@@ -44,58 +44,123 @@ #include "ape.h" +#include <APE_APE.h> +#include <APE_APE_PERI.h> +#include <APE_RX_PORT.h> #include <APE_SHM.h> +#include <Ethernet.h> +#include <NCSI.h> +#include <Network.h> +#include <types.h> -void __attribute__((noreturn)) loaderLoop(void) +void handleCommand(void) { - // Update SHM.Sig to signal ready. - SHM.SegSig.bits.Sig = SHM_SEG_SIG_SIG_LOADER; - SHM.FwStatus.bits.Ready = 1; - - for(;;) + uint32_t command = SHM.LoaderCommand.bits.Command; + if (!command) { - uint32_t command = SHM.LoaderCommand.bits.Command; - if(!command) continue; + return; + } + + uint32_t arg0 = SHM.LoaderArg0.r32; + uint32_t arg1 = SHM.LoaderArg1.r32; - uint32_t arg0 = SHM.LoaderArg0.r32; - uint32_t arg1 = SHM.LoaderArg1.r32; + switch (command) + { + default: + break; - switch(command) + case SHM_LOADER_COMMAND_COMMAND_READ_MEM: + { + // Read word address specified in arg0 + uint32_t *addr = ((void *)arg0); + SHM.LoaderArg0.r32 = *addr; + break; + } + case SHM_LOADER_COMMAND_COMMAND_WRITE_MEM: + { + // Write word address specified in arg0 with arg1 + uint32_t *addr = ((void *)arg0); + *addr = arg1; + break; + } + case SHM_LOADER_COMMAND_COMMAND_CALL: { - default: - break; + // call address specified in arg0. + void (*function)(uint32_t) = ((void *)arg0); + function(arg1); + break; + } + } + + // Mark command as handled. + SHM.LoaderCommand.bits.Command = 0; +} + +void handleBMCPacket(void) +{ + uint32_t buffer[1024]; - case SHM_LOADER_COMMAND_COMMAND_READ_MEM: + RegAPE_PERIBmcToNcRxStatus_t stat; + stat.r32 = APE_PERI.BmcToNcRxStatus.r32; + + if (stat.bits.New) + { + if (stat.bits.Bad) + { + // TODO: ACK bad packet. + APE_PERI.BmcToNcRxControl.bits.ResetBad = 1; + while (APE_PERI.BmcToNcRxControl.bits.ResetBad) { - // Read word address specified in arg0 - uint32_t* addr = ((void*)arg0); - SHM.LoaderArg0.r32 = *addr; - break; + // Wait } - case SHM_LOADER_COMMAND_COMMAND_WRITE_MEM: + } + else + { + int32_t bytes = stat.bits.PacketLength; + if (!stat.bits.Passthru) { - // Write word address specified in arg0 with arg1 - uint32_t* addr = ((void*)arg0); - *addr = arg1; - break; + // stat.print(); + int32_t words = DIVIDE_RND_UP(bytes, sizeof(uint32_t)); + int i = 0; + while (words--) + { + uint32_t word = (APE_PERI.BmcToNcReadBuffer.r32); + buffer[i] = word; + i++; + } + + NetworkFrame_t *frame = ((NetworkFrame_t *)buffer); + + handleNCSIFrame(frame); } - case SHM_LOADER_COMMAND_COMMAND_CALL: + else { - // call address specified in arg0. - void (*function)(uint32_t) = ((void*)arg0); - function(arg1); - break; + // Pass through to network + Network_TX_transmitPassthroughPacket(bytes); } } + } +} - // Mark command as handled. - SHM.LoaderCommand.bits.Command = 0; +void __attribute__((noreturn)) loaderLoop(void) +{ + // Update SHM.Sig to signal ready. + SHM.SegSig.bits.Sig = SHM_SEG_SIG_SIG_LOADER; + SHM.FwStatus.bits.Ready = 1; + + for (;;) + { + handleBMCPacket(); + Network_PassthroughRxPatcket(); + handleCommand(); } } void __attribute__((noreturn)) __start() { - initRxFromNetwork(); + NCSI_init(); + Network_InitTxRx(); initRMU(); + loaderLoop(); }
\ No newline at end of file |