From e3e40d25e9031d5c073a090feeec65edc9961831 Mon Sep 17 00:00:00 2001 From: yichin Date: Tue, 28 May 2019 19:18:57 +0800 Subject: [PATCH] save --- python_test_code/sti/main.py | 8 ++--- .../cc26xx/app/headstage/headstage_sti.h | 29 ++++++++++++------- .../app/headstage/sti/headstage_notify.h | 27 ++++++++++++++++- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/python_test_code/sti/main.py b/python_test_code/sti/main.py index b0fcbd25e..faf5f5e67 100644 --- a/python_test_code/sti/main.py +++ b/python_test_code/sti/main.py @@ -4,10 +4,10 @@ from sti.util import * STI_PARAMETER_0 = { 'CURRENT': 10, # uA 'CHANNEL': CHANNEL_STI_0, - 'STI_MODE': STI_WAVEFORM_POS, + 'STI_MODE': STI_WAVEFORM_P2N, 'PRECISION': STI_PRECISION_10, 'STI_FREQ': 10, # Hz - 'STI_PW': 200, # us + 'STI_PW': 10, # us 'STI_PW_IPI': 10, # us 'STI_NUM': STI_NUM_INFINITE, } @@ -15,11 +15,11 @@ STI_PARAMETER_0 = { STI_PARAMETER_1 = { 'CURRENT': 10, # uA 'CHANNEL': CHANNEL_STI_1, - 'STI_MODE': STI_WAVEFORM_POS, + 'STI_MODE': STI_WAVEFORM_P2N, 'PRECISION': STI_PRECISION_10, 'STI_FREQ': 10, # Hz 'STI_PW': 200, # us - 'STI_PW_IPI': 10, # us + 'STI_PW_IPI': 100, # us 'STI_NUM': STI_NUM_INFINITE, } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_sti.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_sti.h index e0029c03c..ea4dd1e02 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_sti.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage_sti.h @@ -68,6 +68,7 @@ TODO #include "headstage_power.h" #include "headstage_pin.h" #include "headstage_notify.h" +#include "sti/headstage_notify.h" #include "sti/headstage_gptimer.h" #include "sti/headstage_pwm.h" @@ -87,7 +88,7 @@ static uint32_t cpu_frequency; #define headstage_gptimer_get_timeout_load_value(timeout_us) \ ({ \ - GPTimerCC26XX_Value _load = (timeout_us)*cpu_frequency / 1e6 - 1; \ + GPTimerCC26XX_Value _load = 5 * (timeout_us)*cpu_frequency / 1e6 - 1; \ (_load < 0xFFFF) ? _load : ((0xFA0000 | (_load / 250)) - 1); \ }) @@ -435,8 +436,8 @@ static void headstage_init() { ins[0] = 0x40; ins[1] = 0x40; ins[2] = 0x0A; - ins[3] = 0x05; - ins[4] = 0x00; + ins[3] = 0x02; + ins[4] = 0x80; ins[5] = 0xAF; ins[6] = 0xA0; headstage_update_ris_instruction(7, ins); @@ -1075,8 +1076,8 @@ static void headstage_sti_period_callback(NeuLiveStiChannelState *s) { } // stage 3 - headstage_sti_output_pol(s, 3); headstage_sti_output_pon(s, 3); + headstage_sti_output_pol(s, 3); exit: Hwi_restore(__key); @@ -1084,28 +1085,36 @@ exit: } static void headstage_sti_stepping_callback(NeuLiveStiChannelState *s) { - uint8_t stage = ++ (s->stage); + uint8 __key = Hwi_disable(); - headstage_sti_output_pol(s, stage); - headstage_sti_output_pon(s, stage); + uint8_t stage = ++ (s->stage); uint16_t timeout_us = s->timeout_us[stage]; while (stage < 3 && timeout_us != 0) { + + headstage_sti_output_pol(s, stage); + headstage_sti_output_pon(s, stage); + if (timeout_us <= LIMIT_TIMEOUT_US) { // use cpu delay instead headstage_spin_delay(get_spin_timeout_value(timeout_us - 2)); stage = ++ (s->stage); - headstage_sti_output_pol(s, stage); - headstage_sti_output_pon(s, stage); timeout_us = s->timeout_us[stage]; } else { headstage_gptimer_set_timeout(s->step_handle, timeout_us); headstage_gptimer_start(s->step_handle); - return; + goto exit; } } + +exit: + + headstage_sti_output_pon(s, stage); + headstage_sti_output_pol(s, stage); + + Hwi_restore(__key); } /*======================== diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/sti/headstage_notify.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/sti/headstage_notify.h index 0f04af6ba..f156d41bd 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/sti/headstage_notify.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/sti/headstage_notify.h @@ -1,6 +1,26 @@ /* Copyright (c) 2019. BioPro. Scientific. */ +/* + +notify data format +================== + +struct { + uint8_t device_id; + uint8_t data_length; + uint32_t cpu_timestamp; + uint8_t battery_channel :4; + uint16_t battery_voltage :12; + uint8_t sti_channel :4; + uint16_t sti_channel_voltage :12; + uint16_t sti_remind_times; + uint8_t sti_channel :4; + uint16_t sti_channel_voltage :12; + uint16_t sti_remind_times; +} + + */ #ifndef HEADSTAGE_NOTIFY_TDC4VC3_H #define HEADSTAGE_NOTIFY_TDC4VC3_H @@ -31,7 +51,7 @@ static void headstage_notify_flip_buffer() { not_buf_offset = NOT_BUF_OFFSET_INIT; } -static uint8_t headstage_notify_append_data(uint8_t channel, uint16_t data_value) { +static uint8_t headstage_notify_append_data(uint8_t channel, uint16_t data_value, uint16_t times_remind) { if (not_buf_offset <= NOT_BUF_OFFSET_INIT) { headstage_notify_set_timestamp(); @@ -45,6 +65,11 @@ static uint8_t headstage_notify_append_data(uint8_t channel, uint16_t data_value headstage_notify_buffer[not_buf_offset++] = ((channel & 0x0F) << 4) | ((data_value >> 8) & 0x0F); headstage_notify_buffer[not_buf_offset++] = (data_value & 0xFF); + if (channel != 0) { + headstage_notify_buffer[not_buf_offset++] = ((times_remind >> 8) & 0xFF); + headstage_notify_buffer[not_buf_offset++] = (times_remind & 0xFF); + } + uint8_t ret = not_buf_offset; if (not_buf_offset >= BLE_NOT_BUFF_SIZE) {