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): 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): 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 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 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 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 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 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 __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 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 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 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 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.")
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
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 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()
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)
#!/usr/bin/python import os import argparse import pypruss from math import ceil if __name__ == '__main__': pru = 0 firmware = "./clock.bin" pypruss.modprobe() # This only has to be called once pr boot pypruss.init() # Init the PRU pypruss.open(pru) # Open PRU event <num> which is PRU<num>_ARM_INTERRUPT pypruss.pruintc_init() # Init the interrupt controller pypruss.exec_program(pru, firmware) # Load firmware on PRU <num> pypruss.wait_for_event(pru) # Wait for event <num> which is connected to PRU<num>_ARM_INTERRUPT pypruss.clear_event(pru) # Clear the event pypruss.pru_disable(pru) # Disable PRU <num>, this is already done by the firmware pypruss.exit() # Exit, don't know what this does.
# 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()
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)
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
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)
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