Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cb9be51f2 | |||
| f4130016bd | |||
| 8ae2e1771c | |||
| 549db3f6d4 | |||
| 54dd4bc643 | |||
| 435acb745b | |||
| 3cf2bb99f7 | |||
| 93cdfd00f2 | |||
| b10ee4de65 | |||
| 1d3068ac7c |
+8
-4
@@ -114,9 +114,11 @@ typedef enum {
|
||||
static bool STI = false;
|
||||
static bool IsFirstData = true;
|
||||
static uint8_t spi_state_counter = 0;
|
||||
static uint8_t check_reg_counter = 0;
|
||||
static bool ConnectState = false;
|
||||
static bool ErrorRestart = false;
|
||||
static SPI_CB_MODE SPICallBack;
|
||||
static uint8 adc_spi_en_switch = 1;
|
||||
|
||||
/*
|
||||
* Let C = command, S = status;
|
||||
@@ -238,15 +240,17 @@ extern ICall_Semaphore semaphore;
|
||||
#define INS_TYPE_CIS 0x70
|
||||
|
||||
// VIS operator
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_RST 0xF0
|
||||
#define VIS_START 0xC0
|
||||
#define VIS_REC 0x10
|
||||
#define VIS_STI 0x20
|
||||
#define VIS_STOP_REC 0x30
|
||||
#define VIS_STOP_STI 0x40
|
||||
#define VIS_CAL 0xA0
|
||||
#define VIS_ASK 0x50
|
||||
#define VIS_INT 0x60
|
||||
#define VIS_FAST_SET 0x70
|
||||
#define VIS_EN_ADC_CLK 0x80
|
||||
#define VIS_CAL 0xA0
|
||||
#define VIS_START 0xC0
|
||||
#define VIS_RST 0xF0
|
||||
|
||||
|
||||
// CIS operator
|
||||
|
||||
+9
-9
@@ -14,17 +14,17 @@ static uint8_t check_ins(uint16_t trans_ins){
|
||||
}
|
||||
|
||||
static void check_register(uint8_t register_to_check, uint16_t instruction_to_fit, NEU_WORK_STATE next_state){
|
||||
if(spi_state_counter < 6){
|
||||
if(check_reg_counter < 6){
|
||||
SPICallBack = CONTINUOUS_TRANS;
|
||||
spi_txbuf[0] = register_to_check & 0x7F;
|
||||
spi_txbuf[1] = register_to_check;
|
||||
spi_txbuf[2] = register_to_check;
|
||||
spi_txbuf[1] = NEULIVE_STATE.state;
|
||||
spi_txbuf[2] = check_reg_counter;
|
||||
|
||||
spi_state_counter ++;
|
||||
check_reg_counter ++;
|
||||
headstage_spi_transaction(3);
|
||||
}
|
||||
else{
|
||||
spi_state_counter = 0;
|
||||
check_reg_counter = 0;
|
||||
if(check_ins(instruction_to_fit)){
|
||||
NEULIVE_STATE.state = next_state;
|
||||
SPICallBack = ONE_SHOT_SPI;
|
||||
@@ -163,17 +163,17 @@ static void check_sti_t1_t5(NEU_WORK_STATE next_state){
|
||||
}
|
||||
|
||||
static uint8_t check_sti_register(uint8_t address, uint16_t instruction_to_fit){
|
||||
spi_state_counter = 0;
|
||||
while(spi_state_counter < 6){
|
||||
check_reg_counter = 0;
|
||||
while(check_reg_counter < 6){
|
||||
SPICallBack = READ_REG;
|
||||
spi_txbuf[0] = address & 0x7F;
|
||||
spi_txbuf[1] = address;
|
||||
spi_txbuf[2] = address;
|
||||
|
||||
headstage_spi_transaction(3); // spi_state_counter++ would be executed in SPI callback
|
||||
headstage_spi_transaction(3); // check_reg_counter++ would be executed in SPI callback
|
||||
}
|
||||
|
||||
spi_state_counter = 0;
|
||||
check_reg_counter = 0;
|
||||
|
||||
// success = 1; failed = 0
|
||||
return check_ins(instruction_to_fit);
|
||||
|
||||
+57
-1
@@ -459,7 +459,7 @@ static void headstage_spi_callback(SPI_Handle handle, SPI_Transaction* transacti
|
||||
}
|
||||
|
||||
case READ_REG:{
|
||||
spi_state_counter ++;
|
||||
check_reg_counter ++;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -635,6 +635,62 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
|
||||
/**< stop spi transaction */
|
||||
break; /**< reset all the parameter */
|
||||
}
|
||||
|
||||
case VIS_FAST_SET:{
|
||||
INSTRUCTION.sti_t1[7] = 25;
|
||||
INSTRUCTION.sti_t2[7] = 0;
|
||||
INSTRUCTION.sti_t3[7] = 25;
|
||||
INSTRUCTION.sti_t4[7] = 0;
|
||||
INSTRUCTION.sti_t5[7] = 0;
|
||||
|
||||
INSTRUCTION.sti_t1[7] = 25;
|
||||
INSTRUCTION.sti_t2[7] = 0;
|
||||
INSTRUCTION.sti_t3[7] = 25;
|
||||
INSTRUCTION.sti_t4[7] = 0;
|
||||
INSTRUCTION.sti_t5[7] = 0;
|
||||
|
||||
INSTRUCTION.current_sti_cycle[7] = 0;
|
||||
INSTRUCTION.current_sti_cycle[8] = 10; // ch8 is volt ch
|
||||
INSTRUCTION.sti_channel = 0b0000000010000000; // 0bxxxx_xxxv_cccc_cccc, c = current; v = volt, x = don't care
|
||||
INSTRUCTION.arbitrary_en = 0;
|
||||
INSTRUCTION.arbitrary_index = 0;
|
||||
INSTRUCTION.sti_mode = 0; // 1 = continuous mode; 0 = limit mode
|
||||
INSTRUCTION.sti_h_bridge = 0; // voltage sti must use H-bridge
|
||||
INSTRUCTION.sti_ref = 0; // 1 = GND; 0 = Vref
|
||||
|
||||
/* the first byte decide current sti polarity */
|
||||
// e.g. 0b0000_0101 => ch0, ch2 positive, others negative
|
||||
|
||||
/* the second byte decide voltage sti polarity */
|
||||
// for the second byte, 0bxxxx_XXXX, decide voltage sti p & n channel;
|
||||
// xxxx is p-channel (16 choose 1), XXXX is n-channel
|
||||
INSTRUCTION.current_sti_polarity = 0b1000000000000000;
|
||||
INSTRUCTION.sti_amplitude_h = 0x0000; // it's t1 amplitude
|
||||
INSTRUCTION.sti_amplitude_l = 0x0000; // it's t3 amplitude
|
||||
INSTRUCTION.voltage_sti_amplitude = 0x0F;
|
||||
|
||||
rec_sti_command |= ENABLE_STI;
|
||||
NEULIVE_STATE.state = NEU_WRITE_STI_INS;
|
||||
NEULIVE_STATE.config_type = NEU_WARM_UP;
|
||||
SPICallBack = ONE_SHOT_SPI;
|
||||
INSTRUCTION.ins_opcode = T_ZE;
|
||||
|
||||
// is neu wording now?
|
||||
if( (rec_sti_command & STATUS_STI) || (rec_sti_command & STATUS_REC) ){
|
||||
// nothing to do
|
||||
}
|
||||
else{
|
||||
flag_notify(EVT_NEU_SPI);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_EN_ADC_CLK:{
|
||||
adc_spi_en_switch ^= 1;
|
||||
headstage_pin_output(PIN_EN_ADC_SPI_CLK, adc_spi_en_switch);
|
||||
break;
|
||||
}
|
||||
|
||||
case VIS_START: {
|
||||
// for(int i=0 ; i<12 ; i++){
|
||||
// FlushNotify();
|
||||
|
||||
+5
-5
@@ -3,14 +3,14 @@
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 20
|
||||
#define VERSION_DATE_MONTH 6
|
||||
#define VERSION_DATE_DAY 16
|
||||
#define VERSION_DATE_HOUR 15
|
||||
#define VERSION_DATE_MINUTE 21
|
||||
#define VERSION_DATE_MONTH 7
|
||||
#define VERSION_DATE_DAY 9
|
||||
#define VERSION_DATE_HOUR 10
|
||||
#define VERSION_DATE_MINUTE 16
|
||||
|
||||
// this is NOT the version hash !!
|
||||
// it's the last version hash
|
||||
#define VERSION_HASH fce3f53b404738630e7f598238b1936d9bf0a72e
|
||||
#define VERSION_HASH 549db3f6d4f60019e726ba2b4318c2dd968cf3d5
|
||||
#define VERSION_GIT_BRANCH Neulive2.0_developement
|
||||
|
||||
static void get_board_name(char *board_name_ch, uint8 *board_name_int, uint8 name_size){
|
||||
|
||||
+2
@@ -19,6 +19,8 @@ static void MCUReset(){
|
||||
// SPI reset
|
||||
SPI_close(headstage_spi_handle);
|
||||
spi_state_counter = 0;
|
||||
check_reg_counter = 0;
|
||||
|
||||
for(int i=0 ; i<SPI_BUFFER_SIZE ; i++ ){
|
||||
spi_txbuf[i] = 0;
|
||||
spi_rxbuf[i] = 0;
|
||||
|
||||
+62
@@ -803,6 +803,45 @@ static void SimpleBLEPeripheral_stateChangeCB(gaprole_States_t newState) {
|
||||
SimpleBLEPeripheral_enqueueMsg(SBP_STATE_CHANGE_EVT, newState);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn BitReverse
|
||||
*
|
||||
* @brief Change input Array in bit reversed index 0101(5)->1010(10)
|
||||
* cause FFT need Butterfly pairs.
|
||||
*
|
||||
* @param newState - new state (??)
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void BitReverse(int BR_array[],int NUM_FFT) {
|
||||
#if (NUM_FFT >= 512)
|
||||
unsigned int swapA, swapB, sw_cnt;
|
||||
#endif
|
||||
|
||||
#if (NUM_FFT <= 256)
|
||||
unsigned int swapA, swapB, sw_cnt;
|
||||
#endif
|
||||
|
||||
|
||||
unsigned char BR_table = [0,4,2,6,1,3,5,7];
|
||||
int TemStore;
|
||||
|
||||
for (sw_cnt=1; sw_cnt<NUM_FFT/2; sw_cnt++){
|
||||
swapA = sw_cnt;
|
||||
swapB = BR_table[sw_cnt] *2;
|
||||
if (swapB > swapA){
|
||||
TemStore = BR_array[swapA];
|
||||
BR_array[swapA] = BR_array[swapB];
|
||||
BR_array[swapB] = TemStore;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_processStateChangeEvt
|
||||
*
|
||||
@@ -820,11 +859,34 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
|
||||
|
||||
GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);
|
||||
|
||||
uint16_t CH1[], CH2[], CH3[], CH4[], CH5[], CH6[], CH7[], CH8[]; // <======= BS 0709
|
||||
|
||||
|
||||
// use 6 bytes of device address for 8 bytes of system ID value
|
||||
systemId[0] = ownAddress[0];
|
||||
systemId[1] = ownAddress[1];
|
||||
systemId[2] = ownAddress[2];
|
||||
|
||||
switch(ch){ // <======= BS 0709
|
||||
case(1):
|
||||
idx = size(CH1);
|
||||
if (idx<6){
|
||||
CH1[idx+1] = dataIN;
|
||||
}
|
||||
else if (idx<FFT_NUM){
|
||||
LFP_tmp = CH1[idx-1]*w1 + CH1[idx-2]*w2 + CH1[idx-3]*w3 + CH1[idx-4]*w4 + CH1[idx-5]*w5;
|
||||
CH1[idx+1] = (LFP_tmp < 0) ? 0 - LFP_tmp : LFP_tmp;
|
||||
}
|
||||
else{
|
||||
BitReverse(CH1);
|
||||
FFT(CH1)
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// set middle bytes to zero
|
||||
systemId[4] = 0x00;
|
||||
systemId[3] = 0x00;
|
||||
|
||||
Reference in New Issue
Block a user