Lely CANopen port

This commit is contained in:
raiden00pl 2022-10-21 16:30:18 +02:00 committed by Xiang Xiao
parent 0a6539bfc5
commit 003dbe1837
6 changed files with 1182 additions and 0 deletions

2
canutils/lely-canopen/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/lely-*
/*.tar.gz

View File

@ -0,0 +1,512 @@
From 2232cb2e64241fd56293a6bcc51365dd220bdd5d Mon Sep 17 00:00:00 2001
From: raiden00pl <raiden00@railab.me>
Date: Thu, 6 Oct 2022 15:12:49 +0200
Subject: [PATCH] NuttX port tools/coctl.c: eliminate multiple definitions of
poll error for flat address space systems
tools/coctl.c: use readline instead of getline
tools/coctl.c: fix printf warnings
fix compiler warnings related to 'struct __frbuf'
warning: 'struct __frbuf' declared inside parameter list will not be visible outside of this definition or declaration
warning: 'struct __fwbuf' declared inside parameter list will not be visible outside of this definition or declaration
src/io/poll.c: NuttX support
src/util/frbuf.c: NuttX support
src/util/fwbuf.c: NuttX support
src/can/socket.c: NuttX support
src/io/can.c: add support for NuttX
---
include/lely/co/val.h | 2 +-
src/can/socket.c | 7 +++-
src/io/can.c | 93 ++++++++++++++++++++++++++++++++++++++++++-
src/io/poll.c | 2 +-
src/util/frbuf.c | 18 ++++-----
src/util/fwbuf.c | 27 +++++++------
tools/coctl.c | 22 +++++-----
7 files changed, 134 insertions(+), 37 deletions(-)
diff --git a/include/lely/co/val.h b/include/lely/co/val.h
index 2629763d..b5cee564 100644
--- a/include/lely/co/val.h
+++ b/include/lely/co/val.h
@@ -28,7 +28,7 @@
#include <float.h>
#include <stddef.h>
-#if !LELY_NO_CO_DCF || !LELY_NO_CO_OBJ_FILE
+#if !LELY_NO_STDIO
// The read file buffer from <lely/util/frbuf.h>
struct __frbuf;
// The write file buffer from <lely/util/fwbuf.h>
diff --git a/src/can/socket.c b/src/can/socket.c
index 4fc133dd..b059c849 100644
--- a/src/can/socket.c
+++ b/src/can/socket.c
@@ -39,6 +39,11 @@
#include <linux/can/error.h>
#endif
+#ifdef __NuttX__
+#include <nuttx/can.h>
+#include <netpacket/can.h>
+#endif
+
int
can_frame_is_error(const struct can_frame *frame, enum can_state *pstate,
enum can_error *perror)
@@ -51,7 +56,7 @@ can_frame_is_error(const struct can_frame *frame, enum can_state *pstate,
enum can_state state = pstate ? *pstate : CAN_STATE_ACTIVE;
enum can_error error = perror ? *perror : 0;
-#ifdef HAVE_LINUX_CAN_ERROR_H
+#if defined(HAVE_LINUX_CAN_ERROR_H) || defined(__NuttX__)
if (frame->can_dlc != CAN_ERR_DLC) {
set_errnum(ERRNUM_INVAL);
return -1;
diff --git a/src/io/can.c b/src/io/can.c
index ca7e7d95..35d9a9f2 100644
--- a/src/io/can.c
+++ b/src/io/can.c
@@ -26,7 +26,7 @@
#if !LELY_NO_STDIO
#include <lely/util/errnum.h>
-#if !LELY_NO_CAN && defined(__linux__) && HAVE_LINUX_CAN_H
+#if !LELY_NO_CAN && ((defined(__linux__) && HAVE_LINUX_CAN_H) || defined(__NuttX__))
#include <lely/can/socket.h>
#endif
#include "handle.h"
@@ -38,7 +38,7 @@
#include <assert.h>
#include <string.h>
-#if defined(__linux__) && HAVE_LINUX_CAN_H
+#if (defined(__linux__) && HAVE_LINUX_CAN_H) || defined(__NuttX__)
#ifdef HAVE_LINUX_CAN_ERROR_H
#include <linux/can/error.h>
@@ -56,6 +56,13 @@
#include <linux/can/raw.h>
#endif
+#ifdef __NuttX__
+#include <sys/ioctl.h>
+#include <nuttx/can.h>
+#include <netpacket/can.h>
+#include <net/if.h>
+#endif
+
/// A CAN device.
struct can {
/// The I/O device base handle.
@@ -656,6 +663,88 @@ io_can_set_txqlen(io_handle_t handle, size_t txqlen)
#endif // HAVE_LINUX_CAN_NETLINK_H && HAVE_LINUX_RTNETLINK_H
+#if defined(__NuttX__)
+int
+io_can_get_ec(io_handle_t handle, uint16_t *ptxec, uint16_t *prxec)
+{
+ /* tx error count */
+
+ *ptxec = 0;
+
+ /* rx error count */
+
+ *prxec = 0;
+
+ return 0;
+}
+
+int
+io_can_get_bitrate(io_handle_t handle, uint32_t *pbitrate)
+{
+ if (!handle) {
+ errno = EBADF;
+ return -1;
+ }
+
+ if (handle->vtab != &can_vtab) {
+ errno = ENXIO;
+ return -1;
+ }
+ struct can *can = (struct can *)handle;
+ struct ifreq ifr;
+ if_indextoname(can->ifindex, ifr.ifr_name);
+
+ if (ioctl(handle->fd, SIOCGCANBITRATE, &ifr) == -1) {
+ return -1;
+ }
+
+ *pbitrate = ifr.ifr_ifru.ifru_can_data.arbi_bitrate * 1000;
+
+ return 0;
+}
+
+int
+io_can_set_bitrate(io_handle_t handle, uint32_t bitrate)
+{
+ if (!handle) {
+ errno = EBADF;
+ return -1;
+ }
+
+ if (handle->vtab != &can_vtab) {
+ errno = ENXIO;
+ return -1;
+ }
+ struct can *can = (struct can *)handle;
+ struct ifreq ifr;
+ if_indextoname(can->ifindex, ifr.ifr_name);
+
+ ifr.ifr_ifru.ifru_can_data.arbi_bitrate = bitrate / 1000;
+ ifr.ifr_ifru.ifru_can_data.data_bitrate = bitrate / 1000;
+ ifr.ifr_ifru.ifru_can_data.arbi_samplep = 0;
+ ifr.ifr_ifru.ifru_can_data.data_samplep = 0;
+
+ if (ioctl(handle->fd, SIOCSCANBITRATE, &ifr) == -1) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+io_can_get_txqlen(io_handle_t handle, size_t *ptxqlen)
+{
+ return -1;
+}
+
+int
+io_can_set_txqlen(io_handle_t handle, size_t txqlen)
+{
+ return -1;
+}
+
+#endif // __NuttX__
+
static void
can_fini(struct io_handle *handle)
{
diff --git a/src/io/poll.c b/src/io/poll.c
index d474e337..e07b36ce 100644
--- a/src/io/poll.c
+++ b/src/io/poll.c
@@ -261,7 +261,7 @@ io_poll_watch(io_poll_t *poll, io_handle_t handle, struct io_event *event,
assert(handle->vtab);
switch (handle->vtab->type) {
-#if defined(__linux__) && defined(HAVE_LINUX_CAN_H)
+#if (defined(__linux__) && defined(HAVE_LINUX_CAN_H)) || defined(__NuttX__)
case IO_TYPE_CAN:
#endif
#if _POSIX_C_SOURCE >= 200112L
diff --git a/src/util/frbuf.c b/src/util/frbuf.c
index 73a15bc8..403901a5 100644
--- a/src/util/frbuf.c
+++ b/src/util/frbuf.c
@@ -57,7 +57,7 @@ struct __frbuf {
HANDLE hFileMappingObject;
/// The base address of the file mapping.
LPVOID lpBaseAddress;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
/// The file descriptor.
int fd;
/// The base address of the current file mapping.
@@ -75,7 +75,7 @@ struct __frbuf {
void *
__frbuf_alloc(void)
{
- void *ptr = malloc(sizeof(struct __frbuf));
+ void *ptr = zalloc(sizeof(struct __frbuf));
if (!ptr)
set_errc(errno2c(errno));
return ptr;
@@ -102,7 +102,7 @@ __frbuf_init(struct __frbuf *buf, const char *filename)
buf->hFileMappingObject = INVALID_HANDLE_VALUE;
buf->lpBaseAddress = NULL;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
buf->fd = open(filename, O_RDONLY | O_CLOEXEC);
if (buf->fd == -1)
return NULL;
@@ -125,7 +125,7 @@ __frbuf_fini(struct __frbuf *buf)
#if _WIN32
CloseHandle(buf->hFile);
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
close(buf->fd);
#else
fclose(buf->stream);
@@ -176,7 +176,7 @@ frbuf_get_size(frbuf_t *buf)
if (!GetFileSizeEx(buf->hFile, &FileSize))
return -1;
return FileSize.QuadPart;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
#ifdef __linux__
struct stat64 stat;
if (fstat64(buf->fd, &stat) == -1)
@@ -221,7 +221,7 @@ frbuf_get_pos(frbuf_t *buf)
if (!SetFilePointerEx(buf->hFile, li, &li, FILE_CURRENT))
return -1;
return li.QuadPart;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
#ifdef __linux__
return lseek64(buf->fd, 0, SEEK_CUR);
#else
@@ -250,7 +250,7 @@ frbuf_set_pos(frbuf_t *buf, intmax_t pos)
if (!SetFilePointerEx(buf->hFile, li, &li, FILE_BEGIN))
return -1;
return li.QuadPart;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
#ifdef __linux__
return lseek64(buf->fd, pos, SEEK_SET);
#else
@@ -283,7 +283,7 @@ frbuf_read(frbuf_t *buf, void *ptr, size_t size)
if (!ReadFile(buf->hFile, ptr, size, &nNumberOfBytesRead, NULL))
return -1;
return nNumberOfBytesRead;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
ssize_t result;
do
result = read(buf->fd, ptr, size);
@@ -347,7 +347,7 @@ error_ReadFile:
error_get_pos:
SetLastError(dwErrCode);
return result;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
ssize_t result;
#ifdef __linux__
do
diff --git a/src/util/fwbuf.c b/src/util/fwbuf.c
index 22c61fd7..26b7e03b 100644
--- a/src/util/fwbuf.c
+++ b/src/util/fwbuf.c
@@ -72,7 +72,7 @@ struct __fwbuf {
LPVOID lpBaseAddress;
/// The number of bytes mapped at <b>lpBaseAddress</b>.
SIZE_T dwNumberOfBytesToMap;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
/// A pointer to the name of the temporary file.
char *tmpname;
/// The file descriptor of the directory containing the temporary file.
@@ -175,7 +175,7 @@ error_GetTempFileNameA:
error_strdup:
SetLastError(dwErrCode);
return NULL;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
int errsv = 0;
buf->filename = strdup(filename);
@@ -295,7 +295,7 @@ __fwbuf_fini(struct __fwbuf *buf)
fwbuf_commit(buf);
set_errc(errc);
-#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#if _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
free(buf->tmpname);
#endif
free(buf->filename);
@@ -348,7 +348,7 @@ fwbuf_get_size(fwbuf_t *buf)
return -1;
}
return FileSize.QuadPart;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
#ifdef __linux__
struct stat64 stat;
if (fstat64(buf->fd, &stat) == -1) {
@@ -388,7 +388,7 @@ fwbuf_set_size(fwbuf_t *buf, intmax_t size)
return -1;
return 0;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
#ifdef __linux__
if (ftruncate64(buf->fd, size) == -1) {
#else
@@ -424,7 +424,7 @@ fwbuf_get_pos(fwbuf_t *buf)
return -1;
}
return li.QuadPart;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
#ifdef __linux__
intmax_t pos = lseek64(buf->fd, 0, SEEK_CUR);
#else
@@ -456,7 +456,8 @@ fwbuf_set_pos(fwbuf_t *buf, intmax_t pos)
return -1;
}
return li.QuadPart;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+/* #elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) */
+#elif !defined(__NuttX__)
#ifdef __linux__
pos = lseek64(buf->fd, pos, SEEK_SET);
#else
@@ -503,7 +504,7 @@ fwbuf_write(fwbuf_t *buf, const void *ptr, size_t size)
return -1;
}
return nNumberOfBytesWritten;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
ssize_t result;
do
result = write(buf->fd, ptr, size);
@@ -587,7 +588,7 @@ error_get_pos:
error_pos:
SetLastError(buf->dwErrCode);
return result;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
ssize_t result;
#ifdef __linux__
do
@@ -931,7 +932,7 @@ fwbuf_clearerr(fwbuf_t *buf)
#if _WIN32
buf->dwErrCode = 0;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
buf->errsv = 0;
#else
buf->errnum = 0;
@@ -947,7 +948,7 @@ fwbuf_error(fwbuf_t *buf)
if (buf->dwErrCode)
SetLastError(buf->dwErrCode);
return !!buf->dwErrCode;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
if (buf->errsv)
errno = buf->errsv;
return !!buf->errsv;
@@ -966,7 +967,7 @@ fwbuf_cancel(fwbuf_t *buf)
#if _WIN32
if (!buf->dwErrCode)
buf->dwErrCode = ERROR_OPERATION_ABORTED;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
if (!buf->errsv)
buf->errsv = ECANCELED;
#else
@@ -1013,7 +1014,7 @@ fwbuf_commit(fwbuf_t *buf)
done:
SetLastError(buf->dwErrCode = dwErrCode);
return result;
-#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__)
+#elif _POSIX_C_SOURCE >= 200112L && !defined(__NEWLIB__) && !defined(__NuttX__)
int errsv = errno;
if (buf->fd == -1)
diff --git a/tools/coctl.c b/tools/coctl.c
index 351b81c0..5f851b50 100644
--- a/tools/coctl.c
+++ b/tools/coctl.c
@@ -39,6 +39,9 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
+#include <inttypes.h>
+
+#include <system/readline.h>
#if _WIN32
#include <io.h>
@@ -90,7 +93,7 @@ int io_thrd_start(void *arg);
void co_net_err(struct co_net *net);
struct co_net net[CO_GW_NUM_NET];
-io_poll_t *poll;
+static io_poll_t *poll;
int flags;
int inhibit = INHIBIT;
@@ -315,8 +318,8 @@ main(int argc, char *argv[])
errno = errsv;
int eof = 0;
- char *line = NULL;
- size_t n = 0;
+#define LINE_SIZE 100
+ char line[LINE_SIZE];
co_unsigned32_t seq = 1;
char *cmd = NULL;
while (!done) {
@@ -358,11 +361,11 @@ main(int argc, char *argv[])
if (cmd)
printf("... ");
else
- printf("[%u] ", seq);
+ printf("[%" PRIu32 "] ", seq);
fflush(stdout);
}
// Keep reading lines until end-of-file.
- if (getline(&line, &n, stdin) == -1) {
+ if (readline(line, LINE_SIZE-1, stdin, stdout) == -1) {
if (tty)
fputc('\n', stdout);
if (ferror(stdin)) {
@@ -409,7 +412,7 @@ main(int argc, char *argv[])
free(cmd);
cmd = tmp;
} else {
- if (asprintf(&cmd, "[%u] %s", seq, line)
+ if (asprintf(&cmd, "[%" PRIu32 "] %s", seq, line)
== -1) {
cmd = NULL;
break;
@@ -431,7 +434,7 @@ main(int argc, char *argv[])
result = asprintf(&tmp, "%s%s%s",
recv_buf, cmd, line);
else
- result = asprintf(&tmp, "%s[%u] %s",
+ result = asprintf(&tmp, "%s[%" PRIu32 "] %s",
recv_buf, seq, line);
if (result < 0) {
mtx_unlock(&recv_mtx);
@@ -444,7 +447,7 @@ main(int argc, char *argv[])
result = asprintf(&recv_buf, "%s%s",
cmd, line);
else
- result = asprintf(&recv_buf, "[%u] %s",
+ result = asprintf(&recv_buf, "[%" PRIu32 "] %s",
seq, line);
if (result < 0) {
recv_buf = NULL;
@@ -466,7 +469,6 @@ main(int argc, char *argv[])
}
}
free(cmd);
- free(line);
io_poll_signal(poll, 1);
thrd_join(thr, NULL);
@@ -561,7 +563,7 @@ gw_rate(co_unsigned16_t id, co_unsigned16_t rate, void *data)
return;
bitrate = rate * 1000;
if (io_can_set_bitrate(net[id - 1].handle, bitrate) == -1)
- diag(DIAG_ERROR, 0, "unable to set bitrate of %s to %u bit/s",
+ diag(DIAG_ERROR, 0, "unable to set bitrate of %s to %" PRIu32 " bit/s",
net[id - 1].can_path, bitrate);
}
--
2.37.2

View File

@ -0,0 +1,170 @@
menuconfig CANUTILS_LELYCANOPEN
bool "Lely CANopen support"
default n
---help---
Enable the Lely CANopen build
if CANUTILS_LELYCANOPEN
config CANUTILS_LELYCANOPEN_URL
string "URL where Lely CANopen can be downloaded"
default "https://gitlab.com/lely_industries/lely-core/-/archive/master/"
config CANUTILS_LELYCANOPEN_VERSION
string "Version number"
default "a2ecf70b76a42c25c5338d86e85250bf16fd7023"
menu "Lely CANopen configuration"
config CANUTILS_LELYCANOPEN_CANFD
bool "Lely CANopen enable CAN FD support"
default n
config CANUTILS_LELYCANOPEN_DIAG
bool "Lely CANopen enable diagnostic functions"
default n
config CANUTILS_LELYCANOPEN_DCF
bool "Lely CANopen enable EDS/DCF support"
default n
config CANUTILS_LELYCANOPEN_OBJDEFAULT
bool "Lely CANopen enable default values in the object dictionary"
default n
config CANUTILS_LELYCANOPEN_OBJFILE
bool "Lely CANopen enable file support in the object dictionary"
default n
config CANUTILS_LELYCANOPEN_OBJLIMITS
bool "Lely CANopen enable limit values in the object dictionary"
default n
config CANUTILS_LELYCANOPEN_OBJNAME
bool "Lely CANopen enable names in the object dictionary"
default n
config CANUTILS_LELYCANOPEN_OBJUPLOAD
bool "Lely CANopen enable upload indication functions in the object dictionary"
default n
config CANUTILS_LELYCANOPEN_SDEV
bool "Lely CANopen enable static device description support"
default n
config CANUTILS_LELYCANOPEN_CSDO
bool "Lely CANopen enable Client-SDO support"
default n
config CANUTILS_LELYCANOPEN_RPDO
bool "Lely CANopen enable Receive-PDO support"
default n
config CANUTILS_LELYCANOPEN_TPDO
bool "Lely CANopen enable Transmit-PDO support"
default n
config CANUTILS_LELYCANOPEN_MPDO
bool "Lely CANopen enable Multiplex PDO support"
default n
config CANUTILS_LELYCANOPEN_SYNC
bool "Lely CANopen enable SYNC support"
default n
config CANUTILS_LELYCANOPEN_TIME
bool "Lely CANopen enable TIME support"
default n
config CANUTILS_LELYCANOPEN_EMCY
bool "Lely CANopen enable EMCY support"
default n
config CANUTILS_LELYCANOPEN_LSS
bool "Lely CANopen enable LSS support"
default n
config CANUTILS_LELYCANOPEN_WTM
bool "Lely CANopen enable WTM support"
default n
config CANUTILS_LELYCANOPEN_MASTER
bool "Lely CANopen enable MASTER support"
default n
config CANUTILS_LELYCANOPEN_NG
bool "Lely CANopen enable node guardian support"
default n
config CANUTILS_LELYCANOPEN_NMTBOOT
bool "Lely CANopen enable NMT boot slave support"
default n
config CANUTILS_LELYCANOPEN_NMTCFG
bool "Lely CANopen enable NMT configuration request support"
default n
config CANUTILS_LELYCANOPEN_GW
bool "Lely CANopen enable gateway support"
default n
config CANUTILS_LELYCANOPEN_GW_TXT
bool "Lely CANopen enable ASCII gateway support"
default n
if HAVE_CXX
config CANUTILS_LELYCANOPEN_COAPP_MASTER
bool "Lely CANopen C++ CANopen application master support"
default n
config CANUTILS_LELYCANOPEN_COAPP_SLAVE
bool "Lely CANopen C++ CANopen application slave support"
default n
endif # HAVE_CXX
config CANUTILS_LELYCANOPEN_IOLIB
bool "Lely CANopen IO lib"
default n
depends on NET_CAN
select NETDEV_IFINDEX
select NET_CAN_SOCK_OPTS
select PIPES
endmenu # "Lely CANopen configuration"
menu "Lely CANopen tools"
config CANUTILS_LELYCANOPEN_TOOLS_COCTL
bool "coctl"
depends on SERIAL_TERMIOS
depends on SYSTEM_READLINE
default n
select CANUTILS_LELYCANOPEN_IOLIB
select CANUTILS_LELYCANOPEN_DIAG
select CANUTILS_LELYCANOPEN_GW
select CANUTILS_LELYCANOPEN_DCF
select CANUTILS_LELYCANOPEN_OBJNAME
select CANUTILS_LELYCANOPEN_GW_TXT
select CANUTILS_LELYCANOPEN_EMCY
select CANUTILS_LELYCANOPEN_RPDO
select CANUTILS_LELYCANOPEN_TPDO
select CANUTILS_LELYCANOPEN_SYNC
select CANUTILS_LELYCANOPEN_CSDO
if CANUTILS_LELYCANOPEN_TOOLS_COCTL
config CANUTILS_LELYCANOPEN_TOOLS_COCTL_PRIORITY
int "coctl task priority"
default 100
config CANUTILS_LELYCANOPEN_TOOLS_COCTL_STACKSIZE
int "coctl stack size"
default DEFAULT_TASK_STACKSIZE
endif #CANUTILS_LELYCANOPEN_TOOLS_COCTL
endmenu # "Lely CANopen tools"
endif # CANUTILS_LELYCANOPEN

View File

@ -0,0 +1,28 @@
############################################################################
# apps/canutils/lelycanopen/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifneq ($(CONFIG_CANUTILS_LELYCANOPEN),)
CONFIGURED_APPS += $(APPDIR)/canutils/lely-canopen
# It allows `<lely/xxx.h>` import.
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/canutils/lely-canopen/lely-core/include}
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/canutils/lely-canopen/lely-core/include}
endif

View File

@ -0,0 +1,192 @@
############################################################################
# apps/canutils/lely-canopen/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################
# Standard includes
include $(APPDIR)/Make.defs
# Set up build configuration and environment
WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'}
LELYCANOPEN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_CANUTILS_LELYCANOPEN_VERSION)))
LELYCANOPEN_TARBALL = lely-core-$(LELYCANOPEN_VERSION).tar.gz
LELYCANOPEN_UNPACKNAME = lely-core-master-$(LELYCANOPEN_VERSION)
LELYCANOPEN_SRCNAME = lely-core
UNPACK ?= tar -zxf
LELYCANOPEN_SRCDIR = $(WD)/$(LELYCANOPEN_SRCNAME)
# CAN network object
CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/buf.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/msg.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/vci.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/net.c
# CANopen library
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/crc.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/dev.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_hb.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_srv.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/obj.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/pdo.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/sdo.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/ssdo.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/type.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/val.c
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_TIME),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/time.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_CSDO),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/csdo.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_DCF),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/dcf.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_EMCY),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/emcy.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_GW),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/gw.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_GW_TXT),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/gw_txt.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_LSS),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/lss.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_NMTBOOT),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_boot.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_NMTCFG),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/nmt_cfg.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_RPDO),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/rpdo.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_SDEV),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/sdev.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_SYNC),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/sync.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_TPDO),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/tpdo.c
endif
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_WTM),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/co/wtm.c
endif
# utils
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_DIAG),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/diag.c
endif
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/bits.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/bitset.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/cmp.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/config.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/config_ini.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/dllist.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/endian.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/errnum.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/frbuf.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/fwbuf.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/lex.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/membuf.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/pheap.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/print.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/rbtree.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/stop.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/time.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/util/ustring.c
# Lely IO lib
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_IOLIB),y)
CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/handle.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/io.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/pipe.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/poll.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/io2/posix/poll.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/io2/ctx.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/io/can.c
CSRCS += $(LELYCANOPEN_SRCDIR)/src/can/socket.c
endif
# enable config.h
CFLAGS += ${shell $(INCDIR) "$(CC)" $(APPDIR)/include/canutils/lely}
CFLAGS += -DHAVE_CONFIG_H=1
CFLAGS += -Wno-shadow -Wno-undef
MODULE = $(CONFIG_CANUTILS_LELYCANOPEN)
# Lely CANopen tools
ifeq ($(CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL),y)
PROGNAME = coctl
PRIORITY = $(CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL_PRIORITY)
STACKSIZE = $(CONFIG_CANUTILS_LELYCANOPEN_TOOLS_COCTL_STACKSIZE)
MAINSRC = $(LELYCANOPEN_SRCDIR)/tools/coctl.c
endif
# Download and unpack tarball if no git repo found
ifeq ($(wildcard $(LELYCANOPEN_SRCNAME)/.git),)
$(LELYCANOPEN_TARBALL):
@echo "Downloading: $(LELYCANOPEN_TARBALL)"
$(Q) curl -L -O $(CONFIG_CANUTILS_LELYCANOPEN_URL)/$(LELYCANOPEN_TARBALL)
$(LELYCANOPEN_SRCNAME): $(LELYCANOPEN_TARBALL)
@echo "Unpacking: $(LELYCANOPEN_TARBALL) -> $(LELYCANOPEN_UNPACKNAME)"
$(Q) $(UNPACK) $(LELYCANOPEN_TARBALL)
$(Q) mv $(LELYCANOPEN_UNPACKNAME) $(LELYCANOPEN_SRCNAME)
$(Q) cat 0001-NuttX-port.patch | patch -s -N -d $(LELYCANOPEN_SRCNAME) -p1
$(Q) echo "Patching $(LELYCANOPEN_SRCNAME)"
endif
context:: $(LELYCANOPEN_SRCNAME)
distclean::
ifeq ($(wildcard $(LELYCANOPEN_SRCNAME)/.git),)
$(call DELDIR, $(LELYCANOPEN_SRCNAME))
$(call DELFILE, $(LELYCANOPEN_TARBALL))
endif
include $(APPDIR)/Application.mk

