Exemple #1
0
 def join(self):
     logging.debug("joining")
     self.running = False
     self.t.join()        
     self.ddr_mem.close()                                    # Close the memory        
     pypruss.pru_disable(0)                                  # Disable PRU 0, this is already done by the firmware
     pypruss.exit()                                          # Exit, don't know what this does. 
Exemple #2
0
 def __del__(self):
     # Hope we get there
     print('Closing the PRU interface')
     pypruss.pru_disable(0) # Does not wait for program to complete, I don't care here
     pypruss.exit()
     self.pruicss.close()
     self.mem_fd.close()
Exemple #3
0
 def __del__(self):
     # Hope we get there
     print('Closing the PRU interface')
     pypruss.pru_disable(
         0)  # Does not wait for program to complete, I don't care here
     pypruss.exit()
     self.pruicss.close()
     self.mem_fd.close()
Exemple #4
0
 def __del__(self):
     global OneWire  # Hack: sometimes OneWire is deleted before self
     if not OneWire:
         OneWire = self._keepalive
     OneWire.nInstances -= 1
     if not OneWire.nInstances:
         print('Exiting PRU program')
         pypruss.pru_disable(0)
         pypruss.exit()
Exemple #5
0
 def __del__(self):
     global OneWire # Hack: sometimes OneWire is deleted before self
     if not OneWire:
         OneWire = self._keepalive
     OneWire.nInstances -= 1
     if not OneWire.nInstances:
         print('Exiting PRU program')
         pypruss.pru_disable(0)
         pypruss.exit()
Exemple #6
0
def main():
    # Initialize environment
    pypruss.modprobe()

    pypruss.init()              # Init the PRU
    pypruss.open(0)             # Open PRU event 0 which is PRU0_ARM_INTERRUPT
    pypruss.pruintc_init()      # Init the interrupt controller
    pypruss.exec_program(0, "./hello_pru.bin")  # Load firmware on PRU0
    pypruss.wait_for_event(0)   # Wait for event 0 which is conn to PRU0_ARM_INTERUPT
    pypruss.clear_event(0)      # Clear the event
    pypruss.exit()              # Exit PRU

    print("Test completed: PRU was successfully opened and closed.")
Exemple #7
0
def runOnPRU(PRU, binFile, interrupt=1):
    try:
        pypruss.init()  # Init the PRU
        pypruss.open(interrupt)  # Open PRU  PRU1_ARM_INTERRUPT
        pypruss.pruintc_init()  # Init the interrupt controller
        pypruss.exec_program(PRU, binFile)
        log.info('PRU %s executing %s' % (PRU, os.path.split(binFile)[len(os.path.split(binFile)) - 1]))
        pypruss.wait_for_event(interrupt)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
        pypruss.clear_event(interrupt)  # Clear the event
        pypruss.exit()
    except Exception, e:
        log.error(e)
        pypruss.exit()
        raise Exception('Error executing file %s on PRU' % binFile)
Exemple #8
0
    def stop(self):
        print("Ending")
        # Set our command byte to FF and write it out
        self.data[0] = 0x000000FF
        pypruss.pru_write_memory(0, 0, self.data)

        # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
        pypruss.wait_for_event(0)
        # Clear the event
        pypruss.clear_event(0)
        # Disable PRU 0, this is already done by the firmware
        pypruss.pru_disable(0)
        # Exit, don't know what this does.
        pypruss.exit()
Exemple #9
0
	def stop(self):
		print("Ending")
		# Set our command byte to FF and write it out
		self.data[0] = 0x000000FF
		pypruss.pru_write_memory(0, 0, self.data)

		# Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
		pypruss.wait_for_event(0)
		# Clear the event
		pypruss.clear_event(0)
		# Disable PRU 0, this is already done by the firmware
		pypruss.pru_disable(0)
		# Exit, don't know what this does.
		pypruss.exit()
Exemple #10
0
def resetPRU(start_stop):
    for PRU in range(0, 2):
        if os.path.isfile(reset_pru_bin):
            pypruss.init()  # Init the PRU
            pypruss.open(1)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
            pypruss.pruintc_init()  # Init the interrupt controller
            pypruss.exec_program(
                PRU, reset_pru_bin)  # Load firmware "mem_write.bin" on PRU 0
            pypruss.wait_for_event(
                1)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
            print("PRU " + str(PRU) + " " + start_stop)
            pypruss.clear_event(1)  # Clear the event
            pypruss.exit()
        else:
            compile_assembler(os.path.join(header_folder, "reset.p"))
