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

Subversion Repositories timerocd

[/] [timerocd/] [trunk/] [src/] [testbench/] [TimerOCD_testbench.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dewhisna
--------------------------------------------------------------------------------
2
--      File name : TimerOCD_testbench.vhd
3
--------------------------------------------------------------------------------
4
--      Copyright (C) 2015 Donna Whisnant/Dewtronics.
5
--      Contact: http://www.dewtronics.com/
6
--
7
--      This file may be used under the terms of the GNU Lesser General Public License
8
--      version 3.0 as published by the Free Software Foundation and appearing
9
--      in the files lgpl-3.0.txt/gpl-3.0.txt included in the packaging of this file.
10
--      Please review the following information to ensure the GNU Lesser General
11
--      Public License version 3.0 requirements will be met:
12
--      https://www.gnu.org/licenses/lgpl-3.0.html
13
--      Attribution requested, but not required.
14
--
15
--      Target Device: Xilinx Spartan-6 XC6SLX9-2-TQG144
16
--              Using Numato Mimas Spartan 6 FPGA Development Board
17
--              http://numato.com/mimas-spartan-6-fpga-development-board.html
18
--
19
--
20
--      Timer Output Compare Driver Test Bench
21
--
22
--------------------------------------------------------------------------------
23
 
24
library IEEE;
25
use IEEE.std_logic_1164.all;
26
use IEEE.std_logic_arith.all;
27
use IEEE.std_logic_unsigned.all;
28
use std.textio.all;
29
use IEEE.std_logic_textio.all;
30
 
31
--------------------------------------------------------------------------------
32
-- ENTITY DECLARATION
33
--------------------------------------------------------------------------------
34
entity TimerOCD_testbench is
35
end TimerOCD_testbench;
36
 
37
 
38
--------------------------------------------------------------------------------
39
-- ARCHITECTURE DECLARATION
40
--------------------------------------------------------------------------------
41
architecture behavior of TimerOCD_testbench is
42
        constant timerocd_numTimers : INTEGER := 64;            -- Number of Timers Supported
43
        constant timerocd_numTimerBits: INTEGER := 6;           -- Number of Timer Address Bits
44
        constant timerocd_numXferBits: INTEGER := 64;           -- Number of bits transmitted/received during SPI data exchange
45
        constant timerocd_numOutputs: INTEGER := 2;                     -- Number of Outputs Supported
46
 
47
        signal timerocd_reset_n: STD_LOGIC := '0';                       -- Master reset (Active Low)
48
        signal timerocd_SPI_SS_n: STD_LOGIC := '1';                     -- SPI Slave Select In (Active Low)
49
        signal timerocd_SPI_CLK: STD_LOGIC := '0';                       -- SPI Clock In
50
        signal timerocd_SPI_MOSI: STD_LOGIC := '0';                      -- SPI Master Out, Slave In
51
        signal timerocd_SPI_MISO: STD_LOGIC;                            -- SPI Master In, Slave Out
52
        signal timerocd_FiberOut: STD_LOGIC_VECTOR(timerocd_numOutputs-1 downto 0);                      -- Fiber Output Drive Outputs
53
        signal timerocd_GCLK_in: STD_LOGIC := '0';                       -- Master System Clock (GCLK) on Numato Mimas Spartan6 Module
54
 
55
        signal timerocd_SW: STD_LOGIC_VECTOR(3 downto 0) := (OTHERS => '1');     -- Push Buttons
56
        signal timerocd_LED: STD_LOGIC_VECTOR(7 downto 0);       -- LEDs
57
 
58
        subtype TTimerAddr is STD_LOGIC_VECTOR(timerocd_numTimerBits-1 downto 0);
59
        subtype TNote is STD_LOGIC_VECTOR(6 downto 0);
60
        subtype TPower is STD_LOGIC_VECTOR(6 downto 0);
61
        subtype TPitchBend is STD_LOGIC_VECTOR(13 downto 0);
62
 
63
        -- Constant Definitions for test:
64
        constant spiclk_period : time := 125 ns;                        -- AVR will be using CK/2 or 16MHz/2 or 8MHz for the SPI clock (STM32F4 will likely use 5.25MHz or 10.5MHz)
65
        constant gclk_period : time := 10 ns;                           -- Master System Clock (GCLK) on Numato Mimas Spartan6 Module is 100MHz
66
 
67
--      constant spiclk_period_hi : time := spiclk_period/5;    -- Used for simulation to provide non-symmetric clock pulses
68
--      constant spiclk_period_lo : time := (4*spiclk_period/5);
69
        constant spiclk_period_hi : time := spiclk_period/2;
70
        constant spiclk_period_lo : time := spiclk_period/2;
71
        constant spiclk_period_dly : time := 2 us;
72
 
73
        -- Conversion Functions:
74
        function mkTimer(constant nTimer : INTEGER) return TTimerAddr is
75
        begin
76
                return CONV_STD_LOGIC_VECTOR(nTimer, timerocd_numTimerBits);
77
        end function mkTimer;
78
 
79
        function mkNote(constant nNote : INTEGER) return TNote is
80
        begin
81
                return CONV_STD_LOGIC_VECTOR(nNote, 7);
82
        end function mkNote;
83
 
84
        function mkPower(constant nPower : INTEGER) return TPower is
85
        begin
86
                return CONV_STD_LOGIC_VECTOR(nPower, 7);
87
        end function mkPower;
88
 
89
        function mkPitchBend(constant nPitchBend : INTEGER)  return TPitchBend is
90
        begin
91
                return CONV_STD_LOGIC_VECTOR(nPitchBend, 14);
92
        end function mkPitchBend;
93
 
94
 
95
-- --------------------------------------------------------------------
96
-- printLED:
97
--      This procedure prints LED debug string
98
-- --------------------------------------------------------------------
99
procedure printLED(constant nLED : in STD_LOGIC_VECTOR(7 downto 0)) is
100
        variable lineTemp : line;
101
begin
102
        write(lineTemp, string'("LEDs: "));
103
        write(lineTemp, nLED, LEFT, 8);
104
        writeline(output, lineTemp);
105
end procedure printLED;
106
 
107
 
108
-- --------------------------------------------------------------------
109
-- printSW:
110
--      This procedure prints SW debug string
111
-- --------------------------------------------------------------------
112
procedure printSW(constant nSW : in STD_LOGIC_VECTOR(3 downto 0)) is
113
        variable lineTemp : line;
114
begin
115
        write(lineTemp, string'("Switches: "));
116
        write(lineTemp, nSW, LEFT, 4);
117
        writeline(output, lineTemp);
118
end procedure printSW;
119
 
120
 
121
-- --------------------------------------------------------------------
122
-- writeSPI:
123
--      This procedure will write a single byte to the SPI port
124
-- --------------------------------------------------------------------
125
procedure writeSPI(     constant nByte : in STD_LOGIC_VECTOR(7 downto 0);
126
                                        signal MOSI : out STD_LOGIC;
127
                                        signal CLK : out STD_LOGIC) is
128
begin
129
        for i in 7 downto 0 loop
130
                MOSI <= nByte(i);
131
                wait for spiclk_period_lo/2;
132
                CLK <= '1';
133
                wait for spiclk_period_hi/2;
134
                CLK <= '0';
135
        end loop;
136
end procedure writeSPI;
137
 
138
 
139
-- --------------------------------------------------------------------
140
-- readSPI:
141
--      This procedure will read a single byte from the SPI port
142
-- --------------------------------------------------------------------
143
procedure readSPI(      variable nByte : out STD_LOGIC_VECTOR(7 downto 0);
144
                                        signal MISO : in STD_LOGIC;
145
                                        signal MOSI : out STD_LOGIC;
146
                                        signal CLK : out STD_LOGIC) is
147
begin
148
        MOSI <= '0';
149
        for i in 7 downto 0 loop
150
                wait for spiclk_period_lo/2;
151
                CLK <= '1';
152
                wait for spiclk_period_hi/2;
153
                CLK <= '0';
154
                nByte(i) := MISO;
155
        end loop;
156
end procedure readSPI;
157
 
158
 
159
-- --------------------------------------------------------------------
160
-- readWriteSPI:
161
--      This procedure will read a single byte from the SPI port while
162
--              writing a new byte
163
-- --------------------------------------------------------------------
164
procedure readWriteSPI( constant nByteToWrite : in STD_LOGIC_VECTOR(7 downto 0);
165
                                                variable nByteRead : out STD_LOGIC_VECTOR(7 downto 0);
166
                                                signal MISO : in STD_LOGIC;
167
                                                signal MOSI : out STD_LOGIC;
168
                                                signal CLK : out STD_LOGIC) is
169
begin
170
        for i in 7 downto 0 loop
171
                MOSI <= nByteToWrite(i);
172
                wait for spiclk_period_lo/2;
173
                CLK <= '1';
174
                wait for spiclk_period_hi/2;
175
                CLK <= '0';
176
                nByteRead(i) := MISO;
177
        end loop;
178
end procedure readWriteSPI;
179
 
180
 
181
-- --------------------------------------------------------------------
182
-- writeCommand:
183
--      This procedure will write a command to the device
184
-- --------------------------------------------------------------------
185
procedure writeCommand( constant nCommand : in STD_LOGIC_VECTOR(5 downto 0);
186
                                                variable nCmdData : out STD_LOGIC_VECTOR(3 downto 0);
187
                                                signal SS : out STD_LOGIC;
188
                                                signal MISO : in STD_LOGIC;
189
                                                signal MOSI : out STD_LOGIC;
190
                                                signal CLK : out STD_LOGIC) is
191
        variable nReceivedByte : STD_LOGIC_VECTOR(7 downto 0);
192
begin
193
        SS <= '0';
194
        wait for spiclk_period_dly/2;
195
        readWriteSPI(nByteToWrite => "01" & nCommand,           -- Send Write Command
196
                        nByteRead => nReceivedByte,
197
                        MISO => MISO,
198
                        MOSI => MOSI,
199
                        CLK => CLK);
200
        wait for spiclk_period_dly/2;
201
        MOSI <= '0';
202
        SS <= '1';
203
        wait for spiclk_period_dly/2;
204
        nCmdData := nReceivedByte(3 downto 0);
205
end procedure writeCommand;
206
 
207
 
208
-- --------------------------------------------------------------------
209
-- readCommand:
210
--      This procedure will send a readcommand to the device
211
-- --------------------------------------------------------------------
212
procedure readCommand(  constant nCommand : in STD_LOGIC_VECTOR(5 downto 0);
213
                                                variable nCmdData : out STD_LOGIC_VECTOR(3 downto 0);
214
                                                signal SS : out STD_LOGIC;
215
                                                signal MISO : in STD_LOGIC;
216
                                                signal MOSI : out STD_LOGIC;
217
                                                signal CLK : out STD_LOGIC) is
218
        variable nReceivedByte : STD_LOGIC_VECTOR(7 downto 0);
219
begin
220
        SS <= '0';
221
        wait for spiclk_period_dly/2;
222
        readWriteSPI(nByteToWrite => "11" & nCommand,           -- Send Read Command
223
                        nByteRead => nReceivedByte,
224
                        MISO => MISO,
225
                        MOSI => MOSI,
226
                        CLK => CLK);
227
        wait for spiclk_period_dly/2;
228
        MOSI <= '0';
229
        SS <= '1';
230
        wait for spiclk_period_dly/2;
231
        nCmdData := nReceivedByte(3 downto 0);
232
end procedure readCommand;
233
 
234
 
235
-- --------------------------------------------------------------------
236
-- writeTimerOC:
237
--      This procedure will write a Timer Note pair to the specified
238
--              Timer OC
239
-- --------------------------------------------------------------------
240
procedure writeTimerOC( constant nTimer : in TTimerAddr;
241
                                                constant nNoteLeft : in TNote;
242
                                                constant nPowerLeft : in TPower;
243
                                                constant nPitchBendLeft : in TPitchBend;
244
                                                constant nNoteRight : in TNote;
245
                                                constant nPowerRight : in TPower;
246
                                                constant nPitchBendRight : in TPitchBend;
247
                                                signal SS : out STD_LOGIC;
248
                                                signal MOSI : out STD_LOGIC;
249
                                                signal CLK : out STD_LOGIC) is
250
begin
251
        SS <= '0';
252
        wait for spiclk_period_dly/2;
253
        writeSPI(nByte => "00" & nTimer,                -- Send Write Address for the specified output and timer
254
                        MOSI => MOSI,
255
                        CLK => CLK);
256
        WriteSPI(nByte => "0" & nNoteLeft,               -- Send Left Note
257
                        MOSI => MOSI,
258
                        CLK => CLK);
259
        WriteSPI(nByte => "0" & nPowerLeft,
260
                        MOSI => MOSI,
261
                        CLK => CLK);
262
        WriteSPI(nByte => "00" & nPitchBendLeft(13 downto 8),
263
                        MOSI => MOSI,
264
                        CLK => CLK);
265
        WriteSPI(nByte => nPitchBendLeft(7 downto 0),
266
                        MOSI => MOSI,
267
                        CLK => CLK);
268
        WriteSPI(nByte => "0" & nNoteRight,              -- Send Right Note
269
                        MOSI => MOSI,
270
                        CLK => CLK);
271
        WriteSPI(nByte => "0" & nPowerRight,
272
                        MOSI => MOSI,
273
                        CLK => CLK);
274
        WriteSPI(nByte => "00" & nPitchBendRight(13 downto 8),
275
                        MOSI => MOSI,
276
                        CLK => CLK);
277
        WriteSPI(nByte => nPitchBendRight(7 downto 0),
278
                        MOSI => MOSI,
279
                        CLK => CLK);
280
        wait for spiclk_period_dly/2;
281
        MOSI <= '0';
282
        SS <= '1';
283
        wait for spiclk_period_dly/2;
284
end procedure writeTimerOC;
285
 
286
 
287
-- --------------------------------------------------------------------
288
-- readTimerOC:
289
--      This procedure will read a Timer Note pair from the specified
290
--              Timer OC
291
-- --------------------------------------------------------------------
292
procedure readTimerOC(  constant nTimer : in TTimerAddr;
293
                                                variable nRetVal : out STD_LOGIC_VECTOR(timerocd_numXferBits-1 downto 0);
294
                                                signal SS : out STD_LOGIC;
295
                                                signal MISO : in STD_LOGIC;
296
                                                signal MOSI : out STD_LOGIC;
297
                                                signal CLK : out STD_LOGIC) is
298
begin
299
        SS <= '0';
300
        wait for spiclk_period_dly/2;
301
        writeSPI(nByte => "10" & nTimer,                -- Send Read Address for the specified output and timer
302
                        MOSI => MOSI,
303
                        CLK => CLK);
304
        for i in ((timerocd_numXferBits-1)/8)+1 downto 1 loop
305
                readSPI(nRetVal((i*8-1) downto ((i-1)*8)),
306
                                MISO => MISO,
307
                                MOSI => MOSI,
308
                                CLK => CLK);
309
        end loop;
310
        wait for spiclk_period_dly/2;
311
        SS <= '1';
312
        wait for spiclk_period_dly/2;
313
end procedure readTimerOC;
314
 
315
 
316
-- --------------------------------------------------------------------
317
-- readWriteTimerOC:
318
--      This procedure will read a Timer Note pair from the specified
319
--              Timer OC while writing a new Timer Note pair
320
-- --------------------------------------------------------------------
321
procedure readWriteTimerOC(     constant nTimer : in TTimerAddr;
322
                                                        constant nNoteLeft : in TNote;
323
                                                        constant nPowerLeft : in TPower;
324
                                                        constant nPitchBendLeft : in TPitchBend;
325
                                                        constant nNoteRight : in TNote;
326
                                                        constant nPowerRight : in TPower;
327
                                                        constant nPitchBendRight : in TPitchBend;
328
                                                        variable nRetVal : out STD_LOGIC_VECTOR(timerocd_numXferBits-1 downto 0);
329
                                                        signal SS : out STD_LOGIC;
330
                                                        signal MISO : in STD_LOGIC;
331
                                                        signal MOSI : out STD_LOGIC;
332
                                                        signal CLK : out STD_LOGIC) is
333
begin
334
        SS <= '0';
335
        wait for spiclk_period_dly/2;
336
        writeSPI(nByte => "00" & nTimer,                -- Send Read/Write Address for the specified output and timer
337
                        MOSI => MOSI,
338
                        CLK => CLK);
339
        readwriteSPI(nByteToWrite => "0" & nNoteLeft,            -- Send Left Note
340
                                        nByteRead => nRetVal(63 downto 56),
341
                                        MISO => MISO,
342
                                        MOSI => MOSI,
343
                                        CLK => CLK);
344
        readwriteSPI(nByteToWrite => "0" & nPowerLeft,
345
                                        nByteRead => nRetVal(55 downto 48),
346
                                        MISO => MISO,
347
                                        MOSI => MOSI,
348
                                        CLK => CLK);
349
        readwriteSPI(nByteToWrite => "00" & nPitchBendLeft(13 downto 8),
350
                                        nByteRead => nRetVal(47 downto 40),
351
                                        MISO => MISO,
352
                                        MOSI => MOSI,
353
                                        CLK => CLK);
354
        readwriteSPI(nByteToWrite => nPitchBendLeft(7 downto 0),
355
                                        nByteRead => nRetVal(39 downto 32),
356
                                        MISO => MISO,
357
                                        MOSI => MOSI,
358
                                        CLK => CLK);
359
        readwriteSPI(nByteToWrite => "0" & nNoteRight,           -- Send Right Note
360
                                        nByteRead => nRetVal(31 downto 24),
361
                                        MISO => MISO,
362
                                        MOSI => MOSI,
363
                                        CLK => CLK);
364
        readwriteSPI(nByteToWrite => "0" & nPowerRight,
365
                                        nByteRead => nRetVal(23 downto 16),
366
                                        MISO => MISO,
367
                                        MOSI => MOSI,
368
                                        CLK => CLK);
369
        readwriteSPI(nByteToWrite => "00" & nPitchBendRight(13 downto 8),
370
                                        nByteRead => nRetVal(15 downto 8),
371
                                        MISO => MISO,
372
                                        MOSI => MOSI,
373
                                        CLK => CLK);
374
        readwriteSPI(nByteToWrite => nPitchBendRight(7 downto 0),
375
                                        nByteRead => nRetVal(7 downto 0),
376
                                        MISO => MISO,
377
                                        MOSI => MOSI,
378
                                        CLK => CLK);
379
        wait for spiclk_period_dly/2;
380
        MOSI <= '0';
381
        SS <= '1';
382
end procedure readWriteTimerOC;
383
 
384
 
385
begin
386
 
387
        -- Instantiate TimerOCD UUT (Unit Under Test):
388
        uut : entity work.TimerOCD
389
        port map (
390
                reset_n => timerocd_reset_n,
391
                SPI_SS_n_in => timerocd_SPI_SS_n,
392
                SPI_CLK_in => timerocd_SPI_CLK,
393
                SPI_MOSI_in => timerocd_SPI_MOSI,
394
                SPI_MISO => timerocd_SPI_MISO,
395
                FiberOut => timerocd_FiberOut,
396
                GCLK_in => timerocd_GCLK_in,
397
                SW0 => timerocd_SW(0),
398
                SW1 => timerocd_SW(1),
399
                SW2 => timerocd_SW(2),
400
                SW3 => timerocd_SW(3),
401
                LED => timerocd_LED
402
        );
403
 
404
 
405
-- --------------------------------------------------------------------
406
-- gclkproc:
407
--      This process generates the free-running master GCLK clock for
408
--              the FPGA
409
-- --------------------------------------------------------------------
410
gclkproc : process
411
begin
412
        timerocd_GCLK_in <= '0';
413
        wait for gclk_period/2;
414
        timerocd_GCLK_in <= '1';
415
        wait for gclk_period/2;
416
end process gclkproc;
417
 
418
 
419
-- --------------------------------------------------------------------
420
-- stimproc:
421
--      Stimulus Process
422
-- --------------------------------------------------------------------
423
stimproc : process
424
        variable nReceivedData : STD_LOGIC_VECTOR(timerocd_numXferBits-1 downto 0) := (OTHERS => '0');
425
        variable nRcvCmdData : STD_LOGIC_VECTOR(3 downto 0);
426
        variable lineTemp : line;
427
begin
428
        -- System Reset:
429
        timerocd_reset_n <= '0';
430
        wait for 3 ms;
431
        timerocd_reset_n <= '1';
432
        wait for 30 us;                                                 -- At 100MHz GCLK, TimerOCD takes about 20.5uS to complete reset processing after reset signal goes high.  Allow 30uS to be safe.
433
 
434
        writeTimerOC(nTimer => mkTimer(0),
435
                                nNoteLeft => mkNote(21),
436
                                nPowerLeft => mkPower(1),
437
                                nPitchBendLeft => mkPitchBend(16#2000#),
438
                                nNoteRight => mkNote(0),
439
                                nPowerRight => mkPower(0),
440
                                nPitchBendRight => mkPitchBend(16#2000#),
441
                                SS => timerocd_SPI_SS_n,
442
                                MOSI => timerocd_SPI_MOSI,
443
                                CLK => timerocd_SPI_CLK);
444
        write(lineTemp, string'("Writing Bank 0 Timer 0 = 15012000 | 00002000"));
445
        writeline(output, lineTemp);
446
        wait for 5 ms;
447
        report "Switching to Bank 2";
448
        writeCommand(nCommand => "000110",
449
                                nCmdData => nRcvCmdData,
450
                                SS => timerocd_SPI_SS_n,
451
                                MISO => timerocd_SPI_MISO,
452
                                MOSI => timerocd_SPI_MOSI,
453
                                CLK => timerocd_SPI_CLK);
454
        assert (nRcvCmdData = "0000") report "Expected Current Data: 0000" severity warning;
455
        write(lineTemp, string'("Writing Bank 2 Timer 2 = 6A553000 | 00002000"));
456
        writeline(output, lineTemp);
457
        writeTimerOC(nTimer => mkTimer(2),
458
                                nNoteLeft => mkNote(106),
459
                                nPowerLeft => mkPower(85),
460
                                nPitchBendLeft => mkPitchBend(16#3000#),
461
                                nNoteRight => mkNote(0),
462
                                nPowerRight => mkPower(0),
463
                                nPitchBendRight => mkPitchBend(16#2000#),
464
                                SS => timerocd_SPI_SS_n,
465
                                MOSI => timerocd_SPI_MOSI,
466
                                CLK => timerocd_SPI_CLK);
467
        wait for 5 ms;
468
        report "Switching to Bank 3";
469
        writeCommand(nCommand => "000111",
470
                                nCmdData => nRcvCmdData,
471
                                SS => timerocd_SPI_SS_n,
472
                                MISO => timerocd_SPI_MISO,
473
                                MOSI => timerocd_SPI_MOSI,
474
                                CLK => timerocd_SPI_CLK);
475
        assert (nRcvCmdData = "0010") report "Expected Current Data: 0010" severity warning;
476
        writeTimerOC(nTimer => mkTimer(3),
477
                                nNoteLeft => mkNote(0),
478
                                nPowerLeft => mkPower(0),
479
                                nPitchBendLeft => mkPitchBend(16#2000#),
480
                                nNoteRight => mkNote(102),
481
                                nPowerRight => mkPower(119),
482
                                nPitchBendright => mkPitchBend(16#1000#),
483
                                SS => timerocd_SPI_SS_n,
484
                                MOSI => timerocd_SPI_MOSI,
485
                                CLK => timerocd_SPI_CLK);
486
        write(lineTemp, string'("Writing Bank 3 Timer 27 = 00002000 | 66771000"));
487
        writeline(output, lineTemp);
488
        wait for 50 us;
489
        writeCommand(nCommand => "100001",
490
                                nCmdData => nRcvCmdData,
491
                                SS => timerocd_SPI_SS_n,
492
                                MISO => timerocd_SPI_MISO,
493
                                MOSI => timerocd_SPI_MOSI,
494
                                CLK => timerocd_SPI_CLK);
495
        printLED(nLED => timerocd_LED);
496
        assert (nRcvCmdData = "0000") report "Expected OLD LED Status xxxx 0000" severity warning;
497
        wait for 50 us;
498
        readCommand(nCommand => "100000",
499
                                nCmdData => nRcvCmdData,
500
                                SS => timerocd_SPI_SS_n,
501
                                MISO => timerocd_SPI_MISO,
502
                                MOSI => timerocd_SPI_MOSI,
503
                                CLK => timerocd_SPI_CLK);
504
        printLED(nLED => timerocd_LED);
505
        assert (nRcvCmdData = "0001") report "Expected LED Status xxxx 0001" severity warning;
506
        wait for 50 us;
507
        writeCommand(nCommand => "100010",
508
                                nCmdData => nRcvCmdData,
509
                                SS => timerocd_SPI_SS_n,
510
                                MISO => timerocd_SPI_MISO,
511
                                MOSI => timerocd_SPI_MOSI,
512
                                CLK => timerocd_SPI_CLK);
513
        printLED(nLED => timerocd_LED);
514
        assert (nRcvCmdData = "0001") report "Expected OLD LED Status xxxx 0001" severity warning;
515
        wait for 50 us;
516
        readCommand(nCommand => "100000",
517
                                nCmdData => nRcvCmdData,
518
                                SS => timerocd_SPI_SS_n,
519
                                MISO => timerocd_SPI_MISO,
520
                                MOSI => timerocd_SPI_MOSI,
521
                                CLK => timerocd_SPI_CLK);
522
        printLED(nLED => timerocd_LED);
523
        assert (nRcvCmdData = "0010") report "Expected LED Status xxxx 0010" severity warning;
524
        wait for 50 us;
525
        writeCommand(nCommand => "100100",
526
                                nCmdData => nRcvCmdData,
527
                                SS => timerocd_SPI_SS_n,
528
                                MISO => timerocd_SPI_MISO,
529
                                MOSI => timerocd_SPI_MOSI,
530
                                CLK => timerocd_SPI_CLK);
531
        printLED(nLED => timerocd_LED);
532
        assert (nRcvCmdData = "0010") report "Expected OLD LED Status xxxx 0010" severity warning;
533
        wait for 50 us;
534
        readCommand(nCommand => "100000",
535
                                nCmdData => nRcvCmdData,
536
                                SS => timerocd_SPI_SS_n,
537
                                MISO => timerocd_SPI_MISO,
538
                                MOSI => timerocd_SPI_MOSI,
539
                                CLK => timerocd_SPI_CLK);
540
        printLED(nLED => timerocd_LED);
541
        assert (nRcvCmdData = "0100") report "Expected LED Status xxxx 0100" severity warning;
542
        wait for 50 us;
543
        writeCommand(nCommand => "110101",
544
                                nCmdData => nRcvCmdData,
545
                                SS => timerocd_SPI_SS_n,
546
                                MISO => timerocd_SPI_MISO,
547
                                MOSI => timerocd_SPI_MOSI,
548
                                CLK => timerocd_SPI_CLK);
549
        printLED(nLED => timerocd_LED);
550
        assert (nRcvCmdData = "0000") report "Expected OLD LED Status 0000 xxxx" severity warning;
551
        wait for 50 us;
552
        readCommand(nCommand => "110000",
553
                                nCmdData => nRcvCmdData,
554
                                SS => timerocd_SPI_SS_n,
555
                                MISO => timerocd_SPI_MISO,
556
                                MOSI => timerocd_SPI_MOSI,
557
                                CLK => timerocd_SPI_CLK);
558
        printLED(nLED => timerocd_LED);
559
        assert (nRcvCmdData = "0101") report "Expected LED Status 0101 xxxx" severity warning;
560
        wait for 50 us;
561
        writeCommand(nCommand => "101000",
562
                                nCmdData => nRcvCmdData,
563
                                SS => timerocd_SPI_SS_n,
564
                                MISO => timerocd_SPI_MISO,
565
                                MOSI => timerocd_SPI_MOSI,
566
                                CLK => timerocd_SPI_CLK);
567
        printLED(nLED => timerocd_LED);
568
        assert (nRcvCmdData = "0100") report "Expected OLD LED Status xxxx 0100" severity warning;
569
        wait for 50 us;
570
        readCommand(nCommand => "100000",
571
                                nCmdData => nRcvCmdData,
572
                                SS => timerocd_SPI_SS_n,
573
                                MISO => timerocd_SPI_MISO,
574
                                MOSI => timerocd_SPI_MOSI,
575
                                CLK => timerocd_SPI_CLK);
576
        printLED(nLED => timerocd_LED);
577
        assert (nRcvCmdData = "1000") report "Expected LED Status xxxx 1000" severity warning;
578
        wait for 50 us;
579
        writeCommand(nCommand => "111010",
580
                                nCmdData => nRcvCmdData,
581
                                SS => timerocd_SPI_SS_n,
582
                                MISO => timerocd_SPI_MISO,
583
                                MOSI => timerocd_SPI_MOSI,
584
                                CLK => timerocd_SPI_CLK);
585
        printLED(nLED => timerocd_LED);
586
        assert (nRcvCmdData = "0101") report "Expected OLD LED Status 0101 xxxx" severity warning;
587
        wait for 50 us;
588
        readCommand(nCommand => "110000",
589
                                nCmdData => nRcvCmdData,
590
                                SS => timerocd_SPI_SS_n,
591
                                MISO => timerocd_SPI_MISO,
592
                                MOSI => timerocd_SPI_MOSI,
593
                                CLK => timerocd_SPI_CLK);
594
        printLED(nLED => timerocd_LED);
595
        assert (nRcvCmdData = "1010") report "Expected LED Status 1010 xxxx" severity warning;
596
        wait for 50 us;
597
        writeCommand(nCommand => "100000",
598
                                nCmdData => nRcvCmdData,
599
                                SS => timerocd_SPI_SS_n,
600
                                MISO => timerocd_SPI_MISO,
601
                                MOSI => timerocd_SPI_MOSI,
602
                                CLK => timerocd_SPI_CLK);
603
        printLED(nLED => timerocd_LED);
604
        assert (nRcvCmdData = "1000") report "Expected OLD LED Status xxxx 1000" severity warning;
605
        wait for 50 us;
606
        readCommand(nCommand => "100000",
607
                                nCmdData => nRcvCmdData,
608
                                SS => timerocd_SPI_SS_n,
609
                                MISO => timerocd_SPI_MISO,
610
                                MOSI => timerocd_SPI_MOSI,
611
                                CLK => timerocd_SPI_CLK);
612
        printLED(nLED => timerocd_LED);
613
        assert (nRcvCmdData = "0000") report "Expected LED Status xxxx 0000" severity warning;
614
        wait for 50 us;
615
        writeCommand(nCommand => "110000",
616
                                nCmdData => nRcvCmdData,
617
                                SS => timerocd_SPI_SS_n,
618
                                MISO => timerocd_SPI_MISO,
619
                                MOSI => timerocd_SPI_MOSI,
620
                                CLK => timerocd_SPI_CLK);
621
        printLED(nLED => timerocd_LED);
622
        assert (nRcvCmdData = "1010") report "Expected OLD LED Status 1010 xxxx" severity warning;
623
        wait for 50 us;
624
        readCommand(nCommand => "110000",
625
                                nCmdData => nRcvCmdData,
626
                                SS => timerocd_SPI_SS_n,
627
                                MISO => timerocd_SPI_MISO,
628
                                MOSI => timerocd_SPI_MOSI,
629
                                CLK => timerocd_SPI_CLK);
630
        printLED(nLED => timerocd_LED);
631
        assert (nRcvCmdData = "0000") report "Expected LED Status 0000 xxxx" severity warning;
632
        wait for 50 us;
633
 
634
        readCommand(nCommand => "010000",
635
                                nCmdData => nRcvCmdData,
636
                                SS => timerocd_SPI_SS_n,
637
                                MISO => timerocd_SPI_MISO,
638
                                MOSI => timerocd_SPI_MOSI,
639
                                CLK => timerocd_SPI_CLK);
640
        printSW(nSW => nRcvCmdData(3 downto 0));
641
        assert (nRcvCmdData = "1111") report "Expected Switch Status 1111" severity warning;
642
        wait for 50 us;
643
        timerocd_SW(3 downto 0) <= "0110";
644
        readCommand(nCommand => "010000",
645
                                nCmdData => nRcvCmdData,
646
                                SS => timerocd_SPI_SS_n,
647
                                MISO => timerocd_SPI_MISO,
648
                                MOSI => timerocd_SPI_MOSI,
649
                                CLK => timerocd_SPI_CLK);
650
        printSW(nSW => nRcvCmdData(3 downto 0));
651
        assert (nRcvCmdData = "0110") report "Expected Switch Status 0110" severity warning;
652
        wait for 50 us;
653
        timerocd_SW(3 downto 0) <= "1001";
654
        readCommand(nCommand => "010000",
655
                                nCmdData => nRcvCmdData,
656
                                SS => timerocd_SPI_SS_n,
657
                                MISO => timerocd_SPI_MISO,
658
                                MOSI => timerocd_SPI_MOSI,
659
                                CLK => timerocd_SPI_CLK);
660
        printSW(nSW => nRcvCmdData(3 downto 0));
661
        assert (nRcvCmdData = "1001") report "Expected Switch Status 1001" severity warning;
662
        wait for 50 us;
663
        timerocd_SW(3 downto 0) <= "1111";
664
        readCommand(nCommand => "010000",
665
                                nCmdData => nRcvCmdData,
666
                                SS => timerocd_SPI_SS_n,
667
                                MISO => timerocd_SPI_MISO,
668
                                MOSI => timerocd_SPI_MOSI,
669
                                CLK => timerocd_SPI_CLK);
670
        printSW(nSW => nRcvCmdData(3 downto 0));
671
        assert (nRcvCmdData = "1111") report "Expected Switch Status 1111" severity warning;
672
        wait for 50 us;
673
 
674
        wait for 5 ms;
675
        report "Switching to Bank 0";
676
        writeCommand(nCommand => "000100",
677
                                nCmdData => nRcvCmdData,
678
                                SS => timerocd_SPI_SS_n,
679
                                MISO => timerocd_SPI_MISO,
680
                                MOSI => timerocd_SPI_MOSI,
681
                                CLK => timerocd_SPI_CLK);
682
        assert (nRcvCmdData = "0011") report "Expected Current Data: 0011" severity warning;
683
        wait for 5 ms;
684
        writeTimerOC(nTimer => mkTimer(1),
685
                                nNoteLeft => mkNote(108),
686
                                nPowerLeft => mkPower(127),
687
                                nPitchBendLeft => mkPitchBend(16#2000#),
688
                                nNoteRight => mkNote(0),
689
                                nPowerRight => mkPower(0),
690
                                nPitchBendRight => mkPitchBend(16#2000#),
691
                                SS => timerocd_SPI_SS_n,
692
                                MOSI => timerocd_SPI_MOSI,
693
                                CLK => timerocd_SPI_CLK);
694
        write(lineTemp, string'("Writing Bank 0 Timer 1 = 6C7F2000 | 00002000"));
695
        writeline(output, lineTemp);
696
        wait for 5 ms;
697
        writeTimerOC(nTimer => mkTimer(3),
698
                                nNoteLeft => mkNote(0),
699
                                nPowerLeft => mkPower(0),
700
                                nPitchBendLeft => mkPitchBend(16#2000#),
701
                                nNoteRight => mkNote(101),
702
                                nPowerRight => mkPower(127),
703
                                nPitchBendRight => mkPitchBend(16#2000#),
704
                                SS => timerocd_SPI_SS_n,
705
                                MOSI => timerocd_SPI_MOSI,
706
                                CLK => timerocd_SPI_CLK);
707
        write(lineTemp, string'("Writing Bank 0 Timer 3 = 00002000 | 657F2000"));
708
        writeline(output, lineTemp);
709
        wait for 5 ms;
710
        readTimerOC(nTimer => mkTimer(3),
711
                                nRetVal => nReceivedData,
712
                                SS => timerocd_SPI_SS_n,
713
                                MISO => timerocd_SPI_MISO,
714
                                MOSI => timerocd_SPI_MOSI,
715
                                CLK => timerocd_SPI_CLK);
716
        write(lineTemp, string'("Read>>  Bank 0 Timer 3 = "));
717
        hwrite(lineTemp, nReceivedData);
718
        writeline(output, lineTemp);
719
        assert (nReceivedData = X"00002000_657F2000") report "Expected: 00002000 | 657F2000" severity warning;
720
        wait for 5 ms;
721
        readTimerOC(nTimer=>mkTimer(0),
722
                                nRetVal => nReceivedData,
723
                                SS => timerocd_SPI_SS_n,
724
                                MISO => timerocd_SPI_MISO,
725
                                MOSI => timerocd_SPI_MOSI,
726
                                CLK => timerocd_SPI_CLK);
727
        write(lineTemp, string'("Read>>  Bank 0 Timer 0 = "));
728
        hwrite(lineTemp, nReceivedData);
729
        writeline(output, lineTemp);
730
        assert (nReceivedData = X"15012000_00002000") report "Expected: 15012000 | 00002000" severity warning;
731
        wait for 5 ms;
732
        readTimerOC(nTimer => mkTimer(1),
733
                                nRetVal => nReceivedData,
734
                                SS => timerocd_SPI_SS_n,
735
                                MISO => timerocd_SPI_MISO,
736
                                MOSI => timerocd_SPI_MOSI,
737
                                CLK => timerocd_SPI_CLK);
738
        write(lineTemp, string'("Read>>  Bank 0 Timer 1 = "));
739
        hwrite(lineTemp, nReceivedData);
740
        writeline(output, lineTemp);
741
        assert (nReceivedData = X"6C7F2000_00002000") report "Expected: 6C7F2000 | 00002000" severity warning;
742
        wait for 5 ms;
743
        readTimerOC(nTimer=>mkTimer(0),
744
                                nRetVal => nReceivedData,
745
                                SS => timerocd_SPI_SS_n,
746
                                MISO => timerocd_SPI_MISO,
747
                                MOSI => timerocd_SPI_MOSI,
748
                                CLK => timerocd_SPI_CLK);
749
        write(lineTemp, string'("Read>>  Bank 0 Timer 0 = "));
750
        hwrite(lineTemp, nReceivedData);
751
        writeline(output, lineTemp);
752
        assert (nReceivedData = X"15012000_00002000") report "Expected: 15012000 | 00002000" severity warning;
753
        wait for 5 ms;
754
        readTimerOC(nTimer => mkTimer(1),
755
                                nRetVal => nReceivedData,
756
                                SS => timerocd_SPI_SS_n,
757
                                MISO => timerocd_SPI_MISO,
758
                                MOSI => timerocd_SPI_MOSI,
759
                                CLK => timerocd_SPI_CLK);
760
        write(lineTemp, string'("Read>>  Bank 0 Timer 1 = "));
761
        hwrite(lineTemp, nReceivedData);
762
        writeline(output, lineTemp);
763
        assert (nReceivedData = X"6C7F2000_00002000") report "Expected: 6C7F2000 | 00002000" severity warning;
764
        wait for 5 ms;
765
        readTimerOC(nTimer => mkTimer(3),
766
                                nRetVal => nReceivedData,
767
                                SS => timerocd_SPI_SS_n,
768
                                MISO => timerocd_SPI_MISO,
769
                                MOSI => timerocd_SPI_MOSI,
770
                                CLK => timerocd_SPI_CLK);
771
        write(lineTemp, string'("Read>>  Bank 0 Timer 3 = "));
772
        hwrite(lineTemp, nReceivedData);
773
        writeline(output, lineTemp);
774
        assert (nReceivedData = X"00002000_657F2000") report "Expected: 00002000 | 657F2000" severity warning;
775
        wait for 5 ms;
776
        readWriteTimerOC(nTimer => mkTimer(1),
777
                                nNoteLeft => mkNote(56),
778
                                nPowerLeft => mkPower(29),
779
                                nPitchBendLeft => mkPitchBend(16#2000#),
780
                                nNoteRight => mkNote(0),
781
                                nPowerRight => mkPower(0),
782
                                nPitchBendRight => mkPitchBend(16#2000#),
783
                                nRetVal => nReceivedData,
784
                                SS => timerocd_SPI_SS_n,
785
                                MISO => timerocd_SPI_MISO,
786
                                MOSI => timerocd_SPI_MOSI,
787
                                CLK => timerocd_SPI_CLK);
788
        write(lineTemp, string'("Read/Write>>  Rewriting Bank 0 Timer 1 : OLD = "));
789
        hwrite(lineTemp, nReceivedData);
790
        write(lineTemp, string'("  NEW = 381D2000 | 00002000"));
791
        writeline(output, lineTemp);
792
        assert (nReceivedData = X"6C7F2000_00002000") report "Expected: 6C7F2000 | 00002000" severity warning;
793
        wait for 5 ms;
794
        readTimerOC(nTimer=>mkTimer(0),
795
                                nRetVal => nReceivedData,
796
                                SS => timerocd_SPI_SS_n,
797
                                MISO => timerocd_SPI_MISO,
798
                                MOSI => timerocd_SPI_MOSI,
799
                                CLK => timerocd_SPI_CLK);
800
        write(lineTemp, string'("Read>>  Bank 0 Timer 0 = "));
801
        hwrite(lineTemp, nReceivedData);
802
        writeline(output, lineTemp);
803
        assert (nReceivedData = X"15012000_00002000") report "Expected: 15012000 | 00002000" severity warning;
804
        wait for 5 ms;
805
        readTimerOC(nTimer => mkTimer(1),
806
                                nRetVal => nReceivedData,
807
                                SS => timerocd_SPI_SS_n,
808
                                MISO => timerocd_SPI_MISO,
809
                                MOSI => timerocd_SPI_MOSI,
810
                                CLK => timerocd_SPI_CLK);
811
        write(lineTemp, string'("Read>>  Bank 0 Timer 1 = "));
812
        hwrite(lineTemp, nReceivedData);
813
        writeline(output, lineTemp);
814
        assert (nReceivedData = X"381D2000_00002000") report "Expected: 381D2000 | 00002000" severity warning;
815
        wait for 5 ms;
816
        writeTimerOC(nTimer => mkTimer(0),
817
                                nNoteLeft => mkNote(0),
818
                                nPowerLeft => mkPower(0),
819
                                nPitchBendLeft => mkPitchBend(16#2000#),
820
                                nNoteRight => mkNote(0),
821
                                nPowerRight => mkPower(0),
822
                                nPitchBendRight => mkPitchBend(16#2000#),
823
                                SS => timerocd_SPI_SS_n,
824
                                MOSI => timerocd_SPI_MOSI,
825
                                CLK => timerocd_SPI_CLK);
826
        write(lineTemp, string'("Writing Bank 0 Timer 0 = 00002000 | 00002000"));
827
        writeline(output, lineTemp);
828
        wait for 5 ms;
829
        writeTimerOC(nTimer => mkTimer(3),
830
                                nNoteLeft => mkNote(0),
831
                                nPowerLeft => mkPower(0),
832
                                nPitchBendLeft => mkPitchBend(16#2000#),
833
                                nNoteRight => mkNote(0),
834
                                nPowerRight => mkPower(0),
835
                                nPitchBendRight => mkPitchBend(16#2000#),
836
                                SS => timerocd_SPI_SS_n,
837
                                MOSI => timerocd_SPI_MOSI,
838
                                CLK => timerocd_SPI_CLK);
839
        write(lineTemp, string'("Writing Bank 0 Timer 3 = 00002000 | 00002000"));
840
        writeline(output, lineTemp);
841
        wait for 5 ms;
842
        writeTimerOC(nTimer => mkTimer(1),
843
                                nNoteLeft => mkNote(0),
844
                                nPowerLeft => mkPower(0),
845
                                nPitchBendLeft => mkPitchBend(16#2000#),
846
                                nNoteRight => mkNote(0),
847
                                nPowerRight => mkPower(0),
848
                                nPitchBendRight => mkPitchBend(16#2000#),
849
                                SS => timerocd_SPI_SS_n,
850
                                MOSI => timerocd_SPI_MOSI,
851
                                CLK => timerocd_SPI_CLK);
852
        write(lineTemp, string'("Writing Bank 0 Timer 1 = 00002000 | 00002000"));
853
        writeline(output, lineTemp);
854
        wait for 5 ms;
855
 
856
        report "Testing Reset Logic";
857
        writeTimerOC(nTimer => mkTimer(0),
858
                                nNoteLeft => mkNote(21),
859
                                nPowerLeft => mkPower(1),
860
                                nPitchBendLeft => mkPitchBend(16#2000#),
861
                                nNoteRight => mkNote(0),
862
                                nPowerRight => mkPower(0),
863
                                nPitchBendRight => mkPitchBend(16#2000#),
864
                                SS => timerocd_SPI_SS_n,
865
                                MOSI => timerocd_SPI_MOSI,
866
                                CLK => timerocd_SPI_CLK);
867
        write(lineTemp, string'("Writing Bank 0 Timer 0 = 15012000 | 00002000"));
868
        writeline(output, lineTemp);
869
        wait for 10 ms;
870
        writeTimerOC(nTimer => mkTimer(1),
871
                                nNoteLeft => mkNote(108),
872
                                nPowerLeft => mkPower(127),
873
                                nPitchBendLeft => mkPitchBend(16#2000#),
874
                                nNoteRight => mkNote(0),
875
                                nPowerRight => mkPower(0),
876
                                nPitchBendRight => mkPitchBend(16#2000#),
877
                                SS => timerocd_SPI_SS_n,
878
                                MOSI => timerocd_SPI_MOSI,
879
                                CLK => timerocd_SPI_CLK);
880
        write(lineTemp, string'("Writing Bank 0 Timer 1 = 6C7F2000 | 00002000"));
881
        writeline(output, lineTemp);
882
        wait for 5 ms;
883
        writeTimerOC(nTimer => mkTimer(3),
884
                                nNoteLeft => mkNote(0),
885
                                nPowerLeft => mkPower(0),
886
                                nPitchBendLeft => mkPitchBend(16#2000#),
887
                                nNoteRight => mkNote(101),
888
                                nPowerRight => mkPower(127),
889
                                nPitchBendRight => mkPitchBend(16#2000#),
890
                                SS => timerocd_SPI_SS_n,
891
                                MOSI => timerocd_SPI_MOSI,
892
                                CLK => timerocd_SPI_CLK);
893
        write(lineTemp, string'("Writing Bank 0 Timer 3 = 00002000 | 657F2000"));
894
        writeline(output, lineTemp);
895
        wait for 10 ms;
896
        report "Sending Reset";
897
        writeCommand(nCommand => "000000",
898
                                nCmdData => nRcvCmdData,
899
                                SS => timerocd_SPI_SS_n,
900
                                MISO => timerocd_SPI_MISO,
901
                                MOSI => timerocd_SPI_MOSI,
902
                                CLK => timerocd_SPI_CLK);
903
        wait for 5 ms;
904
        readTimerOC(nTimer => mkTimer(0),
905
                                nRetVal => nReceivedData,
906
                                SS => timerocd_SPI_SS_n,
907
                                MISO => timerocd_SPI_MISO,
908
                                MOSI => timerocd_SPI_MOSI,
909
                                CLK => timerocd_SPI_CLK);
910
        write(lineTemp, string'("Read>>  Bank 0 Timer 0 = "));
911
        hwrite(lineTemp, nReceivedData);
912
        writeline(output, lineTemp);
913
        assert (nReceivedData = X"00002000_00002000") report "Expected: 00002000 | 00002000" severity warning;
914
        wait for 5 ms;
915
        readTimerOC(nTimer=>mkTimer(1),
916
                                nRetVal => nReceivedData,
917
                                SS => timerocd_SPI_SS_n,
918
                                MISO => timerocd_SPI_MISO,
919
                                MOSI => timerocd_SPI_MOSI,
920
                                CLK => timerocd_SPI_CLK);
921
        write(lineTemp, string'("Read>>  Bank 0 Timer 1 = "));
922
        hwrite(lineTemp, nReceivedData);
923
        writeline(output, lineTemp);
924
        assert (nReceivedData = X"00002000_00002000") report "Expected: 00002000 | 00002000" severity warning;
925
        wait for 5 ms;
926
        readTimerOC(nTimer => mkTimer(3),
927
                                nRetVal => nReceivedData,
928
                                SS => timerocd_SPI_SS_n,
929
                                MISO => timerocd_SPI_MISO,
930
                                MOSI => timerocd_SPI_MOSI,
931
                                CLK => timerocd_SPI_CLK);
932
        write(lineTemp, string'("Read>>  Bank 0 Timer 3 = "));
933
        hwrite(lineTemp, nReceivedData);
934
        writeline(output, lineTemp);
935
        assert (nReceivedData = X"00002000_00002000") report "Expected: 00002000 | 00002000" severity warning;
936
        wait for 5 ms;
937
 
938
        -- Add more tests here
939
        wait;
940
end process stimproc;
941
 
942
end behavior;
943
 

powered by: WebSVN 2.1.0

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