BLE TX pending queue 확장 및 ADC 패킷 재시도 처리, Ver116 업데이트
- BLE TX pending slot을 1개에서 8개로 확장 - dr_binary_tx_safe()에서 TX 결과 반환 - maa_async TX 실패 시 상태 유지 후 TX ready에서 재시도
This commit is contained in:
@@ -29,7 +29,7 @@ extern uint8_t ble_bin_buffer[];
|
|||||||
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
||||||
extern void ascii_format_data(uint8_t *buffer, const char *tag, const char *ascii, size_t length);
|
extern void ascii_format_data(uint8_t *buffer, const char *tag, const char *ascii, size_t length);
|
||||||
extern void format_data(uint8_t *buffer, const char *tag, const uint16_t *data_array, size_t length);
|
extern void format_data(uint8_t *buffer, const char *tag, const uint16_t *data_array, size_t length);
|
||||||
extern void dr_binary_tx_safe(const uint8_t *buffer, uint16_t length); /* length: word count */
|
extern uint32_t dr_binary_tx_safe(const uint8_t *buffer, uint16_t length); /* length: word count */
|
||||||
extern void dr_sd_delay_ms(uint32_t ms);
|
extern void dr_sd_delay_ms(uint32_t ms);
|
||||||
extern volatile bool data_tx_in_progress;
|
extern volatile bool data_tx_in_progress;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
||||||
extern void format_data(uint8_t *buffer, const char *tag, uint16_t *data, uint8_t length);
|
extern void format_data(uint8_t *buffer, const char *tag, uint16_t *data, uint8_t length);
|
||||||
extern uint8_t ble_bin_buffer[];
|
extern uint8_t ble_bin_buffer[];
|
||||||
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
extern uint32_t dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||||
|
|
||||||
void dr_ble_return_1(const char *tag, uint16_t value)
|
void dr_ble_return_1(const char *tag, uint16_t value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*log)(const char *fmt, ...);
|
void (*log)(const char *fmt, ...);
|
||||||
void (*tx_bin)(const uint8_t *buf, uint16_t len); /* len: word (uint16) count */
|
uint32_t (*tx_bin)(const uint8_t *buf, uint16_t len); /* len: word (uint16) count */
|
||||||
bool crc_check;
|
bool crc_check;
|
||||||
} dr_platform_if_t;
|
} dr_platform_if_t;
|
||||||
|
|
||||||
|
|||||||
@@ -229,9 +229,12 @@ volatile bool ble_connection_st; /* BLE connection state (1=co
|
|||||||
volatile bool data_tx_in_progress = false; /* Binary TX in progress flag */
|
volatile bool data_tx_in_progress = false; /* Binary TX in progress flag */
|
||||||
|
|
||||||
/* -- BLE TX async retry state -- */
|
/* -- BLE TX async retry state -- */
|
||||||
static volatile bool s_tx_pending = false; /* TX retry pending */
|
#define BLE_TX_PENDING_QUEUE_SIZE 8U
|
||||||
static uint8_t s_tx_pending_buf[BLE_NUS_MAX_DATA_LEN] = {0}; /* Pending packet (with CRC) */
|
static uint8_t s_tx_pending_buf[BLE_TX_PENDING_QUEUE_SIZE][BLE_NUS_MAX_DATA_LEN] = {{0}}; /* Pending packets (with CRC) */
|
||||||
static uint16_t s_tx_pending_len = 0; /* Pending packet length */
|
static uint16_t s_tx_pending_len[BLE_TX_PENDING_QUEUE_SIZE] = {0}; /* Pending packet lengths */
|
||||||
|
static volatile uint8_t s_tx_pending_head = 0; /* Next packet to retry */
|
||||||
|
static volatile uint8_t s_tx_pending_tail = 0; /* Next enqueue slot */
|
||||||
|
static volatile uint8_t s_tx_pending_count = 0; /* Queued packet count */
|
||||||
|
|
||||||
char m_static_passkey[PASSKEY_LENGTH] = DEFAULT_PASSKEY; /* Static passkey (6 digits, loaded from FDS) */
|
char m_static_passkey[PASSKEY_LENGTH] = DEFAULT_PASSKEY; /* Static passkey (6 digits, loaded from FDS) */
|
||||||
char SERIAL_NO[SERIAL_NO_LENGTH] = {0}; /* Serial number (used as BLE device name) */
|
char SERIAL_NO[SERIAL_NO_LENGTH] = {0}; /* Serial number (used as BLE device name) */
|
||||||
@@ -562,47 +565,88 @@ extern void maa_async_abort(void);
|
|||||||
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN] = {0};
|
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN] = {0};
|
||||||
static volatile uint8_t pending_cmd_len = 0;
|
static volatile uint8_t pending_cmd_len = 0;
|
||||||
|
|
||||||
|
static bool ble_tx_pending_has_data(void)
|
||||||
|
{
|
||||||
|
return (s_tx_pending_count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_tx_pending_clear(void)
|
||||||
|
{
|
||||||
|
s_tx_pending_head = 0;
|
||||||
|
s_tx_pending_tail = 0;
|
||||||
|
s_tx_pending_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ble_tx_pending_enqueue(uint8_t const *p_data, uint16_t len)
|
||||||
|
{
|
||||||
|
if (s_tx_pending_count >= BLE_TX_PENDING_QUEUE_SIZE)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(s_tx_pending_buf[s_tx_pending_tail], p_data, len);
|
||||||
|
s_tx_pending_len[s_tx_pending_tail] = len;
|
||||||
|
s_tx_pending_tail = (uint8_t)((s_tx_pending_tail + 1U) % BLE_TX_PENDING_QUEUE_SIZE);
|
||||||
|
s_tx_pending_count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_tx_pending_pop(void)
|
||||||
|
{
|
||||||
|
if (s_tx_pending_count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_tx_pending_len[s_tx_pending_head] = 0;
|
||||||
|
s_tx_pending_head = (uint8_t)((s_tx_pending_head + 1U) % BLE_TX_PENDING_QUEUE_SIZE);
|
||||||
|
s_tx_pending_count--;
|
||||||
|
}
|
||||||
|
|
||||||
static bool ble_retry_pending_tx(void)
|
static bool ble_retry_pending_tx(void)
|
||||||
{
|
{
|
||||||
uint16_t send_len;
|
uint16_t send_len;
|
||||||
uint32_t err;
|
uint32_t err;
|
||||||
|
bool freed_slot = false;
|
||||||
|
|
||||||
if (!s_tx_pending)
|
if (!ble_tx_pending_has_data())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (ble_connection_st != BLE_CONNECTED_ST)
|
if (ble_connection_st != BLE_CONNECTED_ST)
|
||||||
{
|
{
|
||||||
s_tx_pending = false;
|
ble_tx_pending_clear();
|
||||||
s_tx_pending_len = 0;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_len = s_tx_pending_len;
|
while (ble_tx_pending_has_data())
|
||||||
err = ble_nus_data_send(&m_nus, s_tx_pending_buf, &send_len, m_conn_handle);
|
{
|
||||||
|
send_len = s_tx_pending_len[s_tx_pending_head];
|
||||||
|
err = ble_nus_data_send(&m_nus, s_tx_pending_buf[s_tx_pending_head], &send_len, m_conn_handle);
|
||||||
|
|
||||||
if (err == NRF_SUCCESS)
|
if (err == NRF_SUCCESS)
|
||||||
{
|
{
|
||||||
s_tx_pending = false;
|
ble_tx_pending_pop();
|
||||||
s_tx_pending_len = 0;
|
freed_slot = true;
|
||||||
return true;
|
continue;
|
||||||
}
|
}
|
||||||
if (err == NRF_ERROR_RESOURCES)
|
if (err == NRF_ERROR_RESOURCES)
|
||||||
{
|
{
|
||||||
return false;
|
return freed_slot;
|
||||||
}
|
}
|
||||||
if (err == NRF_ERROR_INVALID_STATE || err == NRF_ERROR_NOT_FOUND)
|
if (err == NRF_ERROR_INVALID_STATE || err == NRF_ERROR_NOT_FOUND)
|
||||||
{
|
{
|
||||||
DBG_PRINTF("[BLE TX] Pending send aborted\r\n");
|
DBG_PRINTF("[BLE TX] Pending send aborted\r\n");
|
||||||
s_tx_pending = false;
|
ble_tx_pending_clear();
|
||||||
s_tx_pending_len = 0;
|
return false;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
DBG_PRINTF("[BLE TX] Pending err:0x%X\r\n", err);
|
||||||
|
ble_tx_pending_pop();
|
||||||
|
freed_slot = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG_PRINTF("[BLE TX] Pending err:0x%X\r\n", err);
|
return true;
|
||||||
s_tx_pending = false;
|
|
||||||
s_tx_pending_len = 0;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -652,7 +696,7 @@ static void nus_data_handler(ble_nus_evt_t * p_evt)
|
|||||||
else if (p_evt->type == BLE_NUS_EVT_TX_RDY)
|
else if (p_evt->type == BLE_NUS_EVT_TX_RDY)
|
||||||
{
|
{
|
||||||
/* First drain any queued packet that previously hit NRF_ERROR_RESOURCES. */
|
/* First drain any queued packet that previously hit NRF_ERROR_RESOURCES. */
|
||||||
if (s_tx_pending)
|
if (ble_tx_pending_has_data())
|
||||||
{
|
{
|
||||||
if (!ble_retry_pending_tx())
|
if (!ble_retry_pending_tx())
|
||||||
{
|
{
|
||||||
@@ -1072,7 +1116,7 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
|
|||||||
m_tx_in_progress = false;
|
m_tx_in_progress = false;
|
||||||
|
|
||||||
maa_async_abort(); // Prevent hang caused by async measurement state
|
maa_async_abort(); // Prevent hang caused by async measurement state
|
||||||
s_tx_pending = false; // Clear pending TX
|
ble_tx_pending_clear(); // Clear pending TX
|
||||||
|
|
||||||
/* Adjust advertising duration at runtime based on disconnect reason */
|
/* Adjust advertising duration at runtime based on disconnect reason */
|
||||||
(void)sd_ble_gap_adv_stop(m_advertising.adv_handle);
|
(void)sd_ble_gap_adv_stop(m_advertising.adv_handle);
|
||||||
@@ -1554,16 +1598,16 @@ void param_error(const char *cmd)
|
|||||||
dr_binary_tx_safe(ble_bin_buffer, 3);
|
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length)
|
uint32_t dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length)
|
||||||
{
|
{
|
||||||
uint32_t err_code;
|
uint32_t err_code;
|
||||||
static uint8_t tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0};
|
static uint8_t tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0};
|
||||||
uint16_t send_len;
|
uint16_t send_len;
|
||||||
uint16_t total_len;
|
uint16_t total_len;
|
||||||
|
|
||||||
if (ble_connection_st == 0) return;
|
if (ble_connection_st == 0) return NRF_ERROR_INVALID_STATE;
|
||||||
|
|
||||||
if (length * sizeof(uint16_t) > (BLE_NUS_MAX_DATA_LEN - 2)) return;
|
if (length * sizeof(uint16_t) > (BLE_NUS_MAX_DATA_LEN - 2)) return NRF_ERROR_DATA_SIZE;
|
||||||
|
|
||||||
if (ble_connection_st == BLE_CONNECTED_ST)
|
if (ble_connection_st == BLE_CONNECTED_ST)
|
||||||
{
|
{
|
||||||
@@ -1573,37 +1617,48 @@ void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length)
|
|||||||
tx_buffer[length * sizeof(uint16_t) + 1] = (uint8_t)((crc >> 8) & 0xFF);
|
tx_buffer[length * sizeof(uint16_t) + 1] = (uint8_t)((crc >> 8) & 0xFF);
|
||||||
|
|
||||||
total_len = length * sizeof(uint16_t) + 2;
|
total_len = length * sizeof(uint16_t) + 2;
|
||||||
|
|
||||||
|
if (ble_tx_pending_has_data())
|
||||||
|
{
|
||||||
|
if (!ble_tx_pending_enqueue(tx_buffer, total_len))
|
||||||
|
{
|
||||||
|
DBG_PRINTF("[BLE TX] Pending queue full, dropping new packet\r\n");
|
||||||
|
return NRF_ERROR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NRF_ERROR_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
send_len = total_len;
|
send_len = total_len;
|
||||||
err_code = ble_nus_data_send(&m_nus, tx_buffer, &send_len, m_conn_handle);
|
err_code = ble_nus_data_send(&m_nus, tx_buffer, &send_len, m_conn_handle);
|
||||||
|
|
||||||
if (err_code == NRF_SUCCESS)
|
if (err_code == NRF_SUCCESS)
|
||||||
{
|
{
|
||||||
return;
|
return NRF_SUCCESS;
|
||||||
}
|
}
|
||||||
else if (err_code == NRF_ERROR_RESOURCES)
|
else if (err_code == NRF_ERROR_RESOURCES)
|
||||||
{
|
{
|
||||||
if (s_tx_pending)
|
if (!ble_tx_pending_enqueue(tx_buffer, total_len))
|
||||||
{
|
{
|
||||||
DBG_PRINTF("[BLE TX] Pending queue busy, dropping new packet\r\n");
|
DBG_PRINTF("[BLE TX] Pending queue full, dropping new packet\r\n");
|
||||||
return;
|
return NRF_ERROR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(s_tx_pending_buf, tx_buffer, total_len);
|
return NRF_ERROR_RESOURCES;
|
||||||
s_tx_pending_len = total_len;
|
|
||||||
s_tx_pending = true;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (err_code == NRF_ERROR_INVALID_STATE || err_code == NRF_ERROR_NOT_FOUND)
|
else if (err_code == NRF_ERROR_INVALID_STATE || err_code == NRF_ERROR_NOT_FOUND)
|
||||||
{
|
{
|
||||||
DBG_PRINTF("[BLE TX] Disconnected\r\n");
|
DBG_PRINTF("[BLE TX] Disconnected\r\n");
|
||||||
return;
|
return err_code;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DBG_PRINTF("[BLE TX] Err:0x%X\r\n", err_code);
|
DBG_PRINTF("[BLE TX] Err:0x%X\r\n", err_code);
|
||||||
return;
|
return err_code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NRF_ERROR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
|
|||||||
@@ -43,8 +43,9 @@
|
|||||||
* - VBTFW0115 260518 jhChun
|
* - VBTFW0115 260518 jhChun
|
||||||
* : Added mtb? command (reb:+raa:+rim:, 6ch piezo + ICM42670 FIFO at 25 Hz).
|
* : Added mtb? command (reb:+raa:+rim:, 6ch piezo + ICM42670 FIFO at 25 Hz).
|
||||||
* : rim: packet format and FIFO sample cap/filter options (app_raw).
|
* : rim: packet format and FIFO sample cap/filter options (app_raw).
|
||||||
|
* - VBTFW0116 260522 jhChun : Expanded BLE TX pending slots from 1 → 8 to reduce ADC data packet loss when the TX queue is full
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
#define FIRMWARE_VERSION "VBTFW0115"
|
#define FIRMWARE_VERSION "VBTFW0116"
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* Data Length Constants
|
* Data Length Constants
|
||||||
@@ -141,7 +142,7 @@ void data_tx_handler(char const *p_data_to_send);
|
|||||||
/* Safe binary data BLE transmission (CRC16 appended, with retry logic)
|
/* Safe binary data BLE transmission (CRC16 appended, with retry logic)
|
||||||
* @param ble_bin_buff Binary buffer to transmit
|
* @param ble_bin_buff Binary buffer to transmit
|
||||||
* @param length Data length in uint16_t words (actual bytes = length x 2) */
|
* @param length Data length in uint16_t words (actual bytes = length x 2) */
|
||||||
void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
uint32_t dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||||
|
|
||||||
/* SoftDevice-compatible delay (nrf_delay_ms wrapper) */
|
/* SoftDevice-compatible delay (nrf_delay_ms wrapper) */
|
||||||
void dr_sd_delay_ms(uint32_t ms);
|
void dr_sd_delay_ms(uint32_t ms);
|
||||||
|
|||||||
+60
-19
@@ -605,7 +605,7 @@ uint32_t dr_adc_get_vref(void)
|
|||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
|
|
||||||
/* External BLE NUS functions and variables from main.c */
|
/* External BLE NUS functions and variables from main.c */
|
||||||
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
extern uint32_t dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||||
extern void dr_sd_delay_ms(uint32_t ms);
|
extern void dr_sd_delay_ms(uint32_t ms);
|
||||||
|
|
||||||
/* Platform interface (log function) */
|
/* Platform interface (log function) */
|
||||||
@@ -1163,6 +1163,17 @@ static maa_async_ctx_t g_maa_ctx = { .state = MAA_ASYNC_IDLE };
|
|||||||
|
|
||||||
/* (reb+red merged protocol) */
|
/* (reb+red merged protocol) */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
MAA_ASYNC_TX_RETRY = 0,
|
||||||
|
MAA_ASYNC_TX_DONE,
|
||||||
|
MAA_ASYNC_TX_MORE
|
||||||
|
} maa_async_tx_result_t;
|
||||||
|
|
||||||
|
static bool maa_async_tx_accepted(uint32_t err_code)
|
||||||
|
{
|
||||||
|
return (err_code == NRF_SUCCESS || err_code == NRF_ERROR_RESOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Capture one channel (internal helper)
|
* @brief Capture one channel (internal helper)
|
||||||
*/
|
*/
|
||||||
@@ -1192,10 +1203,11 @@ static dr_adc_err_t maa_async_capture_channel(uint8_t ch)
|
|||||||
* reb: tag(4) + num_samples(2) + data(up to 238 bytes)
|
* reb: tag(4) + num_samples(2) + data(up to 238 bytes)
|
||||||
* If <= 100 samples (200B), the channel completes in this single packet
|
* If <= 100 samples (200B), the channel completes in this single packet
|
||||||
*/
|
*/
|
||||||
static void maa_async_send_header(void)
|
static bool maa_async_send_header(void)
|
||||||
{
|
{
|
||||||
dr_maa_channel_t *ch = &g_maa_ctx.channels[g_maa_ctx.current_ch];
|
dr_maa_channel_t *ch = &g_maa_ctx.channels[g_maa_ctx.current_ch];
|
||||||
uint8_t *buf = g_maa_ctx.ble_buffer;
|
uint8_t *buf = g_maa_ctx.ble_buffer;
|
||||||
|
uint32_t tx_err;
|
||||||
|
|
||||||
uint16_t total_data_bytes = ch->num_samples * 2;
|
uint16_t total_data_bytes = ch->num_samples * 2;
|
||||||
|
|
||||||
@@ -1214,7 +1226,12 @@ static void maa_async_send_header(void)
|
|||||||
buf[dst_idx++] = (uint8_t)(sample & 0xFF);
|
buf[dst_idx++] = (uint8_t)(sample & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
dr_binary_tx_safe(buf, dst_idx / 2);
|
tx_err = dr_binary_tx_safe(buf, dst_idx / 2);
|
||||||
|
if (!maa_async_tx_accepted(tx_err))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
dr_sd_delay_ms(MAA_ASYNC_POST_REB_MS);
|
dr_sd_delay_ms(MAA_ASYNC_POST_REB_MS);
|
||||||
|
|
||||||
g_maa_ctx.current_pkt = 0;
|
g_maa_ctx.current_pkt = 0;
|
||||||
@@ -1229,21 +1246,24 @@ static void maa_async_send_header(void)
|
|||||||
{
|
{
|
||||||
g_maa_ctx.state = MAA_ASYNC_TX_DATA;
|
g_maa_ctx.state = MAA_ASYNC_TX_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send next red: data packet
|
* @brief Send next red: data packet
|
||||||
* @return true if more packets to send, false if done with current channel
|
* @return TX result: retry, current channel done, or more packets remain
|
||||||
*/
|
*/
|
||||||
static bool maa_async_send_data_packet(void)
|
static maa_async_tx_result_t maa_async_send_data_packet(void)
|
||||||
{
|
{
|
||||||
dr_maa_channel_t *ch = &g_maa_ctx.channels[g_maa_ctx.current_ch];
|
dr_maa_channel_t *ch = &g_maa_ctx.channels[g_maa_ctx.current_ch];
|
||||||
uint8_t *buf = g_maa_ctx.ble_buffer;
|
uint8_t *buf = g_maa_ctx.ble_buffer;
|
||||||
uint16_t total_data_bytes = ch->num_samples * 2;
|
uint16_t total_data_bytes = ch->num_samples * 2;
|
||||||
|
uint32_t tx_err;
|
||||||
|
|
||||||
if (g_maa_ctx.data_offset >= total_data_bytes)
|
if (g_maa_ctx.data_offset >= total_data_bytes)
|
||||||
{
|
{
|
||||||
return false; /* All data sent */
|
return MAA_ASYNC_TX_DONE; /* All data sent */
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t pkt_idx = g_maa_ctx.current_pkt;
|
uint16_t pkt_idx = g_maa_ctx.current_pkt;
|
||||||
@@ -1265,7 +1285,12 @@ static bool maa_async_send_data_packet(void)
|
|||||||
buf[dst_idx++] = (uint8_t)(sample & 0xFF);
|
buf[dst_idx++] = (uint8_t)(sample & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
dr_binary_tx_safe(buf, dst_idx / 2);
|
tx_err = dr_binary_tx_safe(buf, dst_idx / 2);
|
||||||
|
if (!maa_async_tx_accepted(tx_err))
|
||||||
|
{
|
||||||
|
return MAA_ASYNC_TX_RETRY;
|
||||||
|
}
|
||||||
|
|
||||||
dr_sd_delay_ms(MAA_ASYNC_POST_RED_MS);
|
dr_sd_delay_ms(MAA_ASYNC_POST_RED_MS);
|
||||||
|
|
||||||
g_maa_ctx.data_offset += chunk_size;
|
g_maa_ctx.data_offset += chunk_size;
|
||||||
@@ -1273,15 +1298,16 @@ static bool maa_async_send_data_packet(void)
|
|||||||
|
|
||||||
//ADC_LOG("maa_async: CH%u red:%u (%u/%u bytes)", g_maa_ctx.current_ch, pkt_idx, g_maa_ctx.data_offset, total_data_bytes);
|
//ADC_LOG("maa_async: CH%u red:%u (%u/%u bytes)", g_maa_ctx.current_ch, pkt_idx, g_maa_ctx.data_offset, total_data_bytes);
|
||||||
|
|
||||||
return (g_maa_ctx.data_offset < total_data_bytes);
|
return (g_maa_ctx.data_offset < total_data_bytes) ? MAA_ASYNC_TX_MORE : MAA_ASYNC_TX_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send raa: completion marker
|
* @brief Send raa: completion marker
|
||||||
*/
|
*/
|
||||||
static void maa_async_send_completion(uint16_t status)
|
static bool maa_async_send_completion(uint16_t status)
|
||||||
{
|
{
|
||||||
uint8_t *buf = g_maa_ctx.ble_buffer;
|
uint8_t *buf = g_maa_ctx.ble_buffer;
|
||||||
|
uint32_t tx_err;
|
||||||
|
|
||||||
/* Wait for previous TX to complete before sending raa: */
|
/* Wait for previous TX to complete before sending raa: */
|
||||||
dr_sd_delay_ms(MAA_ASYNC_PRE_RAA_MS);
|
dr_sd_delay_ms(MAA_ASYNC_PRE_RAA_MS);
|
||||||
@@ -1290,7 +1316,11 @@ static void maa_async_send_completion(uint16_t status)
|
|||||||
buf[4] = (uint8_t)(status >> 8);
|
buf[4] = (uint8_t)(status >> 8);
|
||||||
buf[5] = (uint8_t)(status & 0xFF);
|
buf[5] = (uint8_t)(status & 0xFF);
|
||||||
|
|
||||||
dr_binary_tx_safe(buf, 3);
|
tx_err = dr_binary_tx_safe(buf, 3);
|
||||||
|
if (!maa_async_tx_accepted(tx_err))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//if (g_plat.log) g_plat.log("-------------------------------------------------------------------------------------\r\n");
|
//if (g_plat.log) g_plat.log("-------------------------------------------------------------------------------------\r\n");
|
||||||
|
|
||||||
@@ -1307,6 +1337,8 @@ static void maa_async_send_completion(uint16_t status)
|
|||||||
g_maa_ctx.on_complete_cb = NULL; /* one-shot: prevent re-entry */
|
g_maa_ctx.on_complete_cb = NULL; /* one-shot: prevent re-entry */
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
@@ -1397,7 +1429,8 @@ dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us, uint16_t nu
|
|||||||
dr_piezo_power_off();
|
dr_piezo_power_off();
|
||||||
|
|
||||||
/* Send CH0 header - this will trigger TX_RDY for subsequent packets */
|
/* Send CH0 header - this will trigger TX_RDY for subsequent packets */
|
||||||
maa_async_send_header();
|
g_maa_ctx.state = MAA_ASYNC_TX_HEADER;
|
||||||
|
(void)maa_async_send_header();
|
||||||
|
|
||||||
return DR_ADC_OK;
|
return DR_ADC_OK;
|
||||||
}
|
}
|
||||||
@@ -1412,8 +1445,16 @@ bool maa_async_on_tx_ready(void)
|
|||||||
switch (g_maa_ctx.state)
|
switch (g_maa_ctx.state)
|
||||||
{
|
{
|
||||||
case MAA_ASYNC_TX_DATA:
|
case MAA_ASYNC_TX_DATA:
|
||||||
|
{
|
||||||
|
maa_async_tx_result_t tx_result;
|
||||||
|
|
||||||
/* Send next data packet */
|
/* Send next data packet */
|
||||||
if (!maa_async_send_data_packet())
|
tx_result = maa_async_send_data_packet();
|
||||||
|
if (tx_result == MAA_ASYNC_TX_RETRY)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (tx_result == MAA_ASYNC_TX_DONE)
|
||||||
{
|
{
|
||||||
/* Current channel done, move to next */
|
/* Current channel done, move to next */
|
||||||
g_maa_ctx.current_ch++;
|
g_maa_ctx.current_ch++;
|
||||||
@@ -1422,22 +1463,20 @@ bool maa_async_on_tx_ready(void)
|
|||||||
{
|
{
|
||||||
/* All channels done */
|
/* All channels done */
|
||||||
g_maa_ctx.state = MAA_ASYNC_COMPLETE;
|
g_maa_ctx.state = MAA_ASYNC_COMPLETE;
|
||||||
maa_async_send_completion(0x0000);
|
return maa_async_send_completion(0x0000) ? false : true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* all channels already captured, send header directly */
|
/* all channels already captured, send header directly */
|
||||||
g_maa_ctx.state = MAA_ASYNC_CAPTURING;
|
g_maa_ctx.state = MAA_ASYNC_TX_HEADER;
|
||||||
maa_async_send_header();
|
(void)maa_async_send_header();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case MAA_ASYNC_TX_HEADER:
|
case MAA_ASYNC_TX_HEADER:
|
||||||
/* Header sent, start sending data */
|
(void)maa_async_send_header();
|
||||||
g_maa_ctx.state = MAA_ASYNC_TX_DATA;
|
|
||||||
maa_async_send_data_packet();
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case MAA_ASYNC_CAPTURING:
|
case MAA_ASYNC_CAPTURING:
|
||||||
@@ -1445,6 +1484,8 @@ bool maa_async_on_tx_ready(void)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case MAA_ASYNC_COMPLETE:
|
case MAA_ASYNC_COMPLETE:
|
||||||
|
return maa_async_send_completion(0x0000) ? false : true;
|
||||||
|
|
||||||
case MAA_ASYNC_IDLE:
|
case MAA_ASYNC_IDLE:
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+1
-1
@@ -1156,7 +1156,7 @@
|
|||||||
<GroupNumber>1</GroupNumber>
|
<GroupNumber>1</GroupNumber>
|
||||||
<FileNumber>1</FileNumber>
|
<FileNumber>1</FileNumber>
|
||||||
<FileType>1</FileType>
|
<FileType>1</FileType>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<bDave2>0</bDave2>
|
<bDave2>0</bDave2>
|
||||||
<PathWithFileName>..\..\..\main.c</PathWithFileName>
|
<PathWithFileName>..\..\..\main.c</PathWithFileName>
|
||||||
|
|||||||
Reference in New Issue
Block a user