From d041fb2dd1a258534a661ebe04c424500b9d0125 Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 2 Aug 2023 13:47:13 +0900 Subject: [PATCH 1/6] add i2c HAL noop implementation --- Cargo.toml | 2 ++ hal/i2c_noop/Cargo.toml | 7 +++++++ hal/i2c_noop/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 hal/i2c_noop/Cargo.toml create mode 100644 hal/i2c_noop/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index ed403d53c..4c10280d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,8 @@ resolver = "2" members = [ "./sils-runtime", "./Library/bind-utils", + + "./hal/i2c_noop", ] [workspace.dependencies] diff --git a/hal/i2c_noop/Cargo.toml b/hal/i2c_noop/Cargo.toml new file mode 100644 index 000000000..8c00daf38 --- /dev/null +++ b/hal/i2c_noop/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "c2a-i2c-noop" +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) {} From 39d67e7fab09294dad87e532d07675ef0db716ea Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 2 Aug 2023 13:48:17 +0900 Subject: [PATCH 2/6] add SPI HAL noop implementation --- Cargo.toml | 1 + hal/spi_noop/Cargo.toml | 7 +++++++ hal/spi_noop/src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 hal/spi_noop/Cargo.toml create mode 100644 hal/spi_noop/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 4c10280d4..3f0b51feb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "./Library/bind-utils", "./hal/i2c_noop", + "./hal/spi_noop", ] [workspace.dependencies] diff --git a/hal/spi_noop/Cargo.toml b/hal/spi_noop/Cargo.toml new file mode 100644 index 000000000..033b83cb9 --- /dev/null +++ b/hal/spi_noop/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "c2a-spi-noop" +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, +) { +} From ec4a4b920578f4bda150ce04b2e7f95e87dff962 Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 2 Aug 2023 13:49:05 +0900 Subject: [PATCH 3/6] add UART HAL noop implementation --- Cargo.toml | 1 + hal/uart_noop/Cargo.toml | 7 +++++++ hal/uart_noop/src/lib.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 hal/uart_noop/Cargo.toml create mode 100644 hal/uart_noop/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 3f0b51feb..8df2f03ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "./hal/i2c_noop", "./hal/spi_noop", + "./hal/uart_noop", ] [workspace.dependencies] diff --git a/hal/uart_noop/Cargo.toml b/hal/uart_noop/Cargo.toml new file mode 100644 index 000000000..c5ec9c4be --- /dev/null +++ b/hal/uart_noop/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "c2a-uart-noop" +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 +} From af88513494334d2a15b69ea4477cfac49c5d2d26 Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 2 Aug 2023 13:50:07 +0900 Subject: [PATCH 4/6] add WDT HAL noop implementation --- Cargo.toml | 1 + hal/wdt_noop/Cargo.toml | 7 +++++++ hal/wdt_noop/src/lib.rs | 42 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 hal/wdt_noop/Cargo.toml create mode 100644 hal/wdt_noop/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 8df2f03ce..1bbc0cfb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "./hal/i2c_noop", "./hal/spi_noop", "./hal/uart_noop", + "./hal/wdt_noop", ] [workspace.dependencies] diff --git a/hal/wdt_noop/Cargo.toml b/hal/wdt_noop/Cargo.toml new file mode 100644 index 000000000..7be09236d --- /dev/null +++ b/hal/wdt_noop/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "c2a-wdt-noop" +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 +} From e5e6a47044fd39f30a38cc1c883251d217a13f0b Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 2 Aug 2023 14:02:44 +0900 Subject: [PATCH 5/6] add c2a-hal noop impl crates description --- hal/i2c_noop/Cargo.toml | 1 + hal/spi_noop/Cargo.toml | 1 + hal/uart_noop/Cargo.toml | 1 + hal/wdt_noop/Cargo.toml | 1 + 4 files changed, 4 insertions(+) diff --git a/hal/i2c_noop/Cargo.toml b/hal/i2c_noop/Cargo.toml index 8c00daf38..b4e1e4d85 100644 --- a/hal/i2c_noop/Cargo.toml +++ b/hal/i2c_noop/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "c2a-i2c-noop" +description = "No-op c2a-hal I2C implementation for mock" version.workspace = true edition = "2021" diff --git a/hal/spi_noop/Cargo.toml b/hal/spi_noop/Cargo.toml index 033b83cb9..664be7a42 100644 --- a/hal/spi_noop/Cargo.toml +++ b/hal/spi_noop/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "c2a-spi-noop" +description = "No-op c2a-hal SPI implementation for mock" version.workspace = true edition = "2021" diff --git a/hal/uart_noop/Cargo.toml b/hal/uart_noop/Cargo.toml index c5ec9c4be..3bbe07a4d 100644 --- a/hal/uart_noop/Cargo.toml +++ b/hal/uart_noop/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "c2a-uart-noop" +description = "No-op c2a-hal UART implementation for mock" version.workspace = true edition = "2021" diff --git a/hal/wdt_noop/Cargo.toml b/hal/wdt_noop/Cargo.toml index 7be09236d..0cb074196 100644 --- a/hal/wdt_noop/Cargo.toml +++ b/hal/wdt_noop/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "c2a-wdt-noop" +description = "No-op c2a-hal WDT implementation for mock" version.workspace = true edition = "2021" From 2ebb261a023e15ae669ddd5803c55ad13493eedf Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 2 Aug 2023 15:17:39 +0900 Subject: [PATCH 6/6] apply new directory name rule by #42 --- Cargo.toml | 8 ++++---- hal/{i2c_noop => i2c-noop}/Cargo.toml | 0 hal/{i2c_noop => i2c-noop}/src/lib.rs | 0 hal/{spi_noop => spi-noop}/Cargo.toml | 0 hal/{spi_noop => spi-noop}/src/lib.rs | 0 hal/{uart_noop => uart-noop}/Cargo.toml | 0 hal/{uart_noop => uart-noop}/src/lib.rs | 0 hal/{wdt_noop => wdt-noop}/Cargo.toml | 0 hal/{wdt_noop => wdt-noop}/src/lib.rs | 0 9 files changed, 4 insertions(+), 4 deletions(-) rename hal/{i2c_noop => i2c-noop}/Cargo.toml (100%) rename hal/{i2c_noop => i2c-noop}/src/lib.rs (100%) rename hal/{spi_noop => spi-noop}/Cargo.toml (100%) rename hal/{spi_noop => spi-noop}/src/lib.rs (100%) rename hal/{uart_noop => uart-noop}/Cargo.toml (100%) rename hal/{uart_noop => uart-noop}/src/lib.rs (100%) rename hal/{wdt_noop => wdt-noop}/Cargo.toml (100%) rename hal/{wdt_noop => wdt-noop}/src/lib.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 1bbc0cfb4..5be40995d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,10 @@ members = [ "./sils-runtime", "./Library/bind-utils", - "./hal/i2c_noop", - "./hal/spi_noop", - "./hal/uart_noop", - "./hal/wdt_noop", + "./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 similarity index 100% rename from hal/i2c_noop/Cargo.toml rename to hal/i2c-noop/Cargo.toml diff --git a/hal/i2c_noop/src/lib.rs b/hal/i2c-noop/src/lib.rs similarity index 100% rename from hal/i2c_noop/src/lib.rs rename to hal/i2c-noop/src/lib.rs diff --git a/hal/spi_noop/Cargo.toml b/hal/spi-noop/Cargo.toml similarity index 100% rename from hal/spi_noop/Cargo.toml rename to hal/spi-noop/Cargo.toml diff --git a/hal/spi_noop/src/lib.rs b/hal/spi-noop/src/lib.rs similarity index 100% rename from hal/spi_noop/src/lib.rs rename to hal/spi-noop/src/lib.rs diff --git a/hal/uart_noop/Cargo.toml b/hal/uart-noop/Cargo.toml similarity index 100% rename from hal/uart_noop/Cargo.toml rename to hal/uart-noop/Cargo.toml diff --git a/hal/uart_noop/src/lib.rs b/hal/uart-noop/src/lib.rs similarity index 100% rename from hal/uart_noop/src/lib.rs rename to hal/uart-noop/src/lib.rs diff --git a/hal/wdt_noop/Cargo.toml b/hal/wdt-noop/Cargo.toml similarity index 100% rename from hal/wdt_noop/Cargo.toml rename to hal/wdt-noop/Cargo.toml diff --git a/hal/wdt_noop/src/lib.rs b/hal/wdt-noop/src/lib.rs similarity index 100% rename from hal/wdt_noop/src/lib.rs rename to hal/wdt-noop/src/lib.rs