Exemple #11
0
def moveStepper_p9_15(steps):
    pypruss.modprobe()
    pypruss.init()
    pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
    pypruss.pruintc_init()  # Init the interrupt controller

    setSteps(steps)

    pypruss.exec_program(
        0, "./pru/p9_15.bin")  # Load firmware "blinkled.bin" on PRU 0
    pypruss.wait_for_event(
        0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
    pypruss.clear_event(0)  # Clear the event
    pypruss.pru_disable(
        0)  # Disable PRU 0, this is already done by the firmware
    pypruss.exit()  # Exit, don't know what this does.
Exemple #12
0
 def initReceiver(self, clearMem=True, copyMem=False, memBlock=100):
     """Initialize the input receiver
     1. copy out the memory content if set, default false
     2. Reset the moemory contents if set, default True
     3. Start the receiver binary on the receiving PRU"""
     if copyMem:
         self.PRUMemContents = readOutPRUMem(blocks=0)
     if clearMem:
         resetPRUMem(memBlock)
         log.info('PRU Memory Cleared %s blocks' % memBlock)
     pypruss.init()  # Init the PRU
     pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
     pypruss.pruintc_init()  # Init the interrupt controller
     pypruss.exec_program(receivingPRU, self.inputBinary)  # Load firmware for input recording
     pypruss.clear_event(0)
     pypruss.exit()
Exemple #13
0
def sendData(addr, data, rx=0):
    if (rx == 0):
        data = [int((0x00 << 24) + (addr << 16) + data)]
    else:
        data = [int((0x80 << 24) + (addr << 16) + 0x0000)]

    # data = [0x80272345]
    GPIO.output("P8_30", GPIO.LOW)
    pypruss.init()  # Init the PRU
    pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
    pypruss.pruintc_init()  # Init the interrupt controller
    pypruss.pru_write_memory(1, 0, data)  # Load the data in the PRU ram
    pypruss.exec_program(
        1, "arm/spi_awg.bin")  # Load firmware "mem_write.bin" on PRU 0
    pypruss.wait_for_event(
        0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
    pypruss.clear_event(0)  # Clear the event
    # data = [0x12345678]
    pypruss.pru_write_memory(1, 0, data)  # Load the data in the PRU ram
    GPIO.output("P8_30", GPIO.HIGH)
    if (rx == 1):

        PRU_ICSS = 0x4A300000
        PRU_ICSS_LEN = 512 * 1024

        # RAM0_START = 0x00000000
        # RAM1_START = 0x00002000
        RAM2_START = 0x00012000

        with open("/dev/mem", "r+b") as f:
            ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS)
            # local = struct.unpack('LLLL', ddr_mem[RAM1_START:RAM1_START+16])
            shared = struct.unpack('L', ddr_mem[RAM2_START:RAM2_START + 4])
        f.close()
    pypruss.exit()  # Exit
    if (rx == 1):
        return shared[0]
    else:
        return 0
Exemple #14
0
def sendData(addr,data,rx=0):
	if(rx==0):
		data = [int((0x00 << 24) + (addr << 16) + data)]
	else:
		data = [int((0x80 << 24) + (addr << 16) + 0x0000)]
	
	# data = [0x80272345]	
	GPIO.output("P8_30",GPIO.LOW)
	pypruss.init()						# Init the PRU
	pypruss.open(0)						# Open PRU event 0 which is PRU0_ARM_INTERRUPT
	pypruss.pruintc_init()					# Init the interrupt controller
	pypruss.pru_write_memory(1, 0, data)			# Load the data in the PRU ram
	pypruss.exec_program(1, "arm/spi_awg.bin")		# Load firmware "mem_write.bin" on PRU 0
	pypruss.wait_for_event(0)				# Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
	pypruss.clear_event(0)					# Clear the event
	# data = [0x12345678]
	pypruss.pru_write_memory(1, 0, data)			# Load the data in the PRU ram
	GPIO.output("P8_30",GPIO.HIGH)
	if (rx == 1):

		PRU_ICSS = 0x4A300000  
		PRU_ICSS_LEN = 512*1024 

		# RAM0_START = 0x00000000
		# RAM1_START = 0x00002000
		RAM2_START = 0x00012000


		with open("/dev/mem", "r+b") as f:
			ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS) 
			# local = struct.unpack('LLLL', ddr_mem[RAM1_START:RAM1_START+16])
			shared = struct.unpack('L', ddr_mem[RAM2_START:RAM2_START+4])
		f.close()
	pypruss.exit()							# Exit
	if (rx == 1):
		return shared[0]
	else:
		return 0
