Improve hal module.
This commit is contained in:
parent
3f6502c332
commit
dd1cfab956
|
@ -45,6 +45,7 @@ StatusCode MainThread::UnInit(void)
|
||||||
}
|
}
|
||||||
StatusCode MainThread::CreateAllModules(void)
|
StatusCode MainThread::CreateAllModules(void)
|
||||||
{
|
{
|
||||||
|
CreateLogModule();
|
||||||
CreateHalModule();
|
CreateHalModule();
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,3 +59,6 @@ add_custom_command(
|
||||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
define_file_name(${IMPL_TARGET})
|
||||||
|
define_file_name(${ABSTRACT_TARGET})
|
|
@ -18,7 +18,7 @@
|
||||||
// #include <stddef.h>
|
// #include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
static StatusCode IHalInit(IHal *object) { return IHalCpp::GetInstance()->Init(); }
|
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 StatusCode IHalUnInit(IHal *object) { return IHalCpp::GetInstance()->UnInit(); }
|
||||||
static IHal default_hal = {
|
static IHal default_hal = {
|
||||||
.init = IHalInit,
|
.init = IHalInit,
|
||||||
|
|
|
@ -23,7 +23,7 @@ typedef struct i_hal
|
||||||
{
|
{
|
||||||
StatusCode (*init)(IHal *);
|
StatusCode (*init)(IHal *);
|
||||||
StatusCode (*un_init)(IHal *);
|
StatusCode (*un_init)(IHal *);
|
||||||
void (*free)(IHal *);
|
void (*free)(void *);
|
||||||
} IHal;
|
} IHal;
|
||||||
IHal *GetHalIntance(void);
|
IHal *GetHalIntance(void);
|
||||||
StatusCode NewIHal(IHal **object);
|
StatusCode NewIHal(IHal **object);
|
||||||
|
|
|
@ -16,16 +16,17 @@
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
static void HalFree(IHal *object)
|
static void HalFree(void *object)
|
||||||
{
|
{
|
||||||
LogInfo("hal instance free.\n");
|
LogInfo("hal instance free.\n");
|
||||||
if (object) {
|
if (object) {
|
||||||
free(object);
|
free(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void HalImplInit(Hal *hal)
|
void HalImplInit(Hal *hal)
|
||||||
{
|
{
|
||||||
LogInfo("HalImplInit\n");
|
LogInfo("HalImplInit\n");
|
||||||
|
NewIHal((IHal **)&hal);
|
||||||
((IHal *)hal)->free = HalFree;
|
((IHal *)hal)->free = HalFree;
|
||||||
}
|
}
|
||||||
StatusCode NewHal(Hal **hal)
|
StatusCode NewHal(Hal **hal)
|
||||||
|
@ -38,15 +39,12 @@ StatusCode NewHal(Hal **hal)
|
||||||
*hal = (Hal *)malloc(sizeof(Hal));
|
*hal = (Hal *)malloc(sizeof(Hal));
|
||||||
if (*hal) {
|
if (*hal) {
|
||||||
LogInfo("NewHal succeed.\n");
|
LogInfo("NewHal succeed.\n");
|
||||||
NewIHal((IHal **)hal);
|
|
||||||
HalImplInit(*hal);
|
HalImplInit(*hal);
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
LogError("NewHal failed.\n");
|
LogError("NewHal failed.\n");
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
{
|
HalImplInit(*hal);
|
||||||
HalImplInit(*hal);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -25,6 +25,7 @@ typedef struct hal
|
||||||
IHal base;
|
IHal base;
|
||||||
} Hal;
|
} Hal;
|
||||||
StatusCode NewHal(Hal **hal);
|
StatusCode NewHal(Hal **hal);
|
||||||
|
void HalImplInit(Hal *hal);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user