mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Improve hal module.
This commit is contained in:
parent
5b3152355e
commit
6d886d26eb
|
@ -33,5 +33,6 @@ RETURN_CODE_C new_i_hal(IHal **object)
|
||||||
}
|
}
|
||||||
void reset_hal_impl(IHal *impl)
|
void reset_hal_impl(IHal *impl)
|
||||||
{
|
{
|
||||||
|
hal_instance->free(hal_instance);
|
||||||
hal_instance = impl;
|
hal_instance = impl;
|
||||||
}
|
}
|
|
@ -22,15 +22,12 @@ extern "C"
|
||||||
{
|
{
|
||||||
return get_hal_instance()->init(get_hal_instance());
|
return get_hal_instance()->init(get_hal_instance());
|
||||||
}
|
}
|
||||||
static inline void i_hal_free(void)
|
|
||||||
{
|
|
||||||
return get_hal_instance()->free(get_hal_instance());
|
|
||||||
}
|
|
||||||
static inline RETURN_CODE_C i_hal_un_init(void)
|
static inline RETURN_CODE_C i_hal_un_init(void)
|
||||||
{
|
{
|
||||||
return get_hal_instance()->un_init(get_hal_instance());
|
return get_hal_instance()->un_init(get_hal_instance());
|
||||||
}
|
}
|
||||||
RETURN_CODE_C create_hal_module(void);
|
RETURN_CODE_C create_hal_module(void);
|
||||||
|
RETURN_CODE_C destroy_hal_module(void);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,17 +6,22 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
RETURN_CODE_C create_hal_module(void)
|
RETURN_CODE_C create_hal_module(void)
|
||||||
{
|
{
|
||||||
IHal *hal = NULL;
|
Hal *hal = NULL;
|
||||||
RETURN_CODE_C code = create_hal_instance(&hal);
|
RETURN_CODE_C code = create_hal_instance(&hal);
|
||||||
if (C_RETURN_CODE_OK == code.mCode)
|
if (C_RETURN_CODE_OK == code.mCode)
|
||||||
{
|
{
|
||||||
LogInfo("Create hal instance ok.\n");
|
LogInfo("Create hal instance ok.\n");
|
||||||
reset_hal_impl(hal);
|
reset_hal_impl((IHal *)hal);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
return CreateReturnCode(C_RETURN_CODE_NOT_OK);
|
return CreateReturnCode(C_RETURN_CODE_NOT_OK);
|
||||||
}
|
}
|
||||||
static RETURN_CODE_C create_hal_instance_ptr(HalMakePtr *object, IHal **hal)
|
RETURN_CODE_C destroy_hal_module(void)
|
||||||
|
{
|
||||||
|
reset_hal_impl(NULL);
|
||||||
|
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||||
|
}
|
||||||
|
static RETURN_CODE_C create_hal_instance_ptr(HalMakePtr *object, Hal **hal)
|
||||||
{
|
{
|
||||||
return new_hal(hal);
|
return new_hal(hal);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef HAL_MAKE_PTR_H
|
#ifndef HAL_MAKE_PTR_H
|
||||||
#define HAL_MAKE_PTR_H
|
#define HAL_MAKE_PTR_H
|
||||||
#include "ReturnCode.h"
|
#include "ReturnCode.h"
|
||||||
#include "i_hal.h"
|
#include "hal.h"
|
||||||
/*
|
/*
|
||||||
** Make sure we can call this stuff from C++.
|
** Make sure we can call this stuff from C++.
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,7 @@ extern "C"
|
||||||
typedef struct hal_make_ptr
|
typedef struct hal_make_ptr
|
||||||
{
|
{
|
||||||
RETURN_CODE_C (*init)(HalMakePtr *);
|
RETURN_CODE_C (*init)(HalMakePtr *);
|
||||||
RETURN_CODE_C (*create_hal_instance)(HalMakePtr *, IHal **);
|
RETURN_CODE_C (*create_hal_instance)(HalMakePtr *, Hal **);
|
||||||
void (*free)(HalMakePtr *);
|
void (*free)(HalMakePtr *);
|
||||||
RETURN_CODE_C (*un_init)(HalMakePtr *);
|
RETURN_CODE_C (*un_init)(HalMakePtr *);
|
||||||
} HalMakePtr;
|
} HalMakePtr;
|
||||||
|
@ -28,7 +28,7 @@ extern "C"
|
||||||
{
|
{
|
||||||
return get_hal_make_ptr_instance()->un_init(get_hal_make_ptr_instance());
|
return get_hal_make_ptr_instance()->un_init(get_hal_make_ptr_instance());
|
||||||
}
|
}
|
||||||
static inline RETURN_CODE_C create_hal_instance(IHal **hal)
|
static inline RETURN_CODE_C create_hal_instance(Hal **hal)
|
||||||
{
|
{
|
||||||
return get_hal_make_ptr_instance()->create_hal_instance(get_hal_make_ptr_instance(), hal);
|
return get_hal_make_ptr_instance()->create_hal_instance(get_hal_make_ptr_instance(), hal);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ namespace IHalTest
|
||||||
TEST(IHalTest, Demo)
|
TEST(IHalTest, Demo)
|
||||||
{
|
{
|
||||||
InitLog(LOG_EASYLOGGING, nullptr);
|
InitLog(LOG_EASYLOGGING, nullptr);
|
||||||
// create_hal_module();
|
create_hal_module();
|
||||||
i_hal_init();
|
i_hal_init();
|
||||||
i_hal_un_init();
|
i_hal_un_init();
|
||||||
i_hal_free();
|
destroy_hal_module();
|
||||||
UnInitLog();
|
UnInitLog();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user