示例#1
0
    def __init__(self,
                 pru=0,
                 pru0_fw="arm/pru00.bin",
                 pru1_fw="arm/pru01.bin"):
        if pru == 0:
            pru_dataram = pypruss.PRUSS0_PRU0_DATARAM
        else:
            pru_dataram = pypruss.PRUSS0_PRU1_DATARAM

        self._spare = 0
        self._ofile = None
        self._gpsp = None

        logging.debug("[ADC] setting up power control line")
        GPIO.setup("P9_18", GPIO.OUT)

        logging.debug("[ADC] pruss init")
        pypruss.init()  # Init the PRU

        logging.debug("[ADC] pruss open")
        ret = pypruss.open(self.PRU_EVTOUT_0)

        logging.debug("[ADC] pruss intc init")
        pypruss.pruintc_init()  # Init the interrupt controller

        logging.debug("[ADC] mapping memory")
        self._data = pypruss.map_prumem(pru_dataram)

        logging.debug("[ADC] data segment len=%d" % len(self._data))

        logging.debug("[ADC] setting tail")
        self._tail = 0
        struct.pack_into('l', self._data, self.PRU0_OFFSET_DRAM_HEAD,
                         self._tail)

        logging.debug("[ADC] mapping extmem")
        self._extmem = pypruss.map_extmem()
        logging.debug("[ADC] ext segment len=%d" % len(self._extmem))

        logging.debug("[ADC] setup mem")
        self.ddrMem = pypruss.ddr_addr()
        logging.debug("[ADC] V extram_base = 0x%x" % self.ddrMem)

        self._pru01_phys = int(
            open("/sys/class/uio/uio1/maps/map1/addr", 'r').read(), 16)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_SRAM_HEAD, 0)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_DRAM_PBASE,
                         self._pru01_phys)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_SPIN_COUNT, 0)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_RES1, 0x00000000)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_SPIN_COUNT, 0)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_SPIN_COUNT, 0)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_RES2, 0xbabedead)
        struct.pack_into('L', self._data, self.PRU0_OFFSET_RES3, 0xbeefcafe)

        logging.debug("[ADC] loading pru01 code")
        pypruss.exec_program(1, pru1_fw)

        logging.debug("[ADC] loading pru00 code")
        pypruss.exec_program(0, pru0_fw)
示例#2
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
示例#3
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")
示例#4
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
示例#5
0
''' ddr_write.py - Finds the DDR address and size, passes that info to the PRU0 
data memory, executes a program and reads back data from the first and last banks'''


import pypruss
import mmap
import struct 

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
示例#6
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")
示例#7
0
''' ddr_write.py - Finds the DDR address and size, passes that info to the PRU0 
data memory, executes a program and reads back data from the first and last banks'''

import pypruss
import mmap
import struct

pypruss.modprobe(1000)
ddr_addr = pypruss.ddr_addr()
ddr_size = pypruss.ddr_size()

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

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

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

with open("/dev/mem", "r+b") as f:  # Open the physical memory device
示例#8
0
    def __init__(self, sr=0.0, smp_len=0):
        """ Configures several BBB pins as necessary to hold the ADC in an idle state

        Args:
            cr: Conversion Rate (float)
            smp_len: Sample Length (integer)


        Parameters (in order of initialization):
            self.DBus
            self.WR
            self._RD
            self._CONVST
            self._CS
            self."ddr stuff"
            self.n_channels
            self.conversion_rate
            self.deadband_ms
            self.arm_status
            self.seq_desc
            self.ch
            self.delay
            self.digital_gain
            self.threshold
            self.corrected_threshold
            self.cr_specd
            self.modified
            self.sample_rate
            self.dac_voltage
            self.LSB
            self.TOF
            self.TRG_CH
            self.digital_gain
        """
        # Loads the BBB cape overlays that allow control of the PRUSS
        # and it's IO via pypruss. Note: pypruss will not work correctly
        # until this system level command is ran. Do not try to use the
        # pypruss library before running this command.
        boot.load()

        # GPIO Stuff
        self.DBus = Port(DB_pin_table)
        self.DBus.set_port_dir("in")

        self.WR = Port(WR_pin)
        self.WR.set_port_dir("out")
        self.WR.write_to_port(1)

        self._RD = Port(RD_pin)
        self._RD.set_port_dir("out")
        self._RD.write_to_port(1)

        self._CONVST = Port(CONVST_pin)
        self._CONVST.set_port_dir("out")
        self._CONVST.write_to_port(1)

        self._CS = Port(CS_pin)
        self._CS.set_port_dir("out")
        self._CS.write_to_port(0)

        # PRUSS Stuff
        self.ddr = {}
        self.ddr['addr'] = pypruss.ddr_addr()
        self.ddr['size'] = pypruss.ddr_size()
        self.ddr['start'] = 0x10000000
        self.ddr['filelen'] = self.ddr['size'] + 0x10000000
        self.ddr['offset'] = self.ddr['addr'] - 0x10000000
        self.ddr['end'] = 0x10000000 + self.ddr['size']

        msg = ("ADS7865: Allowing one 32bit memory block per sample, it is "
               "possible to collect {samp:.1f}K Samples in a single burst. These "
               "sample points are stored in DDRAM, which is found at the "
               "address range starting at {addr}")

        logging.info(msg.format(
            samp=self.ddr['size'] / 1000.0,
            addr=str(hex(self.ddr['addr'])))
        )

        self.sampling_rate = sr
        self.deadband_ms = 0
        self.sample_length = int(smp_len)
        self.arm_status = "unknown"
        self.seq_desc = "unknown"
        self.ch = ['unknown'] * 4
        self.delay = [-99] * 4

        self.digital_gain = 1

        self.update_threshold(DEFAULT_THRESHOLD)
        self.sr_specd = 0  # parameter for keeping the up with the last spec
        self.modified = True
        self.sample_rate = None
        self.dac_voltage = DEFAULT_DAC_VOLTAGE
        self.lsb = self.dac_voltage / (2**(WORD_SIZE - 1))  # Volts

        # Loads overlays: For that will be later needed for
        # muxing pins from GPIO to pruout/pruin types and vice versa.
        self.sw_reset()

        # Any other variables that will later be relevent
        self.TOF = None
        self.TRG_CH = None
        self.y = None