CAN framework for U-Boot
cover CAN framework for U-Boot
From: Wolfgang Grandegger <[email protected]>
This patch series adds a simple CAN framework for U-Boot. The main purpose is to do simple RX/TX testing when the device boots up but the interface functions could also be used for more complex tasks. This is just a RFC and a few more features need to be added or issues to be fixed, like using a generic device interface, if it already exists, and board specific device configuration, e.g. via i82527_register(addr, cfg-params). The sources are based on GPL v2+ code to be compatible with future U-Boot licence requirement.
Please comment.
Wolfgang
Wolfgang Grandegger (5):
CAN interface library
CAN device test command
CAN device driver for the SJA1000
CAN device driver for the Intel 82527
CAN interface support for the TQM855L module
Makefile | 1 + board/tqc/tqm8xx/tqm8xx.c | 17 ++ common/Makefile | 1 + common/cmd_can.c | 119 +++++++++++++++ drivers/can/Makefile | 49 ++++++ drivers/can/can.c | 88 +++++++++++ drivers/can/i82527.c | 366 +++++++++++++++++++++++++++++++++++++++++++++ drivers/can/sja1000.c | 223 +++++++++++++++++++++++++++ include/can.h | 70 +++++++++ include/configs/TQM855L.h | 8 +- include/i82527.h | 201 +++++++++++++++++++++++++ include/sja1000.h | 159 ++++++++++++++++++++ 12 files changed, 1301 insertions(+), 1 deletions(-) create mode 100644 common/cmd_can.c create mode 100644 drivers/can/Makefile create mode 100644 drivers/can/can.c create mode 100644 drivers/can/i82527.c create mode 100644 drivers/can/sja1000.c create mode 100644 include/can.h create mode 100644 include/i82527.h create mode 100644 include/sja1000.h
RFC 1/5 CAN interface library
From: Wolfgang Grandegger <[email protected]>
--- Makefile | 1 + drivers/can/Makefile | 47 ++++++++++++++++++++++++++ drivers/can/can.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/can.h | 70 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+), 0 deletions(-) create mode 100644 drivers/can/Makefile create mode 100644 drivers/can/can.c create mode 100644 include/can.h
Makefile +1 -0
@@ -203,6 +203,7 @@ LIBS += net/libnet.a LIBS += disk/libdisk.a LIBS += drivers/bios_emulator/libatibiosemu.a LIBS += drivers/block/libblock.a +LIBS += drivers/can/libcan.a LIBS += drivers/dma/libdma.a LIBS += drivers/fpga/libfpga.a LIBS += drivers/gpio/libgpio.a
drivers/can/Makefile new file +47 -0
47 lines not on this page · raw message
drivers/can/can.c new file +88 -0
88 lines not on this page · raw message
include/can.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC 2/5 CAN device test command
From: Wolfgang Grandegger <[email protected]>
--- common/Makefile | 1 + common/cmd_can.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 common/cmd_can.c
common/Makefile +1 -0
@@ -72,6 +72,7 @@ COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o +COBJS-$(CONFIG_CMD_CAN) += cmd_can.o COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o COBJS-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o COBJS-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o
common/cmd_can.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC 3/5 CAN device driver for the SJA1000
From: Wolfgang Grandegger <[email protected]>
--- drivers/can/Makefile | 3 +- drivers/can/sja1000.c | 223 +++++++++++++++++++++++++++++++++++++++++++++++++ include/sja1000.h | 159 +++++++++++++++++++++++++++++++++++ 3 files changed, 384 insertions(+), 1 deletions(-) create mode 100644 drivers/can/sja1000.c create mode 100644 include/sja1000.h
drivers/can/Makefile +2 -1
@@ -25,7 +25,8 @@ include $(TOPDIR)/config.mk LIB := $(obj)libcan.a -COBJS-$(CONFIG_CAN) += can.o +COBJS-$(CONFIG_CAN) += can.o +COBJS-$(CONFIG_CAN_SJA1000) += sja1000.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
drivers/can/sja1000.c new file +223 -0
223 lines not on this page · raw message
include/sja1000.h new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC 4/5 CAN device driver for the Intel 82527
From: Wolfgang Grandegger <[email protected]>
--- drivers/can/Makefile | 1 + drivers/can/i82527.c | 366 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/i82527.h | 201 +++++++++++++++++++++++++++ 3 files changed, 568 insertions(+), 0 deletions(-) create mode 100644 drivers/can/i82527.c create mode 100644 include/i82527.h
drivers/can/Makefile +1 -0
@@ -26,6 +26,7 @@ include $(TOPDIR)/config.mk LIB := $(obj)libcan.a COBJS-$(CONFIG_CAN) += can.o +COBJS-$(CONFIG_CAN_I82527) += i82527.o COBJS-$(CONFIG_CAN_SJA1000) += sja1000.o COBJS := $(COBJS-y)
drivers/can/i82527.c new file +366 -0
366 lines not on this page · raw message
include/i82527.h new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
1.6.2.5
RFC 5/5 CAN interface support for the TQM855L module
From: Wolfgang Grandegger <[email protected]>
--- board/tqc/tqm8xx/tqm8xx.c | 17 +++++++++++++++++ include/configs/TQM855L.h | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletions(-)
board/tqc/tqm8xx/tqm8xx.c +17 -0
@@ -26,6 +26,10 @@#ifdef CONFIG_PS2MULT #include <ps2mult.h> #endif +#ifdef CONFIG_CAN +#include <can.h> +#include <i82527.h> +#endif extern flash_info_t flash_info[];/* FLASH chips info */
@@ -447,6 +451,19 @@ int board_early_init_r (void)#endif /* CONFIG_PS2MULT */ +#if defined(CONFIG_CAN_DRIVER ) && defined(CONFIG_CAN ) +static struct can_dev tqm8xx_can[2 ]; + +#ifdef CONFIG_BOARD_EARLY_INIT_R +int board_early_init_r (void ) +{ +i82527_register (&tqm8xx_can[0 ],CONFIG_SYS_CAN_BASE ); +i82527_register ( &tqm8xx_can[1 ],CONFIG_SYS_CAN_BASE +0x100 ); + +return (0 ); +} +#endif +#endif #ifdef CONFIG_MISC_INIT_R extern void load_sernum_ethaddr (void );
include/configs/TQM855L.h +7 -1
@@ -88,7 +88,13 @@#define CONFIG_STATUS_LED 1/* Status LED enabled */ -#undef CONFIG_CAN_DRIVER/* CAN Driver support disabled */ +#define CONFIG_CAN_DRIVER /* CAN Driver support enabled */ +#ifdef CONFIG_CAN_DRIVER +#define CONFIG_CAN +#define CONFIG_CAN_I82527 +#define CONFIG_CMD_CAN +#define CONFIG_BOARD_EARLY_INIT_R +#endif /* * BOOTP options
Signature · 1 line
1.6.2.5
RFC 3/5 CAN device driver for the SJA1000
In reply to Wolfgang GrandeggerHi Wolfgang,
this patch conflicts with my simple SJA header posted some days ago
http://lists.denx.de/pipermail/u-boot/2009-October/063097.html
together with a fix for two of our boards - which has not much to do with CAN. WD asked me to use a C struct to access the SJA1000.
http://lists.denx.de/pipermail/u-boot/2009-October/062902.html
So where does this bring us? Either we want to use C structs for everything or decide it from patch to patch :-(
Matthias
Quoted 419 lines · Wolfgang Grandegger
From: Wolfgang Grandegger <[email protected]>
Signed-off-by Wolfgang Grandegger <[email protected]>--- drivers/can/Makefile | 3 +- drivers/can/sja1000.c | 223 +++++++++++++++++++++++++++++++++++++++++++++++++ include/sja1000.h | 159 +++++++++++++++++++++++++++++++++++ 3 files changed, 384 insertions(+), 1 deletions(-) create mode 100644 drivers/can/sja1000.c create mode 100644 include/sja1000.hdrivers/can/Makefile +2
-1@@ -25,7 +25,8 @@ include $(TOPDIR)/config.mk LIB := $(obj)libcan.a -COBJS-$(CONFIG_CAN) += can.o +COBJS-$(CONFIG_CAN) += can.o +COBJS-$(CONFIG_CAN_SJA1000) += sja1000.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)drivers/can/sja1000.c new file +223
-0@@ -0,0 +1,223 @@ +/* +* (C) Copyright 2007-2009, Wolfgang Grandegger <[email protected]> +* +* Derived from Xenomai's RT-Socket-CAN driver for SJA1000: +* +* Copyright (C) 2005,2006 Sebastian Smolorz +* <[email protected]> +* +* Copyright (C) 2005, Sascha Hauer, Pengutronix +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program 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 this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <common.h> +#include <asm/io.h> + +#include <can.h> +#include <sja1000.h> + +#define SJA1000_OCR (SJA_OCR_MODE_NORMAL | SJA_OCR_TX0_PUSHPULL) +#define SJA1000_CDR SJA_CDR_CAN_MODE + +/* +* Basic functions to access registers +*/ +#define sja1000_read_reg (dev, reg) \ + in_8 ((volatile u8 *)((dev)->base + (reg))) + +#define sja1000_write_reg (dev, reg, value) \ + out_8 ((volatile u8 *)((dev)->base + (reg)), value) + +/* +* Baudrate table +*/ + +static u16 sja1000_btr0btr1[] = { +0x031c ,/* 125K */ +0x011c ,/* 250K */ +0x001c ,/* 500K */ +}; + +int sja1000_init (struct can_dev *dev,unsigned int ibaud) +{ +int i, wait =1000 ; +u16 btr0btr1; + +/* Disable the controller's interrupts */ +sja1000_write_reg (dev,SJA_IER ,0x00 ); + +/* Set reset mode bit */ +sja1000_write_reg (dev,SJA_MOD ,SJA_MOD_RM ); + +/* Read reset mode bit, multiple tests */ +do { +udelay (100 ); +if (sja1000_read_reg (dev,SJA_MOD ) &SJA_MOD_RM ) +break ; + }while (--wait); + +sja1000_write_reg (dev,SJA_CDR ,SJA1000_CDR ); +sja1000_write_reg (dev,SJA_OCR ,SJA1000_OCR ); + +sja1000_write_reg (dev,SJA_AMR0 ,0xFF ); +sja1000_write_reg (dev,SJA_AMR1 ,0xFF ); +sja1000_write_reg (dev,SJA_AMR2 ,0xFF ); +sja1000_write_reg (dev,SJA_AMR3 ,0xFF ); + +sja1000_write_reg (dev,SJA_RXERR ,0 ); +sja1000_write_reg (dev,SJA_TXERR ,0 ); + + i =sizeof (sja1000_btr0btr1) /sizeof (u16); +if (ibaud >= i) + ibaud = i -1 ; + btr0btr1 = sja1000_btr0btr1[ibaud]; +sja1000_write_reg (dev,SJA_BTR0 , (btr0btr1 >>8 ) &0xff ); +sja1000_write_reg (dev,SJA_BTR1 , (btr0btr1 &0xff )); + +/* Clear error code capture (i.e. read it) */ +sja1000_read_reg (dev,SJA_ECC ); + +/* Clear reset mode bit in SJA1000 */ +sja1000_write_reg (dev,SJA_MOD ,0 ); + +return 0 ; +} + +int sja1000_xmit (struct can_dev *dev,struct can_msg *msg) +{ +int i; +u8 fir; + +if (msg->dlc >8 ) + msg->dlc =8 ; + fir = msg->dlc; + +sja1000_write_reg (dev,SJA_ID1 , msg->id >>3 ); +sja1000_write_reg (dev,SJA_ID2 , msg->id <<5 ); +for (i =0 ; i < msg->dlc; i++) +sja1000_write_reg (dev,SJA_DATA_SFF (i), msg->data[i]); + +/* Write frame information register */ +sja1000_write_reg (dev,SJA_FIR , fir); + +/* Push the 'send' button */ +sja1000_write_reg (dev,SJA_CMR ,SJA_CMR_TR ); + +/* Wait some time */ +for (i =0 ; i <CAN_XMIT_TIMEOUT_US ; i +=10000 ) { +if (sja1000_read_reg (dev,SJA_SR ) &SJA_SR_TCS ) +return 0 ; +if (ctrlc ()) +break ; +udelay (10000 ); + } + +return -1 ; +} + +int sja1000_recv (struct can_dev *dev,struct can_msg *msg) +{ +int i; +u8 fir; + +while (!(sja1000_read_reg (dev,SJA_SR ) &SJA_SR_RBS )) { +if (ctrlc ()) +return -1 ; + } + +/* Read out frame information register */ + fir =sja1000_read_reg (dev,SJA_FIR ); + +/* Extract data length code */ + msg->dlc = fir &SJA_FIR_DLC_MASK ; + +/* If DLC exceeds 8 bytes adjust it to 8 (for the payload size) */ +if (msg->dlc >8 ) + msg->dlc =8 ; + +if (fir &SJA_FIR_EFF ) { +printf ("Extended CAN messages not supported\n" ); +return -1 ; + }else { + msg->id =sja1000_read_reg (dev,SJA_ID1 ) <<3 ; + msg->id |=sja1000_read_reg (dev,SJA_ID2 ) >>5 ; + +if (!(fir &SJA_FIR_RTR )) { +for (i =0 ; i < msg->dlc; i++) + msg->data[i] = +sja1000_read_reg (dev,SJA_DATA_SFF (i)); + } + } +if (fir &SJA_FIR_RTR ) + msg->id |=CAN_RTR_FLAG ; + +/* Release Receive Buffer */ +sja1000_write_reg (dev,SJA_CMR ,SJA_CMR_RRB ); + +return 0 ; +} + +int sja1000_status (struct can_dev *dev,int level) +{ +printf ("SJA1000 at %#x" , dev->base); +if (level >0 ) { +int stat =sja1000_read_reg (dev,SJA_SR ) &0xff ; +printf (", status 0x%02x" , stat); +if (stat &SJA_SR_BS ) +puts (" busoff" ); +if (stat &SJA_SR_ES ) +puts (" error" ); +if (stat &SJA_SR_TS ) +puts (" txing" ); +if (stat &SJA_SR_RS ) +puts (" rxing" ); +if (stat &SJA_SR_TCS ) +puts (" txdone" ); +if (stat &SJA_SR_TBS ) +puts (" txfree" ); +if (stat &SJA_SR_DOS ) +puts (" overrun" ); +if (stat &SJA_SR_RBS ) +puts (" rxfull" ); + } +puts ("\n" ); +if (level >1 ) { +int i; +for (i =0 ; i <SJA1000_SIZE ; i++) { +if ((i %0x10 ) ==0 ) +printf ("\n%02x:" , i); +printf (" %02x" ,sja1000_read_reg (dev, i)); + } +puts ("\n" ); + } +return 0 ; +} + +void sja1000_register (struct can_dev *dev,unsigned long base) +{ + dev->name ="sja1000" ; + dev->base = base; + dev->init = sja1000_init; + dev->xmit = sja1000_xmit; + dev->recv = sja1000_recv; + dev->status = sja1000_status; + +can_register (dev); +}include/sja1000.h new file +159
-0@@ -0,0 +1,159 @@ +/* +* (C) Copyright 2007-2009, Wolfgang Grandegger <[email protected]> +* +* Derived from Xenomai's RT-Socket-CAN driver for SJA1000: +* +* Copyright (C) 2005,2006 Sebastian Smolorz +* <[email protected]> +* +* Copyright (C) 2005, Sascha Hauer, Pengutronix +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program 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 this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#ifndef __SJA1000_H__ +#define __SJA1000_H__ + +#include <can.h> + +/* PeliCAN mode address map */ + +/* reset and operating mode */ +#define SJA_MOD 0/* Mode register */ +#define SJA_CMR 1/* Command register */ +#define SJA_SR 2/* Status register */ +#define SJA_IR 3/* Interrupt register */ +#define SJA_IER 4/* Interrupt enable register */ +#define SJA_BTR0 6/* Bus timing register 0 */ +#define SJA_BTR1 7/* Bus timing register 1 */ +#define SJA_OCR 8/* Output control register */ +#define SJA_ALC 11/* Arbitration lost capture */ +#define SJA_ECC 12/* Error code capture register */ +#define SJA_RXERR 14/* Receive error counter */ +#define SJA_TXERR 15/* Transmit error counter */ +#define SJA_CDR 31/* Clock divider register */ + +/* reset mode */ +#define SJA_ACR0 16/* Acceptance code register 0 */ +#define SJA_ACR1 17/* Acceptance code register 1 */ +#define SJA_ACR2 18/* Acceptance code register 2 */ +#define SJA_ACR3 19/* Acceptance code register 3 */ +#define SJA_AMR0 20/* Acceptance mask register 0 */ +#define SJA_AMR1 21/* Acceptance mask register 1 */ +#define SJA_AMR2 22/* Acceptance mask register 2 */ +#define SJA_AMR3 23/* Acceptance mask register 3 */ + +/* operating mode */ +#define SJA_FIR 16/* Frame information register */ +#define SJA_ID1 17/* Identifier 1 */ +#define SJA_ID2 18/* Identifier 2 */ +#define SJA_ID3 19/* Identifier 3 (EFF only) */ +#define SJA_ID4 20/* Identifier 4 (EFF only) */ + +#define SJA_DATA_SFF (x) (19 + (x))/* Data registers in case of standard +* frame format; 0 <= x <= 7 */ +#define SJA_DATA_EFF (x) (21 + (x))/* Data registers in case of extended +* frame format; 0 <= x <= 7 */ +/* Mode register */ +#define SJA_MOD_RM (1<<0)/* Reset Mode */ +#define SJA_MOD_LOM (1<<1)/* Listen Only Mode */ +#define SJA_MOD_STM (1<<2)/* Self Test Mode */ +#define SJA_MOD_AFM (1<<3)/* Acceptance Filter Mode */ +#define SJA_MOD_SM (1<<4)/* Sleep Mode */ + +/* Command register */ +#define SJA_CMR_TR (1<<0)/* Transmission request */ +#define SJA_CMR_AT (1<<1)/* Abort Transmission */ +#define SJA_CMR_RRB (1<<2)/* Release Receive Buffer */ +#define SJA_CMR_CDO (1<<3)/* Clear Data Overrun */ +#define SJA_CMR_SRR (1<<4)/* Self reception request */ + +/* Status register */ +#define SJA_SR_RBS (1<<0)/* Receive Buffer Status */ +#define SJA_SR_DOS (1<<1)/* Data Overrun Status */ +#define SJA_SR_TBS (1<<2)/* Transmit Buffer Status */ +#define SJA_SR_TCS (1<<3)/* Transmission Complete Status */ +#define SJA_SR_RS (1<<4)/* Receive Status */ +#define SJA_SR_TS (1<<5)/* Transmit Status */ +#define SJA_SR_ES (1<<6)/* Error Status */ +#define SJA_SR_BS (1<<7)/* Bus Status */ + +/* Interrupt register */ +#define SJA_IR_RI (1<<0)/* Receive Interrupt */ +#define SJA_IR_TI (1<<1)/* Transmit Interrupt */ +#define SJA_IR_EI (1<<2)/* Error Warning Interrupt */ +#define SJA_IR_DOI (1<<3)/* Data Overrun Interrupt */ +#define SJA_IR_WUI (1<<4)/* Wake-Up Interrupt */ +#define SJA_IR_EPI (1<<5)/* Error Passive Interrupt */ +#define SJA_IR_ALI (1<<6)/* Arbitration Lost Interrupt */ +#define SJA_IR_BEI (1<<7)/* Bus Error Interrupt */ + +/* Interrupt enable register */ +#define SJA_IER_RIE (1<<0)/* Receive Interrupt Enable */ +#define SJA_IER_TIE (1<<1)/* Transmit Interrupt Enable */ +#define SJA_IER_EIE (1<<2)/* Error Warning Interrupt Enable */ +#define SJA_IER_DOIE (1<<3)/* Data Overrun Interrupt Enable */ +#define SJA_IER_WUIE (1<<4)/* Wake-Up Interrupt Enable */ +#define SJA_IER_EPIE (1<<5)/* Error Passive Interrupt Enable */ +#define SJA_IER_ALIE (1<<6)/* Arbitration Lost Interrupt Enable */ +#define SJA_IER_BEIE (1<<7)/* Bus Error Interrupt Enable */ + +/* Output control register */ +#define SJA_OCR_MODE_BIPHASE 0 +#define SJA_OCR_MODE_TEST 1 +#define SJA_OCR_MODE_NORMAL 2 +#define SJA_OCR_MODE_CLOCK 3 +#define SJA_OCR_TX0_INVERT (1<<2) +#define SJA_OCR_TX0_PULLDOWN (1<<3) +#define SJA_OCR_TX0_PULLUP (2<<3) +#define SJA_OCR_TX0_PUSHPULL (3<<3) +#define SJA_OCR_TX1_INVERT (1<<5) +#define SJA_OCR_TX1_PULLDOWN (1<<6) +#define SJA_OCR_TX1_PULLUP (2<<6) +#define SJA_OCR_TX1_PUSHPULL (3<<6) + +/* Error code capture register */ + +/* +* The segmentation field gives information about the location of +* errors on the bus +*/ +#define SJA_ECC_SEG_MASK 31/* Segmentation field mask */ +#define SJA_ECC_DIR (1<<5)/* Transfer direction */ +#define SJA_ECC_ERR_BIT (0<<6) +#define SJA_ECC_ERR_FORM (1<<6) +#define SJA_ECC_ERR_STUFF (2<<6) +#define SJA_ECC_ERR_MASK (3<<6)/* Error code mask */ + +/* Frame information register */ +#define SJA_FIR_DLC_MASK 15/* Data length code mask */ +#define SJA_FIR_RTR (1<<6)/* Remote transmission request */ +#define SJA_FIR_EFF (1<<7)/* Extended frame format */ + +/* Clock divider register */ +#define SJA_CDR_CLK_OFF (1<<3)/* Clock off (CLKOUT pin) */ +#define SJA_CDR_CBP (1<<6)/* CAN input comparator bypass */ +#define SJA_CDR_CAN_MODE (1<<7)/* CAN mode: 1 = PeliCAN */ + +#define SJA1000_SIZE 0x80 + +void sja1000_register (struct can_dev *dev,unsigned long base); + +#endif /* __SJA1000_H__ */ +
Signature · 13 lines
------------------------------------------------------------------------- Dipl.-Ing. Matthias Fuchs Head of System Design esd electronic system design gmbh Vahrenwalder Str. 207 - 30165 Hannover - GERMANY Phone: +49-511-37298-0 - Fax: +49-511-37298-68 Please visit our homepage http://www.esd.eu Quality Products - Made in Germany ------------------------------------------------------------------------- Gesch?ftsf?hrer: Klaus Detering, Dr. Werner Schulze Amtsgericht Hannover HRB 51373 - VAT-ID DE 115672832 -------------------------------------------------------------------------
RFC 3/5 CAN device driver for the SJA1000
Quoted 6 lines · Matthias Fuchs
Hi Wolfgang,
this patch conflicts with my simple SJA header posted some days ago
http://lists.denx.de/pipermail/u-boot/2009-October/063097.html
Quoted 7 lines
together with a fix for two of our boards - which has not much to do with CAN. WD asked me to use a C struct to access the SJA1000.
http://lists.denx.de/pipermail/u-boot/2009-October/062902.html
So where does this bring us? Either we want to use C structs for everything or decide it from patch to patch :-(
Then it should be changed, of course. This patch is far from being accepted and for the moment it's an implementation detail. I'm especially interested to hear if such a generic CAN interface would serve your purposes as well, as you require access to the SJA1000 somehow.
Wolfgang.
RFC 3/5 CAN device driver for the SJA1000
Hi Wolfgang,
of course I can think of situations where some simple CAN mechanism might be helpful (e.g. simple hardware testing).
But do we really need this inside a bootloader? Surely not for a production build. But please keep on hacking!
Quoted 12 lines · Wolfgang Grandegger
Quoted 11 lines · Matthias Fuchs
Hi Wolfgang,
this patch conflicts with my simple SJA header posted some days ago
http://lists.denx.de/pipermail/u-boot/2009-October/063097.html
together with a fix for two of our boards - which has not much to do with CAN. WD asked me to use a C struct to access the SJA1000.
http://lists.denx.de/pipermail/u-boot/2009-October/062902.html
Quoted 7 lines
Quoted 2 lines
So where does this bring us? Either we want to use C structs for everything or decide it from patch to patch :-(
Then it should be changed, of course. This patch is far from being accepted and for the moment it's an implementation detail. I'm especially interested to hear if such a generic CAN interface would serve your purposes as well, as you require access to the SJA1000 somehow.
I just need to bit bang around in the OCR register. So no need for a full blown and flash consuming CAN implementation. Of course I could life with your register access style. Especially because it makes the code more common with Socket-CAN files which prevents us from rewriting fully functional code ;-)
Matthias
RFC 3/5 CAN device driver for the SJA1000
Quoted 28 lines · Matthias Fuchs
Hi Wolfgang,
of course I can think of situations where some simple CAN mechanism might be helpful (e.g. simple hardware testing).
But do we really need this inside a bootloader? Surely not for a production build. But please keep on hacking!
Quoted 10 lines · Wolfgang Grandegger
Quoted 9 lines · Matthias Fuchs
Hi Wolfgang,
this patch conflicts with my simple SJA header posted some days ago
http://lists.denx.de/pipermail/u-boot/2009-October/063097.html
together with a fix for two of our boards - which has not much to do with CAN. WD asked me to use a C struct to access the SJA1000.
Quoted 8 lines
Quoted 4 lines
http://lists.denx.de/pipermail/u-boot/2009-October/062902.html
So where does this bring us? Either we want to use C structs for everything or decide it from patch to patch :-(
Then it should be changed, of course. This patch is far from being accepted and for the moment it's an implementation detail. I'm especially interested to hear if such a generic CAN interface would serve your purposes as well, as you require access to the SJA1000 somehow.
Quoted 4 lines
I just need to bit bang around in the OCR register. So no need for a full blown and flash consuming CAN implementation. Of course I could life with your register access style. Especially because it makes the code more common with Socket-CAN files which prevents us from rewriting fully functional code ;-)
Well, I think Wolfgang will tell me to use structs sooner than later.
Wolfgang.
RFC 3/5 CAN device driver for the SJA1000
Dear Wolfgang Grandegger,
Quoted 2 lines · In message <[email protected]> you wrote:
Well, I think Wolfgang will tell me to use structs sooner than later.
Why should I? You already know it!
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "There is no statute of limitations on stupidity." - Randomly produced by a computer program called Markov3.
RFC 2/5 CAN device test command
In reply to Wolfgang Grandeggercommon/cmd_can.c line 104
Quoted 5 lines · On Sunday 01 November 2009 06:33:34 Wolfgang Grandegger wrote:
common/cmd_can.c new file +5
-0+if (op =='s' ) { + else if (op == 'i') { + else if (op == 'r') { + } else if (op == 'x') { + } else {
your if style here is inconsistent, but ignoring that, shouldnt this really be a switch() ? although, by only checking the first char, you allow people to encode typos into their commands and not realize it until some point in the future where things get stricter. i.e. people can do can ilovecandy ...
Quoted 4 lines
common/cmd_can.c new file +4
-0+unsigned int dev_num =0 , ibaud =0 ; +struct can_dev *dev; + +if (argc >2 )
common/cmd_can.c line 72
Quoted 10 lines
common/cmd_can.c new file +10
-0+ dev_num =simple_strtoul (argv[2 ],NULL ,10 ); +if (argc >3 ) { + ibaud =simple_strtoul (argv[3 ],NULL ,10 ); +if (ibaud >2 ) + ibaud =2 ; + } + dev =can_init (dev_num, ibaud); +if (!dev) +return 1 ; + can_dev = dev;
if i told CAN to init an unknown device, i would expect to get an error and the command state to remain in said error state until i selected a proper CAN device. otherwise, a script that didnt check the can init status would incorrectly operate on the previously selected can device.
how do other commands work ? am i complaining about common convention here ?
common/cmd_can.c line 105
Quoted 1 line
common/cmd_can.c new file +1
-0+printf ("Usage:\n%s\n" , cmdtp->usage);
cmd_usage() ?
common/cmd_can.c line 118
Quoted 6 lines
common/cmd_can.c new file +6
-0+ can,3 ,1 , do_can, +"can - CAN bus commands\n" , +"can status [level]\n" +"can init [dev] [baud-index]\n" +"can xmit [id] [d0] [d1] ... [d7]\n" +"can recv, abort with CTRL-C\n"
does the help really display correctly here ? i think the "can status" line will have too many "can"'s ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20091101/7d9b8d17/attachment.pgp
RFC 2/5 CAN device test command
Quoted 11 lines · Mike Frysinger
common/cmd_can.c line 104
Quoted 5 lines · On Sunday 01 November 2009 06:33:34 Wolfgang Grandegger wrote:
common/cmd_can.c new file +5
-0+if (op =='s' ) { + else if (op == 'i') { + else if (op == 'r') { + } else if (op == 'x') { + } else {your if style here is inconsistent, but ignoring that, shouldnt this really be a
switch()? although, by only checking the first char, you allow people to encode typos into their commands and not realize it until some point in the future where things get stricter. i.e. people can docan ilovecandy ...
Will fix.
Quoted 11 lines
Quoted 11 lines
common/cmd_can.c new file +11
-0+unsigned int dev_num =0 , ibaud =0 ; +struct can_dev *dev; + +if (argc >2 ) + dev_num =simple_strtoul (argv[2 ],NULL ,10 ); +if (argc >3 ) { + ibaud =simple_strtoul (argv[3 ],NULL ,10 ); +if (ibaud >2 ) + ibaud =2 ; + } + dev =can_init (dev_num, ibaud);
Quoted 8 lines
common/cmd_can.c line 72
Quoted 3 lines
common/cmd_can.c new file +3
-0+if (!dev) +return 1 ; + can_dev = dev;if i told CAN to init an unknown device, i would expect to get an error and the command state to remain in said error state until i selected a proper CAN device. otherwise, a script that didnt check the can init status would incorrectly operate on the previously selected can device.
can_init will already print an error message. But that might be changed.
Quoted 5 lines
how do other commands work ? am i complaining about common convention here ?
common/cmd_can.c line 105
Quoted 1 line
common/cmd_can.c new file +1
-0+printf ("Usage:\n%s\n" , cmdtp->usage);
cmd_usage()?
OK.
Quoted 9 lines
common/cmd_can.c line 118
Quoted 6 lines
common/cmd_can.c new file +6
-0+ can,3 ,1 , do_can, +"can - CAN bus commands\n" , +"can status [level]\n" +"can init [dev] [baud-index]\n" +"can xmit [id] [d0] [d1] ... [d7]\n" +"can recv, abort with CTRL-C\n" does the help really display correctly here ? i think the "can status" line will have too many "can"'s ?
I think the output was OK. But I will check later next week.
Note that this is a RFC trying to discuss the real requirements of a CAN interface in U-Boot. I think it would also be nice to have can_xmit() and can_recv() with a timeout parameter, e.g.:
can_xmit(struct can_dev *dev, int timeout_us);
And maybe also a can_xmit_done() function.
Wolfgang.
RFC 2/5 CAN device test command
Quoted 7 lines · On Sunday 01 November 2009 11:24:59 Wolfgang Grandegger wrote:
Note that this is a RFC trying to discuss the real requirements of a CAN interface in U-Boot. I think it would also be nice to have
can_xmit()andcan_recv()with a timeout parameter, e.g.:can_xmit(struct can_dev *dev, int timeout_us);And maybe also a
can_xmit_done()function.
i only have a passing familiarity with CAN (havent done real work with it), but i can find someone to look over the current stuff
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20091101/b78a8ed4/attachment.pgp
RFC 1/5 CAN interface library
In reply to Wolfgang GrandeggerMakefile LIBS += net/libnet.a · line 206
Quoted 7 lines · On Sunday 01 November 2009 06:33:33 Wolfgang Grandegger wrote:
Makefile +1
-0@@ -203,6 +203,7 @@ LIBS += net/libnet.a LIBS += disk/libdisk.a LIBS += drivers/bios_emulator/libatibiosemu.a LIBS += drivers/block/libblock.a +LIBS += drivers/can/libcan.a
this isnt an issue specific to CAN, but i wonder if we should switch LIBS to LIBS-y now that the top level Makefile can rely on autoconf.mk settings after the point config.mk is included. it would save time on pointlessly recursing into all the empty dirs and creating empty archives.
Quoted 17 lines
drivers/can/Makefile new file +14
-0@@ -0,0 +1,47 @@ +include $(TOPDIR)/config.mk + +LIB := $(obj)libcan.a + +COBJS-$(CONFIG_CAN) += can.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS)
drivers/can/Makefile line 24
Quoted 10 lines
drivers/can/Makefile new file +10
-0+ + +##################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +####################################################
also not specific to CAN, but i think it's time we start creating .mk files for subdirs to include
drivers/can/can.c
Quoted 4 lines
drivers/can/can.c new file +1
-0+static char *baudrates[] = {"125K" ,"250K" ,"500K" };
so we're restricting ourselves to these three speeds ? i have passing familiarity with CAN, but i didnt think the protocol was restricted to specific speeds.
Quoted 1 line
+int
can_register(struct can_dev*can_dev)
no space before the paren, and the * is cuddled on the wrong side of the space. seems like a lot of this code suffers from these two issues.
drivers/can/can.c line 45
Quoted 11 lines
drivers/can/can.c new file +11
-0+{ +struct can_dev * dev; + + can_dev->next =NULL ; +if (!can_devs) + can_devs = can_dev; +else { +for (dev = can_devs; dev->next; dev = dev->next) + ; + dev->next = can_dev; + }
invert the if logic and i think the code would look "nicer" -- use braces on the first branch instead of the second.
Quoted 18 lines
drivers/can/can.c new file +18
-0+struct can_dev *can_init (int dev_num,int ibaud) +{ +struct can_dev *dev; +int i; + +if (!can_devs) { +puts ("No CAN devices registered\n" ); +return NULL ; + } + +/* Advance to selected device */ +for (i =0 , dev = can_devs; dev; i++, dev = dev->next) { +if (i == dev_num) +break ; + } + +if (!dev) { +printf ("CAN device %d does not exist\n" , dev_num);
drivers/can/can.c line 79
Quoted 10 lines
drivers/can/can.c new file +10
-0+return NULL ; + } + +printf ("Initializing CAN%d at 0x%08x with baudrate %s\n" , + i, dev->base, baudrates[ibaud]); + + dev->init (dev, ibaud); + +return dev; +}
wonder if we should have a generic device list code base since this looks similar to a lot of other u-boot device lists ...
include/can.h line 2
Quoted 5 lines
include/can.h new file +2
-0@@ -0,0 +1,70 @@ +/* +* (C) Copyright 2007-2009, Wolfgang Grandegger <[email protected]>
have you really been working on this stuff since 2007 ?
include/can.h line 42
Quoted 2 lines
include/can.h new file +2
-0+struct can_dev { +char *name;
const ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20091101/747d1ff9/attachment.pgp
RFC 1/5 CAN interface library
Quoted 1 line · Mike Frysinger
On Sunday 01 November 2009 06:33:33 Wolfgang Grandegger wrote:
[snip]
Quoted 8 lines
drivers/can/can.c
Quoted 4 lines
drivers/can/can.c new file +1
-0+static char *baudrates[] = {"125K" ,"250K" ,"500K" };so we're restricting ourselves to these three speeds ? i have passing familiarity with CAN, but i didnt think the protocol was restricted to specific speeds.
Well, this is an RFC and as I wrote in the introduction some features need to be added or extended, especially for CAN device configuration. My idea is to have a more complete default bit-timing table, which board specific code may overwrite using, for example:
sja1000_register(&my_sja1000, &my_config_opts);
This would also allow to set the CAN clock, cdr and ocr registers.
Quoted 4 lines
Quoted 1 line
+int
can_register(struct can_dev*can_dev)no space before the paren, and the * is cuddled on the wrong side of the space. seems like a lot of this code suffers from these two issues.
U-Boot coding style requires a space after the function name and before "(". But the "*" is misplaced, of course.
Quoted 6 lines
Quoted 6 lines
drivers/can/can.c new file +6
-0+{ +struct can_dev * dev; + + can_dev->next =NULL ; +if (!can_devs) + can_devs = can_dev;
Quoted 8 lines
drivers/can/can.c line 45
Quoted 5 lines
drivers/can/can.c new file +5
-0+else { +for (dev = can_devs; dev->next; dev = dev->next) + ; + dev->next = can_dev; + }invert the if logic and i think the code would look "nicer" -- use braces on the first branch instead of the second.
OK.
Quoted 23 lines
Quoted 23 lines
drivers/can/can.c new file +23
-0+struct can_dev *can_init (int dev_num,int ibaud) +{ +struct can_dev *dev; +int i; + +if (!can_devs) { +puts ("No CAN devices registered\n" ); +return NULL ; + } + +/* Advance to selected device */ +for (i =0 , dev = can_devs; dev; i++, dev = dev->next) { +if (i == dev_num) +break ; + } + +if (!dev) { +printf ("CAN device %d does not exist\n" , dev_num); +return NULL ; + } + +printf ("Initializing CAN%d at 0x%08x with baudrate %s\n" , + i, dev->base, baudrates[ibaud]);
Quoted 8 lines
drivers/can/can.c line 79
Quoted 5 lines
drivers/can/can.c new file +5
-0+ + dev->init (dev, ibaud); + +return dev; +}wonder if we should have a generic device list code base since this looks similar to a lot of other u-boot device lists ...
Do we already have a generic interface?
Quoted 7 lines
include/can.h line 2
Quoted 5 lines
include/can.h new file +2
-0@@ -0,0 +1,70 @@ +/* +* (C) Copyright 2007-2009, Wolfgang Grandegger <[email protected]> have you really been working on this stuff since 2007 ?
The code was written in 2007. "2007, 2009" is more appropriate.
Quoted 4 lines
include/can.h line 42
Quoted 2 lines
include/can.h new file +2
-0+struct can_dev { +char *name;const ?
OK.
Wolfgang.
RFC 1/5 CAN interface library
Quoted 11 lines · On Sunday 01 November 2009 11:16:59 Wolfgang Grandegger wrote:
Quoted 9 lines · Mike Frysinger
drivers/can/can.c
Quoted 4 lines · On Sunday 01 November 2009 06:33:33 Wolfgang Grandegger wrote:
drivers/can/can.c new file +1
-0+static char *baudrates[] = {"125K" ,"250K" ,"500K" };so we're restricting ourselves to these three speeds ? i have passing familiarity with CAN, but i didnt think the protocol was restricted to specific speeds.
Quoted 8 lines
Well, this is an RFC and as I wrote in the introduction some features need to be added or extended, especially for CAN device configuration. My idea is to have a more complete default bit-timing table, which board specific code may overwrite using, for example:
sja1000_register(&my_sja1000, &my_config_opts);This would also allow to set the CAN clock, cdr and ocr registers.
this makes sense if the device supports a limited number of baud rates. but what if the baud rate is arbitrary (between two limits) ?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+int
can_register(struct can_dev*can_dev)no space before the paren, and the * is cuddled on the wrong side of the space. seems like a lot of this code suffers from these two issues.
U-Boot coding style requires a space after the function name and before "(". But the "*" is misplaced, of course.
it's (thankfully) been changing to Linux kernel style
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+struct
can_dev*can_init(intdev_num, int ibaud)wonder if we should have a generic device list code base since this looks similar to a lot of other u-boot device lists ...
Do we already have a generic interface?
i dont think so
Quoted 9 lines
Quoted 7 lines
include/can.h line 2
Quoted 5 lines
include/can.h new file +2
-0@@ -0,0 +1,70 @@ +/* +* (C) Copyright 2007-2009, Wolfgang Grandegger <[email protected]> have you really been working on this stuff since 2007 ?
The code was written in 2007. "2007, 2009" is more appropriate.
the intro made it sound like this was a recent development (i.e. last few days/weeks). if code is actually from 2007, then the range is fine.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20091101/6367ebef/attachment.pgp
RFC 1/5 CAN interface library
Quoted 15 lines · Mike Frysinger
Quoted 14 lines · On Sunday 01 November 2009 11:16:59 Wolfgang Grandegger wrote:
Quoted 8 lines · Mike Frysinger
drivers/can/can.c
Quoted 4 lines · On Sunday 01 November 2009 06:33:33 Wolfgang Grandegger wrote:
drivers/can/can.c new file +1
-0+static char *baudrates[] = {"125K" ,"250K" ,"500K" };so we're restricting ourselves to these three speeds ? i have passing familiarity with CAN, but i didnt think the protocol was restricted to specific speeds.
Well, this is an RFC and as I wrote in the introduction some features need to be added or extended, especially for CAN device configuration. My idea is to have a more complete default bit-timing table, which board specific code may overwrite using, for example:
Quoted 6 lines
Quoted 3 lines
sja1000_register(&my_sja1000, &my_config_opts);This would also allow to set the CAN clock, cdr and ocr registers.
this makes sense if the device supports a limited number of baud rates. but what if the baud rate is arbitrary (between two limits) ?
Board specific code can define what ever table it likes, including non-standard bit-rate and bit-timings. Nevertheless, for most CAN controllers the default bit-timing parameters are just fine.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+int
can_register(struct can_dev*can_dev)no space before the paren, and the * is cuddled on the wrong side of the space. seems like a lot of this code suffers from these two issues.
U-Boot coding style requires a space after the function name and before "(". But the "*" is misplaced, of course.
it's (thankfully) been changing to Linux kernel style
I really appreciate that.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
+struct
can_dev*can_init(intdev_num, int ibaud)wonder if we should have a generic device list code base since this looks similar to a lot of other u-boot device lists ...
Do we already have a generic interface?
i dont think so
Nor do I.
Wolfgang.