当前位置:网站首页>[AUTOSAR candrive 1. learn the function and structure of candrive]
[AUTOSAR candrive 1. learn the function and structure of candrive]
2022-07-23 12:28:00 【Rest of life】
We know CanDrive It is the bottom layer of the communication protocol stack , The previous article has talked about in autosar In the architecture Com Service layer series Com Introduction to communication series
We don't talk much about , Go straight to today's theme
Catalog
1.CAN Drive To understand the concept of
In order to be consistent with the document description , The following will use CAN Module CAN Driver. In short ,CAN The lowest level content of a module , Its function is to implement hardware access and provide independent hardware interface for the upper layer ( here Access to CAN The upper layer of the module is only Can Interface modular ). Speaking of accessing hardware , Let's start with a few concepts , As shown in the figure below :

The explanation of the figure is as follows :
- One **CAN Hardware unit (CAN HardwareUnit)** It's equivalent to some ECU Of CAN hardware component , It can include one or more CAN controller (Controller).
- One CAN The controller is a CAN Node or a CAN, That is, connect a physical channel correspondingly . It has a lot of Message mailbox (message object).
- One The message mailbox has multiple registers , Used to store message information , Here's the picture 5 Shown .

And so on CAN Receive and send , It can be seen from the above that CAN Module access Yes. CAN Hardware unit Some CAN Some registers of the controller . that CAN Under what conditions can modules be accessed ? Next, we need to introduce a few more concepts :
First, give our conclusion : If we want to accept or happen our message , Ensure the state of the two state machines 1. our Can Drive Driving state machine 2. Corresponding Can Controller State machine of controller .
Let's start with Can Drive Driving state machine
1.1 Can Drive Driving state machine (Driver state machine)
CAN The module driven state machine has two states , After power on or reset ,CAN Module access CAN_UNINIT state ( Uninitialized state ), After the initialization ,CAN Module access CAN_READY state , At this time, you can perform some and read 、 Write 、 Bus off 、 Wake up functions related to controller state settings . in other words CAN Receive and send must be in the drive state machine CAN_READY To perform .

1.2 Can Controller State machine (Controller state machine)
stay The drive state machine is in CAN_READY Under the premise of state , You need to think about CAN Controller status . Because at the hardware level ,CAN The controller will execute a very complex state machine , To implement different hardware behaviors . Sometimes it is necessary to realize some functions in the corresponding state , For example, initialization , Baud rate setting, etc ; Sometimes external events ( Bus off , Wake Events ) Will trigger a state change , Lead to whether certain functions can be performed .
For the sake of simplification , There will be CAN The state of the controller is divided into 4 individual .

CAN The controller is not initialized - UNINIT Belong to CAN All registers of the module are in reset state , Do not enable CAN interrupt . CAN The controller is not involved CAN Bus .
CAN Controller state stopped - STOPPED In this state ,CAN Controller initialized , But do not participate in the bus . Also do not send error frames and acknowledgments .
CAN Controller state started - STARTED The controller is in normal operation mode , It has complete functions , This means that it has joined the network .
For many controllers , Leave “ initialization ” Mode causes the controller to start .CAN The controller status is sleep - SLEEP And STOPPED The only difference is :CAN Your hardware settings support sleep mode ( from CAN The hardware supports wakeup CAN The bus wakes up directly )
From the above definition we can see that :CAN Receive and send must be in the controller state machine STARTED State to execute . How can we make CAN The controller is in STARTED State , It is not difficult to find through the above state machine , have to Enter the first STOPPED It's the state . There are generally the following methods to trigger CAN The state of the controller is transferred to STOPPED:
- Initialization function Can_Init, Change the controller state from UNINIT Transferred to the STOPPED;
- Bit rate setting function Can_SetBaudrare, Transfer the controller state to STOPPED;
- Controller mode setting function Can_SetControllerMode, Transfer the controller state to the target state ;
- Hardware event triggers , For example, a wake-up event causes the controller to switch from SLEEP Transferred to the STOPPED, The bus shutdown event causes the controller to switch from STARTED Transferred to the STOPPED.
Documentation for this 4 State and controller mode setting functions Can_SetControllerMode Make clear definitions 
1.3 Can Contents of module initialization
The above two states are generally set through the initialization function , I'm using Can Before any other functions of the module ,ECU The state manager module invokes CAN Module initialization function (Can_Init) To initialize , Its contents include :
- Static variables , Including signs ;
- complete CAN General settings of hardware unit ;
- Every CAN Controller CAN Controller specific settings .

After the initialization ,CAN The driving state is CAN_READY,CAN The controller status is STOPPED.
When CAN The module meets the conditions , You can access the register , that CAN How to implement the module CAN What about the operations required for sending or receiving ? And what operations need to be done ??
1.4 Protocol data unit (Protocol Data Unit, PDU)
Before answering these two questions , In order to send or receive the data format involved , Need to introduce again PDU The concept of ,PDU Including protocol control information (Protocol Control Information,PCI) And service data unit (Service Data Unit, SDU).
among SDU It refers to the transmission from the upper module , Data required to be sent ; Or received by the lower module , Extracted data , It needs to be passed to the upper level .
PCI It refers to the need to SDU Pass from one instance of a particular protocol layer to another . for example . It contains source and target information .PCI Add , Then it is deleted at the receiver .
Commonly understood as :PDU It's not just data (SDU), Also brought Information about where to go from (PCI); The previous information will be deleted everywhere , Add information about where to go ( Different layers PCI to update ), As shown in the figure below .

1.5 Sending operation
about CanDrive Come on , There are two things to do when sending a signal : First, access the hardware , Write data to register ; Second, after sending successfully , Up to the top CAN Interface Module confirmation .

