Skip to content

Commit

Permalink
fix(device_base): update read/write
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed May 27, 2023
1 parent 6cf89b7 commit 08a5f75
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/device/device_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,41 @@ device_base_t::~device_base_t(void) {
}

int device_base_t::read(buf_t& _buf) {
// 设置要读的位置
buf.sector = _buf.sector;
//
auto res = drv->read(buf);

// 等待中断完成
while (buf.valid == false) {
;
}

// 将设备缓冲区中的数据复制到 _buf
memcpy(_buf.data, buf.data, COMMON::BUFFFER_SIZE);

// 将设备缓冲区设置为无效
buf.valid = false;

return res;
}

int device_base_t::write(buf_t& _buf) {
auto res = drv->write(buf);
// 将设备缓冲区设置为无效
buf.valid = false;
// 将要写的数据复制到设备缓冲区
memcpy(buf.data, _buf.data, COMMON::BUFFFER_SIZE);
// 设置要写的位置
buf.sector = _buf.sector;

//
auto res = drv->write(buf);

// 等待中断完成
while (buf.valid == false) {
;
}

memcpy(buf.data, _buf.data, COMMON::BUFFFER_SIZE);

buf.valid = false;

return res;
}

Expand Down

0 comments on commit 08a5f75

Please sign in to comment.