Esempio n. 1
0
void turnOnCapturePin(const char *msg, brain_pin_e brainPin) {
	ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
	if (driver != NULL) {
		iomode_t mode = (iomode_t) PAL_MODE_ALTERNATE(getAlternateFunctions(driver));
		efiSetPadMode(msg, brainPin, mode);
	}
}
Esempio n. 2
0
static void initWave(const char *name, int index) {
	brain_pin_e brainPin = boardConfiguration->logicAnalyzerPins[index];

	ioportid_t port = getHwPort(brainPin);
	ioportmask_t pin = getHwPin(brainPin);
	ICUDriver *driver = getInputCaptureDriver(brainPin);

	bool mode = boardConfiguration->logicAnalyzerMode[index];

	waveReaderCount++;
	efiAssertVoid(index < MAX_ICU_COUNT, "too many ICUs");
	WaveReader *reader = &readers[index];
	WaveReaderHw *hw = &reader->hw;

	reader->name = name;

	registerCallback(&hw->widthListeners, (IntListener) waAnaWidthCallback, (void*) reader);

	registerCallback(&hw->periodListeners, (IntListener) waIcuPeriodCallback, (void*) reader);

	initWaveAnalyzerDriver(hw, driver, port, pin);

	print("wave%d input on %s%d\r\n", index, portname(reader->hw.port), reader->hw.pin);
	setWaveReaderMode(hw, mode);
}
Esempio n. 3
0
static void turnOffTriggerInputPin(brain_pin_e hwPin) {
	ICUDriver *driver = getInputCaptureDriver(hwPin);
	if (driver != NULL) {
		icuDisable(driver);
		icuStop(driver);
		scheduleMsg(logger, "turnOffTriggerInputPin %s", hwPortname(hwPin));
		unmarkPin(hwPin);
	}
}
Esempio n. 4
0
/**
 * takes next digital_input_s from the registeredIcus pool
 */
digital_input_s * addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin) {
	ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
	if (driver == NULL) {
		warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "w_not input pin");
		return NULL;
	}

	digital_input_s *hw = registeredIcus.add();
	hw->widthListeners.clear();
	hw->periodListeners.clear();
	hw->started = false;
	hw->brainPin = brainPin;
	hw->driver = driver;
	turnOnCapturePin(msg, brainPin);
	return hw;
}
Esempio n. 5
0
static ICUDriver *turnOnTriggerInputPin(brain_pin_e hwPin) {
	// configure pin
	turnOnCapturePin(hwPin);
	shaft_icucfg.channel = ICU_CHANNEL_1;

	ICUDriver *driver = getInputCaptureDriver(hwPin);
	scheduleMsg(logger, "turnOnTriggerInputPin %s", hwPortname(hwPin));
	// todo: reuse 'setWaveReaderMode' method here?
	if (driver != NULL) {
		bool_t needWidthCallback = !CONFIG(useOnlyFrontForTrigger) || TRIGGER_SHAPE(useRiseEdge);
		shaft_icucfg.width_cb = needWidthCallback ? shaft_icu_width_callback : NULL;

		bool_t needPeriodCallback = !CONFIG(useOnlyFrontForTrigger) || !TRIGGER_SHAPE(useRiseEdge);
		shaft_icucfg.period_cb = needPeriodCallback ? shaft_icu_period_callback : NULL;

		efiIcuStart(driver, &shaft_icucfg);
		icuEnable(driver);
	}
	return driver;
}
Esempio n. 6
0
/**
 * turns pin off and returns digital_input_s back into registeredIcus pool
 */
void removeWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin) {
	if (brainPin == GPIO_UNASSIGNED) {
		return;
	}
	brain_pin_markUnused(brainPin);

	ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
	if (driver == NULL) {
		return;
	}
	int regSize = registeredIcus.size;
	for (int i = 0; i < regSize; i++) {
		if (registeredIcus.elements[i].driver == driver) {
			// removing from driver from the list of used drivers
			memcpy(&registeredIcus.elements[i], &registeredIcus.elements[regSize - 1],
				sizeof(digital_input_s));
			registeredIcus.size--;
			icuDisableNotificationsI(driver);
			icuStopCapture(driver);
			icuStop(driver);
			return;
		}
	}
}
Esempio n. 7
0
static void rememberPrimaryChannel(void) {
	primaryCrankDriver = getInputCaptureDriver(boardConfiguration->triggerInputPins[0]);
}