diff --git a/CMakeLists.txt b/CMakeLists.txt index 99d206c..b15cd78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,16 @@ set(TARGET_NAME ${CMAKE_PROJECT_NAME}) # Set path names set(FreeRTOS_PATH FreeRTOS-Kernel/) set(MISSION_PATH mission/) -set(FreeRTOS_CONFIG_PATH bsp_z7/freeRTOS) -set(BSP_PATH bsp_z7) -set(CMAKE_MODULE_PATH Findcommon.cmake) + + +set(TargetIsLinux TRUE) + +endif() + +set(TargetIsZedboard TRUE) + set(FreeRTOS_CONFIG_PATH bsp_z7/freeRTOS) + set(BSP_PATH bsp_z7) +endif() set (LWIP_DIR contrib/lwip) @@ -30,6 +37,12 @@ set (LWIP_DIR contrib/lwip) # Configuration # ############################################################################## + +if(${TargetIsLinux} TRUE) + add_compile_definitions(ZYNQ_USE_UART0) +endif() + + set(ZYNQ_UART UART1 CACHE STRING "Which PS UART to use for stdout") set_property(CACHE ZYNQ_UART PROPERTY STRINGS UART0 UART1) diff --git a/mission/can_rust_helper.c b/mission/can_rust_helper.c index 078d7f8..135ee4d 100644 --- a/mission/can_rust_helper.c +++ b/mission/can_rust_helper.c @@ -335,3 +335,5 @@ static int RecvFrame(XCanPs *InstancePtr) return Status; } + +# define FALSE 2U \ No newline at end of file diff --git a/mission/gpio_rust_helper.c b/mission/gpio_rust_helper.c index 4308b0b..186ad48 100644 --- a/mission/gpio_rust_helper.c +++ b/mission/gpio_rust_helper.c @@ -6,6 +6,27 @@ /* GPIO SETUP AND USAGE */ /************************************************************/ + +if(TargetIsLinux) + +XGpioPs gpio; +void gpio_setup() { +} + + +void gpio_write_pin(uint32_t pin, uint32_t data) { +} + +uint32_t gpio_read_pin(uint32_t pin) { + return 1; +} + +void gpio_toggle_pin(uint32_t pin) { +} +endif() + +if(TargetIsZedboard TRUE) + XGpioPs gpio; void gpio_setup() { XGpioPs_Config config; @@ -34,4 +55,7 @@ void gpio_toggle_pin(uint32_t pin) { static int pinvalue = 1; pinvalue = pinvalue ^ 1; XGpioPs_WritePin(&gpio, pin, pinvalue); -} \ No newline at end of file +} + + +endif() \ No newline at end of file diff --git a/mission_rust/src/fsrc/osal/mod.rs b/mission_rust/src/fsrc/osal/mod.rs index a890e9e..da24140 100644 --- a/mission_rust/src/fsrc/osal/mod.rs +++ b/mission_rust/src/fsrc/osal/mod.rs @@ -57,16 +57,67 @@ extern "C" { pub fn gpio_read_pin(pin: u32) -> u32; pub fn gpio_toggle_pin(pin: u32) -> (); - // CAN Samples - - - pub fn canps_poll_example() -> i32; - } +pub mod can { + use core::fmt::Error; + pub fn read_data() -> Result + { + + if (unsafe {can_unsafe::canps_get_status().is_initialized == false}) { + return Err(Error); + } + unsafe { + Ok(can_unsafe::canps_poll_example()) + } + } + + mod can_unsafe { + extern "C" { + + // CAN Samples + + + pub fn canps_setup() -> i32; + + pub fn canps_send_data() -> i32; + pub fn canps_read_data() -> i32; + + pub fn canps_get_status() -> canps_status; + + pub fn canps_poll_example() -> i32; + + } + + #[repr(C)] + pub struct canps_status { + pub is_initialized: bool + } + } +} + + // RustFSW + // -> hal::can + // -> hal::can::unsafe // + // -> mission/can_rust_helper.c // + // -> BSP/XCanPS + +mod safe_osal { + + /* + * Is safe. Trust me, I'm an engineer. + */ + pub fn gpio_setup() { + unsafe { + crate::osal::gpio_setup(); + } + } +} + + pub fn task_delete_self() { unsafe { diff --git a/mission_rust/src/lib.rs b/mission_rust/src/lib.rs index a936755..7d94ed7 100644 --- a/mission_rust/src/lib.rs +++ b/mission_rust/src/lib.rs @@ -186,7 +186,7 @@ fn mission() { sifln!("Call canps poll example()"); - canps_poll_example(); + can::unsafe::canps_poll_example(); } sifln!("Called canps poll example()");