Example #1
0
	def __init__(self, num=0):
		self.num = num
		pypruss.modprobe()
		pypruss.init()
		pypruss.open(self.num)
		pypruss.pruintc_init()
		pypruss.pru_write_memory(0,0,[ddr])
		pypruss.exec_program(0,'./matrix.bin')
Example #2
0
File: Pru.py Project: zittix/redeem
 def init_pru(self):
     self.ddr_mem[self.ddr_start:self.ddr_start+4] = struct.pack('L', 0)  # Add a zero to the first reg to make it wait
     pypruss.init()                                  # Init the PRU
     pypruss.open(0)                                 # Open PRU event 0 which is PRU0_ARM_INTERRUPT
     pypruss.open(1)                                 # Open PRU event 1 which is PRU1_ARM_INTERRUPT
     pypruss.pruintc_init()                          # Init the interrupt controller
     pypruss.pru_write_memory(0, 0, [self.ddr_addr, self.ddr_nr_events, 0])      # Put the ddr address in the first region         
     pypruss.exec_program(0, self.firmware.get_firmware(0))                      # Load firmware on PRU 0
     pypruss.exec_program(1, self.firmware.get_firmware(1))                      # Load firmware on PRU 1
Example #3
0
	def __init__(self):
		for pwm in range(16):
			self.data.append(0x00000001) # Zero out the PWMs

		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.pru_write_memory(0, 0, self.data)
Example #4
0
 def reload(self):
     """ Re-initializes the PRU's interrupt that this library uses to tell
     python that it can continue running code again. This must be called at
     the end of a function that utilizes this interrupt. The calling
     function should not be responsible for reloading PRUs
     """
     pypruss.init()      # Init the PRU
     pypruss.open(0)     # Open PRU event 0 which is PRU0_ARM_INTERRUPT
     pypruss.pruintc_init()  # Init the interrupt controller
Example #5
0
 def __init__(self, prog):
     self.val = {}
     pypruss.modprobe()
     pypruss.init()
     pypruss.open(event_nr)
     pypruss.pruintc_init()
     pypruss.pru_disable(1)
     self.data = pypruss.map_prumem(pypruss.PRUSS0_PRU1_DATARAM)
     self.write32(COM_RANGE, 0)
     pypruss.exec_program(1, prog)
Example #6
0
	def setup(this):
		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
		this.buffer = pypruss.map_prumem(pypruss.PRUSS0_PRU0_DATARAM)
		pypruss.exec_program(0, "./triac.bin")			# Load firmware "blinkled.bin" on PRU 0
		this.brightness = [0 for x in range(N_BULBS)]

		this.writeOffset = 0
		this.write()
Example #7
0
def init(pru_bin):
  pypruss.modprobe(1024)
  ddr_addr = pypruss.ddr_addr()
  ddr_size = pypruss.ddr_size()
  print "DDR memory address is 0x%x and the size is 0x%x"%(ddr_addr, ddr_size)
  fifo = Fifo(ddr_addr, ddr_size)

  pypruss.init()
  pypruss.open(0)
  pypruss.pruintc_init()
  pypruss.pru_write_memory(0,0,[ddr_addr])
  pypruss.exec_program(0, pru_bin)
  return fifo
Example #8
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.")
Example #9
0
File: dallas.py Project: Miaou/BBB
 def __init__(self, port, pin, pullup_port, pullup_pin, bMappedPRU):
     if not OneWire.nInstances:
         # Init PRU
         print('Loading program into PRU')
         pypruss.init();
         pypruss.open(pypruss.PRU_EVTOUT_0)
         pypruss.pruintc_init();
         pypruss.exec_program(0, './dallas.bin')
     OneWire.nInstances += 1
     self.bIsBusy = False # May help in the future
     self.bMappedPRU = bMappedPRU
     self.port, self.pin, self.pullup_port, self.pullup_pin = port, pin, pullup_port, pullup_pin
     self._keepalive = OneWire # Avoids that the OneWire class is deleted before its instances...
     self.dSensors = {}
Example #10
0
	def __init__(self):
		for pwm in range(32):
			# Initialize the 32 PWM channels to 1
			self.data.append(0x00000001)

		# Init the PRU
		pypruss.modprobe()
		pypruss.init()
		# Open PRU event 0 (PRU0_ARM_INTERRUPT)
		pypruss.open(0)
		# Init the interrupt controller
		pypruss.pruintc_init()
		# Write out our data structure to the PRU Data Ram
		pypruss.pru_write_memory(0, 0, self.data)
