#include "archinc.h"
#include "cli.h"
#include "strutil.h"
#include "eventq.h"
#include "zlregs.h"
#include "zl_event.h"
#include "zl_bus.h"
#include "zarlink.h"

#ifdef CONFIG_INCLUDE_ZARLINK

#include <stdio.h>
#include <stdlib.h>

static void handleResetEvent(void);

static void handleResetEvent(void)
{
  int bufLen;
  char * pOutBuf;

  pOutBuf = clicharGetOutputBuffer(&bufLen);

  sprintf(pOutBuf, "*** eeek! the switch reset!!\r\n");
  clicharSendOutputBuffer(pOutBuf, bufLen);

  // reset, and re-init the switch
  zarlinkIndexedWrite(0xf00, 0x08);
  zarlinkInit();

}

int zarlinkResetInit(void)
{
  // register event handlers for switch reset event
  eventqRegisterHandler(SWITCH_RESET, handleResetEvent);
  
  return 0;
}

#endif