But for the whole world autosar The architecture of We need to know the whole process of sending :

For writing data ,CAN Interface Module call Can_Write function , Its definition is as follows :

First of all, I want to explain Hth The definition of . every last Hardware objects are all composed of ID,DLC and SDU Three parts , Here's the picture 15. be used for The hardware object that stores the written data is called Hth, The hardware object used to store the received data is called Hrh


So it's not hard to understand ,Can_Write Input parameters of Hth It is actually the number of the hardware object (id), And in fact, the number and... Of hardware objects have been defined CAN ID The mapping relation of , For example, below 16 Shown , If you want to send CAN ID by 0x001 The data of , So called Can_Write Function's input parameters Hth Should be 4.

Then quote the content of the document to explain Can_Write The function performs the main actions , As shown below :





So we know the process of writing data , Finally, learn about the sending confirmation process , It can be seen from the previous article ,BSW The scheduler will periodically call Can_MainFunction_Write function , Its definition is as follows :

Note that the condition of this function call is CAN The sending processing method is POLLING( polling ). Here's how CAN Send processing method , Yes 3 Kind of :
(1) Polling mode (polling mode)
In polling mode Can The sending confirmation of the module is Scheduling module (BSW Scheduler) Trigger , Perform subsequent processing . Like setting CAN Send in polling mode , that Can_MainFunction_Write It will be called periodically at predefined intervals ( For example, every few days ms Call once ), then Can_MainFunction_Write And then call the upper CAN Interface Modular CanIf_TxConfirmation modular , Confirm upwards .
(2) Interrupt mode (interrupt mode)
In interrupt mode Can The sending confirmation of the module is made by CAN The interrupt of the controller triggers , Perform subsequent processing , Like setting CAN Send in interrupt mode , After the interrupt is triggered , call Can Module send confirmation processing function , Call... In this function Can Interface Modular CanIf_TxConfirmation function , Confirm upwards .
(3) Mixed mode (mixed mode)
namely (1)(2) A mixture of , See the specific settings , Whether to use polling mode or interrupt mode .
So here I choose the polling method to introduce . according to CanIf_TxConfirmation The input parameters of the function are known , Which is confirmed upward CAN ID Send successfully .( Here is wrong CanIf Function introduction of , The next article will introduce )
Receive operation
It can be seen from the previous article ,CAN Reception time , about CAN The module also has two operations : First, access the hardware , Extract data from registers ; Second, inform the upper level CAN Interface modular , To transfer data .
For data reading operations , First BSW The scheduler periodically calls Can Modular Can_MainFunction_Read function , Its definition is as follows . similarly CAN The receiving processing method includes polling , Interrupt and mixed mode . The polling mode is selected here .

Last , After the data is successfully extracted ,Can_MainFunction_Read The function will call CanIf_RxIndication Function notification CAN Interface modular , Pass data up .( Here is wrong CanIf Function introduction of , The next article will introduce )
summary
We use mind mapping to summarize the whole process of our sending and receiving operations today

Notice : Next, let's talk about learning Canif Layer of knowledge
边栏推荐
- 永磁电机参数的测量获取(电感、电阻、极对数、磁链常数)
- With statement
- In depth interpretation of Google or tools' complex scheduling program
- 编码器的一点理解
- “東數西算”下數據中心的液冷GPU服務器如何發展?
- Six trends and eight technologies of high-performance computing in data centers under "data center white paper 2022" and "computing from the east to the west"
- 利用pycaret:低代码,自动化机器学习框架解决分类问题
- 钢结构基本原理全面详细总结
- 时间序列的数据分析(一):主要成分
- 建设“绿色计算”,解读“智算中心”
猜你喜欢

Connaissance du matériel 1 - schéma et type d'interface (basé sur le tutoriel vidéo complet de l'exploitation du matériel de baiman)

单片机学习笔记6--中断系统(基于百问网STM32F103系列教程)

The green data center "counting from the east to the west" was fully launched

Eigen multi version library installation

【Autosar CP通用 1.如何阅读Autosar官方文档】

Data analysis (II)

论文解读:《基于注意力的多标签神经网络用于12种广泛存在的RNA修饰的综合预测和解释》

硬件知识1--原理图和接口类型(基于百问网硬件操作大全视频教程)

论文解读:《利用注意力机制提高DNA的N6-甲基腺嘌呤位点的鉴定》

Solve Sudoku puzzles with Google or tools
随机推荐
保存实质审查请求书出现Schema校验失败的解决方法
Deep convolution generation countermeasure network
How to build a liquid cooling data center is supported by blue ocean brain liquid cooling technology
Using or tools to solve the path planning problem with capacity constraints (CVRP)
Data analysis of time series (II): Calculation of data trend
数据挖掘场景-发票虚开
Interpretation of the paper: develop and verify the deep learning system to classify the etiology of macular hole and predict the anatomical results
Interpretation of the paper: the interpretability of the transformer model of functional genomics
深度卷积生成对抗网络
论文解读:《开发一种基于多层深度学习的预测模型来鉴定DNA N4-甲基胞嘧啶修饰》
预处理指令#define,你真的懂了吗?
How to develop the liquid cooled GPU server in the data center under the "east to West calculation"?
ARM架构与编程7--异常与中断(基于百问网ARM架构与编程教程视频)
利用or-tools来求解路径规划问题(VRP)
【AUTOSAR CanDrive 1.学习CanDrive的功能和结构】
K-nucleotide frequencies (KNF) or k-mer frequencies
Using Google or tools to solve logical problems: Zebra problem
《高分子合成工艺》简答题答案
Data analysis of time series (III): decomposition of classical time series
高等代数100道题及答案解析