Home
AN2633/D - NXP Semiconductors
Contents
1. 4 WHEN FINISHED JUMP TO break a COMMON EXIT CODE WHICH m CLEARS THE INTERRUPT FLAG THIS SAVES ROM tee g Q SPACE IF DESIRED THIS _ ena switch temp_SLCSV or CODE CAN BE INCLUDED ww AT THE END OF EACH Ne SERVICE HANDLER ais Sits SLEF 1y 7 7 Clear SLIC interrupt flag x LoT end SLIC ISR Figure 9 SLIC Based ISR Flowchart 14 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D CodeWarrior Project C Source Code Basic SLIC Driver An additional feature of the C version of the basic driver is that it will accept a 2 byte message with an ID of 0x97 This is shown as an example of how to handle a LIN command message where data is coming from the master node As mentioned before this driver is included in the LIN kit demo software which can be downloaded free from the Motorola web site It also comes with the M68EVB908QL4 evaluation board It comes in the form of a Metrowerks CodeWarrior 3 0 project LINQL4 C mcp The project structure can be seen in Figure 10 BE Include AB global h A MCBSHCS908GL4 h AB SLIC_LINdriver h HE3 Sources A slave c AB vector c G E Driver source AB StartO8 c A MC6SHC908GL4 C AB SLIC_LINdriver c a Pim AB hcO8GL4 prm Libs ansi lib Figure 10 CodeWarrior Project LINQL4 C mcp C Source Code The LIN driver consists of two files e S LIC_LINdriver c contains the main dr
2. Set LINSleep flag Reset BusOff counter TX Buffer Empty Checksum sent service handler uncomment to terminate service routine code TX Buffer Empty service handler RX Buffer Full Checksum OK service handler RX Buffer Full service handler uncomment to terminate service routine code Bit Error service handler uncomment to terminate service routine code RX Buffer Overrun service handler uncomment to terminate service routine code Checksum Error service handler LIN Drivers for SLIC Module on the MC68HC908QL4 29 For More Information On This Product Go to www freescale com jmp exit _isr serve0x28 jmp exit _isr serve0x2C lda cmp bne lda sta lda sta lda sta bra next_id 1 not_found lda 0 sta SLCDLC lda SLCC1 ora mIMSG sta SLCC1 id_lookup_done lda 0 sta LINSleep jmp exit_isr serve0x30 jmp exit_isr serve0x34 jmp exit _isr serve0x3C jmp exit_isr serve_none exit_isr lda SLCS ora mSLCF sta SLCS pulh rti SLCID LINID next_id 1 LINdata SLCDO 500 SLCD1 SC1 SLCDLC Freescale Semiconductor Inc id_lookup_done F r r AN2633 D uncomment to terminate service routine code Byte Framing Error service handler ID Received Successfully parity OK service handler Performing ID lookup to determine message meaning Load up ID of incoming message Is it the ID we re l
3. This is a different file than the one in the C project 16 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com How to Use the API Driver API Driver Configuration Message File Configuration Freescale Semiconductor Inc AN2633 D CodeWarrior Project C Source Code SLIC Driver with API The SLIC_LINdriver c file used in the API version is different and more generic for the API project than for the C project It is designed to work with the LINmsg c file to search for messages rather than hard coding them directly into the interrupt service routine as the C project does The structure of LINmsg c is very similar to the one used in AN2599 D with one important difference The SLIC module contains a register called the SLIC Data Length Code register SLCDLC which encodes the number of bytes in a message frame the type of checksum calculation to be used standard or enhanced and whether the SLIC is to transmit or receive this frame To simplify the ISR code for the API version a data structure in LINmsg c called MessageDLCTbI1 contains the appropriate value for this register for each message defined This MessageDLCTb1 replaces the function of MessageCountTbl in the AN2599 D drivers The other files serve the same functions as they do in the assembly and C projects The easiest way to begin developing a new application is to use the API sample project To
4. the 2 interrupts required by the QL4 slave node with the SLIC module This performance data suggests that the QL4 and EY16 MCUs are better suited for CPU intensive applications such as motor control For simpler less time critical applications such as contact monitoring the QY4 should be sufficient MCU selection must be made by balancing cost and resource requirements of CPU and memory 26 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D References References MC68HC908QL Data Sheet Motorola Document Number MC68HC908QL4 D LIN Specification Package Rev 1 3 Dec 12 2002 LIN Specification Package Rev 2 0 Sept 16 2003 AN2503 D Slave LIN Driver for the MC68HC908QT QY MCU AN2573 D LIN Kits LIN Evaluation Boards AN2599 D Generic LIN Driver for MC68HC908QY4 AN2575 D MC68HC908EY16 ESCI LIN Drivers M68EVB908QL4 SCH_D pdf M68EVB908QL4 board schematics LINO8 Driver Users Manual Rev 1 1 March 13 2001 Appendix A Software Listings SLIC asm wh ee ey i Title SLIC asm Copyright c Motorola 2003 Assembler P amp E Microcomputer Systems CASM08Z v3 16 Compiler Codewarrior Revision History Rev Date Who Comments 0 1 28 Oct 03 MR Initial release Filename LINQL4 ASM src SLIC asm Author Matt Ruff Revision 0 1 Functions SLIC module routines History Description
5. Notes LIN Drivers for SLIC Module on the MC68HC908QL4 27 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D Include QL4 registers_v0r2 inc MC68HC908QL4 XDEF slic_isr XDEF slic_init Routine to initialize the SLIC MyData SECTION SHORT XREF LINdata Global varibles use XREF XREF LINID XREF BusOff XREF LINSleep MyCode SECTION i SLIC Init Initializes SLIC module i af Configures SLIC for 1 LIN or BTM mode operation Hi 2 Clock Operation in MCU Wait Mode i 3 Receive filter prescaler adjustment for data rate 4 Bit timing setting BTM mode j slic_init lda mINITREQ coma Invert mask and SLCC1 AND with SLCC1 sta SLCC1 wait lda mINITACK Wait for INITACK to clear and SLCS F cmp 0 See if INITACK set bne wait Branch if INITACK still set lda 80 sta SLCP Set filter prescaler lda SLCC2 A ora mSLCE sta SLCC2 Enable SLIC module rts i i SLIC_ISR Interrupt Service Routine Main handler for SLIC interrupts i i slic_isr pshh Push H onto stack clrh Clear H to ensure proper
6. addressing ldx SLCSV Load SLCSV value into index register jmp jmptab x SLCSV used as offset into jump table jmptab jmp serve0x00 No interrupts pending nop 28 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com jmp serve0x04 nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop jmp nop serve0x00 jmp serve0x04 inc BusOff lda BusOff cmpa 02 bne end0x04 inc LINSleep lda 0 sta BusOff end0x04 jmp serve0x08 serve0x08 serve0x0C serve0x10 serve0x14 serve0x18 serve0x1C serve_none serve0x24 serve0x28 serve0x2C serve0x30 serve0x34 serve_none serve0x3C exit _isr exit _isr jmp exit_isr serve0x0C jmp exit _isr serve0x10 jmp exit _isr serve0xl14 jmp exit _isr serve0x18 jmp exit _isr serve0x1C jmp exit_isr serve0x24 Freescale Semiconductor Inc r 1 a AN2633 D Appendix A Software Listings SLIC asm No Bus Activity TX Buffer Empty Checksum sent TX Buffer Empty RX Buffer Full Checksum OK RX Buffer Full Bit Error RX Buffer Overrun lt reserved gt Checksum Error Byte Framing Error ID Received Successfully parity OK ID Parity Error Inconsistent Synch Field Error lt reserved gt Wakeup No interrupts pending service handler No Bus Activity service handler Add 1 to BusOff
7. being sent received or updated Table 5 demonstrates the change of status after PutMsg is called ora message is received at a node Table 5 Status Change after PutMsg is Called Previous State Next State LIN_ MSG_NODATA LIN_MSG_OK LIN_ MSG_NOCHANGE LIN_ MSG_UPDATED LIN_ MSG_UPDATED LIN_ MSG_OVERRUN LIN_MSG_OVERRUN Table 6 demonstrates the change of status after GetMsg is called or data is sent from a node Table 6 Status Change after GetMsg is Called Previous State Next State LIN_ MSG_UPDATED LIN_MSG_OK LIN_MSG_OVERRUN LIN_MSG_OK LIN_ MSG_NOCHANGE LIN_ MSG_NOCHANGE LIN_ MSG_NODATA LIN_ MSG_NODATA This function initializes the LIN driver and makes the driver ready to detect LIN communication Initialization of the driver includes e Initializing the SLIC module e Clearing error flags e Clearing the sleep flag e Initializing the message buffer status LIN_Init must be called before any other LIN API function is called It takes no parameters and returns nothing Usage example LIN Init 20 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com LIN_GetMsg LIN_PutMsg LIN_MsgStatus LIN_GotoRun Freescale Semiconductor Inc AN2633 D CodeWarrior Project C Source Code SLIC Driver with API This function is used for getting the data of th
8. do this simply replace the sample application file slave c with your own application code You can also begin developing by creating a new project in a CodeWarrior development environment and adding the four LIN driver files to the project Then 1 Define the messages you want to use in the LINmsg c file as described below 2 Make sure the vectors _ Startup uses vector 0 and SLIC_ISR uses vector 10 are set up properly either in the vector c file or in a parameter file 3 Don t forget to include the file LINdriver h in your application code file The driver configuration file LINmsg c can be edited by the user It contains definitions of all messages to be recognized by the application and is set up for the demo code to recognize all four possible IDs for the demo application Setting up this file is all that is needed for configuration of the API driver for normal LIN applications All LIN message frames that the slave node is to use in the application must be defined in the LINmsg c file LIN Drivers for SLIC Module on the MC68HC908QL4 17 For More Information On This Product Go to www freescale com NOTE Freescale Semiconductor Inc AN2633 D Message buffers Define one array for each message frame that either requires a response or must be received When defining it is good practice to include the frame ID in the name for example MessageOxID where ID is the message identifier in hexadecimal
9. next id 1 If not check for next ID x IT ALWAYS TAKES TWO 2 jmp INSTRUCTIONS TO co ve BEGIN EXECUTING sxit isr D WHEN FINISHED JUMP T fEexit_isr COMMON EXIT CODE WHICH lda SLCS e E RE ora mSLIC Load mask for SLCF bit IF DESIRED THIS CODE CAN oe eo ee x BE INCLUDED AT THE END pulh 7 restore from stack OF EACH SERVICE HANDLER rex return from interrupt w ooo Figure 7 SLIC Assembly ISR Flowchart The jump table serves the same purpose as a switch temp_SLCSV statement would in a C based ISR but the jump table always executes in fixed time Ina switch var statement cases near the end of the list might take longer to execute because all cases must be searched This may be optimized by the C compiler to minimize execution time but execution time will still vary based on which case is taken It is possible to further optimize this assembly routine by grouping all unused service handlers together so that they can share a common exit point The entries in the jump table for unused services could even be made to jump directly to the exit code 12 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D CodeWarrior Project Assembly Source Code Basic SLIC Driver As mentioned before this driver is included in the LIN Kit demo software which can be downloaded free from the Motorola web site It al
10. set to 1 and cleared by the application code set to 0 The flags are global and can be polled in the application to check whether there is an error during send or receive Table 7 provides a description of bit errors and checksum errors 22 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Sleep Mode Freescale Semiconductor Inc AN2633 D Driver Performance Timer UART and SLIC Compared Table 7 Error Descriptions Flag Description BitERROR Set if there is a bit error when sending ChecksumERROR Set if there is a checksum error while receiving The LIN protocol includes a sleep mode which reduces system power consumption A message with ID 0x3C and first data byte of 0x00 is used to broadcast the Sleep Mode command The API driver will respond to this sleep mode message by setting the sleep flag LINSleep As stated before the method of putting the module in sleep mode is hardware design dependent and is therefore handled by the application code Driver Performance Timer UART and SLIC Compared The following performance data compares various methods of implementing LIN communications with different hardware and software options All are based on using the same basic application found in the LIN kits demonstration software modified to accommodate an 8 byte message This data allows the developer to balance cost performance a
11. to allow the ISR to service all SLIC interrupts in a short fixed and predictable amount of time Details of this are explained in CodeWarrior Project Assembly Source Code Basic SLIC Driver Because the SLIC module automates standard LIN communication functions less time is spent inside the ISR Checksum calculations have been automated which eliminates the extra instructions that would be needed to perform this calculation in a UART solution This further reduces the amount of LIN Drivers for SLIC Module on the MC68HC908QL4 5 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D time spent inside the communications interrupt handlers This time is valuable because other interrupts cannot be handled during this time Hardware LIN Kit Demo Board The LIN kit demo board is made from a QL4 with an added LIN interface which consists of an MC33399 LIN transceiver and a 5 V regulator an LT1121 chip The board can be programmed using either the RS 232 MONO8 interface or a Cyclone or MultiLink tool The board requires three jumpers J2 J4 and J5 for programming it using the RS 232 MONO8 interface The jumper J2 is however not needed when using a MultiLink or Cyclone tool to program or debug NOTE Ifyou plan to use MONO8 tools for debugging you must av
12. with the parity bits included This buffer is for the frame data field for each message The data field can be 1 to 8 bytes The array size must equal the number of data bytes for that message An example of a 2 byte message could be U8 volatile Message0xD8 2 After message buffer storage has been created for all messages that will be recognized by the node these must be included in a number of additional arrays The order of the messages must be consistent in all arrays The following three arrays are required MessagePointerTbl Consists of pointers to all message buffers defined above Example U8 volatile MessagePointerTbl Message0xD8 Message0x99 IdTbI Contains all IDs relevant to this node It is very important that the ID includes the parity bits The order of the messages must be the same as in MessagePointerTbl and MessageDLCTbIl Example U8 const near IdTbl1 0xD8 0x99 MessageDLCTbI Defines the SLIC data length code register values for each message This control register in the SLIC module tells the hardware how many bytes of data are in the message shows if the message should be sent or received by the slave and what method of checksum calculation should be used to ensure data integrity LIN 2 0 allows for standard or enhanced checksum where the ID byte is included in the calculation This DLC register value is copied directly to the SLCDLC register at the appropriate time
13. Freescale Semiconductor Inc Application Note AN2633 D Rev 1 3 2004 LIN Drivers for SLIC Module on the MC68HC908QL4 By Matt Ruff 8 16 Bit Systems Engineering Austin Texas Overview This application note describes three versions of a slave LIN driver developed for the slave LIN interface controller SLIC module on the MC68HC908QL4 QL4 microcontroller unit MCU The slave driver comes with the Motorola QL4 LIN kit evaluation board which also contains AN2573 D LIN Kits LIN Evaluating Boards which demonstrates the functionality of the driver The slave driver also comes with the M68EVBQL4 evaluation board EVB from Metrowerks along with a compatible version of the application code for the EVB The software for the LIN kit including this driver can be downloaded from the Motorola LIN website http motorola com semiconductors LIN Local Interconnect LIN local interconnect network is a low cost communication protocol often Network LIN used in automotive applications that do not require the bandwidth and versatility of CAN The LIN bus uses only a single data wire and can communicate at speeds up to 20 kbps A LIN network has a single master and multiple slaves so bus arbitration is not required The driver and application was developed from the LIN Specification Package See References for this and other useful resources NOTE With the exception of mask set errata documents if any other Motorola document con
14. IC driver code are included in this application note to illustrate several different ways to implement software drivers for this module All methods serve the same basic purpose but every method is a different balance of code portability readability and efficiency The primary difference between each version of the driver code is how the SLIC module ISR is written The three basic versions of the code are e Assembly code version of the SLIC ISR e Basic C based version of the same ISR e C based driver with a standardized application programmers interface API The API is designed to match the API for the QT QY LIN slave drivers described in AN2599 D All versions of the code include a sample application designed for use with either the LIN kit QL4 slave evaluation board or the M68EVB908QL4 evaluation board To indicate which hardware will be used uncomment the appropriate define statement at the beginning of the slave c file in the project Use only one of the following define statements define QL4LINKit Use this define for the QL4 LINkit Board define QL4EVB Use this define for the QL4 EVB Board The sample application responds to message IDs designed for the LIN kit application demo boards The messaging and details regarding this are explained more fully in AN2573 D LIN Kits LIN Evaluation Boards The ASM and C versions are designed to respond to only the default IDs The API version allows the user to d
15. LIC_ISR Interrupt Service Routine Main handler for SLIC interrupts SLIC ISR pragma TRAP PROC void SLIC_ISR void unsigned char temp_SLCSV 0 char ID found 0 If ID not found set IMSG char temp PTB PTBO temp _SLCSV SLCSV Read SLCSV value switch temp _SLCSV switch is temporary measure case 0x00 ___No Interrupts Pending break case 0x04 ____ No Bus Activity BusOff if BusOff 2 LINSleep 1 Set LINSleep flag BusOff 0 Reset BusOff counter break case 0x08 ____TX Buffer Empty Checksum Sent break case 0x0C I____TX Buffer Empty break case 0x10 ____RX Buffer Full Checksum OK TEST if SLCID 0x97 Test message from master oo test code temp_msg buffer 0 SLCDO Load RAM from RX buffers 32 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D Appendix B Software Listings SLIC_LINdriver c temp_msg buffer 1 SLCD1 Load RAM from RX buffers TEST break case 0x14 E EEEE RX Buffer Full No errors _ _ break case 0x18 1E a Bit Error break case Ox1C Je 23 RX Buffer Overrun break case 0x20 1E lt reserved gt break case 0x24 rn Checksum Error break case 0x28 AE EN Byte Framing Error break c
16. True Autobauding up to 120 kbps with No Software Changes The SLIC module on the QL4 represents a level of hardware support for LIN slave applications that offers unparalleled performance This increased performance enables LIN slave node designers to do much more with smaller devices than possible with UART based solutions The SLIC module automatically performs two very important but distinctly separate functions while establishing communication on the LIN bus e Autosynchronization e Autobauding Automatic LIN message frame synchronization autosynchronization is the ability to detect an idle bus and correctly determine when a LIN message frame header has begun In many standard UART solutions this operation can prove problematic because it is possible to erroneously detect a 0x00 data character as a break symbol even when within LIN timing specifications This can happen if the driver software uses the standard UART break detection circuitry without actually measuring the length of the break symbol The ESCI on many Motorola HCO8 MCUs contains a feature controlled by a bit called the LINR bit which prevents this error Autobauding is the ability to derive the LIN bus speed from the synchronization byte in the header Autobauding is possible only if the header is synchronized to the beginning of the message frame The SLIC handles autobauding and sets up to transmit or receive the rest of the message frame at this speed Then
17. age to the SLIC is its ability to dramatically reduce the number of required interrupts and the time spent in servicing those interrupts Table 9 shows a relative comparison of the CPU and interrupt loading impacts of the SLIC and various other driver implementations All have been normalized to 3 2 MHz operation and 8 byte messages to accurately compare the relative performance of each hardware and software combination In the QL4 MCU the internal oscillator speed may be increased to 6 4 MHz by setting the bus frequency select bit BFS in the oscillator status register OSCSTAT This will further reduce the CPU loading by cutting ISR execution times in half This means that it is possible to reduce the average CPU usage on the QL4 to below 0 1 and peak usage to 17 us for an 8 byte LIN message at 9615 bps 24 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D Driver Performance Timer UART and SLIC Compared Table 9 Driver Performance Metrics No of CPU Usage PEEP Std Interrupts LIN Bus CPU Speed sei API Msg Frame Speed MHz 2 8 byte msg Average Peak QY QT bit banged 9 615 T gt drivers N 111 Rx 193 us re 29 rx 5 AN2503 D 19 230 Pe 40 tx o F QY QT bit banged 9 615 n drivers y 97 Rx i 272 us TPN 38 rx AN2599 D 19 230 44 tx EY16 ESCI 9 615 E 29 driv
18. ase 0x2C Nfi uen e a ID received correctly parity OK Perform ID lookup if SLCID LINID Check ID ID found 1 Set ID found flag SLCDO LINdata Load TX buffers SLCD1 0 SLCDLC 0xCl Write DLC code to start TX STD CHECKSUM if SLCID 0x97 Test message from master test code ID_found 1 Set ID found flag SLCDLC 0x41 Write DLC code RX STANDARD CHECKSUM 2 bytes if ID_found 0 warning ALPHA SAMPLE WORKAROUND SLCDLC 0x00 Alpha sample workaround write DLC 0 before IMSG 1 SLCC1_IMSG 1 Set IMSG bit to ignore ID if not found ID_ found 0 reset ID_ found should do anyway on re entry into ISR LINSleep 0 Clear LINSleep flag due to bus activity break case 0x30 5 a ce ID Parity Error break LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com 33 Freescale Semiconductor Inc AN2633 D case 0x34 I_____I Inconsistent Synch Field Error __ break case 0x38 I____ lt reserved gt break case 0x3C ___Wakeup break end switch temp_SLCSV SLCS_ SLCF 1 Clear SLIC interrupt flag end SLIC ISR BRR He He He He EK KE He He He Fe He Fe Fe He RE He He Fe RE EKER ER He He RE He Fe Fe He He ER EKER He He He He He He He He RE He He He He He RE He He He He He He He He He He He He He RE He He He He RE KEK 34 LIN Drivers fo
19. ble EN pin of the device Operation of this feature is beyond the scope of this application note Refer to the documentation for the MC33661 device for more information 8 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D Hardware M68EVB908QL4 Evaluation Board 4 o wm e a Eg C45 q 1UF 3 PEHE TAD ADO KBIO k TR 3 Hemann Fr ri LIN_EW i Taty E T 34125 a ier f x or E al arre H tiad Jir Buns Puma BYPASS CAPACITORS i a ys mg m giie flue tir Tuft Tene Eara Figure 5 Schematic of M68EVB908QL4 Evaluation Board Figure 6 M68EVB908QL4 Evaluation Board LIN Drivers for SLIC Module on the MC68HC908QL4 9 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D The EVB does not support the regulator inhibit function by the physical layer so this must be taken into account when using software that handles sleep mode Care must be taken to ensure that the SLIC module is disabled before disabling the physical layer because recovery from sleep will not result in POR Sleep mode recovery would then need to re enable the physical layer first then re enable the SLIC module Details of this are beyond the scope of this application note SLIC Driver Code Three Versions Three different versions of the SL
20. ding on CPU speed and filter settings This is especially useful for downloading code in a factory programming environment To accommodate higher speed messages changes may be required to ensure e thatthe digital receive filter is adjusted which prevents filtering out valid high speed data e that the physical layer device such as a MC33661 enhanced LIN transceiver slew rate control is adjusted to prevent attenuating the bits of the high speed message Automation of many standard LIN communication functions allows for much smaller and more efficient driver code which frees up vital CPU and memory resources Smaller driver code means that devices with less memory can be used in some applications Applications that require a 4K FLASH when using an ESCI or timer module might easily fit ina 2K FLASH device if using the SLIC module Even in a 2K FLASH device such as HC908QL2 more than 90 of the FLASH memory is available for the application to use Many applications especially motor control systems often have stringent timing requirements to maintain adequate control To service the LIN communications the SLIC module requires a maximum of two interrupts for any standard LIN message frame 1 to 8 data bytes If a message header that the application does not need to handle arrives the SLIC module would require only one interrupt Compared to a UART based solution this reduction in interrupts can mean eliminating as many as 10 interr
21. during the message interrupt handling to send or receive data for this message frame with the proper checksum calculation method Example U8 volatile near MessageDLCTb1 0XC1 0x44 0x47 4 This example shows that the message with ID OxD8 in IdTbl above is 2 bytes long plus checksum uses standard checksum ID not included and it is defined for sending Remember that the order of the messages must be consistent in all previous tables All the arrays except the message buffers must to be named as described above The data type U8 frequently used in the driver and its API is defined as an unsigned 8 bit number For this compiler this is done as unsigned char LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com API Freescale Semiconductor Inc AN2633 D CodeWarrior Project C Source Code SLIC Driver with API The API that comes with the driver makes it easier for the application developer to interface to the driver as it is not necessary to know anything about the communications protocol behind how messages are sent and received Most of this is handled by the SLIC module autonomously so there is not much behind the API but it does provide an abstraction layer between low level driver and application This section describes an overview of the functions and constants used in the API The API includes status constants that describe e Status
22. e message with a certain ID and copying its message data into a buffer The parameters for this function are the ID of the message with parity and a pointer to the buffer where to put the message data LIN_GetMsg returns a status constant describing whether the call was successful LIN _OK LIN_INVALID_ID LIN NO_ID If the status is not LIN OK no data will have been retrieved from the buffer If the message data has been copied into the buffer the status of the message will be changed to show that the message has been read Frame level atomic operation is automatically guaranteed by the fact that while the SLIC_ISR is transferring data from the SLIC module to the message buffer interrupts are suspended Usage example status LIN GetMsg 0x99 MsgData This function is used for copying data to send from a temporary buffer into the message data of the message with a certain ID The parameters for this function are the ID of the message with parity and a pointer to the buffer where the data to send can be found The function returns a status constant describing whether the call was successful or not LIN_OK LIN_INVALID_ID LIN_NO_ID When the message data has been updated the message status will be changed to show that the message has been written The call itself does not send any data on the LIN bus however the next time the master requests this ID the updated data will be sent Frame level atomic operation is guaranteed becaus
23. e the L IN_PutMsg routine disables interrupts during the buffer copy operation Usage example status LIN PutMsg 0x1A MsgData This function returns the current status of the specified message It takes the message ID with parity as a parameter If the ID is not defined the function will return LIN _NO_ID Usage example msgstatus LIN MsgStatus 0x1A This function changes the current driver state from SLEEP to RUN by clearing the LINSleep flag If the driver state is RUN LINSleep 0 the function does nothing It takes no parameters and returns nothing Note This function should be called before calling LIN_Wakeup Usage example LIN _GotoRun LIN Drivers for SLIC Module on the MC68HC908QL4 21 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D LIN_Wakeup Error Handling LIN_Wakeup issues the LIN wake up signal which consists of eight dominant bits including start bit followed by at least four recessive bits including stop bit and a recessive pause This function uses the WAKETX bit feature of the SLIC module to send a single wake up signal on the bus No wake up signal is sent if the driver is in SLEEP state the LINSleep flag is set because the LIN_GotoRun function should have been called before which changes the state to RUN clear LINSleep 0 After the wake up signal is sent there should be a SynchBreak and communication sho
24. ers 3 2 Ao oS N 12 i 39 us n calculated 4 rx ul AN2575 D 19 230 7 tx 0 3 rx LINQL4 ASM 2019 0 2 tx N 34 us AN2633 D 0 5 rx 19 230 0 5 tx 0 4 rx o LINQL4 C aep 0 4 tx N 2 3 2 61 us AN2633 D 0 8 rx 19 230 0 8 tx 0 8 rx LINQL4 API 2613 0 8 tx Y 123 us AN2633 D 1 6 rx Tye 1 7 tx A 9 CPU usage represents the time spent in the communication ISR s vs time spent doing other tasks API functions and handling performed outside of the ISR s is not counted against this metric Average value is reported as a percentage of times but is still a function of CPU speed as LIN communications is asynchronous to CPU operations CPU usage numbers are approximate Peak time represents the longest single interrupt that must be processed From LINO8 Driver User s Manual CPU performance is calculated as L T active T frame 100 where Lis the CPU load in percent T active is the amount of CPU time expended in executing the driver code during T frame T frame is the amount of time required to transmit or receive a regular LIN bus frame of maximum length containing 8 bytes of data 124 bits The required LIN message budget of 40 is also taken into account For Reference T frame 9615 bps 18 055 ms T frame 19230 bps 9 028 ms For received data command messages 0x55 data and checksum used for worst case ISR load EY16 CPU usage info
25. hibbertgroup com Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document Freescale Semiconductor reserves the right to make changes without further notice to any products herein Freescale Semiconductor makes no warranty representation or guarantee regarding the suitability of its products for any particular purpose nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit and specifically disclaims any and all liability including without limitation consequential or incidental damages Typical parameters which may be provided in Freescale Semiconductor data sheets and or specifications can and do vary in different applications and actual performance may vary over time All operating parameters including Typicals must be validated for each customer application by customer s technical experts Freescale Semiconductor does not convey any license under its patent rights nor the rights of others Freescale Semiconductor products are not designed intended or authorized for use as components in systems intended for surgical implant into the body or other applications intended to support or sustain life or for any other applicat
26. ily due to the efficiency of the CodeWarrior compiler and the fact that there is not much code to handle many of the different cases The switch statement in the C ISR is very sparsely populated and the compiler is able to optimize very heavily In more elaborate driver code with support for more messages and features it is likely that the C version would become larger than the ASM version Figure 9 shows the flow of the C based ISR with a SLCSV value of 0x2C ID Received 1 ENTER ISR AND LOAD void SLIC_ISR void E SLCSV INTO TEMPORARY tee z VARIABLE gt temp_SLCV SLCVS Read SLCVS value y switch temp_SLCSV Switch is temporary measure 2 TRAVERSE THE SWITCH case 0x00 Te No interrupts pending CASES UNTIL A MATCH Creat Zo IS FOUND case 0x08 if TX Buffer Empty Checksum sent_ m EXECUTION TIME OF THIS break 7 a WILL VARY DEPENDING SP a n ON HOW MANY CASES case 0x28 ft Byte Framing Error Q D HAVE CODE WHAT ORDER b ee lt ns CASES ARE LISTED IN PER mo AND THE EFFICIENCY AND SETTINGS OF THE COMPILER 3 WHEN FOUND EXECUTE gt case 0x2 c _ID received correctly parity OK_ Q THE CODE FOR THE tee D a APPROPRIATE SERVICE if SLCID LINID Check ID m 2 HANDLER 45 ID found 1 Set ID found flag Z 2 SLCDO LINdata Load TX buffers m 2 SLCD1 0 J z SLCDLC 0xC1 Write DLC code to Sm Start TX STD Checksum a a y OO CD
27. ion in which the failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application Buyer shall indemnify and hold Freescale Semiconductor and its officers employees subsidiaries affiliates and distributors harmless against all claims costs damages and expenses and reasonable attorney fees arising out of directly or indirectly any claim of personal injury or death associated with such unintended or unauthorized use even if such claim alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part O K 2 freescale semiconductor AN2633 D For More Information On This Product Go to www freescale com
28. iver c Author Matt Ruff Revision 0 1 Functions SLIC module routines History Description Notes Motorola 2003 include global h include MC68HC908QL4 h include SLIC LINdriver h ext ext ext ext ern unsigned char temp_msg_buffer 8 Temporary storage of SLIC buffer contents ern unsigned char LINdata ern unsigned char LINID ern unsigned char BusOff extern unsigned char LINSleep 7 7 rrr rrr rr rrr rrr rr ee oo o oo 2 5 2 2 2 2 5 2 SLIC Init Initializes SLIC module Configures SLIC for 1 LIN or BTM mode operation 2 Clock Operation in MCU Wait Mode 3 Receive filter prescaler adjustment for data rate 4 Bit timing setting BTM mode 7 77 rrr rr rr rrr rrr re eo eo ee o oo 2 5 2 25 2 5 void SLIC Init void SLCC1_INITREQ 0 Clear INITREQ bit in SLIC while SLCS_INITACK 1 Wait for INITACK to clear SLCC2_ SLCWCM 0 Wait Clock Mode LIN Drivers for SLIC Module on the MC68HC908QL4 31 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D 0 SLIC clocks continue in CPU WAIT 1 SLIC clocks stop in CPU WAIT SLCP 0x80 RX Filter Prescaler This is only used if a value other than the default is desired vA 00 div 1 01 div 2 Th 10 div 3 default setting 11 div 4 SLCC2_ SLCE 1 Enable SLIC module S
29. iver code e SLIC_LINdriver h header file for the driver The other files serve the same functions as they do in the assembly version project LIN Drivers for SLIC Module on the MC68HC908QL4 15 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D CodeWarrior Project C Source Code SLIC Driver with API The API version of the code is designed to provide essentially the same interface as the one contained in AN2599 D for QT QY LIN slave drivers As mentioned before this driver is included in the LIN kit demo software which can be downloaded free from the Motorola web site It also comes with the M68EVB908QL4 evaluation board It comes in the form of a Metrowerks CodeWarrior 3 0 project LINQL4 API mcp The project structure can be seen below Include RB global h M MCESHCIOSAL4 h AB SLIC_LINdriver h M LiNmsg h a Sources M slave c M vector c Ea Driver source AM Start08 c A MCESHCIOSAL4 C AB SLIC_LINdriver c AB LINmsg c AB LiNapi c EEA Pm AB hcO8GL4 prm E1 a Libs ansi lib Figure 11 CodeWarrior Project LINQL4 API mcp C Source Code with Standard API The LIN driver consists of four files Table 2 Files in LIN Driver File Description SLIC_LINdriver c contains the main driver code LINapi c contains all the driver API functions LINmsg c series LIN message frames are SLIC_LINdriver h header file for the driver 1
30. nd other MCU features for a specific application One of the key advantages to the SLIC module is its ability to simplify user application code Table 8 shows the RAM and ROM usage of the various implementations along with the QY bit banged driver using a timer channel and an ESCI version These numbers show the memory usage for the LIN kit application LIN Drivers for SLIC Module on the MC68HC908QL4 23 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D Table 8 Driver Performance Metrics Driver Code Resource Required Version Std Feature Suck API Level RAM Bytes ROM Bytes Bytes QY QT bit banged MIN 24 8 per 8 byte 536 3 per msg 22 p Pes m N msg S 2503 D MAX 836 3 per msg 22 z p e 7 E 32 12 per 8 byte 1103 driver m msg 487 API AN2599 D a F ESE 19 1 per 8 byte 1130 a divers T msg driver API Sen wW AN2575 D 11 LINQL4 ASM N parron 172 7 o 18 LINQL4 C N Cipra oin 120 20 32 838 driver EINGESAFI Y 412 per 8 byte msg 420 API 33 1 AN2503 D driver assumptions MIN external OSC 9600 bps no SLEEP mode no parity check no bit error checking MAX internal OSC 19200 bps SLEEP parity checking and bit error checking enabled Each also has 7 messages defined using 26 bytes of RAM 2 AN2575 D memory usage data comes from LINO8 driver manual for EY16 Another key advant
31. o 15 slave nodes Information sent on the LIN bus is in the form of message frames which can be of selectable length but always have the same format A message frame has between 1 and 8 bytes of data in addition to the 3 bytes of control and data security information Each message frame starts with the master sending out a synchronization break signal synchbreak field followed by a synchronization field and a message identifier field The slave then responds with the data field which can be between 1 and 8 bytes and then the checksum field The synchbreak field identifies the beginning of a new message frame and provides a regular opportunity for the slave to synchronize on the bus clock The synch field contains the information for the clock synchronization and is always 0x55 An acknowledgement procedure for correctly received LIN messages is not defined in the LIN protocol MESSAGE FRAME INTER FRAME z gt HEADER RESPONSE se ene a I Pg Aa 1 if SYNCH SYNCH INDENT DATA DATA AA DATA A DATA ACHECKSUM BREAK FIELD FIELD FIELD FIELD FIELD FIELD FIELD IN FRAME NTER BYTE RESPONSE SPACE SPACE Figure 1 LIN Message Frame LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D SLIC Module Operation Features and Benefits SLIC Module Operation Features and Benefits
32. of the service calls such as sending or receiving e Status of individual messages such as empty updated or overrun Table 3 LIN Message Status Constants Constant Description Value LIN_OK Service call succeeded without any error 0x00 The ID requested is defined for the node but for the opposite LIN_ INVALID_ID ee seat 0x80 direction sending receiving LIN_NO_ID The message ID requested is not defined for this node 0x7F LIN_INVALID_MODE The service couldn t be called in the current driver state 0x16 Table 4 LIN Message Status Flow Constant Description Value LIN MSG NODATA The data buffer for this message is empty i e data has not Ox01u ig been initialized or received yet LIN _MSG_OK Message data OK i e not overrun and not empty 0x10u LIN_MSG_NOCHANGE The message data has not changed since last read written 0x02u LIN_MSG_UPDATED Message data has been updated 0x20u LIN_ MSG_OVERRUN The message data has not been read and was overwritten 0x04u LIN Drivers for SLIC Module on the MC68HC908QL4 19 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D LIN Message Status Flow API Functions LIN_Init The message status is stored in the table called LinMsgStatus When the LIN driver is initialized all messages will get the status LIN MSG_NODATA Message status will change when the message is
33. oid manipulating pin PTAO since that will disturb the communication with the tool Veat gt Paral e 8 LT1121 1 Ps e 5V 3 al Se 109 7 47 kQ 100 kag 2 2 KQ 1kQ MN 100 nF RESET i won in rN i DD RESET 77 27kQ Vika Al hi 5 V DEBUG PUSH BUTTON o gt Ha S1 A ZZ 9 1V 7 8 47 k ZENER kai Vsup INH WH 6 2 13 9 LIN EN B7 MC68HC908QL4 B0 5 11 MC33399 rx 2 18 B4 SLC Rx B2 Hi7 3 WAKE 4 15 TX g B5 SLC Tx SNE Yyyy 5 OSCILLATOR MODULE DEBUG 2 osc1 7 NA REN 10 ka ie 7 3 1kQ 1 k1 kQ 1 ka GND Figure 3 Schematic of QL4 LIN Kit Board LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc NOTE Freescale Semiconductor Inc AN2633 D Hardware LIN Kit Demo Board o d ps S mi fa m S 2 lt 5 Figure 4 QL4 LIN Kit Board If the application is designed to be powered down in sleep mode there are some things to consider when using the QL4 LIN kit board Because the voltage regulator is connected to the INH pin of the MC33399 physical layer if the EN pin connected to PTB7 of the MCU is driven low in software it will power down the MCU LIN network activity would then cause a power on reset POR and code will begin again from scratch LIN Drivers for SLIC Module on the MC68HC908QL4 7 For More Information On This P
34. ooking for If not Load data byte 0 Load data byte 1 Write DLC TX If additional IDs to be searched for Ignore message frame ID not found Alpha sample workaround write 00 to DLC before IMSG Set IMSG bit Clear LINSleep ID Parity Error service uncomment to termina STD Checksum saw bus check next for next ID 2 bytes traffic handler te service routine code Inconsistent Synch Field Error service handler Wakeup default Load mask for SLCF bit Clear SLCF bit restore from stack return from interrupt uncomment to termina service handler uncomment to termina service handler te service routine code te service routine code 30 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com enter handler here Ap Freescale Semiconductor Inc pendix B Software Listings SLIC_LINdriver c AN2633 D Appendix B Software Listings SLIC_LINdriver c pRB RRR He Fe He Fe He He He Fe Fe He Fe He Fe He He Fe Fe He He Fe KERR EKER ER RE Fe He He He He EKER Fe He e He He He He He He Fe He ER He He He He KEE He He EERE RE He He He ER RE RE RE He He He He He He He He Title SLIC LINdriver c Copyright c Assembler P amp E Microcomputer Systems CASM08Z v3 16 Compiler Codewarrior Revision History Rev Date Who Comments wer eragg oie diarrees O Filename LINQL4 C src SLIC_LINdr
35. r SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D LIN Drivers for SLIC Module on the MC68HC908QL4 35 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc How to Reach Us Home Page www freescale com E mail support freescale com USA Europe or Locations Not Listed Freescale Semiconductor Technical Information Center CH370 1300 N Alma School Road Chandler Arizona 85224 1 800 521 6274 or 1 480 768 2130 support freescale com Europe Middle East and Africa Freescale Halbleiter Deutschland GmbH Technical Information Center Schatzbogen 7 81829 Muenchen Germany 44 1296 380 456 English 46 8 52200080 English 49 89 92103 559 German 33 1 69 35 48 48 French support freescale com Japan Freescale Semiconductor Japan Ltd Headquarters ARCO Tower 15F 1 8 1 Shimo Meguro Meguro ku Tokyo 153 0064 Japan 0120 191014 or 81 3 5437 9125 support japan freescale com Asia Pacific Freescale Semiconductor Hong Kong Ltd Technical Information Center 2 Dai King Street Tai Po Industrial Estate Tai Po N T Hong Kong 800 2666 8080 support asia freescale com For Literature Requests Only Freescale Semiconductor Literature Distribution Center P O Box 5405 Denver Colorado 80217 1 800 441 2447 or 303 675 2140 Fax 303 675 2150 LDCForFreescaleSemiconductor
36. rmation was measured based on 4 9152 MHz CPU frequency then recalculated for a 3 2 MHz CPU frequency LIN Drivers for SLIC Module on the MC68HC908QL4 25 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D Tok Stop heee The difference in the number of interrupts serviced is best seen on an oscilloscope showing the ISR pulses Figure 12 shows the interrupts required to service an 8 byte request message at 9600bps an LL eva A Ls IVAN ll If orton is IEY16 o eect wnnolinenninnnniassainsssienesianssianssianssiansnscnsnissssissanissnnicenainanaisscsissnsicnssiznsnicossisnssisnssicssninseninenninssaisessissssinsssisessisessisassisnssicnanicssnisssnisssninscainsssinsssinsssicccsiconsicnsniccssisessisesnisescisesel 5 00 V MB Ooms of Pattern LH D 5 00 V 3 Dec 2003 5 00 V 2 00ms m gt 7 3 41000ms 19 08 41 Figure 12 8 Byte LIN Request Message and Interrupt Handling for HC908QY4 HC908EY16 and HC908QL4 Channel 1 shows the LIN message as seen at the RX pin of the QL4 slave device Channel R1 is a stored waveform showing the 106 interrupts required to bit bang the message The interrupts seem to extend past the end of the message frame but this is due to the delay between the ID lookup and the beginning of the slave s response Channel R2 is also a stored waveform showing the 12 interrupts required for an EY16 based slave Channel 3 shows
37. roduct Go to www freescale com Freescale Semiconductor Inc AN2633 D Hardware M68EVB908QL4 Evaluation Board The QL4 evaluation board is made from a QL4 with an added enhanced LIN interface which consists of an MC33661 enhanced LIN transceiver and a 5 V regulator an LT1121 chip The board can be programmed either using the RS 232 MONO8 interface or a Cyclone MultiLink tool The primary difference between the EVB and the LIN kit board is the connection of inputs and outputs There is only one LED D1 on the EVB which is used for displaying the least significant data bit This bit is inverted in software to accommodate the circuitry differences in the boards keeping the interface consistent so that a logic 1 turns on the LED The other three bits of data which are output to LEDs D7 D6 and D5 on the LIN kit board are still brought out to PTB1 PTB2 and PTB6 respectively The input button is used differently on the LIN kit board and EVB Because there is not a dedicated button for the application on the EVB the reset button is reused Because the reset function on the QL4 device isn t active unless activated by software in user mode there is no problem using this button for the application Another major difference with running application code on the EVB is the presence of the enhanced LIN transceiver MC33661 This allows the possibility of controlling the physical layer slew rate through software control of the ena
38. ser to build a jump table When using a jump table no matter what interrupt source is being serviced the ISR will begin servicing the interrupt in a fixed amount of time The SLCSV register value is loaded into the index register then used as an offset into the jump table The entries in the jump table point to service handler LIN Drivers for SLIC Module on the MC68HC908QL4 11 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D subroutines which handle each SLCSV value accordingly Figure 7 shows the flow of the assembly based ISR with a SLCSV value of 0x2C ID Received ENTER ISR AND LOAD gt slic _isr SLCSV INTO INDEX psih Push H onto stack REGISTER cirh clear H to ensure proper addressing z ldx SLCSV Load SLCSV value into index register 2 jmp jmptab x SLCSV used as offset into jump table JUMP TO ENTRY IN JUM Jmptab jmp serv0x00 No interrupts pending TABLE FOR INTERRUPT nop SOURCE IN SLCSV a jmp serve 0x2C ID Received Successfully parity OK nop J gt siri wW JUMP DIRECTLY TO jmp serve 0x3C Wakeup m APPROPRIATE nop SERVICE HANDLER SERVICE THE INTERRUPT serve0x2C ID Received Successfully parity OK sex y SOURCE AS NEEDED Performing ID lookup to determine message M NOTE lda SLCID Load up ID of incoming message lt REGARDLESS OF THE cmp LINID Is it the ID we re looking for m LOCATION OF THIS CODE bne
39. so comes with the M68EVB908QL4 evaluation board It comes in the form of a Metrowerks CodeWarrior 3 0 project LINQL4 ASM mcp The project structure can be seen below 4 Include global h MCESHCIOSAL4 h QL4_registers_v0r2 inc EE Sources B slave c E vector c Ea Driver source StartO8 c MCBSHC3908GL4 C SLIC asm 3E Prm B heO8ql4 prm Libs f ansi lib Figure 8 CodeWarrior Project LINQLY ASM mcp Assembly Source Code Table 1 Files in LINQL4 ASM mcp Sample Project File Description SLIC asm pert main driver code The LIN driver is contained in the global h Global variable declarations not used heavily MC68HC908QL4 h MCU register definition header file non standard QL4_ registers _vOr2 inc ASM register definitions file slave c Main application code vector c MCU vector definitions Start08 c Standard HC08 startup code MC68HC908QL4 C MCU register data structure instantiations file also non standard CodeWarrior parameter file for defining memory locations ROM and he08ql4 prm RAM in the MCU LIN Drivers for SLIC Module on the MC68HC908QL4 13 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D CodeWarrior Project C Source Code Basic SLIC Driver In the C and ASM versions of this code the same basic functions are performed The C ISR in this case is just a few bytes smaller than the ASM ISR This is primar
40. t of the system On the LIN kit board for example disabling the physical layer will activate the inhibit function INH pin on the voltage regulator and power down the MCU LIN bus activity will then restore power to the MCU and the code will go through a POR On the EVB however the INH pin of the physical layer is not connected to the regulator at all Turning off the physical layer on the EVB will result in the Rx line to the SLIC being driven to a low state The SLIC should be disabled first to prevent it from trying to interpret this as a break symbol Do NOT try to disable the SLIC from within the SLIC ISR Disable the SLIC only in a code location outside the ISR such as the Check_LIN_Sleep routine where the LINSleep flag is recognized and before the physical layer is disabled CodeWarrior Project Assembly Source Code Basic SLIC Driver The first project described shows a basic C based LIN slave application with a SLIC ISR written in assembly code Writing the ISR in assembly allows the greatest degree of control over the performance and the size of the final code In very small embedded systems such as those used in LIN slave nodes code size and performance efficiency are critical to getting the most out of very few resources One of the key features of handling the ISR in assembly code is to use the design of the SLIC module to ensure maximum execution efficiency The SLIC state vector register SLCSV is encoded to allow the u
41. tains information that conflicts with the information in the device data sheet the data sheet should be considered to have the most current and correct data Cyclone and MultiLink are registered trademarks of P amp E Microcomputer Systems Inc This product incorporates SuperFlash technology licensed from SST e oe Freescale Semiconductor Inc 2004 All rights reserved freescale semiconductor For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D SLIC Module LIN Communication The SLIC module automates many LIN bus functions allowing more of the CPU and memory resources to be used for the user application This application note compares CPU and memory usage details among timer based UART based solutions and SLIC based solutions Other SLIC module features include e Automatic LIN frame synchronization e Autobauding up to and well exceeding LIN standard bus speeds e LIN error detection LIN message handling Automatic checksum generation and verification for both types ID parity checking The SLIC module is compatible with LIN 1 3 and LIN 2 0 and requires almost no configuration code and very minimal driver code More details of the SLIC module are explained in SLIC Module Operation Features and Benefits The driver has been evaluated at 9 615 kbps 10 417 kbps and 19 230 kbps A LIN network consists of a single master node and up t
42. the SLIC receives the identifier for the message frame and checks the parity bits to ensure the data integrity of the identifier byte No software intervention is required until this point when the ID is presented to the application or driver software The software performs a lookup and then decides what to do for this message frame Because LIN was designed to use inexpensive RC oscillators the SLIC module was designed to allow an input clock tolerance of about 50 and ensure that the accuracy of LIN communication is 1 or less This wide range of clock accuracy means that in any LIN slave application it is not necessary to trim the internal oscillator to establish and maintain LIN communications Motorola internal RC oscillators such as the one on the HC908QL4 device typically come from the factory with a guaranteed tolerance of 25 before trimming This also means that ROM devices are perfectly suited to be used without any nonvolatile memory at all because they would never need to store a trim value LIN Drivers for SLIC Module on the MC68HC908QL4 3 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D High Speed Communications and Factory Programming Smaller Faster Driver Code Fewer Interrupts to Service The SLIC is also capable of high speed operations without the need to change driver code It will automatically synchronize to LIN messages up to 120 kbps depen
43. uld resume from the master LIN_Wakeup takes no parameters There are two possible return values either LIN OK the wake up signal was successfully sent or LIN_INVALID_ MODE if the current driver state is SLEEP Usage example status LIN Wakeup The driver detects two types of errors in the LIN message bit errors and checksum errors A bit error is detected when a recessive bit is sent and a dominant bit is detected on the bus This indicates that the bus is controlled by another node or shorted to GND In either case the transmission is aborted and the BitERROR flag is set The SLIC automatically detects bit errors and this function in the ISR simply sets the BitERROR flag in the API The user must then clear the flag when the BitERROR condition is handled generally setting up for a re transmission of the corrupted error frame The node receiving data will calculate the checksum by doing a modulo 256 sum of the message data bits This checksum must match the received checksum If not the message is corrupt and the receiving node will set the ChecksumERROR flag and ignore the received data As with the bit error checksum errors are automatically detected by the SLIC module then the ISR simply sets the ChecksumERROR flag Note that a checksum error might occur if the message DLC value in the MessageDLCTbI array in LINmsg c was set incorrectly The error flags are single bit field values that are set by the driver
44. upts per message frame Figure 2 shows the interrupts required for servicing an 8 byte LIN request frame using both the SLIC module and a traditional UART based solution Channel 1 third trace from top of the scope capture shows the ISR firing on the SLIC module two interrupts required Channel 4 fourth trace from top inverted polarity shows that 12 interrupts are required to service the same message with a UART based controller LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D SLIC Module Operation Features and Benefits ALLEO TE T Wa O NEA ARESU ED RIN Amide r AERA 4 eek Fee baia iia a eee Ge BG ie a y le 500mvV Ch2 mi M1 00ms A Ch2 X 180mY 912 60 Figure 2 SLIC versus UART Based Interrupt Handling With 10 fewer interrupts to service an 83 3 reduction in interrupts the CPU is free for a much greater amount of time Using the SLIC module instead of a UART based solution significantly reduces the chance of an interrupt interfering with other application operations Faster More Efficient In addition to reducing the number of interrupts required to service a LIN frame Interrupt Servicing two interrupts only the SLIC module has been designed to maximize the efficiency of the interrupt service routine ISR which minimizes the CPU requirements for LIN communications A patented encoding method is used
45. ynamically change the ID at runtime as described in AN2573 D One key feature in all versions is a sleep mode function which turns off the LEDs when no activity has been detected on the bus or button for a long time Sleep mode is implemented by regularly calling the Check_LIN_Sleep routine 10 LIN Drivers for SLIC Module on the MC68HC908QL4 For More Information On This Product Go to www freescale com Freescale Semiconductor Inc AN2633 D CodeWarrior Project Assembly Source Code Basic SLIC Driver in the main routine This monitors LINSleep flag and sets power states accordingly Due to differences in hardware between the EVB and LIN kit board this routine only turns off the LEDs to indicate the sleep mode condition In actual applications it is likely the designer would power down the node for sleep mode for energy conservation Exact procedures for putting the SLIC to sleep and waking it up again are beyond the scope of this note but it is important to remember a few basic concepts Like many communication peripheral modules the SLIC contains a state machine that synchronizes to the LIN message traffic It is important to safely disable the SLIC by writing the INITREQ bit before turning off the physical layer Doing this will avoid confusing the state machine and inducing potentially undesirable side effects Depending on external circuitry turning off the physical layer device can have different effects on the res
Download Pdf Manuals
Related Search
Related Contents
EastWest/Quantum Leap Pianos Silver Manual Thomson all-in-one home cinema system DPL943W hielera estimado cliente contenido descripción del producto SHIMATORK SHIMATORK Industrial Balances Nokia 7230 Cell Phone User Manual Kensington Portafolio™ Soft Folio Case for iPad mini™ 3/2/1 - Pink Yun Shield User Manual Copyright © All rights reserved.
Failed to retrieve file