⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slave.c

📁 LIN Driver for S08, LIN 1.3. Source code with codewarrior
💻 C
字号:
/******************************************************************************
*                                                                     
*       Copyright (C) 2005 Freescale Semiconductor, Inc.              
*       All Rights Reserved								              
*														              
* Filename:     slave.c                
*														              
* Revision:      										              
*														              
* Functions:    Sample application for LINS08AW60 Slave Driver with Freescale API
*         
* Description:  Receive message $17 from master and display contents on LEDs.
*
* Notes:        Sample code that may be modified by the user.
*
******************************************************************************/

#include <linapi.h>
#include "slave.h"

unsigned char MsgRcvd [2]; /* received data */
unsigned int  Time;				 /* time from real time counter */

/*****************************************************************************
 * Function:        LIN_Command
 *
 * Description:     User call-back.
 *                  Called by the driver after successful transmission or receiving 
 * 	                of the Master Request Command Frame (ID Field value '0x3C').
 *
 * Returns:         never return 
 *
 * Notes:
 *
 *****************************************************************************/
void LIN_Command()
{
  /* endless loop */
  while(1);
}

/*****************************************************************************
 * Function:        Delay
 *
 * Description:     Initialise RTI for use in Delay() function
 *
 *
 * Returns:         none
 *
 * Notes:			      none
 *
 *****************************************************************************/
void InitDelay(void)
{
	/* Initialise RTI */
	SRTISC = 0x11; /* internal 1kHz oscillator;RTI period of 8ms; enable interrupt */
}

/*****************************************************************************
 * Function:        RTI_ISR
 *
 * Description:     Handle RTI ISR
 *					Add one tick to time
 *
 * Returns:         none
 *
 * Notes:			
 *
 *
 *****************************************************************************/
#pragma TRAP_PROC
void RTI_ISR( void )
{
	Time++;

	/* Clear RTI flag */
	SRTISC |= 0x40;
}


/*****************************************************************************
 * Function:        Delay
 *
 * Description:     Simple delay routine.
 *                  Delay for n * 8ms 
 *
 * Returns:         after n n * 8ms
 *
 * Notes:			      Uses real time interrupt function - must be initialised
 *					        elsewhere to give 8ms timeouts
 *
 *****************************************************************************/
void Delay(unsigned int n)
{
	unsigned int stopTime;
	
	stopTime = Time+n;
	
	while (stopTime != Time);
}

/*****************************************************************************
 * Function:        main
 *
 * Description:     Sends and receives 2 bytes responses periodically
 *
 * Returns:         never return
 *
 * Notes:
 *
 *****************************************************************************/
void main( void )
{
    LINStatusType   ret;
    
    Time = 0;

    /* disable COP */
    SOPT &= ~COPE;  
    
    /* init ICG for 8MHz bus clock*/
    ICGC1 = 0xF8;
    ICGC2 = 0x88;		
    
    for (;ICGS1 & LOCK;);

    /* Initialize driver */
    LIN_Init();
    
    /* Enable LED display */
    DDRF  = 0xFF;
	  PORTF = 0x0;
    
  	/* Enable LIN interface */
    /* Add code for enabling LIN interface when required. Check schematics of used EVB */

 	/* Initialise RTI */
	  InitDelay();

    /* Enable interrupt */
    asm cli;        

    /* Main Loop */
    while( 1 )
    {
        /* Wait for a message */
		ret = LIN_MsgStatus( 0x17 );
    if(( ret == LIN_OK ) || ( ret & LIN_MSG_OVERRUN ))
      {
      /* Read message */
      ret = LIN_GetMsg( 0x17, MsgRcvd );
      
      PORTF = MsgRcvd[0];  
  		Delay(50);
      PORTF = MsgRcvd[1];
  		Delay(50);
      PORTF = MsgRcvd[0];
  		Delay(50);
      PORTF = MsgRcvd[1];
  		}
		
    }   /* while (1) */

}       /* main */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -