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)
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')
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)
def reload(self): """ Re-initializes the PRU's interrupt that this library uses to tell python that it can continue running code again. This must be called at the end of a function that utilizes this interrupt. The calling function should not be responsible for reloading PRUs """ pypruss.init() # Init the PRU pypruss.open(0) # Open PRU event 0 which is PRU0_ARM_INTERRUPT pypruss.pruintc_init() # Init the interrupt controller
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
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)
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()
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
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.")
def runOnPRU(PRU, binFile, interrupt=1): try: pypruss.init() # Init the PRU pypruss.open(interrupt) # Open PRU PRU1_ARM_INTERRUPT pypruss.pruintc_init() # Init the interrupt controller pypruss.exec_program(PRU, binFile) log.info('PRU %s executing %s' % (PRU, os.path.split(binFile)[len(os.path.split(binFile)) - 1])) pypruss.wait_for_event(interrupt) # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT pypruss.clear_event(interrupt) # Clear the event pypruss.exit() except Exception, e: log.error(e) pypruss.exit() raise Exception('Error executing file %s on PRU' % binFile)
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 = {}
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 = {}
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)
def init_receiver(fileName): bin_file = os.path.join(binary_folder, fileName) if not os.path.isfile(bin_file): print("WARN:\t" + bin_file + " not present, trying to create from headers_4W") compile_assembler( os.path.join(header_folder, fileName.replace(".bin", ".p"))) if not os.path.isfile(bin_file): print("ERROR:\t" + bin_file + " not not created, ABORTING") sys.exit(1) 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, bin_file) # Load firmware "mem_write.bin" on PRU 0
def resetPRU(start_stop): for PRU in range(0, 2): if os.path.isfile(reset_pru_bin): 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( PRU, reset_pru_bin) # 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 " + str(PRU) + " " + start_stop) pypruss.clear_event(1) # Clear the event pypruss.exit() else: compile_assembler(os.path.join(header_folder, "reset.p"))
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.
def initReceiver(self, clearMem=True, copyMem=False, memBlock=100): """Initialize the input receiver 1. copy out the memory content if set, default false 2. Reset the moemory contents if set, default True 3. Start the receiver binary on the receiving PRU""" if copyMem: self.PRUMemContents = readOutPRUMem(blocks=0) if clearMem: resetPRUMem(memBlock) log.info('PRU Memory Cleared %s blocks' % memBlock) 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(receivingPRU, self.inputBinary) # Load firmware for input recording pypruss.clear_event(0) pypruss.exit()
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)
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")
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")
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
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)
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
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
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
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']
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()
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.")
pypruss.pru_disable(0) pypruss.exit() # Exit sys.exit() signal.signal(signal.SIGINT, cleanup) signal.signal(signal.SIGTERM, cleanup) 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 = \
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
def pri(off, size): print(hexlify(pruicss[off:off + size])) def write(off, data): pruicss[off:off + len(data)] = data # Useful offsets SHARED = 0x010000 CONTROL = 0x022000 ACTION = 0x010100 # SHARED + 0x100 # Init PRU pypruss.init() pypruss.open(pypruss.PRU_EVTOUT_0) pypruss.pruintc_init() def load(path): print('Loading program') pypruss.exec_program(0, path) def end(): pypruss.pru_disable(0) pypruss.exit() print("Control: " + '-'.join('{:02x}'.format(a)
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
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")