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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [software/] [leon3/] [spimctrl.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
/*
2
 * Simple loopback test for SPIMCTRL
3
 *
4
 * Copyright (c) 2008 Gaisler Research AB
5
 *
6
 * When running this test all core inputs must be
7
 * pulled HIGH.
8
 *
9
 */
10
 
11
#include "testmod.h"
12
 
13
/* Register fields */
14
/* Control register */
15
#define SPIM_CSN  (1 << 3)
16
#define SPIM_EAS  (1 << 2)
17
#define SPIM_IEN  (1 << 1)
18
#define SPIM_USRC (1 << 0)
19
/* Status register */
20
#define SPIM_TO   (1 << 4)
21
#define SPIM_ERR  (1 << 3)
22
#define SPIM_INIT (1 << 2)
23
#define SPIM_BUSY (1 << 1)
24
#define SPIM_DONE (1 << 0)
25
 
26
struct spimctrlregs {
27
  volatile unsigned int conf;
28
  volatile unsigned int ctrl;
29
  volatile unsigned int stat;
30
  volatile unsigned int rx;
31
  volatile unsigned int tx;
32
};
33
 
34
/*
35
 * spimctrl_test(unsigned int addr)
36
 *
37
 * Shifts out 0x5A and verifies that the received data is
38
 * 0xFF. This test application requires that the core is
39
 * initialized.
40
 *
41
 */
42
int spimctrl_test(unsigned int addr)
43
{
44
  struct spimctrlregs *regs;
45
 
46
  report_device(0x01045000);
47
 
48
  regs = (struct spimctrlregs*)addr;
49
 
50
  report_subtest(1);
51
  /* Verify that core is initialized and that the other bits have sensible values */
52
  if (regs->stat & SPIM_TO)
53
     fail(0);
54
  if (regs->stat & SPIM_ERR)
55
     fail(1);
56
  if (!(regs->stat & SPIM_INIT))
57
     fail(2);
58
  if (regs->stat & SPIM_BUSY)
59
     fail(3);
60
  if (regs->stat & SPIM_DONE)
61
     fail(4);
62
  if (!(regs->ctrl & SPIM_CSN))
63
     fail(5);
64
  if (regs->ctrl & SPIM_EAS)
65
     fail(6);
66
  if (regs->ctrl & SPIM_IEN)
67
     fail(7);
68
  if (regs->ctrl & SPIM_USRC)
69
     fail(8);
70
 
71
  report_subtest(2);
72
  /* Transfer one byte */
73
 
74
  regs->ctrl = SPIM_USRC;
75
 
76
  if (regs->ctrl != SPIM_USRC)
77
     fail(0);
78
 
79
  regs->tx = 0x5A;
80
 
81
  while (!(regs->stat & (SPIM_DONE | SPIM_ERR)))
82
     ;
83
 
84
  if (regs->stat & SPIM_ERR)
85
     fail(1);
86
 
87
  regs->stat = SPIM_DONE;
88
 
89
  if (regs->stat != SPIM_INIT)
90
     fail(2);
91
 
92
  if (regs->rx != 0xFF)
93
     fail(3);
94
 
95
  regs->ctrl = 0;
96
 
97
  if (regs->ctrl != SPIM_CSN)
98
     fail(4);
99
 
100
  return 0;
101
}

powered by: WebSVN 2.1.0

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