From 85220734dee8459101a2e1c5516adc00aace3307 Mon Sep 17 00:00:00 2001 From: YiChin Date: Mon, 24 Aug 2020 15:59:18 +0800 Subject: [PATCH] spi hold when run mode --- .../cc26xx/app/headstage/Elite15_PIN.h | 7 ++++ .../cc26xx/app/headstage/EliteADC.h | 21 ++++++++---- .../cc26xx/app/headstage/EliteCVCurve.h | 1 + .../cc26xx/app/headstage/EliteDAC.h | 7 +++- .../cc26xx/app/headstage/EliteIVCurve.h | 2 ++ .../cc26xx/app/headstage/EliteLED.h | 17 ++++++---- .../cc26xx/app/headstage/EliteReset.h | 2 +- .../cc26xx/app/headstage/EliteSPI.h | 32 +++++++++++++++++++ .../cc26xx/app/headstage/Elite_mode_ADC_DAC.h | 4 +-- .../cc26xx/app/headstage/Elite_version.h | 6 ++-- .../cc26xx/app/headstage/headstage.h | 5 +++ .../cc26xx/app/headstage/impedance_meter.h | 2 ++ 12 files changed, 87 insertions(+), 19 deletions(-) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite15_PIN.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite15_PIN.h index 141106dd6..f18ef9a54 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite15_PIN.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite15_PIN.h @@ -133,6 +133,9 @@ static void update_latch_status (uint32_t latch_num, uint32_t elite_pin, bool hi } static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow) { + if(PeriodicEvent){ + ELITE15_SPI_CLOSE(); + } add_elite_pin(); update_latch_status (latch_num, pin_num, highlow); PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch @@ -178,6 +181,10 @@ static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool hig CPUdelay(10); PIN_setOutputValue(&ZM_rst, latch_num, 0); // Turn off latch remove_elite_pin(); + + if(PeriodicEvent){ + ELITE15_SPI_HOLD(); + } } static void Init_Elite15_PIN () { diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h index b65189061..71c752e2c 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h @@ -46,7 +46,11 @@ static void ADC_write(uint8_t ADCin) { spi_ADC_txbuf[0] = ADCin; spi_ADC_txbuf[1] = 0b11101011; - ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf); + if(PeriodicEvent){ + ADC_SPI_TEST(2, spi_ADC_txbuf, spi_ADC_rxbuf); + }else{ + ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf); + } } static void ADC_read(uint8_t *ADCdata){ @@ -55,7 +59,11 @@ static void ADC_read(uint8_t *ADCdata){ spi_ADC_rxbuf[i] = 0; } - ADC_SPI(SPI_ADC_SIZE, spi_ADC_txbuf, ADCdata); + if(PeriodicEvent){ + ADC_SPI_TEST(2, spi_ADC_txbuf, spi_ADC_rxbuf); + }else{ + ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf); + } } static void IinADCGainControl(uint8_t IinADCLevel){ @@ -164,7 +172,7 @@ static void ADCChannelSelect(uint8_t ADCChannel){ static void ReadADCIin(uint8_t *buf){ // Read data twice since the first data we get is previous data - IinADCGainControl(INSTRUCTION.ADCGainLevel); +// IinADCGainControl(INSTRUCTION.ADCGainLevel); ADCChannelSelect(ADC_CH_CURRENT); ADC_read(buf); @@ -174,7 +182,8 @@ static void ReadADCIin(uint8_t *buf){ static void ReadADCVin(uint8_t *buf){ // Read data twice since the first data we get is previous data - VinADCGainControl(INSTRUCTION.VinADCGainLevel); + +// VinADCGainControl(INSTRUCTION.VinADCGainLevel); ADCChannelSelect(ADC_CH_VOLT); ADC_read(buf); @@ -447,7 +456,7 @@ static void AutoGainChangeVin(int32_t RealVin){ else{ VIN_GAIN_30K_counter++; if(VIN_GAIN_30K_counter > 2){ - INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K_counter; + INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K; VinADCGainControl(INSTRUCTION.VinADCGainLevel); VIN_GAIN_30K_counter = 0; record_flag = false; @@ -507,7 +516,7 @@ static void AutoGainChangeVin(int32_t RealVin){ else{ VIN_GAIN_30K_counter++; if(VIN_GAIN_30K_counter > 2){ - INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K_counter; + INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K; VinADCGainControl(INSTRUCTION.VinADCGainLevel); VIN_GAIN_30K_counter = 0; record_flag = false; diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h index 117174459..b1b2ce385 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h @@ -210,6 +210,7 @@ static void CV_Vscan(CVMode *CV){ /*stop condition*/ if(CV->_cycleNumber == 0){ PeriodicEvent = false; + ELITE15_SPI_CLOSE(); ModeLED(NO_EVENT); } } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h index 5843db29a..cb1a71c25 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDAC.h @@ -51,7 +51,12 @@ static uint16_t DAC_outputV(uint16_t voltLV) { spi_DACtxbuf[1] = v1; spi_DACtxbuf[2] = v2; - DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf); + if(PeriodicEvent){ + DAC_SPI_TEST(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf); + }else{ + DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf); + } + return voltLV; } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h index defc2acf1..2388bcab6 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h @@ -28,11 +28,13 @@ static void IV_Vscan(IVMode *IV){ if(IV->_current_direction_up){ if(Vset >= IV->_Vmax){ PeriodicEvent = false; + ELITE15_SPI_CLOSE(); ModeLED(NO_EVENT); } }else{ if(Vset <= IV->_Vmin){ PeriodicEvent = false; + ELITE15_SPI_CLOSE(); ModeLED(NO_EVENT); } } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h index 0de9dd4fe..90b852af0 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h @@ -18,7 +18,12 @@ static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff; spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff; - LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf); + if(PeriodicEvent){ + LED_SPI_TEST(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf); + }else{ + LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf); + } + } static void Elite_led_color(uint16_t color){ @@ -82,28 +87,28 @@ static void ModeLED(uint16_t modeStatus) { switch (modeStatus) { case BT_WAIT: { - BT_WAIT_LED(); btWaitLedFlag = 1; + BT_WAIT_LED(); break; } case NO_EVENT: { - LEDPowerON(); noEventLedFlag = 1; + LEDPowerON(); break; } case PRE_WORK: { - Elite_led_color(COLOR_BLUE); preWorkLedFlag = 1; + Elite_led_color(COLOR_BLUE); break; } case WORKING: { - WorkModeLED(); workingLedFlag = 1; + WorkModeLED(); break; } case POST_WORK: { - Elite_led_color(COLOR_BLUE); postWorkLedFlag = 1; + Elite_led_color(COLOR_BLUE); break; } default: { diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteReset.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteReset.h index 0ebb3cac1..3a796e3b0 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteReset.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteReset.h @@ -39,10 +39,10 @@ static void reset() { } static void Eliteinterrupt() { + InitFlag(); ModeLED(NO_EVENT); InitEliteFlag(); - InitFlag(); InitCT(); InitGPT(); InitLH(); diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteSPI.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteSPI.h index 033f107d0..9bc33f02d 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteSPI.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteSPI.h @@ -96,6 +96,38 @@ static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) { ELITE15_SPI_CLOSE(); } +static void LED_SPI_TEST(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) { + LED_transaction.count = length; + LED_transaction.txBuf = spi_txbuf; + LED_transaction.rxBuf = spi_rxbuf; + + SPI_transfer(spiHandle0, &LED_transaction); +} + +static void ADC_SPI_TEST(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) { + PIN_setOutputValue(pin_handle, D6, 0); // CS_ADC + + ADC_DAC_transaction.count = length; + ADC_DAC_transaction.txBuf = spi_txbuf; + ADC_DAC_transaction.rxBuf = spi_rxbuf; + + SPI_transfer(spiHandle1, &ADC_DAC_transaction); + + PIN_setOutputValue(pin_handle, D6, 1); // CS_ADC +} + +static void DAC_SPI_TEST(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) { + PIN_setOutputValue(pin_handle, D7, 0); // CD_DAC + + ADC_DAC_transaction.count = length; + ADC_DAC_transaction.txBuf = spi_txbuf; + ADC_DAC_transaction.rxBuf = spi_rxbuf; + + SPI_transfer(spiHandle1, &ADC_DAC_transaction); + + PIN_setOutputValue(pin_handle, D7, 1); // CD_DAC +} + static void ELITE15_SPI_HOLD() { PIN_setOutputValue(pin_handle, LOAD0, 1); PIN_setOutputValue(pin_handle, LOAD1, 0); diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h index 819a4d80c..c074218b1 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h @@ -363,8 +363,8 @@ static void VT_Plot(WorkMode *WorkModeData) { } // ADC gain is don't care when measuring voltage - INSTRUCTION.ADCGainLevel = I_GAIN_100R; - IinADCGainControl(INSTRUCTION.ADCGainLevel); +// INSTRUCTION.ADCGainLevel = I_GAIN_100R; +// IinADCGainControl(INSTRUCTION.ADCGainLevel); static uint8_t ADCSwitch = 0; static int32_t VoltData; diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h index 2969fa40a..61e57caf2 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h @@ -4,9 +4,9 @@ #define VERSION_DATE_YEAR 20 #define VERSION_DATE_MONTH 8 -#define VERSION_DATE_DAY 20 -#define VERSION_DATE_HOUR 11 -#define VERSION_DATE_MINUTE 50 +#define VERSION_DATE_DAY 24 +#define VERSION_DATE_HOUR 15 +#define VERSION_DATE_MINUTE 59 // this is NOT the version hash !! // it's the last version hash diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h index a0bda2f39..b25b79e97 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h @@ -1111,6 +1111,7 @@ static void update_ZM_instruction(uint8 *ins) { } PeriodicEvent = true; InitEliteFlag(); + ELITE15_SPI_HOLD(); break; } @@ -1120,6 +1121,10 @@ static void update_ZM_instruction(uint8 *ins) { } case VIS_INT: { + if(PeriodicEvent){ + ELITE15_SPI_CLOSE(); + } + Eliteinterrupt(); for(int i=0 ; i<12 ; i++){ FlushNotify(); diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h index ea24c67ca..23e0c646b 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h @@ -125,6 +125,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) { if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) { DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.Ve1)); PeriodicEvent = false; + ELITE15_SPI_CLOSE(); ModeLED(NO_EVENT); } } @@ -207,6 +208,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) { DAC_outputV(Usercode_Correction_to_DAC(WorkModeData->VO->_Vset)); //UserCode -> DAC code -> DAC out FreeWorkMode(WorkModeData); PeriodicEvent = false; + ELITE15_SPI_CLOSE(); }else{ InitFlag(); }