diff --git a/Cargo.toml b/Cargo.toml index fffbd50b5..f693b4a15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,11 @@ resolver = "2" members = [ "./sils-runtime", "./Library/bind-utils", + + "./hal/i2c-noop", + "./hal/spi-noop", + "./hal/uart-noop", + "./hal/wdt-noop", ] [workspace.dependencies] diff --git a/hal/i2c-noop/Cargo.toml b/hal/i2c-noop/Cargo.toml new file mode 100644 index 000000000..b4e1e4d85 --- /dev/null +++ b/hal/i2c-noop/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c2a-i2c-noop" +description = "No-op c2a-hal I2C implementation for mock" +version.workspace = true +edition = "2021" + +[dependencies] +c2a-core.workspace = true diff --git a/hal/i2c-noop/src/lib.rs b/hal/i2c-noop/src/lib.rs new file mode 100644 index 000000000..e3141a584 --- /dev/null +++ b/hal/i2c-noop/src/lib.rs @@ -0,0 +1,39 @@ +#![no_std] + +use core::ffi::{c_int, c_void}; + +use c2a_core::hal::i2c::*; + +#[no_mangle] +pub extern "C" fn I2C_init(_i2c_config: *mut I2C_Config) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn I2C_rx( + _i2c_config: *mut I2C_Config, + _data: *mut c_void, + _buffer_size: c_int, +) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn I2C_tx( + _i2c_config: *mut I2C_Config, + _data: *mut c_void, + _data_size: c_int, +) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn I2C_reopen(_i2c_config: *mut I2C_Config, _reason: c_int) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn I2C_set_stop_flag(_i2c_config: *mut I2C_Config, _stop_flag: u8) {} + +#[no_mangle] +pub extern "C" fn I2C_set_rx_length(_i2c_config: *mut I2C_Config, _rx_length: u32) {} diff --git a/hal/spi-noop/Cargo.toml b/hal/spi-noop/Cargo.toml new file mode 100644 index 000000000..664be7a42 --- /dev/null +++ b/hal/spi-noop/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c2a-spi-noop" +description = "No-op c2a-hal SPI implementation for mock" +version.workspace = true +edition = "2021" + +[dependencies] +c2a-core.workspace = true diff --git a/hal/spi-noop/src/lib.rs b/hal/spi-noop/src/lib.rs new file mode 100644 index 000000000..8686847fb --- /dev/null +++ b/hal/spi-noop/src/lib.rs @@ -0,0 +1,43 @@ +#![no_std] + +use core::ffi::{c_int, c_void}; + +use c2a_core::hal::spi::*; + +#[no_mangle] +pub extern "C" fn SPI_init(_spi_config: *mut SPI_Config) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn SPI_rx( + _spi_config: *mut SPI_Config, + _data: *mut c_void, + _buffer_size: c_int, +) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn SPI_tx( + _spi_config: *mut SPI_Config, + _data: *mut c_void, + _data_size: c_int, +) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn SPI_reopen(_spi_config: *mut SPI_Config, _reason: c_int) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn SPI_set_rx_length(_spi_config: *mut SPI_Config, _rx_length: u16) {} + +#[no_mangle] +pub extern "C" fn SPI_set_cs_state_after_tx( + _spi_config: *mut SPI_Config, + _cs_state_after_tx: SPI_CS_STATE_AFTER_TX, +) { +} diff --git a/hal/uart-noop/Cargo.toml b/hal/uart-noop/Cargo.toml new file mode 100644 index 000000000..3bbe07a4d --- /dev/null +++ b/hal/uart-noop/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c2a-uart-noop" +description = "No-op c2a-hal UART implementation for mock" +version.workspace = true +edition = "2021" + +[dependencies] +c2a-core.workspace = true diff --git a/hal/uart-noop/src/lib.rs b/hal/uart-noop/src/lib.rs new file mode 100644 index 000000000..a5933bcd2 --- /dev/null +++ b/hal/uart-noop/src/lib.rs @@ -0,0 +1,33 @@ +#![no_std] + +use core::ffi::{c_int, c_void}; + +use c2a_core::hal::uart::*; + +#[no_mangle] +pub extern "C" fn UART_init(_uart_config: *mut UART_Config) -> c_int { + UART_ERR_CODE_UART_OK.0 +} + +#[no_mangle] +pub extern "C" fn UART_rx( + _uart_config: *mut UART_Config, + _data: *mut c_void, + _buffer_size: c_int, +) -> c_int { + UART_ERR_CODE_UART_OK.0 +} + +#[no_mangle] +pub extern "C" fn UART_tx( + _uart_config: *mut UART_Config, + _data: *mut c_void, + _data_size: c_int, +) -> c_int { + UART_ERR_CODE_UART_OK.0 +} + +#[no_mangle] +pub extern "C" fn UART_reopen(_uart_config: *mut UART_Config, _reason: c_int) -> c_int { + UART_ERR_CODE_UART_OK.0 +} diff --git a/hal/wdt-noop/Cargo.toml b/hal/wdt-noop/Cargo.toml new file mode 100644 index 000000000..0cb074196 --- /dev/null +++ b/hal/wdt-noop/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "c2a-wdt-noop" +description = "No-op c2a-hal WDT implementation for mock" +version.workspace = true +edition = "2021" + +[dependencies] +c2a-core.workspace = true diff --git a/hal/wdt-noop/src/lib.rs b/hal/wdt-noop/src/lib.rs new file mode 100644 index 000000000..e35bf42b1 --- /dev/null +++ b/hal/wdt-noop/src/lib.rs @@ -0,0 +1,42 @@ +#![no_std] +#![allow(clippy::missing_safety_doc)] + +use core::ffi::c_int; + +use c2a_core::hal::wdt::*; + +#[no_mangle] +pub unsafe extern "C" fn WDT_initialize(config: *mut WDT_Config) -> c_int { + let cfg = unsafe { &mut (*config) }; + + WDT_set_timer(config, 7); + + cfg.is_clear_enable = 1; + cfg.is_wdt_enable = 1; + + 0 +} + +#[no_mangle] +pub extern "C" fn WDT_clear(_wdt_config: *mut WDT_Config) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn WDT_enable(_wdt_config: *mut WDT_Config) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn WDT_disable(_wdt_config: *mut WDT_Config) -> c_int { + 0 +} + +#[no_mangle] +pub unsafe extern "C" fn WDT_set_timer(config: *mut WDT_Config, time: c_int) -> c_int { + let cfg = unsafe { &mut (*config) }; + + cfg.timer_setting = time; + + 0 +}