Improve hal module.

This commit is contained in:
fancy 2023-11-19 07:30:45 -08:00
parent 3f6502c332
commit dd1cfab956
6 changed files with 13 additions and 10 deletions

View File

@ -45,6 +45,7 @@ StatusCode MainThread::UnInit(void)
}
StatusCode MainThread::CreateAllModules(void)
{
CreateLogModule();
CreateHalModule();
return CreateStatusCode(STATUS_CODE_OK);
}

View File

@ -59,3 +59,6 @@ add_custom_command(
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
)
endif()
define_file_name(${IMPL_TARGET})
define_file_name(${ABSTRACT_TARGET})

View File

@ -18,7 +18,7 @@
// #include <stddef.h>
#include <string.h>
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,

View File

@ -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);

View File

@ -16,16 +16,17 @@
#include "ILog.h"
#include <stddef.h>
#include <stdlib.h>
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);
}
}

View File

@ -25,6 +25,7 @@ typedef struct hal
IHal base;
} Hal;
StatusCode NewHal(Hal **hal);
void HalImplInit(Hal *hal);
#ifdef __cplusplus
}
#endif