Example #11
0
File: servos.py Project: Miaou/BBB
 def __init__(self, sPathBin):
     try:
         addr = int(open('/sys/class/uio/uio0/maps/map0/addr', 'rb').read(), 16)
     except IOError as e:
         print('---> ERROR while opening the pruss memory <---')
         print('Probably there is something wrong with capes (did you "echo BB-BONE-PRU-ACT > /sys/devices/bone_capemgr.9/slots" ?)')
         raise e
     self.sPathBin = sPathBin
     self.mem_fd = open('/dev/mem', 'r+b')
     self.pruicss = mmap.mmap(self.mem_fd.fileno(), 0x080000, offset=addr)
     pypruss.init()
     # Reset is VERY important... otherwise the PRU might start at random
     #pypruss.pru_reset(0) # FAILS! x_x
     self.pruicss[0x022000] = 0 # Manual set 0 to the byte of CONTROL reg in the control regs...
     pypruss.open(pypruss.PRU_EVTOUT_0) # Is this required?
     pypruss.pruintc_init()
     pypruss.exec_program(0, self.sPathBin)
Example #12
0
    def __init__(self):
        pru_hz 			    = 200*1000*1000             # The PRU has a speed of 200 MHz
        self.s_pr_inst 		= 1.0/pru_hz                # I take it every instruction is a single cycle instruction
        self.s_pr_inst_2    = 2.0*(1.0/pru_hz)          # I take it every instruction is a single cycle instruction
        self.inst_pr_loop 	= 16                        # This is the minimum number of instructions needed to step. 
        self.inst_pr_delay 	= 2                         # Every loop adds two instructions: i-- and i != 0            
        self.sec_to_inst_dev = (self.s_pr_inst*2)
        self.pru_data       = []      	    	        # This holds all data for one move (x,y,z,e1,e2)
        self.ddr_used       = Queue.Queue(30)           # List of data lengths currently in DDR for execution
        self.ddr_reserved   = 0      
        self.ddr_mem_used   = 0  
        self.clear_events   = []       
        self.ddr_lock       = Lock() 
        self.debug = 0
    
        self.i = 0
        pypruss.modprobe(0x40000)    			        # This only has to be called once pr boot
        self.ddr_addr = pypruss.ddr_addr()
        self.ddr_size = pypruss.ddr_size() 
        print "The DDR memory reserved for the PRU is "+hex(self.ddr_size)+" and has addr "+hex(self.ddr_addr)

        ddr_offset     		= self.ddr_addr-0x10000000  # The Python mmap function cannot accept unsigned longs. 
        ddr_filelen    		= self.ddr_size+0x10000000
        self.DDR_START      = 0x10000000
        self.DDR_END        = 0x10000000+self.ddr_size
        self.ddr_start      = self.DDR_START
        self.ddr_nr_events  = self.ddr_addr+self.ddr_size-4


        with open("/dev/mem", "r+b") as f:	            # Open the memory device
            self.ddr_mem = mmap.mmap(f.fileno(), ddr_filelen, offset=ddr_offset) # mmap the right area            
            self.ddr_mem[self.ddr_start:self.ddr_start+4] = struct.pack('L', 0)  # Add a zero to the first reg to make it wait
       
        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, [self.ddr_addr, self.ddr_nr_events])		# Put the ddr address in the first region 
        pypruss.exec_program(0, "../firmware/firmware_pru_0.bin")	# Load firmware "ddr_write.bin" on PRU 0
        self.t = Thread(target=self._wait_for_events)         # Make the thread
        self.running = True
        self.t.start()		                

        logging.debug("PRU initialized")
Example #13
0
def init(pru_bin):
  pypruss.modprobe(1024)
  ddr_addr = pypruss.ddr_addr()
  ddr_size = pypruss.ddr_size()
  print "DDR memory address is 0x%x and the size is 0x%x"%(ddr_addr, ddr_size)
  fifo = Fifo(ddr_addr, ddr_size)

  pypruss.init()
  pypruss.open(0)
  pypruss.pruintc_init()

  pru_init = [ddr_addr, len(axes)]
  for step_addr, step_pin, dir_addr, dir_pin in axes:
    pru_init += [step_addr+0x194, 1 << step_pin,
                  dir_addr+0x194, 1 << dir_pin,
                  0, 0]

  pypruss.pru_write_memory(0,0,pru_init)
  pypruss.exec_program(0, pru_bin)
  return fifo
