forked from xuos/xiuos
First commit XiUOS
This commit is contained in:
3
resources/timer/Makefile
Normal file
3
resources/timer/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := bus_hwtimer.c dev_hwtimer.c drv_hwtimer.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
117
resources/timer/bus_hwtimer.c
Normal file
117
resources/timer/bus_hwtimer.c
Normal 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_hwtimer.c
|
||||
* @brief register hwtimer bus function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_hwtimer.h>
|
||||
#include <dev_hwtimer.h>
|
||||
|
||||
int HwtimerBusInit(struct HwtimerBus *hwtimer_bus, const char *bus_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(hwtimer_bus);
|
||||
NULL_PARAM_CHECK(bus_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (BUS_INSTALL != hwtimer_bus->bus.bus_state) {
|
||||
strncpy(hwtimer_bus->bus.bus_name, bus_name, NAME_NUM_MAX);
|
||||
|
||||
hwtimer_bus->bus.bus_type = TYPE_HWTIMER_BUS;
|
||||
hwtimer_bus->bus.bus_state = BUS_INSTALL;
|
||||
hwtimer_bus->bus.private_data = hwtimer_bus->private_data;
|
||||
|
||||
ret = BusRegister(&hwtimer_bus->bus);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwtimerBusInit BusRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("HwtimerBusInit BusRegister bus has been register state%u\n", hwtimer_bus->bus.bus_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HwtimerDriverInit(struct HwtimerDriver *hwtimer_driver, const char *driver_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(hwtimer_driver);
|
||||
NULL_PARAM_CHECK(driver_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (DRV_INSTALL != hwtimer_driver->driver.driver_state) {
|
||||
hwtimer_driver->driver.driver_type = TYPE_HWTIMER_DRV;
|
||||
hwtimer_driver->driver.driver_state = DRV_INSTALL;
|
||||
|
||||
strncpy(hwtimer_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
|
||||
|
||||
hwtimer_driver->driver.configure = hwtimer_driver->configure;
|
||||
|
||||
ret = HwtimerDriverRegister(&hwtimer_driver->driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwtimerDriverInit DriverRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("HwtimerDriverInit DriverRegister driver has been register state%u\n", hwtimer_driver->driver.driver_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HwtimerReleaseBus(struct HwtimerBus *hwtimer_bus)
|
||||
{
|
||||
NULL_PARAM_CHECK(hwtimer_bus);
|
||||
|
||||
return BusRelease(&hwtimer_bus->bus);
|
||||
}
|
||||
|
||||
int HwtimerDriverAttachToBus(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("HwtimerDriverAttachToBus find hwtimer bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_HWTIMER_BUS == bus->bus_type) {
|
||||
driver = HwtimerDriverFind(drv_name);
|
||||
if (NONE == driver) {
|
||||
KPrintf("HwtimerDriverAttachToBus find hwtimer driver error!name %s\n", drv_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_HWTIMER_DRV == driver->driver_type) {
|
||||
ret = DriverRegisterToBus(bus, driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwtimerDriverAttachToBus DriverRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
115
resources/timer/dev_hwtimer.c
Normal file
115
resources/timer/dev_hwtimer.c
Normal 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_hwtimer.c
|
||||
* @brief register hwtimer dev function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_hwtimer.h>
|
||||
#include <dev_hwtimer.h>
|
||||
|
||||
static DoubleLinklistType hwtimerdev_linklist;
|
||||
|
||||
/*Create the hwtimer device linklist*/
|
||||
static void HwtimerDeviceLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&hwtimerdev_linklist);
|
||||
}
|
||||
|
||||
HardwareDevType HwtimerDeviceFind(const char *dev_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev_name);
|
||||
|
||||
struct HardwareDev *device = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &hwtimerdev_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)) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
|
||||
KPrintf("HwtimerDeviceFind cannot find the %s device.return NULL\n", dev_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
int HwtimerDeviceRegister(struct HwtimerHardwareDevice *hwtimer_device, void *hwtimer_param, const char *device_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(hwtimer_device);
|
||||
NULL_PARAM_CHECK(device_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool dev_link_flag = RET_FALSE;
|
||||
|
||||
if (dev_link_flag) {
|
||||
HwtimerDeviceLinkInit();
|
||||
dev_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
if (DEV_INSTALL != hwtimer_device->haldev.dev_state) {
|
||||
strncpy(hwtimer_device->haldev.dev_name, device_name, NAME_NUM_MAX);
|
||||
hwtimer_device->haldev.dev_type = TYPE_HWTIMER_DEV;
|
||||
hwtimer_device->haldev.dev_state = DEV_INSTALL;
|
||||
|
||||
hwtimer_device->haldev.dev_done = (struct HalDevDone *)hwtimer_device->dev_done;
|
||||
|
||||
hwtimer_device->haldev.private_data = hwtimer_param;
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&hwtimerdev_linklist, &(hwtimer_device->haldev.dev_link));
|
||||
} else {
|
||||
KPrintf("HwtimerDeviceRegister device has been register state%u\n", hwtimer_device->haldev.dev_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int HwtimerDeviceAttachToBus(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("HwtimerDeviceAttachToBus find hwtimer bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_HWTIMER_BUS == bus->bus_type) {
|
||||
device = HwtimerDeviceFind(dev_name);
|
||||
if (NONE == device) {
|
||||
KPrintf("HwtimerDeviceAttachToBus find hwtimer device error!name %s\n", dev_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_HWTIMER_DEV == device->dev_type) {
|
||||
ret = DeviceRegisterToBus(bus, device);
|
||||
if (EOK != ret) {
|
||||
KPrintf("HwtimerDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
67
resources/timer/drv_hwtimer.c
Normal file
67
resources/timer/drv_hwtimer.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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_hwtimer.c
|
||||
* @brief register hwtimer drv function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_hwtimer.h>
|
||||
#include <dev_hwtimer.h>
|
||||
|
||||
static DoubleLinklistType hwtimerdrv_linklist;
|
||||
|
||||
/*Create the driver linklist*/
|
||||
static void HwtimerDrvLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&hwtimerdrv_linklist);
|
||||
}
|
||||
|
||||
DriverType HwtimerDriverFind(const char *drv_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv_name);
|
||||
|
||||
struct Driver *driver = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &hwtimerdrv_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)) {
|
||||
return driver;
|
||||
}
|
||||
}
|
||||
|
||||
KPrintf("HwtimerDriverFind cannot find the %s driver.return NULL\n", drv_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
int HwtimerDriverRegister(struct Driver *driver)
|
||||
{
|
||||
NULL_PARAM_CHECK(driver);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool driver_link_flag = RET_FALSE;
|
||||
|
||||
if (!driver_link_flag) {
|
||||
HwtimerDrvLinkInit();
|
||||
driver_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&hwtimerdrv_linklist, &(driver->driver_link));
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user