Merge remote-tracking branch 'origin/neulive/development' into neulive/development

This commit is contained in:
yichin
2020-01-02 11:23:30 +08:00
2 changed files with 128 additions and 40 deletions
@@ -0,0 +1,66 @@
#ifndef NEU_CHECK_LSK
#define NEU_CHECK_LSK
#define LSK_CHECKING_ERROR 0
#define LSK_NO_ERROR 1
#define LSK_ERROR 2
static int32_t CheckLSKBuf[100] = {0};
static uint8_t CheckLSKBufIndex = 0;
static uint8_t CheckLSK(uint8_t dat_buf){
if (((dat_buf[0] & 0xC1) != 0xC1) && (dat_buf[0] != 0x00)) {
headstage_uni_delay();
} else {
if ((dat_buf[1] & 0x28) == 0x28) {
dat_buf[0] = (dat_buf[0] << 1) | ((dat_buf[1] >> 7) & 0x01);
dat_buf[1] = (dat_buf[1] << 1) | ((dat_buf[2] >> 7) & 0x01);
dat_buf[2] = (dat_buf[2] << 1) | ((dat_buf[3] >> 7) & 0x01);
}
}
// uint8_t channel;
//
// if ((INSTRUCTION.enable_channel_number == 1) || (dat_buf[0] == 0xc1)) {
// channel = reverse_channel[INSTRUCTION.last_enable_channel];
// } else {
// uint8_t channel_pointer = (INSTRUCTION.channel_pointer + 1) % INSTRUCTION.last_enable_channel;
// channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
// INSTRUCTION.channel_pointer = channel_pointer;
// }
int32_t Data = ((dat_buf[1] & 0x0F) << 6) | ((dat_buf[2] & 0xFC) >> 2);
CheckLSKBuf[CheckLSKBufIndex] = Data;
CheckLSKBufIndex ++;
// check LSK work well or not
int32_t avg = 0;
if(CheckLSKBufIndex >= 100){
for(int i=0 ; i<100 ; i++){
avg = avg + CheckLSKBuf[CheckLSKBufIndex];
}
avg = avg / 100;
}
// avg abs value
if(avg < 0){ avg = -avg; }
if(CheckLSKBufIndex >= 100){
CheckLSKBufIndex = 0;
if(10 < avg && avg < 30){
return LSK_ERROR;
}
else{
return LSK_NO_ERROR;
}
}
else{
return LSK_CHECKING_ERROR;
}
}
#endif
@@ -119,6 +119,7 @@
#include "headstage_notify.h"
#include "headstage_indicate.h"
#include "headstage_batt.h"
#include "headstage_checkLSK.h"
#include "tni/headstage_notify.h"
#include "uni/headstage_spi.h"
#include "uni/headstage_pwm.h"
@@ -692,6 +693,8 @@ static void headstage_reset() {
flag_disable(EVT_UMC_LSK);
}
static uint8_t CheckLSK(uint8_t spi_rxbuf);
/*===========================
==== function implement ====
==========================*/
@@ -945,7 +948,7 @@ static uint8_t headstage_debug_instruction(uint8_t* ins_buf) {
// todo: check data length extension with this function -> this function should be
static void headstage_uni_umc_data_append_notify_buffer(uint8_t* dat_buf) {
// check LSK data preamble ( 0b01100_0001 ) 58(01011000) 2c(00101100)
// check LSK data preamble ( 0b0110_0000_1 ) 58(01011000) 2c(00101100)
// sometimes we lose the first bit , it means we only receive
// 0110_0000_1010_1xxx_xxxx_xxxX_XXXX_XXXX and
// 1100_0001_0101_xxxx_xxxx_xxXX_XXXX_XXXX
@@ -1189,47 +1192,12 @@ static void headstage_umc_state_transfer_lsk() {
}
TestCounter ++;
break;
/**
* conservative instruction need golden key to trigger DBS
*/
// conservative instruction need golden key to trigger DBS
case UMC_STATE_WAIT_START:
if (headstage_debug_buffer[1] > 18) {
// this transaction make cause amplifier data right shift
switch (INSTRUCTION.mode) {
case 0:
// continuous mode
headstage_state = UMC_STATE_TRIGGER;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
case 1:
// trigger mode
headstage_state = UMC_STATE_TRIGGER;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
case 2:
// limited mode
headstage_state = UMC_STATE_LIMITED;
UMC_STATE.trigger_times = INSTRUCTION.sti_times;
headstage_spi_lsk_transaction(3);
break;
case 3:
// continuous mode
headstage_state = UMC_STATE_CONTINUOUS;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
default:
headstage_state = UMC_STATE_CONTINUOUS;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
}
headstage_state = UMC_STATE_CHECK_LSK;
headstage_spi_lsk_transaction(3);
} else if (headstage_debug_buffer[1] > 10) {
headstage_debug_buffer[1] += 1;
tx_put_u32(0, UMC_GOLDEN_KEY);
@@ -1240,6 +1208,60 @@ static void headstage_umc_state_transfer_lsk() {
headstage_spi_ask_transaction(4);
}
break;
// check lsk, make sure DBS chip have no error
case UMC_STATE_CHECK_LSK:
uint8_t NoError = 0;
NoError = CheckLSK(spi_rxbuf);
if(NoError == LSK_NO_ERROR){
headstage_state = UMC_STATE_REC_STI;
}
else if(NoError == LSK_CHECKING_ERROR){
headstage_state = UMC_STATE_CHECK_LSK;
}
else{
headstage_state = UMC_STATE_REC_STI;
headstage_led_spi_color_debug(0xE1, 0xF1, 0x04, 0x04);
}
headstage_spi_lsk_transaction(3);
break;
case UMC_STATE_REC_STI:
// this transaction make cause amplifier data right shift
switch (INSTRUCTION.mode) {
case 0:
// continuous mode
headstage_state = UMC_STATE_TRIGGER;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
case 1:
// trigger mode
headstage_state = UMC_STATE_TRIGGER;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
case 2:
// limited mode
headstage_state = UMC_STATE_LIMITED;
UMC_STATE.trigger_times = INSTRUCTION.sti_times;
headstage_spi_lsk_transaction(3);
break;
case 3:
// continuous mode
headstage_state = UMC_STATE_CONTINUOUS;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
default:
headstage_state = UMC_STATE_CONTINUOUS;
UMC_STATE.trigger_times = 0;
headstage_spi_lsk_transaction(3);
break;
}
break;
case UMC_STATE_TRIGGER:
headstage_uni_umc_data_append_notify_buffer(spi_rxbuf);
break;