Skip to content

Commit

Permalink
debug gpiolib.py + update testgpiolib.py
Browse files Browse the repository at this point in the history
  • Loading branch information
asteencern committed Dec 13, 2017
1 parent e0ea472 commit 02ff4dd
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gpiolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def read_command(self):
r = r | (l << 7)

result = int(r)
bcm.bcm2835_gpio_write(self.STpin, self.bcm.HIGH)
bcm.bcm2835_gpio_write(self.STpin, self.bcm.HIGH)
bcm.bcm2835_gpio_write(self.STpin, bcm.HIGH)
bcm.bcm2835_gpio_write(self.STpin, bcm.HIGH)
lev = bcm.bcm2835_gpio_lev( self.ACKpin ) # check that ACK is bcm.HIGH
if lev == bcm.LOW:
NoAck = True
Expand Down
93 changes: 91 additions & 2 deletions testgpiolib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
import gpiolib
from optparse import OptionParser
from time import sleep

parser = OptionParser()

parser.add_option("-r", "--saveRawData",dest="saveRawData",
help="save raw data",default=True)

parser.add_option("-m", "--moduleNumber", dest="moduleNumber",type="int",
help="moduleNumber", default=63)

parser.add_option("-n", "--nEvent", dest="nEvent",type="int",
help="number of event",default=100)

parser.add_option("-e", "--externalChargeInjection", dest="externalChargeInjection",
help="set to use external injection",default=False)


parser.add_option("-c", "--channelIds", dest="channelIds",
help="channel Ids for charge injection", default=[36])

parser.add_option("-i", "--acquisitionType", dest="acquisitionType",choices=["standard","sweep","fixed"],
help="method for injection", default="standard")


(options, args) = parser.parse_args()

print(options)

CMD_IDLE = 0x80
CMD_RESETPULSE = 0x88
Expand All @@ -15,13 +43,74 @@
CMDH_LOOPBRFIFO = 0x1E
CMD_LOOPBACK = 0xF8
CMDH_LOOPBACK = 0x1F
DAC_HIGH_WORD = 0x42
DAC_LOW_WORD = 0x0A
TRIGGER_DELAY = 0x07# 0x00 to 0x07

prog_string_no_sign = [ 0xDA,0xA0,0xF9,0x32,0xE0,0xC1,0x2E,0x10,0x98,0xB0,
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xE9,0xD7,0xAE,0xBA,0x80,0x25 ]

gpio=gpiolib.gpiolib()

#Initialize RPI
res=gpio.set_bus_init()
print(res)

gpio.set_output_pin()
gpio.set_bus_read_mode()
res = gpio.send_command(CMD_RESETPULSE);
print(res)
gpio.set_bus_write_mode()

# gpio.set_bus_read_mode()
# gpio.set_bus_write_mode()


# empty local fifo by forcing extra reads, ignore results
for i in range(0,1):
res = gpio.read_local_fifo()

res = gpio.set_trigger_delay(TRIGGER_DELAY);

res = gpio.send_command(CMD_RSTBPULSE);
res = gpio.send_command(CMD_SETSELECT | 1);
print("\n\n####################################################\n")
print("Save Raw Data: %s\nExternal Pulse Injection: %s\nFixed Acquisition type: %s\n\n", options.saveRawData, options.externalChargeInjection, options.acquisitionType);
print("####################################################\n");
if options.externalChargeInjection!=True:
#fprintf(fout,"Configuration used for SK2\n");
#for i in range(0,48)
#fprintf(fout,"%02x ",prog_string_no_sign[i]);

#fprintf(fout,"\nConfiguration read from SK2\n");
print("\nConfiguration read from SK2\n");
outputBytes=gpio.progandverify48(prog_string_no_sign);
print([hex(outputBytes[i]) for i in range(0,48)])
#fprintf(fout,"\n");}
else:
print(fout,"\nConfiguration read from SK2\n");
outputBytes=gpio.progandverify48(prog_string_no_sign);
print([hex(outputBytes[i]) for i in range(0,48)])
# for(i = 0; i < 48; i = i + 1){
# prog_string_base[i]=prog_string_no_sign[i];
# }
# add_channel(ch,prog_string_base);

# fprintf(fout,"Configuration used for SK2\n");
# for(i = 0; i < 48; i = i + 1){
# //fprintf(fout,"%02x ",prog_string_sign_inj[i]);
# fprintf(fout,"%02x ",prog_string_base[i]);
# }
# fprintf(fout,"\nConfiguration read from SK2\n");
# //progandverify48(prog_string_sign_inj, return_string);
# progandverify48(prog_string_base, return_string);
# for(i = 0; i < 48; i = i + 1){
# fprintf(fout,"%02x ",return_string[i]);
# }
# fprintf(fout,"\n");
# }

res = gpio.send_command(CMD_SETSELECT);
sleep(0.01);
print("\nFinished Configuration\n");

0 comments on commit 02ff4dd

Please sign in to comment.