From a2a192b421f581981d04433b46c2e0b53c142ed1 Mon Sep 17 00:00:00 2001 From: alan Date: Mon, 13 May 2019 16:11:40 +0800 Subject: [PATCH] value modify --- .clang-format | 2 +- .../cc26xx/app/headstage/headstage.h | 97 ++++++------ .../cc26xx/app/headstage/headstage_clock.h | 3 +- .../cc26xx/app/headstage/headstage_led.h | 2 +- .../cc26xx/app/headstage/headstage_zm.h | 138 +++++++++--------- .../cc26xx/app/simple_peripheral.c | 2 +- 6 files changed, 119 insertions(+), 125 deletions(-) diff --git a/.clang-format b/.clang-format index e0a254579..e22ef5210 100644 --- a/.clang-format +++ b/.clang-format @@ -8,6 +8,6 @@ AllowAllParametersOfDeclarationOnNextLine: false AllowShortFunctionsOnASingleLine: Empty BinPackArguments: false BinPackParameters: false -IndentCaseLabels: false +IndentCaseLabels: true SortIncludes: true TabWidth: 4 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 4bf7f462a..fe019d913 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 @@ -312,7 +312,7 @@ typedef struct { ==== device implement implement header ==== =========================================*/ -#include "headstage_uni.h" +#include "headstage_zm.h" /*====================== ==== main function ==== @@ -361,53 +361,54 @@ static void headstage_update_instruction(uint8_t *instruction) { uint8_t ins_len = instruction[1] & 0x0F; switch (ins_type) { - case INS_TYPE_RIS: { - headstage_update_ris_instruction(ins_len, instruction + 2); - break; - } - case INS_TYPE_VIS: - headstage_update_vis_instruction(ins_oper); - break; - - case INS_TYPE_CIS: - switch (ins_oper) { - case CIS_NOP: { - // nothing - cdr_buf[0] = _B_4b4b(CIS_NOP, CHIP_ID); - cdr_buf[1] = _B_4b4b(CDR_SUCCESS, 0); - - SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, 2, cdr_buf); + case INS_TYPE_RIS: { + headstage_update_ris_instruction(ins_len, instruction + 2); break; } + case INS_TYPE_VIS: { + headstage_update_vis_instruction(ins_oper); + break; + } + case INS_TYPE_CIS: { + switch (ins_oper) { + case CIS_NOP: { + // nothing + cdr_buf[0] = _B_4b4b(CIS_NOP, CHIP_ID); + cdr_buf[1] = _B_4b4b(CDR_SUCCESS, 0); + + SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, 2, cdr_buf); + break; + } #ifdef HEADSTAGE_CIS_VOLT_H - case CIS_VOLT: { - uint8_t status = headstage_update_vis_volt(ins_len, instruction + 2, cdr_buf + 2); + case CIS_VOLT: { + uint8_t status = headstage_update_vis_volt(ins_len, instruction + 2, cdr_buf + 2); - cdr_buf[0] = _B_4b4b(CIS_VOLT, CHIP_ID); - cdr_buf[1] = status; + cdr_buf[0] = _B_4b4b(CIS_VOLT, CHIP_ID); + cdr_buf[1] = status; - SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf); - break; - } + SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf); + break; + } #endif #ifdef HEADSTAGE_CIS_LED_H - case CIS_LED: { - uint8_t status = headstage_update_vis_led(ins_len, instruction + 2, cdr_buf + 2); + case CIS_LED: { + uint8_t status = headstage_update_vis_led(ins_len, instruction + 2, cdr_buf + 2); - cdr_buf[0] = _B_4b4b(CIS_LED, CHIP_ID); - cdr_buf[1] = status; + cdr_buf[0] = _B_4b4b(CIS_LED, CHIP_ID); + cdr_buf[1] = status; - SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf); - break; - } + SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf); + break; + } #endif - default: { - cdr_buf[0] = _B_4b4b(ins_oper, CHIP_ID); - cdr_buf[1] = _B_4b4b(CDR_FAILURE, 0); + default: { + cdr_buf[0] = _B_4b4b(ins_oper, CHIP_ID); + cdr_buf[1] = _B_4b4b(CDR_FAILURE, 0); - SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf); - break; - } + SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf); + break; + } + } } } } @@ -420,21 +421,21 @@ static void headstage_characteristic_updated(uint8_t characteristic) { static uint8_t dbg_buf[BLE_DEBUG_BUFF_SIZE] = {0}; switch (characteristic) { - case BLE_INS_BUFF_CHAR: - SimpleProfile_GetParameter(BLE_INS_BUFF_CHAR, ins_buf); - headstage_update_instruction(ins_buf); - break; + case BLE_INS_BUFF_CHAR: + SimpleProfile_GetParameter(BLE_INS_BUFF_CHAR, ins_buf); + headstage_update_instruction(ins_buf); + break; #ifdef HEADSTAGE_DEBUG_H - case BLE_DEBUG_BUFF_CHAR: { - SimpleProfile_GetParameter(BLE_DEBUG_BUFF_CHAR, dbg_buf); + case BLE_DEBUG_BUFF_CHAR: { + SimpleProfile_GetParameter(BLE_DEBUG_BUFF_CHAR, dbg_buf); - uint8_t data_length = headstage_debug_instruction(dbg_buf); - if (data_length) { - SimpleProfile_SetParameter(BLE_DEBUG_BUFF_CHAR, data_length, dbg_buf); + uint8_t data_length = headstage_debug_instruction(dbg_buf); + if (data_length) { + SimpleProfile_SetParameter(BLE_DEBUG_BUFF_CHAR, data_length, dbg_buf); + } + break; } - break; - } #endif } } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_clock.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_clock.h index 2be5ee6b7..d350e27e0 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_clock.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_clock.h @@ -29,11 +29,12 @@ static void headstage_clock_callback(UArg arg) { } while (0) // XXX function not tested +// period in mini second #define headstage_clock_open(period) \ do { \ Clock_Params param; \ Clock_Params_init(¶m); \ - param.period = (period); \ + param.period = 48000*(period); \ param.startFlag = false; \ clock_handle = Clock_create(headstage_clock_callback, 1, ¶m, NULL); \ } while (0) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_led.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_led.h index 160acc44c..2c4fdbeb8 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_led.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_led.h @@ -149,7 +149,7 @@ static void headstage_led_open() { SPI_Params_init(&spi_parameter); spi_parameter.transferMode = SPI_MODE_BLOCKING; spi_parameter.mode = SPI_MASTER; - spi_parameter.bitRate = 1000000; + spi_parameter.bitRate = 2500; spi_parameter.dataSize = 16; spi_parameter.frameFormat = SPI_POL0_PHA1; diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_zm.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_zm.h index 3f3709428..0b42ffc80 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_zm.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_zm.h @@ -139,7 +139,6 @@ static void headstage_zm_switch(uint8_t hold); // clang-format on static void headstage_zm_event() { - uint16_t switch_state = (EVENT_MASK & EVT_SWITCH_MASK); if (flag_mask(EVT_PERIODIC_CLOCK)) { @@ -147,8 +146,8 @@ static void headstage_zm_event() { if (switch_state == SWITCH_HOLDING) { headstage_zm_switch(1); - - } else if (INSTRUCTION.headstage_zm_periodic) { + } + if (INSTRUCTION.headstage_zm_periodic) { INSTRUCTION.headstage_zm_periodic(); } } @@ -179,9 +178,9 @@ static void headstage_zm_event() { static void headstage_zm_pin_callback(PIN_Handle handle, PIN_Id pin) { switch (pin) { - case PIN_SWITCH_ON: - flag_notify(EVT_SWITCH_PRESSED); - break; + case PIN_SWITCH_ON: + flag_notify(SWITCH_PRESSED); + break; } } @@ -193,12 +192,12 @@ static void headstage_zm_pin_callback(PIN_Handle handle, PIN_Id pin) { ==== DAC function ==== =====================*/ -#define DAC_CMD_W_IN_REG 0x00 -#define DAC_CMD_W_DAC_REG 0x10 -#define DAC_CMD_WRITE_REG 0x30 -#define DAC_CMD_POWER_ON 0x40 -#define DAC_CMD_REF_INT 0x60 -#define DAC_CMD_REF_EXT 0x70 +#define DAC_CMD_W_IN_REG 0x00 +#define DAC_CMD_W_DAC_REG 0x10 +#define DAC_CMD_WRITE_REG 0x30 +#define DAC_CMD_POWER_ON 0x40 +#define DAC_CMD_REF_INT 0x60 +#define DAC_CMD_REF_EXT 0x70 static uint8_t build_dac_instruction(uint8_t* ins_buf, uint8_t command, uint8_t p1, uint8_t p2) { uint8_t* p = ins_buf; @@ -227,12 +226,12 @@ static void headstage_init() { headstage_led_open(); headstage_spi_open(); - PIN_registerIntCb(headstage_pins_handle, headstage_zm_pin_callback); + PIN_registerIntCb(headstage_pins_handle, &headstage_zm_pin_callback); PIN_setInterrupt(headstage_pins_handle, PIN_SWITCH_ON | PIN_IRQ_NEGEDGE); headstage_pin_output(PIN_SHUTDOWN_6994, 1); - headstage_pin_output(PIN_ENABLE_V10, 1); headstage_pin_output(PIN_ENABLE_V05, 1); + headstage_pin_output(PIN_ENABLE_V10, 1); headstage_pin_output(PIN_ADC_CS, 1); headstage_pin_output(PIN_DAC_CS, 1); @@ -251,60 +250,57 @@ static void headstage_zm_turn(uint8_t on_off) { } } -static void headstage_update_ris_instruction(uint8_t ins_len, uint8_t *instruction) { +static void headstage_update_ris_instruction(uint8_t ins_len, uint8_t* instruction) { uint8_t header = instruction[0] & 0xF0; switch (header) { - case RIS_MODE: - INSTRUCTION.mode = (INSTRUCTION.mode & 0xF0) | (instruction[1] & 0x0F); + case RIS_MODE: + INSTRUCTION.mode = (INSTRUCTION.mode & 0xF0) | (instruction[1] & 0x0F); - flag_notify(EVT_MODE_CHANGE); - break; + flag_notify(EVT_MODE_CHANGE); + break; - case RIS_ADC: - case RIS_DAC: - default: - break; + case RIS_ADC: + case RIS_DAC: + default: + break; } } static void headstage_update_vis_instruction(uint8_t vis_oper) { switch (vis_oper) { - case VIS_ASK: - case VIS_INT: - case VIS_FUH: - case VIS_CAL: - case VIS_STI: - case VIS_RST: + case VIS_ASK: + case VIS_INT: + case VIS_FUH: + case VIS_CAL: + case VIS_STI: + case VIS_RST: } } static void headstage_zm_switch(uint8_t hold) { static uint32_t time_stamp = 0; - bool shutdown = (INSTRUCTION.mode & MODE_READY) != 0; + bool working = (INSTRUCTION.mode & MODE_READY) != 0; if (!hold) { // button just pressed time_stamp = headstage_time_stamp_ms(); - if (headstage_clock_active()) { - headstage_clock_stop(); - headstage_clock_close(); + if (!headstage_clock_active()) { + // TODO clock period + headstage_clock_open(250); + headstage_clock_start(); } - // TODO clock period - headstage_clock_open(1); - headstage_clock_start(); - flag_disable(EVT_SWITCH_MASK); flag_enable(SWITCH_HOLDING); } else if (headstage_pin_input(PIN_SWITCH_ON)) { // button released - if (headstage_clock_active()) { + if (!working) { headstage_clock_stop(); headstage_clock_close(); } @@ -316,7 +312,7 @@ static void headstage_zm_switch(uint8_t hold) { uint32_t current = headstage_time_stamp_ms(); - if (current - time_stamp >= ((shutdown)?3000:1000)) { // 3 sec + if (current - time_stamp >= ((working) ? 3000 : 1000)) { // 3 sec headstage_clock_stop(); headstage_clock_close(); @@ -333,49 +329,45 @@ static void headstage_zm_switch(uint8_t hold) { static void headstage_zm_mode_init() { switch (INSTRUCTION.mode) { - case MODE_READY | MODE_IV: - headstage_led_color(COLOR_RED); + case MODE_READY | MODE_IV: + headstage_led_color(COLOR_RED); - INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_IV; - break; - case MODE_READY | MODE_CV: - headstage_led_color(COLOR_ORANGE); + INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_IV; + break; + case MODE_READY | MODE_CV: + headstage_led_color(COLOR_ORANGE); - INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_CV; - break; - case MODE_READY | MODE_GEN: - headstage_led_color(COLOR_YELLOW); + INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_CV; + break; + case MODE_READY | MODE_GEN: + headstage_led_color(COLOR_YELLOW); - INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_func_gen; - break; - case MODE_READY | MODE_ZT: - headstage_led_color(COLOR_GREEN); + INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_func_gen; + break; + case MODE_READY | MODE_ZT: + headstage_led_color(COLOR_GREEN); - INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_ZT; - break; - case MODE_READY | MODE_VT: - headstage_led_color(COLOR_BLUE); + INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_ZT; + break; + case MODE_READY | MODE_VT: + headstage_led_color(COLOR_BLUE); - INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_VT; - break; - case MODE_READY | MODE_IT: - headstage_led_color(COLOR_CYAN); + INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_VT; + break; + case MODE_READY | MODE_IT: + headstage_led_color(COLOR_CYAN); - INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_IT; - break; - default: - headstage_led_color(COLOR_BLACK); + INSTRUCTION.headstage_zm_periodic = &headstage_zm_mode_IT; + break; + default: + headstage_led_color(COLOR_BLACK); - INSTRUCTION.mode = MODE_READY; - INSTRUCTION.headstage_zm_periodic = NULL; - return; + INSTRUCTION.mode = MODE_READY; + INSTRUCTION.headstage_zm_periodic = NULL; + return; } - headstage_clock_open(/*XXX*/); -} - -static void headstage_zm_mode_init() { - // TODO + headstage_clock_open(500); } static void headstage_zm_mode_IV() { 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 470ba95bc..2adc02764 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 @@ -584,7 +584,7 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) { } } - if (event_mask > 0) { + if (EVENT_MASK > 0) { headstage_event_handle(); }