Skip to content

Commit

Permalink
Merge pull request #1744 from v-thakkar/Apr10
Browse files Browse the repository at this point in the history
Spi: Move SPI buffer size into SPI capsule
  • Loading branch information
bradjc committed Apr 30, 2020
2 parents 8765fa8 + ebd79d9 commit 0520cd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions boards/components/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

use core::mem::MaybeUninit;

use capsules::spi::Spi;
use capsules::spi::{Spi, DEFAULT_READ_BUF_LENGTH, DEFAULT_WRITE_BUF_LENGTH};
use capsules::virtual_spi::{MuxSpiMaster, VirtualSpiMasterDevice};
use kernel::component::Component;
use kernel::hil::spi;
use kernel::static_init_half;
use kernel::{static_init, static_init_half};

// Setup static space for the objects.
#[macro_export]
Expand Down Expand Up @@ -131,10 +131,15 @@ impl<S: 'static + spi::SpiMaster> Component for SpiSyscallComponent<S> {
Spi::new(syscall_spi_device)
);

static mut SPI_READ_BUF: [u8; 1024] = [0; 1024];
static mut SPI_WRITE_BUF: [u8; 1024] = [0; 1024];
let spi_read_buf =
static_init!([u8; DEFAULT_READ_BUF_LENGTH], [0; DEFAULT_READ_BUF_LENGTH]);

spi_syscalls.config_buffers(&mut SPI_READ_BUF, &mut SPI_WRITE_BUF);
let spi_write_buf = static_init!(
[u8; DEFAULT_WRITE_BUF_LENGTH],
[0; DEFAULT_WRITE_BUF_LENGTH]
);

spi_syscalls.config_buffers(spi_read_buf, spi_write_buf);
syscall_spi_device.set_client(spi_syscalls);

spi_syscalls
Expand Down
4 changes: 4 additions & 0 deletions capsules/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ use kernel::{AppId, AppSlice, Callback, Driver, ReturnCode, Shared};
use crate::driver;
pub const DRIVER_NUM: usize = driver::NUM::Spi as usize;

/// Suggested length for the Spi read and write buffer
pub const DEFAULT_READ_BUF_LENGTH: usize = 1024;
pub const DEFAULT_WRITE_BUF_LENGTH: usize = 1024;

// SPI operations are handled by coping into a kernel buffer for
// writes and copying out of a kernel buffer for reads.
//
Expand Down

0 comments on commit 0520cd9

Please sign in to comment.