diff --git a/bsp_z7/coraZ7-10/xparameters.h b/bsp_z7/coraZ7-10/xparameters.h index ba6bcab..a768cab 100644 --- a/bsp_z7/coraZ7-10/xparameters.h +++ b/bsp_z7/coraZ7-10/xparameters.h @@ -415,6 +415,7 @@ /* Canonical definitions for peripheral UARTLITE */ #define XUARTLITE_BASEADDRESS 0x42c00000 +#define XPAR_UARTLITE_0_DEVICE_ID 111 /* Definitions for driver UARTPS */ #define XPAR_XUARTPS_NUM_INSTANCES 1 diff --git a/bsp_z7/ps7_cortexa9_0/include/xuartlite.h b/bsp_z7/ps7_cortexa9_0/include/xuartlite.h new file mode 100644 index 0000000..e41359b --- /dev/null +++ b/bsp_z7/ps7_cortexa9_0/include/xuartlite.h @@ -0,0 +1,292 @@ +/****************************************************************************** +* Copyright (C) 2002 - 2022 Xilinx, Inc. All rights reserved. +* Copyright (C) 2022 - 2023 Advanced Micro Devices, Inc. All Rights Reserved. +* SPDX-License-Identifier: MIT +******************************************************************************/ + +/****************************************************************************/ +/** +* +* @file xuartlite.h +* @addtogroup uartlite Overview +* @{ +* @details +* +* This component contains the implementation of the XUartLite component which is +* the driver for the Xilinx UART Lite device. This UART is a minimal hardware +* implementation with minimal features. Most of the features, including baud +* rate, parity, and number of data bits are only configurable when the hardware +* device is built, rather than at run time by software. +* +* The device has 16 byte transmit and receive FIFOs and supports interrupts. +* The device does not have any way to disable the receiver such that the +* receive FIFO may contain unwanted data. The FIFOs are not flushed when the +* driver is initialized, but a function is provided to allow the user to +* reset the FIFOs if desired. +* +* The driver defaults to no interrupts at initialization such that interrupts +* must be enabled if desired. An interrupt is generated when the transmit FIFO +* transitions from having data to being empty or when any data is contained in +* the receive FIFO. +* +* In order to use interrupts, it's necessary for the user to connect the driver +* interrupt handler, XUartLite_InterruptHandler, to the interrupt system of the +* application. This function does not save and restore the processor context +* such that the user must provide it. Send and receive handlers may be set for +* the driver such that the handlers are called when transmit and receive +* interrupts occur. The handlers are called from interrupt context and are +* designed to allow application specific processing to be performed. +* +* The functions, XUartLite_Send and XUartLite_Recv, are provided in the driver +* to allow data to be sent and received. They are designed to be used in +* polled or interrupt modes. +* +* The driver provides a status for each received byte indicating any parity +* frame or overrun error. The driver provides statistics which allow visibility +* into these errors. +* +* Initialization & Configuration +* +* The XUartLite_Config structure is used by the driver to configure itself. This +* configuration structure is typically created by the tool-chain based on HW +* build properties. +* +* To support multiple runtime loading and initialization strategies employed +* by various operating systems, the driver instance can be initialized in one +* of the following ways: +* +* - XUartLite_Initialize(InstancePtr, DeviceId) - The driver looks up its own +* configuration structure created by the tool-chain based on an ID provided +* by the tool-chain. +* +* - XUartLite_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a +* configuration structure provided by the caller. If running in a system +* with address translation, the provided virtual memory base address +* replaces the physical address present in the configuration structure. +* +* RTOS Independence +* +* This driver is intended to be RTOS and processor independent. It works +* with physical addresses only. Any needs for dynamic memory management, +* threads or thread mutual exclusion, virtual memory, or cache control must +* be satisfied by the layer above this driver. +* +* @note +* +* The driver is partitioned such that a minimal implementation may be used. +* More features require additional files to be linked in. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who  Date     Changes
+* ----- ---- -------- -----------------------------------------------
+* 1.00a ecm  08/31/01 First release
+* 1.00b jhl  02/21/02 Repartitioned the driver for smaller files
+* 1.01a jvb  12/14/05 I separated dependency on the static config table and
+*                     xparameters.h from the driver initialization by moving
+*                     _Initialize and _LookupConfig to _sinit.c. I also added
+*                     the new _CfgInitialize routine.
+* 1.02a rpm  02/14/07 Added check for outstanding transmission before
+*                     calling the send callback (avoids extraneous
+*                     callback invocations) in interrupt service routine.
+* 1.12a mta  03/31/07 Updated to new coding conventions
+* 1.13a sv   01/21/08 Updated driver to support access through DCR bus
+* 1.14a sdm  08/22/08 Removed support for static interrupt handlers from the MDD
+*		      file
+* 1.14a sdm  09/26/08 Updated code to avoid race condition in
+*		      XUartLite_SendBuffer
+* 2.00a ktn  10/20/09 Updated to use HAL Processor APIs. The macros have been
+*		      renamed to remove _m from the name. XUartLite_mClearStats
+*		      macro is removed and XUartLite_ClearStats function should
+*		      be used in its place.
+* 2.01a adk  18/04/13 Updated the code to avoid unused variable
+*		      warnings when compiling with the -Wextra -Wall flags
+*		      In the file xuartlite.c. CR:704999.
+*		      Added notes for CR 710483 that the XUL_FIFO_SIZE is not
+*		      used in the driver. This is the size of the FIFO for
+*		      Transmit/Receive FIFOs which cannot be changed.
+* 3.0 adk 17/12/13  Fixed CR:741186,761863 Changes are made in the file 
+*		      xuartlite_selftest.c      
+* 3.0 adk 19/12/13  Update the driver as per new TCL API's
+* 3.1 nsk 21/07/15  Updated XUartLite_ReceiveBuffer function in xuartlite.c
+*		    to update the receive data into user buffer in critical
+*		    region.CR#865787.
+* 3.2   sk   11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
+*                     Changed the prototype of XUartLite_CfgInitialize API.
+*       ms   01/23/17 Added xil_printf statement in main function for all
+*                     examples to ensure that "Successfully ran" and "Failed"
+*                     strings are available in all examples. This is a fix
+*                     for CR-965028.
+*       ms   03/17/17 Added readme.txt file in examples folder for doxygen
+*                     generation.
+* 3.3   sne 09/09/19  Updated driver tcl file for supporting pl and ps ip's.
+* 3.3	sne 09/13/19  Updated driver tcl file for mdm & tmr_sem ip's.
+* 3.7	adk 31/01/22  Fix interrupt controller name in SMP designs, Changes are
+* 		      made in the interrupt app tcl file.
+* 3.7	adk 14/02/22  When generating peripheral tests for TMR subsystem based
+* 		      designs don't pull the driver examples when uartlite is
+* 		      configured as a TMR SEM fix for CR-1121291, changes are
+* 		      made in the uartlite_tapp.tcl file.
+* 3.9	ht  07/18/23  Fixed GCC warnings.
+*
+* 
+* +*****************************************************************************/ + +#ifndef XUARTLITE_H /* prevent circular inclusions */ +#define XUARTLITE_H /* by using protection macros */ + +#ifdef __cplusplus +extern "C" { +#endif + +/***************************** Include Files ********************************/ + +#include "xil_types.h" +#include "xil_assert.h" +#include "xstatus.h" + +/************************** Constant Definitions ****************************/ + +/**************************** Type Definitions ******************************/ + +/** + * Callback function. The first argument is a callback reference passed in by + * the upper layer when setting the callback functions, and passed back to the + * upper layer when the callback is invoked. + * The second argument is the ByteCount which is the number of bytes that + * actually moved from/to the buffer provided in the _Send/_Receive call. + */ +typedef void (*XUartLite_Handler)(void *CallBackRef, unsigned int ByteCount); + +/** + * Statistics for the XUartLite driver + */ +typedef struct { + u32 TransmitInterrupts; /**< Number of transmit interrupts */ + u32 ReceiveInterrupts; /**< Number of receive interrupts */ + u32 CharactersTransmitted; /**< Number of characters transmitted */ + u32 CharactersReceived; /**< Number of characters received */ + u32 ReceiveOverrunErrors; /**< Number of receive overruns */ + u32 ReceiveParityErrors; /**< Number of receive parity errors */ + u32 ReceiveFramingErrors; /**< Number of receive framing errors */ +} XUartLite_Stats; + +/** + * The following data type is used to manage the buffers that are handled + * when sending and receiving data in the interrupt mode. It is intended + * for internal use only. + */ +typedef struct { + u8 *NextBytePtr; + unsigned int RequestedBytes; + unsigned int RemainingBytes; +} XUartLite_Buffer; + +/** + * This typedef contains configuration information for the device. + */ +typedef struct { +#ifndef SDT + u16 DeviceId; /**< Unique ID of device */ +#else + char *Name; +#endif + UINTPTR RegBaseAddr; /**< Register base address */ + u32 BaudRate; /**< Fixed baud rate */ + u8 UseParity; /**< Parity generator enabled when TRUE */ + u8 ParityOdd; /**< Parity generated is odd when TRUE, even + when FALSE */ + u8 DataBits; /**< Fixed data bits */ +#ifdef SDT + u16 IntrId; /** Bits[11:0] Interrupt-id Bits[15:12] + * trigger type and level flags */ + UINTPTR IntrParent; /** Bit[0] Interrupt parent type Bit[64/32:1] + * Parent base address */ +#endif +} XUartLite_Config; + +/** + * The XUartLite driver instance data. The user is required to allocate a + * variable of this type for every UART Lite device in the system. A pointer + * to a variable of this type is then passed to the driver API functions. + */ +typedef struct { + XUartLite_Stats Stats; /* Component Statistics */ + UINTPTR RegBaseAddress; /* Base address of registers */ + u32 IsReady; /* Device is initialized and ready */ + + XUartLite_Buffer SendBuffer; + XUartLite_Buffer ReceiveBuffer; + + XUartLite_Handler RecvHandler; + void *RecvCallBackRef; /* Callback ref for recv handler */ + XUartLite_Handler SendHandler; + void *SendCallBackRef; /* Callback ref for send handler */ +} XUartLite; + + +/***************** Macros (Inline Functions) Definitions ********************/ + + +/************************** Function Prototypes *****************************/ + +/* + * Initialization functions in xuartlite_sinit.c + */ +#ifndef SDT +int XUartLite_Initialize(XUartLite *InstancePtr, u16 DeviceId); +XUartLite_Config *XUartLite_LookupConfig(u16 DeviceId); +#else +int XUartLite_Initialize(XUartLite *InstancePtr, UINTPTR BaseAddress); +XUartLite_Config *XUartLite_LookupConfig(UINTPTR BaseAddress); +#endif + +/* + * Required functions, in file xuart.c + */ +int XUartLite_CfgInitialize(XUartLite *InstancePtr, + XUartLite_Config *Config, + UINTPTR EffectiveAddr); + +void XUartLite_ResetFifos(XUartLite *InstancePtr); + +unsigned int XUartLite_Send(XUartLite *InstancePtr, u8 *DataBufferPtr, + unsigned int NumBytes); +unsigned int XUartLite_Recv(XUartLite *InstancePtr, u8 *DataBufferPtr, + unsigned int NumBytes); + +int XUartLite_IsSending(XUartLite *InstancePtr); + +/* + * Functions for statistics, in file xuartlite_stats.c + */ +void XUartLite_GetStats(XUartLite *InstancePtr, XUartLite_Stats *StatsPtr); +void XUartLite_ClearStats(XUartLite *InstancePtr); + +/* + * Functions for self-test, in file xuartlite_selftest.c + */ +int XUartLite_SelfTest(XUartLite *InstancePtr); + +/* + * Functions for interrupts, in file xuartlite_intr.c + */ +void XUartLite_EnableInterrupt(XUartLite *InstancePtr); +void XUartLite_DisableInterrupt(XUartLite *InstancePtr); + +void XUartLite_SetRecvHandler(XUartLite *InstancePtr, XUartLite_Handler FuncPtr, + void *CallBackRef); +void XUartLite_SetSendHandler(XUartLite *InstancePtr, XUartLite_Handler FuncPtr, + void *CallBackRef); + +void XUartLite_InterruptHandler(XUartLite *InstancePtr); + +#ifdef __cplusplus +} +#endif + +#endif /* end of protection macro */ + +/** @} */ diff --git a/mission/CMakeLists.txt b/mission/CMakeLists.txt index da6f3d5..352cf22 100644 --- a/mission/CMakeLists.txt +++ b/mission/CMakeLists.txt @@ -1 +1 @@ -target_sources(${TARGET_NAME} PRIVATE mission.c freeRTOS_rust_helper.c) +target_sources(${TARGET_NAME} PRIVATE mission.c freeRTOS_rust_helper.c uart_rust_helper.c gpio_rust_helper.c can_rust_helper.c) diff --git a/mission/mission.c b/mission/mission.c index bfb0a3b..76617b9 100644 --- a/mission/mission.c +++ b/mission/mission.c @@ -85,7 +85,7 @@ void vApplicationMallocFailedHook(void) { timers, and semaphores. The size of the FreeRTOS heap is set by the configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */ taskDISABLE_INTERRUPTS(); - rust_alloc_failed(); + //rust_alloc_failed(); for (;;) ; } diff --git a/mission/uart_rust_helper.c b/mission/uart_rust_helper.c index c78b794..5a198d6 100644 --- a/mission/uart_rust_helper.c +++ b/mission/uart_rust_helper.c @@ -54,7 +54,7 @@ * change all the needed parameters in one place. */ #ifndef SDT -#define UARTLITE_DEVICE_ID XPAR_UARTLITE_0_DEVICE_ID +#define UARTLITE_DEVICE_ID 111 #else #define XUARTLITE_BASEADDRESS XPAR_XUARTLITE_0_BASEADDR #endif diff --git a/mission_rust/src/lib.rs b/mission_rust/src/lib.rs index f313c3f..c566f70 100644 --- a/mission_rust/src/lib.rs +++ b/mission_rust/src/lib.rs @@ -24,7 +24,7 @@ fn panic(panic: &PanicInfo<'_>) -> ! { sifln!(""); sif!("in task \""); unsafe { - //osal::get_task_name is implemented safely in C, so we trust it + //TODO is from_ptr safe enough? let task_name = core::ffi::CStr::from_ptr(osal::get_task_name()); let task_name_utf8 = core::str::from_utf8(task_name.to_bytes()); match task_name_utf8 { @@ -62,11 +62,6 @@ extern "C" fn rust_assert_called(ptr: *const core::ffi::c_char, line: core::ffi: panic!("assertion failed at {file_name}:{}", line); } -#[no_mangle] -extern "C" fn rust_alloc_failed(){ - panic!("allocation failed!"); -} - #[no_mangle] extern "C" fn rust_main() { sifln!("Rust startup 🚀"); @@ -206,7 +201,7 @@ fn mission() { gpio_setup(); sifln!(";"); sifln!("✅"); - gpio_toggle_pin(0x00000070); +// gpio_toggle_pin(0x00000070); sifln!("✅"); @@ -214,7 +209,7 @@ fn mission() { // canps_poll_example(); - + } sifln!("Called canps poll example()");