Skip to content

Commit

Permalink
Merge pull request #40 from arkedge/feature/add-hal-noop-impl
Browse files Browse the repository at this point in the history
Add HAL noop implementation
  • Loading branch information
sksat authored Aug 2, 2023
2 parents d7bf521 + 2ebb261 commit fa03ee3
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions hal/i2c-noop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions hal/i2c-noop/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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) {}
8 changes: 8 additions & 0 deletions hal/spi-noop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions hal/spi-noop/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
) {
}
8 changes: 8 additions & 0 deletions hal/uart-noop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions hal/uart-noop/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions hal/wdt-noop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions hal/wdt-noop/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit fa03ee3

Please sign in to comment.