From 16ac2ab82dbdb95c5f203a32dc30935b671ba51c Mon Sep 17 00:00:00 2001 From: Roy Date: Thu, 18 May 2023 11:34:24 +0800 Subject: [PATCH] Feat(#7): modularize boot function https://www.notion.so/7-Modularize-some-function-e19a0f14fb3f494b9fbb5103d7befb7f --- .../cc26xx/app/headstage/Elite_version.h | 2 +- .../cc26xx/app/headstage/headstage.h | 11 +- .../cc26xx/app/simple_peripheral.c | 142 +++++++++++++----- 3 files changed, 113 insertions(+), 42 deletions(-) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h index eeb9a0c..6f928f8 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h @@ -5,5 +5,5 @@ #define VERSION_DATE_MONTH 5 #define VERSION_DATE_DAY 18 #define VERSION_DATE_HOUR 11 -#define VERSION_DATE_MINUTE 9 +#define VERSION_DATE_MINUTE 34 #endif 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 e7a021f..d7b3ed4 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 @@ -114,7 +114,7 @@ static bool FLT_event = false; /** * ZM function */ -static void ZM_init(); +static void device_init(); // callback for Z meter typedef void (*update_instruction_callback_type)(uint8_t ins_type, uint8_t ins_len, uint8_t *ins); @@ -949,27 +949,28 @@ static void SimpleBLEPeripheral_clockHandler(UArg arg) // Semaphore_post(semaphore); // send samaphore to jump out of infinite waiting(simple_peripheral.c line570) } -static void ZM_init() +static void device_init() { // initialize pin_handle = PIN_open(&ZM_rst, BLE_IO); + InitEliteInstruction(); + InitLED(); InitTrigChan(); Init_Elite15_PIN(); ELITE15_SPI_HOLD(); - PIN15_setOutputValue(E_PIN_OFF, 1); // OFF = 1 => turn off 6994 PIN15_setOutputValue(E_PIN_3V_PULL_UP_DOWN_0, 0); PIN15_setOutputValue(E_PIN_3V_PULL_UP_DOWN_1, 0); disable_trig_output(); // all output disable - InitEliteInstruction(); elite_gptimer_open(); - TW1508reset(); + + InitGPT(); // PIN_registerIntCb(pin_handle, switch_on_callback); // PIN_setInterrupt(pin_handle, CC2650_SHUT_DOWN | PIN_IRQ_POSEDGE); } 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 7944c4b..bccf8b0 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 @@ -554,20 +554,100 @@ void elite_gptimer_task(void) #include "headstage.h" +static bool power_on(uint32_t delta_time) +{ + uint32_t t = delta_time; + bool elite_on = false; + static uint32_t keyTimer = 0; + + keyTimer = keyTimer + t; + + if (keyTimer >= 10000) { + PIN15_setOutputValue(E_PIN_5V_enable, 1); // enable 5V + + CPUdelay_us(320); // need delay 320us to stablize power + ModeLED(BT_WAIT); + + headstage_init_device_info(); + + elite_on = true; + } + + return elite_on; +} + +/*return the button status*/ +uint8_t pin_button_get(void) +{ + /* + * if btn = 0: press key + * if btn = 1: release key + */ + + uint8_t btn; + + btn = PIN_getInputValue(CC2650_SHUT_DOWN); + + return btn; +} + +/* manage the button control*/ +static void key_manage(uint32_t delta_time) +{ + uint32_t t = delta_time; + static uint32_t keyTimer = 0; + static bool byPass1sec = false; + + if (pin_button_get()!=0) { + if (keyTimer > 0) { + checkFlafLED(); + byPass1sec = false; + } + keyTimer = 0; + return; + } + + keyTimer = keyTimer + t; + if (keyTimer >= 30000){ + PIN15_setOutputValue(E_PIN_5V_enable, 0); // disable 5V + + } else if (keyTimer >= 10000 && !byPass1sec) { + Elite_led_color(COLOR_YELLOW); + byPass1sec = true; + } + + return; +} + +/* toggle 6994 to on*/ +static void toggle_6994(uint16_t counter6994) { + if(counter6994 == CLOCK_ONE_SECOND*5) { + PIN15_setOutputValue(E_PIN_OFF, 0); // OFF = 1 => turn off 6994 + } +} + static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) { - uint8_t key = 0; - bool EliteOn = 0; + bool elite_on = false; + uint32_t check_key_time = 0; uint16_t counter6994 = 0; // Initialize application SimpleBLEPeripheral_init(); - ZM_init(); - // Application main loops - GPT.cnt_gpt0 = GPT.cnt_gpt; + device_init(); - headstage_init_device_info(); + while(1) { + if (events & SBP_PERIODIC_EVT) { + events &= ~SBP_PERIODIC_EVT; + GPT_timerIncrement(); + elite_on = power_on(GPT.cnt_gpt_delta); + } + if (elite_on) + break; + } + + // headstage_init_device_info(); for (;;) { @@ -627,42 +707,34 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) } } + GPT_timerIncrement(); + check_key_time = check_key_time + GPT.cnt_gpt_delta; + GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.cnt_gpt_delta; + GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.cnt_gpt_delta; + if (events & SBP_PERIODIC_EVT) { events &= ~SBP_PERIODIC_EVT; + + /* routinely check the button status*/ + if (check_key_time >= 200) { + key_manage(200); + check_key_time = 0; + } if (!PeriodicEvent) { // if there is no periodic event - key = PIN_getInputValue(CC2650_SHUT_DOWN); - if (EliteOn) + + if (counter6994 <= CLOCK_ONE_SECOND * 5) { - if (counter6994 < CLOCK_ONE_SECOND * 5) - { // counter6994 enable a IC after 35 counts - counter6994++; - } - else if (counter6994 == CLOCK_ONE_SECOND * 5) - { - PIN15_setOutputValue(E_PIN_OFF, 0); // OFF = 1 => turn off 6994 - counter6994++; - } - else if (counter6994 > CLOCK_ONE_SECOND * 5) - { - counter6994 = 0; - } - EliteKeyPress(key); - - GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0; - GPT.cnt_gpt0 = GPT.cnt_gpt; - - if (Free_Work_Mode) - { - wm_deinit(); - InitEliteInstruction(); - Free_Work_Mode = false; - } + toggle_6994(counter6994); + counter6994++; } - else + + if (Free_Work_Mode) { - EliteOn = TurnOnElite(key); + wm_deinit(); + InitEliteInstruction(); + Free_Work_Mode = false; } if (TRIG_TrigEnable) @@ -688,8 +760,6 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) // Perform periodic application task SimpleBLEPeripheral_performPeriodicTask(); - key = PIN_getInputValue(CC2650_SHUT_DOWN); - EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650 } }