Skip to content

Commit 5914592

Browse files
Ryan-CW-Codehydevcode
authored andcommitted
[components][serial_v2] 使用spinlock替换中断,对部分结构体变量使用原子操作
1 parent 80c40e6 commit 5914592

File tree

2 files changed

+81
-71
lines changed

2 files changed

+81
-71
lines changed

components/drivers/include/drivers/dev_serial_v2.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
#define __DEV_SERIAL_V2_H__
1313

1414
#include <rtthread.h>
15-
16-
15+
#include <rtdevice.h>
1716
/**
1817
* @addtogroup group_Drivers RTTHREAD Driver
1918
* @defgroup group_Serial_v2 Serial v2
@@ -193,7 +192,7 @@
193192
*/
194193
#define RT_HW_SERIAL_CTRL_GETC 0x01 /* Tx irq get char */
195194
#define RT_HW_SERIAL_CTRL_PUTC 0x02 /* Rx irq put char */
196-
#define RT_HW_SERIAL_CTRL_GET_DMA_PING_BUF 0x03 /* get DMA ping-pong buffer */
195+
#define RT_HW_SERIAL_CTRL_GET_DMA_PING_BUF 0x03 /* Get DMA ping-pong buffer */
197196

198197
/**
199198
* hw isr event
@@ -211,8 +210,8 @@
211210
#define RT_SERIAL_CTRL_SET_TX_TIMEOUT 0x42 /* set Tx timeout. Call before rt_device_write. not supported in poll mode */
212211
#define RT_SERIAL_CTRL_GET_RX_TIMEOUT 0x43 /* get Rx timeout. not supported in poll mode */
213212
#define RT_SERIAL_CTRL_GET_TX_TIMEOUT 0x44 /* get Tx timeout. not supported in poll mode */
214-
#define RT_SERIAL_CTRL_RX_FLUSH 0x45 /* Clear rx buffer. Discard all data */
215-
#define RT_SERIAL_CTRL_TX_FLUSH 0x46 /* Clear tx buffer. Blocking and wait for the send buffer data to be sent. not supported in poll mode */
213+
#define RT_SERIAL_CTRL_RX_FLUSH 0x45 /* clear rx buffer. Discard all data */
214+
#define RT_SERIAL_CTRL_TX_FLUSH 0x46 /* clear tx buffer. Blocking and wait for the send buffer data to be sent. not supported in poll mode */
216215
#define RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT 0x47 /* get unread bytes count. not supported in poll mode */
217216

218217
#define RT_SERIAL_ERR_OVERRUN 0x01
@@ -240,7 +239,8 @@
240239
RT_SERIAL_RX_MINBUFSZ, /* rxBuf size */ \
241240
RT_SERIAL_TX_MINBUFSZ, /* txBuf size */ \
242241
RT_SERIAL_FLOWCONTROL_NONE, /* Off flowcontrol */ \
243-
0 \
242+
0, /* reserved */ \
243+
0, /* dma_ping_bufsz */ \
244244
}
245245

246246
/**
@@ -282,9 +282,9 @@ struct rt_serial_rx_fifo
282282

283283
struct rt_completion rx_cpt;
284284

285-
rt_int32_t rx_timeout;
285+
rt_size_t rx_cpt_index;
286286

287-
rt_uint16_t rx_cpt_index;
287+
rt_atomic_t rx_timeout;
288288
};
289289

290290
/**
@@ -298,8 +298,8 @@ struct rt_serial_tx_fifo
298298
struct rt_completion tx_cpt;
299299

300300
rt_size_t put_size;
301-
302-
rt_int32_t tx_timeout;
301+
302+
rt_atomic_t tx_timeout;
303303

304304
rt_atomic_t activated;
305305
};
@@ -318,6 +318,8 @@ struct rt_serial_device
318318
void *serial_rx;
319319
void *serial_tx;
320320

321+
struct rt_spinlock spinlock;
322+
321323
struct rt_device_notify rx_notify;
322324
};
323325

0 commit comments

Comments
 (0)