Adjust directory structure
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
SRC_FILES += dev_can.c drv_can.c bus_can.c
|
||||
|
||||
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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_can.c
|
||||
* @brief register can bus function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_can.h>
|
||||
#include <dev_can.h>
|
||||
|
||||
/*Register the CAN BUS*/
|
||||
int CanBusInit(struct CanBus *can_bus, const char *bus_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(can_bus);
|
||||
NULL_PARAM_CHECK(bus_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (BUS_INSTALL != can_bus->bus.bus_state) {
|
||||
strncpy(can_bus->bus.bus_name, bus_name, NAME_NUM_MAX);
|
||||
|
||||
can_bus->bus.bus_type = TYPE_CAN_BUS;
|
||||
can_bus->bus.bus_state = BUS_INSTALL;
|
||||
can_bus->bus.private_data = can_bus->private_data;
|
||||
|
||||
ret = BusRegister(&can_bus->bus);
|
||||
if (EOK != ret) {
|
||||
KPrintf("CanBusInit BusRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("CanBusInit BusRegister bus has been register state%u\n", can_bus->bus.bus_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Register the CAN Driver*/
|
||||
int CanDriverInit(struct CanDriver *can_driver, const char *driver_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(can_driver);
|
||||
NULL_PARAM_CHECK(driver_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
|
||||
if (DRV_INSTALL != can_driver->driver.driver_state) {
|
||||
can_driver->driver.driver_type = TYPE_CAN_DRV;
|
||||
can_driver->driver.driver_state = DRV_INSTALL;
|
||||
|
||||
strncpy(can_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
|
||||
|
||||
can_driver->driver.configure = can_driver->configure;
|
||||
can_driver->driver.private_data = can_driver->private_data;
|
||||
|
||||
ret = CanDriverRegister(&can_driver->driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("CanDriverInit DriverRegister error %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
KPrintf("CanDriverInit DriverRegister driver has been register state%u\n", can_driver->driver.driver_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Release the CAN device*/
|
||||
int CanReleaseBus(struct CanBus *can_bus)
|
||||
{
|
||||
NULL_PARAM_CHECK(can_bus);
|
||||
|
||||
return BusRelease(&can_bus->bus);
|
||||
}
|
||||
|
||||
/*Register the CAN Driver to the CAN BUS*/
|
||||
int CanDriverAttachToBus(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("CanDriverAttachToBus find can bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_CAN_BUS == bus->bus_type) {
|
||||
driver = CanDriverFind(drv_name, TYPE_CAN_DRV);
|
||||
if (NONE == driver) {
|
||||
KPrintf("CanDriverAttachToBus find can driver error!name %s\n", drv_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_CAN_DRV == driver->driver_type) {
|
||||
ret = DriverRegisterToBus(bus, driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("CanDriverAttachToBus DriverRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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_can.c
|
||||
* @brief register can dev function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_can.h>
|
||||
#include <dev_can.h>
|
||||
|
||||
static DoubleLinklistType candev_linklist;
|
||||
|
||||
/*Create the CAN device linklist*/
|
||||
static void CanDeviceLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&candev_linklist);
|
||||
}
|
||||
|
||||
/*Find the register CAN device*/
|
||||
HardwareDevType CanDeviceFind(const char *dev_name, enum DevType dev_type)
|
||||
{
|
||||
NULL_PARAM_CHECK(dev_name);
|
||||
|
||||
struct HardwareDev *device = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &candev_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("CanDeviceFind cannot find the %s device.return NULL\n", dev_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/*Register the CAN device*/
|
||||
int CanDeviceRegister(struct CanHardwareDevice *can_device, void *can_param, const char *device_name)
|
||||
{
|
||||
NULL_PARAM_CHECK(can_device);
|
||||
NULL_PARAM_CHECK(device_name);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool dev_link_flag = RET_FALSE;
|
||||
|
||||
if (!dev_link_flag) {
|
||||
CanDeviceLinkInit();
|
||||
dev_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
if (DEV_INSTALL != can_device->haldev.dev_state) {
|
||||
strncpy(can_device->haldev.dev_name, device_name, NAME_NUM_MAX);
|
||||
can_device->haldev.dev_type = TYPE_CAN_DEV;
|
||||
can_device->haldev.dev_state = DEV_INSTALL;
|
||||
|
||||
can_device->haldev.dev_done = (struct HalDevDone *)can_device->dev_done;
|
||||
|
||||
can_device->haldev.private_data = can_param;
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&candev_linklist, &(can_device->haldev.dev_link));
|
||||
} else {
|
||||
KPrintf("CanDeviceRegister device has been register state%u\n", can_device->haldev.dev_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Register the CAN Device to the CAN BUS*/
|
||||
int CanDeviceAttachToBus(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("CanDeviceAttachToBus find can bus error!name %s\n", bus_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_CAN_BUS == bus->bus_type) {
|
||||
device = CanDeviceFind(dev_name, TYPE_CAN_DEV);
|
||||
|
||||
if (NONE == device) {
|
||||
KPrintf("CanDeviceAttachToBus find can device error!name %s\n", dev_name);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (TYPE_CAN_DEV == device->dev_type) {
|
||||
ret = DeviceRegisterToBus(bus, device);
|
||||
|
||||
if (EOK != ret) {
|
||||
KPrintf("CanDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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_can.c
|
||||
* @brief register can drv function using bus driver framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-24
|
||||
*/
|
||||
|
||||
#include <bus_can.h>
|
||||
#include <dev_can.h>
|
||||
|
||||
static DoubleLinklistType candrv_linklist;
|
||||
|
||||
/*Create the driver linklist*/
|
||||
static void CanDrvLinkInit()
|
||||
{
|
||||
InitDoubleLinkList(&candrv_linklist);
|
||||
}
|
||||
|
||||
/*Find the regiter driver*/
|
||||
DriverType CanDriverFind(const char *drv_name, enum DriverType drv_type)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv_name);
|
||||
|
||||
struct Driver *driver = NONE;
|
||||
|
||||
DoubleLinklistType *node = NONE;
|
||||
DoubleLinklistType *head = &candrv_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("CanDriverFind cannot find the %s driver.return NULL\n", drv_name);
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/*Register the Driver, manage with the double linklist*/
|
||||
int CanDriverRegister(struct Driver *driver)
|
||||
{
|
||||
NULL_PARAM_CHECK(driver);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
static x_bool driver_link_flag = RET_FALSE;
|
||||
|
||||
if (!driver_link_flag) {
|
||||
CanDrvLinkInit();
|
||||
driver_link_flag = RET_TRUE;
|
||||
}
|
||||
|
||||
DoubleLinkListInsertNodeAfter(&candrv_linklist, &(driver->driver_link));
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user