diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h index fbfaee1..a23a92b 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h @@ -2,6 +2,18 @@ #ifndef ELITEEIS #define ELITEEIS +static uint16_t LogSpacingTable10[10] = {1000, 1292, 1668, 2154, 2783, 3594, 4642, 5995, 7743, 10000}; +static uint16_t LogSpacingTable9[9] = {1000, 1334, 1778, 2371, 3162, 4217, 5623, 7499, 10000}; +static uint16_t LogSpacingTable8[8] = {1000, 1389, 1931, 2683, 3728, 5179, 7197, 10000}; +static uint16_t LogSpacingTable7[7] = {1000, 1468, 2154, 3162, 4642, 6813, 10000}; +static uint16_t LogSpacingTable6[6] = {1000, 1585, 2512, 3981, 6310, 10000}; +static uint16_t LogSpacingTable5[5] = {1000, 1778, 3162, 5623, 10000}; +static uint16_t LogSpacingTable4[4] = {1000, 2154, 4642, 10000}; +static uint16_t LogSpacingTable3[3] = {1000, 3162, 10000}; +static uint16_t LogSpacingTable2[2] = {1000, 10000}; +static uint32_t TenPowerTable[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000}; + + static void eis_fscan(void) { struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get(); 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 d864531..380b085 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 @@ -2,6 +2,12 @@ #ifndef ELITELED #define ELITELED +static bool btWaitLedFlag = 0; +static bool noEventLedFlag = 0; +static bool preWorkLedFlag = 0; +static bool workingLedFlag = 0; +static bool postWorkLedFlag = 0; + static void WorkModeLED(); static void ModeLED(uint16_t modeStatus) { 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 e0b04a2..cd4514f 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 @@ -5,6 +5,8 @@ #define Vset instru.Vset +static uint8_t avgNumTable[4] = {2, 4, 6, 8}; + static void freq_out() { DAC_outputF(instru.fset); 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 f9c5f44..f7ebff4 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 @@ -1,393 +1,4 @@ -/* -============================ -Chip Parameter Specification -============================ - -======================= ============================= -parameter value range -======================= ============================= -sampling rate 10K .. 180k Hz / channel -recording channel 1, 4, 8, 16 -AMP Gain 400, 1000, 2000 -AMP Fast Settling Time 1 us -Stimulation voltage 2V .. 5V -Stimulation pulse width 40 us .. 490 us (50 us/step) -Stimulation pulse shape POS, NEG, P2N, N2P, AWF -Stimulation pulse times 1 .. 253 (4 times/step) -Stimulation pulse freq 30 .. 10K Hz -======================= ============================= - -========================= -Instruction Specification -========================= - -:: - - | | 1 | 2 | 3 | - 012345678901234567890123456789012 - --------------------------------- - |RIS|ID | |LEN| ............. | real instruction send - |VIS|ID |OP |LEN| ............. | virtual instruction send - -H - header - -ID - chip ID - -RIS - real instruction type - -VIS - virtual instruction type - -OP - virtual instruction - -LEN, length - command length in bytes - -TYP_RIS = 0b0011_0000 # 3x -TYP_VIS = 0b1100_0000 # Cx -TYP_VDR = 0b1010_0000 # Ax - -VIS_RST = 0b1111_0000 # Fx reset -VIS_ASK = 0b0011_0000 # 3x ask in -VIS_STI = 0b1100_0000 # Cx stimulate -VIS_FUH = 0b1001_0000 # 9x flush -VIS_INT = 0b0110_0000 # 6x interrupt -VIS_SHIFT_200K = 0b1010_0000 # Ax shift gear to 200K -VIS_SHIFT_10K = 0b1110_0000 # Ex shift gear to 10K -VIS_SHIFT_200R = 0b1000_0000 # 8x shift gear to 100R - - -========================= -Instruction for HeadStage -========================= - -serial send :: - - | | 1 | 2 | 3 | - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 - ----------------------------------------------------------------- - |HEAD | ------------------------------------------------------- | - |0b100| | MOD | RATE |a|b|c|d| CH[a] | CH[b] | CH[c] | CH[d] | artifact recording mode - |0b101|AGN| LBF | AMP |C|F|S| SVT | SCH_P | SCH_N |A| | actually instruction send to DBS - |0b101|AGN| LBF | AMP |C|F|S| SVT | SCH_P | SCH_N | RATE | direct command - - | CS | LEN |0b1010 | REG_A | |CV |O|B|E|I|PV |RA | DAC control register - | CS | LEN |0b1010 | REG_A | | DAC reset, no operation - | CS | LEN |SS|MUX |PGA |M | DR |T|U|NOP|r| ADC config register - | VIS | - -HEAD - instruction type header. - -MOD - in artifact recording mode. select which wave from should be generated/ - - ====== =========== - value description - ====== =========== - 0b0001 ramp - ====== =========== - -SUB - stimulation instruction sub-type. - -AGN - amp gain - -LBF - low frequency band [1]_ - -AMP - amp mux channel. - -RATE - ADC clock sample rate (index to a value table), used for slave side chip. - - -.. [1] : little-endian. - - -CS - choose instruction write to DAC or ADC - 0000 = DAC - 1111 = ADC - -LEN - command length in bytes - DAC = 3 bytes - ADC = 2 bytes - -REG_A - register address. - 0100 = control address - 0111 = software data reset - 1111 = software full reset - 0000/0101/0110/1101/1110 = no operation - -CV - CLEAR voltage selection. - 00 = zero scale - 01 = midscale - 10/11 = full scale - -O - 5% overrange. - 0 = 5% overrange disable - 1 = 5% overrange enable - -B - bipolar range. - 0 = DAC input for bipolar output range is straight binary coded - 1 = DAC input for bipolar output range is two complement coded - -E - thermal shutdown alert. - 0 = internal digital supplt dosen't power down if die temperature exeeds 150 degrees - 1 = internal digital supply powers down if die temperature exeeds 150 degrees -I - internal reference. - 0 = internal reference turned off - 1 = internal reference turned on (default) - -PV - power up voltage. - 00 = zero scale - 01 = midscale - 10/11 = full scale - -RA - output range. - 000 = -10V to +10V - 001 = 0V to +10V - 010 = -5V to +5V - 011 = 0V to +5V - 100 = -2.5V to +7.5V - 101 = -3V to +3V - 110 = 0V to +16V - 111 = 0V to +20V - -SS - Single-short conversion start - 0 = no effect (default) - 1 = start a single conversion - -MUX - input multiplexer configuration - 000 = AINp is AIN0 and AINn is AIN1 (default) - 001 = AINp is AIN0 and AINn is AIN3 - 010 = AINp is AIN1 and AINn is AIN3 - 011 = AINp is AIN2 and AINn is AIN3 - 100 = AINp is AIN0 and AINn is GND - 101 = AINp is AIN1 and AINn is GND - 110 = AINp is AIN2 and AINn is GND - 111 = AINp is AIN3 and AINn is GND - -PGA - programmable gain amplifier configuration - (Full Scale Range = FSR) - 000 = FSR is 6.144 V - 001 = FSR is 4.096 V - 010 = FSR is 2.048 V (default) - 011 = FSR is 1.024 V - 100 = FSR is 0.512 V - 101 = FSR is 0.256 V - 110 = FSR is 0.256 V - 111 = FSR is 0.256 V - -M - ADC operating mode - 0 = continuous conversion mode - 1 = Power-down and single-shot mode (default) - -DR - data rate - (Sample per second = SPS) - 000 = 8 SPS - 001 = 16 SPS - 010 = 32 SPS - 011 = 64 SPS - 100 = 128 SPS (default) - 101 = 250 SPS - 110 = 475 SPS - 111 = 860 SPS - -T - temperature sensor mode - 0 = ADC mode (default) - 1 = temperature sensor mode - -P - pullup enable - 0 = pullup resistor disable on DOUT - 1 = pullup resistor enable on DOUT (default) - -NOP - no operation - 00/10/11 = Invalid data, do not update the contents of the Config register - 01 = Valid, update the Config register (default) - - -serial receive :: - - | | 1 | 2 | 3 | - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 - ----------------------------------------------------------------- - | HEAD|E| data | .................................. received content from DBS - | CH | data | F | .............................. data in notify content - -HEAD - 0b101 - -E - EOC flag - -CH - channel - -data - data - -F - flag - - ======= ======= - F value mean - ======= ======= - 0x00 success - 0x11 invalid - ======= ======= - -notify content:: - - | | 1 | 2 | 3 | - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 - ----------------------------------------------------------------- - | chip ID | data length | - | cpu time | - | CH | data | F | CH | data | F | - | ............................................................. | - -data length - byte counter from cpu time to end. - -cpu time - first data time. (little endian, float) - -============ -program flow -============ - -**NOTE** - -The function name start with ``@`` are headstage specific function -which just be declared in this header. - -**NOTE** - -The function name start with ``~`` are callback function -whose name is the correspond callback setter function -used to present call the callback function set by this setter function. - -initialized ------------ - -1. headstage_gtimer_init -#. headstage_spi_init -#. @headstage_init - -periodic event --------------- - -1. headstage_gptimer_main_handle - - 1. headstage_periodic_handle - - *. [rec/arm mode] - - 1. @update_ins_rec_buffer - - update channel and ADC clock bits. - - 1. @spi_transact_rec_instruction - - spi_txbuf -> Headstage -> spi_rxbuf - - 1. collect_data - - spi_rxbuf -> not_buf - - 1. [buff full] send_notify - - SimpleProfile_SetParameter(not_buf -> 4) - - *. [sti mode] - - 1. @update_ins_sti_buffer - #. @spi_transact_sti_instruction - -characteristic change event ---------------------------- - -1. headstage_instruction_update_handle - - SimpleProfile_GetParameter(3 -> ins_buf) - - 1. update_instruction - - ins_buf -> instru - - *. [INS_TYPE_RIS] - - *. [HDR_DIR] decode_direct_instruction - *. [HDR_REC] decode_recording_instruction - *. [HDR_ARM] decode_artifact_recording_instruction - *. [HDR_STI] decode_stimulating_instruction - - *. [simple] decode_stimulating_simple_instruction - *. [continuous frequency] decode_stimulating_continuous_frequency - - *. [HDR_AWF] decode_stimulating_awf_instruction - - *. [INS_TYPE_VIS] - - *. [VIS_RST] - *. [VIS_INT] - - *. ~set_update_instruction_callback(callback) - - #. update_clock_period - - GPTimer_SetFreq - - #. update_ins_buffer - - instru -> spi_txbuf - -*/ -/*================ - ==== gptimer ==== - ===============*/ -//#ifndef GPTIMER_PERIODIC_EVT -//#define GPTIMER_PERIODIC_EVT 0x0010 -//#endif - -// static GPTimerCC26XX_Handle hTimer; -// static void headstage_gptimer_init(); -// static void headstage_gptimer_main_handle(); -// static void headstage_gptimer_set_frequency(uint32_t frequency); -// static void headstage_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask); - -/*============ - ==== SPI ==== - ===========*/ - -/* system use SPI parameters */ - #ifndef HEADSTAGE_H #define HEADSTAGE_H @@ -466,94 +77,21 @@ static bool megaStiEnable = false; /** * ZM function */ -static void device_init(void); -/** - * update the instruction buffer major content. - */ -static void update_ins_buffer(); - -/** - * update the instruction buffer for recording mode. - * - * @return do spi transact or not - */ -static bool update_ins_rec_buffer(); - -/** - * send recording instruction to headstage - * - * @return data buffer - */ - -/** - * send instruction to Z meter - */ - -/*===================================== - ==== instruction update function ==== - ====================================*/ - -// callback for Z meter -typedef void (*update_instruction_callback_type)(uint8_t ins_type, uint8_t ins_len, uint8_t *ins); -static update_instruction_callback_type update_instruction_callback = NULL; - -static void set_update_instruction_callback(update_instruction_callback_type callback) { - update_instruction_callback = callback; -} - -// for DPVCurve SWVCurve -static uint16_t Amplitude; -static uint8_t PulseWidth; -static uint16_t PulseWidth_16; -static uint8_t PulsePeriod; -static uint16_t PulsePeriod_16; -static uint32_t notifyRateTable[6] = {100, 1000, 2000, 10000, 100000, 1000000}; -/* notifyRateTable: { -100 Hz: 100 , -10 Hz: 1000 , -5 Hz: 2000 , -1 Hz: 10000 , -0.1 Hz: 100000 , -0.01 Hz: 1000000 }*/ static uint32_t VsetRateTable[5] = {2, 10, 100, 1000, 10000}; //0.2ms -static uint8_t avgNumTable[4] = {2, 4, 6, 8}; -static uint16_t LogSpacingTable10[10] = {1000, 1292, 1668, 2154, 2783, 3594, 4642, 5995, 7743, 10000}; -static uint16_t LogSpacingTable9[9] = {1000, 1334, 1778, 2371, 3162, 4217, 5623, 7499, 10000}; -static uint16_t LogSpacingTable8[8] = {1000, 1389, 1931, 2683, 3728, 5179, 7197, 10000}; -static uint16_t LogSpacingTable7[7] = {1000, 1468, 2154, 3162, 4642, 6813, 10000}; -static uint16_t LogSpacingTable6[6] = {1000, 1585, 2512, 3981, 6310, 10000}; -static uint16_t LogSpacingTable5[5] = {1000, 1778, 3162, 5623, 10000}; -static uint16_t LogSpacingTable4[4] = {1000, 2154, 4642, 10000}; -static uint16_t LogSpacingTable3[3] = {1000, 3162, 10000}; -static uint16_t LogSpacingTable2[2] = {1000, 10000}; -static uint32_t TenPowerTable[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000}; + + static bool batteryCheck_flag; static bool batteryADC_flag; -static bool ADC_flag; -static bool vscan_flag; static bool notify_flag; -static bool notifyFirst_flag; -static bool impedanceRead_flag; static bool record_flag; static bool vscanReset; static bool mode_init; -static bool leadTimeReset; -static bool firstTimeReset; -static bool fset_flag; static bool fout_flag; static bool gainChange_flag; static bool firstFreq_flag; -static uint32_t time0 = 0; -static uint32_t time1 = 0; -static uint32_t delta_time = 0; -static uint32_t time10 = 0; -static uint32_t time11 = 0; -static uint32_t delta_time1 = 0; -static uint32_t test_cnt = 0; //pulse mode variable -static bool stiFirstTime; static int16_t I_GAIN_100R_counter; static int16_t I_GAIN_3K_counter; static int16_t I_GAIN_100K_counter; @@ -565,27 +103,14 @@ static int16_t VOUT_GAIN_240K_counter; static int16_t VOUT_GAIN_15K_counter; static uint8_t lastVinADCGainLv; static uint8_t lastIinADCGainLevel; -static bool btWaitLedFlag = 0; -static bool noEventLedFlag = 0; -static bool preWorkLedFlag = 0; -static bool workingLedFlag = 0; -static bool postWorkLedFlag = 0; -//EIS -static uint32_t RtiaTable[5] = {30000, 12100, 4100, 210, 210}; -static void update_latch_status (uint32_t latch_num, uint32_t elite_pin, bool highlow); -// ADC function -//static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw); -// static void headstage_battery_volt(); -// static void EliteADCBattery(); static void VinADCGainCtrl(uint8_t VinADCLevel); static void VoutGainControl(uint8_t VOUTLevel); static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow); // Elite key detection & turn on/ shutdown function (peripheral hardware control) static void ModeLED(uint16_t modeStatus); -static bool If10Von = false; // periodic event control static void EliteADCControl(void); @@ -605,17 +130,6 @@ static int32_t neg_18bit(int32_t ret); //mode (notify) static void initDATBuf(); -//init parameter -static void InitEliteFlag(); - -//EIS crap - - - - - - - #include "EliteInstruction.h" #include "EliteADC.h" #include "EliteDAC.h" @@ -1028,7 +542,6 @@ static void update_ZM_instruction(uint8 *ins) { } case VIS_STI: { - time0 = (Timestamp_get32()) / 31; for(int i = 0; i < 12; i++) { FlushNotify(); } @@ -1130,10 +643,6 @@ static void update_ZM_instruction(uint8 *ins) { } } - // call back - if (update_instruction_callback != NULL) { - update_instruction_callback(ins_type, chip_ID, ins); - } } static void ZM_instruction_update_handle(uint8_t characteristic) { 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 b771036..8407ea0 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 @@ -19,21 +19,12 @@ // header #include "EliteWorkData.h" - -static void device_init(void) -{ - gpio_create(); - InitEliteInstruction(); - - Board_initSPI(); - spi0_open(SPI_CLK_1M, POL0, PHA1); //SPI 1M: LED - spi1_open(SPI_CLK_4M, POL0, PHA0); //SPI 4M: AD5941 - - elite_gptimer_open(); - InitGPT(); - - return; -} +static bool vscan_flag; +static bool ADC_flag; +static bool notifyFirst_flag; +static bool leadTimeReset; +static bool firstTimeReset; +static bool fset_flag; static void vscan_ctrl(void); @@ -112,9 +103,6 @@ static void elite_task() SendNotify(); //send notify_flag = false; fset_flag = true; - time0 = (Timestamp_get32()) / 31; - time1 = 0; - delta_time = 0; } mode_done(); //finishMode = 1, SendNotify(), Eliteinterrupt() diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c index 969d3df..d64b24a 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/simple_peripheral.c @@ -674,6 +674,21 @@ static void key_manage(uint32_t delta_time) return; } +static void device_init(void) +{ + gpio_create(); + InitEliteInstruction(); + + Board_initSPI(); + spi0_open(SPI_CLK_1M, POL0, PHA1); //SPI 1M: LED + spi1_open(SPI_CLK_4M, POL0, PHA0); //SPI 4M: AD5941 + + elite_gptimer_open(); + InitGPT(); + + return; +} + /********************************************************************* * @fn SimpleBLEPeripheral_taskFxn *