]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - embedded/app/usbcan/main.c
embedded ul_usb1: provide support for external bittiming parameters calculation.
[lincan.git] / embedded / app / usbcan / main.c
index ad7fe36db6caf5891c3f317f9a9c9d195e7097fa..873f4c6d8d2365cf1b18e452dfc6dec40ee534ba 100644 (file)
 
 //#include "./can/ul_usb1.h"
 
-//#include "./can/setup.h"
+#include "./can/setup.h"
 
 #include "./usb/usb_defs.h"
 #include "./usb/usb_vend.h"
 
-// DEBUG CAN
-#include "can/lpc17xx_can.h"
-// DEBUG CAN - end
+extern int can_lmc1_register(struct hwspecops_t *hwspecops);
+extern int ul_usb1_register(struct hwspecops_t *hwspecops);
 
 #define MASK_EP1RX  0x01
 #define MASK_EP1TX  0x02
@@ -109,7 +108,6 @@ typedef void (*FNC)(); //function ptr
 /***********************************************************************
  * global variables
  ***********************************************************************/
-volatile uint32_t cnt;
 
 usb_device_t usb_device;
 
@@ -158,19 +156,6 @@ int sys_err(){
   }
 }
 
-/***********************************************************************
- * Microsecond delay routine
- ***********************************************************************/
-/*
-void udelay(long time)
-{
-  volatile long ticks=(time * CCLK) / 2000000;
-  do{
-    ticks--;
-  } while(ticks>0);
-}
-*/
-
 /***********************************************************************
  * Routine for visible LED blinking (on USB transmission)
  ***********************************************************************/
@@ -209,8 +194,6 @@ int main(void)
        int chipnr,bd;
        int i,size,m=0;
 
-       cnt=0;
-
        CANMSG("Starting USBCAN module firmware...\n");
 
 //     volatile int i=0;
@@ -230,15 +213,13 @@ int main(void)
                sys_err();
        }
 
-// !!! DEBUG - transmitting and receiving CAN messages with usage of queue system from LinCAN - first version! 
 
-
-       //***********************************************************************
+       // ***********************************************************************
        // * CAN device initialization - device side (adapted from LinCAN setup.c)
        // ***********************************************************************
 
-       // DEBUG
-       //can_init(); // only for successful compiling (defined in can_lpcbusemu.c)
+//     useless with lpc17xx (defined in can_lpcbusemu.c)
+//     can_init();
 
 
        DEBUGMSG("Initiating CAN device initialization\n");
@@ -269,12 +250,12 @@ int main(void)
 
        
 
-       // DEBUG
-       //ul_usb1_register(candev->hwspecops);  // only for successful compiling (defined in ul_usb1.c)
-       // register for another board
+#ifdef CONFIG_OC_LINCAN_CARD_ul_usb1
+       ul_usb1_register(candev->hwspecops);
+#endif
+#ifdef CONFIG_OC_LINCAN_CARD_can_lmc1
        can_lmc1_register(candev->hwspecops);
-
-       
+#endif
 
        bd=baudrate[0];
        if (candev->hwspecops->init_hw_data(candev)){
@@ -327,11 +308,12 @@ int main(void)
 
                chip->flags |= CHIP_ATTACHED;
 
-// Interrupts from chip are served in main cycle
-//             if(can_chip_setup_irq(chip)<0) {
-//                     CANMSG("Error to setup chip IRQ\n");
-//                     sys_err();
-//             }
+               // used with lpc17xx:
+               if(can_chip_setup_irq(chip)<0) {
+                       CANMSG("Error to setup chip IRQ\n");
+                       sys_err();
+               }
+
        }
 
        if (candev->flags & CANDEV_PROGRAMMABLE_IRQ)
@@ -434,13 +416,11 @@ int main(void)
                usb_check_events(&usb_device);
                usb_control_response(&usb_device);
 
-// DEBUG
-//             if (!(IO0PIN&P0_SJA1000_INT_PIN)) //INT PIN is inverted
-//                     chip->chipspecops->irq_handler(0,chip);
-
-//             if (CAN1SR & CAN_SR_RBS)
-//                     chip->chipspecops->irq_handler(0,chip);
-
+#ifdef CONFIG_OC_LINCAN_CARD_ul_usb1
+               /* polled IRQ mode for ul_usb1 board*/
+               if (!(IO0PIN&P0_SJA1000_INT_PIN)) /* INT PIN is inverted */
+                       chip->chipspecops->irq_handler(0,chip);
+#endif
 
                if (usb_device.ep_events & MASK_EP1RX) {  //EP1RX - data waiting to receive
                        
@@ -475,7 +455,7 @@ int main(void)
                        
                                        slot->msg=canmsg;
                                        canque_put_inslot(qends, qedge, slot);
-                                       //CAN_send(&canmsg);
+
                                }
                                else
                                        canque_abort_inslot(qends,qedge,slot);
@@ -534,8 +514,6 @@ int main(void)
                                }
                                usb_udev_write_endpoint(&eps[1],ep1_tx_buff,16);
 
-                               //printf("ID: %d\n", msgid);
-
                                canque_free_outslot(qends, qedge, slot);
                                timer_tx_off=50;                //rozsviceni diod pri vysilani
                                CLR_OUT_PIN(LED_PORT,LED1_BIT);
@@ -543,6 +521,7 @@ int main(void)
 
                        }
                        
+
                }