LIN Application for 16 bit microcontrollers

Application Note, V1.0, Feb. 2007
AP16107
LIN Application for XC164CM Using DAvE
LIN Configuration tool
Microcontrollers
Edition 2007-02-15
Published by
Infineon Technologies AG
81726 München, Germany
© Infineon Technologies AG 2007.
All Rights Reserved.
LEGAL DISCLAIMER
THE INFORMATION GIVEN IN THIS APPLICATION NOTE IS GIVEN AS A HINT FOR THE
IMPLEMENTATION OF THE INFINEON TECHNOLOGIES COMPONENT ONLY AND SHALL NOT BE
REGARDED AS ANY DESCRIPTION OR WARRANTY OF A CERTAIN FUNCTIONALITY, CONDITION OR
QUALITY OF THE INFINEON TECHNOLOGIES COMPONENT. THE RECIPIENT OF THIS APPLICATION
NOTE MUST VERIFY ANY FUNCTION DESCRIBED HEREIN IN THE REAL APPLICATION. INFINEON
TECHNOLOGIES HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND LIABILITIES OF ANY KIND
(INCLUDING WITHOUT LIMITATION WARRANTIES OF NON-INFRINGEMENT OF INTELLECTUAL
PROPERTY RIGHTS OF ANY THIRD PARTY) WITH RESPECT TO ANY AND ALL INFORMATION GIVEN
IN THIS APPLICATION NOTE.
Information
For further information on technology, delivery terms and conditions and prices please contact your nearest
Infineon Technologies Office (www.infineon.com).
Warnings
Due to technical requirements components may contain dangerous substances. For information on the types
in question please contact your nearest Infineon Technologies Office.
Infineon Technologies Components may only be used in life-support devices or systems with the express
written approval of Infineon Technologies, if a failure of such components can reasonably be expected to
cause the failure of that life-support device or system, or to affect the safety or effectiveness of that device or
system. Life support devices or systems are intended to be implanted in the human body, or to support
and/or maintain and sustain and/or protect human life. If they fail, it is reasonable to assume that the health
of the user or other persons may be endangered.
AP16107
LIN Application for 16 bit Microcontrollers
AP16107
Revision History:
2007-02
Previous Version:
none
Page
V1.0
Subjects (major changes since last revision)
We Listen to Your Comments
Any information within this document that you feel is wrong, unclear or missing at all?
Your feedback will help us to continuously improve the quality of this document.
Please send your proposal (including a reference to this document) to:
[email protected]
Application Note
3
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
Table of Contents
Page
1
Introduction ................................................................................................................................... 5
2
Local Interconnect Network (LIN) ............................................................................................... 6
3
LIN Low level driver ...................................................................................................................... 9
4
4.1
LIN Configuration Tool ............................................................................................................... 12
DAvE XC164CM ........................................................................................................................... 13
5
5.1
5.2
5.3
5.4
5.5
5.6
5.7
LIN Application............................................................................................................................ 15
Master Configurations................................................................................................................... 15
Slave Configurations..................................................................................................................... 23
Integration steps – Master Node................................................................................................... 26
Master Test application................................................................................................................. 32
Integration steps – Slave Node..................................................................................................... 34
Slave Test application................................................................................................................... 34
Download the executable code to the XC164CM......................................................................... 36
6
Conclusion .................................................................................................................................. 39
Application Note
4
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
Introduction
1
Introduction
In automotive application development, there is a need to have tools which can help you configure the chip
to work the way you need it. Such tools can greatly reduce the overhead of application development. This
paper deals with an idea to provide introduction and hands-on-experience of Infineon Technologies LIN
configuration tool that supports the LIN – a cost effective time triggered automotive protocol. The LIN
configuration tool can be used by the developers to make a prototype LIN applications.
This application note gives an overview of the LIN protocol, and describes the operation of the LIN low level
driver for Infineon Technologies 16bit microcontrollers. The configuration or implementation of the LIN
prototype application is discussed step by step. A LIN application project is explained to build a simple LIN
network with XC164CM devices (master node and one slave node).
Application Note
5
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
Local Interconnect Network (LIN)
2
Local Interconnect Network (LIN)
Automotive Communication Requirements
The automotive system is nowadays a complex distributed system with various demands of networking
capabilities. One automotive application consists of one or several Electronic Control Units (ECUs). In an
automotive system consisting of several automotive applications more than 70 ECUs might need to distribute
more than 2500 signals. This makes the automotive system complicated in terms of networking. Adding so
many ECUs to the car several different types of communication networks are required to reach cost effective
solutions.
A modern car usually contains one or two Controller Area Network (CAN)-networks. CAN is too expensive to
use for connecting simple devices such as simple switches and non safety critical functions like indoor lights
etc. A low cost communication solution called Local Interconnection Network (LIN) has been developed to
solve these problems. The purpose of LIN is not to replace the CAN-bus already running in the vehicles, but
to be a low cost complement for connecting simple functions.
LIN
The LIN is a low cost serial asynchronous communication system intended to be used for distributed
electronic systems in automotive applications. The communication is based on the SCI (UART) byte-word
interface. UART interfaces available as low cost silicon module on almost all micro-controller. The LIN does
not support very high bandwidth and long cables as more expensive bus technologies.
The LIN-bus always consists of one master and n slaves and can also have an interface to other
communication busses. The medium access in a LIN network is controlled by a master node so that no
arbitration or collision management in the slave nodes is required, thus giving a guarantee of the worst-case
latency times for signal transmission.
A particular feature of LIN is the synchronization mechanism that allows the clock recovery by slave nodes
without quartz or ceramics resonator. The maximum transmission speed is 20 kbps.
A node in LIN networks does not make use of any information about the system configuration, except for the
denomination of the master node. Nodes can be added to the LIN network without requiring hardware or
software changes in other slave nodes. The clock synchronization, the simplicity of UART communication,
and the single-wire medium are the major factors for the cost efficiency of LIN.
Applications
Typical applications for the LIN bus are assembly units such as doors, steering wheel, seats, climate
regulation, lighting, rain sensor, or alternator. In these units the cost sensitive nature of LIN enables the
introduction of mechatronic elements such as smart sensors, actuators, or illumination. They can be easily
connected to the car network and become accessible to all types of diagnostics and services.
Application Note
6
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
Local Interconnect Network (LIN)
LIN cluster
The LIN (Local Interconnect Network) is a broadcast bus that operates in speed upto 20 kbps and supports
the control of mechatronic nodes in distributed automotive applications. The LIN bus can have an interface to
other communication busses, for example CAN.
.
Figure 2.1
A LIN Bus with master and slave nodes
Nodes
A node in a LIN cluster interfaces to the physical bus wire using a frame transceiver. The frames are not
accessed directly by the application; a signal based interaction layer is added in between.
Master and slave
A LIN cluster consists of one master task and several slave tasks. A master node contains the master task
as well as a slave task. All other nodes contain a slave task only.
The LIN is a time triggered master slave network, where the master has a schedule that defines when each
frame is to be sent. All frames include a header, which is sent by the master. The header includes
information on which node that should send the data frame. If a slave node recognizes its identification it
either sends or receives the data of the frame specified in the header.
One node can transmit a frame while all of the other nodes can receive the frame, however every frame is
coded to indicate which node is the sender and receiver(s). This enables the receiving nodes to disregard
the frames which they do not require, thereby reducing the load on them.
Frames
Each node in the system has a set of frames that should be sent to other nodes in the system. A frame is
described by name, size, sender and a deadline. Whether a frame accepted is decided solely by the
controller (receiver system). This decision is made using acceptance or message filter. Therefore it is
possible for a frame to be accepted by one, several or all controllers for further processing.
Only one frame is transmitted at any given point in time. Consequently, no mechanism is needed to resolve
bus collisions, since it is impossible for collisions to occur in a LIN network. All frames to be transmitted are
sent within one cycle. The chronological sequence of frames is fixed in a schedule. Schedules may be
switched as needed.
Each frame is composed by a HEADER, which is sent by the master task and a RESPONSE that is sent by
one of the slave tasks. The header consists of a break and sync pattern followed by an identifier. The
identifier uniquely defines the purpose of the frame. The slave task appointed for providing the response
associated with the identifier transmits it.
The HEADER consists of a BREAK FIELD, SYNCHRONISATION FIELD and IDENTIFIER FIELD. The
RESPONSE consists of three to nine BYTE FIELDs: two, four, or eight DATA FIELDs, and one CHECKSUM
FIELD. The BYTE FIELDs are separated by inter-byte spaces, HEADER and RESPONSE are separated by
one in-frame-response space.
Application Note
7
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
Local Interconnect Network (LIN)
.
Figure 2.2
LIN FRAME
The number and size of frames are limited to: 32 numbers of 2 byte frames, QXPEHUVRIE\WHIUDPHV, numbers of 8 byte frames. The slave tasks interested in the data associated with the identifier receives the
response, verifies the checksum and uses the data transported. This results in system flexibility, message
routing and multicast.
Signals
A signal is transported in the data field of a frame. Several signals can be packed into one frame as long as
they do not overlap each other. Each signal has exactly one producer, i.e. it is always written by the same
node in the cluster. Zero, one or multiple nodes may subscribe to the signal. Each signal is described by
name, size, end-to-end deadline, sender node and receiver node(s). Signals may be represented by 1 to 16
bits. A signal may be visualised as a ’virtual wire’, which may either be an input to or an output from a node.
As many as hundred signals may be transmitted back and forth over the communication networks.
A signal is either a scalar value or a byte array. A scalar signal is between 1 and 16 bits long. A byte array is
an array of between one and eight bytes. A signal is transmitted with the LSB first and the MSB last. The
only additional rule for scalar signal packing within a frame is that maximum one byte boundary may be
crossed by a scalar signal. Each byte in a byte array shall map to a single frame byte starting with the lowest
numbered data byte.
Schedule table
A key property of the LIN protocol is the use of schedule tables. Schedule table makes it possible to assure
that the bus will never be overloaded. Deterministic behavior is made possible by the fact that all transfers in
a LIN cluster are initiated by the master task.
The master task transmits frame headers based on a schedule table. The schedule table specifies the
identifiers for each header and it is the responsibility of the master to assure that all frames are given enough
time to be transferred. The master application may use different schedule tables and select among them.
Application Note
8
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Low level driver
3
LIN Low level driver
The LIN Low level driver is developed for the XC164CM, but the principal for the XC166 family is identical.
The LIN bus requires no dedicated on-chip microcontroller communication module. LIN utilizes the standard
serial communication interface. That is one major point for the well-balanced cost/performance ratio of this
Class A subbus. Data exchange is based on a common hardware peripheral controlled by a dedicated LIN
software driver. The LIN LLD handles the basic communication layers and takes care of message transfers,
message filtering, and error detection.
.
Figure 3.1
LIN Driver and application
The Infineon LIN LLD entirely encapsulates the hardware modules and exclusively handles the on-chip
peripherals of the Infineon XC16x microcontrollers, which support LIN. A LIN network based on Infineon
Technologies XC16x microcontroller family can be easily realized by using the driver.
LIN Low level driver compliance to the LIN v2.0 protocol specification and developed according to Infineon
Technologies HAL (Hardware Abstraction Layer) standard. LLD is certified by C&S (communication &
system) group, Germany
Services
The LIN LLD provides several APIs for LIN bus handling. The services of the LIN LLD are Message
transmission, Message reception, Message filtering, Connect/disconnect the LIN node to the LIN bus,
Sending "go to sleep mode" command, Sending "wake up" command, Bus timeout detection, Frame
monitoring, ID field calculation, Data length extraction, Checksum calculation and LIN message scheduler
Requirements
LIN utilizes the serial interface for message frame generation and additionally occupies one timer channel for
LIN bus timing monitoring e.g. for detection of not responding slaves or no bus activity. Both peripherals
require an interrupt handler, with main processes of the LIN software driver being executed from the interrupt
handler of the serial communication channel peripheral.
Application Note
9
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Low level driver
The software driver occupies less than 3 KBytes of code memory and less than 100 bytes of data memory.
These numbers include all the basic LIN software driver functions. Application specific user LIN message
buffers require additional memory space.
The user has to configure the system as such, avoiding several slave tasks concurrently responding to the
same ID. Moreover, the user is responsible for arranging an application specific network management.
LIN LLD
The application has two software parts, the user application and software driver. The software driver consists
of LIN LLD source files and LIN LLD configuration files.
DAvE
LIN LLD
Application
Compiler
Config
fil
Hex-file
XC16x
.
Figure 3.2
LIN application development
LIN LLD source files
COMPILER.h
This file provides the data structures to make the LLD compiler independent. It automatically detects the
compiler being used and changes the compiler dependent data structures to suit to present compiler.
Provides the wrappers to basic data types and ISR handlers.
LIN_IDL.h
Provides the address mapping for the registers used by LIN LLD. To port the LIN LLD to different ECU this
file must be updated.
LIN_IIL.h
Provides the bit mapping and mask for the register control bits. This file must be updated to port LIN LLD to
different ECU.
SYS_API.h
Provides the definitions for system HAL (SYS HAL). This information shall be used by LIN LLD. To port LIN
LLD to different ECU this file must be updated.
LIN_IIL.c
This file contains the implementation of APIs according to LIN protocol specification v2.0.
Application Note
10
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Low level driver
SYS_IIL.c
This file contain the implementation of system HAL (SYS HAL) related APIs, these APIs can be used by all
LLDs of XC164CM.
LDF configuration files
LIN_API.h
Provides the data structures like enums, structures and function prototypes used for LIN LLD.
LIN_LDF.c
This file contains the initialised data for signals, frames and schedule tables. The configured master also act
as slave (transmit/receive a frame) simultaneously depend on the configuration for ‘LIN_publsh_frm_info’
and ‘LIN_sbscrb_frm_info’ in LIN_LDF.c file.
LIN_LDF.h
Provides data structures for signals, frames and schedules that are used by the LIN LLD.
LIN_CFG.h
Provides configurations for the required functionality of ECU like interface, baud rate, Master or Slave mode,
timers and interrupt priorities.
LIN Application file
LIN_test.c
LIN_test.c is a test application source file.
Note : You can contact Infineon Technologies for LIN LLD Source code.
Application Note
11
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Configuration Tool
4
LIN Configuration Tool
The LIN Configuration tool is an integral part of DAvE. Digital Application virtual Engineer is configuration
and code generation tool for Infineon Technologies Microcontrollers. It provides configuration, initialization
and driver code to ease programming of microcontrollers.
Install DAvE XC164CM
•
•
Download and install DAvE Mothersystem from http://www.infineon.com/dave.
Download and install DAvE XC164CM DIP file.
.
Figure 4.1
Application Note
How to install DAvE
12
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Configuration Tool
4.1
DAvE XC164CM
Now we need to configure XC164CM. Open DAvE mothersystem to create a new project on XC164CM.
•
File -> New -> 16-Bit Microcontrollers -> XC164CM -> Create
Application Note
13
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Configuration Tool
Project settings
Default project settings have the necessary configurations; so no change in project settings.
Close the project settings page by clicking the close button.
LIN Configurations
The LIN module in DAvE has 2 sub-modules ECU and LDF
Application Note
14
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
5
LIN Application
Lin application – One master and one slave LIN network using two XC164CMs.
MASTER (XC164CM) Interface ASC1
Timer T3
SLAVE
Timer T3
5.1
(XC164CM) Interface ASC1
Master Configurations
ECU - configure as done below.
Tool restriction: if we want to use only one interface, we have to use interface0 (ASC0). Only when we need
two interfaces, we can configure both interface0 (ASC0) & interface1 (ASC1).
Here we like to use interface1 (ASC1). Though we configured two interfaces, we will be using only LIN
interface1 (ASC1). We are not using interface0 (ASC0), so interface0 Node configured as Dummy. The
reason is, in XC164CM board, ASC0 pin outs are connected to ASC Transceiver, but ASC1 pin outs are
connected to LIN Transceiver.
Application Note
15
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
ECU Interrupts
Place the interrupts as shown above
LDF module will not be enabled until all the ECU and interrupts configurations are done.
Application Note
16
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
LDF
General
Application Note
- No change.
17
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Node - configure one slave (Slave1).
1
Application Note
18
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Signal
- configure 8 signals
Name
Signal1
Signal2
Signal3
Signal4
Signal5
Signal6
Signal7
Signal8
Type
ByteArray
ByteArray
ByteArray
ByteArray
ByteArray
ByteArray
ByteArray
ByteArray
Size
16
16
16
16
32
32
64
64
Signal Value
{1,1}
{2,2}
{16,16}
{17,17}
{32,32,32,32}
{33,33,33,33}
{48,48,48,48,48,48,48,48}
{49,49,49,49,49,49,49,49}
Publisher
Master
Slave1
Master
Slave1
Master
Slave1
Master
Slave1
Subscriber
Slave1
Master
Slave1
Master
Slave1
Master
Slave1
Master
2
3
4
5
6
1
Application Note
19
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Frame
- configure 8 Unconditional frames
Name
Frame1
Frame2
Frame3
Frame4
Frame5
Frame6
Frame7
Frame8
ID
0
1
16
17
32
33
48
49
Size
2
2
2
2
4
4
8
8
Max Time
200
200
200
200
200
200
200
200
Publisher
Master
Slave1
Master
Slave1
Master
Slave1
Master
Slave1
Frame Signals
Signal1
Signal2
Signal3
Signal4
Signal5
Signal6
Signal7
Signal8
2
5
3
4
6
1
Application Note
20
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Schedule
- configure one schedule (schedule1) with 8 frames.
2
3
Application Note
1
21
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Save & Generate code
(1) Save the configurations as ‘Master_D’ dave project in Master_Dave folder. (2) Generate code.
DAvE generates configuration files ()
1
2
Generated files
Application Note
22
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
5.2
Slave Configurations
ECU
Application Note
23
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
ECU Interrupts
Application Note
24
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
LDF
1
2
3
4
Generated files
Application Note
25
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
5.3
Integration steps – Master Node
1. Create a folder “Source”
2. Put the LIN LLD Source files (Compiler.h, LIN_API.h, LIN_IDL.h, LIN_IIL.c, LIN_IIL.h, SYS_API.h,
SYS_IIL.c) in this folder.
3. Create a folder “Master_App”
4. Put the DAvE generated file (LIN_CFG.h, LIN_LDF.h, LIN_LDF.c & LIN_test.c) in this folder from
DAvE project ‘Master_D’ which is in folder ‘Master_DAvE’.
5. Create a folder “Master_keil”
6. Create a project “Master_lin” using keil UV3.
Application Note
26
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
How to use keil UV3 IDE
Keil Software development tools for XC16x support embedded software development. The industry-standard
Keil C Compiler, Macro Assembler, Debugger, Real-time Kernel, and Single-board Computers support ALL
XC16x derivatives.
The starter kit package contains a CD for the installation of the evaluation version of keil IDE.
To install keil UV3 IDE, Run the ‘Setup’ file inside the CD. For more details go to www.keil.com.
New Project - Master
First start the keil UV3 IDE.
Create a new project
• Project -> New Project
• Select folder “Master_keil” where you want to save your project.
• Name the project “Master_LIN” and click ‘Save’.
1
2
3
Application Note
4
27
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Select Device for Target -> Infineon -> XC164CM-8F
Application Note
28
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Add the files to the project
Expand Target1 -> Right click on Source Group1 -> Add Files to Group ‘Source Group 1’.
Browse to ‘Source’ folder and select LIN_IIL.c and SYS_IIL.c files to add to the project.
Application Note
29
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Browse to ‘Master_App’ folder and select LIN_LDF.c and LIN_test.c files to add to the project
Application Note
30
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Options for Target
Project -> Options for Target ‘Target 1’
1
2
Include Paths
Go to Tab ‘A166’ and include the paths for source & Master_App folder as shown.
1
2
Application Note
31
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
5.4
Master Test application
The LIN_test.c file has the master test application. This initializes the master interface, connects to the LIN
cluster, initializes the system timer and sends the wake up signal to slave. This transmits four frames and
receives four frames from salve.
// Include LLD defined header files
#include "COMPILER.h"
#include "LIN_CFG.h"
#include "LIN_IDL.h"
#include "LIN_IIL.h"
#include "LIN_API.h"
#include "SYS_API.h"
l_u8 frm_num = 0;
l_u8 data[8] = {0};
l_u16 main (void)
{
// Initialize Master interface
LIN_calc_freq();
// calculates the system frequency.
l_ifc_init(1);
// Initialize the interface ASC1 for LIN.
l_ifc_connect(1);
// connect and make it ready to transmit & receive frames.
l_sys_init();
// Initialize system timer, used to schedule frames.
LIN_SET(SYS_HW_PSW, SYS_HW_PSW_IEN);
//Enable global interrupt
l_ifc_wake_up(1);
// Send wakeup signal to wakeup the sleeping slave.
l_sch_set(1,0,0);
// Initialize the schedule table.
// Transmit and receive data
while(1)
{
data[0] = 0x01;
data[1] = 0x01;
l_bytes_wr(Signal1, 0, 2, &data[0]);
frm_num = 0;
l_ifc_ioctl(1, LIN_FRM_INFO_UPDATE, &frm_num);
// Initial value to data
// update the signal with data.
// frame number has new data.
// indicates the updated frame.
data[0] = 0x10;
data[1] = 0x10;
l_bytes_wr(Signal3, 0, 2, &data[0]);
frm_num = 0x10;
l_ifc_ioctl(1, LIN_FRM_INFO_UPDATE, &frm_num);
// Frame (0x10) with 2 bytes
data[0] = 0x20;
data[1] = 0x20;
data[2] = 0x20;
data[3] = 0x20;
l_bytes_wr(Signal5, 0, 4, &data[0]);
frm_num = 0x20;
l_ifc_ioctl(1, LIN_FRM_INFO_UPDATE, &frm_num);
// Frame (0x20) with 4 bytes
Application Note
32
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
data[0] = 0x30;
// Frame (0x30) with 8 bytes
data[1] = 0x30;
data[2] = 0x30;
data[3] = 0x30;
data[4] = 0x30;
data[5] = 0x30;
data[6] = 0x30;
data[7] = 0x30;
l_bytes_wr(Signal7, 0, 8, &data[0]);
frm_num = 0x30;
l_ifc_ioctl(1, LIN_FRM_INFO_UPDATE, &frm_num);
}
}
l_flg_clr(0x11); \\ clears the status flag of the frame (0x11)
l_flg_tst(0x11); \\ shows the status flag of the frame (0x11)
These two functions can be used to monitor the transmission and reception of the frames in the LIN. Use the
l_flg_clr(frame no) before the transmission from either side and check the status flag using l_flg_tst(frame
no) for the successful transmission and reception.
Generate executable ‘Master_LIN’
1
Application Note
33
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
5.5
Integration steps – Slave Node
Create a folder ‘Slave_App’
Put the DAvE generated file (LIN_CFG.h, LIN_LDF.h, LIN_LDF.c & LIN_test.c) in this folder from DAvE
project ‘Slave_D’ which is in folder ‘Slave_DAvE’.
Create a folder ‘Slave_keil’
Create a project ‘Slave_lin’ using keil UV3. Follow the same steps shown for Master setup.
Select the LIN_LDF.c and LIN_test.c files from ‘Slave_App’ folder.
5.6
Slave Test application
The LIN_test.c file has the slave test application.
// Include LLD defined header files
#include "COMPILER.h"
#include "LIN_CFG.h"
#include "LIN_IDL.h"
#include "LIN_IIL.h"
#include "LIN_API.h"
#include "SYS_API.h"
l_u8 frm_num = 0;
l_u8 data[8] = {0};
l_u16 main (void)
{
// Initialize Master interface
LIN_calc_freq();
// calculates the system frequency.
l_ifc_init(1);
// Initialize the interface ASC1 for LIN.
l_ifc_connect(1);
// connect and make it ready to transmit & receive frames.
l_sys_init();
// Initialize system timer, used to schedule frames.
LIN_SET(SYS_HW_PSW, SYS_HW_PSW_IEN);
//Enable global interrupt
// receive and Transmit frames
while(1)
{
data[0] = 0x02;
data[1] = 0x02;
l_bytes_wr(Signal2, 0, 2, &data[0]);
frm_num = 1;
l_ifc_ioctl(0, LIN_FRM_INFO_UPDATE, &frm_num);
data[0] = 0x11;
data[1] = 0x11;
l_bytes_wr(Signal4, 0, 2, &data[0]);
frm_num = 0x11;
l_ifc_ioctl(0, LIN_FRM_INFO_UPDATE, &frm_num);
Application Note
34
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
data[0] = 0x21;
data[1] = 0x21;
data[2] = 0x21;
data[3] = 0x21;
l_bytes_wr(Signal6, 0, 4, &data[0]);
frm_num = 0x21;
l_ifc_ioctl(0, LIN_FRM_INFO_UPDATE, &frm_num);
data[0] = 0x31;
data[1] = 0x31;
data[2] = 0x31;
data[3] = 0x31;
data[4] = 0x31;
data[5] = 0x31;
data[6] = 0x31;
data[7] = 0x31;
l_bytes_wr(Signal8, 0, 8, &fifo_data[0]);
frm_num = 0x31;
l_ifc_ioctl(0, LIN_FRM_INFO_UPDATE, &frm_num);
}
}
l_flg_clr(0x10); \\ clears the status flag of the frame (0x10)
l_flg_tst(0x10); \\ shows the status flag of the frame (0x10)
These two functions can be used to monitor the transmission and reception of the frames in the LIN. Use the
l_flg_clr(frame no) before the transmission from either side and check the status flag using l_flg_tst(frame
no) for the successful transmission and reception.
Generate the executable ‘Slave_LIN’
Use pls UAD to download the code to XC164CM.
Application Note
35
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
5.7
Download the executable code to the XC164CM
The pls provides UAD (Universal access device) along with UDE (Universal Debug Engine). Install the UDE,
using setup given in the pls UAE CD.
Use the parallel port to connect the PC and UAD and use JTAG to connect UAD and XC164CM board.
New workspace – Master Node
Start the UDE by double clicking on the UDE Desktop
File -> New workspace
Name the workspace “Master_LIN” and click on open.
Application Note
36
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Program the flash
Tools -> Flash Programming
1
2
3
Load Program
File -> Flash Program
1
2
Select the executable file ‘Master_LIN’ from folder ‘Master_keil’ and click on open.
Application Note
37
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
LIN Application
Memory programming
3
1
2
Slave node – code downloading
Follow the same steps shown above for downloading the slave test application to second XC164CM board.
Load the ‘Slave_LIN’ executable to the slave board.
LIN NETWORK
External connection: the LIN network is designed as one master and one slave, both are using ASC1 and
Timer T3 for the LIN. Connect ASC1 RxD1 to T3IN of T3 in both the boards. Connect the LIN bus from
Master board to slave and same way the ground. Reset both the boards now the nodes start the LIN
communication. This can be monitored in LED by assigning the status of each frame to each P1L port bit
value of XC164CM.
Application Note
38
V1.0, 2007-02
AP16107
LIN Application for 16 bit Microcontrollers
Conclusion
6
Conclusion
The LIN configuration tool can be used by the developers to make a prototype LIN applications. This
application note explained about features of the tool and how it helps to configure each entity like nodes,
signals, frames and schedules in a LIN cluster and automatically generates C-level prototype applications.
By introducing this tool, Infineon Technologies now offers all the elements required for developing a LIN
network, the powerful 16bit XC16x microcontrollers, LIN Transceivers, LIN LLD and LIN Configuration tool.
Application Note
39
V1.0, 2007-02
http://www. inf ineon.com
Published by Infineon Technologies AG