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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [spi/] [sim/] [spi-simple.c] - Blame information for rev 561

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 349 julius
/*
2
  SPI controller simple test
3
 
4
  Do some reads from the SPI slaves. Select a different slave each loop
5
  and does a read and reports the value.
6
 
7
  Nothing much actually gets tested here.
8
 
9 403 julius
  Ensure the slave selects for the spi are enabled in orpsoc-defines.v
10 349 julius
 
11
*/
12
 
13
 
14 403 julius
#include "cpu-utils.h"
15 349 julius
#include "simple-spi.h"
16
 
17 403 julius
#include "orpsoc-defines.h"
18 349 julius
 
19
// Detect which of the SPI cores are enabled, tailor the test for that
20
#ifndef SPI1
21
# ifndef SPI2
22
#  error
23
#  error No SPI cores to test with! Please enable SPI1 and/or SPI2
24
#  error
25
# else
26
#  define NUM_SPI_CORES 1
27
#  define FIRST_SPI_CORE 2
28
# endif
29
#else
30
# ifdef SPI2
31
#  define NUM_SPI_CORES 2
32
#  define FIRST_SPI_CORE 1
33
# else
34
#  define NUM_SPI_CORES 1
35
#  define FIRST_SPI_CORE 1
36
# endif
37
#endif
38
 
39
int main()
40
{
41
  int spi_master = FIRST_SPI_CORE;
42
  int spi_slave = 2;
43
  int i;
44
 
45
  // Init the masters
46
  for (spi_master = FIRST_SPI_CORE;
47
       spi_master < FIRST_SPI_CORE+ NUM_SPI_CORES;
48
       spi_master++)
49
    {
50
      spi_core_clock_setup(spi_master, 0, 0, 2, 0);
51
      spi_core_enable(spi_master);
52
    }
53
 
54
 
55
  // Play with the slaves
56
  for(i=0;i<64;i++)
57
    {
58
      for (spi_master = FIRST_SPI_CORE;
59
           spi_master < FIRST_SPI_CORE+ NUM_SPI_CORES;
60
           spi_master++)
61
        {
62
          spi_slave = i % 3;
63
          spi_slave = (1 << spi_slave);
64
          // Select slave on SPI bus
65
          spi_core_slave_select(spi_master, spi_slave);
66
          // Do a SPI bus transaction - we're only interested in the read data
67
          // coming back
68
          while (!spi_core_write_avail(spi_master));
69
          spi_core_write_data(spi_master, (i&0xff));
70
          while (!spi_core_data_avail(spi_master));
71
          report(spi_core_read_data(spi_master));
72
          // Deselect slaves
73
          spi_core_slave_select(spi_master, 0);
74
        }
75
    }
76
 
77
  exit(0x8000000d);
78
 
79
}

powered by: WebSVN 2.1.0

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