Modify trigger receive function.

Turn on PULSE_MODE.
Use "struct" to express channel.
This commit is contained in:
Benny Liu
2021-05-24 16:20:25 +08:00
parent b5a7720c24
commit 123e620f50
8 changed files with 105 additions and 57 deletions
@@ -115,6 +115,10 @@ struct HEADSTAGE_INSTRUCTION {
bool output_5v_en0;
bool output_5v_en1;
/** trigger mode enable **/
bool trig0_en;
bool trig1_en;
} INSTRUCTION = {0};
/*********************************************************************
@@ -260,7 +260,7 @@ static void WorkModeLED() {
case VT_CURVE:
case IT_CURVE:
case ADC_TEST:{
SET_LED_CHAN(chan_en, WORKING);
SET_LED_CHAN(TRC.chan_en, WORKING);
break;
}
case CYCLIC_VOLTAMMETRY:
@@ -400,22 +400,22 @@ static void SET_LED_CHAN(bool *chan_en, uint16_t modeStatus){
uint8_t trig_chan = 0;
for (int i=0; i<TRIG_CHAN_COUNT-2; i++) {
trig_chan = (uint8_t) (i);
if(chan_en[i]) {
if(TRC.chan_en[i]) {
Elite_chan_led_color(ledcolor, trig_chan);
} else {
Elite_chan_led_color(COLOR_BLACK, trig_chan);
}
}
if(!chan_en[8]) {
if(!TRC.chan_en[8]) {
Elite_chan_led_color(COLOR_PURPLE_DARK, LED_D0);
} else if(chan_en[1]) {
} else if(TRC.chan_en[1]) {
Elite_chan_led_color(ledcolor, LED_D0);
} else {
Elite_chan_led_color(COLOR_BLACK, LED_D0); // determine DOUT on or off
}
if(!chan_en[9]) {
if(!TRC.chan_en[9]) {
Elite_chan_led_color(COLOR_PURPLE_DARK, LED_D1);
} else if(chan_en[6]) {
} else if(TRC.chan_en[6]) {
Elite_chan_led_color(ledcolor, LED_D1);
} else {
Elite_chan_led_color(COLOR_BLACK, LED_D1);
@@ -11,6 +11,7 @@ static void reset() {
InitGPT();
InitLED();
InitTrigChan();
VinADCGainControl(VIN_GAIN_AUTO);
IinADCGainControl(I_GAIN_AUTO);
@@ -1,43 +1,71 @@
#ifndef ELITETRIG
#define ELITETRIG
static bool trig0_event_wait = false;
static bool trig1_event_wait = false;
static void set_output_enable(bool *out_chan);
static void InitTrigChan () {
for(int i=0; i<TRIG_CHAN_COUNT; i++) {
TRC.chan_en[i] = 0;
}
}
static void trig_en_check( ) {
if (INSTRUCTION.trig0_en) {
trig0_event_wait = true;
INSTRUCTION.trig0_en = 0;
} else if (INSTRUCTION.trig1_en) {
trig1_event_wait = true;
INSTRUCTION.trig1_en = 0;
}
}
static void FLT_sense( ) {
bool FLT_value = 1;
bool FLT_value = true;
FLT_value = PIN_getInputValue(FLT);
if(FLT_event) {
FLT_value = PIN_getInputValue(FLT);
if(!FLT_value) { // if FLT = LOW, disable 5V output
PIN15_setOutputValue(OUT_5V_EN_0, 1);
PIN15_setOutputValue(OUT_5V_EN_1, 1);
} else {
PIN15_setOutputValue(OUT_5V_EN_0, 0);
PIN15_setOutputValue(OUT_5V_EN_1, 0);
}
if(!FLT_value) { // if FLT = LOW, disable all output
// PIN15_setOutputValue(OUT_5V_EN_0, 1);
// PIN15_setOutputValue(OUT_5V_EN_1, 1);
// set_output_enable(allDisable);
} else {
// PIN15_setOutputValue(OUT_5V_EN_0, 0);
// PIN15_setOutputValue(OUT_5V_EN_1, 0);
PIN15_setOutputValue_refresh();
}
}
static void trig_sense( ) {
if(trig0_event) {
trig0_event = false;
LED_color(DARKLED, 0xFF, 0x00, 0x00);
} else if(trig1_event) {
trig1_event = false;
LED_color(DARKLED, 0x00, 0xFF, 0x00);
} else {
if (Trig_receive) {
Trig_receive = false;
if (trig0_event) {
trig0_event = false;
trig0_event_wait = true;
} else if (trig1_event) {
trig1_event = false;
trig1_event_wait = true;
} else if (FLT_event) {
FLT_event = false;
FLT_sense();
}
}
if (trig0_event_wait && trig1_event_wait) { // both channel are triggered
trig0_event_wait = false;
trig1_event_wait = false;
if(TRIG_TrigEnable && INSTRUCTION.eliteFxn == PULSE_MODE) {
trig_PeriodicEvent = true;
}
}
}
static void trig_callback(PIN_Handle handle, PIN_Id pinId) {
// booION.eliteFxn == PULSE_MODE && megaTrigEnable){
trig_PeriodicEvent = true;
//// Mega_Trig_receive = true;
// }
if(TRIG_TrigEnable && INSTRUCTION.eliteFxn == PULSE_MODE) {
// trig_PeriodicEvent = true;
Trig_receive = true;
}
// PIN15_setOutputValue(MEGA_G_LED, 1);
// PIN15_setOutputValue(MEGA_G_LED, 1);
switch (pinId) {
@@ -18,6 +18,7 @@
#define VIS_DEVICE_SHINY 0x10
#define VIS_SHINY_DIS 0x20
#define VIS_CC_ZERO 0x40
#define VIS_TRIG_EN 0x41
// RIS (real instruction)
#define IV_CURVE 0x10
@@ -97,7 +98,6 @@
#define BT_WAIT_LED() Elite_led_color(COLOR_YELLOWGREEN)
/* TRIG01 define */
#define TRIG01wait
#define PR_0 0x00
#define MOS_D0 0x01
#define MOS_A0 0x02
@@ -505,8 +505,18 @@ static bool megaStiEnable = false;
static ICall_Semaphore semaphore;
static uint16_t events;
/**
* Trigger channel initialize
*/
struct _TRC{ // Trigger Channel
bool chan_en[TRIG_CHAN_COUNT];
} TRC= {0};
static void InitTrigChan();
/* Trigger Flag */
static bool trig_PeriodicEvent = false;
static bool TRIG_TrigEnable = false;
static bool Trig_receive = false;
static bool trig0_event = false;
static bool trig1_event = false;
static bool FLT_event = false;
@@ -592,7 +602,6 @@ static bool preWorkLedFlag = 0;
static bool workingLedFlag = 0;
static bool postWorkLedFlag = 0;
static bool TRIG01workFlag = 0;
static bool chan_en[TRIG_CHAN_COUNT] = {0};
static void update_latch_status (uint32_t latch_num, uint32_t elite_pin, bool highlow);
@@ -1060,10 +1069,7 @@ static void update_ZM_instruction(uint8 *ins) {
}
case SET_EN_CHAN: { // 0x81
// bool chan_en[10] = {0};
for (int i=0; i<TRIG_CHAN_COUNT; i++){
chan_en[i] = 0;
}
InitTrigChan();
INSTRUCTION.tri_pr0 = (bool) ((ins[3] & 0xF0) >> 4);
INSTRUCTION.tri_d0 = (bool) (ins[3] & 0x0F);
@@ -1083,25 +1089,25 @@ static void update_ZM_instruction(uint8 *ins) {
INSTRUCTION.tri_d1 = 0;
}
chan_en[0] = INSTRUCTION.tri_pr0;
chan_en[1] = INSTRUCTION.tri_d0;
chan_en[2] = INSTRUCTION.tri_a0;
chan_en[3] = INSTRUCTION.tri_a2;
chan_en[4] = INSTRUCTION.tri_a3;
chan_en[5] = INSTRUCTION.tri_a1;
chan_en[6] = INSTRUCTION.tri_d1;
chan_en[7] = INSTRUCTION.tri_pr1;
chan_en[8] = INSTRUCTION.output_5v_en0;
chan_en[9] = INSTRUCTION.output_5v_en1;
TRC.chan_en[0] = INSTRUCTION.tri_pr0;
TRC.chan_en[1] = INSTRUCTION.tri_d0;
TRC.chan_en[2] = INSTRUCTION.tri_a0;
TRC.chan_en[3] = INSTRUCTION.tri_a2;
TRC.chan_en[4] = INSTRUCTION.tri_a3;
TRC.chan_en[5] = INSTRUCTION.tri_a1;
TRC.chan_en[6] = INSTRUCTION.tri_d1;
TRC.chan_en[7] = INSTRUCTION.tri_pr1;
TRC.chan_en[8] = INSTRUCTION.output_5v_en0;
TRC.chan_en[9] = INSTRUCTION.output_5v_en1;
SET_LED_CHAN(chan_en, NO_EVENT);
// set_output_enable(chan_en);
SET_LED_CHAN(TRC.chan_en, NO_EVENT);
// set_output_enable(TRC.chan_en);
break;
}
case ADC_TEST: { // 0x91
INSTRUCTION.eliteFxn = ADC_TEST;
set_output_enable(chan_en);
set_output_enable(TRC.chan_en);
// int32_t ADCRealValue = 0;
uint8_t CIS_buf[9] = {0};
uint16_t ADCValueAVG_RAW = 0;
@@ -1284,14 +1290,14 @@ static void update_ZM_instruction(uint8 *ins) {
}
break;
}
*/
case PULSE_MODE: {
INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
// INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.notifyRate = 100;
INSTRUCTION.VoViSwitch = 0x01;
if (ins[3] == PARA_1) {
PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode // no HIGH_Z for TRIG01
INSTRUCTION.sti_t1 = (int32_t)(ins[4]) << 24 | (int32_t)(ins[5]) << 16 | (int32_t)(ins[6]) << 8 | (int32_t)(ins[7]);
INSTRUCTION.sti_t2 = (int32_t)(ins[8]) << 24 | (int32_t)(ins[9]) << 16 | (int32_t)(ins[10]) << 8 | (int32_t)(ins[11]);
@@ -1299,7 +1305,7 @@ static void update_ZM_instruction(uint8 *ins) {
INSTRUCTION.sti_t4 = (int32_t)(ins[16]) << 24 | (int32_t)(ins[17]) << 16 | (int32_t)(ins[18]) << 8 | (int32_t)(ins[19]);
} else if (ins[3] == PARA_2) {
INSTRUCTION.sti_t5 = (int32_t)(ins[4]) << 24 | (int32_t)(ins[5]) << 16 | (int32_t)(ins[6]) << 8 | (int32_t)(ins[7]);
INSTRUCTION.sti_v1 = 25000; //8~11
INSTRUCTION.sti_v1 = 25000; //8~11
INSTRUCTION.sti_v2 = 50000; //12~15 //41406.43161.
INSTRUCTION.sti_v3 = 25000; //16~19
} else if (ins[3] == PARA_3) {
@@ -1322,11 +1328,12 @@ static void update_ZM_instruction(uint8 *ins) {
megaStiEnable = true;
} else if (ins[3] == PARA_17) {
INSTRUCTION.eliteFxn = PULSE_MODE;
ModeLED(WORKING);
set_output_enable(TRC.chan_en);
// ModeLED(WORKING);
ModeLED(TRIG01_WORK);
}
break;
}
*/
default: {
/** **/
break;
@@ -1413,6 +1420,13 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case VIS_TRIG_EN: { // 0x41
INSTRUCTION.trig0_en = (bool) ((ins[2] & 0xF0) >> 4);
INSTRUCTION.trig1_en = (bool) (ins[2] & 0x0F);
trig_en_check();
break;
}
default: {
break;
}
@@ -47,6 +47,7 @@ static void ZM_init() {
// initialize
pin_handle = PIN_open(&ZM_rst, BLE_IO);
InitLED();
InitTrigChan();
Init_Elite15_PIN();
ELITE15_SPI_HOLD();
@@ -640,11 +640,11 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
EliteOn = TurnOnElite(key);
}
FLT_sense();
trig_sense();
if (trig_PeriodicEvent) {
trig_PeriodicEvent = false;
trig_PeriodicEvent = false;
PeriodicEvent = true;
}
}