2016-06-24 16:02:45 -07:00
|
|
|
/*
|
|
|
|
* @file CJ125.cpp
|
|
|
|
*
|
2016-07-16 23:03:46 -07:00
|
|
|
* Based on Jeff "Turbo SOB" work
|
|
|
|
*
|
2016-06-24 16:02:45 -07:00
|
|
|
* @date: Jun 24, 2016
|
2018-01-20 17:55:31 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2018
|
2016-06-24 16:02:45 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-07-17 00:01:48 -07:00
|
|
|
#include "engine.h"
|
2016-07-16 23:03:46 -07:00
|
|
|
#include "CJ125.h"
|
2016-07-17 00:01:48 -07:00
|
|
|
#include "pwm_generator.h"
|
|
|
|
#include "pid.h"
|
|
|
|
|
2016-07-25 20:03:45 -07:00
|
|
|
#if EFI_CJ125 || defined(__DOXYGEN__)
|
|
|
|
|
2016-08-01 19:04:24 -07:00
|
|
|
#include "pin_repository.h"
|
|
|
|
#include "hardware.h"
|
|
|
|
|
2016-07-17 00:01:48 -07:00
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
|
|
|
static SimplePwm wboHeaderControl;
|
|
|
|
static OutputPin wboHeaderPin;
|
|
|
|
static OutputPin cj125Cs;
|
2016-07-26 19:01:50 -07:00
|
|
|
static Logging *logger;
|
2016-07-30 19:02:52 -07:00
|
|
|
static unsigned char tx_buff[1];
|
|
|
|
static unsigned char rx_buff[1];
|
|
|
|
|
2016-07-25 19:01:42 -07:00
|
|
|
static THD_WORKING_AREA(cjThreadStack, UTILITY_THREAD_STACK_SIZE);
|
|
|
|
|
2016-07-17 00:01:48 -07:00
|
|
|
static SPIDriver *driver;
|
|
|
|
|
|
|
|
|
|
|
|
static SPIConfig cj125spicfg = { NULL,
|
|
|
|
/* HW dependent part.*/
|
|
|
|
NULL, 0,
|
|
|
|
SPI_CR1_MSTR |
|
|
|
|
SPI_CR1_CPHA | SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_BR_2 };
|
2016-07-16 23:03:46 -07:00
|
|
|
|
2016-06-24 16:02:45 -07:00
|
|
|
/**********************************************************************************
|
|
|
|
INIT_REG1 - CJ125 Initialization Register 1
|
|
|
|
00x000x0
|
|
|
|
||||||||---- VL - Pump Current Sense Amplifier - 0 = x8, 1 = x17
|
|
|
|
If VL is set to "0" the amplification of Ip is 8.
|
|
|
|
If VL is "1" the amplification is 17. The higher
|
|
|
|
amplification is needed for a better resolution
|
|
|
|
at Lambda > 1, amplification 8 for Lambda < 1.
|
|
|
|
Note: It seems to make no difference, always set to 1.
|
|
|
|
|||||||----- Unused
|
|
|
|
||||||------ LA - Pump Current Sense Amplifier - 0 = measurement, 1 = calibration
|
|
|
|
If LA is "0" the measurement mode for Ip is active.
|
|
|
|
The current pump current is displayed on Ua. If LA is
|
|
|
|
set to "1" the calibration mode is active. The shown
|
|
|
|
voltage on Ua must been subtracted from the later measurement.
|
|
|
|
|||||------- Undocumented Bit - Note: CJ125 only seems to work when set to 1.
|
|
|
|
||||-------- RA - Measurement Current for Ri - 0 = measurement, 1 = calibration
|
|
|
|
If RA is "0" the measurement mode for Ri is active and
|
|
|
|
the current resistance of the probe is "displayed" on Ur.
|
|
|
|
If RA is "1" the calibration mode is active. You get the
|
|
|
|
optimal voltage for the inner resistance of the probe on Ur.
|
|
|
|
|||--------- Unused
|
|
|
|
||---------- PA - Pump Current Control - Set to 0 to be active
|
|
|
|
|----------- ENABLE/HOLD - Must be set to 1 to enable
|
|
|
|
***********************************************************************************/
|
|
|
|
|
2016-07-25 19:01:42 -07:00
|
|
|
static cj125_state_e state = CJ125_IDLE;
|
|
|
|
|
2016-07-25 20:03:45 -07:00
|
|
|
static msg_t cjThread(void)
|
2016-07-25 19:01:42 -07:00
|
|
|
{
|
|
|
|
chRegSetThreadName("cj125");
|
|
|
|
|
|
|
|
// while(1) {
|
|
|
|
|
|
|
|
// }
|
2016-07-25 21:03:50 -07:00
|
|
|
return -1;
|
2016-07-25 19:01:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cj125test(void) {
|
|
|
|
|
2016-07-30 19:02:52 -07:00
|
|
|
// read identity command
|
|
|
|
spiSelect(driver);
|
|
|
|
tx_buff[0] = IDENT_REG_RD;
|
|
|
|
spiSend(driver, 1, tx_buff);
|
|
|
|
|
|
|
|
spiReceive(driver, 1, rx_buff);
|
|
|
|
int value = rx_buff[0] & 0xF8;
|
|
|
|
|
|
|
|
spiUnselect(driver);
|
|
|
|
|
|
|
|
scheduleMsg(logger, "cj125 got %x", value);
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-25 19:01:42 -07:00
|
|
|
}
|
2016-06-24 16:02:45 -07:00
|
|
|
|
2016-07-26 19:01:50 -07:00
|
|
|
void initCJ125(Logging *sharedLogger) {
|
|
|
|
logger = sharedLogger;
|
2016-06-24 16:02:45 -07:00
|
|
|
// still a lot to be done here :)
|
2016-07-17 00:01:48 -07:00
|
|
|
|
|
|
|
if (!boardConfiguration->isCJ125Enabled)
|
|
|
|
return;
|
|
|
|
|
2017-07-28 11:27:37 -07:00
|
|
|
cj125spicfg.ssport = getHwPort("cj125", boardConfiguration->cj125CsPin);
|
|
|
|
cj125spicfg.sspad = getHwPin("cj125", boardConfiguration->cj125CsPin);
|
2016-07-17 00:01:48 -07:00
|
|
|
|
|
|
|
driver = getSpiDevice(engineConfiguration->cj125SpiDevice);
|
|
|
|
|
2017-04-21 15:11:36 -07:00
|
|
|
cj125Cs.initPin("cj125 CS", boardConfiguration->cj125CsPin,
|
2016-07-17 00:01:48 -07:00
|
|
|
&engineConfiguration->cj125CsPinMode);
|
|
|
|
|
|
|
|
if (boardConfiguration->wboHeaterPin != GPIO_UNASSIGNED) {
|
|
|
|
// todo: use custom pin state method, turn pin off while not running
|
|
|
|
startSimplePwmExt(&wboHeaderControl, "heater control", boardConfiguration->wboHeaterPin,
|
|
|
|
&wboHeaderPin,
|
|
|
|
300, 0.1, applyPinState);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-07-25 19:01:42 -07:00
|
|
|
|
2016-07-26 19:01:50 -07:00
|
|
|
scheduleMsg(logger, "Starting cj125 spi driver");
|
|
|
|
spiStart(driver, &cj125spicfg);
|
|
|
|
|
2016-07-25 19:01:42 -07:00
|
|
|
addConsoleAction("cj125", cj125test);
|
|
|
|
|
|
|
|
chThdCreateStatic(cjThreadStack, sizeof(cjThreadStack), LOWPRIO, (tfunc_t) cjThread, NULL);
|
|
|
|
|
2016-06-24 16:02:45 -07:00
|
|
|
}
|
|
|
|
|
2018-01-28 10:04:19 -08:00
|
|
|
void cjPostState(TunerStudioOutputChannels *tsOutputChannels) {
|
|
|
|
}
|
|
|
|
|
|
|
|
float cjGetAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cjHasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-25 20:03:45 -07:00
|
|
|
#endif /* EFI_CJ125 */
|