#include "lisoc_test.h"
#include "spi.h"
#include "spi_test.h"

/*!
    \brief      spi test
    \param[in]  none
    \param[out] none
    \retval     none
*/
void spi_test(void)
{
  uint32_t i;
  uint32_t recv_len;
  uint8_t txbuff[512] = {0x5a,0x01, 0x02, 0x03, 0x04, 0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11, 0x12, 0x13, 0x14, 0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F};
  uint8_t rxbuff[512] = {0};

  spi_master_init();
  spi_slave_init();

#if 1
  spi_master_send(txbuff, 1);
  recv_len = spi_slave_recv(rxbuff, 1);
    
    if(txbuff[i] != rxbuff[i])
    {
      debug("%d,%x\n",i,rxbuff[i]);
      debug("spi test\t\t\t\t\tNG.\n");
      //return;
    }

#else
  debug("spi slave read wait...\n");
  recv_len = spi_slave_Rx8(rxbuff, 512);

  if((recv_len != 0))
  {
    for(i = 0; i < recv_len; i ++)
    {
      debug("rx:%x\n",rxbuff[i]);
    }
    debug("spi slave write wait...\n");
    if(*(uint32_t*)rxbuff == 0x11111111)
      spi_slave_Tx8(rxbuff, recv_len, 5000);
  }
#endif
  debug("spi test\t\t\t\t\tOK.\n");

}
