<div class="gmail_quote">On Fri, Jan 14, 2011 at 11:28 PM, Dave Hylands <span dir="ltr">&lt;<a href="mailto:dhylands@gmail.com">dhylands@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Cheng,<br>
<div><div></div><div class="h5"><br>
On Fri, Jan 14, 2011 at 6:23 AM, cheng chen &lt;<a href="mailto:freakrobot@acm.org">freakrobot@acm.org</a>&gt; wrote:<br>
&gt; I am studying CAN-bus chip Linux driver, MCP251x.c in the kernel source.<br>
&gt; However, I find a little confused about how this driver works, it registers<br>
&gt; itself as a SPI slave device using the structure<br>
&gt; struct spi_driver  mcp2510_can_driver = {<br>
&gt;     .driver = {...}<br>
&gt;     .probe=<br>
&gt;     ...<br>
&gt; }<br>
&gt; In probe function, it registers itself as a &quot;net_device&quot; with<br>
&gt; &quot;mcp251x_netdev_ops&quot;. So I am not sure how this system works.<br>
&gt; I know that the userspace must see it as a network driver. But can userspace<br>
&gt; really see this driver? Or what it can see is the module &quot;can.ko&quot; -- the<br>
&gt; protocol stack ?<br>
&gt; Does the network stack talks to SPI and SPI talks to mcp2510 chip and<br>
&gt; transmit messages can-bus? Or something else?<br>
<br>
</div></div>I haven&#39;t looked at the code but I have looked at the chip, and I&#39;ve<br>
been sort of following along on the Socket-CAN list.<br>
<a href="https://lists.berlios.de/mailman/listinfo/socketcan-users" target="_blank">https://lists.berlios.de/mailman/listinfo/socketcan-users</a><br>
<br>
It would register itself with the network stack, and the network stack<br>
will expect to send and receive packets. The CAN driver then needs to<br>
send these packets to the chip over a SPI bus. So it uses the SPI<br>
infrastructure to send these packets to the actual MCP2510.<br>
<br>
Every system has different SPI devices, so this way, the MCP2510<br>
driver doesn&#39;t have to know how the actual SPI layer works, it just<br>
knows it needs to use the SPI protocol to talk to the MCP2510.<br>
<br>
>From userspace, you would use the socket API to send you data to<br>
whatever device you&#39;re communicating with via CAN.<br>
<br>
So the whole thing should go together something like this:<br>
<br>
user space talks to socket API<br>
network driver talks to CAN driver<br>
CAN driver talks to SPI driver<br>
SPI driver talks to SPI hardware<br>
messages go over the SPI bus to MCP2510<br>
MCP2510 sends messages over the CAN bus to the actual device<br>
<font color="#888888"><br>
Dave Hylands<br>
</font></blockquote></div><br><meta http-equiv="content-type" content="text/html; charset=utf-8">Thanks for your help, I understand the frameworks now.<br><div>But if I want to make the CAN driver(mcp251x.c) works on my own embedded board, should do some work to make the SPI fit my hardware?<br clear="all">
<br>-- <br>Cheng(誠)<br><br>Fedora Project Contributor -- Ambassador<br><div><a href="https://fedoraproject.org/wiki/User:Freakrobot" target="_blank">https://fedoraproject.org/wiki/User:Freakrobot</a></div><div>_______________________________________________</div>
<div><br></div><div>My Page: <a href="http://freakrobot.blogbus.com/" target="_blank">http://freakrobot.blogbus.com/</a></div><br>
</div>