#include <stdint.h>
#include "app_urv_regs.h"
#include "hydra_supervisor_regs.h"

#define SUPERVISOR_BASE 0x80000
#define SUPERVISOR ((volatile struct hydra_supervisor_regs *)SUPERVISOR_BASE)
#define WD_KEY 0xc0423bc9

#define REGS ((volatile struct app_urv_regs *)0x100000)

void
init (void)
{
  REGS->mailboxes.mboxout = 0x12345678;

  /* Enable scrubber */
  SUPERVISOR->scrub_cfg = HYDRA_SUPERVISOR_REGS_SCRUB_CFG_IRAM_EN
    | HYDRA_SUPERVISOR_REGS_SCRUB_CFG_DRAM_EN;
}

void
main (void)
{
  SUPERVISOR->wd_key = WD_KEY;

  if (REGS->mailboxes.status & MBOX_REGS_STATUS_MBIN)
    {
      unsigned dat;

      dat = REGS->mailboxes.mboxin;
      REGS->mailboxes.mboxout = ~dat;
      if (dat == 0) {
        /* For testing: corrupt ra */
        asm volatile (".insn   r 0x5b, 0x1, 0, ra, ra, %0" : : "r"(1));
      }
    }
}
