From dd1cfab956c379a7912f2ed5ccf6213bce712843 Mon Sep 17 00:00:00 2001 From: fancy <258828110.@qq.com> Date: Sun, 19 Nov 2023 07:30:45 -0800 Subject: [PATCH] Improve hal module. --- application/main/src/MainThread.cpp | 1 + hal/CMakeLists.txt | 5 ++++- hal/abstract/IHal.cpp | 2 +- hal/include/IHal.h | 2 +- hal/src/Hal.c | 12 +++++------- hal/src/Hal.h | 1 + 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/application/main/src/MainThread.cpp b/application/main/src/MainThread.cpp index 417c57a0..b567ea07 100644 --- a/application/main/src/MainThread.cpp +++ b/application/main/src/MainThread.cpp @@ -45,6 +45,7 @@ StatusCode MainThread::UnInit(void) } StatusCode MainThread::CreateAllModules(void) { + CreateLogModule(); CreateHalModule(); return CreateStatusCode(STATUS_CODE_OK); } diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index 8fda88a4..a1c9ef0a 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -58,4 +58,7 @@ add_custom_command( COMMAND make Hal_code_format WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ ) -endif() \ No newline at end of file +endif() + +define_file_name(${IMPL_TARGET}) +define_file_name(${ABSTRACT_TARGET}) \ No newline at end of file diff --git a/hal/abstract/IHal.cpp b/hal/abstract/IHal.cpp index 0db46f6f..e8517921 100644 --- a/hal/abstract/IHal.cpp +++ b/hal/abstract/IHal.cpp @@ -18,7 +18,7 @@ // #include #include static StatusCode IHalInit(IHal *object) { return IHalCpp::GetInstance()->Init(); } -static void IHalFree(IHal *object) {} +static void IHalFree(void *object) {} static StatusCode IHalUnInit(IHal *object) { return IHalCpp::GetInstance()->UnInit(); } static IHal default_hal = { .init = IHalInit, diff --git a/hal/include/IHal.h b/hal/include/IHal.h index f6bb7dc5..be031b3e 100644 --- a/hal/include/IHal.h +++ b/hal/include/IHal.h @@ -23,7 +23,7 @@ typedef struct i_hal { StatusCode (*init)(IHal *); StatusCode (*un_init)(IHal *); - void (*free)(IHal *); + void (*free)(void *); } IHal; IHal *GetHalIntance(void); StatusCode NewIHal(IHal **object); diff --git a/hal/src/Hal.c b/hal/src/Hal.c index 72f1c44b..984a3206 100644 --- a/hal/src/Hal.c +++ b/hal/src/Hal.c @@ -16,16 +16,17 @@ #include "ILog.h" #include #include -static void HalFree(IHal *object) +static void HalFree(void *object) { LogInfo("hal instance free.\n"); if (object) { free(object); } } -static void HalImplInit(Hal *hal) +void HalImplInit(Hal *hal) { LogInfo("HalImplInit\n"); + NewIHal((IHal **)&hal); ((IHal *)hal)->free = HalFree; } StatusCode NewHal(Hal **hal) @@ -38,15 +39,12 @@ StatusCode NewHal(Hal **hal) *hal = (Hal *)malloc(sizeof(Hal)); if (*hal) { LogInfo("NewHal succeed.\n"); - NewIHal((IHal **)hal); HalImplInit(*hal); return CreateStatusCode(STATUS_CODE_OK); } LogError("NewHal failed.\n"); return CreateStatusCode(STATUS_CODE_NOT_OK); } - { - HalImplInit(*hal); - return CreateStatusCode(STATUS_CODE_OK); - } + HalImplInit(*hal); + return CreateStatusCode(STATUS_CODE_OK); } \ No newline at end of file diff --git a/hal/src/Hal.h b/hal/src/Hal.h index 184d1078..bc1da836 100644 --- a/hal/src/Hal.h +++ b/hal/src/Hal.h @@ -25,6 +25,7 @@ typedef struct hal IHal base; } Hal; StatusCode NewHal(Hal **hal); +void HalImplInit(Hal *hal); #ifdef __cplusplus } #endif