Compare commits

...

36 Commits

Author SHA1 Message Date
hchen3 09f640a461 No_Preamble_check 2020-04-08 14:36:20 +08:00
hchen3 bd5db061cf LED_cha_chb 2020-04-08 13:57:33 +08:00
hchen3 42b44c5fa9 Mod_channel_case_2ch_v2 2020-03-31 14:14:04 +08:00
hchen3 570ed42cbc Merge remote-tracking branch 'hchen3/Modify_Pramble_Header_Detection' into Modify_Pramble_Header_Detection 2020-03-30 11:05:43 +08:00
hchen3 6504da47ac Mod_channel_case_3ch_v2 2020-03-30 11:04:55 +08:00
hchen3 208d62eb69 Mod_channel_assign5 2020-03-28 16:58:12 +08:00
hchen3 3a79e48919 Merge remote-tracking branch 'hchen3/Modify_Pramble_Header_Detection' into Modify_Pramble_Header_Detection 2020-03-28 10:27:35 +08:00
hchen3 5adfd81788 Mod_channel_case_3ch 2020-03-28 10:26:37 +08:00
hchen3 9e26e00462 Mod_channel_case_2ch2 2020-03-28 10:24:04 +08:00
hchen3 898433816a Mod_channel_add_case3 2020-03-28 10:14:04 +08:00
hchen3 7e2b3cee98 Mod_channel_case_2ch 2020-03-28 09:50:56 +08:00
hchen3 2610a9e00e Mod_channel_assign6 2020-03-19 18:19:33 +08:00
hchen3 9eea6cac7c Mod_channel_assign5 2020-03-19 17:52:26 +08:00
hchen3 2a46c5d026 Mod_channel_assign4 2020-03-19 17:21:45 +08:00
hchen3 d2045fa63f Mod_channel_assign3 2020-03-19 17:08:02 +08:00
hchen3 36e7163bb3 Mod_channel_assign2 2020-03-19 16:30:58 +08:00
hchen3 1054988b16 0318_Return_Mod_Dat0_check3 2020-03-19 16:16:26 +08:00
yichin 7c708654cd Mod_channel_assign 2020-03-19 11:17:09 +08:00
yichin 496db61308 battery add 2020-03-19 10:46:40 +08:00
yichin a64d13f4e0 battery update 2020-03-19 10:46:37 +08:00
yichin c1132d321d battery update 2020-03-19 10:46:35 +08:00
hchen3 b7fa8b3c7a 0318_Return_Mod_Dat0_check2 2020-03-19 10:04:01 +08:00
hchen3 3cbc906806 0318_Return_Mod_Dat0_check 2020-03-18 17:21:45 +08:00
yichin 50811fa214 error fix 5 2020-02-21 16:09:17 +08:00
hchen3 1efe5c509e no LED indicator 2020-02-21 15:23:52 +08:00
yichin bace7d6aab error fix 3 2020-02-21 12:11:15 +08:00
yichin 2045117015 error fix 3 2020-02-21 12:07:10 +08:00
yichin 45129ab0e6 error fix 3 2020-02-21 12:01:18 +08:00
yichin a486d79200 error fix 2 2020-02-21 11:45:27 +08:00
yichin 9d4a3fb54e error fix 2020-02-21 11:30:30 +08:00
hchen3 0827b776ce modify preamble detection 2 2020-02-21 11:13:05 +08:00
hchen3 206a8b5c5b modify preamble detection 2020-02-20 23:42:08 +08:00
hchen3 dd566be7b5 change LED color 2020-02-20 21:36:38 +08:00
yichin aec34a874f Merge remote-tracking branch 'origin/refix2' into refix2 2020-02-20 17:52:19 +08:00
yichin 707ec44894 channel pointer2 2020-02-20 17:23:53 +08:00
yichin 77e34ea969 error fix 2020-02-20 17:17:22 +08:00
6 changed files with 188 additions and 33 deletions
@@ -5,16 +5,26 @@
#include <driverlib/aon_batmon.h>
#define MAX_BATTERY_CAPACITY 4200
static uint8_t battery_percent = 100;
static uint8_t battery_volt = 256;
static uint8_t headstage_battery_percent() {
static uint8_t headstage_battery_volt1() {
uint8_t internal_battery_percent;
uint32_t internal_batt_sense = AONBatMonBatteryVoltageGet();
internal_batt_sense = (internal_batt_sense * 125) >> 5;
internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
// internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
internal_battery_percent = internal_batt_sense & 0xff;
if (internal_battery_percent < battery_percent) battery_percent = internal_battery_percent;
return battery_percent;
battery_volt = internal_battery_percent;
return battery_volt;
}
#endif // HEADSTAGE_BATT_H
static uint8_t headstage_battery_volt2() {
uint8_t internal_battery_percent;
uint32_t internal_batt_sense = AONBatMonBatteryVoltageGet();
internal_batt_sense = (internal_batt_sense * 125) >> 5;
// internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
internal_battery_percent = (internal_batt_sense >> 8) & 0xff;
battery_volt = internal_battery_percent;
return battery_volt;
}
#endif // HEADSTAGE_BATT_H
@@ -702,6 +702,7 @@ static void headstage_init() {
}
static void headstage_update_ris_instruction(uint8_t ins_len, uint8_t* instruction) {
uint8_t fled;
switch ((instruction[0] & 0xE0)) {
case RIS_DIR: {
uint8_t amp_lbf = (instruction[0] & 0b00000111);
@@ -740,10 +741,43 @@ static void headstage_update_ris_instruction(uint8_t ins_len, uint8_t* instructi
INSTRUCTION.sti_times = sti_times;
INSTRUCTION.sti_freq = sti_freq;
INSTRUCTION.mode = mode;
if (instruction[3] & 0b10000000) INSTRUCTION.channel_table[amp_channel_table[cha] - 1] = TRUE;
if (instruction[3] & 0b01000000) INSTRUCTION.channel_table[amp_channel_table[chb] - 1] = TRUE;
if (instruction[3] & 0b00100000) INSTRUCTION.channel_table[amp_channel_table[chc] - 1] = TRUE;
if (instruction[3] & 0b00010000) INSTRUCTION.channel_table[amp_channel_table[chd] - 1] = TRUE;
if (instruction[3] & 0b10000000) {
INSTRUCTION.channel_table[amp_channel_table[cha] - 1] = TRUE;
for (fled=0; fled < amp_channel_table[cha]; fled++)
{
headstage_led_spi_color(COLOR_RED);
CPUdelay(16000*500); //100ms
headstage_led_spi_color(COLOR_GREEN);
}
}
if (instruction[3] & 0b01000000) {
INSTRUCTION.channel_table[amp_channel_table[chb] - 1] = TRUE;
for (fled=0; fled < amp_channel_table[chb]; fled++)
{
headstage_led_spi_color(COLOR_BLUE);
CPUdelay(16000*500); //100ms
headstage_led_spi_color(COLOR_GREEN);
}
}
if (instruction[3] & 0b00100000) {
INSTRUCTION.channel_table[amp_channel_table[chc] - 1] = TRUE;
for (fled=0; fled < amp_channel_table[chc]; fled++)
{
headstage_led_spi_color(COLOR_RED);
CPUdelay(16000*500); //100ms
headstage_led_spi_color(COLOR_GREEN);
}
}
if (instruction[3] & 0b00010000) {
INSTRUCTION.channel_table[amp_channel_table[chd] - 1] = TRUE;
for (fled=0; fled < amp_channel_table[chd]; fled++)
{
headstage_led_spi_color(COLOR_BLUE);
CPUdelay(16000*500); //100ms
headstage_led_spi_color(COLOR_GREEN);
}
}
break;
}
@@ -773,11 +807,13 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
case VIS_RST:
headstage_reset();
headstage_state = UMC_STATE_HANDSHAKE;
INSTRUCTION.channel_pointer=0;
// try to pull PIN_RESET PIN to ground
break;
case VIS_STI:
if (headstage_state == UMC_STATE_INTERRUPT) {
if (headstage_state == UMC_STATE_INTERRUPT) { //This if cond. seems only for old version digital core
headstage_state = UMC_STATE_INITIAL;
INSTRUCTION.channel_pointer = 0;
rearrange_channel_mux_table();
UMC_STATE.config_type = CONFIG_AMP_MUX;
headstage_led_spi_color(COLOR_BLACK);
@@ -785,6 +821,7 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
headstage_spi_ask_transaction(4);
} else {
headstage_state = UMC_STATE_HANDSHAKE;
INSTRUCTION.channel_pointer = 0;
rearrange_channel_mux_table();
headstage_pwm_start(headstage_system_pwm_handle);
headstage_pwm_start(headstage_poly_r_pwm_handle);
@@ -800,6 +837,7 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
case VIS_INT:
headstage_reset();
headstage_state = UMC_STATE_HANDSHAKE;
INSTRUCTION.channel_pointer = 0;
break;
case VIS_BLE_T:
@@ -834,7 +872,8 @@ static void headstage_update_cis_instruction(uint8_t cis_oper) {
case CIS_VOLT: {
cdr_buf[0] = CIS_VOLT | CHIP_ID;
cdr_buf[1] = headstage_battery_percent();
cdr_buf[1] = headstage_battery_volt1();
cdr_buf[2] = headstage_battery_volt2();
SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf);
@@ -875,37 +914,119 @@ 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 ( 9b01100_0001 ) header 58(0101xxxx)
// if (channel == INSTRUCTION.last_enable_channel) : preamble + header + 10b data
// else: 9b00000_0000 + header + 10b data
// 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
if (((dat_buf[0] & 0xC1) != 0xC1) && (dat_buf[0] != 0x00)) {
headstage_led_spi_color(COLOR_CYAN);
headstage_uni_delay();
headstage_led_spi_color(COLOR_CYAN);
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);
}
//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);
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);
}
}
//headstage_led_spi_color(COLOR_CYAN);
uint8_t channel;
uint8_t channel_pointer = INSTRUCTION.channel_pointer;
uint8_t pramb;
switch (INSTRUCTION.enable_channel_number){
case 1:
pramb = 0;
channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
break;
case 2:
//if ((dat_buf[0] & 0xC1) == 0xC1) {
// channel = reverse_channel[INSTRUCTION.last_enable_channel];
// }
//else if (dat_buf[0] == 0 && pramb == 0) {}
//else{
if(channel_pointer==0 && INSTRUCTION.channel_mux[channel_pointer]==INSTRUCTION.last_enable_channel)
{channel_pointer++;}
if ((INSTRUCTION.last_enable_channel%2) == 0)
if (channel_pointer == INSTRUCTION.last_enable_channel)
{channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer - 1]];}
else
{channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer + 1]];}
else
{channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];}
// }
channel_pointer++;
INSTRUCTION.channel_pointer = channel_pointer % (INSTRUCTION.last_enable_channel+1);
break;
//case 3:
// if ((dat_buf[0] & 0xC1) == 0xC1) {
// channel = reverse_channel[INSTRUCTION.last_enable_channel];
// }
// else {
// channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
// }
// channel_pointer++;
// INSTRUCTION.channel_pointer = channel_pointer % (INSTRUCTION.enable_channel_number);
// break;
default: // for enable_channel_num >4
//expectation on preamble
if (INSTRUCTION.channel_mux[channel_pointer] == INSTRUCTION.last_enable_channel){
pramb=1;
}
else {
pramb=0;
}
uint8_t channel;
uint8_t channel_pointer = INSTRUCTION.channel_pointer;
//if ((dat_buf[0] & 0xC1) == 0xC1) {
// channel = reverse_channel[INSTRUCTION.last_enable_channel];
//}
//else{
if(channel_pointer==0 && INSTRUCTION.channel_mux[channel_pointer]==INSTRUCTION.last_enable_channel)
{channel_pointer++;}
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]];
channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
//}
//else {
// channel = reverse_channel[13];
// //headstage_led_spi_color(COLOR_RED);
//}
//if (channel <= INSTRUCTION.last_enable_channel){
channel_pointer++;
INSTRUCTION.channel_pointer = channel_pointer % INSTRUCTION.enable_channel_number;
}
INSTRUCTION.channel_pointer = channel_pointer % (INSTRUCTION.last_enable_channel+1);
//}
break;
}
//left shift the data buffer by 1 bit according to header position
/*if (((dat_buf[0] & 0xC1) != 0xC1) && (dat_buf[0] != 0x00)) {
// headstage_uni_delay();
} else {
*/
//if (channel < (INSTRUCTION.last_enable_channel+1)){
uint8_t data_size = headstage_notify_append_data(channel, dat_buf);
if (data_size >= BLE_NOT_BUFF_SIZE) {
headstage_notify_flip_buffer();
headstage_notify_send();
}
}
//}
/*else if (channel > INSTRUCTION.last_enable_channel){
headstage_led_spi_color(COLOR_RED);
channel_pointer = channel_pointer+2; //This line may not work for complex channel arrangement
}*/
//else{
/* DO nothing */
//}
// uint16_t data_value = (uint16_t)(((dat_buf[1] & 0x0F) << 6) | ((dat_buf[2] & 0xFC) >> 2));
headstage_spi_lsk_transaction(3);
}
@@ -0,0 +1,11 @@
#ifndef VERSION_DATE
#define VERSION_DATE
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 2
#define VERSION_DATE_DAY 14
#define VERSION_DATE_HOUR 18
#define VERSION_DATE_MINUTE 30
#endif
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>uni</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
@@ -408,8 +408,7 @@ static void SimpleBLEPeripheral_init(void) {
GATT_RegisterForMsgs(self);
headstage_led_spi_color(COLOR_GREEN);
HCI_LE_ReadMaxDataLenCmd();
// HCI_LE_ReadMaxDataLenCmd(); //YiChin said this command is not necessary
HCI_LE_WriteSuggestedDefaultDataLenCmd(251, 2120); // this is used for data length extension
@@ -511,7 +510,7 @@ static void headstage_init_device_info() {
for (unsigned int i = 0; i < sizeof(DEVICE_NAME) - 1; i++) {
*p++ = DEVICE_NAME[i];
}
*p++ = 15;
*p++ = 16;
*p++ = GAP_ADTYPE_MANUFACTURER_SPECIFIC;
// unsafe_memcpy(p, "BPHS", 4);
*p++ = 'B';
@@ -527,7 +526,8 @@ static void headstage_init_device_info() {
*p++ = 'B';
*p++ = 'A';
*p++ = 'T';
*p++ = headstage_battery_percent();
*p++ = headstage_battery_volt1();
*p++ = headstage_battery_volt2();
GGS_SetParameter(GGS_DEVICE_NAME_ATT, sizeof(DEVICE_NAME), DEVICE_NAME);
@@ -847,6 +847,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
case GAPROLE_WAITING:
// Device is started but not advertising, is in waiting period before advertising again
SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
headstage_led_spi_color(COLOR_GREEN);
break;
case GAPROLE_WAITING_AFTER_TIMEOUT:
@@ -862,6 +863,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
break;
case GAPROLE_INIT: // Waiting to be started
case GAPROLE_ADVERTISING: // Currently Advertising
headstage_led_spi_color(COLOR_GREEN);
case GAPROLE_CONNECTED_ADV: // In a connection and advertising
default:
break;