SD reader: optimized stack and binary size
This commit is contained in:
parent
2b1b0dc49f
commit
a55a6291a4
@ -14,7 +14,7 @@ num-traits = { version = "0.2", default-features = false }
|
|||||||
num-derive = "0.3"
|
num-derive = "0.3"
|
||||||
cslice = "0.3"
|
cslice = "0.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
core_io = { version = "0.1", features = ["alloc", "collections"] }
|
core_io = { version = "0.1", features = ["collections"] }
|
||||||
byteorder = { version = "1.3", default-features = false }
|
byteorder = { version = "1.3", default-features = false }
|
||||||
void = { version = "1", default-features = false }
|
void = { version = "1", default-features = false }
|
||||||
futures = { version = "0.3", default-features = false, features = ["async-await"] }
|
futures = { version = "0.3", default-features = false, features = ["async-await"] }
|
||||||
@ -24,4 +24,4 @@ libsupport_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
|||||||
libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
||||||
libasync = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
libasync = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
||||||
dyld = { path = "../libdyld" }
|
dyld = { path = "../libdyld" }
|
||||||
fatfs = { version = "0.3", features = ["core_io", "alloc"], default-features = false }
|
fatfs = { version = "0.3", features = ["core_io"], default-features = false }
|
||||||
|
@ -2,6 +2,7 @@ use core_io::{BufRead, Error, ErrorKind, Read, Result as IoResult, Seek, SeekFro
|
|||||||
use fatfs;
|
use fatfs;
|
||||||
use libboard_zynq::sdio::{sd_card::SdCard, CmdTransferError};
|
use libboard_zynq::sdio::{sd_card::SdCard, CmdTransferError};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
fn cmd_error_to_io_error(_: CmdTransferError) -> Error {
|
fn cmd_error_to_io_error(_: CmdTransferError) -> Error {
|
||||||
Error::new(ErrorKind::Other, "Command transfer error")
|
Error::new(ErrorKind::Other, "Command transfer error")
|
||||||
@ -19,7 +20,7 @@ pub struct SdReader {
|
|||||||
/// Internal SdCard handle.
|
/// Internal SdCard handle.
|
||||||
sd: SdCard,
|
sd: SdCard,
|
||||||
/// Read buffer with the size of 1 block.
|
/// Read buffer with the size of 1 block.
|
||||||
buffer: [u8; BLOCK_SIZE],
|
buffer: Vec<u8>,
|
||||||
/// Address for the next byte.
|
/// Address for the next byte.
|
||||||
byte_addr: u32,
|
byte_addr: u32,
|
||||||
/// Internal index for the next byte.
|
/// Internal index for the next byte.
|
||||||
@ -47,9 +48,13 @@ pub enum PartitionEntry {
|
|||||||
impl SdReader {
|
impl SdReader {
|
||||||
/// Create SdReader from SdCard
|
/// Create SdReader from SdCard
|
||||||
pub fn new(sd: SdCard) -> SdReader {
|
pub fn new(sd: SdCard) -> SdReader {
|
||||||
|
let mut vec: Vec<u8> = Vec::with_capacity(BLOCK_SIZE);
|
||||||
|
unsafe {
|
||||||
|
vec.set_len(vec.capacity());
|
||||||
|
}
|
||||||
SdReader {
|
SdReader {
|
||||||
sd,
|
sd,
|
||||||
buffer: [0; BLOCK_SIZE],
|
buffer: vec,
|
||||||
byte_addr: 0,
|
byte_addr: 0,
|
||||||
index: BLOCK_SIZE,
|
index: BLOCK_SIZE,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user