forked from xuos/xiuos
First commit XiUOS
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
SRC_FILES += dev_lcd.c bus_lcd.c drv_lcd.c
|
||||
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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_lcd.c
|
||||
* @brief register lcd bus function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_lcd.h>
|
||||
#include <dev_lcd.h>
|
||||
|
||||
int LcdBusInit(struct LcdBus *lcd_bus, const char *bus_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(lcd_bus);
|
||||
NULL_PARAM_CHECK(bus_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (BUS_INSTALL != lcd_bus->bus.bus_state) {
|
||||
strncpy(lcd_bus->bus.bus_name, bus_name, NAME_NUM_MAX);
|
||||
|
||||
lcd_bus->bus.bus_type = TYPE_LCD_BUS;
|
||||
lcd_bus->bus.bus_state = BUS_INSTALL;
|
||||
lcd_bus->bus.private_data = lcd_bus->private_data;
|
||||
|
||||
ret = BusRegister(&lcd_bus->bus);
|
||||
if (EOK != ret) {
|
||||
KPrintf("LCDBusInit BusRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("LCDBusInit BusRegister bus has been register state%u\n", lcd_bus->bus.bus_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LcdDriverInit(struct LcdDriver *lcd_driver, const char *driver_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(lcd_driver);
|
||||
NULL_PARAM_CHECK(driver_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (DRV_INSTALL != lcd_driver->driver.driver_state) {
|
||||
lcd_driver->driver.driver_type = TYPE_LCD_DRV;
|
||||
lcd_driver->driver.driver_state = DRV_INSTALL;
|
||||
|
||||
strncpy(lcd_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
|
||||
|
||||
lcd_driver->driver.configure = lcd_driver->configure;
|
||||
|
||||
ret = LcdDriverRegister(&lcd_driver->driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("LcdDriverInit DriverRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("LcdDriverInit DriverRegister driver has been register state%u\n", lcd_driver->driver.driver_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LcdReleaseBus(struct LcdBus *lcd_bus)
|
||||
{
|
||||
NULL_PARAM_CHECK(lcd_bus);
|
||||
|
||||
return BusRelease(&lcd_bus->bus);
|
||||
}
|
||||
|
||||
int LcdDriverAttachToBus(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("LcdDriverAttachToBus find lcd bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_LCD_BUS == bus->bus_type) {
|
||||
driver = LcdDriverFind(drv_name, TYPE_LCD_DRV);
|
||||
if (NONE == driver) {
|
||||
KPrintf("LcdDriverAttachToBus find lcd driver error!name %s\n", drv_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_LCD_DRV == driver->driver_type) {
|
||||
ret = DriverRegisterToBus(bus, driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("LcdDriverAttachToBus DriverRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -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_lcd.c
|
||||
* @brief register lcd dev function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_lcd.h>
|
||||
#include <dev_lcd.h>
|
||||
|
||||
static DoubleLinklistType lcddev_linklist;
|
||||
|
||||
/*Create the lcd device linklist*/
|
||||
static void LcdDeviceLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&lcddev_linklist);
|
||||
}
|
||||
|
||||
HardwareDevType LcdDeviceFind(const char *dev_name, enum DevType dev_type)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev_name);
|
||||
|
||||
struct HardwareDev *device = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &lcddev_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("LcdDeviceFind cannot find the %s device.return NULL\n", dev_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
int LcdDeviceRegister(struct LcdHardwareDevice *lcd_device, void *lcd_param, const char *device_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(lcd_device);
|
||||
NULL_PARAM_CHECK(device_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool dev_link_flag = RET_FALSE;
|
||||
|
||||
if (!dev_link_flag) {
|
||||
LcdDeviceLinkInit();
|
||||
dev_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
if (DEV_INSTALL != lcd_device->haldev.dev_state) {
|
||||
strncpy(lcd_device->haldev.dev_name, device_name, NAME_NUM_MAX);
|
||||
lcd_device->haldev.dev_type = TYPE_LCD_DEV;
|
||||
lcd_device->haldev.dev_state = DEV_INSTALL;
|
||||
|
||||
lcd_device->haldev.dev_done = (struct HalDevDone *)lcd_device->dev_done;
|
||||
|
||||
lcd_device->haldev.private_data = lcd_param;
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&lcddev_linklist, &(lcd_device->haldev.dev_link));
|
||||
} else {
|
||||
KPrintf("LcdDeviceRegister device has been register state%u\n", lcd_device->haldev.dev_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LcdDeviceAttachToBus(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("LcdDeviceAttachToBus find lcd bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_LCD_BUS == bus->bus_type) {
|
||||
device = LcdDeviceFind(dev_name, TYPE_LCD_DEV);
|
||||
if (NONE == device) {
|
||||
KPrintf("LcdDeviceAttachToBus find lcd device error!name %s\n", dev_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_LCD_DEV == device->dev_type) {
|
||||
ret = DeviceRegisterToBus(bus, device);
|
||||
if (EOK != ret) {
|
||||
KPrintf("LcdDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
@@ -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_lcd.c
|
||||
* @brief register lcd drv function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_lcd.h>
|
||||
#include <dev_lcd.h>
|
||||
|
||||
static DoubleLinklistType lcddrv_linklist;
|
||||
|
||||
/*Create the driver linklist*/
|
||||
static void LcdDrvLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&lcddrv_linklist);
|
||||
}
|
||||
|
||||
DriverType LcdDriverFind(const char *drv_name, enum DriverType drv_type)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv_name);
|
||||
|
||||
struct Driver *driver = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &lcddrv_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("LcdDriverFind cannot find the %s driver.return NULL\n", drv_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
int LcdDriverRegister(struct Driver *driver)
|
||||
{
|
||||
NULL_PARAM_CHECK(driver);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool driver_link_flag = RET_FALSE;
|
||||
|
||||
if (!driver_link_flag) {
|
||||
LcdDrvLinkInit();
|
||||
driver_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&lcddrv_linklist, &(driver->driver_link));
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user