[PATCH v4] cpukit/dev/can: Added CAN support
--- cpukit/dev/can/can.c | 521 +++ cpukit/include/dev/can/can-msg.h | 105 + cpukit/include/dev/can/can-queue.h | 219 ++ cpukit/include/dev/can/can.h | 258 +++ spec/build/cpukit/librtemscpu.yml| 6 + spec/build/testsuites/libtests/can01.yml | 19 + spec/build/testsuites/libtests/grp.yml | 2 + testsuites/libtests/can01/init.c | 257 +++ 8 files changed, 1387 insertions(+) create mode 100644 cpukit/dev/can/can.c create mode 100644 cpukit/include/dev/can/can-msg.h create mode 100644 cpukit/include/dev/can/can-queue.h create mode 100644 cpukit/include/dev/can/can.h create mode 100644 spec/build/testsuites/libtests/can01.yml create mode 100644 testsuites/libtests/can01/init.c diff --git a/cpukit/dev/can/can.c b/cpukit/dev/can/can.c new file mode 100644 index 00..02377a9098 --- /dev/null +++ b/cpukit/dev/can/can.c @@ -0,0 +1,521 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup CANBus + * + * @brief Controller Area Network (CAN) Bus Implementation + * + */ + +/* + * Copyright (C) 2022 Prashanth S (fishesprasha...@gmail.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include +#include + +#include +#include + +#include + +#define can_interrupt_lock_acquire(bus) \ + do { \ + CAN_DEBUG_LOCK("acquiring lock %s:%d\n", __FILE__, __LINE__); \ + real_can_interrupt_lock_acquire(bus); \ + } while (0); + +#define can_interrupt_lock_release(bus) \ + do { \ + CAN_DEBUG_LOCK("releasing lock %s:%d\n", __FILE__, __LINE__); \ + real_can_interrupt_lock_release(bus); \ + } while (0); + +static ssize_t +can_bus_open(rtems_libio_t *iop, const char *path, int oflag, mode_t mode); +static ssize_t +can_bus_read(rtems_libio_t *iop, void *buffer, size_t count); +static ssize_t +can_bus_write(rtems_libio_t *iop, const void *buffer, size_t count); +static ssize_t +can_bus_ioctl(rtems_libio_t *iop, ioctl_command_t request, void *buffer); + +static int can_xmit(struct can_bus *bus); + +static int can_create_sem(struct can_bus *); +static int try_sem(struct can_bus *); +static int take_sem(struct can_bus *); +static int give_sem(struct can_bus *); + +/* sem_count this is for debug purpose, for debugging +the take_sem and give_sem +*/ +static int sem_count = 0; + +static void can_bus_obtain(can_bus *bus) +{ + printf("can_bus_obtain Entry\n"); + rtems_mutex_lock(&bus->mutex); + printf("can_bus_obtain Exit\n"); +} + +static void can_bus_release(can_bus *bus) +{ + printf("can_bus_release Entry\n"); + rtems_mutex_unlock(&bus->mutex); + printf("can_bus_release Exit\n"); +} + +static void can_bus_destroy_mutex(struct can_bus *bus) +{ + rtems_mutex_destroy(&bus->mutex); +} + +static int can_create_sem(struct can_bus *bus) +{ + int ret = 0; + + ret = rtems_semaphore_create(rtems_build_name('c', 'a', 'n', bus->index), + CAN_TX_BUF_COUNT, RTEMS_FIFO | RTEMS_COUNTING_SEMAPHORE | RTEMS_LOCAL, + 0, &bus->tx_fifo_sem_id); + + if (ret != 0) { +printf("can_create_sem: rtems_semaphore_create failed %d\n", ret); + } + + return ret; +} + +static void can_free_tx_semaphore(struct can_bus *bus) +{ + rtems_semaphore_delete(bus->tx_fifo_sem_id); +} + +static void real_can_interrupt_lock_acquire(struct can_bus *bus) +{ + bus->can_dev_ops->dev_int(bus->priv, false); + can_bus_obtain(bus); +} + +static void
Re: devel Digest, Vol 129, Issue 37
Hi All, This is a review request for DCAN (Work in Progress) support. As the patch size exceeds the mail limit, I am attaching the patch in compressed format. Regards Prashanth S Prashanth S On Sun, 14 Aug 2022 at 13:56, wrote: > > Send devel mailing list submissions to > devel@rtems.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://lists.rtems.org/mailman/listinfo/devel > or, via email, send a message with subject or body 'help' to > devel-requ...@rtems.org > > You can reach the person managing the list at > devel-ow...@rtems.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of devel digest..." > > > Today's Topics: > >1. [PATCH v4] cpukit/dev/can: Added CAN support (Prashanth S) > > > -- > > Message: 1 > Date: Sun, 14 Aug 2022 13:56:16 +0530 > From: Prashanth S > To: devel@rtems.org > Cc: Prashanth S > Subject: [PATCH v4] cpukit/dev/can: Added CAN support > Message-ID: <20220814082616.7345-1-fishesprasha...@gmail.com> > > --- > cpukit/dev/can/can.c | 521 +++ > cpukit/include/dev/can/can-msg.h | 105 + > cpukit/include/dev/can/can-queue.h | 219 ++ > cpukit/include/dev/can/can.h | 258 +++ > spec/build/cpukit/librtemscpu.yml| 6 + > spec/build/testsuites/libtests/can01.yml | 19 + > spec/build/testsuites/libtests/grp.yml | 2 + > testsuites/libtests/can01/init.c | 257 +++ > 8 files changed, 1387 insertions(+) > create mode 100644 cpukit/dev/can/can.c > create mode 100644 cpukit/include/dev/can/can-msg.h > create mode 100644 cpukit/include/dev/can/can-queue.h > create mode 100644 cpukit/include/dev/can/can.h > create mode 100644 spec/build/testsuites/libtests/can01.yml > create mode 100644 testsuites/libtests/can01/init.c > > diff --git a/cpukit/dev/can/can.c b/cpukit/dev/can/can.c > new file mode 100644 > index 00..02377a9098 > --- /dev/null > +++ b/cpukit/dev/can/can.c > @@ -0,0 +1,521 @@ > +/* SPDX-License-Identifier: BSD-2-Clause */ > + > +/** > + * @file > + * > + * @ingroup CANBus > + * > + * @brief Controller Area Network (CAN) Bus Implementation > + * > + */ > + > +/* > + * Copyright (C) 2022 Prashanth S (fishesprasha...@gmail.com) > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS > IS" > + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE > + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR > + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF > + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS > + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN > + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) > + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE > + * POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +#include > +#include > + > +#include > +#include > + > +#include > + > +#define can_interrupt_lock_acquire(bus) \ > + do { \ > + CAN_DEBUG_LOCK("acquiring lock %s:%d\n", > __FILE__, __LINE__); \ > + real_can_interrupt_lock_acquire(bus); > \ > + } while (0); > + > +#define can_interrupt_lock_release(bus) \ > + do { \ > + CAN_DEBUG_LOCK("releasing lock %s:%d\n", > __FILE__, __LINE__); \ > + real_can_interrupt_lock_release(bus); > \ > + } while (0); > + > +static ssize_t > +can_bus_open(rtems_libio_t *iop, const char *path, int oflag, mode_t mode); > +static ssize_t > +can_bus_read(rtems_libio_t *iop, void *buffer, size_t count); > +static ssize_t > +can_bus_write(rtems_libio_t *iop, const void *buffer, size_t count); > +static ssize_t > +can_bus_ioctl(rtems_libio_t *iop, ioctl_command_t request, void *buffer); > + > +static int can_xmit(struct can_bus *bus); > + > +static int can_create_sem(struct can_