2323#
2424#******************************************************************************
2525#
26- # File: rpi_strand_test .py
26+ # File: rpi_strand_gpo_test .py
2727# Date: Sun Aug 18 12:00:00 EDT 2019
2828#
2929# Functional Description:
3030#
31- # Raspberry Pi Based Strand Test
31+ # Raspberry Pi Strand Plus GPO Test
32+ #
33+ # Notes:
34+ #
35+ # - Raspbery Pi SPI Master Code
36+ # - RPi Board Pin 36 is used as an Active Low FPGA Logic Reset
37+ # - RPi CE0 is used for the FPGA User SPI Slave Chip Select
3238#
3339#******************************************************************************
3440
35- # Raspbery Pi SPI Master Code
36- # Board Pin 36 is used as an Active Low FPGA Logic Reset
37- # RPi CE0 is used for the FPGA User SPI Slave Chip Select
38-
3941import sys
4042import time
4143import spidev
4648metrics ['tx_sum' ] = 0
4749metrics ['tx_max' ] = 0
4850metrics ['tx_min' ] = 10000
51+ fc_count = 0
52+ led_state = 0
4953
5054def spi_transfer (msg , verbose ):
5155 if (verbose == 1 ):
@@ -103,25 +107,31 @@ def reg_write(offset, wdata):
103107 print ()
104108
105109def rgb_load (rgb ):
110+ global fc_count
111+
106112 msg = [0x04 ]
107113 msg .extend (rgb )
108114 retval = spi_transfer (msg , 0 )
109115
110116 # Wait until not Almost fulll
111- while ((retval [- 1 ] & 0x08 ) == 1 ):
112- print ("Flow Controlled" )
117+ while ((retval [- 1 ] & 0x08 ) != 0x00 ):
118+ # print ("Flow Controlled")
113119 msg = [0x00 , 0x00 , 0x00 , 0x00 ]
114120 retval = spi_transfer (msg , 0 )
121+ fc_count += 1
115122
116123def rgb_reset_code ():
124+ global fc_count
125+
117126 msg = [0x07 , 0xA5 ]
118127 retval = spi_transfer (msg , 0 )
119128
120129 # Wait until not Almost fulll
121- while ((retval [- 1 ] & 0x08 ) == 1 ):
122- print ("Flow Controlled" )
130+ while ((retval [- 1 ] & 0x08 ) != 0x00 ):
131+ # print ("Flow Controlled")
123132 msg = [0x00 , 0x00 , 0x00 , 0x00 ]
124133 retval = spi_transfer (msg , 0 )
134+ fc_count += 1
125135
126136
127137RESET_PIN = 36
@@ -138,7 +148,7 @@ def rgb_reset_code():
138148spi .open (BUS_ID , DEVICE_ID )
139149
140150# Set SPI speed and mode
141- spi .max_speed_hz = 1953000
151+ spi .max_speed_hz = 15600000
142152spi .mode = 0
143153
144154print ("\n Reset FPGA Fabric Logic" )
@@ -154,7 +164,7 @@ def rgb_reset_code():
154164print ("Issue Hardware Revision Command" )
155165revision_read ()
156166
157- # print ("Issue Register Write Command (Reset Code Timing")
167+ print ("Issue Register Write Command (Reset Code Timing) " )
158168reg_write (0x0C , [0xA0 ])
159169
160170print ("Issue Register Reads Command (All Registers)" )
@@ -164,6 +174,9 @@ def rgb_reset_code():
164174reg_write (0xF2 , [0x12 , 0x34 , 0x56 , 0x78 ])
165175reg_read (0xF2 , 4 )
166176
177+ print ("Enabling LEDs" )
178+ reg_write (0xF1 , [3 ])
179+
167180print ("Issue RGB Commands" )
168181loop_count = 1
169182while (1 ):
@@ -229,9 +242,24 @@ def rgb_reset_code():
229242 if (delta < metrics ['tx_min' ]):
230243 metrics ['tx_min' ] = delta
231244
245+ # Set PCB LED
246+ if (led_state == 0 ):
247+ reg_write (0xF0 , [1 ])
248+ led_state = 1
249+ elif (led_state == 1 ):
250+ reg_write (0xF0 , [2 ])
251+ led_state = 2
252+ elif (led_state == 2 ):
253+ reg_write (0xF0 , [3 ])
254+ led_state = 3
255+ else :
256+ reg_write (0xF0 , [0 ])
257+ led_state = 0
258+
232259 # Render Average
233260 metrics ['rend_avg' ] = (metrics ['tx_sum' ] / metrics ['loop_count' ])
234- print ("LEDs: %1d; Current Render: %9f; TX Avg: %9f; TX Max: %9f, TX Min: %9f" % (LED_COUNT , cdelta , metrics ['rend_avg' ], metrics ['tx_max' ], metrics ['tx_min' ]))
261+ print ("LEDs: %1d; Current Render: %9f; TX Avg: %9f; TX Max: %9f, TX Min: %9f; Flow Control: %5d" % (LED_COUNT , cdelta , metrics ['rend_avg' ], metrics ['tx_max' ], metrics ['tx_min' ], fc_count ))
262+ fc_count = 0
235263
236264spi .close ()
237265exit ()
0 commit comments