auto-sync

This commit is contained in:
rusEfi 2015-01-05 17:03:30 -06:00
parent de499f3497
commit 943bc509e0
1 changed files with 10 additions and 6 deletions

View File

@ -54,6 +54,8 @@ static int settingUpdateCount = 0;
*/ */
static bool_t isIntegrating = false; static bool_t isIntegrating = false;
/** /**
* we cannot afford relatively slow synchronous SPI communication from the scheduler callbacks, thus
* SPI is taken care from a dedicated thread where we care less about how long it would take
* true by default so that we can update the settings before starting to integrate * true by default so that we can update the settings before starting to integrate
*/ */
static bool_t needToSendSpiCommand = true; static bool_t needToSendSpiCommand = true;
@ -78,12 +80,14 @@ SPI_CR1_MSTR |
static unsigned char tx_buff[1]; static unsigned char tx_buff[1];
static unsigned char rx_buff[1]; static unsigned char rx_buff[1];
static int nonZeroResponse = 0;
#define SPI_SYNCHRONOUS(value) \ #define SPI_SYNCHRONOUS(value) \
spiSelect(driver); \ spiSelect(driver); \
tx_buff[0] = value; \ tx_buff[0] = value; \
spiExchange(driver, 1, tx_buff, rx_buff); \ spiExchange(driver, 1, tx_buff, rx_buff); \
spiUnselect(driver); spiUnselect(driver); \
if (rx_buff[0] != 0) nonZeroResponse++;
// todo: make this configurable // todo: make this configurable
static SPIDriver *driver = &SPID2; static SPIDriver *driver = &SPID2;
@ -151,8 +155,8 @@ static void showHipInfo(void) {
scheduleMsg(&logger, "band_index=%d gain_index=%d", bandIndex, currentGainIndex); scheduleMsg(&logger, "band_index=%d gain_index=%d", bandIndex, currentGainIndex);
scheduleMsg(&logger, "integrator index=%d", currentIntergratorIndex); scheduleMsg(&logger, "integrator index=%d", currentIntergratorIndex);
scheduleMsg(&logger, "spi= int=%s CS=%s updateCount=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), scheduleMsg(&logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), nonZeroResponse);
hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount); scheduleMsg(&logger, "CS=%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount);
} }
void setHip9011FrankensoPinout(void) { void setHip9011FrankensoPinout(void) {
@ -168,10 +172,10 @@ void setHip9011FrankensoPinout(void) {
static void startIntegration(void) { static void startIntegration(void) {
if (!needToSendSpiCommand) { if (!needToSendSpiCommand) {
/** /**
* SPI communication is only allowed while not integrading, so we initiate the exchange * SPI communication is only allowed while not integrating, so we postpone the exchange
* once we are done integrating * until we are done integrating
*/ */
isIntegrating = false; isIntegrating = true;
turnPinHigh(HIP9011_INT_HOLD); turnPinHigh(HIP9011_INT_HOLD);
} }
} }