Adjust directory structure

This commit is contained in:
Zhao_Jiasheng
2021-06-03 17:38:11 +08:00
parent 92301257f3
commit 89a2236b18
1993 changed files with 40 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
SRC_FILES += bus_rtc.c dev_rtc.c drv_rtc.c
include $(KERNEL_ROOT)/compiler.mk
+117
View File
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file bus_rtc.c
* @brief register rtc bus function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#include <bus_rtc.h>
#include <dev_rtc.h>
int RtcBusInit(struct RtcBus *rtc_bus, const char *bus_name)
{
NULL_PARAM_CHECK(rtc_bus);
NULL_PARAM_CHECK(bus_name);
x_err_t ret = EOK;
if (BUS_INSTALL != rtc_bus->bus.bus_state) {
strncpy(rtc_bus->bus.bus_name, bus_name, NAME_NUM_MAX);
rtc_bus->bus.bus_type = TYPE_RTC_BUS;
rtc_bus->bus.bus_state = BUS_INSTALL;
rtc_bus->bus.private_data = rtc_bus->private_data;
ret = BusRegister(&rtc_bus->bus);
if (EOK != ret) {
KPrintf("RtcBusInit BusRegister error %u\n", ret);
return ret;
}
} else {
KPrintf("RtcBusInit BusRegister bus has been register state%u\n", rtc_bus->bus.bus_state);
}
return ret;
}
int RtcDriverInit(struct RtcDriver *rtc_driver, const char *driver_name)
{
NULL_PARAM_CHECK(rtc_driver);
NULL_PARAM_CHECK(driver_name);
x_err_t ret = EOK;
if (DRV_INSTALL != rtc_driver->driver.driver_state) {
rtc_driver->driver.driver_type = TYPE_RTC_DRV;
rtc_driver->driver.driver_state = DRV_INSTALL;
strncpy(rtc_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
rtc_driver->driver.configure = rtc_driver->configure;
ret = RtcDriverRegister(&rtc_driver->driver);
if (EOK != ret) {
KPrintf("RtcDriverInit DriverRegister error %u\n", ret);
return ret;
}
} else {
KPrintf("RtcDriverInit DriverRegister driver has been register state%u\n", rtc_driver->driver.driver_state);
}
return ret;
}
int RtcReleaseBus(struct RtcBus *rtc_bus)
{
NULL_PARAM_CHECK(rtc_bus);
return BusRelease(&rtc_bus->bus);
}
int RtcDriverAttachToBus(const char *drv_name, const char *bus_name)
{
NULL_PARAM_CHECK(drv_name);
NULL_PARAM_CHECK(bus_name);
x_err_t ret = EOK;
struct Bus *bus;
struct Driver *driver;
bus = BusFind(bus_name);
if (NONE == bus) {
KPrintf("RtcDriverAttachToBus find rtc bus error!name %s\n", bus_name);
return ERROR;
}
if (TYPE_RTC_BUS == bus->bus_type) {
driver = RtcDriverFind(drv_name, TYPE_RTC_DRV);
if (NONE == driver) {
KPrintf("RtcDriverAttachToBus find rtc driver error!name %s\n", drv_name);
return ERROR;
}
if (TYPE_RTC_DRV == driver->driver_type) {
ret = DriverRegisterToBus(bus, driver);
if (EOK != ret) {
KPrintf("RtcDriverAttachToBus DriverRegisterToBus error %u\n", ret);
return ERROR;
}
}
}
return ret;
}
+115
View File
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file dev_rtc.c
* @brief register rtc dev function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#include <bus_rtc.h>
#include <dev_rtc.h>
static DoubleLinklistType rtcdev_linklist;
/*Create the rtc device linklist*/
static void RtcDeviceLinkInit()
{
InitDoubleLinkList(&rtcdev_linklist);
}
HardwareDevType RtcDeviceFind(const char *dev_name, enum DevType dev_type)
{
NULL_PARAM_CHECK(dev_name);
struct HardwareDev *device = NONE;
DoubleLinklistType *node = NONE;
DoubleLinklistType *head = &rtcdev_linklist;
for (node = head->node_next; node != head; node = node->node_next) {
device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct HardwareDev, dev_link);
if ((!strcmp(device->dev_name, dev_name)) && (dev_type == device->dev_type)) {
return device;
}
}
KPrintf("RtcDeviceFind cannot find the %s device.return NULL\n", dev_name);
return NONE;
}
int RtcDeviceRegister(struct RtcHardwareDevice *rtc_device, void *rtc_param, const char *device_name)
{
NULL_PARAM_CHECK(rtc_device);
NULL_PARAM_CHECK(device_name);
x_err_t ret = EOK;
static x_bool dev_link_flag = RET_FALSE;
if (!dev_link_flag) {
RtcDeviceLinkInit();
dev_link_flag = RET_TRUE;
}
if (DEV_INSTALL != rtc_device->haldev.dev_state) {
strncpy(rtc_device->haldev.dev_name, device_name, NAME_NUM_MAX);
rtc_device->haldev.dev_type = TYPE_RTC_DEV;
rtc_device->haldev.dev_state = DEV_INSTALL;
rtc_device->haldev.dev_done = (struct HalDevDone *)rtc_device->dev_done;
rtc_device->haldev.private_data = rtc_param;
DoubleLinkListInsertNodeAfter(&rtcdev_linklist, &(rtc_device->haldev.dev_link));
} else {
KPrintf("RtcDeviceRegister device has been register state%u\n", rtc_device->haldev.dev_state);
}
return ret;
}
int RtcDeviceAttachToBus(const char *dev_name, const char *bus_name)
{
NULL_PARAM_CHECK(dev_name);
NULL_PARAM_CHECK(bus_name);
x_err_t ret = EOK;
struct Bus *bus;
struct HardwareDev *device;
bus = BusFind(bus_name);
if (NONE == bus) {
KPrintf("RtcDeviceAttachToBus find rtc bus error!name %s\n", bus_name);
return ERROR;
}
if (TYPE_RTC_BUS == bus->bus_type) {
device = RtcDeviceFind(dev_name, TYPE_RTC_DEV);
if (NONE == device) {
KPrintf("RtcDeviceAttachToBus find rtc device error!name %s\n", dev_name);
return ERROR;
}
if (TYPE_RTC_DEV == device->dev_type) {
ret = DeviceRegisterToBus(bus, device);
if (EOK != ret) {
KPrintf("RtcDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
return ERROR;
}
}
}
return EOK;
}
+244
View File
@@ -0,0 +1,244 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file drv_rtc.c
* @brief register rtc drv function using bus driver framework
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-04-24
*/
#include <bus_rtc.h>
#include <dev_rtc.h>
static DoubleLinklistType rtcdrv_linklist;
/*Create the driver linklist*/
static void RtcDrvLinkInit()
{
InitDoubleLinkList(&rtcdrv_linklist);
}
DriverType RtcDriverFind(const char *drv_name, enum DriverType drv_type)
{
NULL_PARAM_CHECK(drv_name);
struct Driver *driver = NONE;
DoubleLinklistType *node = NONE;
DoubleLinklistType *head = &rtcdrv_linklist;
for (node = head->node_next; node != head; node = node->node_next) {
driver = SYS_DOUBLE_LINKLIST_ENTRY(node, struct Driver, driver_link);
if ((!strcmp(driver->drv_name, drv_name)) && (drv_type == driver->driver_type)) {
return driver;
}
}
KPrintf("RtcDriverFind cannot find the %s driver.return NULL\n", drv_name);
return NONE;
}
int RtcDriverRegister(struct Driver *driver)
{
NULL_PARAM_CHECK(driver);
x_err_t ret = EOK;
static x_bool driver_link_flag = RET_FALSE;
if (!driver_link_flag) {
RtcDrvLinkInit();
driver_link_flag = RET_TRUE;
}
DoubleLinkListInsertNodeAfter(&rtcdrv_linklist, &(driver->driver_link));
return ret;
}
int RtcDrvSetFunction(char *driver_name, struct RtcSetParam *rtc_set_param)
{
NULL_PARAM_CHECK(driver_name);
x_err_t ret = EOK;
time_t now;
struct tm *tm_now;
struct tm tm_tmp;
x_base lock;
struct Driver *driver;
struct BusConfigureInfo configure_info;
struct RtcDrvConfigureParam drv_param;
configure_info.private_data = &drv_param;
driver = RtcDriverFind(driver_name, TYPE_RTC_DRV);
if (NONE == driver) {
KPrintf("RtcDrvSetFunction find rtc driver %s error\n", driver_name);
return ERROR;
}
if (OPER_RTC_SET_TIME == rtc_set_param->rtc_set_cmd) {
now = time(NONE);
lock = CriticalAreaLock();
tm_now = localtime(&now);
memcpy(&tm_tmp, tm_now, sizeof(struct tm));
CriticalAreaUnLock(lock);
tm_tmp.tm_year = rtc_set_param->date_param.year - 1900;
tm_tmp.tm_mon = rtc_set_param->date_param.month - 1;
tm_tmp.tm_mday = rtc_set_param->date_param.day;
tm_tmp.tm_hour = rtc_set_param->time_param.hour;
tm_tmp.tm_min = rtc_set_param->time_param.minute;
tm_tmp.tm_sec = rtc_set_param->time_param.second;
now = mktime(&tm_tmp);
drv_param.rtc_operation_cmd = OPER_RTC_SET_TIME;
drv_param.time = &now;
ret = driver->configure(driver, &configure_info);
if (EOK != ret) {
KPrintf("RtcDrvSetFunction set time error %d\n", ret);
return ret;
}
} else if (OPER_RTC_GET_TIME == rtc_set_param->rtc_set_cmd) {
drv_param.rtc_operation_cmd = OPER_RTC_GET_TIME;
drv_param.time = rtc_set_param->time;
ret = driver->configure(driver, &configure_info);
if (EOK != ret) {
KPrintf("RtcDrvSetFunction set time error %d\n", ret);
return ret;
}
}
return EOK;
}
#ifdef USING_SOFT_RTC
static x_ticks_t SoftRtc_InitTick;
static time_t SoftRtc_InitTime;
static int SoftRtcInitTime(struct tm *time, struct RtcDateParam *date_param, struct RtcTimeParam *time_param)
{
NULL_PARAM_CHECK(time);
time->tm_year = date_param->year - 1900;
time->tm_mon = date_param->month - 1;
time->tm_mday = date_param->day;
time->tm_hour = time_param->hour;
time->tm_min = time_param->minute;
time->tm_sec = time_param->second;
return EOK;
}
static uint32 SoftRtcConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
struct RtcDriver *rtc_drv = (struct RtcDriver *)drv;
struct RtcDrvConfigureParam *drv_param = (struct RtcDrvConfigureParam *)configure_info->private_data;
int cmd = drv_param->rtc_operation_cmd;
time_t *time = drv_param->time;
switch(cmd)
{
case OPER_RTC_GET_TIME:
{
*time = SoftRtc_InitTime + (CurrentTicksGain() - SoftRtc_InitTick) / TICK_PER_SECOND;
break;
}
case OPER_RTC_SET_TIME:
{
SoftRtc_InitTime = *time - (CurrentTicksGain() - SoftRtc_InitTick) / TICK_PER_SECOND;
break;
}
}
return EOK;
}
static struct RtcDateParam date_param =
{
.year = 2021,
.month = 1,
.day = 1,
};
static struct RtcTimeParam time_param =
{
.hour = 0,
.minute = 0,
.second = 0,
};
static int SoftRtcBusInit(struct RtcBus *softrtc_bus, struct RtcDriver *softrtc_driver)
{
x_err_t ret = EOK;
/*Init the soft rtc bus */
ret = RtcBusInit(softrtc_bus, SOFT_RTC_BUS_NAME);
if(EOK != ret)
{
KPrintf("SoftRtcBusInit RtcBusInit error %d\n", ret);
return ERROR;
}
/*Init the soft rtc driver*/
ret = RtcDriverInit(softrtc_driver, SOFT_RTC_DRV_NAME);
if(EOK != ret)
{
KPrintf("SoftRtcBusInit RtcDriverInit error %d\n", ret);
return ERROR;
}
/*Attach the soft rtc driver to the soft rtc bus*/
ret = RtcDriverAttachToBus(SOFT_RTC_DRV_NAME, SOFT_RTC_BUS_NAME);
if(EOK != ret)
{
KPrintf("SoftRtcBusInit RtcDriverAttachToBus error %d\n", ret);
return ERROR;
}
return ret;
}
int SoftRtcInit(void)
{
x_err_t ret = EOK;
struct tm time;
SoftRtcInitTime(&time, &date_param, &time_param);
static struct RtcBus softrtc_bus;
memset(&softrtc_bus, 0, sizeof(struct RtcBus));
static struct RtcDriver softrtc_driver;
memset(&softrtc_driver, 0, sizeof(struct RtcDriver));
softrtc_driver.configure = &(SoftRtcConfigure);
ret = SoftRtcBusInit(&softrtc_bus, &softrtc_driver);
if (EOK != ret) {
KPrintf("SoftRtcInit error ret %u\n", ret);
return ERROR;
}
SoftRtc_InitTick = CurrentTicksGain();
SoftRtc_InitTime = mktime(&time);
return ret;
}
#endif