From 089990fd8d75196bf73b9c004519781d733afacc Mon Sep 17 00:00:00 2001 From: Jan Kriz Date: Sun, 6 Jul 2008 11:15:05 +0200 Subject: [PATCH] can_quesysless.c remains to be fixed (tasklets and sleeping) --- embedded/app/usbcan/can/main.h | 7 ++++ embedded/app/usbcan/can/sja1000p.h | 15 ++++--- embedded/app/usbcan/can_queue.c | 6 +-- embedded/app/usbcan/sja1000p.c | 64 +++++++++++++++--------------- 4 files changed, 52 insertions(+), 40 deletions(-) diff --git a/embedded/app/usbcan/can/main.h b/embedded/app/usbcan/can/main.h index 9a1d65b..9511d84 100644 --- a/embedded/app/usbcan/can/main.h +++ b/embedded/app/usbcan/can/main.h @@ -7,6 +7,9 @@ * Version lincan-0.3 17 Jun 2004 */ +#ifndef MAIN_H +#define MAIN_H + #include #include "./can.h" @@ -14,6 +17,7 @@ #include "./ul_listbase.h" #include "./can_sysless.h" #include "./can_queue.h" +#include "./errno.h" #ifdef CAN_DEBUG #define DEBUGMSG(fmt,args...) can_printk(KERN_ERR "can.o (debug): " fmt,\ @@ -513,3 +517,6 @@ void can_filltimestamp(canmsg_tstamp_t *ptimestamp) #ifdef CAN_WITH_RTL extern int can_rtl_priority; #endif /*CAN_WITH_RTL*/ + +#endif /* MAIN_H */ + diff --git a/embedded/app/usbcan/can/sja1000p.h b/embedded/app/usbcan/can/sja1000p.h index 1aa0923..fe81a9c 100644 --- a/embedded/app/usbcan/can/sja1000p.h +++ b/embedded/app/usbcan/can/sja1000p.h @@ -2,13 +2,16 @@ * Header file for the Linux CAN-bus driver. * Written by Arnaud Westenberg email:arnaud@wanadoo.nl * Added by T.Motylewski@bfad.de - * See app. note an97076.pdf from Philips Semiconductors + * See app. note an97076.pdf from Philips Semiconductors * and SJA1000 data sheet * PELICAN mode * This software is released under the GPL-License. * Version lincan-0.3 17 Jun 2004 */ +#ifndef SJA1000P_H +#define SJA1000P_H + int sja1000p_chip_config(struct canchip_t *chip); int sja1000p_extended_mask(struct canchip_t *chip, unsigned long code, unsigned long mask); int sja1000p_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw, @@ -57,7 +60,7 @@ enum SJA1000_PeliCAN_regs { /// Transmit Buffer (write) Receive Buffer (read) Frame Information SJAFRM = 0x10, /// ID bytes (11 bits in 0 and 1 or 16 bits in 0,1 and 13 bits in 2,3 (extended)) - SJAID0 = 0x11, SJAID1 = 0x12, + SJAID0 = 0x11, SJAID1 = 0x12, /// ID cont. for extended frames SJAID2 = 0x13, SJAID3 = 0x14, /// Data start standard frame @@ -69,7 +72,7 @@ enum SJA1000_PeliCAN_regs { /// Acceptance Mask (4 bytes) in RESET mode SJAAMR0 = 0x14, /// 4 bytes - SJA_PeliCAN_AC_LEN = 4, + SJA_PeliCAN_AC_LEN = 4, /// Clock Divider SJACDR = 0x1f }; @@ -84,7 +87,7 @@ enum sja1000_PeliCAN_MOD { }; /** Command Register 0x01 */ -enum sja1000_PeliCAN_CMR { +enum sja1000_PeliCAN_CMR { sjaCMR_SRR= 1<<4, // Self Reception Request (GoToSleep in BASIC mode) sjaCMR_CDO= 1<<3, // Clear Data Overrun sjaCMR_RRB= 1<<2, // Release Receive Buffer @@ -114,7 +117,7 @@ enum sja1000_PeliCAN_IER { sjaIER_RIE = 1, // Receive Interrupt Enable sjaENABLE_INTERRUPTS = sjaIER_BEIE|sjaIER_EPIE|sjaIER_DOIE|sjaIER_EIE|sjaIER_TIE|sjaIER_RIE, sjaDISABLE_INTERRUPTS = 0 -// WARNING: the chip automatically enters RESET (bus off) mode when +// WARNING: the chip automatically enters RESET (bus off) mode when // error counter > 255 }; @@ -198,3 +201,5 @@ enum sja1000_CDR { /** flags for sja1000_baud_rate */ #define BTR1_SAM (1<<1) + +#endif /* SJA1000P_H */ diff --git a/embedded/app/usbcan/can_queue.c b/embedded/app/usbcan/can_queue.c index 3f72015..5a098bb 100644 --- a/embedded/app/usbcan/can_queue.c +++ b/embedded/app/usbcan/can_queue.c @@ -6,9 +6,9 @@ * Version lincan-0.3 17 Jun 2004 */ -#include "../include/can.h" -#include "../include/can_sysdep.h" -#include "../include/can_queue.h" +#include "./can/can.h" +#include "./can/can_sysdep.h" +#include "./can/can_queue.h" /* * Modifies Tx message processing diff --git a/embedded/app/usbcan/sja1000p.c b/embedded/app/usbcan/sja1000p.c index ffadb6c..8a527ff 100644 --- a/embedded/app/usbcan/sja1000p.c +++ b/embedded/app/usbcan/sja1000p.c @@ -9,10 +9,10 @@ * Version lincan-0.3 17 Jun 2004 */ -#include "../include/can.h" -#include "../include/can_sysdep.h" -#include "../include/main.h" -#include "../include/sja1000p.h" +#include "./can/can.h" +#include "./can/can_sysdep.h" +#include "./can/main.h" +#include "./can/sja1000p.h" #ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS @@ -168,7 +168,7 @@ int sja1000p_disable_configuration(struct canchip_t *chip) * This function configures chip and prepares it for message * transmission and reception. The function resets chip, * resets mask for acceptance of all messages by call to - * sja1000p_extended_mask() function and then + * sja1000p_extended_mask() function and then * computes and sets baudrate with use of function sja1000p_baud_rate(). * Return Value: negative value reports error. * File: src/sja1000p.c @@ -177,19 +177,19 @@ int sja1000p_chip_config(struct canchip_t *chip) { int i; unsigned char n, r; - + if (sja1000p_enable_configuration(chip)) return -ENODEV; /* Set mode, clock out, comparator */ - can_write_reg(chip,sjaCDR_PELICAN|chip->sja_cdr_reg,SJACDR); + can_write_reg(chip,sjaCDR_PELICAN|chip->sja_cdr_reg,SJACDR); /* Ensure, that interrupts are disabled even on the chip level now */ can_write_reg(chip, sjaDISABLE_INTERRUPTS, SJAIER); /* Set driver output configuration */ - can_write_reg(chip,chip->sja_ocr_reg,SJAOCR); - + can_write_reg(chip,chip->sja_ocr_reg,SJAOCR); + /* Simple check for chip presence */ for (i=0, n=0x5a; i<8; i++, n+=0xf) { can_write_reg(chip,n,SJAACR0+i); @@ -202,21 +202,21 @@ int sja1000p_chip_config(struct canchip_t *chip) return -ENODEV; } } - + if (sja1000p_extended_mask(chip,0x00000000, 0xffffffff)) return -ENODEV; - + if (!chip->baudrate) chip->baudrate=1000000; if (sja1000p_baud_rate(chip,chip->baudrate,chip->clock,0,75,0)) return -ENODEV; /* Enable hardware interrupts */ - can_write_reg(chip, sjaENABLE_INTERRUPTS, SJAIER); + can_write_reg(chip, sjaENABLE_INTERRUPTS, SJAIER); sja1000p_disable_configuration(chip); - + return 0; } @@ -236,7 +236,7 @@ int sja1000p_extended_mask(struct canchip_t *chip, unsigned long code, unsigned if (sja1000p_enable_configuration(chip)) return -ENODEV; -// LSB to +3, MSB to +0 +// LSB to +3, MSB to +0 for(i=SJA_PeliCAN_AC_LEN; --i>=0;) { can_write_reg(chip,code&0xff,SJAACR0+i); can_write_reg(chip,mask&0xff,SJAAMR0+i); @@ -270,7 +270,7 @@ int sja1000p_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw, int best_error = 1000000000, error; int best_tseg=0, best_brp=0, best_rate=0, brp=0; int tseg=0, tseg1=0, tseg2=0; - + if (sja1000p_enable_configuration(chip)) return -ENODEV; @@ -316,7 +316,7 @@ int sja1000p_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw, can_write_reg(chip, sjw<<6 | best_brp, SJABTR0); - can_write_reg(chip, ((flags & BTR1_SAM) != 0)<<7 | (tseg2<<4) + can_write_reg(chip, ((flags & BTR1_SAM) != 0)<<7 | (tseg2<<4) | tseg1, SJABTR1); sja1000p_disable_configuration(chip); @@ -381,7 +381,7 @@ int sja1000p_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj) { int status; status=can_read_reg(chip,SJASR); - + if(status & sjaSR_BS) { /* Try to recover from error condition */ DEBUGMSG("sja1000p_pre_read_config bus-off recover 0x%x\n",status); @@ -416,20 +416,20 @@ int sja1000p_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj) * Return Value: negative value reports error. * File: src/sja1000p.c */ -int sja1000p_pre_write_config(struct canchip_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; + int i=0; unsigned int id; int status; int len; /* Wait until Transmit Buffer Status is released */ - while ( !((status=can_read_reg(chip, SJASR)) & sjaSR_TBS) && + while ( !((status=can_read_reg(chip, SJASR)) & sjaSR_TBS) && i++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); } @@ -691,7 +691,7 @@ void sja1000p_irq_write_handler(struct canchip_t *chip, struct msgobj_t *obj) canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot); obj->tx_slot=NULL; } - + can_msgobj_clear_fl(obj,TX_PENDING); cmd=canque_test_outslot(obj->qends, &obj->tx_qedge, &obj->tx_slot); if(cmd<0) @@ -721,7 +721,7 @@ void sja1000p_irq_write_handler(struct canchip_t *chip, struct msgobj_t *obj) * sja1000p_irq_handler: - interrupt service routine * @irq: interrupt vector number, this value is system specific * @chip: pointer to chip state structure - * + * * Interrupt handler is activated when state of CAN controller chip changes, * there is message to be read or there is more space for new messages or * error occurs. The receive events results in reading of the message from @@ -783,14 +783,14 @@ int sja1000p_irq_handler(int irq, struct canchip_t *chip) DEBUGMSG("TX looping in sja1000_irq_handler\n"); } } - if ((irq_register & (sjaIR_EI|sjaIR_BEI|sjaIR_EPI|sjaIR_DOI)) != 0) { + if ((irq_register & (sjaIR_EI|sjaIR_BEI|sjaIR_EPI|sjaIR_DOI)) != 0) { // Some error happened error_code=can_read_reg(chip,SJAECC); sja1000_report_error(chip, status, irq_register, error_code); // FIXME: chip should be brought to usable state. Transmission cancelled if in progress. // Reset flag set to 0 if chip is already off the bus. Full state report obj->ret=-1; - + if(error_code == 0xd9) { obj->ret= -ENXIO; /* no such device or address - no ACK received */ @@ -844,9 +844,9 @@ int sja1000p_irq_handler(int irq, struct canchip_t *chip) */ int sja1000p_wakeup_tx(struct canchip_t *chip, struct msgobj_t *obj) { - + can_preempt_disable(); - + can_msgobj_set_fl(obj,TX_PENDING); can_msgobj_set_fl(obj,TX_REQUEST); while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){ @@ -856,7 +856,7 @@ int sja1000p_wakeup_tx(struct canchip_t *chip, struct msgobj_t *obj) obj->tx_retry_cnt=0; sja1000p_irq_write_handler(chip, obj); } - + can_msgobj_clear_fl(obj,TX_LOCK); if(!can_msgobj_test_fl(obj,TX_REQUEST)) break; DEBUGMSG("TX looping in sja1000p_wakeup_tx\n"); -- 2.39.2