Example #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
Example #15
0
    def ready_pruss_for_burst(self, CR=None):
        """ Arms the ADC for sample collection. This removes some GPIO control
        from the BBB, and replaces it with PRUIN/OUT control.
        """

        # Initialize variables
        if CR is None:
            CR = self.conversion_rate
        else:
            self.conversion_rate = CR

        if CR == 0:
            raise ValueError("CR currently set to 0 (DEFAULT), indicating that"
                             + "user forgot to preset the sample/conversion rate."
                             + "prior to calling this function.")

        CR_BITECODE = int(round(1.0 / CR * F_CLK))  # Converts user CR input to Hex.

        # 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

        # init PRU Registers
        pypruss.exec_program(0, INIT0)  # Cleaning the registers
        pypruss.exec_program(1, INIT1)  # Cleaning the registers
        pypruss.pru_write_memory(0, 0x0000, [0x0, ] * 0x0800)  # clearing pru0 ram
        pypruss.pru_write_memory(0, 0x0800, [0x0, ] * 0x0800)  # clearing pru1 ram
        pypruss.pru_write_memory(0, 0x4000, [0x0, ] * 300)  # clearing ack bit from pru1
        pypruss.pru_write_memory(0, PRU0_CR_Mem_Offset, [CR_BITECODE, ])  # Setting conversion

        pypruss.exec_program(1, ADS7865_ClkAndSamplePRU)        # Load firmware on PRU1

        # end readying process by arming the PRUs
        boot.arm()
        self.arm_status = 'armed'
        self.modified = False
Example #16
0
    def __init__(self):
        pru_hz 			    = 200*1000*1000             # The PRU has a speed of 200 MHz
        self.s_pr_inst      = 2.0*(1.0/pru_hz)          # I take it every instruction is a single cycle instruction
        self.inst_pr_loop 	= 42                        # This is the minimum number of instructions needed to step. 
        self.inst_pr_delay 	= 2                         # Every loop adds two instructions: i-- and i != 0            
        self.sec_to_inst_dev = (self.s_pr_inst*2)
        self.pru_data       = []      	    	        # This holds all data for one move (x,y,z,e1,e2)
        self.ddr_used       = Queue.Queue()             # List of data lengths currently in DDR for execution
        self.ddr_reserved   = 0      
        self.ddr_mem_used   = 0  
        self.clear_events   = []       

        self.ddr_addr = int(open("/sys/class/uio/uio0/maps/map1/addr","rb").read().rstrip(), 0)
        self.ddr_size = int(open("/sys/class/uio/uio0/maps/map1/size","rb").read().rstrip(), 0)
        logging.info("The DDR memory reserved for the PRU is "+hex(self.ddr_size)+" and has addr "+hex(self.ddr_addr))

        ddr_offset     		= self.ddr_addr-0x20000000  # The Python mmap function cannot accept unsigned longs. 
        ddr_filelen    		= self.ddr_size+0x20000000
        self.DDR_START      = 0x20000000
        self.DDR_END        = 0x20000000+self.ddr_size
        self.ddr_start      = self.DDR_START
        self.ddr_nr_events  = self.ddr_addr+self.ddr_size-4

        with open("/dev/mem", "r+b") as f:	            # Open the memory device
            self.ddr_mem = mmap.mmap(f.fileno(), ddr_filelen, offset=ddr_offset) # mmap the right area            
            self.ddr_mem[self.ddr_start:self.ddr_start+4] = struct.pack('L', 0)  # Add a zero to the first reg to make it wait
       
        dirname = os.path.dirname(os.path.realpath(__file__))
        pypruss.init()						            # Init the PRU
        pypruss.open(PRU0)						        # Open PRU event 0 which is PRU0_ARM_INTERRUPT
        pypruss.pruintc_init()					        # Init the interrupt controller
        pypruss.pru_write_memory(0, 0, [self.ddr_addr, self.ddr_nr_events])		# Put the ddr address in the first region 
        pypruss.exec_program(0, dirname+"/../firmware/firmware_00A3.bin")	# Load firmware "ddr_write.bin" on PRU 0
        self.t = Thread(target=self._wait_for_events)         # Make the thread
        self.running = True
        self.t.start()		        
