| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
AN2103 Local Interconnect Network (LIN) Demonstration Alan D
Top Searches for this datasheetOrder this document AN2103/D AN2103 Local Interconnect Network (LIN) Demonstration Alan Devine Systems Engineering East Kilbride, Scotland. Freescale Semiconductor, Inc. Introduction This application note describes demo that designed show March 2000. project intended demonstrate protocol, tools Motorola products that were available. Although demo purely visual does represent particular application, does introduce many features that would implemented actual applications, such CAN-LIN gateway, sleep mode, messaging scheme, drivers tools. hardware designed flexible easily configured drive many real applications. introduction protocol general description demo presented first, followed detailed description hardware software, including schematics flow diagrams. code listings included Appendix. Local Interconnect Network (LIN) inexpensive serial communications protocol, which effectively supports remote application within car's network. particularly intended mechatronic nodes distributed automotive applications, equally suited industrial applications. intended complement existing network leading hierarchical networks within cars. protocol's main features listed below: Single master, multiple slave (i.e. arbitration) Motorola, Inc., 2000 More Information This Product, www.freescale.com AN2103 Freescale Semiconductor, Inc. Application Note Single wire communications 20Kbit/s Guaranteed latency times Variable length data frame byte) Configuration flexibility Multi-cast reception with time synchronization, without crystals ceramic resonators. Data checksum error detection Detection defect nodes cost silicon implementation based standard UART/SCI hardware Enabler hierarchical networks Freescale Semiconductor, Inc. Data transferred across fixed form messages selectable lengths. master task transmits header that consists break signal followed synchronization identifier fields. slaves respond with data frame that consists between data bytes plus bytes control information. Figure shows communication concept message transfer message format. slave control unit master control unit master task slave task slave control unit slave task slave task MESSAGE FRAME HEADER RESPONSE SYNCH BREAK SYNCH FIELD IDENT FIELD In-Frame response space DATA FIELD DATA FIELD DATA FIELD CHECKSUM FIELD Interbyte Space Figure Message frame AN2103 More Information This Product, www.freescale.com MOTOROLA Local Interconnect Network (LIN) Header Frame master controls traffic network. master initiates communication transmitting header frame with synchronization identifier information. slave, including slave task master control unit, respond with data frame. Only slave respond each identifier. However, number slaves configured recognize particular identifier driven bus. master control unit transfer data number slaves through slave task. i.e. master's slave task responds header (sent master) transmits data bus. other slaves simultaneously receive data frame. Freescale Semiconductor, Inc. Header Frame header frame consists main parts: SYNCH BREAK signal, SYNCH FIELD IDENTIFIER. SYNCH BREAK used identify beginning message frame allow slaves synchronise master's clock. unique signal that parts: Dominant SYNCH BREAK that longer than regular dominant stream, synchronisation delimiter that required enable detection start following SYNCH FIELD. Figure shows SYNCH BREAK field. SYNCH BREAK FIELD SYNCH FIELD TSYNBRK TSYNDEL Figure SYNCH BREAK field timing specification SYNCH_BREAK field dependent tolerance slave node's clock source. master always required transmit dominant TSYNBRK signal, that minimum bits, measured master's time base. slave detects break signal dominant longer than regular stream. slave's clock source tolerance lower than (FTOL_UNSYNCH) SYNCH BREAK THRESHOLD times (number dominant bits required recognised SYNCH BREAK FIELD) measured slave's time base. clock source's tolerance less than (FTOL_SYNCH threshold reduced dominant bits. second part header SYNCH FIELD that contains pattern 0x55 allow slave synchronize with master. This AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note allows cost microcontrollers with internal oscillators used slave nodes. NOTE: Internal oscillators have tolerance that requires trimmed (actively changed) reliable communication maintained. final part header IDENTIFIER FIELD that denotes content length message. content represented identifier bits parity bits. Identifier bits specify number data fields message. Figure shows identifier field. IDENTIFIER FIELD Freescale Semiconductor, Inc. START Figure Identifier Field parity information calculated using mixed parity algorithm that prevents bits being recessive dominant. Response Frame response frame always transmitted slave task (this slave master). consists between data fields checksum field. data fields consist bits data transmitted first. checksum contains inverted modulo over data bytes. reserved Sleep Mode Frame with fixed 0x80 identifier specified original version specification. version later Sleep Mode Frame been removed replaced reserved identifiers, which described section 2.4. However, demo software developed original specification uses fixed identifier 0x80 Sleep Mode Frame. Sleep Mode Frame NOTE: slave node bring sleep mode transmitting WAKE_UP signal). However, only master that allowed network sleep. Refer specifications further details. AN2103 More Information This Product, www.freescale.com MOTOROLA Local Interconnect Network (LIN) Reserved Identifiers Reserved Identifiers 2.4.1 Command Frame Identifiers Version specification contains reserved identifiers; Command frame identifiers Extended frame identifiers. COMMAND FRAME IDENTIFIERS have been reserved broadcast general command requests from master participants. frame structure identical regular 8-byte message frames with following reserved IDENTIFIER FIELDS: 0x3C Download frame 0x7D Upload frame download frame used send commands data from master slave nodes. upload frame used trigger slave nodes (being addressed prior download frame) send data master. Additionally, command frames with their first byte containing 0x00 0x7F reserved specific consortium. remaining frames free assigned user. Freescale Semiconductor, Inc. 2.4.2 Sleep Mode Command SLEEP MODE COMMAND used broadcast sleep mode nodes. SLEEP MODE COMMAND download COMMAND FRAME with first data byte 0x00 EXTENDED FRAME IDENTIFIERS have been reserved allow embedding user defined message formats future expansion without violating specification. frame structure identical regular 8-byte message frames with following reserved IDENTIFIER FIELDS: 0xFE User defined extended frame 0xBF Future extension identifier followed arbitrary number BYTE FIELDS. frame length, communication concept data content specified. Also, length coding within field does apply EXTENDED frame identifiers. 2.4.3 Extended Frame Identifier AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Demo Description Demo consists single master node twelve slave nodes mounted `clock face' (see Figure details). master controls slave nodes. schedules messages that flash slave's LEDs predetermined sequence. addition, request from master, each slave node responds with status messages. status returned value switches mounted slave hardware. value changed, real time, monitored buses. demo several modes operation that described below. Each mode selected message switch master node, when operated standalone mode. Finally, master node removed demo driven using LINspector configured emulation mode. Freescale Semiconductor, Inc. Figure Clock Face Hardware AN2103 More Information This Product, www.freescale.com MOTOROLA Demo Description Demo Configuration: NOTE: LINspector cost effective tool that used variety situations, including development, testing verification. driven from configuration description file, which contains details network. used monitor traffic, provide detailed timing information advanced triggering functions. Additionally, enables basic advanced emulation features that allow user `replace' number nodes network. Refer VCT's page more details. http://www.vct.se Freescale Semiconductor, Inc. Demo Configuration: 3.1.1 Standard: Software master node used control demo. LINspector used monitor activity. node used activate different demo modes display status messages. 3.1.2 Standalone: Software master node used control demo. LINspector used monitor activity. switches master used select modes 3.1.3 Emulator: LINspector used control demo display activity. Modes operation: 3.2.1 Default Mode: this mode, master sequentially transmits messages slave nodes that control their LEDs. slaves respond with settings their switches. switch settings translated message transmitted onto bus. slave node removed NO_NODE code (0x00) transmitted this mode, master periodically transmits messages that each slave node simultaneously receives. transmitted messages switch slave's LEDs. master node controls pattern. 3.2.2 Broadcast Mode: AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 3.2.3 Ident Mode: This mode primarily used set-up demo. master transmits broadcast message that each slave node receives. reception this message, slaves output their LEDs. This demo's power mode. master transmits sleep command that signals slaves enter sleep mode disabling their voltage regulators. master also enters sleep mode once sleep command been successfully transmitted. slave wake-up demo pressing buttons around perimeter `clock face'. slave node that woken wakes entire network transmitting wake-up sequence bus. physical interface (MC33399) supports wake-up from from external source. detection valid wake-up signal, physical interface drives inhibit output signal low, enabling external voltage regulator this feature used). Alternatively, inhibit output used drive microcontroller. Refer MC33399 data sheet specific application details. 3.2.4 Sleep Mode: Freescale Semiconductor, Inc. Messaging Scheme simple data driven messaging scheme used control demo. Each slave node statically configured recognize message identifiers. These NodeX_Write, NodeX_Read Broadcast message, where denotes node number. This allows master transmit commands data individual nodes each node transmit status responses back master. broadcast message identifier common each slave node. allows master transmit data nodes simultaneously. Table lists messages that were used demo. Table Messages Message Name Node1_Write Node2_Write Node3_Write Node4_Write Node5_Write Node6_Write Message (LIN LINMsg01 (0xC1) LINMsg02 (0x42) LINMsg03 (0x03) LINMsg04 (0xC4) LINMsg05 (0x85) LINMsg06 (0x06) Slave Response Source Master Master Master Master Master Master Slave Response Destination Slave_ID Slave_ID Slave_ID Slave_ID Slave_ID Slave_ID Description Master transmits node1 control command Master transmits node2 control command Master transmits node3 control command Master transmits node4 control command Master transmits node5 control command Master transmits node6 control command AN2103 More Information This Product, www.freescale.com MOTOROLA Demo Description Messaging Scheme Table Messages Message Name Node7_Write Node8_Write Node9_Write Node10_Write Node11_Write Node12_Write Node1_Read Node2_Read Node3_Read Node4_Read Node5_Read Node6_Read Node7_Read Node8_Read Node9_Read Node10_Read Node11_Read Node12_Read BroadCast Message (LIN LINMsg07 (0x47) LINMsg08 (0x08) LINMsg09 (0x49) Slave Response Source Master Master Master Slave Response Destination Slave_ID Slave_ID Slave_ID Slave_ID Slave_ID Slave_ID Master Master Master Master Master Master Master Master Master Master Master Master slave nodes Description Master transmits node7 control command Master transmits node8 control command Master transmits node9 control command Master transmits node10 control command Master transmits node11 control command Master transmits node12 control command Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Slave transmits status data back master. Master transmits command slave nodes LINMsg0A (0xCA) Master LINMsg0B (0x8B) LINMsg0C (0x4C) LINMsg11 (0x11) LINMsg12 (0x92) LINMsg13 (0xD3) LINMsg14 (0x14) LINMsg15 (0x55) LINMsg16 (0xD6) LINMsg17 (0x97) LINMsg18 (0xD8) LINMsg19 (0x99) LINMsg1A (0x1A) LINMsg1B (0x5B) LINMsg1C (0x9C) LINMsg0F (0x80) Master Master Node1 Node2 Node3 Node4 Node5 Node6 Node7 Node8 Node9 Node10 Node11 Node12 Master Freescale Semiconductor, Inc. messages selected demo bytes long. first byte command byte second data. Table details NodeX_Write Message Format. AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note NodeX_Write Message Format Table NodeX_Write Messages Identifier table Byte1 Command Byte Byte2 Pattern Write Message Command Byte Command SLAVE_LEDS_COMMAND CLOCK_LEDS_COMMAND Code 0x01 0x03 Freescale Semiconductor, Inc. Broadcast_ Message Format Table Broadcast Messages Identifier table Byte1 Command Byte Byte2 Pattern Broadcast Message Command Byte Command BROADCAST_COMMAND IDENT_COMMAND SLEEP_COMMAND Code 0x02 0x04 0x80 NOTE: pattern sent with command byte. Pattern written slave node LEDs. IDENT SLEEP commands pattern ignored. NodeX_Read Message Format Table NodeX_Read Messages Identifier table Byte1 NodeID Byte2 Switch message format adopted allow flexibility within demo. Additional commands added without much effort. slaves also easily decode various commands accordingly. Another benefit that master node software total control over pattern that slaves output. order change LED's sequence, only master software changed. AN2103 More Information This Product, www.freescale.com MOTOROLA Demo Description Hardware Description actual applications signal-based messaging scheme should adopted. Refer section Section Motorola Drivers details Motorola's signal-based API. Hardware Description Freescale Semiconductor, Inc. demo consists nodes; single master slaves. hardware each node identical shown schematic (see appendix schematic details). Identical hardware used enable universal master/slave board designed. This makes slaves more flexible reduces demo cost. main drawback adopting this common solution that microcontroller required master node, MC68HC908AZ60, suitable slave nodes because additional functionality (particularly CAN). This makes expensive typical slave node. Figure shows block diagram hardware. Table details more suitable slave microcontrollers. Contact Motorola further details (www.mcu.motsps.com). AZ60 Vreg (LT1121) Monitor Mode D-Type Connector Output Drive CANH/L Wake-Up select (MC33388) TX/RX Control C33399 TX/RX Control Input Switch Input Figure Master/Slave Hardware AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note hardware several functions that make design flexible suitable other general applications. Table Slave Devices Slave MCUs Device 68HC908JK3 68HC908JL3 68HC908JK1 68HC08AB16 68HC908EY8 FLASH 1.5K Features Timer, PWM, Timer, PWM, Timer, PWM, Timer, PWM, ATD, SCI, Timers, ATD, SPI, Enhanced Freescale Semiconductor, Inc. Slave HyperIntegration/Mechatronics Device 68HC05PV8 68HC805PV8 33393ROM FLASH EEPROM Features Timer, PWM, A/D, OSC, I/O, OP-Amp, Timer, PWM, A/D, OSC, I/O, OP-Amp, Timer, Osc, 2x175mA H-Bridge, Mechatronic package 3.4.1 Monitor Mode hardware additional circuitry included allow microcontroller communicate with monitor mode. This enables in-circuit Flash programming simple debugging performed. Hiware's MON08 target used application development. MC33399 used demo. This interface serial link interface designed provide bi-directional, half-duplex communication interfacing automotive applications. similar ISO9141 interface, additional features specific protocol. These features wake-up from bus, wakeup from external source slew rate control reduce emissions. Refer MC33399 data sheet detailed description application diagrams. addition interface, each node physical interface (MC33388). This required master node, simple gateway implemented. Each node LEDs green) switches. LEDs driven directly from Port configured output, used demonstrate protocol sequencing messages from AN2103 3.4.2 Physical Interface (MC33399) 3.4.3 Physical Interface 3.4.4 LEDs Switch interface More Information This Product, www.freescale.com MOTOROLA Software Description Motorola Drivers master. switches input Port allow each node have status identifier value that changed real time transmitted bus. LEDs switches positioned edge boards easily removed board used drive actual application. example, port lines that interface LEDs switches could connected power drive board could used control motors mirror module. This makes board very flexible allows quick prototyping applications. 3.4.5 Motorola Components used MC68HC908AZ60 General purpose flash with CAN. MC33399 Physical interface. MC33388 speed, fault tolerant, physical interface. Freescale Semiconductor, Inc. Software Description demo comprises single master slave nodes. master software responsible scheduling messages, providing gateway general communications. slave software interrogates header frames transmitted either receives response frame from another slave transmits response frame bus. Each slave waits pre-configured message, decodes command either outputs data port, NodeX_Write broadcast message, transmits status message network, NodeX_Read message detected. code each slave practically identical, only difference being messages configured specific individual nodes. Table details. master slave code implementations both Motorola HC08 level drivers manage communications. drivers application code demo described this section. data flow diagrams flow charts included. Refer appendix code listing. Motorola Drivers driver provides full protocol eliminating application code from implementing level kernel. user interfaces with drivers, statically compile time dynamically time through API. versions drivers exist: with custom Motorola second with API. project used Motorola drivers. AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Motorola entirely message based. message identifiers specific node configured compile time through header files. application accesses data transmitted using LIN_GetMsg() LIN_PutMsg() services. application retrieves transmits data associated with identifier. (The address buffer that contains data transmitted received message identifier passed driver, application). drivers easily used with additional tools linked with application code. main difference that signal based. application code does access entire message data, only specific signals. signal consists more bits data. drivers provide services access particular signals varying lengths. bit, 2-8bits 9-16bits). order drivers additional description file required that describes signals that specific particular node. This description file then converted header files additional tool required this) included with application. Every node network requires separate description file that contains specific signals. This file also used with LINspector tool development evaluation. provision connect several hardware interfaces (more than SCI). Drivers currently available HC05, HC08 HC12 families microcontrollers. Details HC08 implementation given below. Freescale Semiconductor, Inc. Node Master Slave LINBaud Rate(bps) 20000 20000 frequency load <5%/6% (bytes) 20/21 (bytes) 1391 Stack (bytes) 1071/689 <34/19 Note1: Figures exclude message overhead Note2: Motorola API/LIN Contact Motorola Software Systems further information. AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Motorola Drivers 4.1.1 Static Configuration drivers statically configured through header files, lincfg.h linmsgid.h. lincfg.h file used provide general configuration information, such baud rate timer pre-scalers. information this file same each node network, assuming they same target hardware. linmsgid.h file used define node's messages whether they received transmitted. This file usually unique every node network. further details refer drivers manual demo configuration files. interface with drivers. application code calls time services provided driver, during execution. services used demo software described below. Refer driver manual full descriptions Motorola API. LIN_Init service performs initialization driver. function must called before other service call made. service initializes following functions: Sets baud rate (Information entered lincfg.h file) Assigns physical interface pins Sets idle state Clears error flags counters Clears data buffers Change state drivers Initializes variables unsigned char LIN_Init (void); Master, Slave None LIN_OK 4.1.2 Driver Freescale Semiconductor, Inc. 4.1.2.1 LIN_Init: Syntax: Applicable: Parameters: Return: AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.1.2.2 LIN_GetMsg: LIN_GetMsg service retrieves current content specified message buffer application defined buffer unsigned char LIN_GetMsg (unsigned char MsgId, unsigned char Data); Applicable: Master, Slave Parameters: MsgId Message identifier Data Pointer memory buffer where received data stored. Return: LIN_OK, LIN_NO_ID, LIN_INVALID_ID LIN_MSG_NODATA 4.1.2.3 LIN_PutMsg: LIN_PutMsg service transmits current contents specified message buffer application specified message buffer. unsigned char LIN_PutMsg (unsigned char MsgId, unsigned char Data); Applicable: Master, Slave Parameters: MsgId Message identifier Data Pointer memory buffer where data transmitted. Return: LIN_OK, LIN_NO_ID LIN_INVALID_ID 4.1.2.4 LIN_RequestMsg: LIN_RequestMsg service transmits message identifiers header frame Syntax: Applicable: Parameters: Return: unsigned char LIN_RequestMsg (unsigned char MsgId); Master MsgId Message identifier LIN_OK, LIN_REQ_PENDING LIN_MSG_SLEEP Syntax: Syntax: Freescale Semiconductor, Inc. AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation 4.1.2.5 LIN_MsgStatus: LIN_MsgStatus service returns current status specified message buffer. unsigned char LIN_MsgStatus (unsigned char MsgId); Master, Slave MsgId Message identifier LIN_NO_ID, LIN_OK, LIN_MSG_NOCHANGE LIN_MSG_NODATA master software main tasks that schedule messages provide gateway. scheduler operates from periodic tick, driven from Timer overflow, transmits header frame every150ms. gateway function driven from CANRx interrupt either changes demo mode transmits message specific slave node. Figure shows data flow diagram master software. PortD Syntax: Applicable: Parameters: Return: Freescale Semiconductor, Inc. Master code implementation CANRxISR SCITx RequestMsg Message Handler GetMsg Demo Mode PutMsg Drivers Port SCIRx Message Data PortCAN CANRx CANTx msCAN Buffer Port Data Global Data Buffer Demo Mode CANTX Data Transmit Tramsmit CANMsg Write Data Read Data RequestMSG Message Data Schedule 150ms Figure Master Data flow Diagram AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.2.1 Demo Modes discussed demo several modes operation that user selectable. mode controlled message switch master PEC, when operated standalone mode. mode changed time. Table shows messages switch positions that select different modes. Table Mode Selection Table Mode Selection Table Mode Default Broadcast Ident Sleep Message 0x00, Byte0=0x0E, 0x00 0x00, Byte0=0x0E, 0x01 0x00, Byte0=0x0E, 0x02 0x00, Byte0=0x0E, 0x03 Switch Position Freescale Semiconductor, Inc. mode select controlled ScheduleMessage function. software reads demomode control variable depending value calls default message handler, broadcast message handler, ident message handler sleep message handler. control variable initialized DEFAULT mode reset, updated directly from switch Port from message. AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation Start Transmit ALIVE Message Update demomode varible with mode select switch settings Standalone Mode Freescale Semiconductor, Inc. DEFAULT Mode Call DefaultMsgHandler Call BroadcastMsgHandler BROADCAST Mode IDENT Mode Call IdentMsgHandler Call SleepMsgHandler SLEEP Mode Figure ScheduleMessage Flow Diagram AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Each mode software described below: 4.2.1.1 Default mode default mode software executes loop that sequentially transmits messages each slave node. Table sequence. first message NodeX_Read message that requests status response from slave indicate that present. master does receive slave response within 10mS timeout assumed that node present NO_NODE code (0x00) transmitted bus. second message transmitted (assuming node present) NodeX_Write message that transmits command byte data byte specific slave. slave decodes command outputs data port. status response message checked changed since last interrogation. changed translated message transmitted onto bus. status information updated before function exited. Freescale Semiconductor, Inc. NOTE: transmission performed demo standalone mode. scheduler software exits this function then waits main loop before transmitting next node sequence. node number transmitted controlled TIMBOVF_ISR. main loop further details. AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation Table Schedule Sequence Default Message Sequence Node Number REPEAT Data ALL_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON ALL_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON RED_LEDS_ON GREEN_LEDS_ON REPEAT Freescale Semiconductor, Inc. default message table shows order that nodes written data that transmitted. AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Start Reset Index Index ithin range Freescale Semiconductor, Inc. Index alulate AltScheduleIndex (AltScheduleIndex ScheduleIndex) Transmit Function pass ScheduleIndex, RED_LEDS_ON data &MsgReadBuf Transmit Function pass AltScheduleIndex, GREEN_LEDS_ON data &MsgReadBuf2 Transmit Function pass ScheduleIndex, ALL_LEDS_ON data &MsgReadBuf1 Status Changed Standalone Mode Transmit status Update Status Figure Default Mode Flow Diagram AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation Start Initialise timeout count flags Transmit ReadMsg header frame Freescale Semiconductor, Inc. Start Timeout Timeout NewMsg Data Stop Timeout NewMsg Data Updata MsgRead Buffer with NO_NODE command Store data MsgRead buffer Transmit SLAVES_LED_COMMAND with data byte passed into function Figure Default Transmit Function AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.2.1.2 Broadcast Mode this mode, master software periodically transmits broadcast message which received every slave node. first byte message contains broadcast command, second byte contains data byte that each slave outputs port. single shifted through data byte from bit0 bit7, sequence then reversed repeated. data bytes broadcast stored lookup table. Table below details. Table Broadcast Table 0x01 0x03 0x07 0x0F 0x1F 0x3F 0x7F 0xFF Freescale Semiconductor, Inc. NOTE: lookup table used allow pattern sequence changed with ease AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation Start Reset Index Index within range Freescale Semiconductor, Inc. Load Write Buffer with Command data transmitted Transfer command data Broadcast messge transmit buffer Request Transmission Broadcast Message Transmission Complete Index equal Initialise conter (UpDownControl Initialise Down conter (UpDownControl Index equal Figure Broadcast Mode Flow Diagram AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.2.1.3 IDENT Mode this mode, master software periodically transmits broadcast message with IDENT command. Each slave node receives this command outputs individual identifier port. NOTE: slave pre-programmed with identifier. Start Freescale Semiconductor, Inc. Load Write Buffer with Ident Command data transmitted Transfer command data Broadcast messge transmit buffer Request Transmission Broadcast Message Transmission Complete Figure Ident Mode Flow Diagram AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation 4.2.1.4 Sleep Mode this mode, demo enters power state switching voltage regulator. master node transmits SLEEP command that received slave nodes. Once SLEEP command been successfully transmitted, master disables voltage regulator driving interface into Sleep mode. software then waits infinite loop until regulator disabled. master only node that issue SLEEP command. master woken wake-up request initiated slave nodes. device recognizes specific wake-up message driven onto bus. brings node sleep mode turning voltage regulator. Freescale Semiconductor, Inc. Start Enable control ports output (PTF pins output) Disable device into NORMAL mode into SLEEP_RQ mode into SLEEP mode Wait forever Figure Sleep Mode Flow Diagram AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.2.2 Communication master software also provides communication implements simple gateway. receive transmit functions described below: NOTE: communication occur when demo configured standalone mode. receiver function interrupt driven. message passes filters written into receive buffer receive interrupt request issued. CANRx sets msgrxd flag that indicates that message been received clears interrupt flag enable further interrupts. main routine, discussed below, polls msgrxd flag, waiting until set. When message received, code calls MsgHandlerTable (array pointers functions) jumps appropriate MsgHandlerFunction. function that executed dependent first byte received message. This byte, masked with 0x0F, determines index MsgHandlerTable subsequently handler that code executes. basis communication gateway function performed using series message handlers. These described below: This handler used transmit message particular slave node. node that message transmitted determined index (CanMsgIndex). index calculated from message that received. slaves receive messages control external button around circumference `clock face'. Start 4.2.2.1 Receiving Messages Freescale Semiconductor, Inc. 4.2.2.2 Message Handlers 4.2.2.2.1 Common Message Handler Transmit CLOCK_LED_COMMAND slave node denotes node number >=12) Figure Message Handler (1-12) flow diagrams AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation 4.2.2.2.2 SleepHandler 4.2.2.2.3 ModeSelect Handler sleep mode description This function decodes mode select message writes appropriate value demomode variable. Start Freescale Semiconductor, Inc. DEFAULT MODE demomode DEFAULT BROADCAST MODE demomode BROADCAST Reset Broadcast index IDENT MODE demomode IDENT Figure ModeSelectHandler flow diagrams 4.2.2.2.4 DefaultHandler This handler consists function prototype. This included expandability ensure that code does `run away' even invalid entry message handler vector table accessed, i.e. unused entries table jump DefaultMessage handler. AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.2.2.3 Transmitting Messages transmitter function called from initialisation default mode functions. identifier data transmitted written TxBuffer0 transmitted when idle. function that transmits message, TxCANBuffer(), receives pointer structure that contains data transmitted TxBuffer number arguments. Start Start Freescale Semiconductor, Inc. Calculate message transmitted copy StatusMsg field buffer empty Calculate number data bytes transmitted store value StatusMsg field Load CANTx buffer with message Copy data bytes transmitted StatusMsg field Load CANTx buffer with data bytes Call TxCANBuffer function pass address StatusMsg CANTx buffer number Load CANTx buffer with data length byte Request Transmission (clear TXE0 flag) Figure Transmit flow diagrams AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Master code implementation 4.2.2.4 Master Node Main Loop main routine essentially simple infinite loop that waits either msgrxd system flag loopcontrol system flag cleared. msgrxd flag CANRx_ISR when message received. flag set, MsgHandlerTable called appropriate handler routine executed described Receiving Messages section. loopcontrol flag cleared periodically TIMBOVF_ISR, which overflows every 150ms. When flag cleared, ScheduleMsg function called selected mode executed. Once message received mode executed, main function resets appropriate flags returns infinite loop waiting flag change again. main loop also performs initialization, calling appropriate initialization function, before infinite loop entered. Initialisation registers, drivers application also performed. Freescale Semiconductor, Inc. AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Start Initialise Register Initialise Drivers Transmit Alive Message Check demo mode flag Initialise Schedule Table Initialise loop control flag Freescale Semiconductor, Inc. LoopControl flag clear msgrxd LoopControl Flag clear Schedule Message transmitted msgrxd Flag LoopControl Flag Call Message Handler Table Execute specific handler Clear msgrxd Flag Figure Main Loop flow diagram AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Slave Code description Slave Code description slave code entirely message driven. software each node practically identical, only difference being messages node configured recognize nodeID. individual slaves configured react preprogrammed message identifiers: NodeX_Write, NodeX_Read common broadcast message (NodeX_Write message that every slave programmed receive). Table details. Each slave monitors every header that master drives bus, only reacts configured identifiers. NodeX_Write message detected, receives message data, decodes command, either writes output port external output enters SLEEP mode. NodeX_Read message detected, slave automatically transmits status information bytes (i.e. switch settings) bus. Received messages handled exactly same master code handles messages. When message received (NodeX_Write) code calls MsgHandlerTable (array pointers functions) jumps appropriate MsgHandlerFunction. Periodic PortD Freescale Semiconductor, Inc. Message Status Status Read Port Data Read omandData MsgIndex PortB SCIRx Port SCITx Drivers GetMsg PutMsg Golbal Data Buffer Read Data Write Port Data Write Port Data Message Handler PortE Figure Slave code data flow diagram AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.3.1 Slave Code Main Function slave code's main function very similar master's that performs some initialization before entering infinite loop. During iteration loop, code updates status message buffer writing switch settings NodeX_Read message buffer using LIN_PUTMsg() service checks received message been detected. message been detected, MsgHandlerTable called appropriate handler function executed. Several housekeeping tasks also performed main loop, such control timeouts etc. Once iteration complete, code jumps back start loop performs tasks again. Freescale Semiconductor, Inc. AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Slave Code description Start Initialise Register ivers Enable Global Interrupts Write NodeID switch Status MsgSent Buffer Transfer MsgSent buffer drivers buffer (LIN_PutMsg) Freescale Semiconductor, Inc. MsgData Changed Reset WakupTimeOut NodeX_Write message message from buffers transfer MsgRcvd buffer Mask command &Jump message handler table Reset WakupTimeOut NodeX_Write message message from buffers transfer MsgRcvd buffer Mask command &Jump message handler table Reset WakupTimeOut Figure Main Loop flow diagram AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.3.2 Receiving messages Each slave node configured receive messages: broadcast message NodeX_Write message. first byte message command. main function polls message status flags configured messages transfers received data application receive buffer, MsgRcvd, when valid message received. command byte decoded appropriate handler function executed. Each message handler described below: This handler entered when demo configured default mode (SLAVE_LEDS command transmitted master). handler decodes data received, illuminate GREEN LEDs, resets appropriate time counter then outputs data output port. 4.3.2.1 Rotating Handler Freescale Semiconductor, Inc. AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Slave Code description Start Data equal RED_LED_ON Reset Timeout Freescale Semiconductor, Inc. Data equal GREEN_LED_ON Reset GREEN Timeout Enable System Timeout Write data output port Figure Rotating Message Handler flow diagram AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.3.2.2 Broadcast Handler This handler entered when demo configured broadcast mode (BROADCAST command transmitted master). handler disables time then outputs data output port. Start Disable System Timeout Freescale Semiconductor, Inc. Write data output port Figure Broadcast Message Handler flow diagram 4.3.2.3 External Handler This handler entered when demo configured external mode (CLOCK_LEDS_COMMAND command transmitted master). handler enables time then outputs data external output port (PortE, bit4) Start Reset external timeout counter Enable external timeout counter Swiitch external Figure External Message Handler flow diagram AN2103 More Information This Product, www.freescale.com MOTOROLA Software Description Slave Code description 4.3.2.4 Identify Handler This handler entered when demo configured IDENT mode (IDENT command transmitted master). handler disables time then outputs data output port Start Disable System timeout Freescale Semiconductor, Inc. Write NodeID byte output port Figure Identify Message Handler flow diagram 4.3.2.5 Default Handler This handler consists function prototype. This included expandability ensure that code does `run away' even invalid entry message handler vector table accessed. I.e. unused entries table jump DefaultMessage handler. sleep mode description 4.3.2.6 SleepHandler AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note 4.3.3 Sleep Mode Sleep mode demo's power mode. entered when master transmits SLEEP identifier (0x80). Each slave receives command jumps sleep message handler. handler disables voltage regulator driving into sleep mode. node brought sleep mode external switch (switches around circumference clock face) wake-up message (see protocol specification details) detected bus. slave that woken transmits wake-up message onto bus, which wakes master other nodes. Each slave distinguishes between wake-up (switch voltage regulator) normal power sequence, detecting master present (master will communicating standard power sequence). master transmits ALIVE (0x0F) message every 150ms signal presence. slave detects ALIVE message assumes that power sequence. ALIVE detected within 200ms slave assumes that woken subsequently transmits wake-up message network. Freescale Semiconductor, Inc. AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code Master08.C Code Listings Master Code Master08.C Copyright Motorola 1998 File Name MASTER08.C Engineer Location Date Created Current Revision Notes R29414 07/02/2000 $Revision: 1.0$ Master software Demo Freescale Semiconductor, Inc. Motorola reserves right make changes without further notice Product herein improve reliability, function design. Motorola does assume liability arising application product, circuit, software described herein; neither does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other applications intended support life, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended Unauthorized application, Buyer shall idemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury death associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola Motorola logo* registered trademarks Motorola Ltd. /************************* System Include Files #include <linapi.h> Drivers Header file /************************* Project Include Files #include #include #include #include #include #include #include #include <master08CodeReview.h> <common.h> <port.h> <timer.h> <sim.h> <si.h> <kbd.h> <mscan08.h> Master08 header file Common data structure Port register definitions Timer register definitions Register definitions Serial Interface Register definitions Keyboard wakeup Register definitions msCAN Register definitions /*************************** Constants Slave Node Message array const SlaveNodeMsgType SlaveMsg {0x0F,0x0F}, Broadcast message {0x01,0x11}, Node1 Write messageID, Node1 Read messageID {0x02,0x12}, Node2 Write messageID, Node2 Read messageID {0x03,0x13}, Node3 Write messageID, Node3 Read messageID AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note {0x04,0x14}, {0x05,0x15}, {0x06,0x16}, {0x07,0x17}, {0x08,0x18}, {0x09,0x19}, {0x0A,0x1A}, {0x0B,0x1B}, {0x0C,0x1C} Broadcast table settings const tU08 BroadcastTable 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF Node4 Write messageID, Node4 Read messageID Node5 Write messageID, Node5 Read messageID Node6 Write messageID, Node6 Read messageID Node7 Write messageID, Node7 Read messageID Node8 Write messageID, Node8 Read messageID Node9 Write messageID, Node9 Read messageID Node10 Write messageID, Node10 Read messageID Node11 Write messageID, Node11 Read messageID Node12 Write messageID, Node12 Read messageID Data bytes transmitted when broadcast mode Freescale Semiconductor, Inc. Message handler vector table void const MsgHandlerTable[])() CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, CommonMsgHandler, SleepHandler, ModeSelect, DefaultHandler required different handlers used /************************* Global Variables SlaveMsgBufferType CurrentSlaveStatus [12]; DemoModeType_t DemoMode DEFAULT; tFLAG SystemFlags; tTXBUF StatusMsg; tU08 tU08 tU08 tU08 tU08 tU08 tU08 tU08 tU08 MsgWriteBuf [2]; ScheduleIndex 0x01; AltScheduleIndex 0x00; BroadcastIndex 0x00; MsgReadBuf1[2] {0x00,0x00}; MsgReadBuf2[2] {0x00,0x00}; CanMsgIndex 0x00; TimeoutCount 0x00; LoopControlTime 0x00; Current slave node status Current demo mode (DEFAULT,BROADCAST,IDENT,SLEEP) System flags Temp write buffer used with Drivers Slave node index Broadcast control index Temp read buffer used with Drivers Timeout counter slave nodes. AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code Master08.C /************************* #Defines Points register block memory #define AZ60_PORT (*(tPORT*) (0x0000)) #define AZ60_TIMER (*(tTIMER*) (0x0020)) #define AZ60_SI (*(tSI*) (0x0010)) #define AZ60_SIM (*(tSIM*) (0xFE00)) #define AZ60_KBD (*(tKBD*) (0x001A)) #define AZ60_MSCAN08 (*(tMSCAN*) (0x0500)) Function Name Main Engineer R29414 Date 09/02/2000 Parameters none Returns none Notes Main loop void main(void) Local variables tU08 MCUInitialisation(); LIN_Init(); drivers attached output ports Disabled production software Disable timer channels from ports AZ60_TIMER.tasc0.byte AZ60_TIMER.tasc0.byte 0xF3; AZ60_TIMER.tasc1.byte AZ60_TIMER.tasc1.byte 0xF3; Enable MC33399 device AZ60_PORT.pte.bit.pte3 AZ60_PORT.ddre.bit.ddre3 //LIN Freescale Semiconductor, Inc. loop control Initialisation register Drivers Initialisation service (i=0; i<0xff; ++i) Enable Global Interrupts Transmit Alive Message MsgWriteBuf[0] ALIVE_COMMAND; MsgWriteBuf[1] ALIVE_BYTE; MsgWriteBuf); ((AZ60_PORT.ptd.byte 0xF0) 0x00) SystemFlags.bit.canmode=1; ScheduleTableInit(); Wait switch Copy transmit data buffers Transmit message Standalone mode mode mode Initialise schedule table AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note SystemFlags.bit.loopcontrol=1; Initialise loop control Main Loop while(1) Wait timer interrupt receive message while (SystemFlags.bit.msgrxd==0)) (SystemFlags.bit.msgrxd==0)) Timer interrupt ScheduleMsg(); Schedule another message SystemFlags.bit.loopcontrol else message received CanMsgIndex (AZ60_MSCAN08.rxbuf.dsr[0] 0x0F); MsgHandlerTable[CanMsgIndex](); Jump message handler table SystemFlags.bit.msgrxd while main next message next loop iteration Freescale Semiconductor, Inc. Function Name ScheduleTableInit Engineer R29414 Date 09/02/2000 none none Initialise schedule table. identifies slave void ScheduleTableInit (void) Local variables tU08 Index counter tU08 msgTempBuffer[] {0x00, 0x00}; Initialise temp buffer Schedule table Initialisation (i=0 i<12 i++) Clear elements Slave table array*/ CurrentSlaveStatus [i].Byte0 NO_NODE; NO_NODE 0x00 CurrentSlaveStatus [i].Byte1 NO_NODE; Check nodes Nodes (i=1 i<13 i++) while LIN_OK) Transmit header TimeoutCount 0x00; Initialise Timeout count Initialise timeout flag Parameters Returns Notes AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code Master08.C SystemFlags.bit.starttimeout=1; Start time while !=LIN_OK Wait data timeout SystemFlags.bit.starttimeout=0; Stop timeout. Disables timeout TIMBOVF_ISR Timeout Valid message received LIN_GetMsg (SlaveMsg[i].ReadMsg, msgTempBuffer); Transfer Node status Temp buffer Update Current slave status CurrentSlaveStatus[i-1].Byte0 msgTempBuffer[0]; CurrentSlaveStatus[i-1].Byte1 msgTempBuffer[1]; Transmit initial status standalone mode (SystemFlags.bit.canmode==1) Standalone mode canmode= (tU16) CANId TxCANMsg(msgTempBuffer,i); Transmit message scheduleTableInit function Task Name ScheduleMsg Engineer R29414 Date Parameters none Returns none Notes Determine mode demo calls handler void ScheduleMsg(void) Transmit Alive Message MsgWriteBuf[0] ALIVE_COMMAND; MsgWriteBuf[1] ALIVE_BYTE; MsgWriteBuf); Transmit message while !=LIN_OK) Wait message request complete (SystemFlags.bit.canmode==0) DemoMode AZ60_PORT.ptd.byte 0x03; switch (DemoMode) case DEFAULT: DefaultMsgHandler(); break; case BROADCAST: Check mode Stand alone mode Freescale Semiconductor, Inc. Call NodeMsgHandler AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note BroadcastMsgHandler(); break; case IDENT: IdentMsgHandler(); break; case SLEEPMODE: SleepHandler(); break; default: break; switch Call BroadcastMsgHandler Call IdentMsgHandler Call SleepHandler scheduleMsg Task Name DefaultMsgHandler Engineer R29414 Date 26/07/2000 Parameters none Returns none Notes void DefaultMsgHandler(void) ((ScheduleIndex (ScheduleIndex 13)) ScheduleIndex Within range ((ScheduleIndex (ScheduleIndex Node LINTransmit(ScheduleIndex, ALL_LEDS_ON, MsgReadBuf1); else AltScheduleIndex ScheduleIndex; LINTransmit(ScheduleIndex, RED_LEDS_ON, MsgReadBuf1); Check index within range range make index Freescale Semiconductor, Inc. Valid ScheduleIndex Transmit specified message header frame Calculate alternate index Transmit specified message header frame Transmit specified message header LINTransmit(AltScheduleIndex, GREEN_LEDS_ON, MsgReadBuf2); frame Compare status data with previous data 1].Byte0 MsgReadBuf1[0]) 1].Byte1 MsgReadBuf1[1])) (SystemFlags.bit.canmode==1) transmit standalone mode Standalone (tU16) ScheduleIndex; 1].Byte0 MsgReadBuf1[0]; Update status data ScheduleIndex CANId Transmit message AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code Master08.C 1].Byte1 MsgReadBuf1[1]; DefaultMsgHandler Task Name LINTransmit Engineer R29414 Date 26/07/2000 Parameters index, ledcommand, &msgbuffer Returns none Notes void LINTransmit(tU08 index, tU08 ledcommand, tU08 *msgbuffer) TimeoutCount 0x00; Initialise Timeout count Initialise Timeout SystemFlags.bit.starttimeout=1; Transmit specified message header frame Start Timeout Freescale Semiconductor, Inc. Wait data timeout while !=LIN_OK SystemFlags.bit.starttimeout=0; Stop timeout Check valid message received msgbuffer); Store status information MsgWriteBuf[0] MsgWriteBuf[1] SLAVE_LEDS_COMMAND; ledcommand; //Set write buffer transmit command node Transmit default message node MsgWriteBuf); while !=LIN_OK) else msgbuffer[0] NO_NODE; msgbuffer[1] NO_NODE; LINTransmit Wait transmission complete Timeout Update temporary buffer indicating that node Task Name BroadcastMsgHandler Engineer R29414 Date Parameters none Returns none Notes void BroadcastMsgHandler(void) AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note (BroadcastIndex BroadcastIndex BroadcastIndex MsgWriteBuf[0] BROADCAST_COMMAND; MsgWriteBuf[1] BroadcastTable[BroadcastIndex]; MsgWriteBuf); while !=LIN_OK) (BroadcastIndex SystemFlags.bit.updowncontrol (BroadcastIndex SystemFlags.bit.updowncontrol BroadcastMsgHandler Task Name IdentMsgHandler Engineer R29414 Date Parameters none Returns none Notes void IdentMsgHandler(void) MsgWriteBuf[0] IDENT_COMMAND; MsgWriteBuf[1] AZ60_PORT.ptd.byte; switch input MsgWriteBuf); while !=LIN_OK); Wait message complete BroadcastMsgHandler Dont Index outwith range Wait message complete Counter Freescale Semiconductor, Inc. Down Counter Task Name MCUInitialisation Engineer R29414 Date Parameters none Returns none Notes Initialise hardware void MCUInitialisation(void) Device configuration AZ60_KBD.config1.bit.copd AZ60_SIM.config2.byte Ports Initialisation AZ60_PORT.ddrd.byte 0x00; Disable Watchdog Mode enabled PortD switches AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code Master08.C AZ60_PORT.ptb.byte 0xFF; AZ60_PORT.ddrb.byte 0xFF; AZ60_PORT.ptc.bit.ptc0 AZ60_PORT.ddrc.bit.ddrc0 Configuration SetMC33388Mode(NORMAL); AZ60_PORT.ddrf.byte PTF4|PTF3; SystemFlags.byte InitialiseMSCAN08(); StatusMsg.id.w[0] 0x0000; StatusMsg.dlr StatusMsg.tbpr Initialise TIMB Overflow AZ60_TIMER.tbsc.byte 0x30; AZ60_TIMER.tbmod.word 0x3E8; AZ60_TIMER.tbsc.byte 0x40; //End Initialisation Port LEDs MC33388 into normal mode PTF3=EN PTF4=STB pins MC33388 reset system flags MSCAN Initialisation standard 11-bit data bytes status message priority Freescale Semiconductor, Inc. Reset TIMB overflow when 1Meg pre-scale=0 Enable TIMB Interrupt Start timer Function Name TxCANMsg Engineer R29414 Date 22/02/00 Parameters *MsgBuffer, CANId Returns None Notes void TxCANMsg (tU08 *MsgBuffer, tU16 CANId) tU08 StatusMsg.id.w[0] ((CANId <<5) 0xFFE0); StatusMsg.dlr sizeof(MsgBuffer); (i=0 StatusMsg.dlr StatusMsg.dsr[i] MsgBuffer[i]; Calculate Calculate number data bytes buffer Transfer data bytes message buffer Function Name TxCANBuffer Engineer R38917 Date 11/02/00 Parameters *Buffer, TxBufferID Returns None Notes void TxCANBuffer(tTXBUF *Buffer, tU08 TxBufferID) tU08 AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note while(!(AZ60_MSCAN08.ctflg.byte TxBufferID)) /*** Timeout Period Abort Stuff ***/ AZ60_MSCAN08.txbuf[(TxBufferID 1)].id.l Buffer id.l; for(i=0 Buffer i++) AZ60_MSCAN08.txbuf[(TxBufferID 1)].dsr[i] Buffer dsr[i]; AZ60_MSCAN08.txbuf[(TxBufferID 1)].dlr Buffer dlr; AZ60_MSCAN08.txbuf[(TxBufferID 1)].tbpr Buffer tbpr; AZ60_MSCAN08.ctflg.byte TxBufferID; Function Name SetMC33388Mode Engineer R38917 Date 11/02/00 Parameters Mode Returns None Notes void SetMC33388Mode(enum tMC33388 Mode) switch(Mode) case SLEEP: AZ60_PORT.ptf.byte break; case SLEEP_RQ: AZ60_PORT.ptf.byte PTF3; break; case RX_ONLY: AZ60_PORT.ptf.byte PTF4; break; case NORMAL: AZ60_PORT.ptf.byte PTF4|PTF3; break; default: Function Name CommonMsgHandler Engineer R38917 Date 20/07/00 Parameters None Returns None Notes This handler common messages only index different. void CommonMsgHandler(void) Common handler replaces Node1 Node12 handlers Freescale Semiconductor, Inc. //STB=EN=0 //STB=0,EN=1 //STB=1,EN=0 //STB=EN=1 AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code Master08.C tU08 msgSent[] {CLOCK_LEDS_COMMAND, ALL_LEDS_OFF}; LIN_PutMsg msgSent); Local Declaration Transfer data buffer Request message while LIN_OK)// Wait while Function Name SleepHandler Engineer R38917 Date 11/02/00 Parameters None Returns None Notes void SleepHandler(void) Send Sleep command MsgWriteBuf[0] SLEEP_COMMAND; MsgWriteBuf[1] 0x00; MsgWriteBuf); Freescale Semiconductor, Inc. while !=LIN_OK) AZ60_PORT.pte.bit.pte3 SetMC33388Mode(SLEEP_RQ); SetMC33388Mode(SLEEP); while(1) Wait message complete Disable //placing MC33388 into SLEEP mode switches Vreg Function Name ModeSelect Engineer R38917 Date 10/02/00 Parameters None Returns None Notes void ModeSelect(void) case DEFAULT: DemoMode DEFAULT; break; case BROADCAST: Demo mode byte1 demo default mode AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note DemoMode BROADCAST; BroadcastIndex break; case IDENT: DemoMode IDENT; break; default: Function Name DefaultHandler Engineer R38917 Date 11/02/00 Parameters None Returns None Notes void DefaultHandler(void) demo broadcast mode demo IDENT mode Freescale Semiconductor, Inc. Function Name InitialiseMSCAN08 Engineer R38917 Date 10/02/00 Parameters None Returns None Notes void InitialiseMSCAN08(void) AZ60_MSCAN08.cmcr0.bit.sftres AZ60_MSCAN08.cbtr0.byte CBT0_125K; AZ60_MSCAN08.cbtr1.byte CBT1_125K; AZ60_MSCAN08.cid.mr.l 0xFFFFFFFF; AZ60_MSCAN08.cmcr0.bit.sftres AZ60_MSCAN08.crier.bit.rxfie //accept messages //release module from soft reset //enable receive interrupts //put module soft reset //wait synchronize Task Name TimerB Overflow Engineer R29414 Date Parameters none Returns none Notes Overflow period 1ms. AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code Master08.C Hiware compiler #pragma TRAP_PROC void TIMBOVF_ISR (void) LoopControlTime++; else LoopControlTime=0x00; SystemFlags.bit.loopcontrol ScheduleIndex++; (ScheduleIndex >=13) ScheduleIndex 0x01; (DemoMode BROADCAST) (SystemFlags.bit.updowncontrol BroadcastIndex++; else BroadcastIndex-; (SystemFlags.bit.starttimeout (TimeoutCount<TIMEOUT_PERIOD) TimeoutCount++; else SystemFlags.bit.linmsgtimeout Clear Interrupt flag AZ60_TIMER.tbsc.byte ~TOF; Reset Schedule Index Loop control timer timeout LoopControlPeriod header file Freescale Semiconductor, Inc. Reset LoopControlTime Clear system flag Increment Schedule Table Index Timeoutperiod header file Timeout flag Read TBSC0 write CH0F Function Name CANRxISR Engineer R38917 Date 10/02/00 Parameters None AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Returns None Notes message received interrupt service routine #pragma TRAP_PROC void CANRx_ISR(void) SystemFlags.bit.msgrxd AZ60_MSCAN08.crflg.bit.rxf //clear interrupt flag Master Code MASTER08.H Copyright Motorola 1998 File Name MASTER08.C Engineer Location Date Created Current Revision Notes R29414 07/02/2000 $Revision:1.0 driver header file Freescale Semiconductor, Inc. Motorola reserves right make changes without further notice Product herein improve reliability, function design. Motoroladoes assume liability arising application product, circuit, software described herein; neither does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other applications intended support life, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended unauthorized application, Buyer shall idemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury ordeath associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola Motorola logo* registered trademarks Motorola Ltd. #ifndef MASTER08CODEREVIEW_H #define MASTER08CODEREVIEW_H /************************* System Include Files ******************************/ /************************* Project Include Files *****************************/ #include "c:\header_files\hc08\common.h" common data structure #include common data structure /************************* User #Defines Timmer period Control #define LOOP_CONTROL_PERIOD #define TIMEOUT_PERIOD AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Master Code MASTER08.H /************************* typedefs typedef struct SlaveNodeMsgStruct tU08 WriteMsg; tU08 ReadMsg; SlaveNodeMsgType; typedef struct SlaveMsgBufferStruct tU08 Byte0; tU08 Byte1; SlaveMsgBufferType; Freescale Semiconductor, Inc. typedef union tU08 byte; struct tU08 msgrxd:1; tU08 loopcontrol tU08 updowncontrol tU08 canmode tU08 linmsgtimeout tU08 starttimeout tU08 }bit; }tFLAG; //target connection established //Loop control flag //Broadcast message down flag 0=Up, 1=Down //Flag indicates mode. Standalone //LIN timeout. Timeout //LIN timeout. Timeout used typedef enum DEFAULT, BROADCAST, IDENT, SLEEPMODE DemoModeType_t; enumtMC33388 SLEEP, SLEEP_RQ, RX_ONLY, NORMAL /************************* #Defines Timmer period Control #define NODE_CONNECTED #define NO_NODE #define CBT0_125K #define CBT1_125K #define MSCAN_TX0 0x80 0x00 0xC0 0xD8 0x01 //based 4MHz xtal, sampling points, AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note #define MSCAN_TX1 #define MSCAN_TX2 0x02 0x04 #define #define #define #define #define #define #define #define #define #define #define #define LED0_ON LED1_ON LED2_ON LED3_ON LED4_ON LED5_ON LED6_ON LED7_ON ALL_LEDS_ON ALL_LEDS_OFF GREEN_LEDS_ON RED_LEDS_ON 0x01 0x02 0x04 0x08 0x10 0x20 0x40 0x80 0x00 0xFF 0x0F 0xF0 Freescale Semiconductor, Inc. command bytes #define SLAVE_LEDS_COMMAND #define BROADCAST_COMMAND #define CLOCK_LEDS_COMMAND #define IDENT_COMMAND #define SLEEP_COMMAND #define ALIVE_COMMAND #define ALIVE_BYTE 0x01 0x02 0x03 0x04 0x08 0x0F 0xAD /************************* Macros /************************* Prototypes void MCUInitialisation (void); void ScheduleTableInit (void); void ScheduleMsg (void); void DefaultMsgHandler (void); void BroadcastMsgHandler (void); void IdentMsgHandler(void); void TxCANMsg (tU08 tU16); void void void void void void void void void CommonMsgHandler(void); TxCANBuffer(tTXBUF ,tU08); SetMC33388Mode(enum tMC33388); SleepHandler(void); StatusRequestHandler(void); ModeSelect(void); DefaultHandler(void); InitialiseMSCAN08(void); LINTransmit(tU08, tU08, tU08 #endif/* Header file ifndef*/ Slave Code SLAVE08.C Copyright Motorola 2000 File Name SLAVE08.C Engineer Project Location TTZ740 Demo Project AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Slave Code SLAVE08.C Date Created Current Revision Functions Tasks January 2000 $Revision:1.0 Freescale Semiconductor, Inc. Motorola reserves right make changes without further notice Product herein improve reliability, function design. Motorola does assume liability arising application product, circuit, software described herein; neither does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other applications intended support life, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended unauthorized application, Buyer shall idemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury ordeath associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola Motorola logo* registered trademarks Motorola Ltd. /************************* System Include Files ******************************/ #include #include #include #include #include #include #include "SAEdemo.h" <linapi.h> <port.h> <sim.h> <kbd.h> <si.h> <timer.h> //demo header file //lin driver //port registers definitions //system register definitions //register definitions //register definitions //register definitions /************************* Declarations /*************************** defines #define #define #define #define #define AZ60 TIMER (*(tPORT (*(tSIM (*(tKBD (*(tSI (*(tTIMER *)(0x0000)) *)(0xFE00)) *)(0x001A)) *)(0x0010)) *)(0x0020)) /************************* typedefs typedef union tU08 byte; struct tU08 enableTimeout tU08 enableExternal tU08 disableWaketime tU08 }bit; }tFLAG; //enable defautl mode timeout //enable external timeout //not used AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note enum tMC33388 SLEEP, SLEEP_RQ, RX_ONLY, NORMAL /************************* Global Variables tFLAG tU08 tU08 tU08 tU08 tU08 tU08 tU16 SystemFlags; REDTIMticks GREENTIMticks EXTERNTIMticks TIMticks MsgSent[2]; MsgRcvd[2]; WakeupTimeout Freescale Semiconductor, Inc. /************************* Prototypes Function Name SetMC33388Mode Engineer r38917 Date 11/02/00 Parameters Mode Returns None Notes void SetMC33388Mode(enum tMC33388 Mode) switch(Mode) case SLEEP: AZ60.ptf.byte break; case SLEEP_RQ: AZ60.ptf.byte PTF3; break; case RX_ONLY: AZ60.ptf.byte PTF4; break; case NORMAL: AZ60.ptf.byte PTF4|PTF3; break; default: Function Name Rotating LEDs message Engineer TTZ740 //STB=EN=0 //STB=0,EN=1 //STB=1,EN=0 //STB=EN=1 AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Slave Code SLAVE08.C Date 10/02/00 Parameters None Returns None Notes void RotatingHandler(void) if((MsgRcvd[1] RED_LED_MASK) RED_LED_MASK) REDTIMticks //reset timeout period if((MsgRcvd[1] GREEN_LED_MASK) GREEN_LED_MASK) GREENTIMticks //reset green timeout period SystemFlags.bit.enableTimeout AZ60.ptb.byte MsgRcvd[1]; Freescale Semiconductor, Inc. //send data portb switch LEDs Function Name Broadcast message Engineer TTZ740 Date 10/02/00 Parameters None Returns None Notes void BroadcastHandler(void) SystemFlags.bit.enableTimeout AZ60.ptb.byte ~MsgRcvd[1]; //output data byte port Function Name External message Engineer TTZ740 Date 10/02/00 Parameters None Returns None Notes void ExternalHandler(void) EXTERNTIMticks SystemFlags.bit.enableExternal AZ60.pte.bit.pte4 //reset external timeout period //switch external Function Name MsgHandler4 Engineer TTZ740 Date 10/02/00 Parameters None Returns None Notes void IdentifyHandler(void) AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note SystemFlags.bit.enableTimeout AZ60.ptb.byte ~nodeID; //display node LEDs Function Name SleepHandler Engineer r38917 Date 11/02/00 Parameters None Returns None Notes void SleepHandler(void) AZ60.ddrf.byte DDRF3|DDRF4; AZ60.pte.bit.pte3 SetMC33388Mode(NORMAL); SetMC33388Mode(SLEEP_RQ); SetMC33388Mode(SLEEP); while(1) Freescale Semiconductor, Inc. //enable pins output //disable interface //MC33388 can't sleep from Vbat //standby mode //placing MC33388 into SLEEP mode switches Vreg Function Name DefaultHandler Engineer r38917 Date 11/02/00 Parameters None Returns None Notes void DefaultHandler(void) Message handler vector table void const MsgHandlerTable[])() DefaultHandler, RotatingHandler, BroadcastHandler, ExternalHandler, IdentifyHandler, DefaultHandler, DefaultHandler, DefaultHandler, SleepHandler, DefaultHandler, DefaultHandler, DefaultHandler, DefaultHandler, DefaultHandler, AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Slave Code SLAVE08.C DefaultHandler, DefaultHandler Task Name LINInitialise Engineer TTZ740 Date none none driver timer setup causes output compare pins toggle which creates conflict with hardware design void LINInitialise(void) LIN_Init(); Parameters Returns Notes Freescale Semiconductor, Inc. //initialise driver TIMER.tasc0.byte TIMER.tasc0.byte 0xF3; TIMER.tasc1.byte TIMER.tasc1.byte 0xF3; Task Name LINWakeup Engineer TTZ740 Date Parameters: Returns Notes none none Initial hardware design used interface, which compatible with protocol wakeup, hence custom wakeup routine required interface void LINWakeup(void) SI.sci.scc1.bit.ensci SI.sci.scbr.bit.scr SI.sci.scbr.bit.scp SI.sci.scc1.bit.ensci SI.sci.scc2.bit.te disable 10400 baud 10400 baud enable enable transmit while (SI.sci.scs1.bit.scte SI.sci.scdr 0xAA; while (SI.sci.scs1.bit.tc send wake LINInitialise(); //initialise driver Task Name initialise Engineer TTZ740 Date Parameters Returns none none AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Notes void initialise (void) tU08 SIM.config2.byte 0x11; KBD.config1.byte 0x71; AZ60.ptb.byte ALL_LEDS_OFF; AZ60.ddrb.byte 0xFF; SystemFlags.byte LINInitialise(); TIMER.tsc.byte 0x54; TIMER.tmod.word 0x003E; AZ60.pte.byte PTE3; AZ60.ddre.byte DDRE3|DDRE4; 0xFF; ++i) //enable interrupt, counter prescaler //1mS overflow based 4MHz xtal //enable device, switch external //disable module, enable mode //disable //port LEDs switch //set port output //reset system flags Freescale Semiconductor, Inc. //delay switch Task Name main Engineer TTZ740 Date Parameters none Returns none Notes void main( void initialise(); cli; while( MsgSent[0] nodeID; MsgSent[1] AZ60.ptd.byte; LIN_PutMsg(MESSAGESEND, MsgSent); //initialisation routine //enable global interrupts //data byte1 sent node //Data byte1 sent switch status //send data data buffer (LIN_MsgStatus(MESSAGESEND) LIN_MSG_NOCHANGE) WakeupTimeout //reset wakeup timeout (LIN_MsgStatus(MESSAGERECEIVE) LIN_OK)//if message LIN_GetMsg(MESSAGERECEIVE, MsgRcvd); //read message MsgHandlerTable[(MsgRcvd[0] 0x0F)]();//call subroutine appropriate command WakeupTimeout //reset wakeup timeout LIN_OK)//if broadcast message AN2103 More Information This Product, www.freescale.com MOTOROLA Code Listings Slave Code SLAVE08.C LIN_GetMsg(BROADCASTRECEIVE, MsgRcvd); //read message MsgHandlerTable[(MsgRcvd[0] 0x0F)](); //call subroutine appropriate command WakeupTimeout //reset wakeup timeout Task Name PIT_ISR Engineer TTZ740 Date Parameters none Returns none Notes #pragma TRAP_PROC void PIT_ISR(void) if(REDTIMticks REDTIMPeriod) REDTIMticks++; else AZ60.ptb.byte RED_LED_MASK; if(GREENTIMticks GREENTIMPeriod) GREENTIMticks++; else AZ60.ptb.byte GREEN_LED_MASK; if(AZ60.ptb.byte ALL_LEDS_OFF) SystemFlags.bit.enableTimeout if(EXTERNTIMticks EXTERNTIMPeriod) EXTERNTIMticks++; else AZ60.pte.bit.pte4 if(!AZ60.pte.bit.pte4) SystemFlags.bit.enableExternal Freescale Semiconductor, Inc. //check timeout period LEDs expired //increment ticks //switch LEDs //check timeout period green LEDs expired //increment ticks //switch green LEDs //check timeout period external LEDs expired //increment ticks //switch external AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note if(WakeupTimeout TXWAKEUPMSG) WakeupTimeout++; else static tU08retry (retry WakeupTimeout 0;//reset wakeup timeout LINWakeup(); //attempt wake network retry++; else SystemFlags.bit.disableWaketime TIMER.tsc.bit.tof //clear overflow flag Freescale Semiconductor, Inc. Slave Code SLAVE08.H Copyright Motorola 1998 File Name SLAVE08.C Engineer Location Date Created Current Revision Notes TTZ740 07/02/2000 $Revision:1.0 driver header file Motorola reserves right make changes without further notice Product herein improve reliability, function design. Motorola does assume liability arising application product, circuit, software described herein; neither does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other applications intended support life, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended unauthorized application, Buyer shall idemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury ordeath associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola Motorola logo* registered trademarks Motorola Ltd. #ifndef SLAVE08_H #define SLAVE08_H /************************* #Defines standard defs that defined compiler AN2103 More Information This Product, www.freescale.com MOTOROLA Schematic Slave Code SLAVE08.H !defined(TRUE) #define TRUE #define FALSE #endif #define #define #define #define #define #define #define #define #define #define #define #define #define #define 0x01 0x00 TRUE FALSE TRUE FALSE 0x0F 0xF0 0xF0 0x0F 0xFF 0x00 //generates 150mS timeout (4MHz xtal) //generates 150mS timeout (4MHz xtal) //generates 150mS timeout (4MHz xtal) Freescale Semiconductor, Inc. RED_LED_MASK GREEN_LED_MASK RED_LEDS_ON GREEN_LEDS_ON ALL_LEDS_OFF ALL_LEDS_ON REDTIMPeriod GREENTIMPeriod EXTERNTIMPeriod TXWAKEUPMSG /************************* Prototypes #endif Header file ifndef Schematic AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Freescale Semiconductor, Inc. AN2103 More Information This Product, www.freescale.com MOTOROLA Schematic Slave Code SLAVE08.H Freescale Semiconductor, Inc. AN2103 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Motorola reserves right make changes without further notice products herein. Motorola makes warranty, representation guarantee regarding suitability products particular purpose, does Motorola assume liability arising application product circuit, specifically disclaims liability, including without limitation consequential incidental damages. "Typical" parameters which provided Motorola data sheets and/or specifications vary different applications actual performance vary over time. operating parameters, including "Typicals" must validated each customer application customer's technical experts. Motorola does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other applications intended support sustain life, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended unauthorized application, Buyer shall indemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims, costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury death associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola registered trademarks Motorola, Inc. Motorola, Inc. Equal Opportunity/Affirmative Action Employer. reach USA/EUROPE: Motorola Literature Distribution; P.O. 5405, Denver, Colorado 80217. 1-303-675-2140 HOME PAGE: http://motorola.com/sps/ JAPAN: Motorola Japan Ltd.; SPS, Technial Information Center, 3-20-1, Minami-Azabu, Minato-ku, Tokyo 106-8573 Japan. 81-3-3440-3569 ASIA/PACIFIC: Motorola Semiconductors H.K. Ltd.; Silicon Harbour Centre, King Street, Industrial Estate, N.T., Hong Kong. 852-266668334 CUSTOMER FOCUS CENTER: 1-800-521-6274 Motorola, Inc., 2000 More Information This Product, www.freescale.com AN2103/D Other recent searchesWM8141 - WM8141 WM8141 Datasheet UP0111FG - UP0111FG UP0111FG Datasheet MPQF015C - MPQF015C MPQF015C Datasheet LRF3W - LRF3W LRF3W Datasheet ISL6424 - ISL6424 ISL6424 Datasheet HD6473297 - HD6473297 HD6473297 Datasheet HD64333297 - HD64333297 HD64333297 Datasheet HD6433296 - HD6433296 HD6433296 Datasheet HD6473294 - HD6473294 HD6473294 Datasheet HD6433294 - HD6433294 HD6433294 Datasheet HD6433292 - HD6433292 HD6433292 Datasheet ELB-1010SURD - ELB-1010SURD ELB-1010SURD Datasheet S530-A3 - S530-A3 S530-A3 Datasheet ED-012YGU - ED-012YGU ED-012YGU Datasheet
Privacy Policy | Disclaimer |