コード例 #1
0
ファイル: leds.py プロジェクト: danasf/bbb-matrix
	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')
コード例 #2
0
ファイル: Pru.py プロジェクト: 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
コード例 #3
0
ファイル: pru_stick.py プロジェクト: pbrook/beagle-football
 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)
コード例 #4
0
ファイル: triac.py プロジェクト: boxysean/pru-triac
	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()
コード例 #5
0
ファイル: stepper.py プロジェクト: hakalan/quickstep
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
コード例 #6
0
ファイル: test.py プロジェクト: ncsurobotics/acoustics
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.")
コード例 #7
0
ファイル: dallas.py プロジェクト: 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 = {}
コード例 #8
0
ファイル: servos.py プロジェクト: 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)
コード例 #9
0
ファイル: Pru.py プロジェクト: Bingzo/replicape
    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")
コード例 #10
0
ファイル: stepper.py プロジェクト: stela111/quickstep
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
コード例 #11
0
ファイル: spi_awg.py プロジェクト: antarctica/EMSLED
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
コード例 #12
0
ファイル: ultrasonic.py プロジェクト: travislovespie/bot
    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']
コード例 #13
0
ファイル: timer_app.py プロジェクト: ncsurobotics/acoustics
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.")
コード例 #14
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()		        
コード例 #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
コード例 #16
0
ファイル: minecraft.py プロジェクト: CoryStewart/ledgrid
        for iy in xrange(20):
            sprite_idx_arr.append((ix, iy))

    sprite_idx_arr = [(7, 0), (8, 0), (9, 0), (11, 0), (12, 0), (13, 0), (15, 0), (12, 1), (14, 1), (13, 3)]
    for (ix, iy) in sprite_idx_arr:
        box = ((ix) * sizex, (iy) * sizey, (ix + 1) * sizex, (iy + 1) * sizey)
        region = sheet.crop(box)

        ni = Image.new("RGB", (sizex, sizey))
        ni.paste(region, (0, 0, sizex, sizey))
        newimgname = "img_%d_%d.png" % (ix, iy)
        print "Writing %s" % newimgname
        # ni.save( newimgname )
        data = get_img_array(ni)
        pypruss.pru_write_memory(0, 0, data)  # Load the data in the PRU ram
        pypruss.exec_program(0, "./ledgriddrvr.bin")  # Load firmware 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
        sleep(1.500)  # sleep 1s

    if clear_leds_at_end:
        empty_data = [256] + [0] * 256  # 1st index is #_of_pixels, then 256 pixel values of 0 follow it
        pypruss.pru_write_memory(0, 0, empty_data)  # Load the data in the PRU ram
        pypruss.exec_program(0, "./ledgriddrvr.bin")  # Load firmware 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
        sleep(1.000)  # sleep 1s

    pypruss.exit()  # Exit
    sys.exit(0)
コード例 #17
0
ファイル: memtest.py プロジェクト: danasf/bbbio
cycle_count = 0x000014 # 20 cycles
pwm_ratio = 0x0000000E # 16 cycles on
# new io object
io = IOCtrl()

io.setPin(22,1)
io.setPin(23,1)
io.setPin(24,1)
gpio=io.getData()


#

# write gpio data to memory

# mem type, offset, data, len*4
# pru memory, offset bytes, data
pypruss.modprobe()
pypruss.init()
pypruss.open(0)
pypruss.pruintc_init()

data = [escape, cycle_count, pwm_ratio, gpio]
pypruss.pru_write_memory(0,0,data)

print "running program!"
pypruss.exec_program(0,"./memtest.bin")

pypruss.clear_event(0)
pypruss.exit()
コード例 #18
0
ファイル: beagleclock.py プロジェクト: normansaez/lotuce2
    JMP START

#else
START:
    SET r30.t14
    CLR r30.t14
    JMP START

#endif""" % constant

    if os.path.exists(filename):
        os.remove(filename)
    fp = file(filename, 'w')
    fp.write(generate_code)
    fp.close()
    cmd = "make -C %s clean all" % path
    print cmd
    os.system(cmd)

    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, "./clock.bin")              # Load firmware "clock.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.
    print "Constant to reach %d hertz: %d" % (hertz, constant)

コード例 #19
0
''' test.py - test script for the PyPRUSS library with the PRU'''

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, "./text.bin")  # Load firmware "text.bin" on PRU 0

# Optional commands if you would like to disable the PRU
#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.
コード例 #20
0
ファイル: starter.py プロジェクト: SadatAnwar/TI-Internship
    if ".bin" in bin_file and "reset.bin" not in bin_file and "inputReceiver_PRU0.bin" not in bin_file:
        binaries.append(bin_file)
binaries.sort()
# Power up VCC
with open("/dev/mem", "r+b") as f:
    mem = mmap.mmap(f.fileno(), GPIO0_size, offset=GPIO0_offset)
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
コード例 #21
0
#import numpy as np                          # Needed for braiding the pins with the delays
import struct
import mmap

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)
    ddr_mem[RAM0_START:RAM0_START + 4] = struct.pack('L', 0)

#pypruss.modprobe()                # This only has to be called once pr boot
pypruss.init()
pypruss.open(0)
pypruss.pruintc_init()
pypruss.exec_program(0, "./photodiodetest.bin")
pypruss.wait_for_event(0)
pypruss.clear_event(0, pypruss.PRU0_ARM_INTERRUPT)
pypruss.pru_disable(0)
pypruss.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])
    #TODO: add check if test is succesfull or not
    print(hex(local[0]))
コード例 #22
0
ファイル: division.py プロジェクト: hakalan/quickstep
    return struct.unpack('L',
      self.ddr_mem[self.ddr_start:self.ddr_start+4])[0]

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, "./division.bin")

fifo.write([int(i) for i in sys.argv[1:3]]) 
fifo.write([0,0])

olda = fifo.front()
while True:
  a = fifo.front()
  if not olda == a:
    print 'front:',a
    olda = a
  if a == fifo.back:
    break

print fifo.memread(40, 3)
pypruss.wait_for_event(0)
コード例 #23
0
        (float(speed[0]) - float(lines[0])) /
        float(lines[0])) * 100  ##Calculate the new percent changed

    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
コード例 #24
0
ファイル: endstop_test.py プロジェクト: zittix/redeem
import pypruss  # The Programmable Realtime Unit Library
import struct
import mmap
import time

PRU_ICSS = 0x4A300000
PRU_ICSS_LEN = 512 * 1024

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

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, "../firmware/firmware_endstops.bin"
                     )  # Load firmware "mem_write.bin" on PRU 0

with open("/dev/mem", "r+b") as f:
    ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS)
    while True:
        shared = struct.unpack('LLL', ddr_mem[RAM2_START:RAM2_START + 12])
        print "Raw: " + bin(shared[0]) + " Masked: " + bin(
            shared[1]) + " Allowed: " + bin(shared[2]) + (" " * 30) + "\r",

pypruss.exit()  # Exit
コード例 #25
0
ファイル: test.py プロジェクト: jadonk/PRdUino
''' test.py - test script for the PyPRUSS library with the PRU'''

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, "./text.bin")			# Load firmware "text.bin" on PRU 0

# Optional commands if you would like to disable the PRU
#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. 
コード例 #26
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.
コード例 #27
0
 def _sendPixels( self, data ):
     pypruss.pru_write_memory(0, 0, data)    # Load the data in the PRU ram
     pypruss.exec_program(0, "./ledgriddrvr.bin")    # Load firmware 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
コード例 #28
0
    ddr_mem = mmap.mmap(f.fileno(), DDR_FILELEN, offset=DDR_BASEADDR) #
