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

#ifdef CONFIG_INCLUDE_ZARLINK

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

static void handleCtrl2RxEvent(void);

static int ctl2showHandler(int argc, char * argv[], int flags);

static unsigned short ctrl2Data16[20];

int zarlinkCtrlRetrieveCtrl2(unsigned short *pCtrl2Buffer)
{
  int i;
  for(i=0;i<40/2;i++) {
    ctrl2Data16[i] = zarlinkCtrlBuffer2Read();
    }
  zarlinkCommandWrite(0x04);

  return 0;
}

static void handleCtrl2RxEvent(void)
{
  if (zarlinkCtrlRetrieveCtrl2(ctrl2Data16) == 0) {
    zarlinkRmonUpdateStats((unsigned char *)ctrl2Data16);
    }
  zarlinkEventUnmaskIrq(INT_CONTROL_FRAME2);
}

int zarlinkCtrl2Init(void)
{
  // register event handlers for CTRL1 and CTRL2 events
  eventqRegisterHandler(SWITCH_CTRL2_RX, handleCtrl2RxEvent);
  
  return 0;
}

#endif

