 Hi, good morning all. I am Vivek Yadav working at SEMS and semiconductor India R&D. Hi, good morning all. I am Vivek Yadav working at SEMS and semiconductor India R&D. Let's begin. I welcome you all to the presentation on CAN, deep dive into board rate and error handling model. This presentation provides a great introduction to the fundamentals of CAN, Controller Area Network. I will be touching all the important topics required by a programmer to understand the CAN protocol as we know it is used in industrial automation controls and many more applications. Let's begin and move on to the next slide. So these are the topics we are going to cover in this presentation. We will be covering the basic introduction of the CAN protocol and its features and bus details and we will talk about the real-time application in the automotive and the aerospace industry. And we will go through the Linux CAN subsystem includes protocol configuration with timing and message frame. In the end, we will discuss about the error handling model and gives the basic idea about the user space tools with the applications. And let's move on to the next slide and start with the introduction of the CAN protocol. So CAN is short for a Controller Area Network. It is an electronic communication bus defined by the ISO 898 standard. Basically, the standard defines how communication happens, how the wiring is configured and how messages are constructed. Let's talk about the CAN bus here. CAN bus is a two-wire serial differential bus over which all the devices connected via trans receiver. And in the given diagram, we can notice we have a CAN bus with the two-wire serial differential bus. One is CAN H and the CAN LOW that is CAN HIGH and CAN LOW and the nodes are connected via trans receiver to the bus. So it is a dot-cast type of bus. Dot-cast refers here transmitting a packet on the bus and that will be received by every CAN device into the network. That means all the nodes can hear all the transmission. When we say node in this presentation, that means CAN device and CAN node or we can say CAN node. To understand more about the broadcast here, let's take an example of a very common example of a communication. We have multiple CAN devices over to the bus. And suppose one of the nodes dot-cast the message on the bus and then all the CAN devices will invariably pick all the messages frame. And like every node on the bus captures all the traffic of the CAN bus. Now here the question came like how do we differentiate the message belongs to a particular node or node. So here comes the feature of a CAN protocol called CAN filters. The CAN hardware provides local filtering so that interesting CAN node device reacts only on the intended messages only. Let me explain about the little bit about the filters in depth. CAN hardware have a number of filter registers. Those filter registers are configured during the CAN initialization with a predefined identifier called message IDs. And when the node receives any message frame, then CAN nodes search the receiver message identifier or called ID in the predefined filter register configuration. And if the ID matches the filter configuration or the ID configured in the filters, then the message will be stored in the FIFO and the receiver buffer and go to the application layer. And if that doesn't match with the filters, then it will be discarded. So as we will discuss this identifier term in the later slide. And now as we have discussed CAN message is a message-based protocol. Let me tell you the difference between the address-based protocol and the message-based protocol in short. In an address-based message protocol, the data packet or the frames contains the address of the device for which message is intended. And in a message-based protocol, a free message is identified a predefined ID. In case of CAN frame, we can say called identifier rather than an address. And CAN bus supports a bitwise arbitration to control the arbitration or it's like a CSMA supports a CSMA career sense mode action. And let's move on to the next slide. So here are the some of the features of the CAN that's why CAN is widely used because of its manufacturer. It offers excellent error detection and error handling mechanism which provides a highly reliable transmission. And it is very flexible because hundreds of phone CAN nodes can be easily connected or disconnected at a time and it supports multi-master communication. So every node on the bus can access the bus anytime and supports a broadcast-based message communication. So broadcast I have already explained that means like a node can communicate to the single node or the multiple node or can send the message to all the nodes connected over the bus. And it is very reliable like we can say very low cost effective because we are having only two wires to communicate between hundreds of CAN devices. So it is very cost effective as compared to the other networks called like those use point to point communication between two nodes only. So that's it and we will go further. So let me go through the bus details. CAN supports two standards ISO 118983 and ISO 118982. Both the bus have different features. One supports the fault tolerance and other supports the speed. Maximum speed can be achieved according to that standard is 1 mbps but some of the CAN controllers supports higher speed are 5 mbps on CAN FT. CAN FT was developed by the Porsche that is for flexible data and that like actually what is CAN FT and why it is developed I will tell you. CAN FT is a flexible data bit rate and because it supports 64 bytes of data and we can change the board rate during the transmission of the data. So it is like flexible data bit rate. So now let me move. Speed is inversely proportional to the length of the bus or the propagation delay and we can see here 1 mbps can be achieved at a 40 meter length and this is because the arbitration scheme requires the signal must be able to propagate at the most remote node back again before it is sampled. And the last thing is bus should be terminated by the 120 ohm register. The termination register serves two purposes here. Remove the signal reflections at the end of the bus and ensures that first gets connected correct DC levels. So and some of the examples we have given as the speed varies with the length of the CAN bus. We can see okay 6 kilometer of distance we are having 10 mbps and 125 kbps for 500 meter and 100 meters we can support up to 500 kbps. Let me move on to the next slide. So CAN is widely used in today's world almost in all the industry while known in the automotive aviation, building automation, medical equipment, marine automation and navigation. I think it has a vast use in the current industry. So let me move on to the next slide. CAN in automotive and aerospace industry. First to understand the CAN in the automotive industry, first let's talk about the history of the CAN. Almost every vehicle contains a number of electronic devices that shares information with one another. Let's take an example of automobiles transmission control system in the autonomous car. So what happens it automatically changes vehicles gear in relation to its speed by using data from the engine control unit or the various sensors in the systems. So all the data come at the real time. Before CAN was used in the vehicle each electronic devices was connected to another wire wires or more specifically we can say point to point wiring. This worked effectively enough but then the functions were we can say basic as the time goes and automotive industry advanced. One of the major problem for the automotive was linking the ECUs or off different devices wire point to point wiring because a single car automotive car can have I think 60 to 70 ECUs connected and this is very difficult to manage to buy a wire to wire communication and the major problem was the real time information could be accessed. The CAN protocol was designed to address this problem basically because CAN bus is a serial bus a wire network interface supports real time broadcasting of messages. Here we can refer this picture as point to point connection between devices. So if we can see that engine control power windows power locks airbags all are connected to the dashboard wire point to point connection. So like if I am saying that air conditioner it depends on the temperature sensor from the some other electronic ECU then it has to first send the data to the dashboard then dashboard sends to the data to the air conditioner. So this is not a basic a good way to not a real time communication basically. So let me move on to the next slide. So CAN in automotive industry that is same. Here we will take an example of a CAN bus. So as we can see there is a serial wire CAN bus and active suspension power windows engine control airbags airconditions power locks all the ECUs all the can devices are connected over a single wire. And it like this is a very like at the conclusion we can say here is broadcasting a message to the number of nodes at a real time is greater advantage over point to point communication because it reduces the wire connections and overall complexity of the system. And that is clearly visible here. And it supports the real time data transfer also. So that is the example of the automotive industry. Let's move on to the next slide. So here this is the example of a Linux Kansas subsystem how we are communicating from the application to the driver level and how we are configuring configuring the can't protocol it's about rate and link up and link down. Let's look at on this architecture. So we have a user space application can have the can utils. Okay. And application will communicate with the network layer to the system code interface and network layer uses the socket can which provides socket interface to user space application. Which builds upon the Linux network layer only can network device helps to set up the can network subsystem. It creates the creates and set up the link and calculate the board rate configuration for the can and do the bit timing list calculations. After this can net device interact with the can subsystem. Here we can see and with a platform driver and the can driver. So do the can frame configuration and do the all the transmit and receive operations with the hardware and with the external devices can devices. So this is all about the can architecture and we can have a Linux can subsystem that move on to the next slide. So now we have taken an example here from the Bosch can and can actually that is a real this is the can device node. So that given example I have already told this is a Bosch and can device node example. Okay. First parameter here is compatible and this refers the owner and the driver name and the second property is a range range names. So this defines the register and the message RAM base that is with the proper site and the third is the interrupts. What all are the interrupts we are using and the interrupt numbers and they are two clocks we are using here. One is H clock that is can be high clock and one is C clock. Okay. And these are the peripheral clock will be used to configure the board rate configuration for the can protocol. Second last is Bosch and RAM configuration CFG. So this is important to understand here for the like because we can see message RAM configuration data is multiple and can instances can share the message RAM and each element number in message RAM is also configured. So this property is telling how the shared or the private message RAM are used by the and can controllers like I am like if you see the parameters of the message RAM configuration are 128 64 64. So these are the like sizes of the allocation of a memory for the transmitter buffers transmitter fee force receiver buffers receiver fee force and the filters. So we have to we have to create a buffer size into the message RAM to make the transmission and the reception possible to save the messages from the actual hardware purpose to the message. So at the last parameter is the can transfer receiver and can and we are setting a maximum of 500. So can will be configured with the 500k board rate. So let's move on to the next slide. Okay. Here we'll go through the can be timing configuration. It is a very important topic in can configuration. Let's understand the basic need of can be timing. Every if you see every connectivity protocol at the UI you are to see all has to be configured with some board rate. But there is a way to configure the board rate here in can protocol if you want to configure the board rate configuration. So you have to do the bit timing register configuration for that. So like a bit is divided or divided into multiple segments. First is a synchronization segment. Second is a propagation. Third is a face segment. Fourth one is a face segment. So these are all the segments that decides in a single bit and all those four segments you have to configure into the control register of the can protocol to set the board rate. Okay. And as we can see. Okay. Now there are total number of time quantas concepts here. Like let me go through this layout of a layout of a bit. I will explain about what is this thing segment and propagation delay and all those things. So first the synchronization segment which always is one quantum long and is used for the synchronization of the clock. And second one is the propagation delay that depends on the truly cable for the wire we are using and the distance. And the worst case propagation delay is twice between the two pervious node. And a face segment like face segment one and face segment two will be shortened or lantern if necessary to make the flow in the sink. The bus levels are sampled at the border between face segment and face segment two. Let me explain this bit what is actually how to configure the bit rate. So a single bit is called as a nominal can bit time. And if this bit time is divided into as we told the sink propagation plus face segment plus segment two. So this will be the addition of the all the segments. And if you are calculating time for all the time quanta. So you have to calculate that you have to multiply the one time quanta time that is TQ. And that TQ is calculated equals to border rate rescaler plus one multiplication factor into one clock period time of a peripheral clock. That is one divided by clock frequency. And so this will be total number of quanta and in the next slide we will see how to configure the control registers and what is the concept of the synchronization. So this is the clock synchronization means adjusting the phase error in the signal. And we can say the maximum value of the bit time adjustment are termed as synchronization jump. That is called LJW here and this LJW will be configured in the control register of the CAN protocol during the configuration. So there are two types of synchronization here. One is hard synchronization and one is re synchronization. Harder synchronization means that is well known that is performed by the hardware only like it. When it occurs on the recessive to dominant transition of the start way, the bit time is restarted from that edge only. So re synchronization occurs when a bit edge doesn't occur within the synchronization segment in a method that depends on the phase error in the signal. But this LJW what we will configure in the control register will be used to adjust that sync actually. Now we will see how to calculate the board rate and configure the clock register. We need to configure here four segments. One is BRTPS segment 1, P segment 2 and SJW here. So we have taken an example of a board rate 500K and we will be using peripheral clock here. 42 MHz frequency that is a peripheral clock. So number of quantas will be used as equals to 14 in which we have phase segment 1. That is the addition of propagation segment plus phase segment 1 equals to 11. So we will be using segment 2 as a 2. So if you count the total number of segments here, sync plus propagation plus phase segment 1 plus phase segment 2. So it is coming 13 but I have told in the earlier slide that the sync segment will always be 1. So 13 plus 1 equals to 4. So this 14 is the total number of time quantas and we have to calculate first what is the time period of one time quanta. That equals to time quanta equals to BRT plus 1 into one clock period time of a peripheral clock. So when we calculate this, then we will put all these factors in the board rate formula. That is one upon nominal bit time and nominal bit time equals to this BRT into total time quanta. That is 42 MHz by 65 into 14 and we will get the board rate equals to 500K. So this is the board rate configuration for the CAN protocol. So let's move on to the next slide. Linux CAN bit timing structure example. So this structure defines what are all the configuration you will be storing during the programming of a CAN configuration or CAN protocol. First one is the bit rate, what will be the bit rate, what is the sample point of the CAN bit. What will be the time quanta in nanosectin. What is the propagation segment, phase segment 1, phase segment 2. Synchronous jump between time quanta and the last one is the BRT board rate free scalar will be used. Let's move on to the next slide. So as we have discussed in the CAN introduction, CAN is a message based protocol and there are four different messages types. We can say that frame, we have multiple types of frames and these all the frames serves different purposes and for the different user. So let's move on to the type of message frame directly. First one is data frame as name suggests that is used to transmit the data over the bus. Second one is the remote frame here. So remote frame is the remote transmission request to a particular node that is actually a signal. Like I am sending a signal, then a device or a node will respond back to the signal or will be using for other purposes that depends on the application only. So now we have an error frame here. So error frame is actually something like when I am transmitting a message frame and that message frame is corrupted because of some failure happen on to the bus and the receiver on the node, they will actually capture the errors and generate the error frame on to the bus. That will be very helpful for the transmitter to understand actually what happens on to the bus during the transmission of the bus by reading the error flags of the error frames. And accordingly it will take appropriate actions like it will retransmit the message or we can say it will discard the message according to the error flags. It can be errors can be CRC and acknowledgement frame errors that we will discuss in the next slide in the error handling model will be covering all these errors and how to capture all these errors. Let's move on to the next slide here. So let then now we will take the example of can message frame and we will take first as an example can data frame. So that data frame or the frame is divided into actually four segments. The first one is the arbitration field, second is the data field, third is the CRC field and the fourth one is the acknowledgement slot. This arbitration field means what is this actually arbitration field which determines the priority of a message when two or more nodes are contending for the bus. There are multiple nodes on to the bus like hundreds of nodes on the bus and all the nodes are trying to access the bus but this arbitration field decides who will get the bus based on the CRC because it supports the CSM. So according to that you will get the bus and this arbitration contains the field identifier called IDE and let's give you some idea. Can frame is divided into two parts like one is the standard frame that is can 2.0a and other one is can 2.0p that is a 29 bit identifier. Both the message frames are different by only one thing that is called 11 bit identifier is used here and the extended identifier used 29 bit identifier. Other than that all the bits will be same and the control bits or the other bits will be IDE that is called identifier extension. That will tell you it is used to specify the frame format actually standard frame or the extended frame and other thing is the remote RTR bit that is remote transmission request. It defines whether it's a data frame or the remote frame as we have explained that remote frame is just a signal to the destination node or data frame is the we are transmitting a data or the information to the particular node or the bus we can say because it's a broadcast way of communication. So actually we didn't go through the term identifier so based on the identifier only the receiver decides whether a message is relevant to node or not like every message has this identifier. This is a unique number and that unique number is configured during the can initialization in the filter register configuration. And this ID matches and a message can send and the receiver take this ID and compares with the filter if the ID and the filter in the filter this ID matches then the frame will be shifted to the people otherwise it will be discarded that it was the purpose of the identifier here. So let's move on to the data field. Data field is 0 to 8 bytes. The last one is the second last one is the CRC that is cyclic redundancy check contains the checks of application data for error detection that is for the data integrity whether the data is received properly or any corruption happens. Acknowledgement bit is when data is received correctly then this acknowledgement bit will be set that defines that transmission of a frame was successful. Now we will see the different message frames here and I will explain all these frames. So we have a data frame that is having two frame format that is standard camp format and extended camp frame. So that difference is the 11 bit and the 29 bit identifier as we have already discussed and we will see this in the diagram that is 11 bit identifier and that here is the 29 bit identifier for the extended camp. Otherwise all the other control bits and data field and the CRC and the acknowledgement sort all those things will be same for the data frame. So now our second one is the we have a remote frame. So this remote the purpose of the remote frame is to seek permission for the transmission of a data from another node. Actually this remote frame doesn't have a DLC node data length code because the frame is not integrated for the data. So there is no data field here only the signal only the RTR bit is set. So that defines okay I am seeking for some data or I am sending a signal to you. So other than that other fields will be same arbitration or the CRC and that acknowledgement. Then we have an error frame when any node on the canvas received error on the bus it will generate the error frame on the bus to notify all the nodes over the bus that frame was corrupted or there is an error on the bus. It will set some of the error flag that defines what happens actually in the last communication over the bus. So it will immediately or detecting node what happens when a node detects the error frame. So it will immediately abort the transmission and send a frame consistently on the error flag. But and like it will whether it will retransmit the frame or rather it will discard the frame. So let's move on to the next slide. Linux can frame structures so we have taken an example of two can frames one is can frame that is for the can standard and the can extended frame both and one is the can FD can flexible data frame. Let me explain you what is this can FD frame here. The flexible can data was developed by the force to transmit data faster than the one mbps speed. The payload the data field is now up to 64 bytes long. Both the frame structure are similar except the control field that is called flags here. So for for to differentiate between can FD and can standard frame we can set the FD of bit and the bit rates which bit during the communication during the frame communication or during the can in configuration. That's how we differentiate between the flexible data frame and normal standard extended data frames. Other than that we have a same can ID where parameter and the DLC and you can see the data in part of data and ID ID bit and other control paddings are there. So it will be this will be similar only. So let's move on to the next slide. So now we will discuss can error framework in the can protocol and it is a very interesting topping and it that's why can is so famous because of our handling model. This aims here to detect error handle handling aims here to detect error in the messages appearing on to the canvas so that the transmitter and receiver can take appropriate actions based on the error flag and retransmit the message. Error handling is like very important in a we can say in critical task like if I take an example of a automobile vehicle let's suppose and any any car that got any let's take an example of a car if it got hit in the accident. So accident control system sends a signal to the airbags to open the airbag. So suppose that message fails and then current protocol so this message shouldn't be filled because that that message is having the higher priority that should be reached to the destination. So now the error framework comes like can protocol has the capability to capture the errors and we transmit the message again within the microsecond and shows that signals should transmit successfully. So now we will see what happens when error is captured actually. So when the discovering mode will raise error flag then destroying the bus traffic so the nodes will detect the error flag and take appropriate action like discard the message or the retransmit the message. Okay we have a different ways of detecting error here like first one is bus monitoring so what is the meaning of bus monitoring is the transmitter on the canvas monitors the transmitted signal level. If the bit level actually read a differ from then one transmitter bit error is signal that means like if I'm if I know it is writing one to the bus when we read the signal back it should be one only otherwise it will be discarded frame is will be discarded and and the arbitration will be failed that is a bit monitoring. Second one is let's talk about the bit stopping means then when a five consecutive bits are sensed then one extra bit will be transmitted to opposite level to be transmitted by a node it will be a six bit opposite level to the outgoing bit system. The receiver will remove the extra bit when it acknowledge that stuffing. So third one is acknowledgement bit that is the nodes of the bus that correctly receive a message are expected to send back and acknowledgement to the transmitter. Okay I have received the frame successfully. The last one is the cyclic redundancy check that is for the integrity of the data. So when the different CRC in the message okay a node detector different CRC what is received and what is calculated then it will generate a CRC error. So these are the all about the can errors. So let me move on to the next slide and we will see the can error confinement methods. Okay so a can load let me discuss about the can error confinement method here. Let's take an simple example to understand suppose a node A starts out in an error active state. So every node starts into the active state only that means that TEC and REC will be less than equal to 127. So that is called that I will explain you what is TEC and REC. These are the counters registers in the can protocol that TEC means transmitter error counter and receiver error counter. These counters are incremented or decremented when a can node encounters an error. Now node A transmitter frame let's suppose A transmitter frame and it fails. Then each time whatever that transmitter error counters increment or the counter by 8 and when the TEC is and the REC is greater than the 127. So it jumps into the error passive state and then if that error counter goes above the 255 number then it goes to the bus offer. Okay so now when there is when you are in the active state or the passive state you will transmit the error flags accordingly. That for example if you are in the active node if an active node detects the error will transmit the active error flags only. So this is how these nodes transmit the error flag. Okay so there is a there are two ways of a can node will come out from the bus or when it enters the bus or that is important. So when a node is enters the bus or first thing it will not participate in any of in any of the can bus communication. So now how to remove from the can from the bus or there are two ways. One is enable the automatic bus of management bit during the can node configuration. This bit automatically generate bus of recovery messages over the bus and second one is manually generate message on the bus. Recovery message contains 128 occurrence of the 11 consecutive recessive bit and the status. Now that there are two status bits are here first of status and warning status. These status are will be available in the can controller status and also you can have the interrupts for that. So it will be easy to monitor the bus. So let me move on to the next slide. So here we have an example of the Linux can error framework structure. One is the can devices state. That means we are defining here the can status can state. So that is the one is the bus errors error warning state error passively state bus office state and arbitration loss and restart all controllers will be restarted. And this is a switch case when a receiver receive or not receive the error frames. And if there will be some there will be a one switch case in the application in the driver in the can driver that defines which what will what was the error you found on the can bus. Accordingly we will we will debug the error or we will print this message over the console or the or passes to the application. So we can understand this error. We got this error on to the first. These are the form error acknowledgement error and we have discussed bit zero error and the bit one error. These are the more bit monitoring error actually and last one the CRC error. Okay, let me be more on the next slide. So these are the reasons for the bus can failure. So can bus can be filled with the various returns can high and because we have two wires and those two wires have the actually a basic voltage levels fixed voltage levels. And if these voltage level is stopped and bus will be failed that you will not be able to achieve that forward rate. What it can be changed or the signal can be discarded or the propagation delay will be increased. Now this how this happened is can and be shorted when can high will be shorted or the battery voltage is problem. Voltage because hardware as the voltage level and it will be shorted with a can high or the can low bus. And the last can high and the can low interrupted at the same location. That means you are can high and the can low are connected to each other or some short happen. And last one is the termination register. If you have if you are not terminated can bus is not terminated with 120 ohm register. So it will be like not DC level will be not be proper. So that's how can bus will be filled. And next move on to the next. So these are the user space tools like can utilities is a command line utility that is used to test the can interface. And to install the can utilities in your working space. So we have to use a pseudo get install can utilities icon Y and we have these are the commands. The example commands actually will be using in the to test the can dump. We can send display record generator replay the can traffic here. So here can we have a help command. We have a 960k board rate in which we are working in the loopback mode. So we are not communicating with the external can bus. Rounding back from the transfer receiver only. And second is the 10800k and we are setting the db rate that is flexible data bit. And we are using the flexible data on configuration for this can protocol or can not actually. So and other commands are can send commands. We are sending the frame on to the bus other is the statistics link show. So let's move on to the next slide. And these are the can utility dumps actually like what if you are giving a can zero type can help it will show you what all or what all our options you have. You can select using by the can utilities command loopback mode is an only one chart or one short error or FD known ISO. So these are the can commands. There is a you can set the board rate here. You can set the can dump you will you will send when you send the can frame. This is a transmitter message. And this is a receive so transmission frame and that seems for frame are the same. And this is the example of the statistics can zero. It will show you the about the can node that is can state is an active and bit rate configuration what is the bit rate configuration. What is the time point propagation segment phase segment and phase segment when the synchronous jump it and in the 40,000 40 megahertz clock. You can see and these are the bus error arbitration most errors and all are those things and other is the receiver byte and the transfer byte. Let's move on to the next slide. So I have okay if you have any questions related to the can protocol please feel free to ask. Thank you all for all joining this session. I hope I have covered all the insights and this session was useful. I hope and thanks again. Have a great day ahead. Thank you.