def _wait_for_events(self): events_caught = 0 self.dev = os.open("/dev/uio0", os.O_RDONLY) self.new_events = 0 self.old_events = 0 nr_interrupts = 0 while self.running: ret = select.select( [self.dev],[],[], 1.0 ) if ret[0] == [self.dev]: self._wait_for_event() pypruss.clear_event(PRU0_ARM_INTERRUPT) # Clear the event nr_events = struct.unpack("L", self.ddr_mem[self.DDR_END-4:self.DDR_END])[0] else: nr_events = struct.unpack("L", self.ddr_mem[self.DDR_END-4:self.DDR_END])[0] while nr_interrupts < nr_events: ddr = self.ddr_used.get() # Pop the first ddr memory amount with Pru.ddr_lock: self.ddr_mem_used -= ddr #logging.debug("Popped "+str(ddr)+"\tnow "+hex(self.get_capacity())) if self.get_capacity() < 0: logging.error("Capacity less than 0!") if self.get_capacity() == 0x40000: logging.warning("PRU empty!") nr_interrupts += 1 self.ddr_used.task_done()
def run(self): old_consume = 0 while not self.stopped.is_set(): pypruss.wait_for_event(TARGET_PRU_NO) pypruss.clear_event(TARGET_PRU_NO, TARGET_PRU_INTERRUPT) self.calls += 1 (produce, consume) = \ struct.unpack("LL", self.ddr_mem[DDR_START:DDR_START + RX_RING_BUFFER_FRAMES_OFFSET]) while consume != produce: length = struct.unpack("B", self.ddr_mem[self.frames_ptr])[0] frame = \ struct.unpack("B"*length, self.ddr_mem[self.frames_ptr+1: self.frames_ptr+1+length]) #sys.stderr.write('rx ' + str(frame) + '\n') consume = (consume + 1) % RX_RING_BUFFER_LEN self.frames_ptr = self.frames_base + \ (consume * RX_FRAME_SIZE) if old_consume != consume: self.ddr_mem[DDR_START + RX_RING_BUFFER_CONSUME_OFFSET: DDR_START + RX_RING_BUFFER_FRAMES_OFFSET] = \ struct.pack('L', consume) old_consume = consume
def run(self): old_consume = 0 while not self.stopped.is_set(): pypruss.wait_for_event(TARGET_PRU_NO) pypruss.clear_event(TARGET_PRU_NO, TARGET_PRU_INTERRUPT) self.calls += 1 (produce, consume) = \ struct.unpack("LL", self.ddr_mem[DDR_START:DDR_START + RING_BUFFER_FRAMES_OFFSET]) while consume != produce: length = struct.unpack("B", self.ddr_mem[self.frames_ptr])[0] frame = \ struct.unpack("B"*length, self.ddr_mem[self.frames_ptr+1: self.frames_ptr+1+length]) self.socket.sendto(''.join(map(chr, frame)), ('localhost', UDP_PORTS[1])) consume = (consume + 1) % RX_RING_BUFFER_LEN self.frames_ptr = self.frames_base + \ (consume * FRAME_SIZE) if old_consume != consume: self.ddr_mem[DDR_START + RING_BUFFER_CONSUME_OFFSET: DDR_START + RING_BUFFER_FRAMES_OFFSET] = \ struct.pack('L', consume) old_consume = consume
def run(self): ddr_start = 0x10000000 old_consume = 0 while not self.stopped.is_set(): pypruss.wait_for_event( 1) # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT pypruss.clear_event(1, pypruss.PRU1_ARM_INTERRUPT) # Clear the event self.calls += 1 (produce, consume) = struct.unpack("LL", self.ddr_mem[ddr_start:ddr_start + 8]) while consume != produce: length = struct.unpack("B", self.ddr_mem[self.messages_ptr])[0] message = struct.unpack( "B" * length, self.ddr_mem[self.messages_ptr + 1:self.messages_ptr + 1 + length]) # print(",".join(map(lambda x: "{:02x}".format(x), message))) self.socket.sendto(''.join(map(chr, message)), ('localhost', 6972)) consume = (consume + 1) % 16 self.messages_ptr = self.messages_base + (consume * 43) if old_consume != consume: self.ddr_mem[ddr_start + 4:ddr_start + 8] = struct.pack( 'L', consume) old_consume = consume
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 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()
def ExecuteActions(prussmem, lActions): # Write actions (PRU is in standby) WriteActions(prussmem, lActions) # Makes the PRU treat actions prussmem[SHARED] = 1 # COMMAND_START # Waits for completion. pypruss.wait_for_event(pypruss.PRU_EVTOUT_0) pypruss.clear_event(pypruss.PRU_EVTOUT_0, pypruss.PRU0_ARM_INTERRUPT) # I don't know why we have to wait and clear 2 times... # I thought that there was a delay between the PRU signaled the interrupt and # and the Linux updating the shared mem, but no, you have to wait for event twice... pypruss.wait_for_event(pypruss.PRU_EVTOUT_0) pypruss.clear_event(pypruss.PRU_EVTOUT_0, pypruss.PRU0_ARM_INTERRUPT) return ReadActions(prussmem, lActions)
def __init__(self, firmware): self.pru_hz = 200*1000*1000 # The PRU has a speed of 200 MHz self.s_pr_inst = (1.0/self.pru_hz) # I take it every instruction is a single cycle instruction self.max_delay_cycles = self.pru_hz*4 #Maximum delay to avoid bugs (4 seconds) 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.firmware = firmware 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 self.init_pru(); #Wait until we get the GPIO output in the DDR self.dev = os.open("/dev/uio0", os.O_RDONLY) ret = select.select( [self.dev],[],[], 1.0 ) if ret[0] == [self.dev]: pypruss.clear_event(PRU0_ARM_INTERRUPT) # Clear the event self.initial_gpio = [struct.unpack("L", self.ddr_mem[self.DDR_START+4:self.DDR_START+8])[0], struct.unpack("L", self.ddr_mem[self.DDR_START+8:self.DDR_START+12])[0], struct.unpack("L", self.ddr_mem[self.DDR_START+12:self.DDR_START+16])[0], struct.unpack("L", self.ddr_mem[self.DDR_START+16:self.DDR_START+20])[0] ] os.close(self.dev) #Clear DDR self.ddr_mem[self.DDR_START+4:self.DDR_START+8] = struct.pack('L', 0) self.ddr_mem[self.DDR_START+8:self.DDR_START+12] = struct.pack('L', 0) self.ddr_mem[self.DDR_START+12:self.DDR_START+16] = struct.pack('L', 0) self.ddr_mem[self.DDR_START+16:self.DDR_START+20] = struct.pack('L', 0) self.t = Thread(target=self._wait_for_events) # Make the thread self.t.daemon = True self.running = True self.t.start()
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 __del__(self): # Tells the PRU program to end (optional) # Using __del__ to clean out is not a very brilliant idea, as many objects are already deleted global ServoController # Pb with order of del print('Waiting for the PRU program to self-stop') pMem = PruInterface.MASK_FETCH | PruInterface.P_HEADER self.pruface.getMappedMem()[pMem:pMem + 4] = self.struct.pack('<I', 2) # Waits for completion. pypruss.wait_for_event(pypruss.PRU_EVTOUT_0) pypruss.clear_event(pypruss.PRU_EVTOUT_0, pypruss.PRU0_ARM_INTERRUPT) # I don't know why we have to wait and clear 2 times... # I thought that there was a delay between the PRU signaled the interrupt and # and the Linux updating the shared mem, but no, you have to wait for event twice... pypruss.wait_for_event(pypruss.PRU_EVTOUT_0) pypruss.clear_event(pypruss.PRU_EVTOUT_0, pypruss.PRU0_ARM_INTERRUPT)
def __del__(self): # Tells the PRU program to end (optional) # Using __del__ to clean out is not a very brilliant idea, as many objects are already deleted global ServoController # Pb with order of del print('Waiting for the PRU program to self-stop') pMem = PruInterface.MASK_FETCH|PruInterface.P_HEADER self.pruface.getMappedMem()[pMem:pMem+4] = self.struct.pack('<I', 2) # Waits for completion. pypruss.wait_for_event(pypruss.PRU_EVTOUT_0) pypruss.clear_event(pypruss.PRU_EVTOUT_0, pypruss.PRU0_ARM_INTERRUPT) # I don't know why we have to wait and clear 2 times... # I thought that there was a delay between the PRU signaled the interrupt and # and the Linux updating the shared mem, but no, you have to wait for event twice... pypruss.wait_for_event(pypruss.PRU_EVTOUT_0) pypruss.clear_event(pypruss.PRU_EVTOUT_0, pypruss.PRU0_ARM_INTERRUPT)
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 get_distances(self): distances = [] pypruss.wait_for_event( 0) # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT time.sleep(0.2) pypruss.clear_event(0, pypruss.PRU0_ARM_INTERRUPT) # Clear the event for j in range(5): distances.append( round( float( struct.unpack( 'L', self.pruData[offset + j * 4:offset + (j + 1) * 4])[0] / 58.44), 2)) return distances
def _wait_for_events(self): events_caught = 0 self.dev = os.open("/dev/uio0", os.O_RDONLY) self.new_events = 0 self.old_events = 0 nr_interrupts = 0 while self.running: ret = select.select( [self.dev],[],[], 1.0 ) if ret[0] == [self.dev]: self._wait_for_event() pypruss.clear_event(PRU0_ARM_INTERRUPT) # Clear the event nr_events = struct.unpack("L", self.ddr_mem[self.DDR_END-4:self.DDR_END])[0] while nr_interrupts < nr_events: ddr = self.ddr_used.get() # Pop the first ddr memory amount with self.ddr_lock: self.ddr_mem_used -= ddr if self.debug > 0: print "Popped "+str(ddr)+"\tnow "+hex(self.get_capacity()) self.ddr_used.task_done() nr_interrupts += 1
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 read_times(self): """Get readings from all ultrasonic sensors, as a pulse time. :returns: Readings from all ultrasonic sensors """ self.logger.debug("Waiting for PRU interrupt") pypruss.wait_for_event(self.PRU_EVOUT_0) self.logger.debug("Received PRU interrupt") pypruss.clear_event(self.PRU_EVOUT_0, self.PRU0_ARM_INTERRUPT) times = {} inches = {} for i in self.sensors: times[i] = struct.unpack_from( 'I', self.pru_mem, self.sensors[i]['offset'])[0] self.logger.debug("Sensor: %s = %d", i, times[i]) self.logger.debug("Waiting for duplicate PRU interrupt") pypruss.wait_for_event(self.PRU_EVOUT_0) self.logger.debug("Received (expected) duplicated PRU interrupt") pypruss.clear_event(self.PRU_EVOUT_0, self.PRU0_ARM_INTERRUPT) self.logger.debug("Times: {}".format(times)) return times
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.")
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... ", pypruss.wait_for_event(PRU_EVOUT_0) print "Got event" pypruss.clear_event(PRU_EVOUT_0, PRU0_ARM_INTERRUPT)
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
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
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
pypruss.exec_program(1, prog) def read32(self, offset): return struct.unpack('L', self.data[offset:offset+4])[0] def write32(self, offset, val): self.data[offset:offset+4] = struct.pack('L', val) def poll(self, offset): newval = self.read32(offset) prev = self.val.get(offset) if prev != newval: self.val[offset] = newval print "%x = %x" % (offset, newval) return newval def stop(self): pypruss.pru_disable(1) # Disable PRU 1, this is already done by the firmware pypruss.exit() self.data = None if __name__ == '__main__': mon = PRUMonitor("./pru_stick.bin") mon.write32(COM_SET_POS, 0x808080) while True: mon.poll(0xf0) mon.poll(COM_RANGE) mon.poll(COM_CURRENT_POS) mon.poll(COM_INPUT_BITS) time.sleep(1.0/1000) pypruss.wait_for_event(event_nr) pypruss.clear_event(event_nr) mon.stop()
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) # read out result and state of the program with open("/dev/mem", "r+b") as f: # byte number should be set via amount interrupts received ddr_mem = mmap.mmap(f.fileno(), PRU_ICSS_LEN, offset=PRU_ICSS) # substracted 1 to read out error local = struct.unpack( 'L', ddr_mem[RAM0_START + byte - 1:RAM0_START + byte - 1 + 4]) # START_RINGBUFFER 1 --> ja hij zit in de 1//4 (eerste vier bytes) # bit shift to get the first byte # bit mask to ignore higher bytes command_index = (local[0] >> 8 * 1) & 255 try: command = COMMANDS[command_index] if command == 'CMD_EMPTY': if response % queue_len == 0:
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... ", pypruss.wait_for_event(PRU_EVOUT_0) print "Got event" pypruss.clear_event(PRU_EVOUT_0, PRU0_ARM_INTERRUPT)
# self.rest = 0 pass steps, speed, acc, dec = (float(arg) for arg in sys.argv[1:5]) if sim: fifo = SimFifo() else: fifo = init('./stepper.bin') stepper = Stepper(fifo) stepper.move(steps, speed, acc, dec) if not sim: fifo.write([0,0,0,0]) olda = fifo.front() while True: a = fifo.front() if not olda == a: print 'front:',a olda = a if a == fifo.back: break time.sleep(0.1) pypruss.wait_for_event(0) pypruss.clear_event(0) pypruss.pru_disable(0) pypruss.exit()
mem = mmap.mmap( m.fileno(), 512*1024, offset=PRU_ICSS) valuestring = mem[START:START+4] value = struct.unpack('L', valuestring)[0] seconds = value * 0.000000005 # 5ns per cycle return seconds os.system("config-pin p8.15 pruin") 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, "./rpm.bin") # Load firmware "blinkled.bin" on PRU 0 try: while True: pypruss.wait_for_event(0) # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT seconds = readrpm() print( r'{} seconds'.format(seconds) ) pypruss.clear_event(0,pypruss.PRU0_ARM_INTERRUPT) # Clear the event except KeyboardInterrupt as e: print(e) pypruss.pru_disable(0) # Disable PRU 0, this is already done by the firmware pypruss.exit() # Exit, don't know what this does.
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