View File

@ -0,0 +1,278 @@
/****************************************************************************
* apps/canutils/lely/config.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __CANUTILS_LELY_CONFIG_H
#define __CANUTILS_LELY_CONFIG_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* General NuttX port configuration */
#define _WIN32 0
#define _WIN64 0
#define LELY_NO_ERRNO 0
#define LELY_NO_MALLOC 0
#define LELY_NO_THREADS 0
#define LELY_NO_STDIO 0
#define LELY_NO_ATOMICS 0
#define HAVE_SYS_IOCTL_H 1
#define LELY_HAVE_ITIMERSPEC 1
#define LELY_HAVE_SYS_TYPES_H 1
#define LELY_HAVE_STRINGS_H 1
#define LELY_HAVE_UCHAR_H 0
#define _POSIX_C_SOURCE 200112L
/* --disable-daemon */
#define LELY_NO_DAEMON 1
/* --disable-cxx */
#ifdef CONFIG_HAVE_CXX
# define LELY_NO_CXX 0
#else
# define LELY_NO_CXX 1
#endif
/* SocketCAN support */
#ifdef CONFIG_NET_CAN
# define LELY_HAVE_SOCKET_CAN 1
#else
# define LELY_HAVE_SOCKET_CAN 0
#endif
/* --disable-canfd */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_CANFD
# define LELY_NO_CANFD 1
#else
# define LELY_NO_CANFD 0
#endif
/* --disable-diag */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_DIAG
# define LELY_NO_DIAG 0
#else
# define LELY_NO_DIAG 1
#endif
/* --disable-dcf */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_DCF
# define LELY_NO_CO_DCF 0
#else
# define LELY_NO_CO_DCF 1
#endif
/* --disable-obj-default */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJDEFAULT
# define LELY_NO_CO_OBJ_DEFAULT 0
#else
# define LELY_NO_CO_OBJ_DEFAULT 1
#endif
/* --disable-obj-file */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJFILE
# define LELY_NO_CO_OBJ_FILE 0
#else
# define LELY_NO_CO_OBJ_FILE 1
#endif
/* --disable-obj-limits */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJLIMITS
# define LELY_NO_CO_OBJ_LIMITS 0
#else
# define LELY_NO_CO_OBJ_LIMITS 1
#endif
/* --disable-obj-name */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJNAME
# define LELY_NO_CO_OBJ_NAME 0
#else
# define LELY_NO_CO_OBJ_NAME 1
#endif
/* --disable-obj-upload */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_OBJUPLOAD
# define LELY_NO_CO_OBJ_UPLOAD 0
#else
# define LELY_NO_CO_OBJ_UPLOAD 1
#endif
/* --disable-sdev */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_SDEV
# define LELY_NO_CO_SDEV 0
#else
# define LELY_NO_CO_SDEV 1
#endif
/* --disable-csdo */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_CSDO
# define LELY_NO_CO_CSDO 0
#else
# define LELY_NO_CO_CSDO 1
#endif
/* --disable-rpdo */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_RPDO
# define LELY_NO_CO_RPDO 0
#else
# define LELY_NO_CO_RPDO 1
#endif
/* --disable-tpdo */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_TPDO
# define LELY_NO_CO_TPDO 0
#else
# define LELY_NO_CO_TPDO 1
#endif
/* --disable-mpdo */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_MPDO
# define LELY_NO_CO_MPDO 0
#else
# define LELY_NO_CO_MPDO 1
#endif
/* --disable-sync */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_SYNC
# define LELY_NO_CO_SYNC 0
#else
# define LELY_NO_CO_SYNC 1
#endif
/* --disable-time */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_TIME
# define LELY_NO_CO_TIME 0
#else
# define LELY_NO_CO_TIME 1
#endif
/* --disable-emcy */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_EMCY
# define LELY_NO_CO_EMCY 0
#else
# define LELY_NO_CO_EMCY 1
#endif
/* --disable-lss */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_LSS
# define LELY_NO_CO_LSS 0
#else
# define LELY_NO_CO_LSS 1
#endif
/* --disable-wtm */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_WTM
# define LELY_NO_CO_WTM 0
#else
# define LELY_NO_CO_WTM 1
#endif
/* --disable-master */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_MASTER
# define LELY_NO_CO_MASTER 0
#else
# define LELY_NO_CO_MASTER 1
#endif
/* --disable-ng */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_NG
# define LELY_NO_CO_NG 0
#else
# define LELY_NO_CO_NG 1
#endif
/* --disable-nmt-boot */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_NMTBOOT
# define LELY_NO_CO_NMT_BOOT 0
#else
# define LELY_NO_CO_NMT_BOOT 1
#endif
/* --disable-nmt-cfg */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_NMTCFG
# define LELY_NO_CO_NMT_CFG 0
#else
# define LELY_NO_CO_NMT_CFG 1
#endif
/* --disable-gw */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_GW
# define LELY_NO_CO_GW 0
#else
# define LELY_NO_CO_GW 1
#endif
/* --disable-gw-txt */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_GW_TXT
# define LELY_NO_CO_GW_TXT 0
#else
# define LELY_NO_CO_GW_TXT 1
#endif
/* --disable-coapp-master */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_COAPP_MASTER
# define LELY_NO_CO_COAPP_MASTER 0
#else
# define LELY_NO_CO_COAPP_MASTER 1
#endif
/* --disable-coapp-slave */
#ifdef CONFIG_CANUTILS_LELYCANOPEN_COAPP_SLAVE
# define LELY_NO_CO_COAPP_SLAVE 0
#else
# define LELY_NO_CO_COAPP_SLAVE 1
#endif
#endif /* __CANUTILS_LELY_CONFIG_H */