コード例 #1
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
	def update(self, channel, value):
		value += 1
		if value > 256:
			value = 256

		self.data[4 + channel] = value
		pypruss.pru_write_memory(0, 0, self.data)
コード例 #2
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
    def update(self, channel, value):
        value += 1
        if value > 256:
            value = 256

        self.data[4 + channel] = value
        pypruss.pru_write_memory(0, 0, self.data)
コード例 #3
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')
コード例 #4
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
	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)
コード例 #5
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
コード例 #6
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
    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)
コード例 #7
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
	def update(self, channel, value):
		# Clamp the value to 255
		# this would have to change if we change our period
		value += 1
		if value > 256:
			value = 256

		# Channels start after six command bytes
		self.data[6 + channel] = value
		# print(self.data)
		# Write our whole data structure out to PRU Data Ram
		pypruss.pru_write_memory(0, 0, self.data)
コード例 #8
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
    def update(self, channel, value):
        # Clamp the value to 255
        # this would have to change if we change our period
        value += 1
        if value > 256:
            value = 256

        # Channels start after six command bytes
        self.data[6 + channel] = value
        # print(self.data)
        # Write our whole data structure out to PRU Data Ram
        pypruss.pru_write_memory(0, 0, self.data)
コード例 #9
0
ファイル: stepper.py プロジェクト: miaoqqqq123/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
コード例 #10
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
	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)
コード例 #11
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
    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()
コード例 #12
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
    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)
コード例 #13
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
	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()
コード例 #14
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")
コード例 #15
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
コード例 #16
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
コード例 #17
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
コード例 #18
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.")
コード例 #19
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()		        
コード例 #20
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
コード例 #21
0
ファイル: division.py プロジェクト: hakalan/quickstep
  def front(self):
    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)
コード例 #22
0
ファイル: stepperTest.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

steps = int(1)
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(1, 0, [delay])                # Load data in the pru RAM
pypruss.pru_write_memory(1, 4, [steps])                # Load data in the pru RAM
pypruss.exec_program(1, "./bin/stepperTest.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.
コード例 #23
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
	def stop(self):
		self.data[0] = 0x000000FF
		pypruss.pru_write_memory(0, 0, self.data)
コード例 #24
0
""" mem_write.py - test script for writing to PRU 0 mem using PyPRUSS library """

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

steps = [(7 << 22), 0] * 10  # 10 blinks, this control the GPIO1 pins
delays = [0xFFFFFF
          ] * 20  # number of delays. Each delay adds 2 instructions, so ~10ns

data = np.array([steps,
                 delays])  # Make a 2D matrix combining the ticks and delays
data = data.transpose().flatten()  # Braid the data so every other item is a
data = [20] + list(
    data)  # Make the data into a list and add the number of ticks total

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, data)  # Load the data in the PRU ram
pypruss.exec_program(
    0, "./mem_write.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
コード例 #25
0
ファイル: minecraft.py プロジェクト: CoryStewart/ledgrid
    for ix in xrange(24):
        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)
コード例 #26
0
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 +
                                       4])[0]  # Parse the data
read_back2 = struct.unpack("L",
                           ddr_mem[ddr_end - 4:ddr_end])[0]  # Parse the data
コード例 #27
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)
コード例 #28
0
ファイル: backlight.py プロジェクト: nycresistor/TotU
 def stop(self):
     self.data[0] = 0x000000FF
     pypruss.pru_write_memory(0, 0, self.data)
コード例 #29
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
コード例 #30
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
コード例 #31
0
ファイル: blinkled.py プロジェクト: nycresistor/TotU
gpio2_mask = '\x00\x00\x3f\xc0'
gpio3_mask = '\x00\x3f\xc0\x00'

data = [0x00000000, 0x000000FF, 0x00003FC0, 0x003FC000]

for _ in range(16):
	data.append(0x00000001)

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

pypruss.pru_write_memory(0, 0, data)

import time
for x in range(256):
	data[4] = 0x00000000 + x
	pypruss.pru_write_memory(0,0, data)
	time.sleep(0.001)

for x in xrange(255, 0, -1):
	data[4] = 0x00000000 + x
	pypruss.pru_write_memory(0, 0, data)
	time.sleep(0.001)


pypruss.wait_for_event(0)							# Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)								# Clear the event
コード例 #32
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.
コード例 #33
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 
コード例 #34
0
gpio2_mask = '\x00\x00\x3f\xc0'
gpio3_mask = '\x00\x3f\xc0\x00'

data = [0x00000000, 0x000000FF, 0x00003FC0, 0x003FC000]

for _ in range(16):
    data.append(0x00000001)

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

pypruss.pru_write_memory(0, 0, data)

import time
for x in range(256):
    data[4] = 0x00000000 + x
    pypruss.pru_write_memory(0, 0, data)
    time.sleep(0.001)

for x in xrange(255, 0, -1):
    data[4] = 0x00000000 + x
    pypruss.pru_write_memory(0, 0, data)
    time.sleep(0.001)

pypruss.wait_for_event(
    0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)  # Clear the event