<commit_before>/*
 * CypressFX3Biasgen.java
 *
 * Created on 23 Jan 2008
 */
package net.sf.jaer.hardwareinterface.usb.cypressfx3libusb;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;

import org.usb4java.Device;

import ch.unizh.ini.jaer.chip.cochlea.CochleaLP;
import net.sf.jaer.aemonitor.AEPacketRaw;
import net.sf.jaer.event.BasicEvent;
import net.sf.jaer.hardwareinterface.HardwareInterfaceException;

/**
 * Adds functionality of apsDVS sensors to based CypressFX3Biasgen class. The
 * key method is translateEvents that parses the data from the sensor to
 * construct jAER raw events.
 *
 * @author Christian/Tobi
 */
public class CochleaFX3HardwareInterface extends CypressFX3Biasgen {

	protected CochleaFX3HardwareInterface(final Device device) {
		super(device);
	}

	@Override
	synchronized public void sendConfiguration(final net.sf.jaer.biasgen.Biasgen biasgen) throws HardwareInterfaceException {
		if ((biasgen != null) && (biasgen instanceof CochleaLP.Biasgen)) {
			((CochleaLP.Biasgen) biasgen).sendConfiguration();
		}
	}

	/**
	 * The USB product ID of this device
	 */
	static public final short PID_FX3 = (short) 0x841C;
	static public final int REQUIRED_FIRMWARE_VERSION_FX3 = 2;
	static public final int REQUIRED_LOGIC_REVISION_FX3 = 0;

	/**
	 * Starts reader buffer pool thread and enables in endpoints for AEs. This
	 * method is overridden to construct our own reader with its translateEvents
	 * method
	 */
	@Override
	public void startAEReader() throws HardwareInterfaceException {
		setAeReader(new RetinaAEReader(this));
		allocateAEBuffers();

		getAeReader().startThread(); // arg is number of errors before giving up
		HardwareInterfaceException.clearException();
	}

	public static final int CHIP_COCHLEALP = 11;
	public static final int CHIP_COCHLEA4EAR = 12;
	public static final int CHIP_SAMPLEPROB = 13; // Reuse Cochlea code for SampleProb chip.

	/**
	 * Data word is tagged as AER address or ADC sample by bit 0x2000 (DATA_TYPE_MASK). Set (ADDRESS_TYPE_ADC)=ADC
	 * sample; unset (DATA_TYPE_AER_ADDRESS)=AER address.
	 */
	public static final int DATA_TYPE_AER_ADDRESS = 0x0000; // aer addresses don't have the bit set
	public static final int DATA_TYPE_ADC = 0x2000; // adc samples have this bit set
	public static final int DATA_TYPE_ADC_CNV_START = 0x3000; // adc conversion start events also have bit 12 set
	public static final int DATA_TYPE_RANDOMDAC = 0x40000; // SampleProb only, 18 bits of space needed

	/**
	 * This reader understands the format of raw USB data and translates to the
	 * AEPacketRaw
	 */
	public class RetinaAEReader extends CypressFX3.AEReader implements PropertyChangeListener {
		private final int chipID;

		private final int aerMaxAddress;

		// Event Codes
		private static final int EC_SPECIAL = 0;
		private static final int EC_SPECIAL_RESERVED = 0;
		private static final int EC_SPECIAL_TIMESTAMP_RESET = 1;
		private static final int EC_SPECIAL_ADC_START_CNV = 44;
		private static final int EC_SPECIAL_ADC_START_CNV_1US = 45;

		private static final int EC_MISC10_RANDOM_PART1 = 0;
		private static final int EC_MISC10_RANDOM_PART2 = 1;

		private int wrapAdd;
		private int lastTimestamp;
		private int currentTimestamp;

		private int randomChannel;
		private int randomNumber;

		public RetinaAEReader(final CypressFX3 cypress) throws HardwareInterfaceException {
			super(cypress);

			checkFirmwareLogic(CochleaFX3HardwareInterface.REQUIRED_FIRMWARE_VERSION_FX3,
				CochleaFX3HardwareInterface.REQUIRED_LOGIC_REVISION_FX3);

			chipID = spiConfigReceive(CypressFX3.FPGA_SYSINFO, (short) 1);

			if (chipID == CochleaFX3HardwareInterface.CHIP_COCHLEALP) {
				aerMaxAddress = 256;
			}
			else if (chipID == CochleaFX3HardwareInterface.CHIP_COCHLEA4EAR) {
				aerMaxAddress = 1024;
			}
			else {
				// CHIP_SAMPLEPROB -- 11 bits
				aerMaxAddress = 2048;
			}

			updateTimestampMasterStatus();
		}

