196{
198
200 {
202 if (port.queue_info_->Peek(info) != ErrorCode::OK)
203 {
204 return ErrorCode::EMPTY;
205 }
206
207 uint8_t *buffer = nullptr;
208 bool use_pending = false;
209
210 if (uart->uart_handle_->gState == HAL_UART_STATE_READY)
211 {
212 buffer =
reinterpret_cast<uint8_t *
>(uart->dma_buff_tx_.
ActiveBuffer());
213 }
214 else
215 {
216 buffer =
reinterpret_cast<uint8_t *
>(uart->dma_buff_tx_.
PendingBuffer());
217 use_pending = true;
218 }
219
220 if (port.queue_data_->
PopBatch(
reinterpret_cast<uint8_t *
>(buffer),
222 {
223 ASSERT(false);
224 return ErrorCode::EMPTY;
225 }
226
227 if (use_pending)
228 {
231 if (uart->uart_handle_->gState == HAL_UART_STATE_READY &&
233 {
234 uart->dma_buff_tx_.
Switch();
235 }
236 else
237 {
238 return ErrorCode::FAILED;
239 }
240 }
241
242 port.queue_info_->Pop(uart->write_info_active_);
243
244#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
245 SCB_CleanDCache_by_Addr(
247#endif
248
249 auto ans = HAL_UART_Transmit_DMA(
250 uart->uart_handle_,
static_cast<uint8_t *
>(uart->dma_buff_tx_.
ActiveBuffer()),
252
253 if (ans != HAL_OK)
254 {
255 port.
Finish(
false, ErrorCode::FAILED, info, 0);
256 return ErrorCode::FAILED;
257 }
258 else
259 {
260 return ErrorCode::OK;
261 }
262 }
263
264 return ErrorCode::FAILED;
265}
size_t size_
数据大小(字节)。 The size of the data (in bytes).
void SetPendingLength(size_t length)
设置备用缓冲区的数据长度 Sets the size of the pending buffer
void EnablePending()
手动启用 pending 状态 Manually sets the pending state to true
bool HasPending() const
判断是否有待切换的缓冲区 Checks whether a pending buffer is ready
uint8_t * ActiveBuffer() const
获取当前正在使用的缓冲区指针 Returns the currently active buffer
uint8_t * PendingBuffer() const
获取备用缓冲区的指针 Returns the pending (inactive) buffer
void Switch()
切换到备用缓冲区(若其有效) Switches to the pending buffer if it's valid
ErrorCode PopBatch(Data *data, size_t size)
批量弹出数据 / Pops multiple elements from the queue
void Finish(bool in_isr, ErrorCode ans, WriteInfoBlock &info, uint32_t size)
更新写入操作的状态。 Updates the status of the write operation.
ConstRawData data
Data buffer. 数据缓冲区。