Skip to content

Commit cdb5b23

Browse files
committed
chore: 优化代码格式和结构,调整导入顺序,简化内存管理逻辑
1 parent 7f84364 commit cdb5b23

5 files changed

Lines changed: 96 additions & 229 deletions

File tree

interface/rdif-pcie/src/addr_alloc/address_allocator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ mod tests {
288288
.unwrap(),
289289
RangeInclusive::new(0x500, 0x9FD).unwrap()
290290
);
291-
assert!(pool
292-
.free(&RangeInclusive::new(0x500, 0x9FD).unwrap())
293-
.is_ok());
291+
assert!(
292+
pool.free(&RangeInclusive::new(0x500, 0x9FD).unwrap())
293+
.is_ok()
294+
);
294295
}
295296
}

interface/rdif-pcie/src/addr_alloc/allocation_engine/interval_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
44

5-
use core::cmp::{max, Ordering};
5+
use core::cmp::{Ordering, max};
66

77
use alloc::boxed::Box;
88

interface/rdif-pcie/src/addr_alloc/id_allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl IdAllocator {
9999

100100
#[cfg(test)]
101101
mod tests {
102-
use crate::id_allocator::IdAllocator;
103102
use crate::Error;
103+
use crate::id_allocator::IdAllocator;
104104

105105
#[test]
106106
fn test_slot_id_allocation() {

interface/rdif-serial/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
extern crate alloc;
44

5-
use core::{any::Any, ptr::NonNull};
5+
use core::any::Any;
66

77
use alloc::boxed::Box;
88
use bitflags::bitflags;
@@ -57,6 +57,8 @@ pub enum TransferError {
5757
Framing,
5858
#[error("Break condition")]
5959
Break,
60+
#[error("Serial port released")]
61+
SerialReleased,
6062
}
6163

6264
impl From<RegisterTransferError> for TransferError {
@@ -170,7 +172,7 @@ impl Config {
170172
}
171173
}
172174

173-
pub trait Register: Clone + Send + Sync + Any + 'static {
175+
pub trait Register: Send + Sync + Any + 'static {
174176
// ==================== 基础数据传输 ====================
175177
fn write_byte(&mut self, byte: u8);
176178
fn read_byte(&self) -> Result<u8, RegisterTransferError>;
@@ -215,7 +217,7 @@ pub trait Register: Clone + Send + Sync + Any + 'static {
215217
fn write_reg(&mut self, offset: usize, value: u32);
216218

217219
fn get_base(&self) -> usize;
218-
fn set_base(&mut self, base: NonNull<u8>);
220+
fn set_base(&mut self, base: usize);
219221

220222
fn read_buf(&mut self, buf: &mut [u8]) -> Result<usize, RegisterTransferError> {
221223
let mut read_count = 0;
@@ -257,14 +259,14 @@ pub trait Register: Clone + Send + Sync + Any + 'static {
257259
}
258260
}
259261

260-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
261-
pub struct NotMatchError;
262-
263262
pub trait Interface: DriverGeneric {
264263
fn irq_handler(&mut self) -> Option<Box<dyn TIrqHandler>>;
265264
fn take_tx(&mut self) -> Option<Box<dyn TSender>>;
266265
fn take_rx(&mut self) -> Option<Box<dyn TReciever>>;
266+
/// Base address of the serial port
267267
fn base(&self) -> usize;
268+
/// Set base address of the serial port
269+
fn set_base(&mut self, base: usize);
268270

269271
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError>;
270272

@@ -289,7 +291,7 @@ pub trait TIrqHandler: Send + Sync + 'static {
289291

290292
pub trait TSender: Send + 'static {
291293
/// Send data from buf, return sent bytes. If return bytes is less than buf.len(), it means no more space, need to retry later.
292-
fn send(&mut self, buf: &[u8]) -> usize;
294+
fn send(&mut self, buf: &[u8]) -> Result<usize, TransferError>;
293295
}
294296

295297
pub trait TReciever: Send + 'static {

0 commit comments

Comments
 (0)