Exemple #15
0
    def emergency_interrupt(self):
        pypruss.pru_disable(0)                                  # Disable PRU 0, this is already done by the firmware
        pypruss.exit()                                          # Exit, don't know what this does. 
        logging.debug('Resetting PRU...')
      
        self.pru_data       = []

        while True:
            try:
                b = self.ddr_used.get(block=False)
                if b != None:
                    self.ddr_used.task_done()
            except Queue.Empty:
                break

        self.ddr_reserved   = 0      
        with Pru.ddr_lock: 
            self.ddr_mem_used   = 0  
        self.clear_events   = []       
        self.ddr_start      = self.DDR_START
        self.ddr_nr_events  = self.ddr_addr+self.ddr_size-4

        self.init_pru()
Exemple #16
0
def main():
    # Initialize evironment
    pypruss.modprobe()
    pypruss.init()		# Init the PRU
    pypruss.open(0)		# Open PRU event 0 which is PRU0_ARM_INTERRUPT
    pypruss.pruintc_init()  # Init the interrupt controller

    # Configure PRU Registers
    pypruss.pru_write_memory(0, 0, [0, ])

    # Execute the PRU program
    a = time.time()
    pypruss.exec_program(0, "./bin/timer_app.bin")  # Load firmware on PRU0

    # Wait for PRU to finish its job.
    pypruss.wait_for_event(0)  # Wait for event 0 which is conn to PRU0_ARM_INTERUPT
    loop_time = time.time() - a

    # Once signal has been received, clean up house
    pypruss.clear_event(0)  # Clear the event
    pypruss.exit()		# Exit PRU

    print("That's a %ds loop you have there." % loop_time)
    print("Test completed: PRU was successfully opened and closed.")
Exemple #17
0
def end():
    pypruss.pru_disable(0)
    pypruss.exit()
Exemple #18
0
''' blinkled.py - test script for the PyPRUSS library
It blinks the user leds ten times'''

import pypruss

pypruss.modprobe()  # This only has to be called once pr boot
pypruss.init()  # Init the PRU
pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.pruintc_init()  # Init the interrupt controller
pypruss.exec_program(0,
                     "./blinkled.bin")  # Load firmware "blinkled.bin" on PRU 0
pypruss.wait_for_event(
    0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)  # Clear the event
pypruss.pru_disable(0)  # Disable PRU 0, this is already done by the firmware
pypruss.exit()  # Exit, don't know what this does.
Exemple #19
0
reg = struct.unpack("<L", mem[GPIO_OE:GPIO_OE + 4])[0]
mem[GPIO_OE:GPIO_OE + 4] = struct.pack("<L", reg & ~VCC)
mem[GPIO_SETDATAOUT:GPIO_SETDATAOUT + 4] = struct.pack("<L", VCC)

init_receiver("inputReceiver_PRU0.bin")
for binary in binaries:
    pypruss.init()  # Init the PRU
    pypruss.open(1)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
    pypruss.pruintc_init()  # Init the interrupt controller
    pypruss.exec_program(1, os.path.join(
        binary_folder, binary))  # Load firmware "mem_write.bin" on PRU 0
    pypruss.wait_for_event(
        1)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
    print("PRU 1 completed " + binary)
    pypruss.clear_event(1)  # Clear the event
    pypruss.exit()
# end_receiver()
raw_input("All files executed, press ENTER to shutdown device\n")

# Reset the GPIO on both PRU
resetPRU("shut down")
mem[GPIO_CLEARDATAOUT:GPIO_CLEARDATAOUT + 4] = struct.pack("<L", VCC)

with open("/dev/mem", "r+b") as f:
    ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS)
    endReached = False
    x = 0
    comparePattern = ""
    lines_printed = 0
    system("clear")
    print("Printing memory dump:\n\n")
Exemple #20
0
 def stop(self):
     pypruss.pru_disable(1)				# Disable PRU 1, this is already done by the firmware
     pypruss.exit()
     self.data = None
Exemple #21
0
 def close( self ):
     if( self.clear_leds_at_end ):
         self.clear()
     pypruss.exit()
Exemple #22
0
ddr_size = pypruss.ddr_size()

print "DDR memory address is 0x%x and the size is 0x%x"%(ddr_addr, ddr_size)

ddr_offset  = ddr_addr-0x10000000
ddr_filelen = ddr_size+0x10000000
ddr_start 	= 0x10000000
ddr_end 	= 0x10000000+ddr_size