data = "".join(map(chr, [b0, b1, b2, b3]))              # Make the data, it needs to be a string
ddr_mem[DDR_OFFSET:DDR_OFFSET+4] = data             # Write the data to the DDR memory, four bytes should suffice
ddr_mem.close()                                     # Close the memory
f.close()                                           # Close the file





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.exec_program(0, "./gpioLEDBlink.out") # 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. 

#import pypruss as pru                   # The Programmable Realtime Unit Library
#import numpy as np                      # Needed for braiding the pins with the delays

#distance =100
#steps_pr_mm = 1
#inst_pr_step = 1
#num_steps = int(distance*steps_pr_mm)   # Number of ticks in total
#steps     = [(1<<12), 0]*num_steps      # Make the table of ticks for the stepper.
#delays    = [inst_pr_step]*2*num_steps  # Make the table of delays
 
コード例 #29
0
ファイル: beaglePovTest.py プロジェクト: zojeda/beagle_pov
#!/usr/bin/python
""" blinkled.py - test script for the PyPRUSS library
It blinks the user leds ten times
"""

import sys
import pypruss

delay = int(600000)

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, [delay])  # Load data in the pru RAM
pypruss.exec_program(0, "./bin/beagle_pov.bin")  # Load firmware "beagle_pov.bin" on PRU 0
pypruss.exit()  # Exit, don't know what this does.
コード例 #30
0
ファイル: stabilizer.py プロジェクト: hexastorm/ldgraphy
# TODO: machine halts at zero
# TODO: why is there a ringbuffer!?
# START
start_lines = queue_len if total_lines > queue_len else total_lines
# byte zero is error byte
data = [0] + ([1] + line) * start_lines + [10]
bit_data = (len(data) // 4 + 1) * [0]
for idx, item in enumerate(data):
    bit_data[idx // 4] += item << (8 * (idx % 4))

#pypruss.modprobe()                # This only has to be called once pr boot
pypruss.init()
pypruss.open(0)
pypruss.pruintc_init()
pypruss.pru_write_memory(0, 0, bit_data)  # Load the data in the PRU ram
pypruss.exec_program(0, "./stabilizer.bin")

if total_lines > queue_len:
    total_lines -= queue_len

# continue_line
#data = ([1] + line)
#bit_data = (len(data)//4+1)*[0]
#for idx, item in enumerate(data):
#    bit_data[idx//4]+=item<<(8*(idx%4))

byte = 1  # note byte0 is error
response = 1
while True:
    pypruss.wait_for_event(0)
    pypruss.clear_event(0, pypruss.PRU0_ARM_INTERRUPT)
コード例 #31
0
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):
    pru_stop_thread.kill_me()
    pru_send_thread.kill_me()
    pru_stop_thread.join()
    pru_send_thread.join()


signal.signal(signal.SIGINT, signal_handler)

pru_stop_thread.join()
pru_send_thread.join()

pypruss.exit()
コード例 #32
0
""" blinkled.py - test script for the PyPRUSS library
blinks the laser 3 times with a period of 6 seconds
"""

import pypruss

#pypruss.modprobe()        # This only has to be called once pr boot
pypruss.init()
pypruss.open(0)
pypruss.pruintc_init()
pypruss.exec_program(0, "./blinklaser.bin")
pypruss.wait_for_event(0)
pypruss.clear_event(0, pypruss.PRU0_ARM_INTERRUPT)
pypruss.pru_disable(0)
pypruss.exit()
コード例 #33
0
ファイル: blinkled.py プロジェクト: Agoa/pypruss
''' 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. 
コード例 #34
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
 def run(self):
     print("Starting PRU binary %s" % self.bin_file)
     pypruss.exec_program(0, self.bin_file)
コード例 #35
0
ddr_start = 0x10000000
ddr_end = 0x10000000 + ddr_size

f = open("/dev/mem", "r+b")
ddr_mem = mmap.mmap(f.fileno(), ddr_filelen,
                    offset=ddr_offset)  # mmap the right area

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

stopped = threading.Event()
stopped.clear()
pru_stop_thread = PRUReadThread(stopped, my_socket, ddr_mem)
pru_send_thread = PRUWriteThread(stopped, my_socket, ddr_mem)
pru_stop_thread.start()
pru_send_thread.start()
pypruss.exec_program(1, "/opt/bbonePRU/text2.bin")


def signal_handler(signal, frame):
    print("Program termination requested")
    pru_stop_thread.killme()
    pru_send_thread.killme()
    pru_stop_thread.join()
    pru_send_thread.join()


signal.signal(signal.SIGINT, signal_handler)

pru_stop_thread.join()
pru_send_thread.join()
コード例 #36
0
ファイル: mem_read.py プロジェクト: Miaou/pypruss-fork
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])
コード例 #37
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])
コード例 #38
0
ファイル: Ledgrid.py プロジェクト: CoryStewart/ledgrid
 def _sendPixels( self, data ):
     pypruss.pru_write_memory(0, 0, data)    # Load the data in the PRU ram
     pypruss.exec_program(0, self.prucode_file )    # Load firmware on PRU 0
     pypruss.wait_for_event(0)               # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
     sleep( 0.003 )                          # Allow pru to complete
     pypruss.clear_event(0)                  # Clear the event
コード例 #39
0
    def burst(self, length=None, n_channels=None, raw=None, fmt_volts=1):
        """
        Args:
            length: Number of samples to record. Overides natural behavior to
          use the value stored in self.length

            n_channels: Number of channel that will collect samples. overrides
          natural behavior to use the value storing in self.n_channels

            raw: Bit that lets the user specify that he wants the data in the
          raw binary non-2's compliment format instead of 2's compliment.

            fmt_volts: Specify's whether to convert the raw binary data into
          human readable volts form.

        """
        if length is None:  # Optional argument for sample length
            length = self.sample_length
        else:
            self.sample_length = int(length)

        if n_channels is None:
            n_channels = self.n_channels
        else:
            self.n_channels = n_channels

        # Share DDR RAM Addr with PRU0
        pypruss.pru_write_memory(0, PRU0_DDR_MEM_OFFSET, [self.ddr['addr'], ])

        # Share SL with PRU0: pru_SL_mapping just incorporates
        # some math that translates the user specified SL parameter
        # to a byte addressable memory size value that the PRU will use to
        # check whether it has finished writing it's data to the
        # memory
        pru_SL_mapping = (length - MIN_SAMPLE_LENGTH) * BYTES_PER_SAMPLE
        pypruss.pru_write_memory(0, PRU0_SL_MEM_OFFSET, [pru_SL_mapping, ])

        # Share deadband length with PRU0
        db_hex = int(round(self.deadband_ms / 1000.0 * F_CLK * 2.0))  # counts
        pypruss.pru_write_memory(0, PRU0_DB_MEM_OFFSET, [db_hex, ])

        # Share Threshold with PRU0
        thr_hex = self.V_to_12bit_Hex(self.corrected_threshold)
        pypruss.pru_write_memory(0, PRU0_THR_Mem_Offset, [thr_hex, ])

        # Launch the Sample collection program
        a = time.time()
        pypruss.exec_program(0, ADS7865_MasterPRU)  # 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_INTERRUPT
        b = time.time()
        t = b - a

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

        # Read the memory: Extract raw status code
        raw_data = read_sample(self.ddr, length + STATUS_BLOCK)
        logging.info("ADC: RAW_DATA %d:" % raw_data[0])
        status_code = raw_data[0] & 0x3F

        # Read the memory: Extract TOF Flag
        TOF = get_bit(raw_data[0], TIMEOUT_STATUS_BIT)
        self.TOF = TOF

        # Read the memory: Extract TRG_CH Data
        self.TRG_CH = get_bit(raw_data[0], TFLG0_BIT)
        print
        if self.n_channels != 2:
            self.TRG_CH += 2 * get_bit(raw_data[0], TFLG1_BIT)
        logging.info("ADC: Triggered off ch %d" % self.TRG_CH)
        

        # Read the DB overflow bit
        DBOVF = get_bit(raw_data[0], DBOVF_BIT)
        logging.info("ADC: DBOVF = %d" % DBOVF)

        # Read the memory: Move on. Treat actual data as raw data now.
        raw_data = raw_data[1:]

        # Print out stuff
        logging.info("ADC: Returned Status code = %d" % status_code)
        logging.info("ADC: Returned TOF code = %d" % TOF)
        if TOF:
            logging.warning("ADC: TIMEOUT occured!")

        y_orig = y = [0] * n_channels
        for chan in range(n_channels):

            # user may specify whether he wants a numpy array
            # ... or not.
            y[chan] = np.asarray(raw_data[chan::n_channels])

            # User may specify whether he wants values to come in
            # raw, or two's compliment.
            if raw is None or raw == 0:
                i = 0
                for sample in y[chan]:
                    y[chan][i] = twos_comp(sample, WORD_SIZE)
                    i += 1

                # Assuming that the user is requesting 2 compliment values,
                # it is possible to do conversion to voltage values. How ever,
                # if the user has set raw to True, then this option is
                # unavailable.
                if fmt_volts:
                    y[chan] = y[chan] * self.lsb

                    # Apply digital gain
                    y_orig[chan] = y[chan]
                    y[chan] = y[chan] * self.digital_gain

        # Perform some commands that ready the ADC for another burst.
        self.reload()

        # Storing collected samples internally
        self.y = y
        self.y_orig = y_orig

        # Return values
        return (y, TOF)
コード例 #40
0
ファイル: ddr_write.py プロジェクト: smosh/BBB-PRU-Exercises
pypruss.modprobe()
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+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
コード例 #41
0
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 +
                                       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)
コード例 #42
0
def load(path):
    print('Loading program')
    pypruss.exec_program(0, path)
コード例 #43
0
ファイル: pru-enable.py プロジェクト: normansaez/lotuce2
#!/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.


コード例 #44
0
ファイル: PRUtoPRU.py プロジェクト: adamatom/PRUtoPRU
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       
コード例 #45
0
	percentChange = ( ( float(speed[0]) - float(lines[0])) / float(lines[0])) * 100 ##Calculate the new percent changed

	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
コード例 #46
0
ファイル: pypruss_test.py プロジェクト: AhmedSamara/bot-1
pru_addr = 0x4a300000
PRU_EVOUT_0 = 0
PRU0_ARM_INTERRUPT = 19

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

pypruss.init()  # Init the PRU
try:
    pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
except SystemError as e:
    print e
    print "Is the PRU module (uio_pruss) loaded?"

pypruss.pruintc_init()  # Init the interrupt controller
pypruss.exec_program(0, "./ultrasonic.bin")

while True:
    print "Wait for event... ",
    pypruss.wait_for_event(PRU_EVOUT_0)
    print "Got event"
    pypruss.clear_event(PRU_EVOUT_0, PRU0_ARM_INTERRUPT)
    time1, pre1, time2, pre2, time3, pre3, time4, pre4 = \
        struct.unpack_from('LLLLLLLL', mem, 0)
    print "Vals:"
    print "  %d, %d = %0.2f in" % (pre1, time1, time1 / 149.3)
    print "  %d, %d = %0.2f in" % (pre2, time2, time2 / 149.3)
    print "  %d, %d = %0.2f in" % (pre3, time3, time3 / 149.3)
    print "  %d, %d = %0.2f in" % (pre4, time4, time4 / 149.3)

    print "Wait for event2... ",
コード例 #47
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
 def run(self):
     pypruss.exec_program(
         0, self.bin_file)  # Load firmware "blinkled.bin" on PRU 0