#include "Drivers.h"
#include <targets/LPC2000.h>
#include <targets/liblpc2000.h>
#include <ctl_api.h>

int cntr = 1;

char t;
void spiISR(void)
{
  S0SPINT = 1;
  

  if ((S0SPSR_SPIF_MASK&S0SPSR)==0)
  {
    t = S0SPDR  ;
  }
  else
  {
    if (DRV_WIFI_REBOOT[cntr]!=0)
    {
      S0SPDR = DRV_WIFI_REBOOT[cntr++];
    }
  }
  
  
}


void initSPI(void)
{
  PCLKSEL0 |= (3<<PCLKSEL0_PCLK_SPI_BIT);                                                //9 MHz
  PINSEL0 |= (2<<PINSEL0_P0_15_BIT);                                                     //SCK
  PINSEL1 |= (2<<PINSEL1_P0_16_BIT)|(2<<PINSEL1_P0_17_BIT)|(2<<PINSEL1_P0_18_BIT);       //SSEL|MISO0|MOSI0
  S0SPCR = S0SPCR_MSTR | S0SPCR_SPIE |S0SPCR_CPHA;
  S0SPCCR = 9;
  ctl_set_isr(10, 5, CTL_ISR_TRIGGER_FIXED, spiISR, 0);
  ctl_unmask_isr(10);
}