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
    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 #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 __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 #5
0
def start(PWM_freq=1e7, PWM_duty_cycle=50, clock_divider=2):
	GPIO.setup("P8_30",GPIO.OUT)	#SPI CS for AWG
	GPIO.output("P8_30",GPIO.HIGH)	#Set CS high initally - i.e. disabled
	GPIO.setup("P9_23",GPIO.OUT)	#AFG External trigger.  NB check JP1 setting too!
	GPIO.setup("P9_24",GPIO.OUT)	#What is this for?  Possibly old code for the old SPI non bit banged bus?
	PWM.start("P8_34",PWM_duty_cycle,PWM_freq) 	# setup ADC master clock 13e6 = 25khz  ~ NCO sees 50MHz clock - connects to J10 on AFG

# NCO removed P8_46 because of a device tree conflict with SPI_overlay_PRU1
#	PWM.start("P8_46",50,50e6) # 100e5

	pypruss.modprobe()					# This only has to be called once pr boot
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
	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 #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
def moveStepper_p9_15(steps):
    pypruss.modprobe()
    pypruss.init()
    pypruss.open(0)  # Open PRU event 0 which is PRU0_ARM_INTERRUPT
    pypruss.pruintc_init()  # Init the interrupt controller

    setSteps(steps)

    pypruss.exec_program(
        0, "./pru/p9_15.bin")  # Load firmware "blinkled.bin" on PRU 0
    pypruss.wait_for_event(
        0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
    pypruss.clear_event(0)  # Clear the event
    pypruss.pru_disable(
        0)  # Disable PRU 0, this is already done by the firmware
    pypruss.exit()  # Exit, don't know what this does.
Example #12
0
def start(PWM_freq=1e7, PWM_duty_cycle=50, clock_divider=2):
    GPIO.setup("P8_30", GPIO.OUT)  #SPI CS for AWG
    GPIO.output("P8_30", GPIO.HIGH)  #Set CS high initally - i.e. disabled
    GPIO.setup("P9_23",
               GPIO.OUT)  #AFG External trigger.  NB check JP1 setting too!
    GPIO.setup(
        "P9_24", GPIO.OUT
    )  #What is this for?  Possibly old code for the old SPI non bit banged bus?
    PWM.start(
        "P8_34", PWM_duty_cycle, PWM_freq
    )  # setup ADC master clock 13e6 = 25khz  ~ NCO sees 50MHz clock - connects to J10 on AFG

    # NCO removed P8_46 because of a device tree conflict with SPI_overlay_PRU1
    #	PWM.start("P8_46",50,50e6) # 100e5

    pypruss.modprobe()  # This only has to be called once pr boot
Example #13
0
    def __init__(self):

        pypruss.modprobe(100)

        print 'Initializing PRU'
        pypruss.init()

        print 'successfully initialized!'

        if pypruss.open(0):
            print 'PRU open failed'
            return 1

        pypruss.pruintc_init()

        self.pruData = pypruss.map_prumem(pypruss.PRUSS0_PRU0_DATARAM)

        pypruss.exec_program(0, "./hcsr04.bin")
Example #14
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 #15
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 #16
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 #17
0
def init():
    import pypruss
    import mmap

    import Adafruit_BBIO.GPIO as GPIO

    print "> pypruss init"
    with open("/dev/mem", "r+b") as f:  # Open the memory device
        ddr_mem = mmap.mmap(f.fileno(), DDR_FILELEN, offset=DDR_BASEADDR)  #
    data = "".join(map(chr,
                       [0, 0, 0, 0]))  # 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

    GPIO.setup('P9_15', GPIO.OUT)
    GPIO.setup('P9_23', GPIO.OUT)
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
    #print lines
    #f = open('out.txt'), 'w')
    speed = [line.strip() for line in cmd.stdout]
    print lines[0]  #need a file with a number in it for this to work
    print speed[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
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
import pypruss
import os

print "This example toggles pin P8.12 as fast as it can, 5ns pr cycle."
print "It muxes the pin to mode 6 and does not stop, so use Ctrl-c to end the script."
#P8.12 = gpio_num = 44
gpio_num = 44

#os.system("echo 6 > /sys/kernel/debug/omap_mux/gpmc_ad12")
open("/sys/class/gpio/export", "w").write(str(gpio_num))
open("/sys/class/gpio/gpio%d/direction" % gpio_num, "w").write("out")
open("/sys/class/gpio/gpio%d/value" % gpio_num, "w").write("1")

pypruss.modprobe(1000)
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, "./speed_test.bin")  # Load firmware "blinkled.bin" on PRU 0
pypruss.wait_for_event(
    0)  # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
Example #22
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 #23
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. 
Example #24
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 #25
0
                frame = frame[:PAYLOAD_LEN]

            len_byte = struct.pack('B', len(frame))
            self.ddr_mem[self.frames_ptr] = len_byte
            frame_offset = self.frames_ptr + 1
            self.ddr_mem[frame_offset:frame_offset + len(frame)] = \
                frame
            produce = (produce + 1) % TX_RING_BUFFER_LEN
            self.frames_ptr = \
                self.frames_base + (produce * FRAME_SIZE)
            self.ddr_mem[self.struct_start:self.struct_start +
                         RING_BUFFER_CONSUME_OFFSET] = \
                struct.pack('L', produce)


pypruss.modprobe()

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()
Example #26
0
  def memread(self, offset, length):
    begin = self.ddr_start + offset
    return struct.unpack('l'*length,
      self.ddr_mem[begin:begin+4*length])

  def write(self, data):
    self.back += self.memwrite(self.back, data, 'l')
    if self.back >= self.fifo_size:
      self.back = 8
    self.memwrite(4, [self.back])

  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])