diff --git a/easy_embedded/service/_driver/CMakeLists.txt b/easy_embedded/service/_driver/CMakeLists.txt deleted file mode 100755 index 18d210e..0000000 --- a/easy_embedded/service/_driver/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -add_library(ez_driver STATIC) - -message(STATUS " Adding HAL Driver service") - -set(CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR}) -set(SDK_ROOT_DIR ${CMAKE_SOURCE_DIR}/ezmsdk/) -set(HAL_DRV_PATH "hal") - -if(ENABLE_EZ_HAL_ECHO) - message(STATUS " HAL Echo driver is activated") -endif() - -if(ENABLE_EZ_HAL_UART) - message(STATUS " HAL Uart driver is activated") -endif() - - -target_compile_definitions(ez_driver - PUBLIC - EZ_HAL_DRIVER=$ - WINDOWS_TARGET=$ - EZ_HAL_ECHO=$ - EZ_HAL_UART=$ -) - -target_sources(ez_driver PRIVATE - ez_driver_common.c - $<$:${HAL_DRV_PATH}/hal_echo/ez_hal_echo.c> - $<$:${HAL_DRV_PATH}/hal_uart/ez_hal_uart.c> -) - -target_include_directories(ez_driver PUBLIC - ${CURRENT_DIR} - ${SDK_ROOT_DIR} - ${HAL_DRV_PATH} -) - -target_link_libraries(ez_driver PUBLIC - ez_utilities - $<$:ez_windows_target> -) \ No newline at end of file diff --git a/easy_embedded/service/_driver/ez_driver_common.c b/easy_embedded/service/_driver/ez_driver_common.c deleted file mode 100755 index 360a491..0000000 --- a/easy_embedded/service/_driver/ez_driver_common.c +++ /dev/null @@ -1,136 +0,0 @@ - -/******************************************************************************* -* Filename: ez_driver_common.c -* Author: Hai Nguyen -* Original Date: 30.06.2023 -* Last Update: 30.06.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 30.06.2023 -* -*******************************************************************************/ - -/** @file ez_driver_common.c - * @author Hai Nguyen - * @date 30.06.2023 - * @brief This is the source for a module - * - * @details - * - */ - -/****************************************************************************** -* Includes -*******************************************************************************/ -#include "ez_driver_common.h" -#include "utilities/linked_list/ez_linked_list.h" -#include "utilities/assert/ez_assert.h" - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* Function Definitions -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* External functions -*******************************************************************************/ -ezDriverStatus_t ezDriverCommon_Initialized(struct ezDriver *driver) -{ - ezDriverStatus_t status = EZ_DRIVER_ERR_INIT; - struct ezDriverCommon *common = NULL; - - if (driver) - { - common = (struct ezDriverCommon *)driver->target_driver; - - ASSERT(common != NULL); - ASSERT(common->initialize != NULL); - ASSERT(common->get_configuration != NULL); - ASSERT(common->set_callback != NULL); - ASSERT(driver->callback != NULL); - - if (common - && common->initialize - && common->get_configuration - && common->set_callback) - { - if (common->initialize(common->index) == EZ_DRIVER_OK) - { - driver->configuration = common->get_configuration(common->index); - - if (driver->configuration) - { - ezmLL_InitNode(&driver->parent_list); - common->set_callback(common->index, driver->callback); - status = EZ_DRIVER_OK; - }/* else error cannot get configuration */ - }/* else error cannot initialize low level driver*/ - }/* else error common api are not set */ - }/* else error invalid arguments */ - - return status; -} - - -ezDriverStatus_t ezDriverCommon_Deinitialized(struct ezDriver *driver) -{ - ezDriverStatus_t status = EZ_DRIVER_ERR_GENERIC; - struct ezDriverCommon *common = NULL; - - if (driver) - { - common = (struct ezDriverCommon *)driver->target_driver; - - ASSERT(common != NULL); - ASSERT(common->deinitialize != NULL); - - if (common - && common->deinitialize - && common->deinitialize(common->index) == EZ_DRIVER_OK) - { - driver->target_driver = NULL; - driver->configuration = NULL; - driver->current_handle = NULL; - - status = EZ_DRIVER_OK; - }/* else error function pointer is null*/ - }/* else error invalid argument*/ - - return status; -} - - -/****************************************************************************** -* Internal functions -*******************************************************************************/ -/* None */ - -/* End of file*/ - diff --git a/easy_embedded/service/_driver/ez_driver_common.h b/easy_embedded/service/_driver/ez_driver_common.h deleted file mode 100755 index ff3b00d..0000000 --- a/easy_embedded/service/_driver/ez_driver_common.h +++ /dev/null @@ -1,193 +0,0 @@ - -/******************************************************************************* -* Filename: ez_driver_common.h -* Author: Hai Nguyen -* Original Date: 30.06.2023 -* Last Update: 30.06.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 30.06.2023 -* -*******************************************************************************/ - -/** @file ez_driver_common.h - * @author Hai Nguyen - * @date 30.06.2023 - * @brief This is the source for a module - * - * @details - * - */ - -#ifndef _EZ_DRIVER_COMMON_H -#define _EZ_DRIVER_COMMON_H - -/******************************************************************************* -* Includes -*******************************************************************************/ -#include "stdint.h" -#include "stdbool.h" -#include "ez_hal_driver_def.h" -#include "utilities/linked_list/ez_linked_list.h" - - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ - -/**< Get the target driver structure */ -#define GET_TARGET_DRIVER(target_driver_type, driver_handle) \ - ((target_driver_type)driver_handle->target_driver) \ - - -/**< Initialize a driver structure */ -#define INIT_DRIVER_STRUCT(driver_name, version_number, callback_func) \ - { \ - .initialized = false, \ - .name = driver_name, \ - .version = version_number, \ - .configuration = NULL, \ - .target_driver = NULL, \ - .current_handle = NULL, \ - .callback = callback_func, \ - } \ - - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Inline functions -*******************************************************************************/ - -/****************************************************************************** -* Function : ezDriverCommon_LockDriver -*//** -* @Description: Lock the driver by setting the handle as the current handle. -* Users must check if the driver is free be for lock it by calling -* ezDriverCommon_IsDriverAvail() -* -* @param (IN)handle: pointer to the handle -* @return None -* -*******************************************************************************/ -static inline void ezDriverCommon_LockDriver(ezDriverHandle_t *handle) -{ - handle->driver->current_handle = handle; -} - - -/****************************************************************************** -* Function : ezDriverCommon_UnlockDriver -*//** -* @Description: This function unlocks the driver by setting the current driver -* handle to NULL -* -* @param (IN)handle: pointer to the handle -* @return None -* -*******************************************************************************/ -static inline void ezDriverCommon_UnlockDriver(ezDriverHandle_t *handle) -{ - handle->driver->current_handle = NULL; -} - - -/****************************************************************************** -* Function : ezDriverCommon_IsDriverAvail -*//** -* @Description: This function checks if the driver is available. The function -* must be called prior to the lock function. -* -* @param (IN)handle: pointer to the handle -* @return true if the driver is available, else false -* -*******************************************************************************/ -static inline bool ezDriverCommon_IsDriverAvail(ezDriverHandle_t *handle) -{ - return ((handle->driver->current_handle == NULL) - || (handle->driver->current_handle == handle)); -} - - -/****************************************************************************** -* Function : ezDriverCommon_IsHandleRegistered -*//** -* @Description: This function checks if the handle is registered to the driver -* structure. The register function is normall the XXX_GetDriver() -* function. -* -* @param (IN)handle: pointer to the handle -* @return true is handle is registered, else false -* -*******************************************************************************/ -static inline bool ezDriverCommon_IsHandleRegistered(ezDriverHandle_t *handle) -{ - return ((handle != NULL) - && (handle->driver != NULL) - && (ezmLL_IsNodeInList(&handle->driver->parent_list, &handle->node))); -} - - -/****************************************************************************** -* Function : ezDriverCommon_Initialized -*//** -* @Description: This function initializes the driver structure. It must be -* called by every HAL driver to ensure coherence operation. -* -* Internally, this function link the target driver to the HAL driver and -* initializes the target driver. -* -* @param (IN)handle: pointer to the handle -* @return EZ_DRIVER_OK if success, else EZ_DRIVER_ERR_INIT -* -*******************************************************************************/ -ezDriverStatus_t ezDriverCommon_Initialized(struct ezDriver *driver); - - -/****************************************************************************** -* Function : ezDriverCommon_Deinitialized -*//** -* @Description: This function deinitializes the driver structure. It must be -* called by every HAL driver to ensure coherence operation. -* -* Internally, this function deinitializes the target driver and free the -* resources. The function can be used as the reset function to set the driver -* to known state. -* -* @param (IN)handle: pointer to the handle -* @return EZ_DRIVER_OK if success, else EZ_DRIVER_ERR_GENERIC -* -*******************************************************************************/ -ezDriverStatus_t ezDriverCommon_Deinitialized(struct ezDriver *driver); - - -/****************************************************************************** -* Function Prototypes -*******************************************************************************/ -/* None */ - -#endif /* _EZ_DRIVER_COMMON_H */ -/* End of file */ - diff --git a/easy_embedded/service/_driver/ez_hal_driver_def.h b/easy_embedded/service/_driver/ez_hal_driver_def.h deleted file mode 100755 index 35b0a94..0000000 --- a/easy_embedded/service/_driver/ez_hal_driver_def.h +++ /dev/null @@ -1,173 +0,0 @@ - -/******************************************************************************* -* Filename: ez_driver_def.h -* Author: Hai Nguyen -* Original Date: 12.06.2023 -* Last Update: 12.06.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 12.06.2023 -* -*******************************************************************************/ - -/** @file ez_driver_def.h - * @author Hai Nguyen - * @date 12.06.2023 - * @brief Boilerplate for the HAL driver module. All of the driver module must - * be implemented according to this template to ensure a unified and - * compatibility implementation of the HAL driver - * - * @details - - * - */ - -#ifndef _EZ_HAL_DRIVER_DEF_H -#define _EZ_HAL_DRIVER_DEF_H - -/******************************************************************************* -* Includes -*******************************************************************************/ -#include "stdint.h" -#include "stdbool.h" -#include "utilities/linked_list/ez_linked_list.h" - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ - -/** @brief Return status of the driver function - */ -typedef enum -{ - EZ_DRIVER_OK, /**< OK, function as expected */ - EZ_DRIVER_BUSY, /**< Driver is occupied by other module */ - EZ_DRIVER_ERR_NO_DRIVER,/**< Driver does not exist */ - EZ_DRIVER_ERR_INIT, /**< Error occur during initialization */ - EZ_DRIVER_ERR_GENERIC, /**< Generic, uncategorized error */ -}ezDriverStatus_t; - - -/****************************************************************************** -* Function : ezDriverCallback -*//** -* @Description: Callback to receive event from the target module -* -* @param (IN)cb_code: event code -* @param (IN)param1: first parameter, depending on cb_code -* @param (IN)param1: second parameter, depending on cb_code -* -* @return None -* -* -*******************************************************************************/ -typedef void (*ezDriverCallback)(uint8_t cb_code, - void *param1, - void *param2); - - -/** @brief Define driver's configuration. The actual implementation depends on - * individual target - */ -typedef void* ezDriverConfiguration_t; - - -/** @brief Define target driver. The actual implementation depends on individual - * target - */ -typedef void* ezTargetDriver_t; - - -/** @brief Define driver handle type - */ -typedef struct ezDriverHandle ezDriverHandle_t; - - -/** @brief - */ -typedef ezDriverStatus_t(*ezDriver_Initilialize)(uint8_t driver_index); - - -/** @brief - */ -typedef ezDriverStatus_t(*ezDriver_Deinitilialize)(uint8_t driver_index); - - -/** @brief - */ -typedef void (*ezDriver_SetCallback)(uint8_t driver_index, ezDriverCallback Callback); - - -/** @brief - */ -typedef ezDriverConfiguration_t *(*ezDriver_GetConfiguration)(uint8_t driver_index); - - -/** @brief Structure holds common data and function callbacks which must be - * implemented by every target driver. - */ -struct ezDriverCommon -{ - uint8_t index; /**< Index of the current driver */ - ezDriver_Initilialize initialize; /**< Pointer to initialize function */ - ezDriver_Deinitilialize deinitialize; /**< Pointer to deinitialize function */ - ezDriver_SetCallback set_callback; /**< Pointer to set callback function */ - ezDriver_GetConfiguration get_configuration; /**< Pointer to get configuration function */ -}; - - -/** @brief Contain information, data, API of a driver - */ -struct ezDriver -{ - bool initialized; /**< Driver inialized flag */ - const char *name; /**< Name of the driver */ - uint32_t version; /**< Version of the driver */ - ezDriverConfiguration_t configuration; /**< Point to the configuration */ - ezTargetDriver_t target_driver; /**< Point to the hardware api */ - ezDriverCallback callback; /**< Callback function */ - struct Node parent_list; /**< List of the module using the driver */ - ezDriverHandle_t *current_handle; /**< Handle currently "own" the driver */ -}; - - -/** @brief Hal driver handle for accessing the driver structure (see ezDriver) - */ -struct ezDriverHandle -{ - struct Node node; /**< Node of linked list */ - ezDriverCallback callback; /**< Callback function to receive event */ - struct ezDriver *driver; /**< pointer to the driver struct */ -}; - - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Function Prototypes -*******************************************************************************/ -/* None */ - -#endif /* _EZ_HAL_DRIVER_DEF_H */ - -/* End of file */ diff --git a/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo.c b/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo.c deleted file mode 100755 index 44f5604..0000000 --- a/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo.c +++ /dev/null @@ -1,303 +0,0 @@ - -/******************************************************************************* -* Filename: ez_hal_echo.c -* Author: Hai Nguyen -* Original Date: 13.06.2023 -* Last Update: 13.06.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 13.06.2023 -* -*******************************************************************************/ - -/** @file ez_hal_echo.c - * @author Hai Nguyen - * @date 13.06.2023 - * @brief Implementation of the HAL echo driver - * - * @details - - * - */ - -/****************************************************************************** -* Includes -*******************************************************************************/ -#include "ez_hal_echo.h" - -#define DEBUG_LVL LVL_DEBUG /**< logging level */ -#define MOD_NAME "ez_hal_echo" /**< module name */ - -#include "utilities/logging/ez_logging.h" -#include "utilities/assert/ez_assert.h" - -#if(WINDOWS_TARGET == 1) -#include "targets/windows/echo_driver/ez_windows_echo.h" -#endif - -#include "service/driver/ez_driver_common.h" -#include "service/driver/ez_hal_driver_def.h" -#include "ez_hal_echo_target_def.h" -#include "string.h" - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -#define ECHO_INTERFACE_1 0 /**< index of the hardware 1st device */ -#define ECHO_INTERFACE_2 1 /**< index of the hardware 1st device */ -#define NUM_OF_ECHO_INTERFACE 2 /**< Number of the supported devices*/ - - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Function Definitions -*******************************************************************************/ -static void ezHalEchoCallback1(uint8_t cb_code, void *param1, void *param2); -static void ezHalEchoCallback2(uint8_t cb_code, void *param1, void *param2); - - -static struct ezDriver echo_drivers[NUM_OF_ECHO_INTERFACE] = -{ - INIT_DRIVER_STRUCT(ECHO_INTERFACE_1_NAME, 10000, ezHalEchoCallback1), - INIT_DRIVER_STRUCT(ECHO_INTERFACE_2_NAME, 10000, ezHalEchoCallback2), -}; - - -/****************************************************************************** -* External functions -*******************************************************************************/ -ezDriverStatus_t ezHalEcho_Initialize(void) -{ - EZDEBUG("ezHalEcho_Initialize()"); - ezDriverStatus_t status = EZ_DRIVER_ERR_INIT;; - - - for (uint8_t i = 0; i < NUM_OF_ECHO_INTERFACE; i++) - { - EZDEBUG(" Init driver index = %d, name = %s", i, echo_drivers[i].name); - status = EZ_DRIVER_ERR_INIT; - -#if(WINDOWS_TARGET == 1) - echo_drivers[i].target_driver = (ezTargetDriver_t)ezTargetEcho_GetDriver(i); -#endif /* WINDOWS_TARGET == 1 */ - - status = ezDriverCommon_Initialized(&echo_drivers[i]); - if (status == EZ_DRIVER_OK) - { - /* set flag to indicate initialized is completed */ - echo_drivers[i].initialized = true; - } - else - { - /* error, stop init proccess */ - EZERROR(" Initialization failed"); - break; - } - } - - return status; -} - - -ezDriverStatus_t ezHalEcho_GetDriver(char *driver_name, - ezDriverHandle_t *handle, - ezDriverCallback callback) -{ - EZDEBUG("ezHalEcho_GetDriver(name = %s)", driver_name); - - ASSERT(driver_name != NULL); - ASSERT(handle != NULL); - ASSERT(callback != NULL); - - ezDriverStatus_t status = EZ_DRIVER_ERR_NO_DRIVER; - struct ezDriver *driver = NULL; - - if (driver_name && handle && callback) - { - for (uint8_t i = 0; i < NUM_OF_ECHO_INTERFACE; i++) - { - if (strcmp(driver_name, echo_drivers[i].name) == 0) - { - driver = &echo_drivers[i]; - EZDEBUG(" driver found"); - break; - } /* else string does not match */ - } - - if (driver) - { - if (!driver->initialized) - { - EZERROR(" Driver is not initialized"); - } - else - { - EZMLL_ADD_TAIL(&driver->parent_list, &handle->node); - handle->driver = driver; - handle->callback = callback; - - status = EZ_DRIVER_OK; - } - }/* else no drier found */ - } - - return status; -}; - - -ezDriverStatus_t ezHalEcho_ReleaseDriver(ezDriverHandle_t *handle) -{ - EZDEBUG("ezHalEcho_ReleaseDriver()"); - ezDriverStatus_t status = EZ_DRIVER_OK; - - ASSERT(handle != NULL); - - if (handle) - { - EZMLL_UNLINK_NODE(&handle->node); - handle->driver = NULL; - handle->callback = NULL; - }/* else invalid argument */ - - return status; -} - - -uint32_t ezHalEcho_Write(ezDriverHandle_t *handle, uint8_t *buff, uint32_t buff_size) -{ - uint32_t num_written_byte = 0; - const struct ezHalEchoDriver *target_driver = NULL; - - if (ezDriverCommon_IsHandleRegistered(handle) - && ezDriverCommon_IsDriverAvail(handle) - && buff - && buff_size > 0) - { - target_driver = GET_TARGET_DRIVER(const struct ezHalEchoDriver*, handle->driver); - - if (target_driver->api.Write) - { - ezDriverCommon_LockDriver(handle); - num_written_byte = target_driver->api.Write(target_driver->common.index, buff, buff_size); - - /* Unlock when receive callback or timeout */ - }/* else error function pointer is null */ - } - - return num_written_byte; -} - - -uint32_t ezHalEcho_Read(ezDriverHandle_t *handle, uint8_t *buff, uint32_t buff_size) -{ - uint32_t num_read_byte = 0; - const struct ezHalEchoDriver *target_driver = NULL; - - if (ezDriverCommon_IsHandleRegistered(handle) - && ezDriverCommon_IsDriverAvail(handle) - && buff - && buff_size > 0) - { - target_driver = GET_TARGET_DRIVER(const struct ezHalEchoDriver*, handle->driver); - - if (target_driver->api.Read) - { - ezDriverCommon_LockDriver(handle); - num_read_byte = target_driver->api.Read(target_driver->common.index, buff, buff_size); - - /* Unblock when receive callback or timeout */ - }/* else error function pointer is null */ - }/* else error invalid arguments */ - - return num_read_byte; -} - - -/****************************************************************************** -* Internal functions -*******************************************************************************/ - -/****************************************************************************** -* Function : ezHalEchoCallback1 -*//** -* @Description: Callback function to receive and handle the event from the -* target layer -* -* @param (IN)cb_code: event code from the tartget layer -* @param (IN)param1: pointer to the first parameter. Depend on cb_code -* @param (IN)param2: pointer to the second parameter. Depend on cb_code -* -* @return - -* -*******************************************************************************/ -static void ezHalEchoCallback1(uint8_t cb_code, void *param1, void *param2) -{ - if (echo_drivers[0].current_handle - && echo_drivers[0].current_handle->callback) - { - EZDEBUG("Executing callback"); - echo_drivers[0].current_handle->callback(cb_code, param1, param2); - } - else - { - EZERROR("No callback found"); - } - - ezDriverCommon_UnlockDriver(echo_drivers[0].current_handle); -} - - -/****************************************************************************** -* Function : ezHalEchoCallback2 -*//** -* @Description: Callback function to receive and handle the event from the -* target layer -* -* @param (IN)cb_code: event code from the tartget layer -* @param (IN)param1: pointer to the first parameter. Depend on cb_code -* @param (IN)param2: pointer to the second parameter. Depend on cb_code -* -* @return - -* -*******************************************************************************/ -static void ezHalEchoCallback2(uint8_t cb_code, void *param1, void *param2) -{ - if (echo_drivers[1].current_handle - && echo_drivers[1].current_handle->callback) - { - EZDEBUG("Executing callback"); - echo_drivers[1].current_handle->callback(cb_code, param1, param2); - } - else - { - EZERROR("No callback found"); - } - - ezDriverCommon_UnlockDriver(echo_drivers[1].current_handle); -} - - -/* End of file*/ - diff --git a/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo.h b/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo.h deleted file mode 100755 index dd8edd0..0000000 --- a/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo.h +++ /dev/null @@ -1,144 +0,0 @@ - -/******************************************************************************* -* Filename: ez_hal_echo.h -* Author: Hai Nguyen -* Original Date: 13.06.2023 -* Last Update: 13.06.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 13.06.2023 -* -*******************************************************************************/ - -/** @file ez_hal_echo.h - * @author Hai Nguyen - * @date 13.06.2023 - * @brief Public functions to use the echo driver - * - * @details - - * - */ - -#ifndef _EZ_HAL_ECHO_H -#define _EZ_HAL_ECHO_H - -/******************************************************************************* -* Includes -*******************************************************************************/ -#include "service/driver/ez_hal_driver_def.h" -#include "stdint.h" -#include "stdbool.h" - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -#define ECHO_INTERFACE_1_NAME "echo_interface_1" -#define ECHO_INTERFACE_2_NAME "echo_interface_2" - - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* Function Prototypes -*******************************************************************************/ - -/****************************************************************************** -* Function : ezHalEcho_Initialize -*//** -* @Description: Initialize the HAL Echo driver. -* -* Internally, this function bind the HAL driver to the target -* driver and initialize the target driver -* -* @param: - -* -* @return EZ_DRIVER_OK is success, else error code -* -*******************************************************************************/ -ezDriverStatus_t ezHalEcho_Initialize(void); - - -/****************************************************************************** -* Function : ezHalEcho_GetDriver -*//** -* @Description: Get the driver handle. Additionall, register a callback for -* receiving event -* -* @param (IN)driver_name: name of the driver -* @param (OUT)handle: driver handle -* @param (IN)callback: callback to receive events from the HAL -* -* @return EZ_DRIVER_OK is success, else EZ_DRIVER_ERR_NO_DRIVER -* -*******************************************************************************/ -ezDriverStatus_t ezHalEcho_GetDriver(char *driver_name, - ezDriverHandle_t *handle, - ezDriverCallback callback); - - -/****************************************************************************** -* Function : ezHalEcho_ReleaseDriver -*//** -* @Description: Release the driver. Release the resources -* -* @param (IN)handle: pointer to driver handle -* -* @return Always return EZ_DRIVER_OK -* -*******************************************************************************/ -ezDriverStatus_t ezHalEcho_ReleaseDriver(ezDriverHandle_t *handle); - - -/****************************************************************************** -* Function : ezHalEcho_Write -*//** -* @Description: Write data to the echo device -* -* @param (IN)handle: name of the driver -* @param (IN)buff: data to be written -* @param (IN)buff_size: size of written buffer -* -* @return Number of bytes written in the echo device -* -*******************************************************************************/ -uint32_t ezHalEcho_Write(ezDriverHandle_t *handle, uint8_t *buff, uint32_t buff_size); - - -/****************************************************************************** -* Function : ezHalEcho_Read -*//** -* @Description: Read data from the echo device -* -* @param (IN)handle: name of the driver -* @param (OUT)buff: data to be read -* @param (IN)buff_size: size of read buffer -* -* @return Number of bytes read from the echo device -* -*******************************************************************************/ -uint32_t ezHalEcho_Read(ezDriverHandle_t *handle, uint8_t *buff, uint32_t buff_size); - - -#endif /* _EZ_HAL_ECHO_H */ - -/* End of file */ - diff --git a/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo_target_def.h b/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo_target_def.h deleted file mode 100755 index cacca32..0000000 --- a/easy_embedded/service/_driver/hal/hal_echo/ez_hal_echo_target_def.h +++ /dev/null @@ -1,160 +0,0 @@ - -/******************************************************************************* -* Filename: ez_hal_echo_def.h.h -* Author: Hai Nguyen -* Original Date: 18.06.2023 -* Last Update: 18.06.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 18.06.2023 -* -*******************************************************************************/ - -/** @file ez_hal_echo_target_def.h - * @author Hai Nguyen - * @date 18.06.2023 - * @brief Boilerplate for the echo target. Every implmentation of the target - * must implemented according to this template - * - * @details - * - */ - -#ifndef _EZ_HAL_ECHO_TARGET_DEF_H -#define _EZ_HAL_ECHO_TARGET_DEF_H - -/******************************************************************************* -* Includes -*******************************************************************************/ -#include "string.h" -#include "stdint.h" -#include "stdbool.h" -#include "service/driver/ez_driver_common.h" - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ - -/** @brief Define events returned by the target driver. - */ -typedef enum -{ - ECHO_TX_CMPLT, /* Transmit commplete */ - ECHO_RX_CMPLT, /* Receive complete */ - ECHO_ERR, /* Error */ -}ezHalEchoCallbackCode; - - -/****************************************************************************** -* Function : ezEcho_TargetWrite -*//** -* @Description: Write data to buffer. -* Define the function which must be implemented by the target driver -* -* @param: (IN)driver_index: index of the driver. -* @param: (IN)data: pointer to the written data. -* @param: (IN)data_size: size of written data. -* -* @return Number of written data -* -*******************************************************************************/ -typedef uint32_t(*ezEcho_TargetWrite)(uint8_t driver_index, - uint8_t *data, - uint32_t data_size); - - -/****************************************************************************** -* Function : ezEcho_TargeRead -*//** -* @Description: Read data from buffer. -* Define the function which must be implemented by the target driver -* -* @param: (IN)driver_index: index of the driver. -* @param: (OUT)data: pointer to the read data. -* @param: (IN)data_size: size of written data. -* -* @return Number of read data -* -*******************************************************************************/ -typedef uint32_t(*ezEcho_TargeRead)(uint8_t driver_index, - uint8_t *data, - uint32_t data_size); - - -/****************************************************************************** -* Function : ezEcho_TargetInitialize -*//** -* @Description: Initialize driver. -* Define the function which must be implemented by the target driver -* -* @param: (IN)driver_index: index of the driver. -* -* @return - -* -*******************************************************************************/ -typedef void (*ezEcho_TargetInitialize)(uint8_t driver_index); - - -/** @brief Configuration of the Echo Driver - */ -struct ezHalEchoConfiguration -{ - uint32_t size_of_ring_buff; /**< size of the ring buffer holding data for echoing */ -}; - - -/** @brief Hold the functions must be implemented by the target driver. - * These functions are expected by the Echo HAL layer - */ -struct ezTargetEchoApi -{ - ezEcho_TargetWrite Write; /**< Pointer to the write function */ - ezEcho_TargeRead Read; /**< Pointer to the read function */ -}; - - -/** @brief Hold the data and api, which must be implemented by the targer driver. - * This block is the boiler plate for the implementation of the driver. - */ -struct ezHalEchoDriver -{ - struct ezDriverCommon common; /**< Common data and function, MUST BE THE FIRST ELEMENT OF STRUCT */ - struct ezHalEchoConfiguration config; /**< Configuration of the target driver */ - struct ezTargetEchoApi api; /**< Pointer to the API implementation */ -}; - - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Function Prototypes -*******************************************************************************/ -/* None */ - - -#endif /* _EZ_HAL_ECHO_TARGET_DEF_H */ - -/* End of file */ - diff --git a/easy_embedded/service/_driver/hal/hal_uart/ez_hal_uart.c b/easy_embedded/service/_driver/hal/hal_uart/ez_hal_uart.c deleted file mode 100755 index e8e3f33..0000000 --- a/easy_embedded/service/_driver/hal/hal_uart/ez_hal_uart.c +++ /dev/null @@ -1,428 +0,0 @@ - -/******************************************************************************* -* Filename: ez_hal_uart.c -* Author: Hai Nguyen -* Original Date: 25.06.2023 -* Last Update: 07.03.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 25.06.2023 -* -*******************************************************************************/ - -/** @file ez_hal_uart.c - * @author Hai Nguyen - * @date 25.06.2023 - * @brief Implementation of the UART HAL Driver - * - * @details - * - */ - -/****************************************************************************** -* Includes -*******************************************************************************/ -#include "ez_hal_uart.h" - -#define DEBUG_LVL LVL_TRACE /**< logging level */ -#define MOD_NAME "ez_hal_uart" /**< module name */ - -#include "service/driver/ez_driver_common.h" - -#include "utilities/logging/ez_logging.h" -#include "utilities/assert/ez_assert.h" -#include "utilities/linked_list/ez_linked_list.h" - -#if(WINDOWS_TARGET) -#include "targets/windows/uart_driver/ez_windows_uart.h" -#endif - - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Function Definitions -*******************************************************************************/ - -#if (NUM_OF_UART_INTERFACE > 0) -static void ezHalUart_Callback1(uint8_t cb_code, - void *param1, - void *param2); -#endif /* (NUM_OF_UART_INTERFACE > 0) */ - -#if (NUM_OF_UART_INTERFACE > 1) -static void ezHalUart_Callback2(uint8_t cb_code, - void *param1, - void *param2); -#endif /* (NUM_OF_UART_INTERFACE > 1) */ - -static struct ezDriver uart_drivers[NUM_OF_UART_INTERFACE] = -{ -#if (NUM_OF_UART_INTERFACE > 0) - INIT_DRIVER_STRUCT(UART0_NAME, 10000, ezHalUart_Callback1), -#endif /* (NUM_OF_UART_INTERFACE > 0) */ - -#if (NUM_OF_UART_INTERFACE > 1) - INIT_DRIVER_STRUCT(UART1_NAME, 10000, ezHalUart_Callback2), -#endif /* (NUM_OF_UART_INTERFACE > 1) */ -}; - -/****************************************************************************** -* External functions -*******************************************************************************/ - -ezDriverStatus_t ezHalUart_Initialize(void) -{ - EZDEBUG("ezHalUart_Initialize()"); - ezDriverStatus_t status = EZ_DRIVER_ERR_INIT; - - for (uint8_t i = 0; i < NUM_OF_UART_INTERFACE; i++) - { - EZDEBUG(" Init driver index = %d, name = %s", i, uart_drivers[i].name); - status = EZ_DRIVER_ERR_INIT; - -#if(WINDOWS_TARGET == 1) - uart_drivers[i].target_driver = (ezTargetDriver_t)ezWinUart_GetDriver(i); -#endif /* WINDOWS_TARGET == 1 */ - - status = ezDriverCommon_Initialized(&uart_drivers[i]); - if (status == EZ_DRIVER_OK) - { - /* set flag to indicate initialized is completed */ - uart_drivers[i].initialized = true; - } - else - { - /* error, stop init proccess */ - EZERROR(" Initialization failed"); - break; - } - } - - return status; -} - - -ezDriverStatus_t ezHalUart_Deinitialize(void) -{ - EZDEBUG("ezHalUart_Deinitialize()"); - - ezDriverStatus_t status = EZ_DRIVER_ERR_GENERIC; - - for (uint8_t i = 0; i < NUM_OF_UART_INTERFACE; i++) - { - status = ezDriverCommon_Deinitialized(&uart_drivers[i]); - if (status == EZ_DRIVER_OK) - { - uart_drivers[i].initialized = false; - } - else - { - /* error, stop deinit proccess */ - break; - } - } - - return status; -} - - -ezDriverStatus_t ezHalUart_GetDriver(char *driver_name, - ezDriverHandle_t *handle, - ezDriverCallback callback) -{ - ASSERT(driver_name != NULL); - ASSERT(handle != NULL); - ASSERT(callback != NULL); - - ezDriverStatus_t status = EZ_DRIVER_ERR_NO_DRIVER; - struct ezDriver *driver = NULL; - - EZDEBUG("ezHalUart_GetDriver(name = %s)", driver_name); - - if (driver_name && handle && callback) - { - for (uint8_t i = 0; i < NUM_OF_UART_INTERFACE; i++) - { - if (strcmp(driver_name, uart_drivers[i].name) == 0) - { - driver = &uart_drivers[i]; - EZDEBUG(" driver found"); - break; - } /* else string does not match */ - } - - if (driver) - { - if (!driver->initialized) - { - EZERROR(" Driver is not initialized"); - } - else - { - EZMLL_ADD_TAIL(&driver->parent_list, &handle->node); - handle->driver = driver; - handle->callback = callback; - - status = EZ_DRIVER_OK; - } - }/* else no drier found */ - } - - return status; -} - - -ezDriverStatus_t ezHalUart_ReleaseDriver(ezDriverHandle_t *handle) -{ - ezDriverStatus_t status = EZ_DRIVER_OK; - ASSERT(handle != NULL); - - if (handle) - { - EZMLL_UNLINK_NODE(&handle->node); - }/* else invalid argument */ - - return status; -} - - -uint32_t ezHalUart_WriteBlocking(ezDriverHandle_t *handle, - uint8_t *buff, - uint32_t buff_size) -{ - ASSERT(handle != NULL); - ASSERT(buff != NULL); - - uint32_t num_written_bytes = 0; - const struct ezTargetUartDriver *driver = NULL; - - if (ezDriverCommon_IsHandleRegistered(handle) - && ezDriverCommon_IsDriverAvail(handle) - && buff - && buff_size > 0) - { - driver = GET_TARGET_DRIVER(const struct ezTargetUartDriver*, handle->driver); - ezDriverCommon_LockDriver(handle); - - if (driver->api.write_blocking) - { - num_written_bytes = driver->api.write_blocking(driver->common.index, - buff, - buff_size); - }/* else error function pointer is null */ - - ezDriverCommon_UnlockDriver(handle); - }/* else error invalid arguments */ - - return num_written_bytes; -} - - -uint32_t ezHalUart_ReadBlocking(ezDriverHandle_t *handle, uint8_t *buff, uint32_t buff_size) -{ - ASSERT(handle != NULL); - ASSERT(buff != NULL); - - uint32_t num_read_bytes = 0; - const struct ezTargetUartDriver *driver = NULL; - - if (ezDriverCommon_IsHandleRegistered(handle) - && ezDriverCommon_IsDriverAvail(handle) - && buff - && buff_size > 0) - { - driver = GET_TARGET_DRIVER(const struct ezTargetUartDriver*, handle->driver); - ezDriverCommon_LockDriver(handle); - - if (driver->api.read_blocking) - { - num_read_bytes = driver->api.read_blocking(driver->common.index, - buff, - buff_size); - }/* else error function pointer is null */ - - /* Blocking operation so unlock the driver */ - ezDriverCommon_UnlockDriver(handle); - - }/* else error invalid arguments */ - - return num_read_bytes; -} - - -uint32_t ezHalUart_Write(ezDriverHandle_t *handle, - uint8_t *buff, - uint32_t buff_size) -{ - ASSERT(handle != NULL); - ASSERT(buff != NULL); - - uint32_t num_written_bytes = 0; - const struct ezTargetUartDriver *driver = NULL; - - if (ezDriverCommon_IsHandleRegistered(handle) - && ezDriverCommon_IsDriverAvail(handle) - && buff - && buff_size > 0) - { - driver = GET_TARGET_DRIVER(const struct ezTargetUartDriver*, handle->driver); - - if (driver->api.write) - { - ezDriverCommon_LockDriver(handle); - num_written_bytes = driver->api.write(driver->common.index, - buff, - buff_size); - } - else - { - EZWARNING(" ezHalUart_Write() is not supported by target driver"); - } - - }/* else error invalid arguments */ - - return num_written_bytes; -} - - -uint32_t ezHalUart_Read(ezDriverHandle_t *handle, - uint8_t *buff, - uint32_t buff_size) -{ - ASSERT(handle != NULL); - ASSERT(buff != NULL); - - uint32_t num_read_bytes = 0; - const struct ezTargetUartDriver *driver = NULL; - - if (ezDriverCommon_IsHandleRegistered(handle) - && ezDriverCommon_IsDriverAvail(handle) - && buff - && buff_size > 0) - { - driver = GET_TARGET_DRIVER(const struct ezTargetUartDriver*, handle->driver); - - if (driver->api.read) - { - ezDriverCommon_LockDriver(handle); - num_read_bytes = driver->api.read(driver->common.index, - buff, - buff_size); - } - else - { - EZWARNING(" ezHalUart_Read() is not supported by target driver"); - } - - }/* else error invalid arguments */ - - return num_read_bytes; -} - - -/****************************************************************************** -* Internal functions -*******************************************************************************/ - -#if (NUM_OF_UART_INTERFACE > 0) -/****************************************************************************** -* Function : ezHalUart_Callback1 -*//** -* @Description: -* -* This function recieves the event from the target driver, checks which module is -* using the driver and forwards the event and data to that module. In case no -* module uses the driver (error), the event and its data will be discarded. -* -* @param (IN)cb_code: event code, depend on the driver. See ezHalUartCallbackCode_t -* @param (IN)param1: Point to the first parameter, can be NULL. -* @param (IN)param2: Point to the second parameter, can be NULL. -* -* @return None -* -*******************************************************************************/ -static void ezHalUart_Callback1(uint8_t cb_code, - void *param1, - void *param2) -{ - if (uart_drivers[0].current_handle - && uart_drivers[0].current_handle->callback) - { - EZDEBUG("Executing callback"); - uart_drivers[0].current_handle->callback(cb_code, param1, param2); - } - else - { - EZERROR("No callback found"); - } - - ezDriverCommon_UnlockDriver(uart_drivers[0].current_handle); -} -#endif /* (NUM_OF_UART_INTERFACE > 0) */ - -#if (NUM_OF_UART_INTERFACE > 1) -/****************************************************************************** -* Function : ezHalUart_Callback1 -*//** -* @Description: -* -* This function recieves the event from the target driver, checks which module is -* using the driver and forwards the event and data to that module. In case no -* module uses the driver (error), the event and its data will be discarded. -* -* @param (IN)cb_code: event code, depend on the driver. See ezHalUartCallbackCode_t -* @param (IN)param1: Point to the first parameter, can be NULL. -* @param (IN)param2: Point to the second parameter, can be NULL. -* -* @return None -* -*******************************************************************************/ -static void ezHalUart_Callback2(uint8_t cb_code, - void *param1, - void *param2) -{ - if (uart_drivers[1].current_handle - && uart_drivers[1].current_handle->callback) - { - EZDEBUG("Executing callback"); - uart_drivers[1].current_handle->callback(cb_code, param1, param2); - } - else - { - EZERROR("No callback found"); - } - - ezDriverCommon_UnlockDriver(uart_drivers[1].current_handle); -} -#endif /* (NUM_OF_UART_INTERFACE > 1) */ - -/* End of file*/ diff --git a/easy_embedded/service/_driver/hal/hal_uart/ez_hal_uart.h b/easy_embedded/service/_driver/hal/hal_uart/ez_hal_uart.h deleted file mode 100755 index b3f5409..0000000 --- a/easy_embedded/service/_driver/hal/hal_uart/ez_hal_uart.h +++ /dev/null @@ -1,213 +0,0 @@ - -/******************************************************************************* -* Filename: ez_hal_uart.h -* Author: Hai Nguyen -* Original Date: 25.06.2023 -* Last Update: 25.06.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 25.06.2023 -* -*******************************************************************************/ - -/** @file ez_hal_uart.h - * @author Hai Nguyen - * @date 25.06.2023 - * @brief Public function to use the HAL UART driver - * - * @details - * - */ - -#ifndef _EZ_HAL_UART_H -#define _EZ_HAL_UART_H - -/******************************************************************************* -* Includes -*******************************************************************************/ -#include "stdint.h" -#include "stdbool.h" -#include "service/driver/ez_hal_driver_def.h" -#include "hal_uart/ez_target_uart_def.h" - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ -/* None */ - - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* Function Prototypes -*******************************************************************************/ - -/****************************************************************************** -* Function : ezHalUart_Initialize -*//** -* @Description: -* -* This function initializes the UART abstraction layer -* -* @param None -* @return None -* -*******************************************************************************/ -ezDriverStatus_t ezHalUart_Initialize(void); - - -/****************************************************************************** -* Function : ezHalUart_Deinitialize -*//** -* @Description: -* -* This function deinitializes the UART abstraction layer -* -* @param None -* @return None -* -*******************************************************************************/ -ezDriverStatus_t ezHalUart_Deinitialize(void); - - -/****************************************************************************** -* Function : ezHalUart_GetDriver -*//** -* @Description: -* -* This function returns the driver handle which giving access to the HAL api -* -* @param (IN)driver_name: Name of the driver in used -* @param (IN)handle: driver handle to access the driver -* @param (IN)callback: callback function to handle the event -* -* @return EZ_DRIVER_OK if success, else ERROR status -* -*******************************************************************************/ -ezDriverStatus_t ezHalUart_GetDriver(char *driver_name, - ezDriverHandle_t *handle, - ezDriverCallback callback); - - -/****************************************************************************** -* Function : ezHalUart_Deinitialize -*//** -* @Description: -* -* This function releases the driver which is previously used by -* ezHalUart_GetDriver() -* -* @param (IN)handle: driver handle -* -* @return EZ_DRIVER_OK if success, else ERROR status -* -*******************************************************************************/ -ezDriverStatus_t ezHalUart_ReleaseDriver(ezDriverHandle_t *handle); - - -/****************************************************************************** -* Function : ezHalUart_WriteBlocking -*//** -* @Description: -* -* This function uses the driver handle to send data to UART bus. This is a -* blocking function. -* -* @param (IN)handle: driver handle, see ezHalUart_GetDriver() -* @param (IN)buff: buffer to be written -* @param (IN)buff_size: size of buff -* -* @return Number of byte being written. -* -*******************************************************************************/ -uint32_t ezHalUart_WriteBlocking(ezDriverHandle_t *handle, - uint8_t *buff, - uint32_t buff_size); - - -/****************************************************************************** -* Function : ezHalUart_ReadBlocking -*//** -* @Description: -* -* This function uses the driver handle to read data from UART bus. This is a -* blocking function. -* -* @param (IN)handle: driver handle, see ezHalUart_GetDriver() -* @param (IN)buff: buffer to store read data -* @param (IN)buff_size: size of buff -* -* @return Number of byte being read. -* -*******************************************************************************/ -uint32_t ezHalUart_ReadBlocking(ezDriverHandle_t *handle, - uint8_t *buff, - uint32_t buff_size); - - -/****************************************************************************** -* Function : ezHalUart_WriteBlocking -*//** -* @Description: -* -* This function uses the driver handle to send data to UART bus. This is a -* non blocking function. -* -* @param (IN)handle: driver handle, see ezHalUart_GetDriver() -* @param (IN)buff: buffer to be written -* @param (IN)buff_size: size of buff -* -* @return Number of byte being written. -* -*******************************************************************************/ -uint32_t ezHalUart_Write(ezDriverHandle_t *handle, - uint8_t *buff, - uint32_t buff_size); - - - -/****************************************************************************** -* Function : ezHalUart_ReadBlocking -*//** -* @Description: -* -* This function uses the driver handle to read data from UART bus. This is a -* non blocking function. -* -* @param (IN)handle: driver handle, see ezHalUart_GetDriver() -* @param (IN)buff: buffer to store read data -* @param (IN)buff_size: size of buff -* -* @return Number of byte being read. -* -*******************************************************************************/ -uint32_t ezHalUart_Read(ezDriverHandle_t *handle, - uint8_t *buff, - uint32_t buff_size); - - -#endif /* _EZ_HAL_UART_H */ - -/* End of file */ - diff --git a/easy_embedded/service/_driver/hal/hal_uart/ez_target_uart_def.h b/easy_embedded/service/_driver/hal/hal_uart/ez_target_uart_def.h deleted file mode 100755 index 7e2b8a8..0000000 --- a/easy_embedded/service/_driver/hal/hal_uart/ez_target_uart_def.h +++ /dev/null @@ -1,266 +0,0 @@ - -/******************************************************************************* -* Filename: ez_hal_uart_target_def.h -* Author: Hai Nguyen -* Original Date: 25.06.2023 -* Last Update: 07.03.2023 -* -* ----------------------------------------------------------------------------- -* Company: Embedded Easy -* Address Line 1 -* Address Line 2 -* -* ----------------------------------------------------------------------------- -* Contact: Embedded Easy -* hainguyen.ezm@gmail.com -* -* ----------------------------------------------------------------------------- -* Copyright Hai Nguyen - All Rights Reserved -* Unauthorized copying of this file, via any medium is strictly prohibited -* Proprietary and confidential -* Written by Hai Nguyen 25.06.2023 -* -*******************************************************************************/ - -/** @file ez_hal_uart_target_def.h - * @author Hai Nguyen - * @date 25.06.2023 - * @brief This file provide the boilerplate for every implementation of the - * UART driver. - * - * @details The Uart driver in the target device must be implemented following - * this template to guarantee a smooth operation between the target - * and the HAL driver - */ - -#ifndef _EZ_TARGET_UART_DEF_H -#define _EZ_TARGET_UART_DEF_H - -/******************************************************************************* -* Includes -*******************************************************************************/ -#include "string.h" -#include "stdint.h" -#include "stdbool.h" - - -/****************************************************************************** -* Module Preprocessor Macros -*******************************************************************************/ -#ifndef NUM_OF_UART_INTERFACE -#define NUM_OF_UART_INTERFACE 2 /**< Number of the supported devices*/ -#endif /* NUM_OF_UART_INTERFACE */ - -#if (NUM_OF_UART_INTERFACE > 0) - #ifndef UART0_NAME - #define UART0_NAME "uart1" /**< Name of the first UART */ - #endif /* UART0_NAME */ - - #ifndef UART0_INDEX - #define UART0_INDEX 0 /**< index of the first UART */ - #endif /* UART0_INDEX */ -#endif /* (NUM_OF_UART_INTERFACE > 0) */ - -#if (NUM_OF_UART_INTERFACE > 1) - #ifndef UART1_NAME - #define UART1_NAME "uart2" /**< Name of the second UART */ - #endif /* UART1_NAME */ - - #ifndef UART1_INDEX - #define UART1_INDEX 1 /**< index of the second UART */ - #endif /* UART1_INDEX */ -#endif /* (NUM_OF_UART_INTERFACE > 1) */ - -#if(WINDOWS_TARGET) - #ifndef UART_PORT - #define UART_PORT "COM1" /**< Connected port of the first driver */ - #endif /* UART_PORT */ -#endif /* WINDOWS_TARGET */ - -/****************************************************************************** -* Module Typedefs -*******************************************************************************/ - -/** @brief Event code from the UART driver - */ -typedef enum -{ - UART_TX_CMPLT, /**< Transmit completed */ - UART_RX_CMPLT, /**< Reception completed */ - UART_ERROR, /**< Error occured*/ -}ezHalUartCallbackCode_t; - - -/** @brief Number of stop bit - */ -typedef enum -{ - ONE_BIT, /**< 1 stop bit */ - ONE_AND_HALF_BIT, /**< 1.5 stop bit */ - TWO_BITS, /**< 2 stop bits */ -}ezHalUartStopBit_t; - - -/** @brief Parity value - */ -typedef enum -{ - PARITY_NONE, /**< None */ - PARITY_ODD, /**< Odd */ - PARITY_EVEN, /**< Even */ - PARITY_MARK, /**< Mark */ - PARITY_SPACE, /**< Space */ -}ezHalUartParity_t; - - -/** @brief Target configuration data - */ -struct ezTargetUartConfiguration -{ - char *port_name; /**< Name of the serial port */ - uint8_t byte_size; /**< Size of data in bit */ - uint32_t baudrate; /**< Baudrate*/ - ezHalUartParity_t parity; /**< Parity */ - ezHalUartStopBit_t stop_bit; /**< Number of Stop bit */ -}; - - -/** @brief Define callback for uart driver - */ -typedef ezDriverCallback ezUartCallback; - - -/****************************************************************************** -* Function : ezTargetUart_Initialize -*//** -* @Description: Initialize the target driver -* -* @param (IN)driver_index: index of the driver -* -* @return true if success, else false -* -*******************************************************************************/ -typedef bool(*ezTargetUart_Initialize)(uint8_t driver_index); - - -/****************************************************************************** -* Function : ezTargetUart_Deinitialize -*//** -* @Description: Deinitialize the target driver -* -* @param (IN)driver_index: index of the driver -* -* @return true if success, else false -* -*******************************************************************************/ -typedef bool(*ezTargetUart_Deinitialize)(uint8_t driver_index); - - -/****************************************************************************** -* Function : ezTargetUart_Write -*//** -* @Description: Write data to targer UART bus. Non blocking operation. -* If the operation is comnpleted. Callback function is triggered -* with the return code UART_TX_CMPLT. -* -* @param (IN)driver_index: index of the driver -* @param (IN)data: data to be written -* @param (IN)data_size: number of byte to be written -* -* @return Number of bytes are actually written on the bus -* -*******************************************************************************/ -typedef uint32_t(*ezTargetUart_Write)(uint8_t driver_index, - uint8_t *data, - uint32_t data_size); - - -/****************************************************************************** -* Function : ezTargetUart_Read -*//** -* @Description: Read data to targer UART bus. Non blocking operation. -* If the operation is comnpleted. Callback function is triggered -* with the return code UART_RX_CMPLT. -* -* @param (IN)driver_index: index of the driver -* @param (IN)data_size: number of byte to be read -* -* @return Number of bytes are actually read from the bus -* -*******************************************************************************/ -typedef uint32_t(*ezTargetUart_Read)(uint8_t driver_index, - uint8_t *data, - uint32_t data_size); - - -/****************************************************************************** -* Function : ezTargetUart_WriteBlocking -*//** -* @Description: Write data to targer UART bus. Blocking operation. -* -* @param (IN)driver_index: index of the driver -* @param (IN)data: data to be written -* @param (IN)data_size: number of byte to be written -* -* @return Number of bytes are actually written on the bus -* -*******************************************************************************/ -typedef uint32_t(*ezTargetUart_WriteBlocking)(uint8_t driver_index, - uint8_t *data, - uint32_t data_size); - - -/****************************************************************************** -* Function : ezTargetUart_ReadBlocking -*//** -* @Description: Read data to targer UART bus. Blocking operation. -* -* @param (IN)driver_index: index of the driver -* @param (IN)data: buffer containing read data -* @param (IN)data_size: number of byte to be read -* -* @return Number of bytes are actually read from the bus -* -*******************************************************************************/ -typedef uint32_t(*ezTargetUart_ReadBlocking)(uint8_t driver_index, - uint8_t *data, - uint32_t data_size); - - -/** @brief Hold the functions must be implemented by the target driver. - * These functions are expected by the Uart HAL layer - */ -struct ezTargetUartApi -{ - ezTargetUart_Write write; /**< Pointer to the write function */ - ezTargetUart_WriteBlocking write_blocking; /**< Pointer to the blocking write function */ - ezTargetUart_Read read; /**< Pointer to the read function */ - ezTargetUart_ReadBlocking read_blocking; /**< Pointer to the blocking read function */ -}; - - -/** @brief Hold the data and api, which must be implemented by the targer driver. - * This block is the boiler plate for the implementation of the driver. - */ -struct ezTargetUartDriver -{ - struct ezDriverCommon common; /**< Common data and function, MUST BE THE FIRST ELEMENT OF STRUCT */ - struct ezTargetUartApi api; /**< Pointer to the API implementation */ - struct ezTargetUartConfiguration config; /**< Configuration of the target driver */ -}; - - -/****************************************************************************** -* Module Variable Definitions -*******************************************************************************/ -/* None */ - -/****************************************************************************** -* Function Prototypes -*******************************************************************************/ -/* None */ - -#endif /* _EZ_TARGET_UART_DEF_H */ - -/* End of file */ -