]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/sja1000p.c
To prevent future name collisions "chip_t" changed to "canchip_t"
[lincan.git] / lincan / src / sja1000p.c
index 74dae55d245cef6cdff160f3119232abc2287a36..dd9d696ae14f059384dbd8cb4f5d7dbe5a3f96f0 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"
@@ -18,7 +18,7 @@
  * sja1000p_enable_configuration - enable chip configuration mode
  * @chip: pointer to chip state structure
  */
-int sja1000p_enable_configuration(struct chip_t *chip)
+int sja1000p_enable_configuration(struct canchip_t *chip)
 {
        int i=0;
        enum sja1000_PeliCAN_MOD flags;
@@ -48,7 +48,7 @@ int sja1000p_enable_configuration(struct chip_t *chip)
  * sja1000p_disable_configuration - disable chip configuration mode
  * @chip: pointer to chip state structure
  */
-int sja1000p_disable_configuration(struct chip_t *chip)
+int sja1000p_disable_configuration(struct canchip_t *chip)
 {
        int i=0;
        enum sja1000_PeliCAN_MOD flags;
@@ -86,7 +86,7 @@ int sja1000p_disable_configuration(struct chip_t *chip)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_chip_config(struct chip_t *chip)
+int sja1000p_chip_config(struct canchip_t *chip)
 {
        int i;
        unsigned char n, r;
@@ -138,7 +138,7 @@ int sja1000p_chip_config(struct chip_t *chip)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_extended_mask(struct chip_t *chip, unsigned long code, unsigned  long mask)
+int sja1000p_extended_mask(struct canchip_t *chip, unsigned long code, unsigned  long mask)
 {
        int i;
 
@@ -173,7 +173,7 @@ int sja1000p_extended_mask(struct chip_t *chip, unsigned long code, unsigned  lo
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_baud_rate(struct chip_t *chip, int rate, int clock, int sjw,
+int sja1000p_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw,
                                                        int sampl_pt, int flags)
 {
        int best_error = 1000000000, error;
@@ -240,7 +240,7 @@ int sja1000p_baud_rate(struct chip_t *chip, int rate, int clock, int sjw,
  *
  * File: src/sja1000p.c
  */
-void sja1000p_read(struct chip_t *chip, struct msgobj_t *obj) {
+void sja1000p_read(struct canchip_t *chip, struct msgobj_t *obj) {
        int i, flags, len, datastart;
        do {
                flags = can_read_reg(chip,SJAFRM);
@@ -267,6 +267,9 @@ void sja1000p_read(struct chip_t *chip, struct msgobj_t *obj) {
                        obj->rx_msg.data[i]=can_read_reg(chip,datastart+i);
                }
 
+               /* fill CAN message timestamp */
+               can_filltimestamp(&obj->rx_msg.timestamp);
+
                canque_filter_msg2edges(obj->qends, &obj->rx_msg);
 
                can_write_reg(chip, sjaCMR_RRB, SJACMR);
@@ -283,7 +286,7 @@ void sja1000p_read(struct chip_t *chip, struct msgobj_t *obj) {
  *     Positive value indicates immediate reception of message.
  * File: src/sja1000p.c
  */
-int sja1000p_pre_read_config(struct chip_t *chip, struct msgobj_t *obj)
+int sja1000p_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj)
 {
        int status;
        status=can_read_reg(chip,SJASR);
@@ -322,7 +325,7 @@ int sja1000p_pre_read_config(struct chip_t *chip, struct msgobj_t *obj)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_pre_write_config(struct chip_t *chip, struct msgobj_t *obj, 
+int sja1000p_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj, 
                                                        struct canmsg_t *msg)
 {
        int i=0; 
@@ -401,7 +404,7 @@ int sja1000p_pre_write_config(struct chip_t *chip, struct msgobj_t *obj,
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_send_msg(struct chip_t *chip, struct msgobj_t *obj, 
+int sja1000p_send_msg(struct canchip_t *chip, struct msgobj_t *obj, 
                                                        struct canmsg_t *msg)
 {
        can_write_reg(chip, sjaCMR_TR, SJACMR);
@@ -418,7 +421,7 @@ int sja1000p_send_msg(struct chip_t *chip, struct msgobj_t *obj,
  *     Zero value indicates finishing of all issued transmission requests.
  * File: src/sja1000p.c
  */
-int sja1000p_check_tx_stat(struct chip_t *chip)
+int sja1000p_check_tx_stat(struct canchip_t *chip)
 {
        if (can_read_reg(chip,SJASR) & sjaSR_TCS)
                return 0;
@@ -435,7 +438,7 @@ int sja1000p_check_tx_stat(struct chip_t *chip)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_set_btregs(struct chip_t *chip, unsigned short btr0, 
+int sja1000p_set_btregs(struct canchip_t *chip, unsigned short btr0, 
                                                        unsigned short btr1)
 {
        if (sja1000p_enable_configuration(chip))
@@ -456,7 +459,7 @@ int sja1000p_set_btregs(struct chip_t *chip, unsigned short btr0,
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_start_chip(struct chip_t *chip)
+int sja1000p_start_chip(struct canchip_t *chip)
 {
        enum sja1000_PeliCAN_MOD flags;
 
@@ -473,7 +476,7 @@ int sja1000p_start_chip(struct chip_t *chip)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_stop_chip(struct chip_t *chip)
+int sja1000p_stop_chip(struct canchip_t *chip)
 {
        enum sja1000_PeliCAN_MOD flags;
 
@@ -492,7 +495,7 @@ int sja1000p_stop_chip(struct chip_t *chip)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_remote_request(struct chip_t *chip, struct msgobj_t *obj)
+int sja1000p_remote_request(struct canchip_t *chip, struct msgobj_t *obj)
 {
        CANMSG("sja1000p_remote_request not implemented\n");
        return -ENOSYS;
@@ -507,7 +510,7 @@ int sja1000p_remote_request(struct chip_t *chip, struct msgobj_t *obj)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_standard_mask(struct chip_t *chip, unsigned short code,
+int sja1000p_standard_mask(struct canchip_t *chip, unsigned short code,
                unsigned short mask)
 {
        CANMSG("sja1000p_standard_mask not implemented\n");
@@ -521,7 +524,7 @@ int sja1000p_standard_mask(struct chip_t *chip, unsigned short code,
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_clear_objects(struct chip_t *chip)
+int sja1000p_clear_objects(struct canchip_t *chip)
 {
        CANMSG("sja1000p_clear_objects not implemented\n");
        return -ENOSYS;
@@ -535,7 +538,7 @@ int sja1000p_clear_objects(struct chip_t *chip)
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_config_irqs(struct chip_t *chip, short irqs)
+int sja1000p_config_irqs(struct canchip_t *chip, short irqs)
 {
        CANMSG("sja1000p_config_irqs not implemented\n");
        return -ENOSYS;
@@ -552,13 +555,16 @@ int sja1000p_config_irqs(struct chip_t *chip, short irqs)
  * sja1000p_irq_write_handler() for transmit events.
  * File: src/sja1000p.c
  */
-void sja1000p_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
+void sja1000p_irq_write_handler(struct canchip_t *chip, struct msgobj_t *obj)
 {
        int cmd;
        
        if(obj->tx_slot){
                /* Do local transmitted message distribution if enabled */
                if (processlocal){
+                       /* fill CAN message timestamp */
+                       can_filltimestamp(&obj->tx_slot->msg.timestamp);
+                       
                        obj->tx_slot->msg.flags |= MSG_LOCAL;
                        canque_filter_msg2edges(obj->qends, &obj->tx_slot->msg);
                }
@@ -595,7 +601,7 @@ void sja1000p_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
  * @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 chip_t
+ *     to chip state structure - @struct canchip_t
  * @regs: system dependent value pointing to registers stored in exception frame
  * 
  * Interrupt handler is activated when state of CAN controller chip changes,
@@ -605,10 +611,9 @@ void sja1000p_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
  * message queues.
  * File: src/sja1000p.c
  */
-can_irqreturn_t sja1000p_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
+int sja1000p_irq_handler(int irq, struct canchip_t *chip)
 {
        int irq_register, status, error_code;
-       struct chip_t *chip=(struct chip_t *)dev_id;
        struct msgobj_t *obj=chip->msgobj[0];
 
        irq_register=can_read_reg(chip,SJAIR);
@@ -617,11 +622,11 @@ can_irqreturn_t sja1000p_irq_handler(int irq, void *dev_id, struct pt_regs *regs
 //                                     can_read_reg(chip,SJASR));
 
        if ((irq_register & (sjaIR_BEI|sjaIR_EPI|sjaIR_DOI|sjaIR_EI|sjaIR_TI|sjaIR_RI)) == 0)
-               return CAN_IRQ_NONE;
+               return CANCHIP_IRQ_NONE;
 
        if(!(chip->flags&CHIP_CONFIGURED)) {
                CANMSG("sja1000p_irq_handler: called for non-configured device, irq_register 0x%02x\n", irq_register);
-               return CAN_IRQ_NONE;
+               return CANCHIP_IRQ_NONE;
        }
 
        if ((irq_register & sjaIR_RI) != 0) {
@@ -677,7 +682,7 @@ can_irqreturn_t sja1000p_irq_handler(int irq, void *dev_id, struct pt_regs *regs
                obj->tx_retry_cnt=0;
        }
 
-       return CAN_IRQ_HANDLED;
+       return CANCHIP_IRQ_HANDLED;
 }
 
 /**
@@ -691,7 +696,7 @@ can_irqreturn_t sja1000p_irq_handler(int irq, void *dev_id, struct pt_regs *regs
  * Return Value: negative value reports error.
  * File: src/sja1000p.c
  */
-int sja1000p_wakeup_tx(struct chip_t *chip, struct msgobj_t *obj)
+int sja1000p_wakeup_tx(struct canchip_t *chip, struct msgobj_t *obj)
 {
        
        can_preempt_disable();
@@ -738,3 +743,19 @@ int sja1000p_register(struct chipspecops_t *chipspecops)
        chipspecops->irq_handler=sja1000p_irq_handler;
        return 0;
 }
+
+/**
+ * sja1000p_fill_chipspecops - fills chip specific operations
+ * @chip: pointer to chip representation structure
+ *
+ * The function fills chip specific operations for sja1000 (PeliCAN) chip.
+ *
+ * Return Value: returns negative number in the case of fail
+ */
+int sja1000p_fill_chipspecops(struct canchip_t *chip)
+{
+       chip->chip_type="sja1000p";
+       chip->max_objects=1;
+       sja1000p_register(chip->chipspecops);
+       return 0;
+}