OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [spi/] [sim/] [spi-simple.c] - Diff between revs 393 and 403

Only display areas with differences | Details | Blame | View Log

Rev 393 Rev 403
/*
/*
  SPI controller simple test
  SPI controller simple test
 
 
  Do some reads from the SPI slaves. Select a different slave each loop
  Do some reads from the SPI slaves. Select a different slave each loop
  and does a read and reports the value.
  and does a read and reports the value.
 
 
  Nothing much actually gets tested here.
  Nothing much actually gets tested here.
 
 
  Ensure the slave selects for the spi are enabled in design-defines.v
  Ensure the slave selects for the spi are enabled in orpsoc-defines.v
 
 
*/
*/
 
 
 
 
#include "or32-utils.h"
#include "cpu-utils.h"
#include "simple-spi.h"
#include "simple-spi.h"
 
 
#include "design-defines.h"
#include "orpsoc-defines.h"
 
 
// Detect which of the SPI cores are enabled, tailor the test for that
// Detect which of the SPI cores are enabled, tailor the test for that
#ifndef SPI1
#ifndef SPI1
# ifndef SPI2
# ifndef SPI2
#  error
#  error
#  error No SPI cores to test with! Please enable SPI1 and/or SPI2
#  error No SPI cores to test with! Please enable SPI1 and/or SPI2
#  error
#  error
# else
# else
#  define NUM_SPI_CORES 1
#  define NUM_SPI_CORES 1
#  define FIRST_SPI_CORE 2
#  define FIRST_SPI_CORE 2
# endif
# endif
#else
#else
# ifdef SPI2
# ifdef SPI2
#  define NUM_SPI_CORES 2
#  define NUM_SPI_CORES 2
#  define FIRST_SPI_CORE 1
#  define FIRST_SPI_CORE 1
# else
# else
#  define NUM_SPI_CORES 1
#  define NUM_SPI_CORES 1
#  define FIRST_SPI_CORE 1
#  define FIRST_SPI_CORE 1
# endif
# endif
#endif
#endif
 
 
int main()
int main()
{
{
  int spi_master = FIRST_SPI_CORE;
  int spi_master = FIRST_SPI_CORE;
  int spi_slave = 2;
  int spi_slave = 2;
  int i;
  int i;
 
 
  // Init the masters
  // Init the masters
  for (spi_master = FIRST_SPI_CORE;
  for (spi_master = FIRST_SPI_CORE;
       spi_master < FIRST_SPI_CORE+ NUM_SPI_CORES;
       spi_master < FIRST_SPI_CORE+ NUM_SPI_CORES;
       spi_master++)
       spi_master++)
    {
    {
      spi_core_clock_setup(spi_master, 0, 0, 2, 0);
      spi_core_clock_setup(spi_master, 0, 0, 2, 0);
      spi_core_enable(spi_master);
      spi_core_enable(spi_master);
    }
    }
 
 
 
 
  // Play with the slaves
  // Play with the slaves
  for(i=0;i<64;i++)
  for(i=0;i<64;i++)
    {
    {
      for (spi_master = FIRST_SPI_CORE;
      for (spi_master = FIRST_SPI_CORE;
           spi_master < FIRST_SPI_CORE+ NUM_SPI_CORES;
           spi_master < FIRST_SPI_CORE+ NUM_SPI_CORES;
           spi_master++)
           spi_master++)
        {
        {
          spi_slave = i % 3;
          spi_slave = i % 3;
          spi_slave = (1 << spi_slave);
          spi_slave = (1 << spi_slave);
          // Select slave on SPI bus
          // Select slave on SPI bus
          spi_core_slave_select(spi_master, spi_slave);
          spi_core_slave_select(spi_master, spi_slave);
          // Do a SPI bus transaction - we're only interested in the read data
          // Do a SPI bus transaction - we're only interested in the read data
          // coming back
          // coming back
          while (!spi_core_write_avail(spi_master));
          while (!spi_core_write_avail(spi_master));
          spi_core_write_data(spi_master, (i&0xff));
          spi_core_write_data(spi_master, (i&0xff));
          while (!spi_core_data_avail(spi_master));
          while (!spi_core_data_avail(spi_master));
          report(spi_core_read_data(spi_master));
          report(spi_core_read_data(spi_master));
          // Deselect slaves
          // Deselect slaves
          spi_core_slave_select(spi_master, 0);
          spi_core_slave_select(spi_master, 0);
        }
        }
    }
    }
 
 
  exit(0x8000000d);
  exit(0x8000000d);
 
 
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.