pypruss.init()		# Init the PRU
pypruss.open(0)		# Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.pruintc_init()	# Init the interrupt controller
pypruss.pru_write_memory(0, 0, [ddr_addr, ddr_addr+ddr_size-4])	# Put the ddr address in the first region 
pypruss.exec_program(0, "./ddr_write.bin")	# Load firmware "ddr_write.bin" on PRU 0
pypruss.wait_for_event(0)	# Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)		# Clear the event
pypruss.exit()			# Exit PRU

with open("/dev/mem", "r+b") as f:	# Open the physical memory device
	ddr_mem = mmap.mmap(f.fileno(), ddr_filelen, offset=ddr_offset) # mmap the right area

read_back = struct.unpack("L", ddr_mem[ddr_start:ddr_start+4])[0]	# Parse the data
read_back2 = struct.unpack("L", ddr_mem[ddr_end-4:ddr_end])[0]		# Parse the data

print "The first 4 bytes of DDR memory reads "+hex(read_back)
print "The last 4 bytes of DDR memory reads "+hex(read_back2)

ddr_mem.close()								# Close the memory 
f.close()								# Close the file

Exemple #23
0
from __future__ import print_function

import pypruss

print("Running modprobe")
pypruss.modprobe(1000)
print("modprobe ok")

pypruss.init()
print("init ok")

pypruss.open(0)
print("open ok")

pypruss.pruintc_init()
print("intc ok")

print("ddr addr is " + hex(pypruss.ddr_addr()))
print("ddr size is " + hex(pypruss.ddr_size()))

pypruss.exit()
print("exit ok")

pypruss.modunprobe()
print("modunprobe ok")
	print percentChange
	#Now we've compared. Let's write the most recent speed to our file.
	f = open('speed.txt', 'w')
	f.write (speed[0])
	f.close()


	pypruss.modprobe() 			  				       	# This only has to be called once pr boot
	pypruss.init()										# Init the PRU
	pypruss.open(0)										# Open PRU event 0 which is PRU0_ARM_INTERRUPT
	pypruss.pruintc_init()								# Init the interrupt controller

	if percentChange < -5:
		pypruss.exec_program(0,"./red.bin")
	else: 
		if percentChange < 0:
			pypruss.exec_program(0,"./orange.bin")
		else:
			if percentChange > 0:
				pypruss.exec_program(0,"./green.bin")
			else:
				pypruss.exec_program(0,"./other.bin")   #should never hit this
		
	pypruss.wait_for_event(0)							# Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
	pypruss.clear_event(0)								# Clear the event
	pypruss.pru_disable(0)								# Disable PRU 0, this is already done by the firmware
	pypruss.exit()									# Exits pypruss 
	time.sleep(interval)                        						# restarts speed evaluation after 'interval' seconds

Exemple #25
0
def cleanup(signum, frame):
    pypruss.pru_disable(0)
    pypruss.exit()                                # Exit
    sys.exit()
Exemple #26
0
RAM0_START = 0x00000000
RAM1_START = 0x00002000
RAM2_START = 0x00012000


with open("/dev/mem", "r+b") as f:	       
    ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS) 
    ddr_mem[RAM0_START:RAM0_START+4] = struct.pack('L', 0)
    ddr_mem[RAM1_START:RAM1_START+4] = struct.pack('L', 0)
    ddr_mem[RAM2_START:RAM2_START+4] = struct.pack('L', 0)

pypruss.init()								# Init the PRU
pypruss.open(0)								# Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.pruintc_init()						# Init the interrupt controller
pypruss.exec_program(1, "./mem_read.bin")	# Load firmware "mem_write.bin" on PRU 0
pypruss.wait_for_event(0)					# Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)						# Clear the event
pypruss.exit()								# Exit



with open("/dev/mem", "r+b") as f:	       
    ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS) 
    local = struct.unpack('L', ddr_mem[RAM0_START:RAM0_START+4])
    print hex(local[0])
    local = struct.unpack('L', ddr_mem[RAM1_START:RAM1_START+4])
    print hex(local[0])
    shared = struct.unpack('L', ddr_mem[RAM2_START:RAM2_START+4])
    print hex(shared[0])
Exemple #27
0
ddr_offset = ddr_addr - 0x10000000
ddr_filelen = ddr_size + 0x10000000
ddr_start = 0x10000000
ddr_end = 0x10000000 + ddr_size

