]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/c_can_irq.c
Merge: C_CAN changes
[lincan.git] / lincan / src / c_can_irq.c
index 5257d0f016c8ba5feb3860aba1a02cfeb24f6f94..72ac0b5154cfb52435611ff34f64f47e5cebd753 100644 (file)
@@ -6,7 +6,7 @@
  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
  * email:pisa@cmp.felk.cvut.cz
  * This software is released under the GPL-License.
- * Version lincan-0.2  9 Jul 2003
+ * Version lincan-0.3  17 Jun 2004
  */
  
 #include "../include/can.h"
@@ -23,11 +23,11 @@ union c_can_data
 
 
 // prototypes
-inline void c_can_irq_read_handler( struct chip_t *pchip, int idxobj, u32 msgid  );
+inline void c_can_irq_read_handler( struct canchip_t *pchip, int idxobj, u32 msgid  );
 
-inline void c_can_irq_write_handler( struct chip_t *pchip, int idxobj);
+inline void c_can_irq_write_handler( struct canchip_t *pchip, int idxobj);
 
-void c_can_irq_rtr_handler( struct chip_t *pchip, int idxobj, u32 msgid );
+void c_can_irq_rtr_handler( struct canchip_t *pchip, int idxobj, u32 msgid );
 
 u16 readMaskCM = IFXCM_ARB | IFXCM_CNTRL | IFXCM_CLRINTPND
   | IFXCM_TRND | IFXCM_DA | IFXCM_DB;
@@ -41,7 +41,7 @@ u16 msgLstWriteMaskCM =  IFXCM_CNTRL | IFXCM_WRRD;
 // Send a message from the output fifo ( if any ).
 //
 