		private void checkMonotonicTimestamp() {
			if (currentTimestamp <= lastTimestamp) {
				CypressFX3.log.severe(toString() + ": non strictly-monotonic timestamp detected: lastTimestamp=" + lastTimestamp
					+ ", currentTimestamp=" + currentTimestamp + ", difference=" + (lastTimestamp - currentTimestamp) + ".");
			}
		}
<commit_msg>jAER SampleProb: use all 12 bits.<commit_after>/*
 * CypressFX3Biasgen.java
 *
 * Created on 23 Jan 2008
 */
package net.sf.jaer.hardwareinterface.usb.cypressfx3libusb;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;

import org.usb4java.Device;

import ch.unizh.ini.jaer.chip.cochlea.CochleaLP;
import net.sf.jaer.aemonitor.AEPacketRaw;
import net.sf.jaer.event.BasicEvent;
import net.sf.jaer.hardwareinterface.HardwareInterfaceException;

/**
 * Adds functionality of apsDVS sensors to based CypressFX3Biasgen class. The
 * key method is translateEvents that parses the data from the sensor to
 * construct jAER raw events.
 *
 * @author Christian/Tobi
 */
public class CochleaFX3HardwareInterface extends CypressFX3Biasgen {

	protected CochleaFX3HardwareInterface(final Device device) {
		super(device);
	}

	@Override
	synchronized public void sendConfiguration(final net.sf.jaer.biasgen.Biasgen biasgen) throws HardwareInterfaceException {
		if ((biasgen != null) && (biasgen instanceof CochleaLP.Biasgen)) {
			((CochleaLP.Biasgen) biasgen).sendConfiguration();
		}
	}

	/**
	 * The USB product ID of this device
	 */
	static public final short PID_FX3 = (short) 0x841C;
	static public final int REQUIRED_FIRMWARE_VERSION_FX3 = 2;
	static public final int REQUIRED_LOGIC_REVISION_FX3 = 0;

	/**
	 * Starts reader buffer pool thread and enables in endpoints for AEs. This
	 * method is overridden to construct our own reader with its translateEvents
	 * method
	 */
	@Override
	public void startAEReader() throws HardwareInterfaceException {
		setAeReader(new RetinaAEReader(this));
		allocateAEBuffers();

		getAeReader().startThread(); // arg is number of errors before giving up
		HardwareInterfaceException.clearException();
	}

	public static final int CHIP_COCHLEALP = 11;
	public static final int CHIP_COCHLEA4EAR = 12;
	public static final int CHIP_SAMPLEPROB = 13; // Reuse Cochlea code for SampleProb chip.

	/**
	 * Data word is tagged as AER address or ADC sample by bit 0x2000 (DATA_TYPE_MASK). Set (ADDRESS_TYPE_ADC)=ADC
	 * sample; unset (DATA_TYPE_AER_ADDRESS)=AER address.
	 */
	public static final int DATA_TYPE_AER_ADDRESS = 0x0000; // aer addresses don't have the bit set
	public static final int DATA_TYPE_ADC = 0x2000; // adc samples have this bit set
	public static final int DATA_TYPE_ADC_CNV_START = 0x3000; // adc conversion start events also have bit 12 set
	public static final int DATA_TYPE_RANDOMDAC = 0x40000; // SampleProb only, 18 bits of space needed

	/**
	 * This reader understands the format of raw USB data and translates to the
	 * AEPacketRaw
	 */
	public class RetinaAEReader extends CypressFX3.AEReader implements PropertyChangeListener {
		private final int chipID;

		private final int aerMaxAddress;

		// Event Codes
		private static final int EC_SPECIAL = 0;
		private static final int EC_SPECIAL_RESERVED = 0;
		private static final int EC_SPECIAL_TIMESTAMP_RESET = 1;
		private static final int EC_SPECIAL_ADC_START_CNV = 44;
		private static final int EC_SPECIAL_ADC_START_CNV_1US = 45;

		private static final int EC_MISC10_RANDOM_PART1 = 0;
		private static final int EC_MISC10_RANDOM_PART2 = 1;

		private int wrapAdd;
		private int lastTimestamp;
		private int currentTimestamp;

		private int randomChannel;
		private int randomNumber;

		public RetinaAEReader(final CypressFX3 cypress) throws HardwareInterfaceException {
			super(cypress);

			checkFirmwareLogic(CochleaFX3HardwareInterface.REQUIRED_FIRMWARE_VERSION_FX3,
				CochleaFX3HardwareInterface.REQUIRED_LOGIC_REVISION_FX3);

			chipID = spiConfigReceive(CypressFX3.FPGA_SYSINFO, (short) 1);

			if (chipID == CochleaFX3HardwareInterface.CHIP_COCHLEALP) {
				aerMaxAddress = 256;
			}
			else if (chipID == CochleaFX3HardwareInterface.CHIP_COCHLEA4EAR) {
				aerMaxAddress = 1024;
			}
			else {
				// CHIP_SAMPLEPROB -- 12 bits
				aerMaxAddress = 4096;
			}

			updateTimestampMasterStatus();
		}

		private void checkMonotonicTimestamp() {
			if (currentTimestamp <= lastTimestamp) {
				CypressFX3.log.severe(toString() + ": non strictly-monotonic timestamp detected: lastTimestamp=" + lastTimestamp
					+ ", currentTimestamp=" + currentTimestamp + ", difference=" + (lastTimestamp - currentTimestamp) + ".");
			}
		}

{'fraction_non_alphanumeric': 0.0757401882028919, 'fraction_numerical': 0.02318108790452146, 'mean_word_length': 4.5901218729955096, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4631644', 'n_tokens_mistral': 3133, 'n_tokens_neox': 2763, 'n_words': 779}