pypruss.init()  # Init the PRU
pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.pruintc_init()  # Init the interrupt controller
pypruss.pru_write_memory(0, 0, [ddr_addr, ddr_addr + ddr_size - 4
                                ])  # Put the ddr address in the first region
pypruss.exec_program(
    0, "./ddr_write.bin")  # Load firmware "ddr_write.bin" on PRU 0
pypruss.wait_for_event(
    0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)  # Clear the event
pypruss.exit()  # Exit PRU

with open("/dev/mem", "r+b") as f:  # Open the physical memory device
    ddr_mem = mmap.mmap(f.fileno(), ddr_filelen,
                        offset=ddr_offset)  # mmap the right area

read_back = struct.unpack("L", ddr_mem[ddr_start:ddr_start +
                                       4])[0]  # Parse the data
read_back2 = struct.unpack("L",
                           ddr_mem[ddr_end - 4:ddr_end])[0]  # Parse the data

print "The first 4 bytes of DDR memory reads " + hex(read_back)
print "The last 4 bytes of DDR memory reads " + hex(read_back2)

ddr_mem.close()  # Close the memory
f.close()  # Close the file
Exemple #28
0
PRU_ICSS_LEN = 512 * 1024

RAM0_START = 0x00000000
RAM1_START = 0x00002000
RAM2_START = 0x00012000

with open("/dev/mem", "r+b") as f:
    ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS)
    ddr_mem[RAM0_START:RAM0_START + 4] = struct.pack('L', 0)
    ddr_mem[RAM1_START:RAM1_START + 4] = struct.pack('L', 0)
    ddr_mem[RAM2_START:RAM2_START + 4] = struct.pack('L', 0)

pypruss.init()  # Init the PRU
pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.pruintc_init()  # Init the interrupt controller
pypruss.exec_program(
    1, "./mem_read.bin")  # Load firmware "mem_write.bin" on PRU 0
pypruss.wait_for_event(
    0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)  # Clear the event
pypruss.exit()  # Exit

with open("/dev/mem", "r+b") as f:
    ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS)
    local = struct.unpack('L', ddr_mem[RAM0_START:RAM0_START + 4])
    print hex(local[0])
    local = struct.unpack('L', ddr_mem[RAM1_START:RAM1_START + 4])
    print hex(local[0])
    shared = struct.unpack('L', ddr_mem[RAM2_START:RAM2_START + 4])
    print hex(shared[0])
Exemple #29
0
 def force_exit(self):
     self.running = False  
     pypruss.pru_disable(0)                                  # Disable PRU 0, this is already done by the firmware
     pypruss.exit()                                          # Exit, don't know what this does. 
Exemple #30
0
    print percentChange
    #Now we've compared. Let's write the most recent speed to our file.
    f = open('speed.txt', 'w')
    f.write(speed[0])
    f.close()

    pypruss.modprobe()  # This only has to be called once pr boot
    pypruss.init()  # Init the PRU
    pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
    pypruss.pruintc_init()  # Init the interrupt controller

    if percentChange < -5:
        pypruss.exec_program(0, "./red.bin")
    else:
        if percentChange < 0:
            pypruss.exec_program(0, "./orange.bin")
        else:
            if percentChange > 0:
                pypruss.exec_program(0, "./green.bin")
            else:
                pypruss.exec_program(0, "./other.bin")  #should never hit this

    pypruss.wait_for_event(
        0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
    pypruss.clear_event(0)  # Clear the event
    pypruss.pru_disable(
        0)  # Disable PRU 0, this is already done by the firmware
    pypruss.exit()  # Exits pypruss
    time.sleep(interval)  # restarts speed evaluation after 'interval' seconds
Exemple #31
0
''' blinkled.py - test script for the PyPRUSS library
It blinks the user leds ten times'''

import pypruss

pypruss.modprobe() 			  				       	# This only has to be called once pr boot
pypruss.init()										# Init the PRU
pypruss.open(0)										# Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.pruintc_init()								# Init the interrupt controller
pypruss.exec_program(0, "./blinkled.bin")			# Load firmware "blinkled.bin" on PRU 0
pypruss.wait_for_event(0)							# Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)								# Clear the event
pypruss.pru_disable(0)								# Disable PRU 0, this is already done by the firmware
pypruss.exit()										# Exit, don't know what this does. 
Exemple #32
0
def cleanup(signum, frame):
    pypruss.pru_disable(0)
    pypruss.exit()  # Exit
    sys.exit()
Exemple #33
0
    def stop_pru(self):

        pypruss.pru_disable(0)
        pypruss.exit()
        return 0