-inline void c_can_irq_write_handler( struct chip_t *pchip, int idxobj)
+inline void c_can_irq_write_handler( struct canchip_t *pchip, int idxobj)
 {
        int cmd;
        struct msgobj_t *pmsgobj = pchip->msgobj[idxobj];
@@ -52,6 +52,9 @@ inline void c_can_irq_write_handler( struct chip_t *pchip, int idxobj)
        if(pmsgobj->tx_slot){
                /* Do local transmitted message distribution if enabled */
                if (processlocal){
+                       /* fill CAN message timestamp */
+                       can_filltimestamp(&pmsgobj->tx_slot->msg.timestamp);
+
                        pmsgobj->tx_slot->msg.flags |= MSG_LOCAL;
                        canque_filter_msg2edges(pmsgobj->qends, &pmsgobj->tx_slot->msg);
                }
@@ -100,7 +103,7 @@ inline void c_can_irq_write_handler( struct chip_t *pchip, int idxobj)
 // Message received form the line. Write it in the input fifo->
 //
 
-inline void c_can_irq_read_handler( struct chip_t *pchip,
+inline void c_can_irq_read_handler( struct canchip_t *pchip,
                                    int idxobj, u32 msgid  )
 {
        int i=0;
@@ -140,13 +143,16 @@ inline void c_can_irq_read_handler( struct chip_t *pchip,
                }
                DEBUGMSG("(c%dm%d)Received Message:\n",
                      pchip->chip_idx, pmsgobj->object);
-               DEBUGMSG(" id = %d\n",
+               DEBUGMSG(" id = %ld\n",
                      pmsgobj->rx_msg.id);
                DEBUGMSG(" length = %d\n",
                      pmsgobj->rx_msg.length);
                for ( i=0; i < pmsgobj->rx_msg.length; i++ )
                        DEBUGMSG(" data[%d] = 0x%.2x\n", i, pmsgobj->rx_msg.data[i]);
                
+               /* fill CAN message timestamp */
+               can_filltimestamp(&pmsgobj->rx_msg.timestamp);
+
                canque_filter_msg2edges(pmsgobj->qends, &pmsgobj->rx_msg);
            
            #ifdef CAN_WITH_STATISTICS
@@ -157,8 +163,6 @@ inline void c_can_irq_read_handler( struct chip_t *pchip,
                pchip->stat.cntRxData += pmsgobj->rx_msg.length;
            #endif /*CAN_WITH_STATISTICS*/
 
-               spin_unlock( &c_can_sprlock );
-
                // Check if new data arrived
                if (c_can_if1_busycheck(pchip)) ;
                c_can_write_reg_w(pchip, readMaskCM, CCIF1CM);
@@ -178,7 +182,7 @@ inline void c_can_irq_read_handler( struct chip_t *pchip,
        // while
 }
 
-void c_can_irq_sync_activities(struct chip_t *chip, struct msgobj_t *obj)
+void c_can_irq_sync_activities(struct canchip_t *chip, struct msgobj_t *obj)
 {
        while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)) {
 
@@ -208,38 +212,29 @@ void c_can_irq_sync_activities(struct chip_t *chip, struct msgobj_t *obj)
 // c_can_irq_handler
 //
 
-can_irqreturn_t c_can_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
+int c_can_irq_handler(int irq, struct canchip_t *pchip)
 {
        struct rtr_id *rtr_search = hardware_p->rtr_queue;
-       struct chip_t *pchip = (struct chip_t *)dev_id;
        u16 chip_status;
        int id0=0, id1=0;
        u16 errcount = 0;
        u16 irqreg = 0;
        u32 msgid = 0;
        u16 tempCntlReg = 0;
-       //#ifdef CAN_DEBUG
-       // u32 intCntrVAddr = 0;
-       //#endif
-       //unsigned short flags = 0;
 
-       //if (pchip->ntype != CAN_CHIPTYPE_C_CAN)       {
-       //      DEBUGMSG("\n(c%d)IRQ not for c_can_irq_handler(...)\n", pchip->chip_idx);
-       //      return;
-       //}
 
        irqreg = c_can_read_reg_w( pchip, CCINTR );
 
        if(!irqreg) {
                DEBUGMSG( "\n(c%d)IRQ handler: addr=%.8lx spurious interrupt\n",
                        pchip->chip_idx,
-                       (long)( pchip->/*v*/base_addr/* + CCSR*/));
-               return CAN_IRQ_NONE;
+                       (long)( pchip->/*v*/chip_base_addr/* + CCSR*/));
+               return CANCHIP_IRQ_NONE;
        }
        
        DEBUGMSG( "\n(c%d)IRQ handler: addr=%.8lx irqreg=0x%.4x\n",
             pchip->chip_idx,
-            (long)( pchip->/*v*/base_addr/* + CCSR*/),
+            (long)( pchip->/*v*/chip_base_addr/* + CCSR*/),
             irqreg);
 
 
@@ -248,28 +243,6 @@ can_irqreturn_t c_can_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
        c_can_registerdump(pchip);
     #endif
 
-/*
-#ifdef CAN_DEBUG
-       if ( (!( intCntrVAddr = (u32)ioremap( 0x80024000, 0xCD ) ))) {
-               DEBUGMSG("Failed to map Interrupt Controller IO-memory\n");
-       }
-       else {
-
-   DEBUGMSG( "Mapped Interrupt Controller IO-memory: 0x%lx - 0x%lx to 0x%lx\n",
-               (unsigned long)0X80024000,
-             (unsigned long)0X800240CC,
-             (unsigned long)intCntrVAddr);
-       }
-
-       DEBUGMSG("Current Interrupt Status Register (ISR): 0x%4.4lx\n",
-                               (long)readl(intCntrVAddr + 4));
-       DEBUGMSG("Current Interrupt ID: %d\n",
-                               (int)(readl(intCntrVAddr + 0x90) & 0xF));
-       iounmap( (void*)intCntrVAddr);
-       DEBUGMSG( "Unmapped Interrupt Controller IO-memory: 0x%lx\n",
-             (unsigned long)intCntrVAddr);
-#endif
-*/
        while ( irqreg ){
                // Handle change in status register
            
@@ -470,14 +443,14 @@ can_irqreturn_t c_can_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
                // Get irq status again
                irqreg = c_can_read_reg_w( pchip, CCINTR );
        }
-       return CAN_IRQ_HANDLED;
+       return CANCHIP_IRQ_HANDLED;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // c_can_irq_rtr_handler
 //
 
-void c_can_irq_rtr_handler( struct chip_t *pchip, int idxobj, u32 msgid   )
+void c_can_irq_rtr_handler( struct canchip_t *pchip, int idxobj, u32 msgid   )
 {
        short int i=0;
        struct rtr_id *prtr_search = hardware_p->rtr_queue;