Skip to content

Commit 5f3ac91

Browse files
author
Zhou Xiao
committed
change(ble): upgraded spi log frame header
1 parent 6e38464 commit 5f3ac91

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

components/bt/common/ble_log/ble_log_spi_out.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
#define BLE_LOG_TAG "BLE_LOG"
4242
#define SPI_OUT_BUS SPI2_HOST
4343
#define SPI_OUT_MAX_TRANSFER_SIZE (10240)
44-
#define SPI_OUT_FRAME_HEAD_LEN (4)
45-
#define SPI_OUT_FRAME_TAIL_LEN (4)
46-
#define SPI_OUT_FRAME_OVERHEAD (8)
47-
#define SPI_OUT_PACKET_LOSS_FRAME_SIZE (6)
4844
#define SPI_OUT_TRANS_ITVL_MIN_US (30)
4945
#define SPI_OUT_LOG_STR_BUF_SIZE (100)
5046
#define SPI_OUT_MALLOC(size) heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
@@ -108,10 +104,10 @@ typedef struct {
108104
typedef struct {
109105
spi_out_trans_cb_t *trans_cb[2];
110106
uint8_t trans_cb_idx;
111-
uint8_t frame_sn;
107+
uint8_t type;
112108
uint16_t lost_frame_cnt;
113109
uint32_t lost_bytes_cnt;
114-
uint8_t type;
110+
uint32_t frame_sn;
115111
} spi_out_log_cb_t;
116112

117113
typedef struct {
@@ -123,7 +119,8 @@ typedef struct {
123119
typedef struct {
124120
uint16_t length;
125121
uint8_t source;
126-
uint8_t frame_sn;
122+
uint8_t type;
123+
uint16_t frame_sn;
127124
} __attribute__((packed)) frame_head_t;
128125

129126
typedef struct {
@@ -404,6 +401,12 @@ DECLARE_LOG_MODULE(mesh, LOG_CB_TYPE_MESH, SPI_OUT_MESH_BUF_SIZE,
404401
SPI_OUT_MESH_TASK_CNT, 0, 1)
405402
#endif // SPI_OUT_MESH_ENABLED
406403

404+
// Private macros
405+
#define SPI_OUT_FRAME_HEAD_LEN (sizeof(frame_head_t))
406+
#define SPI_OUT_FRAME_TAIL_LEN (sizeof(uint32_t))
407+
#define SPI_OUT_FRAME_OVERHEAD (SPI_OUT_FRAME_HEAD_LEN + SPI_OUT_FRAME_TAIL_LEN)
408+
#define SPI_OUT_GET_FRAME_SN(VAR) __atomic_fetch_add(VAR, 1, __ATOMIC_RELAXED)
409+
407410
// Private functions
408411
static int spi_out_init_trans(spi_out_trans_cb_t **trans_cb, uint16_t buf_size)
409412
{
@@ -546,7 +549,6 @@ IRAM_ATTR static inline bool spi_out_log_cb_check_trans(spi_out_log_cb_t *log_cb
546549
failed:
547550
log_cb->lost_bytes_cnt += frame_len;
548551
log_cb->lost_frame_cnt++;
549-
log_cb->frame_sn++;
550552
return false;
551553
}
552554

@@ -587,27 +589,23 @@ IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8
587589
frame_head_t head = {
588590
.length = total_length,
589591
.source = source,
590-
.frame_sn = log_cb->frame_sn,
592+
.type = log_cb->type,
593+
.frame_sn = SPI_OUT_GET_FRAME_SN(&(log_cb->frame_sn)) & 0xFFFF,
591594
};
592-
uint32_t checksum = 0;
593-
if (with_checksum) {
594-
for (int i = 0; i < len; i++) {
595-
checksum += addr[i];
596-
}
597-
for (int i = 0; i < len_append; i++) {
598-
checksum += addr_append[i];
599-
}
600-
}
601595

602596
memcpy(buf, (const uint8_t *)&head, SPI_OUT_FRAME_HEAD_LEN);
603597
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN, addr, len);
604598
if (len_append && addr_append) {
605599
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
606600
}
601+
602+
uint32_t checksum = 0;
603+
for (int i = 0; i < SPI_OUT_FRAME_HEAD_LEN + total_length; i++) {
604+
checksum += buf[i];
605+
}
607606
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + total_length, &checksum, SPI_OUT_FRAME_TAIL_LEN);
608607

609608
trans_cb->length += total_length + SPI_OUT_FRAME_OVERHEAD;
610-
log_cb->frame_sn++;
611609
if ((trans_cb->buf_size - trans_cb->length) <= SPI_OUT_FRAME_OVERHEAD) {
612610
trans_cb->flag = TRANS_CB_FLAG_NEED_QUEUE;
613611
return true;

0 commit comments

Comments
 (0)