On 03/14/2011 03:06 PM, Jorge Fernandez Monteagudo wrote:
> 
> 
>> -----Mensaje original-----
>> De: Wolfgang Grandegger [mailto:[email protected]]
>> Enviado el: Monday, March 14, 2011 2:51 PM
>> Para: Jorge Fernandez Monteagudo
>> CC: [email protected]
>> Asunto: Re: [Socketcan-users] Setting the clock, ocr and cdr values
>>
>> On 03/14/2011 02:37 PM, Jorge Fernandez Monteagudo wrote:
>>>> -----Mensaje original-----
>>>> De: Wolfgang Grandegger [mailto:[email protected]]
>>>> Enviado el: Monday, March 14, 2011 1:06 PM
>>>> Para: Jorge Fernandez Monteagudo
>>>> CC: [email protected]
>>>> Asunto: Re: [Socketcan-users] Setting the clock, ocr and cdr values
>>>>
>>>> On 03/14/2011 11:42 AM, Jorge Fernandez Monteagudo wrote:
>>>>> Hi,
>>>>>
>>>>> I'm trying to implement my can infrastructure with socketcan. I
>> would
>>>> like to know where to find
>>>>> information about the values from sja1000_priv struct, the
>>>> can.clock.freq, ocr and cdr.
>>>>
>>>> Not sure what you are looking for. The meaning of theses values is
>>>> described in the SJA1000 datasheet.
>>>>
>>>
>>> Well, I'm trying to setup the sja1000 chip using the socketcan
>> architecture.
>>> In my old code I had the registers CDR, BTR0, BTR1, OCR, CMR and IER
>>> loaded with some values in order to set the pelican mode with 1Mbps
>>> and let the chip ready to serve interruptions. Now I'm trying to
>> replicate
>>> this in a modified version of the plx_pci.c but I've seen that the
>> only
>>> register used are from the sja1000_priv struct.
>>
>> You need to provide proper cdr, ocr and the CAN clock sources
>> frequency.
>> See also:
>>
>> http://lxr.linux.no/#linux+v2.6.37.3/drivers/net/can/sja1000/sja1000.c#
>> L242
>>
>> The rest is handled by the SJA1000 driver.
>>
> 
> Oh yes, I see where this sja1000_priv struct fields are used!
> 
>>From the 'static int sja1000_set_bittiming(struct net_device *dev)' method
> there is some way to set manually the btr0 and btr1 values? In my code I set
> 
> BTR0 <- 0x01
> BTR1 <- 0x10
> 
> to set the 1000 Kbs.

You can use the methods described in

http://lxr.linux.no/#linux+v2.6.37.3/Documentation/networking/can.txt#L635

to set the bit-timing parameters. You cannot set btr0/1 directly. Make
sure you define a proper CAN clock source frequency. The BTR0/1 values
above indicate that it's not 8 MHz.

>>>>> I'm following the plx_pci.c code but in my driver I setup these
>>>> register in a different way.
>>>>> First, I set the CDR <- 0xC0, then I set the clock using the BTR0
>> and
>>>> BTR1 registers to set the 1Mbps
>>>>> baudrate, BTR0 <- 0x01, BTR1 <- 0x10 and finally the OCR register
>> is
>>>> initialized with OCR <- 0x1A.
>>>>
>>>> The input clock frequency, cdr and ocr must be defined by the
>> SJA1000
>>>> driver, e.g.:
>>>>
>>>>
>> http://lxr.linux.no/#linux+v2.6.37.3/drivers/net/can/sja1000/plx_pci.c#
>>>> L526
>>>>
>>>> Some drivers allow to set these values via module parameter. So,
>>>> depending on the driver appropriate for your CAN hardware, you need
>> to
>>>> adjust them. The bit-timing have to be defined via netlink interface
>> as
>>>> described here:
>>>>
>>>>
>> http://lxr.linux.no/#linux+v2.6.37.3/Documentation/networking/can.txt#L
>>>> 635
>>>>
>>>
>>> Thanks for the info, now I get an error in dmesg: "bit-timing not yet
>> defined"
>>> then I suppose I'll need to follow this last link.
>>
>> Yes, you need to set the bit-timing before you can start the device.
>>
> 
> 
> Where I can found the iproute2 utility suite? I have debian 5.0.7, but
> the command
> 
> # ip link set can0 type can help
> 
> don't print any bitrate or tq option...
> 
> # ip -V
> ip utility, iproute2-ss080725

You need a recent version of the IPROUTE2 utility suite, which you can
get from:

http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2

Wolfgang.
_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to