forked from xuos/xiuos
support PLC bus and clean codes
This commit is contained in:
parent
a101e994ff
commit
5185501d72
|
@ -17,6 +17,7 @@
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
* @date 2021-05-29
|
* @date 2021-05-29
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <transform.h>
|
#include <transform.h>
|
||||||
#include <xiuos.h>
|
#include <xiuos.h>
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
@ -24,25 +25,11 @@
|
||||||
#include <lwip/sockets.h>
|
#include <lwip/sockets.h>
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Definitions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#define TCP_DEMO_BUF_SIZE 65535
|
#define TCP_DEMO_BUF_SIZE 65535
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
char tcp_socket_ip[] = {192, 168, 250, 252};
|
char tcp_socket_ip[] = {192, 168, 250, 252};
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static void TCPSocketRecvTask(void *arg)
|
static void TCPSocketRecvTask(void *arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,27 +26,14 @@
|
||||||
#include <lwip/sockets.h>
|
#include <lwip/sockets.h>
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Definitions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#define UDP_BUF_SIZE 65536
|
#define UDP_BUF_SIZE 65536
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
extern char udp_target[];
|
extern char udp_target[];
|
||||||
static struct udp_pcb *udpecho_raw_pcb;
|
static struct udp_pcb *udpecho_raw_pcb;
|
||||||
char udp_socket_ip[] = {192, 168, 250, 252};
|
char udp_socket_ip[] = {192, 168, 250, 252};
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
static void UdpSocketRecvTask(void *arg)
|
static void UdpSocketRecvTask(void *arg)
|
||||||
{
|
{
|
||||||
lw_print("UdpSocketRecvTask start.\n");
|
lw_print("UdpSocketRecvTask start.\n");
|
||||||
|
|
|
@ -19,43 +19,27 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "open62541.h"
|
#include "open62541.h"
|
||||||
#include "plc.h"
|
|
||||||
#include "ua_api.h"
|
#include "ua_api.h"
|
||||||
#include "sys_arch.h"
|
#include "sys_arch.h"
|
||||||
#include "plc_bus.h"
|
#include "plc_bus.h"
|
||||||
#include "plc_dev.h"
|
#include "plc_dev.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
#define PLC_BUS_NAME "PLC"
|
||||||
* Definitions
|
#define PLC_DRV_NAME "OPCUA"
|
||||||
******************************************************************************/
|
#define PLC_DEV_NAME "PLC_1"
|
||||||
|
|
||||||
#define PLC_BUS_NAME "plc bus"
|
|
||||||
#define PLC_DRV_NAME "plc driver"
|
|
||||||
#define PLC_BUF_LEN 1000
|
#define PLC_BUF_LEN 1000
|
||||||
|
|
||||||
#define PLC_STACK_SIZE 4096
|
#define PLC_STACK_SIZE 4096
|
||||||
#define PLC_TASK_PRIO 15
|
#define PLC_TASK_PRIO 15
|
||||||
|
|
||||||
#define plc_print KPrintf
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
struct PlcBus plc_demo_bus;
|
struct PlcBus plc_demo_bus;
|
||||||
struct PlcDriver plc_demo_drv;
|
struct PlcDriver plc_demo_drv;
|
||||||
struct PlcDevice plc_demo_dev;
|
struct PlcDevice plc_demo_dev;
|
||||||
|
|
||||||
char plc_demo_ip[] = {192, 168, 250, 5};
|
char plc_demo_ip[] = {192, 168, 250, 5};
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
void PlcTestInit(void)
|
void PlcTestInit(void)
|
||||||
{
|
{
|
||||||
|
@ -63,10 +47,13 @@ void PlcTestInit(void)
|
||||||
|
|
||||||
PlcBusInit(&plc_demo_bus, PLC_BUS_NAME);
|
PlcBusInit(&plc_demo_bus, PLC_BUS_NAME);
|
||||||
PlcDriverInit(&plc_demo_drv, PLC_DRV_NAME);
|
PlcDriverInit(&plc_demo_drv, PLC_DRV_NAME);
|
||||||
|
PlcDriverAttachToBus(PLC_DRV_NAME, PLC_BUS_NAME);
|
||||||
|
|
||||||
// register plc device
|
// register plc device
|
||||||
plc_demo_dev.state = DEV_INIT;
|
plc_demo_dev.state = DEV_INIT;
|
||||||
PlcDevRegister(&plc_demo_dev, NULL, "plc test device");
|
PlcDevRegister(&plc_demo_dev, NULL, PLC_DEV_NAME);
|
||||||
|
|
||||||
|
PlcDeviceAttachToBus(PLC_DEV_NAME, PLC_BUS_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlcReadUATask(void *arg)
|
void PlcReadUATask(void *arg)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
SRC_FILES := plc.c plc_dev.c plc_bus.c plc_drv.c
|
SRC_FILES := plc_dev.c plc_bus.c plc_drv.c
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
||||||
|
|
|
@ -1,185 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2021 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 plc.c
|
|
||||||
* @brief plc relative activities
|
|
||||||
* @version 1.0
|
|
||||||
* @author AIIT XUOS Lab
|
|
||||||
* @date 2021.12.15
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "open62541.h"
|
|
||||||
#include "ua_api.h"
|
|
||||||
#include "plc.h"
|
|
||||||
#include "plc_bus.h"
|
|
||||||
#include "plc_dev.h"
|
|
||||||
|
|
||||||
|
|
||||||
static DoubleLinklistType plcdev_list;
|
|
||||||
|
|
||||||
int PlcDevConfigure(struct HardwareDev *dev, uint8 plc_chip_select, uint8 plc_cs_release);
|
|
||||||
|
|
||||||
|
|
||||||
/*Create the plc device linklist*/
|
|
||||||
static void PlcDeviceLinkInit()
|
|
||||||
{
|
|
||||||
InitDoubleLinkList(&plcdev_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int PlcDeviceOpen(void *dev)
|
|
||||||
{
|
|
||||||
NULL_PARAM_CHECK(dev);
|
|
||||||
|
|
||||||
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
|
||||||
|
|
||||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
|
||||||
{
|
|
||||||
return ua_open(plc_dev->priv_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PlcDeviceClose(void *dev)
|
|
||||||
{
|
|
||||||
NULL_PARAM_CHECK(dev);
|
|
||||||
|
|
||||||
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
|
||||||
|
|
||||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
|
||||||
{
|
|
||||||
ua_close(plc_dev->priv_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int PlcDeviceWrite(void *dev, const void *buf, size_t len)
|
|
||||||
{
|
|
||||||
NULL_PARAM_CHECK(dev);
|
|
||||||
NULL_PARAM_CHECK(buf);
|
|
||||||
|
|
||||||
int ret;
|
|
||||||
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
|
||||||
|
|
||||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
|
||||||
{
|
|
||||||
ret = ua_write(plc_dev->priv_data, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int PlcDeviceRead(void *dev, void *buf, size_t len)
|
|
||||||
{
|
|
||||||
NULL_PARAM_CHECK(dev);
|
|
||||||
NULL_PARAM_CHECK(buf);
|
|
||||||
|
|
||||||
int ret;
|
|
||||||
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
|
||||||
|
|
||||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
|
||||||
{
|
|
||||||
ret = ua_read(plc_dev->priv_data, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct PlcOps plc_done =
|
|
||||||
{
|
|
||||||
.open = PlcDeviceOpen,
|
|
||||||
.close = PlcDeviceClose,
|
|
||||||
.write = PlcDeviceWrite,
|
|
||||||
.read = PlcDeviceRead,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PlcDevice *PlcDevFind(const char *dev_name, enum DevType dev_type)
|
|
||||||
{
|
|
||||||
NULL_PARAM_CHECK(dev_name);
|
|
||||||
|
|
||||||
struct PlcDevice *device = NONE;
|
|
||||||
|
|
||||||
DoubleLinklistType *node = NONE;
|
|
||||||
DoubleLinklistType *head = &plcdev_list;
|
|
||||||
|
|
||||||
for (node = head->node_next; node != head; node = node->node_next) {
|
|
||||||
device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct PlcDevice, link);
|
|
||||||
if ((!strcmp(device->name, dev_name)) && (dev_type == device->type)) {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KPrintf("PlcDevFind cannot find the %s device.return NULL\n", dev_name);
|
|
||||||
return NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PlcDevRegister(struct PlcDevice *plc_device, void *plc_param, const char *device_name)
|
|
||||||
{
|
|
||||||
NULL_PARAM_CHECK(plc_device);
|
|
||||||
NULL_PARAM_CHECK(device_name);
|
|
||||||
|
|
||||||
x_err_t ret = EOK;
|
|
||||||
static x_bool dev_link_flag = RET_FALSE;
|
|
||||||
|
|
||||||
if (!dev_link_flag) {
|
|
||||||
PlcDeviceLinkInit();
|
|
||||||
dev_link_flag = RET_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DEV_INSTALL != plc_device->state) {
|
|
||||||
strncpy(plc_device->name, device_name, strlen(device_name));
|
|
||||||
plc_device->ops = &plc_done;
|
|
||||||
DoubleLinkListInsertNodeAfter(&plcdev_list, &(plc_device->link));
|
|
||||||
plc_device->state = DEV_INSTALL;
|
|
||||||
} else {
|
|
||||||
KPrintf("PlcDevRegister device has been register state%u\n", plc_device->type);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PlcDeviceAttachToBus(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("PlcDeviceAttachToBus find plc bus error!name %s\n", bus_name);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TYPE_PLC_BUS == bus->bus_type) {
|
|
||||||
device = PlcHardwareDevFind(dev_name, TYPE_PLC_DEV);
|
|
||||||
if (NONE == device) {
|
|
||||||
KPrintf("PlcDeviceAttachToBus find plc device error!name %s\n", dev_name);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TYPE_PLC_DEV == device->dev_type) {
|
|
||||||
ret = DeviceRegisterToBus(bus, device);
|
|
||||||
if (EOK != ret) {
|
|
||||||
KPrintf("PlcDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,140 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2021 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 plc.h
|
|
||||||
* @brief plc relative definition and structure
|
|
||||||
* @version 1.0
|
|
||||||
* @author AIIT XUOS Lab
|
|
||||||
* @date 2022-01-24
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __PLC_H_
|
|
||||||
#define __PLC_H_
|
|
||||||
|
|
||||||
#include "bus.h"
|
|
||||||
#include "xs_klist.h"
|
|
||||||
|
|
||||||
#define IP_ADDR_SIZE 32
|
|
||||||
#define PLC_NAME_SIZE 32
|
|
||||||
|
|
||||||
// PLC device information
|
|
||||||
struct PlcInfo {
|
|
||||||
uint32_t ability; // PLC ability
|
|
||||||
uint32_t id; // PLC Device ID
|
|
||||||
uint32_t soft_version; // software version
|
|
||||||
uint32_t hard_version; // hardware version
|
|
||||||
uint32_t date; // manufact date
|
|
||||||
const char *vendor; // vendor
|
|
||||||
const char *model; // product model
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PlcSerialType {
|
|
||||||
PLC_SERIAL_232,
|
|
||||||
PLC_SERIAL_485,
|
|
||||||
PLC_SERIAL_CAN
|
|
||||||
};
|
|
||||||
|
|
||||||
union PlcCfg {
|
|
||||||
struct {
|
|
||||||
char ip_addr[IP_ADDR_SIZE];
|
|
||||||
uint32_t ip_port;
|
|
||||||
} PlcIpCfg;
|
|
||||||
struct {
|
|
||||||
enum PlcSerialType serial_type;
|
|
||||||
char station_id;
|
|
||||||
char serial_port;
|
|
||||||
} PlcSerialCfg;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PlcDevice;
|
|
||||||
|
|
||||||
#undef open
|
|
||||||
#undef close
|
|
||||||
#undef read
|
|
||||||
#undef write
|
|
||||||
|
|
||||||
// operation API
|
|
||||||
struct PlcOps {
|
|
||||||
int (*open)(void *dev); // open and connect PLC device
|
|
||||||
void (*close)(void* dev); // close and disconnect PLC device
|
|
||||||
int (*read)(void* dev, void *buf, size_t len); // read data from PLC
|
|
||||||
int (*write)(void* dev, const void *buf, size_t len); // write data from PLC
|
|
||||||
int (*ioctl)(void* dev, int cmd, void *arg); // send control command to PLC
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PlcCtlType {
|
|
||||||
PLC_CTRL_TYPE_HSC,
|
|
||||||
PLC_CTRL_TYPE_PID,
|
|
||||||
PLC_CTRL_TYPE_PHASING
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define PLC_ABILITY_HSC ((uint32_t)(1 << PLC_CTRL_TYPE_HSC))
|
|
||||||
#define PLC_ABILITY_PID ((uint32_t)(1 << PLC_CTRL_TYPE_PID))
|
|
||||||
#define PLC_ABILITY_PHASING ((uint32_t)(1 << PLC_CTRL_TYPE_PHASING))
|
|
||||||
|
|
||||||
|
|
||||||
enum PlcIndHybridNet
|
|
||||||
{
|
|
||||||
// PLC Field Bus
|
|
||||||
PLC_IND_FIELD_MODBUS_485,
|
|
||||||
PLC_IND_FIELD_PROFIBUS,
|
|
||||||
PLC_IND_FIELD_CANOPEN,
|
|
||||||
PLC_IND_FIELD_DEVICENET,
|
|
||||||
PLC_IND_FIELD_CONTROLNET,
|
|
||||||
|
|
||||||
// PLC ETHERNET
|
|
||||||
PLC_IND_ENET_ETHERNET_IP,
|
|
||||||
PLC_IND_ENET_PROFINET,
|
|
||||||
PLC_IND_ENET_ETHERCAT,
|
|
||||||
PLC_IND_ENET_SERCOS,
|
|
||||||
PLC_IND_ENET_OPCUA,
|
|
||||||
|
|
||||||
// PLC wireless net
|
|
||||||
PLC_IND_WIRELESS
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PlcTransType
|
|
||||||
{
|
|
||||||
PLC_TRANS_TCP,
|
|
||||||
PLC_TRANS_UDP,
|
|
||||||
PLC_TRANS_SERIAL
|
|
||||||
};
|
|
||||||
|
|
||||||
//communication interface
|
|
||||||
struct PlcInterface
|
|
||||||
{
|
|
||||||
char ip_addr[IP_ADDR_SIZE];
|
|
||||||
char attrib;
|
|
||||||
};
|
|
||||||
|
|
||||||
// identify PLC device
|
|
||||||
struct PlcDevice {
|
|
||||||
char name[PLC_NAME_SIZE]; /* name of the device */
|
|
||||||
enum PlcCtlType type; /* PLC Control Type */
|
|
||||||
enum DevState state;
|
|
||||||
enum PlcIndHybridNet net;
|
|
||||||
enum PlcTransType trans;
|
|
||||||
|
|
||||||
struct PlcInfo info;/* Plc info, such as vendor name and model name */
|
|
||||||
union PlcCfg cfg;
|
|
||||||
struct PlcOps *ops; /* filesystem-like APIs for data transferring */
|
|
||||||
struct PlcInterface interface; /* protocols used for transferring data from program to plc */
|
|
||||||
|
|
||||||
void *priv_data;
|
|
||||||
DoubleLinklistType link;/* link list node */
|
|
||||||
};
|
|
||||||
|
|
||||||
int PlcDevRegister(struct PlcDevice *plc_device, void *plc_param, const char *device_name);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include "plc_bus.h"
|
#include "plc_bus.h"
|
||||||
#include "plc_dev.h"
|
#include "plc_dev.h"
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
int PlcBusInit(struct PlcBus *plc_bus, const char *bus_name)
|
int PlcBusInit(struct PlcBus *plc_bus, const char *bus_name)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(plc_bus);
|
NULL_PARAM_CHECK(plc_bus);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 AIIT XUOS Lab
|
* Copyright (c) 2021 AIIT XUOS Lab
|
||||||
* XiUOS is licensed under Mulan PSL v2.
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
* You can use this software according to the terms and conditions of the 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:
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
@ -11,136 +11,117 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file plc_dev.c
|
* @file plc.c
|
||||||
* @brief register plc dev function using bus driver framework
|
* @brief plc relative activities
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
* @date 2022-01-24
|
* @date 2021.12.15
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ua_api.h"
|
||||||
#include "plc_bus.h"
|
#include "plc_bus.h"
|
||||||
#include "plc_dev.h"
|
#include "plc_dev.h"
|
||||||
|
|
||||||
static DoubleLinklistType plcdev_linklist;
|
static DoubleLinklistType plcdev_list;
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
/*Create the plc device linklist*/
|
/*Create the plc device linklist*/
|
||||||
static void PlcHardwareDevLinkInit()
|
static void PlcDeviceLinkInit()
|
||||||
{
|
{
|
||||||
InitDoubleLinkList(&plcdev_linklist);
|
InitDoubleLinkList(&plcdev_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32 PlcHardwareDevOpen(void *dev)
|
static int PlcDeviceOpen(void *dev)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(dev);
|
NULL_PARAM_CHECK(dev);
|
||||||
|
|
||||||
PlcHardwareDevConfigureCs(dev, 1, 0);
|
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
||||||
|
|
||||||
|
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||||
|
{
|
||||||
|
return ua_open(plc_dev->priv_data);
|
||||||
|
}
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void PlcDeviceClose(void *dev)
|
||||||
static uint32 PlcHardwareDevClose(void *dev)
|
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(dev);
|
NULL_PARAM_CHECK(dev);
|
||||||
|
|
||||||
PlcHardwareDevConfigureCs(dev, 0, 1);
|
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
||||||
|
|
||||||
return EOK;
|
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||||
|
{
|
||||||
|
ua_close(plc_dev->priv_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int PlcDeviceWrite(void *dev, const void *buf, size_t len)
|
||||||
static uint32 PlcHardwareDevWrite(void *dev, struct BusBlockWriteParam *write_param)
|
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(dev);
|
NULL_PARAM_CHECK(dev);
|
||||||
NULL_PARAM_CHECK(write_param);
|
NULL_PARAM_CHECK(buf);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
struct PlcHardwareDevice *plc_dev = (struct PlcHardwareDevice *)dev;
|
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
||||||
struct PlcDataStandard *plc_msg;
|
|
||||||
|
|
||||||
plc_msg = (struct PlcDataStandard *)x_malloc(sizeof(struct PlcDataStandard));
|
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||||
if (NONE == plc_msg) {
|
{
|
||||||
KPrintf("PlcHardwareDevWrite x_malloc msg error\n");
|
ret = ua_write(plc_dev->priv_data, buf, len);
|
||||||
x_free(plc_msg);
|
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//memset(plc_msg, 0, sizeof(struct PlcDataStandard));
|
|
||||||
|
|
||||||
plc_msg->tx_buff = (uint8 *)write_param->buffer;
|
|
||||||
plc_msg->rx_buff = NONE;
|
|
||||||
plc_msg->length = write_param->size;
|
|
||||||
plc_msg->plc_chip_select = 0;
|
|
||||||
plc_msg->plc_cs_release = 0;
|
|
||||||
plc_msg->next = NONE;
|
|
||||||
|
|
||||||
ret = plc_dev->plc_dev_done->dev_write(plc_dev, plc_msg);
|
|
||||||
x_free(plc_msg);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32 PlcHardwareDevRead(void *dev, struct BusBlockReadParam *read_param)
|
static int PlcDeviceRead(void *dev, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(dev);
|
NULL_PARAM_CHECK(dev);
|
||||||
NULL_PARAM_CHECK(read_param);
|
NULL_PARAM_CHECK(buf);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
|
||||||
|
|
||||||
struct PlcHardwareDevice *plc_dev = (struct PlcHardwareDevice *)dev;
|
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||||
|
{
|
||||||
struct PlcDataStandard *plc_msg;
|
ret = ua_read(plc_dev->priv_data, buf, len);
|
||||||
|
|
||||||
plc_msg = (struct PlcDataStandard *)x_malloc(sizeof(struct PlcDataStandard));
|
|
||||||
if (NONE == plc_msg) {
|
|
||||||
x_free(plc_msg);
|
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//memset(plc_msg, 0, sizeof(struct PlcDataStandard));
|
|
||||||
|
|
||||||
plc_msg->tx_buff = NONE;
|
|
||||||
plc_msg->rx_buff = (uint8 *)read_param->buffer;
|
|
||||||
plc_msg->length = read_param->size;
|
|
||||||
plc_msg->plc_chip_select = 0;
|
|
||||||
plc_msg->plc_cs_release = 0;
|
|
||||||
plc_msg->next = NONE;
|
|
||||||
|
|
||||||
ret = plc_dev->plc_dev_done->dev_read(plc_dev, plc_msg);
|
|
||||||
x_free(plc_msg);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct HalDevDone dev_done =
|
static struct PlcOps plc_done =
|
||||||
{
|
{
|
||||||
.open = PlcHardwareDevOpen,
|
.open = PlcDeviceOpen,
|
||||||
.close = PlcHardwareDevClose,
|
.close = PlcDeviceClose,
|
||||||
.write = PlcHardwareDevWrite,
|
.write = PlcDeviceWrite,
|
||||||
.read = PlcHardwareDevRead,
|
.read = PlcDeviceRead,
|
||||||
};
|
};
|
||||||
|
|
||||||
HardwareDevType PlcHardwareDevFind(const char *dev_name, enum DevType dev_type)
|
/* find PLC device with device name */
|
||||||
|
struct HardwareDev *PlcDevFind(const char *dev_name)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(dev_name);
|
NULL_PARAM_CHECK(dev_name);
|
||||||
|
|
||||||
struct HardwareDev *device = NONE;
|
struct PlcDevice *device = NONE;
|
||||||
|
struct HardwareDev *haldev = NONE;
|
||||||
|
|
||||||
DoubleLinklistType *node = NONE;
|
DoubleLinklistType *node = NONE;
|
||||||
DoubleLinklistType *head = &plcdev_linklist;
|
DoubleLinklistType *head = &plcdev_list;
|
||||||
|
|
||||||
for (node = head->node_next; node != head; node = node->node_next) {
|
for (node = head->node_next; node != head; node = node->node_next) {
|
||||||
device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct HardwareDev, dev_link);
|
device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct PlcDevice, link);
|
||||||
if ((!strcmp(device->dev_name, dev_name)) && (dev_type == device->dev_type)) {
|
if (!strcmp(device->name, dev_name)) {
|
||||||
return device;
|
haldev = &device->haldev;
|
||||||
|
return haldev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KPrintf("PlcHardwareDevFind cannot find the %s device.return NULL\n", dev_name);
|
plc_print("plc: [%s] cannot find the %s device\n", __func__, dev_name);
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlcHardwareDevRegister(struct PlcHardwareDevice *plc_device, void *plc_param, const char *device_name)
|
int PlcDevRegister(struct PlcDevice *plc_device, void *plc_param, const char *device_name)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(plc_device);
|
NULL_PARAM_CHECK(plc_device);
|
||||||
NULL_PARAM_CHECK(device_name);
|
NULL_PARAM_CHECK(device_name);
|
||||||
|
@ -149,31 +130,28 @@ int PlcHardwareDevRegister(struct PlcHardwareDevice *plc_device, void *plc_param
|
||||||
static x_bool dev_link_flag = RET_FALSE;
|
static x_bool dev_link_flag = RET_FALSE;
|
||||||
|
|
||||||
if (!dev_link_flag) {
|
if (!dev_link_flag) {
|
||||||
PlcHardwareDevLinkInit();
|
PlcDeviceLinkInit();
|
||||||
dev_link_flag = RET_TRUE;
|
dev_link_flag = RET_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEV_INSTALL != plc_device->haldev.dev_state) {
|
if (DEV_INSTALL != plc_device->state) {
|
||||||
strncpy(plc_device->haldev.dev_name, device_name, NAME_NUM_MAX);
|
strncpy(plc_device->haldev.dev_name, device_name, NAME_NUM_MAX);
|
||||||
plc_device->haldev.dev_type = TYPE_PLC_DEV;
|
plc_device->haldev.dev_type = TYPE_PLC_DEV;
|
||||||
plc_device->haldev.dev_state = DEV_INSTALL;
|
plc_device->haldev.dev_state = DEV_INSTALL;
|
||||||
|
|
||||||
//only plc bus dev need to register dev_done
|
strncpy(plc_device->name, device_name, strlen(device_name));
|
||||||
if (RET_TRUE != plc_device->plc_dev_flag) {
|
plc_device->ops = &plc_done;
|
||||||
plc_device->haldev.dev_done = &dev_done;
|
|
||||||
}
|
|
||||||
|
|
||||||
plc_device->haldev.private_data = plc_param;
|
DoubleLinkListInsertNodeAfter(&plcdev_list, &(plc_device->link));
|
||||||
|
plc_device->state = DEV_INSTALL;
|
||||||
DoubleLinkListInsertNodeAfter(&plcdev_linklist, &(plc_device->haldev.dev_link));
|
|
||||||
} else {
|
} else {
|
||||||
KPrintf("PlcHardwareDevRegister device has been register state%u\n", plc_device->haldev.dev_state);
|
KPrintf("PlcDevRegister device has been register state%u\n", plc_device->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlcHardwareDevAttachToBus(const char *dev_name, const char *bus_name)
|
int PlcDeviceAttachToBus(const char *dev_name, const char *bus_name)
|
||||||
{
|
{
|
||||||
NULL_PARAM_CHECK(dev_name);
|
NULL_PARAM_CHECK(dev_name);
|
||||||
NULL_PARAM_CHECK(bus_name);
|
NULL_PARAM_CHECK(bus_name);
|
||||||
|
@ -185,21 +163,21 @@ int PlcHardwareDevAttachToBus(const char *dev_name, const char *bus_name)
|
||||||
|
|
||||||
bus = BusFind(bus_name);
|
bus = BusFind(bus_name);
|
||||||
if (NONE == bus) {
|
if (NONE == bus) {
|
||||||
KPrintf("PlcHardwareDevAttachToBus find plc bus error!name %s\n", bus_name);
|
KPrintf("PlcDeviceAttachToBus find plc bus error!name %s\n", bus_name);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TYPE_PLC_BUS == bus->bus_type) {
|
if (TYPE_PLC_BUS == bus->bus_type) {
|
||||||
device = PlcHardwareDevFind(dev_name, TYPE_PLC_DEV);
|
device = PlcDevFind(dev_name);
|
||||||
if (NONE == device) {
|
if (NONE == device) {
|
||||||
KPrintf("PlcHardwareDevAttachToBus find plc device error!name %s\n", dev_name);
|
KPrintf("PlcDeviceAttachToBus find plc device error!name %s\n", dev_name);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TYPE_PLC_DEV == device->dev_type) {
|
if (TYPE_PLC_DEV == device->dev_type) {
|
||||||
ret = DeviceRegisterToBus(bus, device);
|
ret = DeviceRegisterToBus(bus, device);
|
||||||
if (EOK != ret) {
|
if (EOK != ret) {
|
||||||
KPrintf("PlcHardwareDevAttachToBus DeviceRegisterToBus error %u\n", ret);
|
KPrintf("PlcDeviceAttachToBus DeviceRegisterToBus error %u\n", ret);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,32 +186,3 @@ int PlcHardwareDevAttachToBus(const char *dev_name, const char *bus_name)
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlcHardwareDevConfigureCs(struct HardwareDev *dev, uint8 plc_chip_select, uint8 plc_cs_release)
|
|
||||||
{
|
|
||||||
NULL_PARAM_CHECK(dev);
|
|
||||||
|
|
||||||
int ret;
|
|
||||||
struct PlcHardwareDevice *plc_dev = (struct PlcHardwareDevice *)dev;
|
|
||||||
struct PlcDataStandard *msg;
|
|
||||||
|
|
||||||
msg = (struct PlcDataStandard *)x_malloc(sizeof(struct PlcDataStandard));
|
|
||||||
if (NONE == msg){
|
|
||||||
KPrintf("PlcHardwareDevConfigureCs x_malloc msg error\n");
|
|
||||||
x_free(msg);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
//memset(msg, 0, sizeof(struct PlcDataStandard));
|
|
||||||
msg->length = 0;
|
|
||||||
msg->rx_buff = NONE;
|
|
||||||
msg->tx_buff = NONE;
|
|
||||||
msg->next = NONE;
|
|
||||||
msg->plc_chip_select = plc_chip_select;
|
|
||||||
msg->plc_cs_release = plc_cs_release;
|
|
||||||
|
|
||||||
ret = plc_dev->plc_dev_done->dev_write(plc_dev, msg);
|
|
||||||
|
|
||||||
x_free(msg);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 AIIT XUOS Lab
|
* Copyright (c) 2021 AIIT XUOS Lab
|
||||||
* XiUOS is licensed under Mulan PSL v2.
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
* You can use this software according to the terms and conditions of the 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:
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
@ -11,129 +11,139 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file dev_plc.h
|
* @file plc_dev.h
|
||||||
* @brief define plc dev function using bus driver framework
|
* @brief plc relative definition and structure
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
* @date 2022-01-24
|
* @date 2022-01-24
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DEV_PLC_H
|
#ifndef __PLC_DEV_H_
|
||||||
#define DEV_PLC_H
|
#define __PLC_DEV_H_
|
||||||
|
|
||||||
#include <bus.h>
|
#include "bus.h"
|
||||||
|
#include "xs_klist.h"
|
||||||
|
|
||||||
#ifdef __cpluspluss
|
#undef open
|
||||||
extern "C" {
|
#undef close
|
||||||
#endif
|
#undef read
|
||||||
|
#undef write
|
||||||
|
|
||||||
#define PLC_MAX_CLOCK 40000000
|
#define IP_ADDR_SIZE 32
|
||||||
#define plc_device_max_num 4
|
#define PLC_NAME_SIZE 32
|
||||||
|
|
||||||
#define PLC_LINE_CPHA (1 << 0)
|
// PLC device information
|
||||||
#define PLC_LINE_CPOL (1 << 1)
|
struct PlcInfo {
|
||||||
|
uint32_t ability; // PLC ability
|
||||||
#define PLC_LSB (0 << 2)
|
uint32_t id; // PLC Device ID
|
||||||
#define PLC_MSB (1 << 2)
|
uint32_t soft_version; // software version
|
||||||
|
uint32_t hard_version; // hardware version
|
||||||
#define PLC_MASTER (0 << 3)
|
uint32_t date; // manufact date
|
||||||
#define DEV_PLC_SLAVE (1 << 3)
|
const char *vendor; // vendor
|
||||||
|
const char *model; // product model
|
||||||
#define PLC_MODE_0 (0 | 0)
|
|
||||||
#define PLC_MODE_1 (0 | PLC_LINE_CPHA)
|
|
||||||
#define PLC_MODE_2 (PLC_LINE_CPOL | 0)
|
|
||||||
#define PLC_MODE_3 (PLC_LINE_CPOL | PLC_LINE_CPHA)
|
|
||||||
#define PLC_MODE_MASK (PLC_LINE_CPHA | PLC_LINE_CPOL | PLC_MSB)
|
|
||||||
|
|
||||||
#define PLC_CS_HIGH (1 << 4)
|
|
||||||
#define PLC_NO_CS (1 << 5)
|
|
||||||
#define PLC_3WIRE (1 << 6)
|
|
||||||
#define PLC_READY (1 << 7)
|
|
||||||
|
|
||||||
struct PlcDataStandard
|
|
||||||
{
|
|
||||||
uint8 plc_chip_select;
|
|
||||||
uint8 plc_cs_release;
|
|
||||||
|
|
||||||
const uint8 *tx_buff;
|
|
||||||
uint32 tx_len;
|
|
||||||
|
|
||||||
uint8 *rx_buff;
|
|
||||||
uint32 rx_len;
|
|
||||||
|
|
||||||
uint32 length;
|
|
||||||
struct PlcDataStandard *next;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlcMasterParam
|
enum PlcSerialType {
|
||||||
{
|
PLC_SERIAL_232,
|
||||||
uint8 plc_work_mode;//CPOL CPHA
|
PLC_SERIAL_485,
|
||||||
uint8 plc_frame_format;//frame format
|
PLC_SERIAL_CAN
|
||||||
uint8 plc_data_bit_width;//bit width
|
|
||||||
uint8 plc_data_endian;//little endian 0 : big endian 1
|
|
||||||
uint32 plc_maxfrequency;//work frequency
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlcDmaParam
|
union PlcCfg {
|
||||||
{
|
struct {
|
||||||
uint8 plc_master_id;
|
char ip_addr[IP_ADDR_SIZE];
|
||||||
uint8 plc_dmac_txchannel;
|
uint32_t ip_port;
|
||||||
uint8 plc_dmac_rxchannel;
|
} PlcIpCfg;
|
||||||
|
struct {
|
||||||
|
enum PlcSerialType serial_type;
|
||||||
|
char station_id;
|
||||||
|
char serial_port;
|
||||||
|
} PlcSerialCfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlcSlaveParam
|
struct PlcDevice;
|
||||||
{
|
|
||||||
uint8 plc_slave_id;
|
// operation API
|
||||||
uint8 plc_cs_gpio_pin;
|
struct PlcOps {
|
||||||
uint8 plc_cs_select_id;
|
int (*open)(void *dev); // open and connect PLC device
|
||||||
|
void (*close)(void* dev); // close and disconnect PLC device
|
||||||
|
int (*read)(void* dev, void *buf, size_t len); // read data from PLC
|
||||||
|
int (*write)(void* dev, const void *buf, size_t len); // write data from PLC
|
||||||
|
int (*ioctl)(void* dev, int cmd, void *arg); // send control command to PLC
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
enum PlcCtlType {
|
||||||
{
|
PLC_CTRL_TYPE_HSC,
|
||||||
struct PlcDmaParam *plc_dma_param;
|
PLC_CTRL_TYPE_PID,
|
||||||
|
PLC_CTRL_TYPE_PHASING
|
||||||
struct PlcSlaveParam *plc_slave_param;
|
|
||||||
|
|
||||||
struct PlcMasterParam *plc_master_param;
|
|
||||||
|
|
||||||
}PlcDeviceParam;
|
|
||||||
|
|
||||||
struct PlcHardwareDevice;
|
|
||||||
|
|
||||||
struct PlcDevDone
|
|
||||||
{
|
|
||||||
uint32 (*dev_open) (struct PlcHardwareDevice *dev);
|
|
||||||
uint32 (*dev_close) (struct PlcHardwareDevice *dev);
|
|
||||||
uint32 (*dev_write) (struct PlcHardwareDevice *dev, struct PlcDataStandard *msg);
|
|
||||||
uint32 (*dev_read) (struct PlcHardwareDevice *dev, struct PlcDataStandard *msg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlcHardwareDevice
|
|
||||||
|
#define PLC_ABILITY_HSC ((uint32_t)(1 << PLC_CTRL_TYPE_HSC))
|
||||||
|
#define PLC_ABILITY_PID ((uint32_t)(1 << PLC_CTRL_TYPE_PID))
|
||||||
|
#define PLC_ABILITY_PHASING ((uint32_t)(1 << PLC_CTRL_TYPE_PHASING))
|
||||||
|
|
||||||
|
|
||||||
|
enum PlcIndHybridNet
|
||||||
{
|
{
|
||||||
struct HardwareDev haldev;
|
// PLC Field Bus
|
||||||
PlcDeviceParam plc_param;
|
PLC_IND_FIELD_MODBUS_485,
|
||||||
|
PLC_IND_FIELD_PROFIBUS,
|
||||||
|
PLC_IND_FIELD_CANOPEN,
|
||||||
|
PLC_IND_FIELD_DEVICENET,
|
||||||
|
PLC_IND_FIELD_CONTROLNET,
|
||||||
|
|
||||||
x_bool plc_dev_flag;
|
// PLC ETHERNET
|
||||||
|
PLC_IND_ENET_ETHERNET_IP,
|
||||||
|
PLC_IND_ENET_PROFINET,
|
||||||
|
PLC_IND_ENET_ETHERCAT,
|
||||||
|
PLC_IND_ENET_SERCOS,
|
||||||
|
PLC_IND_ENET_OPCUA,
|
||||||
|
|
||||||
const struct PlcDevDone *plc_dev_done;
|
// PLC wireless net
|
||||||
|
PLC_IND_WIRELESS
|
||||||
void *private_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Register the plc device*/
|
enum PlcTransType
|
||||||
int PlcHardwareDevRegister(struct PlcHardwareDevice *plc_device, void *plc_param, const char *device_name);
|
{
|
||||||
|
PLC_TRANS_TCP,
|
||||||
|
PLC_TRANS_UDP,
|
||||||
|
PLC_TRANS_SERIAL
|
||||||
|
};
|
||||||
|
|
||||||
/*Register the plc device to the plc bus*/
|
//communication interface
|
||||||
int PlcHardwareDeviceAttachToBus(const char *dev_name, const char *bus_name);
|
struct PlcInterface
|
||||||
|
{
|
||||||
|
char ip_addr[IP_ADDR_SIZE];
|
||||||
|
char attrib;
|
||||||
|
};
|
||||||
|
|
||||||
/*Find the register plc device*/
|
// identify PLC device
|
||||||
HardwareDevType PlcHardwareDevFind(const char *dev_name, enum DevType dev_type);
|
struct PlcDevice {
|
||||||
|
struct HardwareDev haldev; /* hardware device driver for bus */
|
||||||
|
char name[PLC_NAME_SIZE]; /* name of the device */
|
||||||
|
enum PlcCtlType type; /* PLC Control Type */
|
||||||
|
enum DevState state;
|
||||||
|
enum PlcIndHybridNet net;
|
||||||
|
enum PlcTransType trans;
|
||||||
|
|
||||||
/*Configure the cs pin of plc dev*/
|
struct PlcInfo info;/* Plc info, such as vendor name and model name */
|
||||||
int PlcHardwareDevConfigureCs(struct HardwareDev *dev, uint8 plc_chip_select, uint8 plc_cs_release);
|
union PlcCfg cfg;
|
||||||
|
struct PlcOps *ops; /* filesystem-like APIs for data transferring */
|
||||||
|
struct PlcInterface interface; /* protocols used for transferring data from program to plc */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
void *priv_data; /* private data for different PLC*/
|
||||||
}
|
DoubleLinklistType link;/* link list node */
|
||||||
#endif
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define plc_print KPrintf
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
int PlcDevRegister(struct PlcDevice *plc_device, void *plc_param, const char *device_name);
|
||||||
|
int PlcDeviceAttachToBus(const char *dev_name, const char *bus_name);
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
static DoubleLinklistType plcdrv_linklist;
|
static DoubleLinklistType plcdrv_linklist;
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
/*Create the driver linklist*/
|
/*Create the driver linklist*/
|
||||||
static void PlcDrvLinkInit()
|
static void PlcDrvLinkInit()
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,11 +18,6 @@
|
||||||
* @date 2021.12.15
|
* @date 2021.12.15
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Includes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#include "lwip/opt.h"
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
#if LWIP_IPV4 && LWIP_RAW
|
#if LWIP_IPV4 && LWIP_RAW
|
||||||
|
@ -41,21 +36,7 @@
|
||||||
#include <sys_arch.h>
|
#include <sys_arch.h>
|
||||||
#include "connect_ethernet.h"
|
#include "connect_ethernet.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Definitions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static void *LwipSetIPTask(void *param)
|
static void *LwipSetIPTask(void *param)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,23 +39,9 @@
|
||||||
#include "fsl_iomuxc.h"
|
#include "fsl_iomuxc.h"
|
||||||
#include "sys_arch.h"
|
#include "sys_arch.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Definitions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#define LWIP_DHCP_TIME 10000 // 10s
|
#define LWIP_DHCP_TIME 10000 // 10s
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Prints DHCP status of the interface when it has changed from last status.
|
* @brief Prints DHCP status of the interface when it has changed from last status.
|
||||||
|
|
|
@ -18,10 +18,6 @@
|
||||||
* @date 2021.12.15
|
* @date 2021.12.15
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Includes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#include "lwip/opt.h"
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
#if LWIP_IPV4 && LWIP_RAW
|
#if LWIP_IPV4 && LWIP_RAW
|
||||||
|
@ -39,26 +35,12 @@
|
||||||
#include <sys_arch.h>
|
#include <sys_arch.h>
|
||||||
#include "connect_ethernet.h"
|
#include "connect_ethernet.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Definitions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
char test_ip_addr[] = {192, 168, 250, 253};
|
char test_ip_addr[] = {192, 168, 250, 253};
|
||||||
char test_net_mask[] = {255, 255, 255, 0};
|
char test_net_mask[] = {255, 255, 255, 0};
|
||||||
char test_gw_addr[] = {192, 168, 250, 252};
|
char test_gw_addr[] = {192, 168, 250, 252};
|
||||||
ip4_addr_t ping_addr;
|
ip4_addr_t ping_addr;
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
void LwipPingTest(int argc, char *argv[])
|
void LwipPingTest(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,27 +24,13 @@
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
#include "tcpecho_raw.h"
|
#include "tcpecho_raw.h"
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Definitions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#define MSG_SIZE 128
|
#define MSG_SIZE 128
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
// this is for test in shell, in fact, shell restrict the length of input string, which is less then 128
|
// this is for test in shell, in fact, shell restrict the length of input string, which is less then 128
|
||||||
char tcp_send_msg[MSG_SIZE] = {0};
|
char tcp_send_msg[MSG_SIZE] = {0};
|
||||||
char tcp_target[] = {192, 168, 250, 252};
|
char tcp_target[] = {192, 168, 250, 252};
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static void LwipTcpSendTask(void *arg)
|
static void LwipTcpSendTask(void *arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,31 +24,16 @@
|
||||||
#include <lwip/sockets.h>
|
#include <lwip/sockets.h>
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Definitions
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#define UDP_TASK_STACK_SIZE 4096
|
#define UDP_TASK_STACK_SIZE 4096
|
||||||
#define UDP_TASK_PRIO 15
|
#define UDP_TASK_PRIO 15
|
||||||
#define PBUF_SIZE 27
|
#define PBUF_SIZE 27
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Prototypes
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static struct udp_pcb *udpecho_raw_pcb;
|
static struct udp_pcb *udpecho_raw_pcb;
|
||||||
char udp_target[] = {192, 168, 250, 252};
|
char udp_target[] = {192, 168, 250, 252};
|
||||||
char hello_str[] = {"hello world\r\n"};
|
char hello_str[] = {"hello world\r\n"};
|
||||||
char udp_send_msg[] = "\n\nThis one is UDP pkg. Congratulations on you.\n\n";
|
char udp_send_msg[] = "\n\nThis one is UDP pkg. Congratulations on you.\n\n";
|
||||||
|
|
||||||
/*******************************************************************************
|
/******************************************************************************/
|
||||||
* Code
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static void LwipUDPSendTask(void *arg)
|
static void LwipUDPSendTask(void *arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -384,6 +384,7 @@ static char *const bus_type_str[] =
|
||||||
"SERIAL_BUS",
|
"SERIAL_BUS",
|
||||||
"ADC_BUS",
|
"ADC_BUS",
|
||||||
"DAC_BUS",
|
"DAC_BUS",
|
||||||
|
"PLC_BUS",
|
||||||
"Unknown"
|
"Unknown"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue