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

📄 main.c

📁 飞思卡尔车身控制技术研讨会资料范例 基于LIN的收发通信
💻 C
字号:
/*******************************************************************************/
/*
Copyright (c) 2008 Freescale Semiconductor
\file       main.c
\brief      DZ60 - EEPROM sample code
\author     Freescale Semiconductor
\author     B05114
\version    0.1
\date       January/2008
*/
/*******************************************************************************/
 
/* Derivative peripheral declarations */
#include "derivative.h" 

#include <hidef.h>

#include "typedefs.h"

/* DZ60 initialization functions */
#include "DZ60_init.h"

/* EEPROM driver */
#include "EEPROM_Drv.h"

/* TPM1 overflow interrupt service routine */
interrupt void TPM1_ISR(void);

/* Global variables */
UINT8   Scheduler_Ctrl;
UINT8   Scheduler_Flag;

static UINT16 Dest, Offset = 8;

/* Definition of data table in EEPROM */
#pragma DATA_SEG EEPROM_TABLE
UINT8 EEPROM_Data; 
#pragma DATA_SEG DEFAULT


void Clear_TableSpace(void); /* Prepare sector to store data */
void Backup_Data(void);     /* Record data in EEPROM table */


/*****************************************************************************/

void main( void )
{    
	MCG_Init();     /* Clock Generator initialization */
    
    GPIO_Init();    /* GPIO configuration */ 
         
    TPM1_Init();    /* Real time counter initialization */ 
    
    vfnEE_Init(EEPROM_DIV);   
                                
    EnableInterrupts;  /* Enable interrupts */
    	             
     
	while(1)
	{    	
        if ((Scheduler_Flag & 0x01) == 0x01)
        {
            /* Execute pending EEPROM update tasks */
            vfnEEPROM_Tasks();
                        
            Scheduler_Flag = 0x00;
        }
        else
        {            
            if ((Scheduler_Flag & 0x02) == 0x02)
            {
                Scheduler_Flag = 0x00;
            }
            else
            {
                if ((Scheduler_Flag & 0x04) == 0x04)
                {
                    Scheduler_Flag = 0x00;
                }
                else
                {            
                    if ((Scheduler_Flag & 0x08) == 0x08)
                    {
                        Clear_TableSpace();
                        Scheduler_Flag = 0x00;
                    }
                    else
                    {                
                        if ((Scheduler_Flag & 0x10) == 0x10)
                        {
                            Backup_Data();
                            Scheduler_Flag = 0x00;
                        }
                    }
                }
            }
        }
	} 
} 

/*****************************************************************************/
/*
* \brief    TPM1 overflow interrupt service routine
* \author   B05114
*/ 
interrupt void TPM1_ISR(void)
{       

/* Verify that Timer caused the interrupt */
  if (TPM1SC_TOF ==1)
    {
        /* Update scheduler control variables */
        Scheduler_Ctrl++;     
        
        if ((Scheduler_Ctrl & 0x01) == 0x01)
        {
            Scheduler_Flag = 0x01;
        }
        else
        { 
            if ((Scheduler_Ctrl & 0x02) == 0x02)
            {                    
                Scheduler_Flag = 0x02;
            }
            else
            { 
                if ((Scheduler_Ctrl & 0x04) == 0x04)
                {
                    Scheduler_Flag = 0x04;
                }
                else
                {     
                    if ((Scheduler_Ctrl & 0x08) == 0x08)
                    {                       
                        Scheduler_Flag = 0x08;
                    }
                    else
                    {     
                        if ((Scheduler_Ctrl & 0x0F) == 0x00)
                        {
                            Scheduler_Flag = 0x10;
                        }
                    }
                }
            }
        }        
    }
      	
  	(void)TPM1SC;       /* Read TPM status register */
    TPM1SC_TOF = 0;     /* and clear interrupt flag */		   
}

/*******************************************************************************/
/*
* \brief    Store data in EEPROM table
* \author   B05114
*/ 

void Backup_Data(void)
{ 
    static UINT8* Source;    
    static UINT8 Data[4], loops = 0;
          
                  
    /* Request data backup in EEPROM if it is not being accessed */
    if ((IsEEPROMBusy() == EEPROM_READY))
    {    
        Data[0] = 0x05 + Offset + loops;
        Data[1] = 0x0A + Offset + loops;   
        Data[2] = 0x50 + Offset + loops;
        Data[3] = 0xA0 + Offset + loops;          
    
        Dest   = ((UINT16) &EEPROM_Data + Offset);
        Source = (Data);          
                               
        if (u8ByteWriteOnlyEEPROM(Dest,Source,4)== ERR_OK)
        {
            Offset = Offset + 4;                                    
                if (Offset >= 24)
                {                                                                                                     
                    Offset = 8;
                    loops++;                                                                           
                }                            
        }               
    }      
}

void Clear_TableSpace(void)
{
    (void)u8SectorEraseEEPROM(Dest, 1);                
}

/*******************************************************************************/

/*******************************************************************************/
/*                                                                             */
/* All software, source code, included documentation, and any implied know-how */
/* are property of Freescale Semiconductor and therefore considered            */ 
/* CONFIDENTIAL INFORMATION.                                                   */
/*                                                                             */
/* This confidential information is disclosed FOR DEMONSTRATION PURPOSES ONLY. */
/*                                                                             */
/* All Confidential Information remains the property of Freescale Semiconductor*/
/* and will not be copied or reproduced without the express written permission */
/* of the Discloser, except for copies that are absolutely necessary in order  */
/* to fulfill the Purpose.                                                     */
/*                                                                             */
/* Services performed by FREESCALE in this matter are performed AS IS and      */
/* without any warranty. CUSTOMER retains the final decision relative to the   */
/* total design and functionality of the end product.                          */
/*                                                                             */
/* FREESCALE neither guarantees nor will be held liable by CUSTOMER for the    */
/* success of this project.                                                    */
/*                                                                             */
/* FREESCALE disclaims all warranties, express, implied or statutory including,*/
/* but not limited to, implied warranty of merchantability or fitness for a    */
/* particular purpose on any hardware, software ore advise supplied to the     */
/* project by FREESCALE, and or any product resulting from FREESCALE services. */
/*                                                                             */
/* In no event shall FREESCALE be liable for incidental or consequential       */
/* damages arising out of this agreement. CUSTOMER agrees to hold FREESCALE    */
/* harmless against any and all claims demands or actions by anyone on account */
/* of any damage,or injury, whether commercial, contractual, or tortuous,      */
/* rising directly or indirectly as a result of the advise or assistance       */
/* supplied CUSTOMER in connectionwith product, services or goods supplied     */
/* under this Agreement.                                                       */
/*                                                                             */
/*******************************************************************************/

⌨️ 快捷键说明

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