]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
embedded: provide generic support functions for sysless variant.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Mon, 13 Feb 2012 17:02:45 +0000 (18:02 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Mon, 13 Feb 2012 17:02:45 +0000 (18:02 +0100)
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
embedded/app/usbcan/Makefile.omk
embedded/app/usbcan/sysdep_sysless.c [new file with mode: 0644]

index 3077876153c5dca0831ad29965e347429726546b..723e15730f386322f2aa623cfdf5d50d23d37142 100644 (file)
@@ -19,7 +19,9 @@ INCLUDES += -I.
 #include_HEADERS  = ul_idstr.h
 
 bin_PROGRAMS = usbcan
 #include_HEADERS  = ul_idstr.h
 
 bin_PROGRAMS = usbcan
-usbcan_SOURCES = main.c can_queue.c sja1000p.c  devcommon.c setup.c finish.c usb_vend.c can_quesysless.c lpc17xx_can.c
+usbcan_SOURCES = main.c can_queue.c sja1000p.c  devcommon.c setup.c finish.c
+usbcan_SOURCES += usb_vend.c can_quesysless.c sysdep_sysless.c
+usbcan_SOURCES += lpc17xx_can.c
 #usbcan_SOURCES += can_lpcbusemu.c ul_usb1.c
 
 #usbtest_SOURCES +=  ul_idstr.c
 #usbcan_SOURCES += can_lpcbusemu.c ul_usb1.c
 
 #usbtest_SOURCES +=  ul_idstr.c
diff --git a/embedded/app/usbcan/sysdep_sysless.c b/embedded/app/usbcan/sysdep_sysless.c
new file mode 100644 (file)
index 0000000..40ad822
--- /dev/null
@@ -0,0 +1,164 @@
+/**************************************************************************/
+/* File: sysdep_sysless.c - System-less support routines                  */
+/*                                                                        */
+/* LinCAN - (Not only) Linux CAN bus driver                               */
+/* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz>   */
+/* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz>             */
+/* Funded by OCERA and FRESCOR IST projects                               */
+/* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl>      */
+/*                                                                        */
+/* LinCAN is free software; you can redistribute it and/or modify it      */
+/* under terms of the GNU General Public License as published by the      */
+/* Free Software Foundation; either version 2, or (at your option) any    */
+/* later version.  LinCAN is distributed in the hope that it will be      */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
+/* General Public License for more details. You should have received a    */
+/* copy of the GNU General Public License along with LinCAN; see file     */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
+/* Cambridge, MA 02139, USA.                                              */
+/*                                                                        */
+/* To allow use of LinCAN in the compact embedded systems firmware        */
+/* and RT-executives (RTEMS for example), main authors agree with next    */
+/* special exception:                                                     */
+/*                                                                        */
+/* Including LinCAN header files in a file, instantiating LinCAN generics */
+/* or templates, or linking other files with LinCAN objects to produce    */
+/* an application image/executable, does not by itself cause the          */
+/* resulting application image/executable to be covered by                */
+/* the GNU General Public License.                                        */
+/* This exception does not however invalidate any other reasons           */
+/* why the executable file might be covered by the GNU Public License.    */
+/* Publication of enhanced or derived LinCAN files is required although.  */
+/**************************************************************************/
+
+#include <cpu_def.h>
+#include <system_def.h>
+#include "./can/can.h"
+#include "./can/can_sysdep.h"
+#include "./can/main.h"
+#include "./can/devcommon.h"
+#include "./can/setup.h"
+#include "./can/finish.h"
+
+#ifndef IRQF_SHARED
+#define IRQF_SHARED 0
+#endif  /*IRQF_SHARED*/
+
+IRQ_HANDLER_FNC(can_default_irq_dispatch);
+
+/**
+ * can_request_io_region - request IO space region
+ * @start: the first IO port address
+ * @n: number of the consecutive IO port addresses
+ * @name: name/label for the requested region
+ *
+ * The function hides system specific implementation of the feature.
+ *
+ * Return Value: returns positive value (1) in the case, that region could
+ *     be reserved for the driver. Returns zero (0) if there is collision with
+ *     other driver or region cannot be taken for some other reason.
+ */
+int can_request_io_region(unsigned long start, unsigned long n, const char *name)
+{
+       return 1;
+}
+
+/**
+ * can_release_io_region - release IO space region
+ * @start: the first IO port address
+ * @n: number of the consecutive IO port addresses
+ */
+void can_release_io_region(unsigned long start, unsigned long n)
+{
+}
+
+/**
+ * can_request_mem_region - request memory space region
+ * @start: the first memory port physical address
+ * @n: number of the consecutive memory port addresses
+ * @name: name/label for the requested region
+ *
+ * The function hides system specific implementation of the feature.
+ *
+ * Return Value: returns positive value (1) in the case, that region could
+ *     be reserved for the driver. Returns zero (0) if there is collision with
+ *     other driver or region cannot be taken for some other reason.
+ */
+int can_request_mem_region(unsigned long start, unsigned long n, const char *name)
+{
+       return 1;
+}
+
+/**
+ * can_release_mem_region - release memory space region
+ * @start: the first memory port physical address
+ * @n: number of the consecutive memory port addresses
+ */
+void can_release_mem_region(unsigned long start, unsigned long n)
+{
+       return;
+}
+
+
+/**
+ * can_default_irq_dispatch - the first level interrupt dispatch handler
+ * @irq: interrupt vector number, this value is system specific
+ * @dev_id: driver private pointer registered at time of request_irq() call.
+ *     The CAN driver uses this pointer to store relationship of interrupt
+ *     to chip state structure - @struct canchip_t
+ * @regs: system dependent value pointing to registers stored in exception frame
+ *
+ * File: src/setup.c
+ */
+IRQ_HANDLER_FNC(can_default_irq_dispatch)
+{
+       int retval;
+       struct canchip_t *chip;
+
+       chip = (struct canchip_t*)irq_handler_get_context();
+
+       retval=chip->chipspecops->irq_handler(0, chip);
+       return CAN_IRQ_RETVAL(retval);
+}
+
+/**
+ * can_chip_setup_irq - attaches chip to the system interrupt processing
+ * @chip: pointer to CAN chip structure
+ *
+ * Return Value: returns negative number in the case of fail
+ */
+int can_chip_setup_irq(struct canchip_t *chip)
+{
+       if(chip==NULL)
+               return -1;
+       if(!chip->chipspecops->irq_handler)
+               return 0;
+       if(chip->flags & CHIP_IRQ_CUSTOM)
+               return 1;
+
+       if (request_irq(chip->chip_irq,can_default_irq_dispatch,IRQF_SHARED,DEVICE_NAME,chip))
+               return -1;
+       else {
+               DEBUGMSG("Registered interrupt %d\n",chip->chip_irq);
+               chip->flags |= CHIP_IRQ_SETUP;
+       }
+       return 1;
+}
+
+
+/**
+ * can_chip_free_irq - unregisters chip interrupt handler from the system
+ * @chip: pointer to CAN chip structure
+ */
+void can_chip_free_irq(struct canchip_t *chip)
+{
+       if((chip->flags & CHIP_IRQ_SETUP) && (chip->chip_irq>=0)) {
+               if(chip->flags & CHIP_IRQ_CUSTOM)
+                       return;
+
+               free_irq(chip->chip_irq, chip);
+               chip->flags &= ~CHIP_IRQ_SETUP;
+       }
+}
+