Example #17
0
    def __init__(self):
        """Build ultrasonic abstraction objects and logger."""

        # Load system configuration
        self.config = lib.get_config()
        # Get and store logger object
        self.logger = lib.get_logger()

        # Memory address that maps to the 8k PRU0 datamem block
        PRU_ADDR = 0x4a300000
        self.PRU_EVOUT_0 = 0
        self.PRU0_ARM_INTERRUPT = 19

        us_config = self.config['ultrasonics']

        try:
            with open("/dev/mem", "r+b") as f:
                # TODO: replace 32 with len(sensors) * 4 * 2 ?
                self.pru_mem = mmap.mmap(f.fileno(), 32, offset=PRU_ADDR)
        except IOError as e:
            self.logger.warning("Could not open /dev/mem: {}".format(e))
            self.pru_mem = struct.pack('IIIIIIII', 1, 2, 3, 4, 5, 6, 7, 8)

        # Initialize the PRU driver (not sure what this does?)
        pypruss.init()
        try:
            pypruss.open(self.PRU_EVOUT_0)
        except SystemError as e:
            self.logger.error("Could not open PRU: {}".format(e))
            self.logger.error("Is the PRU module (uio_pruss) loaded?")

        pypruss.pruintc_init()  # Init the interrupt controller
        self.logger.debug("Loading PRU program: {}".format(
            us_config['pru_file']))
        pypruss.exec_program(us_config['pru_num'], us_config['pru_file'])
        self.sensors = us_config['sensors']
Example #18
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.")
Example #19
0
 def __init__( self ):
     pypruss.modprobe()                          # This only has to be called once per 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
Example #20
0
from __future__ import print_function

import pypruss
import os

#on PRU0
# wait for input on PRU0 to go high.
# when it goes high, send interrupt to PRU1.

#on PRU1
# wait for interrupt from PRU0
# generate square wave

pypruss.modprobe()

pypruss.init()                                      # Init the PRU

pypruss.open(0)                                     # Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.open(1)                                     # also PRU1

pypruss.pruintc_init()

pypruss.exec_program(0, "./PRU0toPRU1.bin")
pypruss.exec_program(1, "./PRU1toPRU0.bin")

pypruss.wait_for_event(0)                   # wait for an interrupt from PRU0. currently not sent, use CtrlC       
Example #21
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")
Example #22
0
sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)

try:
    sock.bind(('localhost', UDP_PORTS[0]))
except OSError as e:
    print(e)
    sys.exit(-1)

f = open("/dev/mem", "r+b")
shared_mem = mmap.mmap(f.fileno(), SHARED_FILELEN, offset=SHARED_OFFSET)

if TARGET_PRU_NO == 1:
    pypruss.init()

pypruss.open(TARGET_PRU_NO)

if TARGET_PRU_NO == 1:
    pypruss.pruintc_init()

stopped = threading.Event()
stopped.clear()
pru_stop_thread = PRU_read_thread(stopped, sock, shared_mem)
pru_send_thread = PRU_write_thread(stopped, sock, shared_mem)
pru_stop_thread.start()
pru_send_thread.start()

pypruss.exec_program(TARGET_PRU_NO, TARGET_PRU_FW)


def signal_handler(signal, frame):
Example #23
0
#!/usr/bin/python
import os
import argparse
import pypruss

from math import ceil

if __name__ == '__main__':
    pru = 0
    firmware = "./clock.bin"
    pypruss.modprobe()                                  # This only has to be called once pr boot
    pypruss.init()                                      # Init the PRU
    pypruss.open(pru)                                   # Open PRU event <num> which is PRU<num>_ARM_INTERRUPT
    pypruss.pruintc_init()                              # Init the interrupt controller
    pypruss.exec_program(pru, firmware)                 # Load firmware on PRU <num>
    pypruss.wait_for_event(pru)                         # Wait for event <num> which is connected to PRU<num>_ARM_INTERRUPT
    pypruss.clear_event(pru)                            # Clear the event
    pypruss.pru_disable(pru)                            # Disable PRU <num>, this is already done by the firmware
    pypruss.exit()                                      # Exit, don't know what this does.


Example #24
0
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"
Example #25
0
import mmap
import struct

pypruss.modprobe(1000)
ddr_addr = pypruss.ddr_addr()
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 +