From 6c01859cbe861ce1c340afcb6fd059f983a7b8b9 Mon Sep 17 00:00:00 2001 From: "Zone.N" Date: Sat, 27 May 2023 09:02:39 +0800 Subject: [PATCH] fix(device_base): update read/write Signed-off-by: Zone.N --- src/device/device_base.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/device/device_base.cpp b/src/device/device_base.cpp index 35ce680ff..99564096a 100644 --- a/src/device/device_base.cpp +++ b/src/device/device_base.cpp @@ -35,7 +35,9 @@ device_base_t::~device_base_t(void) { } int device_base_t::read(buf_t& _buf) { + // 设置要读的位置 buf.sector = _buf.sector; + // 读 auto res = drv->read(buf); // 等待中断完成 @@ -43,25 +45,31 @@ int device_base_t::read(buf_t& _buf) { ; } + // 将设备缓冲区中的数据复制到 _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; }