This commit is contained in:
sunbeam 2024-12-23 11:04:44 +08:00
commit c9428891ad
72 changed files with 37644 additions and 0 deletions

157
.cproject Normal file
View File

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="com.freescale.s12z.toolchain.release.333878984">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.freescale.s12z.toolchain.release.333878984" moduleId="org.eclipse.cdt.core.settings" name="FLASH">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.managedbuilder.core.ManagedBuildManager" point="org.eclipse.cdt.core.ScannerInfoProvider"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.LltErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.AsmErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.IcodeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.CobjErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.MwErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.S08ErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.MPWErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.MwfeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="com.freescale.core.ide.cdt.errorParsers.LnkErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="LIN_TEST_Project" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="&quot;${system:ECLIPSE_HOME}/../gnu/bin/rm&quot; -f" description="" errorParsers="com.freescale.core.ide.cdt.errorParsers.GCCErrorParser;org.eclipse.cdt.core.GmakeErrorParser;com.freescale.core.ide.cdt.errorParsers.LnkErrorParser;com.freescale.core.ide.cdt.errorParsers.AsmErrorParser;com.freescale.core.ide.cdt.errorParsers.CobjErrorParser;com.freescale.core.ide.cdt.errorParsers.IcodeErrorParser;com.freescale.core.ide.cdt.errorParsers.LltErrorParser;com.freescale.core.ide.cdt.errorParsers.MwfeErrorParser;com.freescale.core.ide.cdt.errorParsers.MwErrorParser;com.freescale.core.ide.cdt.errorParsers.MPWErrorParser;com.freescale.core.ide.cdt.errorParsers.S08ErrorParser;" id="com.freescale.s12z.toolchain.release.333878984" isPrebuildInvalidatingBuild="false" isVersionInfoProjSpecific="false" name="FLASH" parent="com.freescale.s12z.toolchain.release">
<folderInfo id="com.freescale.s12z.toolchain.release.333878984." name="/" resourcePath="">
<toolChain errorParsers="" id="com.freescale.s12z.toolchain.release.1983133853" name="S12Z Toolchain" superClass="com.freescale.s12z.toolchain.release">
<targetPlatform id="com.freescale.s12z.toolchain.targetPlatform.1446191669" isAbstract="false" name="S12Z Target Platform" superClass="com.freescale.s12z.toolchain.targetPlatform"/>
<builder buildPath="${ProjDirPath}/FLASH" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;com.freescale.core.ide.cdt.errorParsers.GCCErrorParser;com.freescale.core.ide.cdt.errorParsers.LltErrorParser;com.freescale.core.ide.cdt.errorParsers.AsmErrorParser;com.freescale.core.ide.cdt.errorParsers.IcodeErrorParser;com.freescale.core.ide.cdt.errorParsers.CobjErrorParser;com.freescale.core.ide.cdt.errorParsers.MwErrorParser;com.freescale.core.ide.cdt.errorParsers.S08ErrorParser;com.freescale.core.ide.cdt.errorParsers.MPWErrorParser;com.freescale.core.ide.cdt.errorParsers.MwfeErrorParser;com.freescale.core.ide.cdt.errorParsers.LnkErrorParser" id="com.freescale.s12z.toolchain.builder.957650138" keepEnvironmentInBuildfile="false" name="GNU Make Builder" parallelBuildOn="true" parallelBuildWorkspaceOn="true" parallelizationNumber="optimal" superClass="com.freescale.s12z.toolchain.builder"/>
<tool errorParsers="" id="com.freescale.s12z.toolchain.preprocessor.945117802" name="S12Z Preprocessor" superClass="com.freescale.s12z.toolchain.preprocessor"/>
<tool errorParsers="" id="com.freescale.s12z.toolchain.disassembler.1111326326" name="S12Z Disassembler" superClass="com.freescale.s12z.toolchain.disassembler"/>
<tool errorParsers="" id="com.freescale.s12z.toolchain.burner.687913333" name="S12Z Burner" superClass="com.freescale.s12z.toolchain.burner"/>
<tool errorParsers="" id="com.freescale.s12z.toolchain.linker.1705342602" name="S12Z Linker" superClass="com.freescale.s12z.toolchain.linker">
<option id="com.freescale.s12z.toolchain.linker.input.paramFile.882294648" name="Parameter File" superClass="com.freescale.s12z.toolchain.linker.input.paramFile" value="${ProjDirPath}/Project_Settings/Linker_Files/mc9s12zvl32.prm" valueType="string"/>
<option id="com.freescale.s12z.toolchain.linker.input.libs.854515094" name="Libraries" superClass="com.freescale.s12z.toolchain.linker.input.libs" valueType="libs">
<listOptionValue builtIn="false" value="&quot;${MCUToolsBaseDir}/S12lisa_Support/s12lisac/lib_small/ansii.lib&quot;"/>
</option>
<option id="com.freescale.s12z.toolchain.linker.msgs.WmsgSd.852587382" name="Set Messages to Disable" superClass="com.freescale.s12z.toolchain.linker.msgs.WmsgSd" valueType="stringList">
<listOptionValue builtIn="false" value="1100"/>
<listOptionValue builtIn="false" value="1912"/>
</option>
<option id="com.freescale.s12z.toolchain.linker.base.linkOrder.77398002" name="Link Order" superClass="com.freescale.s12z.toolchain.linker.base.linkOrder" valueType="stringList">
<listOptionValue builtIn="false" value="LIN_Stack/bsp/SCI/lin_isr.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/bsp/SCI/lin_lld_sci.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/bsp/SCI/lin_lld_timesrv.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/coreapi/lin_common_api.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/coreapi/lin_common_proto.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/coreapi/lin_j2602_api.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/coreapi/lin_j2602_proto.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/coreapi/lin_lin21_api.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/coreapi/lin_lin21_proto.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/diagnostic/lin_diagnostic_service.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/lowlevel/lin.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/transport/lin_commontl_api.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/transport/lin_commontl_proto.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/transport/lin_j2602tl_api.c"/>
<listOptionValue builtIn="false" value="LIN_Stack/transport/lin_lin21tl_api.c"/>
<listOptionValue builtIn="false" value="Lib/mc9s12zvl32.c"/>
<listOptionValue builtIn="false" value="Project_Settings/Startup_Code/starts12z.c"/>
<listOptionValue builtIn="false" value="Sources/main.c"/>
<listOptionValue builtIn="false" value="Sources/AD1.c"/>
<listOptionValue builtIn="false" value="Sources/CPU.c"/>
<listOptionValue builtIn="false" value="Sources/DMK-S301-77.c"/>
<listOptionValue builtIn="false" value="Sources/TI1.c"/>
<listOptionValue builtIn="false" value="Sources/diagnostic_service_slave.c"/>
<listOptionValue builtIn="false" value="lin_cfg/lin_cfg.c"/>
</option>
<option id="com.freescale.s12z.toolchain.linker.output.b.1935526437" name="Generate S-Record file" superClass="com.freescale.s12z.toolchain.linker.output.b" value="true" valueType="boolean"/>
<inputType id="com.freescale.s12z.toolchain.linker.inputType.233201006" name="S12Z Linker Input" superClass="com.freescale.s12z.toolchain.linker.inputType">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool errorParsers="" id="com.freescale.s12z.toolchain.compiler.1919819728" name="S12Z Compiler" superClass="com.freescale.s12z.toolchain.compiler">
<option id="com.freescale.s12z.toolchain.compiler.input.sysInclude.2088267548" name="Search System Paths (#include &lt;...&gt;)" superClass="com.freescale.s12z.toolchain.compiler.input.sysInclude" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${MCUToolsBaseDir}/S12lisa_Support/s12lisac/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MCUToolsBaseDir}/S12lisa_Support/s12lisac/src&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MCUToolsBaseDir}/S12lisa_Support/s12lisac/lib_small&quot;"/>
</option>
<option id="com.freescale.s12z.toolchain.compiler.input.include.1977425397" name="Search User Paths (#include &quot;...&quot;)" superClass="com.freescale.s12z.toolchain.compiler.input.include" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/LIN_Stack/transport&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/Sources/diagnostic&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/lin_cfg&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/LIN_Stack&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/LIN_Stack/bsp/SCI&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/LIN_Stack/coreapi&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/LIN_Stack/diagnostic&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/LIN_Stack/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}\lin_cfg&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/LIN_Stack/lowlevel&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/Project_Headers&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/Sources&quot;"/>
</option>
<option id="com.freescale.s12z.toolchain.compiler.warnings.warningsFlag.hidden.adjusted.2097999947.adjusted.1080819042" superClass="com.freescale.s12z.toolchain.compiler.warnings.warningsFlag.hidden.adjusted.2097999947" value="false" valueType="boolean"/>
<option id="com.freescale.s12z.toolchain.compiler.warnings.enableWarnings.hidden.adjusted.779736889.adjusted.1434993962" superClass="com.freescale.s12z.toolchain.compiler.warnings.enableWarnings.hidden.adjusted.779736889" value="com.freescale.s12z.toolchain.warnings.enableWarnings.custom.hidden" valueType="enumerated"/>
<inputType id="com.freescale.s12z.toolchain.compiler.inputType2.c.257802963" name="S12Z C Compiler Input" superClass="com.freescale.s12z.toolchain.compiler.inputType2.c"/>
<inputType id="com.freescale.s12z.toolchain.compiler.inputType2.cpp.527776362" name="S12Z C++ Compiler Input" superClass="com.freescale.s12z.toolchain.compiler.inputType2.cpp"/>
</tool>
<tool errorParsers="" id="com.freescale.s12z.toolchain.assembler.911572405" name="S12Z Assembler" superClass="com.freescale.s12z.toolchain.assembler">
<option id="com.freescale.s12z.toolchain.asm.input.searchPaths.1104836695" name="Include File Search Path" superClass="com.freescale.s12z.toolchain.asm.input.searchPaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/Project_Headers&quot;"/>
</option>
<inputType id="com.freescale.s12z.toolchain.asm.inputType.1752661748" name="S12Z Assembler Input" superClass="com.freescale.s12z.toolchain.asm.inputType"/>
</tool>
</toolChain>
</folderInfo>
<fileInfo id="com.freescale.s12z.toolchain.release.333878984.Project_Settings/Startup_Code/starts12z.c" name="starts12z.c" rcbsApplicability="disable" resourcePath="Project_Settings/Startup_Code/starts12z.c" toolsToInvoke="com.freescale.s12z.toolchain.compiler.1919819728.148920662">
<tool errorParsers="" id="com.freescale.s12z.toolchain.compiler.1919819728.148920662" name="S12Z Compiler" superClass="com.freescale.s12z.toolchain.compiler.1919819728">
<inputType id="com.freescale.s12z.toolchain.compiler.inputType2.c.446632076" name="S12Z C Compiler Input" superClass="com.freescale.s12z.toolchain.compiler.inputType2.c"/>
<inputType id="com.freescale.s12z.toolchain.compiler.inputType2.cpp.1487949640" name="S12Z C++ Compiler Input" superClass="com.freescale.s12z.toolchain.compiler.inputType2.cpp"/>
</tool>
</fileInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="LIN_TEST_Project.com.freescale.s12z.toolchain.project.executable.1208149682" name="Freescale S12Z Project" projectType="com.freescale.s12z.toolchain.project.executable"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="com.freescale.s12z.toolchain.release.333878984;com.freescale.s12z.toolchain.release.333878984.;com.freescale.s12z.toolchain.compiler.1919819728;com.freescale.s12z.toolchain.compiler.inputType2.c.257802963">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.freescale.s12z.c.symbols.toolchain.discoveryProfile"/>
<profile id="com.freescale.s12z.c.symbols.toolchain.discoveryProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="false"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="" command="" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="com.freescale.s12z.toolchain.release.333878984;com.freescale.s12z.toolchain.release.333878984.;com.freescale.s12z.toolchain.compiler.1919819728;com.freescale.s12z.toolchain.compiler.inputType2.cpp.527776362">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="com.freescale.s12z.c.symbols.toolchain.discoveryProfile"/>
<profile id="com.freescale.s12z.c.symbols.toolchain.discoveryProfile">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="false"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
<runAction arguments="" command="" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
</storageModule>
</cproject>

8
.cwGeneratedFileSetLog Normal file
View File

@ -0,0 +1,8 @@
Sources/main.c
Project_Settings/Linker_Files/mc9s12zvl32.prm
Project_Settings/Startup_Code/starts12z.c
Project_Headers/derivative.h
Project_Headers/mc9s12zvl32.h
Lib/mc9s12zvl32.c
.settings/com.freescale.core.ide.newprojectwizard.prefs
ReferencedRSESystems.xml

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/FLASH

25
.project Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DMK-EBO-77A-SW0312</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,25 @@
eclipse.preferences.version=1
hotfix/arm.cdt.toolchain.ErrorParserHotFix=true
hotfix/arm.cdt.toolchain.UIElementValueTypeUpdate=true
hotfix/class\ com.freescale.core.ide.cdt.toolchain.ProjectErrorParserHotFix=true
hotfix/class\ com.freescale.core.ide.cdt.toolchain.QuotePathsHotFix=true
hotfix/class\ com.freescale.core.ide.cdt.toolchain.ToolOptionsUpdateHotFix=true
hotfix/class\ com.freescale.core.ide.cdt.toolchain.UiElementValueTypeHotFix=true
hotfix/coldfire.cdt.toolchain.UIElementValueTypeUpdate=true
hotfix/com.freescale.arm.cdt.toolchain=true
hotfix/com.freescale.arm.cdt.toolchain.ToolOptionsUpdate.fileAndProgram_v1=true
hotfix/com.freescale.coldfire.cdt.gcc.toolchain=true
hotfix/com.freescale.coldfire.cdt.toolchain=true
hotfix/com.freescale.coldfire.toolchain.ToolOptionsUpdate.fileAndProgram_v1=true
hotfix/com.freescale.core.ide.util.pbhotfix=true
hotfix/com.freescale.dsc.cdt.toolchain=true
hotfix/com.freescale.hc08.cdt.toolchain=true
hotfix/com.freescale.hc08.cdt.toolchain.FixCommandLinePatternHotFix=true
hotfix/com.freescale.hc08.cdt.toolchain.hc08.cdt.toolchain.UIElementValueTypeUpdate=true
hotfix/com.freescale.ppc.cdt.toolchain=true
hotfix/com.freescale.ppc.toolchain.ToolOptionsUpdate.fileAndProgram_v1=true
hotfix/com.freescale.ppc.toolchain.UIElementValueTypeUpdate.toSymbolFiles=true
hotfix/com.freescale.s12z.cdt.toolchain=true
hotfix/com.freescale.s12z.cdt.toolchain.LibOptionsHotFix=true
hotfix/dsc.cdt.toolchain.UIElementValueTypeUpdate=true
hotfix/s12z.cdt.toolchain.UIElementValueTypeUpdate=true

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
versionGenerated/versionGenerated=1.10.1.FSL_mcu105_5051

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//LIN_Stack/bsp/SCI/lin_lld_sci.c=UTF-8

7
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}

9
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,9 @@
{
"editor.renderLineHighlight": "all",
"files.associations": {
"lin_diagnostic_service.h": "c",
"lin_commontl_proto.h": "c",
"lin.h": "c",
"derivative.h": "c"
}
}

28
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "D:\\MinGW-w64\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}

1133
LIN_Stack/bsp/SCI/lin_isr.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,811 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup SCI_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file bsp/SCI/lin_lld_sci.h
*
* @author FPT Software
*
* @brief SCI for LIN network
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20101027 v1.0 First version
* 20111005 v1.1 Updated hardware support, multi timers
*
*****************************************************************************/
#ifndef __LIN_LLD_SCI
#define __LIN_LLD_SCI
/* MODULE LIN_LLD_SCI. */
#include "lin_reg.h"
#include "lin_cfg.h"
#include "lin.h"
#ifndef SCI_VERSION
#error "SCI_VERSION is not defined in lin_hw_cfg.h"
#endif
/*** MARCOS ***/
#if ((SCI_VERSION == SCI_V5) || (SCI_VERSION == SCI_V6))
#define LIN_LLD_SCI_MCU_RESET { COPCTL = 0x01; ARMCOP = 0x00;} /**< MCU reset */
#endif /* End (SCI_VERSION == SCI_V5) */
/* Define _MC9S12ZVMB_H for all MCU of MC9S12ZVMB Family */
#if (defined(_MC9S12ZVMB48_H) || defined(_MC9S12ZVMBA48_H) || defined(_MC9S12ZVMB64_H) || defined(_MC9S12ZVMBA64_H))
#define _MC9S12ZVMB_H
#endif /* End (defined(_MC9S12ZVMB48_H) || defined(_MC9S12ZVMBA48_H) || defined(_MC9S12ZVMB64_H) || defined(_MC9S12ZVMBA64_H))*/
/* Define _MC9S12ZVMA_H for all MCU of MC9S12ZVMB Family*/
#if (defined(_MC9S12ZVMA32_H) || defined(_MC9S12ZVMAL32_H) || defined(_MC9S12ZVMA16_H) || defined(_MC9S12ZVMAL16_H))
#define _MC9S12ZVMA_H
#endif /* End defined(_MC9S12ZVMA32_H) || defined(_MC9S12ZVMAL32_H) || defined(_MC9S12ZVMA16_H) || defined(_MC9S12ZVMAL16_H) */
/* Lin status bit mask */
#define LIN_STA_SUCC_TRANSFER 1 /**< LIN status bit mask: success transfer */
#define LIN_STA_ERROR_RESP 2 /**< LIN status bit mask: error in response */
#define LIN_STA_BUS_ACTIVITY 4 /**< LIN status bit mask: bus activity */
#define LIN_STA_FRAME_ERR 8 /**< LIN status bit mask: frame error */
#define LIN_STA_CHECKSUM_ERR 16 /**< LIN status bit mask: checksum error */
#define LIN_STA_READBACK_ERR 32 /**< LIN status bit mask: readback error */
#define LIN_STA_PARITY_ERR 64 /**< LIN status bit mask: parity error */
#define LIN_STA_RESET 128 /**< LIN status bit mask: reset */
#if (LIN_MODE == _SLAVE_MODE_)
/* Low-level API prototype */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_init(l_ifc_handle iii)
* @brief SCI v5 init
*
* @param iii <B>[IN]</B> lin interface handle
*
* @SDD_ID LIN_SDD_168
* @endif
*
* @return #void
*
* @local_var
* -# <B>#l_u16</B> <I>temp</I>
*
*
* @details Init SCI for LIN network
*
*
* @see #lin_goto_idle_state
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_init(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_deinit()
* @brief SCI deinit
*
* @SDD_ID LIN_SDD_169
* @endif
*
* @return #void
*
* @details
* Deinit SCI for LIN network
*//*END*----------------------------------------------------------------------*/
#if (AUTOBAUD == 1)
void lin_lld_sci_init_autobaud(l_u16 baudrate);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_deinit()
* @brief SCI deinit
*
* @SDD_ID LIN_SDD_169
* @endif
*
* @return #void
*
* @details
* Deinit SCI for LIN network
*//*END*----------------------------------------------------------------------*/
#endif
void lin_lld_sci_deinit(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_tx_wake_up()
* @brief This function requests to send wake up signal via SCI channel
*
*
* @SDD_ID LIN_SDD_170
* @endif
*
* @return #void
*
*
* @details
* This function requests to send wake up signal via SCI channel
* Send 4Tbit to 64 Tbit
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_tx_wake_up(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_int_enable()
* @brief This function enables SCI Interrupt
*
* @SDD_ID LIN_SDD_171
* @endif
*
* @return #void
*
* @details
* This function enables SCI Interrupt
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_int_enable(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_int_disable()
* @brief This function disables SCI Interrupt
*
* @SDD_ID LIN_SDD_172
* @endif
*
* @return #void
*
* @details
* This function disables SCI Interrupt
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_int_disable(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_ignore_response()
* @brief Set low level ignore flag lin_lld_ignore_flag
*
* @SDD_ID LIN_SDD_173
* @endif
*
* @return #void
*
* @details
* Set low level ignore flag lin_lld_ignore_flag
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_ignore_response(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_set_low_power_mode()
* @brief Request to enter low power mode in SCI Driver
*
* @SDD_ID LIN_SDD_174
* @endif
*
* @return #void
*
* @details
* Request to enter low power mode in SCI Driver
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_set_low_power_mode(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_rx_response(l_u8 msg_length)
*
* @param msg_length <B>IN</B> length of response data expect to wait
*
* @brief This function requests to receive response data of LIN frame via SCI channel
*
* @SDD_ID LIN_SDD_175
* @endif
*
* @return #void
*
* @details
* This function requests to receive response data of LIN frame via SCI channel
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_rx_response(l_u8 msg_length);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_tx_response()
*
* @brief This function requests to send first data and set lin_lld_state to SEND_DATA
*
* @SDD_ID LIN_SDD_179
* @endif
*
* @return #void
*
*
* @details
* This function requests to send first data and set lin_lld_state to SEND_DATA
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_tx_response(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_lld_sci_get_status()
*
* @brief Get LIN status ( return lin_status )
*
* @SDD_ID LIN_SDD_180
* @endif
*
* @return #l_u8
*
* @details
* Get LIN status ( return lin_status )
*//*END*----------------------------------------------------------------------*/
l_u8 lin_lld_sci_get_status(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_lld_sci_get_state()
*
* @brief This function is to get state of Low level layer
*
* @SDD_ID LIN_SDD_181
* @endif
*
* @return #l_u8
*
* @details
* This function is to get state of Low level layer
*//*END*----------------------------------------------------------------------*/
l_u8 lin_lld_sci_get_state(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_timeout()
*
* @brief This function is called in period Tbit in order to check timeout for IDLE and MAXFRAME
*
* @SDD_ID LIN_SDD_
* @endif
*
* @return #void
*
* @details
* This function is called in period Tbit in order to check timeout for IDLE and MAXFRAME
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_timeout(void);
#if ((SCI_VERSION != SCI_V5) && (SCI_VERSION != SCI_V6))
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_err_isr ( )
* @brief SCI Interrupt service routine that handles SCI Error
*
* @return #void
*
* @SDD_ID LIN_SDD_187
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>sci_flag_sr1</I>
* -# <B>#l_u8</B> <I>tmp_byte</I>
*
* @static_global_var
* -# <B>#pSCI</B>
* -# <B>#l_status</B>
* -# <B>#state</B>
* -# <B>#l_ifc_handle</B>
* -# <B>#current_id</B>
* -# <B>#ifc</B>
*
* @details
* SCI Interrupt service routine that handles SCI Error
*
* @see #lin_goto_idle_state
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_err_isr(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_rx_isr ( )
* @brief SCI Interrupt service routine that handles RX LIN Communication
*
* @return #void
*
* @SDD_ID LIN_SDD_188
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>sci_flag_sr1</I>
* -# <B>#l_u8</B> <I>sci_flag_sr2</I>
* -# <B>#l_u8</B> <I>tmp_byte</I>
*
* @static_global_var
* -# <B>#pSCI</B>
* -# <B>#l_status</B>
* -# <B>#frame_timeout_cnt</B>
* -# <B>#lin_max_frame_res_timeout_val</B>
* -# <B>#current_id</B>
* -# <B>#ifc</B>
* -# <B>#l_ifc_handle</B>
* -# <B>#response_buffer</B>
*
* @details
* SCI Interrupt service routine that handles RX LIN Communication
*
* @see #lin_checksum
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_rx_isr(void);
#else
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_isr()
*
* @brief SCI Interrupt service routine that handles LIN Communication
*
* @SDD_ID LIN_SDD_189
* @endif
*
* @return #void
*
* @local_var
* -# <B>#l_u8</B> <I>sci_flag_sr1</I>
* -# <B>#l_u8</B> <I>tmp_byte</I>
*
* @details
* SCI Interrupt service routine that handles LIN Communication
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_isr(void);
#endif /* End (SCI_VERSION != SCI_V5) */
/*** INTERNAL FUNCTIONS ***/
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_goto_idle_state()
*
* @brief Enter IDLE state
*
* @SDD_ID LIN_SDD_182
* @endif
*
* @return #void
*
* @details
* Enter IDLE state
*//*END*----------------------------------------------------------------------*/
void lin_goto_idle_state(void);
#endif /* End (LIN_MODE == _SLAVE_MODE_) */
#if LIN_MODE == _MASTER_MODE_
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_init(sci_channel_name channel, l_ifc_handle iii)
*
* @param channel <B>IN</B> sci channel name
* @param iii <B>IN</B> LIN interface name
*
* @brief SCI Init
*
* @SDD_ID LIN_SDD_97
* @endif
*
* @return #void
*
* @local_var
* -# <B>#l_u16</B> <I>*tmp</I>
* -# <B>#lin_node</B> <I>*lnode_p</I>
* -# <B>#lin_configuration</B> <I>*lconf_p</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @see lin_goto_idle_state
*
* @details
* This function is inited SCI for LIN network
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_init(sci_channel_name channel, l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_deinit(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief SCI deinit
*
* @SDD_ID LIN_SDD_98
* @endif
*
* @return #void
*
*
* @static_global_var
* -# <B>#lin_node</B>
* -# <B>#lnode_p</B>
*
* @see lin_lld_sci_int_disable
* @see lin_node_descrs
*
* @details
* This function is deinited SCI
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_deinit(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_tx_header(sci_channel_name channel, l_u8 pid_id)
*
* @param channel <B>IN</B> sci channel name
* @param pid_id <B>IN</B> PID to be send
*
* @brief This function requests to send header of LIN frame via SCI channel
*
* @SDD_ID LIN_SDD_99
* @endif
*
* @return #void
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
*
* @see lin_process_parity
* @see lin_node_descrs
*
* @details
* This function requests to send header of LIN frame via SCI channel
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_tx_header(sci_channel_name channel, l_u8 pid_id);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_tx_wake_up(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief This function requests to send wake up signal via SCI channel.
*
* @SDD_ID LIN_SDD_100
* @endif
*
* @return #void
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @see lin_goto_idle_state
*
* @details
* This function requests to send wake up signal via SCI channel.
* Send 4Tbit to 64 Tbit
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_tx_wake_up(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_int_enable(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief This function enables SCI Interrupt
*
* @SDD_ID LIN_SDD_101
* @endif
*
* @return #void
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
*
* @details
* This function enables SCI Interrupt
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_int_enable(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_int_disable(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief This function disables SCI Interrupt
*
* @SDD_ID LIN_SDD_102
* @endif
*
* @return #void
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
*
* @details
* This function disables SCI Interrupt
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_int_disable(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_ignore_response(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief Set low level ignore flag lin_lld_ignore_flag
*
* @SDD_ID LIN_SDD_103
* @endif
*
* @return #void
*
* @see lin_goto_idle_state
*
* @details
* Set low level ignore flag lin_lld_ignore_flag
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_ignore_response(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_set_low_power_mode(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief Request to enter low power mode in SCI Driver
*
* @SDD_ID LIN_SDD_104
* @endif
*
* @return #void
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* Request to enter low power mode in SCI Driver
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_set_low_power_mode(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_rx_response(sci_channel_name channel, l_u8 msg_length)
*
* @param channel <B>IN</B> sci channel name
* @param msg_length <B>IN</B> length of response data expect to wait
*
* @brief This function requests to receive response data of LIN frame via SCI channel
*
* @SDD_ID LIN_SDD_105
* @endif
*
* @return #void
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* This function requests to receive response data of LIN frame via SCI channel
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_rx_response(sci_channel_name channel,l_u8 msg_length);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_tx_response(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief This function requests to send first data and set lin_lld_state to SEND_DATA
*
* @SDD_ID LIN_SDD_109
* @endif
*
* @return #void
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* This function requests to send first data and set lin_lld_state to SEND_DATA
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_tx_response(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_lld_sci_get_status(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief Get LIN status ( return lin_status )
*
* @SDD_ID LIN_SDD_110
* @endif
*
* @return #l_u8
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* Get LIN status ( return lin_status )
*//*END*----------------------------------------------------------------------*/
l_u8 lin_lld_sci_get_status(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_lld_sci_get_state(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief Get LIN state ( return state )
*
* @SDD_ID LIN_SDD_
* @endif
*
* @return #l_u8
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* Get LIN state ( return state )
*//*END*----------------------------------------------------------------------*/
l_u8 lin_lld_sci_get_state(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_timeout(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief This function is called in period Tbit in order to check timeout for IDLE and MAXFRAME
*
* @SDD_ID LIN_SDD_111
* @endif
*
* @return #void
*
* @local_var
* -# <B>#register lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* This function is called in period Tbit in order to check timeout for IDLE and MAXFRAME
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_timeout(sci_channel_name channel);
#if ((SCI_VERSION != SCI_V5) && (SCI_VERSION != SCI_V6))
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_err_isr ( sci_channel_name channel)
* @brief SCI Interrupt service routine that handles SCI Error
*
* @param channel <B>[IN]</B> sci channel name
*
* @return #void
*
* @SDD_ID LIN_SDD_115
* @endif
*
* @local_var
* -# <B>#lin_node</B> <I>*lnode_p</I>
* -# <B>#l_u8</B> <I>sci_flag_sr1</I>
* -# <B>#l_u8</B> <I>tmp_byte</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* SCI Interrupt service routine that handles SCI Error
*
* @see #lin_goto_idle_state
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_err_isr(sci_channel_name channel);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_rx_isr ( sci_channel_name channel)
* @brief SCI Interrupt service routine that handles RX LIN Communication
*
* @param channel <B>[IN]</B> sci channel name
*
* @return #void
*
* @SDD_ID LIN_SDD_116
* @endif
*
* @local_var
* -# <B>#register lin_node</B> <I>*lnode_p</I>
* -# <B>#l_u8</B> <I>sci_flag_sr1</I>
* -# <B>#l_u8</B> <I>sci_flag_sr2</I>
* -# <B>#l_u8</B> <I>tmp_byte</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
* -# <B>#lin_max_frame_res_timeout_val</B>
*
* @details
* SCI Interrupt service routine that handles RX LIN Communication
*
* @see #lin_goto_idle_state
* @see #lin_process_parity
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_rx_isr(sci_channel_name channel);
#else
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_sci_isr(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief SCI Interrupt service routine that handles LIN Communication
*
* @SDD_ID LIN_SDD_117
* @endif
*
* @return #void
*
* @local_var
* -# <B>#l_u8 </B> <I>sci_flag_sr1</I>
* -# <B>#l_u8 </B> <I>tmp_byte</I>
* -# <B>#register lin_node </B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @see #lin_goto_idle_state
* @see #lin_checksum
* @see #lin_process_parity
*
* @details
* SCI Interrupt service routine that handles LIN Communication
*//*END*----------------------------------------------------------------------*/
void lin_lld_sci_isr(sci_channel_name channel);
#endif /* End (SCI_VERSION != SCI_V5) */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_goto_idle_state(sci_channel_name channel)
*
* @param channel <B>IN</B> sci channel name
*
* @brief Enter IDLE state
*
* @SDD_ID LIN_SDD_112
* @endif
*
* @return #void
*
* @local_var
* -# <B>#register lin_node</B> <I>*lnode_p</I>
*
* @static_global_var
* -# <B>#lin_node_descrs</B>
*
* @details
* Enter IDLE state
*//*END*----------------------------------------------------------------------*/
void lin_goto_idle_state(sci_channel_name channel);
#endif /* End (LIN_MODE == _MASTER_MODE_) */
#endif /* ifndef _LIN_LLD_SCI */
/**
* @}
*/

View File

@ -0,0 +1,423 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup SCI_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file bsp/SCI/lin_lld_timesrv.c
*
* @author FPT Software
*
* @brief Timer for S08, S12, S12X
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20101027 v1.0 First version
* 20111005 v1.1 Updated hardware support
* 20111121 v1.2 Updated timer config for J637
*
*****************************************************************************/
#include "lin_lld_timesrv.h"
#include "lin_lld_sci.h"
#include "lin_common_proto.h"
#include "lin_hw_cfg.h"
#if defined(_MC9S12I32_H)
#include "analog_die_reg.h"
#endif /* End defined(_MC9S12I32_H) */
#if defined (_MC9S12I128_H)
#include "mm912j637.h"
#endif /* End defined(_MC9S12I128_H) */
#if (LIN_MODE == _MASTER_MODE_)
extern const lin_hardware_name lin_virtual_ifc[LIN_NUM_OF_IFCS];
#endif /* End (LIN_MODE == _MASTER_MODE_) */
#ifdef MULTI_TIMER_MODE
extern const l_u16 time_base_period[LIN_NUM_OF_IFCS];
#endif /* End MULTI_TIMER_MODE */
#if (_MCU_ == _S12X_)
void lin_lld_timer_S12X_init (void)
{
#ifdef MULTI_TIMER_MODE
/* Init PIT timer */
PITTF = 0x00;
PITCE = 0x00;
PITINTE = 0x00;
/* Configures the PIT (Periodic Interrupt Timer) to generate a periodic interrupt of 500us */
/* (Interrupt on channel 0) */
/*** USING PIT Chanel 0 ***/
#if (_PIT0_ == 1)
PITTF_PTF0 = 1;
PITCE_PCE0 = 1;
PITINTE_PINTE0 = 1;
/* Baudrate register loading */
PITLD0 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT0_INDEX]));
#endif /* (_PIT0_ == 1) */
/*** USING PIT Chanel 1 ***/
#if (_PIT1_ == 1)
PITTF_PTF1 = 1;
PITCE_PCE1 = 1;
PITINTE_PINTE1 = 1;
/* Baudrate register loading*/
PITLD1 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT1_INDEX]));
#endif /* (_PIT1_ == 1) */
/*** USING PIT Chanel 2 ***/
#if (_PIT2_ == 1)
PITTF_PTF2 = 1;
PITCE_PCE2 = 1;
PITINTE_PINTE2 = 1;
/* Baudrate register loading*/
PITLD2 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT2_INDEX]));
#endif /* (_PIT2_ == 1) */
/*** USING PIT Chanel 3 ***/
#if (_PIT3_ == 1)
PITTF_PTF3 = 1;
PITCE_PCE3 = 1;
PITINTE_PINTE3 = 1;
/* Baudrate register loading */
PITLD3 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT3_INDEX]));
#endif /* (_PIT3_ == 1) */
/*** USING PIT Chanel 4 ***/
#if (_PIT4_ == 1)
PITTF_PTF4 = 1;
PITCE_PCE4 = 1;
PITINTE_PINTE4 = 1;
/* Baudrate register loading */
PITLD4 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT4_INDEX]));
#endif /* (_PIT4_ == 1) */
/*** USING PIT Chanel 5 ***/
#if (_PIT5_ == 1)
PITTF_PTF5 = 1;
PITCE_PCE5 = 1;
PITINTE_PINTE5 = 1;
/* Baudrate register loading*/
PITLD5 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT5_INDEX]));
#endif /* (_PIT5_ == 1) */
/*** USING PIT Chanel 2 ***/
#if (_PIT6_ == 1)
PITTF_PTF6 = 1;
PITCE_PCE6 = 1;
PITINTE_PINTE6 = 1;
/* Baudrate register loading*/
PITLD6 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT6_INDEX]));
#endif /* (_PIT6_ == 1) */
/*** USING PIT Chanel 7 ***/
#if (_PIT7_ == 1)
PITTF_PTF7 = 1;
PITCE_PCE7 = 1;
PITINTE_PINTE7 = 1;
/* Baudrate register loading */
PITLD7 = (l_u16)((MCU_BUS_FREQ/1000000)*(time_base_period[PIT7_INDEX]));
#endif /* (_PIT7_ == 1) */
PITMTLD0=0x00;
/* Enable PIT Module */
PITCFLMT = 0xA0;
#else /* Else MULTI_TIMER_MODE */
/* Init PIT0 timer for single timer mode */
PITTF = 0x00;
PITCE = 0x00;
PITINTE = 0x00;
/* Configures the PIT (Periodic Interrupt Timer) to generate a periodic interrupt of 500us */
/* (Interrupt on channel 0) */
/*** USING PIT Chanel 0 ***/
PITTF_PTF0 = 1;
PITCE_PCE0 = 1;
PITINTE_PINTE0 = 1;
/* TIME_BASE_PERIOD micro seconds with Fbus = MCU_BUS_FREQ Mhz*/
PITLD0 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
PITMTLD0=0x00;
/* Enable PIT Module */
PITCFLMT = 0xA0;
#endif /* End MULTI_TIMER_MODE */
}
#endif /* End (_MCU_ == _S12X_) */
/* ----------------------------------------------------------------- */
#if (_MCU_ == _S12_)
void lin_lld_timer_S12_init (void)
{
#if defined(_MC9S12I32_H)
l_u16 temp;
/* Init timer for MM912F634 apply for 9S12I32 MCU */
/* Initialize TIM timer */
/* Timer functions normally */
TSCR1 = 0x00;
/* Output Compare Select Timer 3 */
TIOS = 8;
/* Define an output associated OC3 */
TCTL1 = 192;
/* Enable toggle output compare pin */
TTOV = 8;
/* Enable Hardware interrupt request */
TSCR2 = 0x88;
/* Enable tim3 */
TIE = 8;
/* Set timer period */
temp = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
TC3hi = (l_u8)(temp>>8);
TC3lo = (l_u8)temp;
TSCR1 = 128;
/* End define for I32 */
#elif defined(_MC9S12GN32_H) || defined(_MC9S12G64_H)
/* Timer functions normally */
TSCR1 = 8;
/* Set up timer channel 0 */
/* Timer output compare */
TIOS = TIOS_IOS0_MASK;
/* Enable toggle output compare pin */
TTOV = TTOV_TOV0_MASK;
/* Enable Hardware interrupt request */
TSCR2 = 0x00;
/* Enable timer channel 0 interrupt */
TIE = TIE_C0I_MASK;
/* Set timer period */
TC0 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
/* Enable timer */
TSCR1 = TSCR1_TEN_MASK ;
/* End define for GN32, G64 */
#elif (defined(_MC9S12VR64_H) || defined(_MC9S12VR32_H))
/* Timer functions normally */
TSCR1 = 8;
/* Set up timer channel 3 */
CFORC |= CFORC_FOC0_MASK;
/* Timer output compare */
TIOS |= TIOS_IOS0_MASK;
/* Enable toggle output compare pin */
TTOV |= TTOV_TOV0_MASK;
/* Disable Hardware interrupt request and Timer prescaler = 1 */
TSCR2 = 0x00;
/* Enable timer channel 3 interrupt */
TIE |= TIE_C0I_MASK;
/* Set timer period */
TC0 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
/* Enable timer */
TSCR1 = TSCR1_TEN_MASK;
/* End (defined(_MC9S12VR64_H) || defined(_MC9S12VR32_H))*/
#elif defined(_MM912J637_H)
/* Disable Timer */
TSCR1 = 0x00;
/* Timer output compare */
TIOS = 0x08;
/* Timer disconnect from output pin */
TCTL1 = 0x00;
/* Disable input capture */
TCTL2 = 0x00;
/* disable toggle output compare pin */
TTOV = 0x00;
/* Enable timer counter reset by successfull OC on channel */
TSCR2 = 0x08;
/* Enable timer channel 3 interrupt */
TIE = 0x08;
/* Set timer period */
TC3 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
/* Enable timer */
TSCR1 = 0x80;
/* End define for 9S12I128 */
#elif defined(_MM9Z1J638_H)
/* Disable Timer */
B_TSCR1 = 0x00;
/* Timer output compare */
B_TIOS = 0x08;
/* Timer disconnect from output pin */
B_TCTL1 = 0x00;
/* Disable input capture */
B_TCTL2 = 0x00;
/* disable toggle output compare pin */
B_TTOV = 0x00;
/* Enable timer counter reset by successfull OC on channel */
B_TSCR2 = 0x08;
/* Enable timer channel 3 interrupt */
B_TIE = 0x08;
/* Set timer period */
B_TC3 = MCU_BUS_FREQ/(1000000/TIME_BASE_PERIOD);
/* Enable timer */
B_TSCR1 = 0x80;
#else
#if defined(_MC9S12XHY256_H) || defined(_MC9S12HY64_H)
#define TSCR1 TIM0_TSCR1
#define OCPD TIM0_OCPD
#define PACTL TIM0_PACTL
#define OC7M TIM0_OC7M
#define TIOS TIM0_TIOS
#define TCTL1 TIM0_TCTL1
#define TTOV TIM0_TTOV
#define TSCR2 TIM0_TSCR2
#define TFLG1 TIM0_TFLG1
#define TIE TIM0_TIE
#define TC7 TIM0_TC7
#endif /* End for 9S12XHY256 and 9S12HY64 */
#if (defined(_MC9S12ZVML128_H) || defined(_MC9S12ZVL32_H)||defined(_MC9S12ZVHY64_H)||defined(_MC9S12ZVH128_H)\
||defined(_MC9S12ZVML31_H)||defined(_MC9S12ZVMC256_H)||defined(_MC9S12ZVL128_H)||defined(_MC9S12ZVMB_H))
/*Configure the timer*/
/*Timer prescaler = 1 */
TIM0TSCR2 = 0x00;
/*Enable Channel 2 as Output Compare */
TIM0TIOS_IOS2 = 1;
/*Enable Channel 2 interrupt */
TIM0TIE_C2I = 1;
TIM0TC2 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
/*Disable the timer when the MCU is in freeze mode */
TIM0TSCR1_TSFRZ = 1;
/*Enable the Timer */
TIM0TSCR1_TEN = 1;
#else
#if (defined(_MC9S12ZVMA_H)|| defined(_MC9S12VRP64_H) || defined(_MC9S12VRP48_H))
/*Configure the timer*/
/*Timer prescaler = 1 */
TIM1TSCR2 = 0x00;
/*Enable Channel 0 as Output Compare */
TIM1TIOS_IOS0 = 1;
/*Enable Channel 0 interrupt */
TIM1TIE_C0I = 1;
TIM1TC0 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
/*Disable the timer when the MCU is in freeze mode */
TIM1TSCR1_TSFRZ = 1;
/*Enable the Timer */
TIM1TSCR1_TEN = 1;
#else
#if defined(_MC9S12ZVC64_H)
/*Configure the timer*/
/*Timer prescaler = 32 (6.25MHZ/32 ~ 5.12[us]) */
TIM1TSCR2 = 0x08;
/*Enable Channel 2 as Output Compare */
TIM1TIOS_IOS2 = 1;
/*Enable Channel 2 interrupt */
TIM1TIE_C2I = 1;
TIM1TC2 = (MCU_BUS_FREQ/500000)*TIME_BASE_PERIOD;
/*Disable the timer when the MCU is in freeze mode */
TIM1TSCR1_TSFRZ = 1;
/*Enable the Timer */
TIM1TSCR1_TEN = 1;
#else
/* Initialize TIM timer */
/* Timer functions normally */
TSCR1 = 8;
/* Disable timer */
OCPD = 128;
/* Clock select bits: Div. by 64 clock enabled with pin low level */
PACTL = 12;
/* Timer output compare */
OC7M = 128;
/* Output Compare Select Timer 7 */
TIOS = 128;
/* Define an output associated OC7 */
TCTL1 = 192;
/* Enable toggle output compare pin */
TTOV = 128;
/* Enable Hardware interrupt request */
TSCR2 = 136;
/* Enable Output Compare */
TFLG1 = 255;
/* Enable tim7 */
TIE = 128;
/* Set timer period */
TC7 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
/* Enable timer */
TSCR1 = 128;
#endif /* End defined(_MC9S12ZVC64_H) */
#endif /* End (defined(_MC9S12ZVMA_H)|| defined(_MC9S12VRP64_H) || defined(_MC9S12VRP48_H)) */
#endif /* End (defined(_MC9S12ZVML128_H) || defined(_MC9S12ZVL32_H) || defined(_MC9S12ZVML31_H)) */
#endif /* End defined(_MC9S12I32_H) */
}
#endif /* End (_MCU_ == _S12_) */
/* ----------------------------------------------------------------- */
#if (_MCU_ == _S08_)
void lin_lld_timer_S08_init (void)
{
#if defined(_MC9S08RN60_H)
/* Stop timer */
MTIM0_SC = 0x10;
/* Initialize appropriate value to the compare/modulo/reload register */
MTIM0_MOD = 0xFE;
/* Set pre-scaler */
MTIM0_CLK = 0x05;
/* Reset HW Counter and run timer */
MTIM0_SC = 0x60;
#else
/* Configures the TPM to generate a periodic interrupt of 500us */
/* (Interrupt on channel 0) */
/* clear prescaler and disable the timer */
TPM1SC = 0x00;
/* clear interrupt flag and disable interrupt channel;
channel performs output compare with not using pin */
TPM1C0SC = 0x50;
/* set maximum modulo value */
TPM1C0V = TPM1MOD = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
TPM1CNTH = 0x00;
/* enable timer and select the TPM clock source*/
TPM1SC = 0x08;
#endif /*End defined(_MC9S08RN60_H)*/
}
#endif /* End (_MCU_ == _S08_) */
#ifdef MULTI_TIMER_MODE
void lin_lld_timer_isr(l_u8 index)
{
/* Timeout for SCI channel */
lin_lld_sci_timeout(lin_virtual_ifc[index]);
/*** Master task firing ***/
}
#else /* Else MULTI_TIMER_MODE */
void lin_lld_timer_isr(void)
{
#if LIN_MODE == _MASTER_MODE_
l_u8 i;
/* Timeout for SCI channel */
for(i=0; i<LIN_NUM_OF_IFCS; i++)
{
lin_lld_sci_timeout(lin_virtual_ifc[i]);
}
/*** Master task firing ***/
#else
lin_lld_sci_timeout();
#endif /* End LIN_MODE == _MASTER_MODE_ */
}
#endif /* End MULTI_TIMER_MODE */
/**
* @}
*/

View File

@ -0,0 +1,130 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup SCI_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file bsp/SCI/lin_lld_timesrv.h
*
* @author FPT Software
*
* @brief Timer and time interrupt for S08, S12, S12X
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
* 20111005 v1.1 Updated hardware support
*
*****************************************************************************/
#ifndef __LIN_LLD_TIMESRV
#define __LIN_LLD_TIMESRV
/* MODULE LIN_LLD_TIMESRV. */
#include "lin_cfg.h"
#include "lin.h"
#if defined(_MC9S08MP16_H) /* If using MC9S08MP16 then replace TPM timer by FTM timer */
#define TPM1SC FTM1SC
#define TPM1C0SC FTM1C0SC
#define TPM1C0V FTM1C0V
#define TPM1MOD FTM1MOD
#define TPM1CNTH FTM1CNTH
#define TPM1CNTL FTM1CNTL
#define TPM1C0SC_CH0F_MASK FTM1C0SC_CH0F_MASK
#define VectorNumber_Vtpm1ch0 VectorNumber_Vftm1ch0
#endif /* End MC9S08MP16 */
#if (_MCU_ == _S12X_)
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_timer_S12X_init()
* @brief Initialize TPM Timer and Configures the PIT (Periodic Interrupt Timer) to generate a periodic interrupt of 500us.
*
* @return #void
*
* @SDD_ID LIN_SDD_114
* @endif
*
* @details
* Initialize TPM Timer and Configures the PIT (Periodic Interrupt Timer) to generate a periodic interrupt of 500us.
*
*//*END*----------------------------------------------------------------------*/
void lin_lld_timer_S12X_init(void);
#endif /* End (_MCU_ == _S12X_) */
#if (_MCU_ == _S12_)
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_timer_S12_init()
* @brief Initialize TIM1 timer
*
*
* @SDD_ID LIN_SDD_114
* @endif
*
* @return #void
*
* @details
* Initialize TIM1 timer
*
*//*END*----------------------------------------------------------------------*/
void lin_lld_timer_S12_init(void);
#endif /* End (_MCU_ == _S12_) */
#if (_MCU_ == _S08_)
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_timer_S08_init ( )
* @brief Timer interrupt service routine
*
* @return #void
*
* @SDD_ID LIN_SDD_114
* @endif
*
* @details
* Initialize TPM Timer
*
*//*END*----------------------------------------------------------------------*/
void lin_lld_timer_S08_init(void);
#endif /* End (_MCU_ == _S08_) */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_lld_timer_isr()
* @brief Timer interrupt service routine
*
* @return #void
*
* @SDD_ID LIN_SDD_113
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
*
* @see #lin_lld_sci_timeout
*
* @details
* Timer interrupt service routine
*//*END*----------------------------------------------------------------------*/
#ifdef MULTI_TIMER_MODE
void lin_lld_timer_isr(l_u8 index);
#else
void lin_lld_timer_isr(void);
#endif /* End MULTI_TIMER_MODE */
#endif /* __LIN_LLD_TIMESRV */
/**
* @}
*/

991
LIN_Stack/bsp/SCI/lin_reg.h Normal file
View File

@ -0,0 +1,991 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup SCI_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file bsp/SCI/lin_reg.h
*
* @author FPT Software
*
* @brief SCI register definition on S08, S12, S12X
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20101027 v1.0 First version
*
*****************************************************************************/
#ifndef LIN_REG_H
#define LIN_REG_H
#include "lin_hw_cfg.h"
/*************************************/
/****** Common Register struct *****/
/*************************************/
/**
* @var typedef unsigned char tU08
* unsigned 8 bits definition
*/
typedef unsigned char tU08; /**< unsigned 8 bit definition */
/**
* @var typedef unsigned char tU16
* unsigned 16 bits definition
*/
typedef unsigned short tU16; /**< unsigned 16 bit definition */
/**
* @var typedef unsigned long tU32
* unsigned 32 bits definition
*/
typedef unsigned long tU32; /**< unsigned 32 bit definition */
/**
* @var typedef unsigned char tS08
* signed 32 bits definition
*/
typedef signed char tS08; /**< signed 8 bit definition */
/**
* @var typedef signed int tS16
* signed 16 bits definition
*/
typedef signed short tS16; /**< signed 16 bit definition */
/**
* @var typedef signed long tS32
* signed 32 bits definition
*/
typedef signed long tS32; /**< signed 32 bit definition */
#if (!defined(_MC9S12ZVML128_H) && !defined(_MC9S12ZVML31_H))
#pragma MESSAGE DISABLE C1106 /**< WARNING C1106: Non-standard bitfield type */
#endif /* End if (!defined(_MC9S12ZVML128_H) && !defined(_MC9S12ZVML31_H)) */
/**
* @var uREG08 tREG08
* register 8 bits
*/
/**
* @union uREG08
* register 8 bits
*/
typedef union uREG08 /**< 8 bit register with byte and bit access*/
{
tU08 byte; /**< access whole register e.g. var.byte = 0xFF;*/
struct
{
tU08 _0 :1; /**< bit 0 */
tU08 _1 :1; /**< bit 1 */
tU08 _2 :1; /**< bit 2 */
tU08 _3 :1; /**< bit 3 */
tU08 _4 :1; /**< bit 4 */
tU08 _5 :1; /**< bit 5 */
tU08 _6 :1; /**< bit 6 */
tU08 _7 :1; /**< bit 7 */
} bit; /**< access bit at a time e.g. var.bit._7 = 1; */
} tREG08;
/**
* @var uREG16 tREG16
* register 16 bits
*/
/**
* @union uREG16
* register 16 bits
*/
typedef union uREG16 /**< 16 bit register with word and byte access*/
{
tU16 word; /**< access whole word */
struct
{
tREG08 msb; /**< msb byte */
tREG08 lsb; /**< lsb byte */
} byte; /**< access byte at a time */
} tREG16;
/*************************************/
/******* SCI Register struct *******/
/*************************************/
#if (SCI_VERSION == SCI_V2)
/**
* @var uSCIBDH tSCIBDH
* SCI baurate high register
*/
/**
* @union uSCIBDH
* SCI baurate high register
*/
typedef union uSCIBDH
{
tU08 byte; /**< access register as byte */
struct
{
tU08 sbr8 :1; /**< msb baud rate select bits: bit 8 */
tU08 sbr9 :1; /**< msb baud rate select bits: bit 9 */
tU08 sbr10 :1; /**< msb baud rate select bits: bit 10 */
tU08 sbr11 :1; /**< msb baud rate select bits: bit 11 */
tU08 sbr12 :1; /**< msb baud rate select bits: bit 12 */
tU08 :1; /**< bit reserved area */
tU08 :1; /**< bit reserved area */
tU08 :1; /**< bit reserved area */
} bit; /**< access register as bits */
} tSCIBDH;
#endif /* End (SCI_VERSION == SCI_V2) */
#if (SCI_VERSION == SCI_V4)
/**
* @union tSCIBDH
* SCI baud rate higher byte
*/
typedef union uSCIBDH
{
tU08 byte; /**< access register as byte */
struct
{
tU08 sbr8 :1; /**< msb baud rate select bits: bit 8 */
tU08 sbr9 :1; /**< msb baud rate select bits: bit 9 */
tU08 sbr10 :1; /**< msb baud rate select bits: bit 10 */
tU08 sbr11 :1; /**< msb baud rate select bits: bit 11 */
tU08 sbr12 :1; /**< msb baud rate select bits: bit 12 */
tU08 :1; /**< bit reserved area */
tU08 rxegie :1; /**< RxD Input Active Edge Interrupt Enable (for RXEDGIF) */
tU08 lbkdie :1; /**< LIN Break Detect Interrupt Enable (for LBKDIF) */
} bit; /**< access register as bits */
} tSCIBDH;
#endif /* End (SCI_VERSION == SCI_V4) */
#if (SCI_VERSION == SCI_V5)
/**
* @var uSCIBDH tSCIBDH
*/
/**
* @union uSCIBDH
* SCI Baud Rate Register
*/
typedef union uSCIBDH
{
tU08 byte; /**< access register as byte */
struct
{
tU08 sbr8 :1; /**< msb baud rate select bits: bit 8 */
tU08 sbr9 :1; /**< msb baud rate select bits: bit 9 */
tU08 sbr10 :1; /**< msb baud rate select bits: bit 10 */
tU08 sbr11 :1; /**< msb baud rate select bits: bit 11 */
tU08 sbr12 :1; /**< msb baud rate select bits: bit 12 */
tU08 tnp :2; /**< transmit narrow pulse */
tU08 iren :1; /**< IRDA enable */
} bit; /**< access register as bits */
struct /**< alternate bits for SCIASR1 */
{
tU08 bkdif :1; /**< break detect interrupt flag */
tU08 berrif :1; /**< bit error interrupt flag */
tU08 berrv :1; /**< bit error value */
tU08 :4; /**< bit reserved area */
tU08 rxedgif:1; /**< receive input active edge interrupt flag */
} abit; /**< alternate bits for SCIBDH */
} tSCIBDH;
#endif /* End (SCI_VERSION == SCI_V5) */
#if (SCI_VERSION == SCI_V6)
/**
* @var uSCIBDH tSCIBDH
*/
/**
* @union uSCIBDH
* SCI Baud Rate Register
*/
typedef union uSCIBDH
{
tU08 byte; /**< access register as byte */
struct
{
tU08 sbr8 :1; /**< msb baud rate select bits: bit 8 */
tU08 sbr9 :1; /**< msb baud rate select bits: bit 9 */
tU08 sbr10 :1; /**< msb baud rate select bits: bit 10 */
tU08 sbr11 :1; /**< msb baud rate select bits: bit 11 */
tU08 sbr12 :1; /**< msb baud rate select bits: bit 12 */
tU08 sbr13 :1; /**< msb baud rate select bits: bit 13 */
tU08 sbr14 :1; /**< msb baud rate select bits: bit 14 */
tU08 sbr15 :1; /**< msb baud rate select bits: bit 15 */
} bit; /**< access register as bits */
struct /**< alternate bits for SCIASR1 */
{
tU08 bkdif :1; /**< break detect interrupt flag */
tU08 berrif :1; /**< bit error interrupt flag */
tU08 berrv :1; /**< bit error value */
tU08 :4; /**< bit reserved area */
tU08 rxedgif:1; /**< receive input active edge interrupt flag */
} abit; /**< alternate bits for SCIBDH */
} tSCIBDH;
#endif /* End (SCI_VERSION == SCI_V6) */
#if ((SCI_VERSION != SCI_V5) && (SCI_VERSION != SCI_V6))
/**
* @union tSCIBDL
* SCI baud rate lower byte
*/
typedef union uSCIBDL
{
tU08 byte; /**< access register as byte */
struct
{
tU08 sbr0 :1; /**< lsb baud rate select bits: bit 0 */
tU08 sbr1 :1; /**< lsb baud rate select bits: bit 1 */
tU08 sbr2 :1; /**< lsb baud rate select bits: bit 2 */
tU08 sbr3 :1; /**< lsb baud rate select bits: bit 3 */
tU08 sbr4 :1; /**< lsb baud rate select bits: bit 4 */
tU08 sbr5 :1; /**< lsb baud rate select bits: bit 5 */
tU08 sbr6 :1; /**< lsb baud rate select bits: bit 6 */
tU08 sbr7 :1; /**< lsb baud rate select bits: bit 7 */
} bit; /**< access register as bits */
} tSCIBDL;
#else
typedef union uSCIBDL
{
tU08 byte; /**< access register as byte */
struct
{
tU08 sbr0 :1; /**< lsb baud rate select bits: bit 0 */
tU08 sbr1 :1; /**< lsb baud rate select bits: bit 1 */
tU08 sbr2 :1; /**< lsb baud rate select bits: bit 2 */
tU08 sbr3 :1; /**< lsb baud rate select bits: bit 3 */
tU08 sbr4 :1; /**< lsb baud rate select bits: bit 4 */
tU08 sbr5 :1; /**< lsb baud rate select bits: bit 5 */
tU08 sbr6 :1; /**< lsb baud rate select bits: bit 6 */
tU08 sbr7 :1; /**< lsb baud rate select bits: bit 7 */
} bit; /**< access register as bits */
struct
{
tU08 bkdie :1; /**< break detect interrupt enable */
tU08 berrie :1; /**< bit error interrupt enable */
tU08 :5; /**< bit reserved area */
tU08 rxedgie:1; /**< receive input active edge interrupt enable */
} abit; /**< alternate bits for SCIBDL */
} tSCIBDL;
#endif /* End (SCI_VERSION != SCI_V5 && SCI_VERSION != SCI_V6) */
#if (SCI_VERSION == SCI_V6)
/**
* @var uSCICR1 tSCICR1
*/
/**
* @union uSCICR1
* SCI Control Register 1
*/
typedef union uSCICR1
{
tU08 byte; /**< access register as byte */
struct
{
tU08 pt :1; /**< parity type */
tU08 pe :1; /**< parity enable */
tU08 ilt :1; /**< idle line type */
tU08 wake :1; /**< wake up by address mark/idle */
tU08 m :1; /**< mode select */
tU08 rsrc :1; /**< receiver source */
tU08 sciswai :1; /**< stop in wait mode */
tU08 loops :1; /**< loop mode/single wire mode enable */
} bit; /**< access register as bits */
struct
{
tU08 bkdfe :1; /**< break detect feature enable */
tU08 berrm0 :1; /**< bit error mode */
tU08 berrm1 :1; /**< bit error mode */
tU08 :2; /**< bit reserved area */
tU08 tnp :2; /**< transmit narrow pulse */
tU08 iren :1; /**< IRDA enable */
} abit; /**< alternate bits for SCIACR1 */
} tSCICR1;
#elif (SCI_VERSION == SCI_V5)
/**
* @var uSCICR1 tSCICR1
*/
/**
* @union uSCICR1
* SCI Control Register 1
*/
typedef union uSCICR1
{
tU08 byte; /**< access register as byte */
struct
{
tU08 pt :1; /**< parity type */
tU08 pe :1; /**< parity enable */
tU08 ilt :1; /**< idle line type */
tU08 wake :1; /**< wake up by address mark/idle */
tU08 m :1; /**< mode select */
tU08 rsrc :1; /**< receiver source */
tU08 sciswai :1; /**< stop in wait mode */
tU08 loops :1; /**< loop mode/single wire mode enable */
} bit; /**< access register as bits */
struct
{
tU08 bkdfe :1; /**< break detect feature enable */
tU08 berrm0 :1; /**< bit error mode */
tU08 berrm1 :1; /**< bit error mode */
tU08 :5; /**< bit reserved area */
} abit; /**< alternate bits for SCIACR1 */
} tSCICR1;
#else /* SCI V2 and V4 */
/**
* @union tSCICR1
* SCI control register 1
*/
typedef union uSCICR1
{
tU08 byte; /**< access register as byte */
struct
{
tU08 pt :1; /**< parity type */
tU08 pe :1; /**< parity enable */
tU08 ilt :1; /**< idle line type */
tU08 wake :1; /**< wake up by address mark/idle */
tU08 m :1; /**< mode select */
tU08 rsrc :1; /**< receiver source */
tU08 sciswai :1; /**< stop in wait mode */
tU08 loops :1; /**< loop mode/single wire mode enable */
} bit; /**< access register as bits */
} tSCICR1;
#endif /* End (SCI_VERSION == SCI_V6) */
/**
* @var uSCICR2 tSCICR2
*/
/**
* @union uSCICR2
* * SCI Control Register 2
*/
typedef union uSCICR2
{
tU08 byte; /**< access register as byte */
struct
{
tU08 sbk :1; /**< send break character */
tU08 rwu :1; /**< receiver wake-up control */
tU08 re :1; /**< receiver enable */
tU08 te :1; /**< transmitter enable */
tU08 ilie :1; /**< idle line interrupt enable */
tU08 rie :1; /**< receiver interrupt enable */
tU08 tcie :1; /**< transmit complete interrupt enable */
tU08 tie :1; /**< transmit interrupt enable */
} bit; /**< access register as bits */
} tSCICR2;
/**
* @var uSCISR1 tSCISR1
*/
/**
* @union uSCISR1
* SCI Status Register 1
*/
typedef union uSCISR1
{
tU08 byte; /**< access register as byte */
struct
{
tU08 pf :1; /**< parity error flag */
tU08 fe :1; /**< framing error flag */
tU08 nf :1; /**< noise error flag */
tU08 orf :1; /**< overrun error flag - 'or' in specification */
tU08 idle :1; /**< idle line detected flag */
tU08 rdrf :1; /**< receive data register full flag */
tU08 tc :1; /**< transmit complete flag */
tU08 tdre :1; /**< transmit data register empty flag */
} bit; /**< access register as bits */
} tSCISR1;
#if (SCI_VERSION == SCI_V2)
/**
* @var uSCISR2 tSCISR2
* SCI status register 2
*/
/**
* @union uSCISR2
* SCI status register 2
*/
typedef union uSCISR2
{
tU08 byte; /**< access register as byte */
struct
{
tU08 raf :1; /**< receiver active flag */
tU08 :1; /**< bit reserved area */
tU08 brk13 :1; /**< break character length */
tU08 :1; /**< bit reserved area */
tU08 :1; /**< bit reserved area */
tU08 :1; /**< bit reserved area */
tU08 :1; /**< bit reserved area */
tU08 :1; /**< bit reserved area */
} bit; /**< access register as bits */
} tSCISR2;
#endif /* End (SCI_VERSION == SCI_V2) */
#if (SCI_VERSION == SCI_V4)
/**
* @var uSCISR2 tSCISR2
* SCI status register 2
*/
/**
* @union uSCISR2
* SCI status register 2
*/
typedef union uSCISR2
{
tU08 byte; /**< access register as byte */
struct
{
tU08 raf :1; /**< receiver active flag */
tU08 lbkde :1; /**< LIN Break Detection Enable */
tU08 brk13 :1; /**< Break Character Generation Length */
tU08 rwuid :1; /**< Receive Wake Up Idle Detect */
tU08 rxinv :1; /**< Receive Data Inversion */
tU08 :1; /**< bit reserved area */
tU08 rxedgif:1; /**< RxD Pin Active Edge Interrupt Flag */
tU08 lbkdif :1; /**< LIN Break Detect Interrupt Flag */
} bit; /**< access register as bits */
} tSCISR2;
#endif /* End (SCI_VERSION == SCI_V4) */
#if ((SCI_VERSION == SCI_V5) || (SCI_VERSION == SCI_V6))
/**
* @var uSCISR2 tSCISR2
*/
/**
* @union uSCISR2
* SCI status register 2
*/
typedef union uSCISR2
{
tU08 byte; /**< access register as byte */
struct
{
tU08 raf :1; /**< receiver active flag */
tU08 txdir :1; /**< receiver active flag */
tU08 brk13 :1; /**< 13-bit break */
tU08 rxpol :1; /**< receiver polarity */
tU08 txpol :1; /**< transmitter polarity */
tU08 :2; /**< bit reserved area */
tU08 amap :1; /**< alternate register map */
} bit; /**< access register as bits */
} tSCISR2;
#endif /* End (SCI_VERSION == SCI_V5 || SCI_VERSION == SCI_V6) */
#if ((SCI_VERSION != SCI_V5) && (SCI_VERSION != SCI_V6))
/**
* @var uSCICR3 tSCICR3
*/
/**
* @union uSCICR3
* SCI control register 3
*/
typedef union uSCICR3
{
tU08 byte; /**< access register as byte */
struct
{
tU08 peie :1; /**< Parity Error Interrupt Enable */
tU08 feie :1; /**< Framing Error Interrupt Enable */
tU08 neie :1; /**< Noise Error Interrupt Enable */
tU08 orie :1; /**< Overrun Interrupt Enable */
tU08 txinv :1; /**< Transmit Data Inversion */
tU08 txdir :1; /**< TxD Pin Direction in Single-Wire Mode */
tU08 t8 :1; /**< Ninth Data Bit for Transmitter */
tU08 r8 :1; /**< Ninth Data Bit for Receiver */
} bit; /**< access register as bits */
} tSCICR3;
/**
* @var uSCID tSCID
*/
/**
* @union uSCID
* SCI data
*/
typedef union uSCID
{
tU08 byte; /**< access register as byte */
struct
{
tU08 r0_t0 :1; /**< Receive/Transmit Data Bit 0 */
tU08 r1_t1 :1; /**< Receive/Transmit Data Bit 1 */
tU08 r2_t2 :1; /**< Receive/Transmit Data Bit 2 */
tU08 r3_t3 :1; /**< Receive/Transmit Data Bit 3 */
tU08 r4_t4 :1; /**< Receive/Transmit Data Bit 4 */
tU08 r5_t5 :1; /**< Receive/Transmit Data Bit 5 */
tU08 r6_t6 :1; /**< Receive/Transmit Data Bit 6 */
tU08 r7_t7 :1; /**< Receive/Transmit Data Bit 7 */
} bit; /**< access register as bits */
} tSCID;
#else
/**
* @var uSCIDRH tSCIDRH
*/
/**
* @union uSCIDRH
* SCI Data Register hight
*/
typedef union uSCIDRH
{
tU08 byte; /**< access register as byte */
struct
{
tU08 :6; /**< not used */
tU08 t8 :1; /**< transmit bit 8 */
tU08 r8 :1; /**< receive bit 8 */
} bit; /**< access register as bits */
} tSCIDRH;
#endif /* End (SCI_VERSION != SCI_V5) */
#if ((SCI_VERSION != SCI_V5) && (SCI_VERSION != SCI_V6))
/**
* @struct tSCI
* SCI data structure
*/
typedef struct /**< sci datastructure */
{
volatile tSCIBDH scibdh; /**< sci baud rate high register */
volatile tSCIBDL scibdl; /**< sci baud rate low register */
volatile tSCICR1 scicr1; /**< sci control register 1 */
volatile tSCICR2 scicr2; /**< sci control register 2 */
volatile tSCISR1 scisr1; /**< sci status register 1 */
volatile tSCISR2 scisr2; /**< sci status register 2 */
volatile tSCICR3 scicr3; /**< sci control register 3 */
volatile tSCID scid; /**< sci data register */
} tSCI;
#else /* SCI v5 and v6 */
/**
* @struct tSCI
* sci datastructure
*/
typedef struct /**< sci datastructure */
{
volatile tSCIBDH scibdh; /**< sci baud rate high register / alternate status register */
volatile tSCIBDL scibdl; /**< sci baud rate low register / alternate control register 1 */
volatile tSCICR1 scicr1; /**< sci control register 1 / alternate control register 2 */
volatile tSCICR2 scicr2; /**< sci control register 2 */
volatile tSCISR1 scisr1; /**< sci status register 1 */
volatile tSCISR2 scisr2; /**< sci status register 2 */
volatile tSCIDRH scidrh; /**< sci data register high */
volatile tREG08 scidrl; /**< sci data register low */
} tSCI;
#define sciasr1 scibdh /**< SCI alternate status register */
#define sciacr1 scibdl /**< SCI alternate control register 1 */
#define sciacr2 scicr1 /**< SCI alternate control register 2 */
#endif /* End (SCI_VERSION != SCI_V5) */
/*************************************/
/************ SCI Bit masks **********/
/*************************************/
/* SCIBH - SCI Baud Rate Register High */
#if (defined(_MC9S08DZ128_H)|| defined(_MM9Z1J638_H)||(SCI_VERSION == SCI_V4))
#ifndef SCIBDH_RXEDGIE_MASK
#define SCIBDH_RXEDGIE_MASK 64 /**< SCI baud rate register high bit mask: RxD input active edge interrupt enable */
#endif /* ifndef SCIBDH_RXEDGIE_MASK */
#ifndef SCIBDH_LBKDIE_MASK
#define SCIBDH_LBKDIE_MASK 128 /**< SCI baud rate register high bit mask: LIN break detected interrupt enable */
#endif /* ifndef SCIBDH_LBKDIE_MASK */
#endif /* End (SCI_VERSION == SCI_V4) */
/* SCIASR1 - SCI Alternative Status Register */
#if ((SCI_VERSION == SCI_V5) || (SCI_VERSION == SCI_V6))
#ifndef SCIASR1_BKDIF_MASK
#define SCIASR1_BKDIF_MASK 1 /**< SCI alternate status register 1 bit mask: break detect interrupt flag */
#endif /* ifndef SCIASR1_BKDIF_MASK */
#ifndef SCIASR1_BERRIF_MASK
#define SCIASR1_BERRIF_MASK 2 /**< SCI alternate status register 1 bit mask: bit error interrupt flag */
#endif /* ifndef SCIASR1_BERRIF_MASK */
#ifndef SCIASR1_BERRV_MASK
#define SCIASR1_BERRV_MASK 4 /**< SCI alternate status register 1 bit mask: bit error value */
#endif /* ifndef SCIASR1_BERRV_MASK */
#ifndef SCIASR1_RXEDGIF_MASK
#define SCIASR1_RXEDGIF_MASK 128 /**< SCI alternate status register 1 bit mask: receive input active interrupt flag */
#endif /* ifndef SCIASR1_RXEDGIF_MASK */
/* SCI0ACR1 - SCI Alternative Control Register 1 */
#ifndef SCIACR1_BKDIE_MASK
#define SCIACR1_BKDIE_MASK 1 /**< SCI alternate control register 1 bit mask: break detect interrupt enable */
#endif /* ifndef SCIACR1_BKDIE_MASK */
#ifndef SCIACR1_BERRIE_MASK
#define SCIACR1_BERRIE_MASK 2 /**< SCI alternate control register 1 bit mask: bit error interrupt enable */
#endif /* ifndef SCIACR1_BERRIE_MASK */
#ifndef SCIACR1_RXEDGIE_MASK
#define SCIACR1_RXEDGIE_MASK 128 /**< SCI alternate control register 1 bit mask: receive input active edge interrupt enable */
#endif /* ifndef SCIACR1_RXEDGIE_MASK */
#endif /* End (SCI_VERSION == SCI_V5) */
/* SCICR1 - SCI Control Register 1 */
#if (SCI_VERSION == SCI_V2)
#ifndef SCICR1_PT_MASK
#define SCICR1_PT_MASK 1 /**< SCI control register 1 bit mask: parity type*/
#endif /* ifndef SCICR1_PT_MASK */
#ifndef SCICR1_PE_MASK
#define SCICR1_PE_MASK 2 /**< SCI control register 1 bit mask: parity enable*/
#endif /* ifndef SCICR1_PE_MASK */
#ifndef SCICR1_ILT_MASK
#define SCICR1_ILT_MASK 4 /**< SCI control register 1 bit mask: idle line type select*/
#endif /* ifndef SCICR1_ILT_MASK */
#ifndef SCICR1_WAKE_MASK
#define SCICR1_WAKE_MASK 8 /**< SCI control register 1 bit mask: receiver wakeup method select*/
#endif /* ifndef SCICR1_WAKE_MASK */
#ifndef SCICR1_M_MASK
#define SCICR1_M_MASK 16 /**< SCI control register 1 bit mask: 8 bit or 9 bit mode select*/
#endif /* ifndef SCICR1_M_MASK */
#ifndef SCICR1_RSTC_MASK
#define SCICR1_RSTC_MASK 32 /**< SCI control register 1 bit mask: receiver source select*/
#endif /* ifndef SCICR1_RSTC_MASK */
#ifndef SCICR1_SCIWAI_MASK
#define SCICR1_SCIWAI_MASK 64 /**< SCI control register 1 bit mask: SCI stops in wait mode*/
#endif /* ifndef SCICR1_SCIWAI_MASK */
#ifndef SCICR1_LOOPS_MASK
#define SCICR1_LOOPS_MASK 128 /**< SCI control register 1 bit mask: loop mode select*/
#endif /* ifndef SCICR1_LOOPS_MASK */
#else
#ifndef SCICR1_PT_MASK
#define SCICR1_PT_MASK 1 /**< SCI control register 1 bit mask: parity type*/
#endif /* ifndef SCICR1_PT_MASK */
#ifndef SCICR1_PE_MASK
#define SCICR1_PE_MASK 2 /**< SCI control register 1 bit mask: parity enable*/
#endif /* ifndef SCICR1_PE_MASK */
#ifndef SCICR1_ILT_MASK
#define SCICR1_ILT_MASK 4 /**< SCI control register 1 bit mask: idle line type select*/
#endif /* ifndef SCICR1_ILT_MASK */
#ifndef SCICR1_WAKE_MASK
#define SCICR1_WAKE_MASK 8 /**< SCI control register 1 bit mask: receiver wakeup method select*/
#endif /* ifndef SCICR1_WAKE_MASK */
#ifndef SCICR1_M_MASK
#define SCICR1_M_MASK 16 /**< SCI control register 1 bit mask: 8 bit or 9 bit mode select*/
#endif /* ifndef SCICR1_M_MASK */
#ifndef SCICR1_RSRC_MASK
#define SCICR1_RSRC_MASK 32 /**< SCI control register 1 bit mask: receiver source select*/
#endif /* ifndef SCICR1_RSRC_MASK */
#ifndef SCICR1_SCISWAI_MASK
#define SCICR1_SCISWAI_MASK 64 /**< SCI control register 1 bit mask: SCI stops in wait mode*/
#endif /* ifndef SCICR1_SCISWAI_MASK */
#ifndef SCICR1_LOOPS_MASK
#define SCICR1_LOOPS_MASK 128 /**< SCI control register 1 bit mask: loop mode select*/
#endif /* ifndef SCICR1_LOOPS_MASK */
#endif /* End (SCI_VERSION == SCI_V2) */
/* SCIACR2 - SCI Alternative Control Register 2 */
#if ((SCI_VERSION == SCI_V5) || (SCI_VERSION == SCI_V6))
#ifndef SCIACR2_BKDFE_MASK
#define SCIACR2_BKDFE_MASK 1 /**< SCI alternate control register 2: break detect feature enable */
#endif /* ifndef SCIACR2_BKDFE_MASK */
#ifndef SCIACR2_BERRM0_MASK
#define SCIACR2_BERRM0_MASK 2 /**< SCI alternate control register 2: bit error mode 0 */
#endif /* ifndef SCIACR2_BERRM0_MASK */
#ifndef SCIACR2_BERRM1_MASK
#define SCIACR2_BERRM1_MASK 4 /**< SCI alternate control register 2: bit error mode 1 */
#endif /* ifndef SCIACR2_BERRM1_MASK */
#ifndef SCIACR2_BERRM_MASK
#define SCIACR2_BERRM_MASK 6 /**< SCI alternate control register 2: bit error mode bit 0 and 1 is set */
#endif /* ifndef SCIACR2_BERRM_MASK */
#ifndef SCIACR2_BERRM_BITNUM
#define SCIACR2_BERRM_BITNUM 1 /**< SCI alternate control register 2: bit num */
#endif /* ifndef SCIACR2_BERRM_BITNUM */
#endif /* End (SCI_VERSION == SCI_V5) */
/* SCICR2 - SCI Control Register 2 */
#ifndef SCICR2_SBK_MASK
#define SCICR2_SBK_MASK 1 /**< SCI control register 2 bit mask: send break */
#endif /* ifndef SCICR2_SBK_MASK */
#ifndef SCICR2_RWU_MASK
#define SCICR2_RWU_MASK 2 /**< SCI control register 2 bit mask: receiver wakeup control */
#endif /* ifndef SCICR2_RWU_MASK */
#ifndef SCICR2_RE_MASK
#define SCICR2_RE_MASK 4 /**< SCI control register 2 bit mask: receiver enable */
#endif /* ifndef SCICR2_RE_MASK */
#ifndef SCICR2_TE_MASK
#define SCICR2_TE_MASK 8 /**< SCI control register 2 bit mask: transmitter enable */
#endif /* ifndef SCICR2_TE_MASK */
#ifndef SCICR2_ILIE_MASK
#define SCICR2_ILIE_MASK 16 /**< SCI control register 2 bit mask: idle line interrupt enable*/
#endif /* ifndef SCICR2_ILIE_MASK */
#ifndef SCICR2_RIE_MASK
#define SCICR2_RIE_MASK 32 /**< SCI control register 2 bit mask: receiver interrupt enable */
#endif /* ifndef SCICR2_RIE_MASK */
#ifndef SCICR2_TCIE_MASK
#define SCICR2_TCIE_MASK 64 /**< SCI control register 2 bit mask: transmission complete interrupt enable */
#endif /* ifndef SCICR2_TCIE_MASK */
#ifndef SCICR2_TIE_MASK
#define SCICR2_TIE_MASK 128 /**< SCI control register 2 bit mask: transmit interrupt enable */
#endif /* ifndef SCICR2_TIE_MASK */
/* SCISR1 - SCI Status Register */
#ifndef SCISR1_PF_MASK
#define SCISR1_PF_MASK 1 /**< SCI status register 1 bit mask: parity error flag */
#endif /* ifndef SCISR1_PF_MASK */
#ifndef SCISR1_FE_MASK
#define SCISR1_FE_MASK 2 /**< SCI status register 1 bit mask: framing error flag */
#endif /* ifndef SCISR1_FE_MASK */
#ifndef SCISR1_NF_MASK
#define SCISR1_NF_MASK 4 /**< SCI status register 1 bit mask: noise flag */
#endif /* ifndef SCISR1_NF_MASK */
#ifndef SCISR1_OR_MASK
#define SCISR1_OR_MASK 8 /**< SCI status register 1 bit mask: receiver overrun flag */
#endif /* ifndef SCISR1_OR_MASK */
#ifndef SCISR1_IDLE_MASK
#define SCISR1_IDLE_MASK 16 /**< SCI status register 1 bit mask: idle line flag */
#endif /* ifndef SCISR1_IDLE_MASK */
#ifndef SCISR1_RDRF_MASK
#define SCISR1_RDRF_MASK 32 /**< SCI status register 1 bit mask: receive data register full flag */
#endif /* ifndef SCISR1_RDRF_MASK */
#ifndef SCISR1_TC_MASK
#define SCISR1_TC_MASK 64 /**< SCI status register 1 bit mask: transmission complete flag*/
#endif /* ifndef SCISR1_TC_MASK */
#ifndef SCISR1_TDRE_MASK
#define SCISR1_TDRE_MASK 128 /**< SCI status register 1 bit mask: transmit data register empty flag */
#endif /* ifndef SCISR1_TDRE_MASK */
/* SCISR2 - SCI Status Register 2 */
#if (SCI_VERSION == SCI_V2)
#ifndef SCISR2_RAF_MASK
#define SCISR2_RAF_MASK 1 /**< SCI status register 2 bit mask: receiver active flag */
#endif /* ifndef SCISR2_RAF_MASK */
#ifndef SCISR2_BRK13_MASK
#define SCISR2_BRK13_MASK 4 /**< SCI status register 2 bit mask: break character length */
#endif /* ifndef SCISR2_BRK13_MASK */
#endif /* End (SCI_VERSION == SCI_V2) */
#if (SCI_VERSION == SCI_V4)
#ifndef SCISR2_RAF_MASK
#define SCISR2_RAF_MASK 1 /**< SCI status register 2 bit mask: receiver active flag */
#endif /* ifndef SCISR2_RAF_MASK */
#ifndef SCISR2_LBKDE_MASK
#define SCISR2_LBKDE_MASK 2 /**< SCI status register 2 bit mask: LIN break detection enable */
#endif /* ifndef SCISR2_LBKDE_MASK */
#ifndef SCISR2_BRK13_MASK
#define SCISR2_BRK13_MASK 4 /**< SCI status register 2 bit mask: break character length */
#endif /* ifndef SCISR2_BRK13_MASK */
#ifndef SCISR2_RWUID_MASK
#define SCISR2_RWUID_MASK 8 /**< SCI status register 2 bit mask: receive wakeup idle detect */
#endif /* ifndef SCISR2_RWUID_MASK */
#ifndef SCISR2_RXINV_MASK
#define SCISR2_RXINV_MASK 16 /**< SCI status register 2 bit mask: receive data inversion */
#endif /* ifndef SCISR2_RXINV_MASK */
#ifndef SCISR2_RXEDGIF_MASK
#define SCISR2_RXEDGIF_MASK 64 /**< SCI status register 2 bit mask: RxD pin active edge interrupt flag */
#endif /* ifndef SCISR2_RXEDGIF_MASK */
#ifndef SCISR2_LBKDIF_MASK
#define SCISR2_LBKDIF_MASK 128 /**< SCI status register 2 bit mask: LIN break detect interrupt flag */
#endif /* ifndef SCISR2_LBKDIF_MASK */
#endif /* End (SCI_VERSION == SCI_V4) */
#if ((SCI_VERSION == SCI_V5) || (SCI_VERSION == SCI_V6))
#ifndef SCISR2_RAF_MASK
#define SCISR2_RAF_MASK 1 /**< SCI status register 2 bit mask: receiver active flag */
#endif /* ifndef SCISR2_RAF_MASK */
#ifndef SCISR2_TXDIR_MASK
#define SCISR2_TXDIR_MASK 2 /**< SCI status register 2 bit mask: transmitter pin data direction in single-wire mode */
#endif /* ifndef SCISR2_TXDIR_MASK */
#ifndef SCISR2_BRK13_MASK
#define SCISR2_BRK13_MASK 4 /**< SCI status register 2 bit mask: break character length */
#endif /* ifndef SCISR2_BRK13_MASK */
#ifndef SCISR2_RXPOL_MASK
#define SCISR2_RXPOL_MASK 8 /**< SCI status register 2 bit mask: receive polarity */
#endif /* ifndef SCISR2_RXPOL_MASK */
#ifndef SCISR2_TXPOL_MASK
#define SCISR2_TXPOL_MASK 16 /**< SCI status register 2 bit mask: transmit polarity */
#endif /* ifndef SCISR2_TXPOL_MASK */
#ifndef SCISR2_AMAP_MASK
#define SCISR2_AMAP_MASK 128 /**< SCI status register 2 bit mask: transmit map */
#endif /* ifndef SCISR2_AMAP_MASK */
#endif /* End (SCI_VERSION == SCI_V5) */
#if ((SCI_VERSION != SCI_V5) && (SCI_VERSION != SCI_V6))
/* SCICR3 - SCI Control Register 3 */
#ifndef SCICR3_PEIE_MASK
#define SCICR3_PEIE_MASK 1 /**< SCI control register 3 bit mask: parity error interrupt enable */
#endif /* ifndef SCICR3_PEIE_MASK */
#ifndef SCICR3_FEIE_MASK
#define SCICR3_FEIE_MASK 2 /**< SCI control register 3 bit mask: framing error interrupt enable */
#endif /* ifndef SCICR3_FEIE_MASK */
#ifndef SCICR3_NEIE_MASK
#define SCICR3_NEIE_MASK 4 /**< SCI control register 3 bit mask: noise error interrupt enable */
#endif /* ifndef SCICR3_NEIE_MASK */
#ifndef SCICR3_ORIE_MASK
#define SCICR3_ORIE_MASK 8 /**< SCI control register 3 bit mask: overrun interrupt enable */
#endif /* ifndef SCICR3_ORIE_MASK */
#ifndef SCICR3_TXINV_MASK
#define SCICR3_TXINV_MASK 16 /**< SCI control register 3 bit mask: transmit data inversion */
#endif /* ifndef SCICR3_TXINV_MASK */
#ifndef SCICR3_TXDIR_MASK
#define SCICR3_TXDIR_MASK 32 /**< SCI control register 3 bit mask: TxD pin direction in single-wire mode */
#endif /* ifndef SCICR3_TXDIR_MASK */
#ifndef SCICR3_T8_MASK
#define SCICR3_T8_MASK 64 /**< SCI control register 3 bit mask: Ninth data bit for transmitter */
#endif /* ifndef SCICR3_T8_MASK */
#ifndef SCICR3_R8_MASK
#define SCICR3_R8_MASK 128 /**< SCI control register 3 bit mask: ninth data bit for receiver */
#endif /* ifndef SCICR3_R8_MASK */
/* SCID - SCI Data Register */
#if (defined(_MC9S08DZ128_H)|| defined(_MM9Z1J638_H)||(SCI_VERSION == SCI_V4))
#ifndef SCID_R0_T0_MASK
#define SCID_R0_T0_MASK 1 /**< SCI data register bit mask: bit 0 */
#endif /* ifndef SCID_R0_T0_MASK */
#ifndef SCID_R1_T1_MASK
#define SCID_R1_T1_MASK 2 /**< SCI data register bit mask: bit 1 */
#endif /* ifndef SCID_R1_T1_MASK */
#ifndef SCID_R2_T2_MASK
#define SCID_R2_T2_MASK 4 /**< SCI data register bit mask: bit 2 */
#endif /* ifndef SCID_R2_T2_MASK */
#ifndef SCID_R3_T3_MASK
#define SCID_R3_T3_MASK 8 /**< SCI data register bit mask: bit 3 */
#endif /* ifndef SCID_R3_T3_MASK */
#ifndef SCID_R4_T4_MASK
#define SCID_R4_T4_MASK 16 /**< SCI data register bit mask: bit 4 */
#endif /* ifndef SCID_R4_T4_MASK */
#ifndef SCID_R5_T5_MASK
#define SCID_R5_T5_MASK 32 /**< SCI data register bit mask: bit 5 */
#endif /* ifndef SCID_R5_T5_MASK */
#ifndef SCID_R6_T6_MASK
#define SCID_R6_T6_MASK 64 /**< SCI data register bit mask: bit 6 */
#endif /* ifndef SCID_R6_T6_MASK */
#ifndef SCID_R7_T7_MASK
#define SCID_R7_T7_MASK 128 /**< SCI data register bit mask: bit 7 */
#endif /* ifndef SCID_R7_T7_MASK */
#endif /* End (!defined(_MC9S08SG32_H))*/
#else
/* SCI Data Register High */
#ifndef SCIDRH_T8_MASK
#define SCIDRH_T8_MASK 64 /**< SCI data register high bit mask: transmit bit 8 */
#endif /* ifndef SCIDRH_T8_MASK */
#ifndef SCIDRH_R8_MASK
#define SCIDRH_R8_MASK 128 /**< SCI data register high bit mask: receive bit 8 */
#endif /* ifndef SCIDRH_R8_MASK */
/* SCI Data Register Low */
#ifndef SCIDRL_R0_T0_MASK
#define SCIDRL_R0_T0_MASK 1 /**< SCI data register low bit mask: bit 0 */
#endif /* ifndef SCIDRL_R0_T0_MASK */
#ifndef SCIDRL_R1_T1_MASK
#define SCIDRL_R1_T1_MASK 2 /**< SCI data register low bit mask: bit 1 */
#endif /* ifndef SCIDRL_R1_T1_MASK */
#ifndef SCIDRL_R2_T2_MASK
#define SCIDRL_R2_T2_MASK 4 /**< SCI data register low bit mask: bit 2 */
#endif /* ifndef SCIDRL_R2_T2_MASK */
#ifndef SCIDRL_R3_T3_MASK
#define SCIDRL_R3_T3_MASK 8 /**< SCI data register low bit mask: bit 3 */
#endif /* ifndef SCIDRL_R3_T3_MASK */
#ifndef SCIDRL_R4_T4_MASK
#define SCIDRL_R4_T4_MASK 16 /**< SCI data register low bit mask: bit 4 */
#endif /* ifndef SCIDRL_R4_T4_MASK */
#ifndef SCIDRL_R5_T5_MASK
#define SCIDRL_R5_T5_MASK 32 /**< SCI data register low bit mask: bit 5 */
#endif /* ifndef SCIDRL_R5_T5_MASK */
#ifndef SCIDRL_R6_T6_MASK
#define SCIDRL_R6_T6_MASK 64 /**< SCI data register low bit mask: bit 6 */
#endif /* ifndef SCIDRL_R6_T6_MASK */
#ifndef SCIDRL_R7_T7_MASK
#define SCIDRL_R7_T7_MASK 128 /**< SCI data register low bit mask: bit 7 */
#endif /* ifndef SCIDRL_R7_T7_MASK */
#endif /* End (SCI_VERSION != SCI_V5) */
#endif /* Lin register */
/**
* @}
*/

View File

@ -0,0 +1,246 @@
/******************************************************************************
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*****************************************************************************/
/** @addtogroup common_core_api_group
* @{ */
/**************************************************************************//**
*
* @file lin_common_api.c
*
* @author FPT Software
*
* @brief Common LIN API functions
*
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
*
*****************************************************************************/
/** @} */
#include "lin_common_api.h"
#include "lin_common_proto.h"
#include "lin.h"
#if (XGATE_SUPPORT == 1)
#include "lin_lld_xgate.h"
#endif /* End (XGATE_SUPPORT == 1) */
/* -------------------------------FUNCTION COMMON --------------------------- */
/** @addtogroup driver_cluster_group
* @{ */
l_bool l_sys_init ()
{
#if XGATE_SUPPORT == 1
lin_lld_setup_xgate();
#endif /* End (XGATE_SUPPORT == 1) */
lin_lld_timer_init();
return 0;
} /* end of l_sys_init() */
/** @} */
#if LIN_MODE == _MASTER_MODE_
/** @addtogroup schedule_management_group
* @{ */
void l_sch_set
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] schedule table for interface */
l_schedule_handle schedule_iii,
/* [IN] entry to be set */
l_u8 entry
)
{
lin_configuration const *conf;
/* Get current configuration */
conf = &lin_ifc_configuration[iii];
if ((conf->function == _MASTER_) && (schedule_iii < LIN_NUM_OF_SCHD_TBL))
{
/* Check if input entry is in range from 0 to N = (Number of frame slots) */
if (entry <= conf->schedule_tbl[schedule_iii].num_slots)
{
/* save the new schedule which is activated after the */
/* current schedule reaches its next schedule entry point */
*(conf->previous_schedule_id) = *(conf->active_schedule_id);
/* Insert new schedule at that point of the current schdule */
*(conf->active_schedule_id) = (l_u8)schedule_iii;
/* if entry is 0 or 1 the new schedule table will be started from the beginning. */
if (entry == 0U)
{
/* Set entry equal to 1 */
entry = 1U;
}
/* Assign the start entry of new schedule table by argument entry */
conf->schedule_start_entry[schedule_iii] = entry - 1;
}
}
} /* end of l_sch_set() */
l_u8 l_sch_tick
(
/* [IN] interface name */
l_ifc_handle iii
)
{
return lin_tick_callback_handler(iii);
} /* end of l_sch_tick() */
/** @} */
#endif /* End LIN_MODE == _MASTER_MODE_ */
/** @addtogroup interface_management_group
* @{ */
l_bool l_ifc_init
(
/* [IN] interface name */
l_ifc_handle iii
)
{
#if LIN_MODE == _SLAVE_MODE_
return lin_lld_init();
#else
return lin_lld_init(iii);
#endif /* End LIN_MODE == _SLAVE_MODE_ */
} /* end of l_ifc_init() */
void l_ifc_goto_sleep
(
/* [IN] interface name */
l_ifc_handle iii
)
{
/* If node is master node */
#if LIN_MODE == _MASTER_MODE_
/* Get current configuration */
lin_configuration const *conf;
/* Get current configuration */
conf = &lin_ifc_configuration[iii];
/* Set active schedule as GOTO_SLEEP_SCHEDULE */
l_sch_set(iii, (l_schedule_handle)(conf->schedule_start + 1), 0);
#endif /* End LIN_MODE == _MASTER_MODE_ */
} /* end of l_ifc_goto_sleep() */
void l_ifc_wake_up
(
/* [IN] interface name */
l_ifc_handle iii
)
{
#if LIN_MODE == _SLAVE_MODE_
lin_lld_tx_wake_up();
#else
/* Send wakeup signal */
lin_lld_tx_wake_up(iii);
#endif /* End (LIN_MODE == _SLAVE_MODE_) */
} /* end of l_ifc_wake_up() */
void l_ifc_rx
(
/* [IN] interface name */
l_ifc_handle iii
)
{
} /* end of l_ifc_rx() */
void l_ifc_tx
(
/* [IN] interface name */
l_ifc_handle iii
)
{
} /* end of l_ifc_tx() */
void l_ifc_aux
(
/* [IN] interface name */
l_ifc_handle iii
)
{
} /* end of l_ifc_aux() */
l_u16 l_ifc_read_status
(
/* [IN] interface name */
l_ifc_handle iii
)
{
static l_u16 tmp_word_status;
#if LIN_MODE == _SLAVE_MODE_
tmp_word_status = lin_word_status.word;
/* Clear Word status */
lin_word_status.word = 0;
/* Clear Save configuration flag value */
lin_save_configuration_flg = 0;
/* Clear Successful transfer */
lin_successful_transfer = 0;
/* Clear Error in response */
lin_error_in_response = 0;
/* Clear Goto sleep flag */
lin_goto_sleep_flg = 0;
/* Clear Current pid */
lin_current_pid = 0x00;
#else
lin_configuration const *conf;
conf = &lin_ifc_configuration[iii];
tmp_word_status = *((l_u16*)(conf->word_status));
/* Read-reset call; meaning that after the call has returned,
the status word is set to 0 */
/* Clear word status */
*((l_u16*)(conf->word_status)) = 0;
/* Clear save configuration flag value */
lin_save_configuration_flg[iii] = 0;
/* Clear Successful transfer */
*(conf->successful_transfer)= 0;
/* Clear Error in response */
*(conf->error_in_response)= 0;
/* Clear Goto sleep flag */
*(conf->goto_sleep_flg) = 0;
/* Clear Current pid */
*(conf->current_pid) = 0x00;
#endif /* End (LIN_MODE == _SLAVE_MODE_) */
return (tmp_word_status);
} /* end of l_ifc_read_status() */
/** @} */
/** @addtogroup call_out_group
* @{ */
l_u16 l_sys_irq_disable
(
/* [IN] interface name */
l_ifc_handle iii
)
{
#if LIN_MODE == _SLAVE_MODE_
return lin_lld_int_disable();
#else
return lin_lld_int_disable(iii);
#endif /* End (LIN_MODE == _SLAVE_MODE_) */
} /* end of l_sys_irq_disable() */
void l_sys_irq_restore
(
/* [IN] interface name */
l_ifc_handle iii
)
{
#if LIN_MODE == _SLAVE_MODE_
lin_lld_int_enable();
#else
lin_lld_int_enable(iii);
#endif /* End (LIN_MODE == _SLAVE_MODE_) */
} /* end of l_sys_irq_restore() */
/** @} */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup J2602_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_j2602_api.c
*
* @author FPT Software
*
* @brief J2602 LIN core API functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
*
*****************************************************************************/
#include "lin_j2602_api.h"
l_bool l_ifc_connect
(
/* [IN] interface name */
l_ifc_handle iii
)
{
return 0;
}
l_bool l_ifc_disconnect
(
/* [IN] interface name */
l_ifc_handle iii
)
{
return 0;
}
/**
* @}
*/

View File

@ -0,0 +1,210 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup J2602_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_j2602_proto.c
*
* @author FPT Software
*
* @brief J2602 LIN protocol functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
*
*****************************************************************************/
#include "lin_j2602_proto.h"
/* ---------------------------- For 1 interface -----------------------------------*/
#if LIN_MODE == _SLAVE_MODE_
#if LIN_PROTOCOL != PROTOCOL_21
void lin_update_word_status_j2602
(
/* [IN] event of Low-level driver */
lin_lld_event_id event_id,
/* [IN] PID of frame */
l_u8 pid
)
{
l_u8 overrun = 0;
if((lin_word_status.word & 0x03) > 0)
{
overrun |= lin_successful_transfer | lin_error_in_response;
}
lin_word_status.word |= ((lin_error_in_response) | (lin_successful_transfer << 1) |
(overrun << 2) | (lin_goto_sleep_flg << 3));
lin_word_status.word = (lin_word_status.word & 0x00FF) | (pid << 8);
lin_successful_transfer = 0;
}
void lin_update_status_byte
(
/* [IN] interface name */
lin_lld_event_id event_id
)
{
l_u8 i;
l_u8 signal_data;
l_u16 byte_offset_temp;
l_u8 bit_offset_temp;
l_bool set_error_signal = 0;
switch (event_id)
{
/* Parity error */
case LIN_LLD_PID_ERR:
/* Set ID Parity Error 0x07 */
signal_data = 0x07;
set_error_signal = 1;
break;
/* Byte Field Framing Error*/
case LIN_LLD_FRAME_ERR:
/* Set Byte Field Framing Error 0x06 */
signal_data = 0x06;
set_error_signal = 1;
break;
/* Checksum error */
case LIN_LLD_CHECKSUM_ERR:
/* Set Checksum error 0x05 */
signal_data = 0x05;
set_error_signal = 1;
break;
/* Data error */
case LIN_LLD_READBACK_ERR:
/* Set Data error 0x04 */
signal_data = 0x04;
set_error_signal = 1;
break;
default:
break;
}
if (set_error_signal == 1)
{
for (i = 0; i < num_frame_have_esignal; i++)
{
/* Get pointer to Byte and bit offset values in each frame that contains the error signal */
byte_offset_temp = lin_response_error_byte_offset[i];
bit_offset_temp = lin_response_error_bit_offset[i];
/* Set error signal equal to error in response */
lin_pFrameBuf[byte_offset_temp] = (l_u8)((lin_pFrameBuf[byte_offset_temp] & (~(0x07U << bit_offset_temp))) |
(signal_data << bit_offset_temp));
}
}
}
#endif /* End (LIN_PROTOCOL != PROTOCOL_21) */
#endif /* End of (LIN_MODE == _SLAVE_MODE_)*/
/*-----------------------------------------------------------------------*/
#if LIN_MODE == _MASTER_MODE_
void lin_update_word_status_j2602
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] event of Low-level driver */
lin_lld_event_id event_id,
/* [IN] PID of frame */
l_u8 pid
)
{
l_u8 err_in_res, suc_in_tras;
lin_word_status_str *word_status;
lin_configuration const *conf;
conf = &(lin_ifc_configuration[iii]);
err_in_res = *(conf->error_in_response);
suc_in_tras = *(conf->successful_transfer);
word_status = conf->word_status;
word_status->bit.error_in_res = err_in_res;
if((word_status->word & 0x03) > 0)
{
word_status->bit.overrun |= (err_in_res | suc_in_tras);
}
word_status->bit.successful_transfer = suc_in_tras;
word_status->bit.last_pid = pid;
word_status->bit.gotosleep = *(conf->goto_sleep_flg);
*(conf->successful_transfer) = 0;
}
void lin_update_status_byte
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] interface name */
lin_lld_event_id event_id
)
{
l_u8 i;
l_u8 signal_data;
l_u16* byte_offset_temp_ptr;
l_u8* bit_offset_temp_ptr;
lin_node_attribute *node_att_ptr;
l_bool set_error_signal = 0;
lin_configuration const *conf;
conf = &(lin_ifc_configuration[iii]);
switch (event_id)
{
/* Parity error */
case LIN_LLD_PID_ERR:
/* Set ID Parity Error 0x07 */
signal_data= 0x07;
set_error_signal = 1;
break;
/* Byte Field Framing Error*/
case LIN_LLD_FRAME_ERR:
/* Set Byte Field Framing Error 0x06 */
signal_data = 0x06;
set_error_signal = 1;
break;
/* Checksum error */
case LIN_LLD_CHECKSUM_ERR:
/* Set Checksum error 0x05 */
signal_data = 0x05;
set_error_signal = 1;
break;
/* Data error */
case LIN_LLD_READBACK_ERR:
/* Set Data error 0x04 */
signal_data = 0x04;
set_error_signal = 1;
break;
default:
break;
}
if (set_error_signal == 1)
{
node_att_ptr = conf->node_attribute;
for (i = 0; i < node_att_ptr->num_frame_have_esignal; i++)
{
/* Get pointer to Byte and bit offset values in each frame that contains the error signal */
byte_offset_temp_ptr = node_att_ptr->response_error_byte_offset_ptr + i;
bit_offset_temp_ptr = node_att_ptr->response_error_bit_offset_ptr + i;
/* Set error signal equal to error in response */
lin_pFrameBuf[*byte_offset_temp_ptr] = (l_u8)((lin_pFrameBuf[*byte_offset_temp_ptr] & (~(0x07U << (*bit_offset_temp_ptr)))) |
(signal_data << (*bit_offset_temp_ptr)));
}
}
}
#endif /* End of (LIN_MODE == _SLAVE_MODE_)*/
/**
* @}
*/

View File

@ -0,0 +1,33 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup LIN21_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_lin21_api.c
*
* @author FPT Software
*
* @brief Common LIN 2.1 API functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
*
*****************************************************************************/
#include "lin_lin21_api.h"
/**
* @}
*/

View File

@ -0,0 +1,300 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup LIN21_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_lin21_proto.c
*
* @author FPT Software
*
* @brief Common LIN 2.1 protocol functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
* 20111005 v1.1 Updated word status
*
*****************************************************************************/
#include "lin_lin21_proto.h"
#include "lin_common_proto.h"
#include "lin.h"
/* ---------------------------- For 1 interface ----------------------------------- */
#if (LIN_MODE == _SLAVE_MODE_)
#if ((LIN_PROTOCOL == PROTOCOL_21) || (LIN_PROTOCOL == PROTOCOL_20))
#if !defined(MCU_SKEAZN84) /* Not cover for KEA8 platform */
extern l_u8 frame_index;
void lin_update_word_status_lin21
(
/* [IN] PID of frame */
l_u8 pid
)
{
l_u8 overrun = 0;
if((lin_word_status.word & 0x03) > 0)
{
overrun |= lin_successful_transfer | lin_error_in_response;
}
lin_word_status.word |= ((lin_error_in_response) | (lin_successful_transfer << 1) |
(overrun << 2)|
(lin_goto_sleep_flg << 3) |
(lin_save_configuration_flg << 6));
if(pid != 0xff)
{
lin_word_status.word = (lin_word_status.word & 0x00FF) | (pid << 8);
/* Set bus activity */
lin_word_status.word |= 1 << 4;
}
lin_successful_transfer = 0;
}
void lin_update_err_signal
(
/* [IN] index of frame */
l_u8 frm_id
)
{
l_u8 i;
l_u16 byte_offset_temp;
l_u8 bit_offset_temp;
/* Set error signal equal to error in response */
if (LIN_FRM_EVNT != lin_frame_tbl[frm_id].frm_type)
{
for (i = 0; i < num_frame_have_esignal; i++)
{
byte_offset_temp = lin_response_error_byte_offset[i];
bit_offset_temp = lin_response_error_bit_offset[i];
lin_pFrameBuf[byte_offset_temp] = (l_u8)((lin_pFrameBuf[byte_offset_temp] & (~(1U << (bit_offset_temp)))) |
(lin_error_in_response << (bit_offset_temp)));
}
}
}
void lin_make_res_evnt_frame
(
/* [IN] PID of frame */
l_u8 pid
)
{
/* Create response */
lin_process_uncd_frame(pid, MAKE_UNCONDITIONAL_FRAME);
lin_lld_response_buffer[1] = lin_process_parity(pid, MAKE_PARITY);
}
#endif /* End (LIN_PROTOCOL == PROTOCOL_21) */
#endif /* #if !defined(MCU_SKEAZN84) */
#endif /* End of (LIN_MODE == _SLAVE_MODE_) */
/* ------------------------ FOR MULTI-INTERFACE -------------------------- */
#if (LIN_MODE == _MASTER_MODE_)
void lin_collision_resolve
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] PID of frame */
l_u8 pid
)
{
lin_associate_frame_struct *ptr;
l_u8 frame_index;
const lin_configuration *conf;
l_u8 *_active_schedule_id;
conf = &(lin_ifc_configuration[iii]);
frame_index = lin_get_frame_index(iii, pid);
/* Check MASTER function */
if (_MASTER_ == conf->function)
{
/* Find collision resolver table */
/* Swap schedule table */
/* Get active_schedule_id */
_active_schedule_id = conf->active_schedule_id;
*(conf->previous_schedule_id) = *_active_schedule_id ;
/* Set collision resolver table to active schedule */
ptr = (lin_associate_frame_struct*)conf->frame_tbl[frame_index].frame_data;
*_active_schedule_id = ptr->coll_resolver_id;
conf->schedule_start_entry[*_active_schedule_id] = 0;
}
}
void lin_update_word_status_lin21
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] event of Low-level driver */
lin_lld_event_id event_id,
/* [IN] PID of frame */
l_u8 pid
)
{
l_u8 err_in_res, suc_in_tras, frame_index, save_config;
lin_word_status_str *word_status_ptr;
const lin_configuration *conf;
conf = &(lin_ifc_configuration[iii]);
err_in_res = *(conf->error_in_response);
suc_in_tras = *(conf->successful_transfer);
save_config = lin_save_configuration_flg[iii];
word_status_ptr = conf->word_status;
if((word_status_ptr->word & 0x03) > 0)
{
word_status_ptr->bit.overrun |= err_in_res | suc_in_tras;
}
word_status_ptr->bit.error_in_res |= err_in_res;
word_status_ptr->bit.successful_transfer |= suc_in_tras;
if(pid != 0xff)
{
word_status_ptr->bit.last_pid = pid;
}
if(LIN_LLD_BUS_ACTIVITY_TIMEOUT != event_id)
{
/* Set bus activity timeout */
word_status_ptr->bit.bus_activity = 1U;
}
if (_MASTER_ == conf->function)
{
/* For Master node */
word_status_ptr->bit.gotosleep = *(conf->goto_sleep_flg);
/* If is Master node, value always equal 0 */
word_status_ptr->bit.save_conf = 0;
frame_index = lin_get_frame_index(iii, pid);
if (0xFF == frame_index) /* This PID doesn't belong to this node */
{
/* Error */
return;
}
/* PID belongs to this node, then check type of frame */
if (LIN_SCH_TBL_COLL == conf->schedule_tbl->sch_tbl_type)
{
word_status_ptr->bit.etf_collision = 1;
}
else
{
word_status_ptr->bit.etf_collision = 0;
}
}
else
{
/* For Slave node */
word_status_ptr->bit.gotosleep = *(conf->goto_sleep_flg);
word_status_ptr->bit.etf_collision = 0;
/* Updated save configuration value to word status */
word_status_ptr->bit.save_conf = save_config;
word_status_ptr->bit.dummy = 0;
}
}
void lin_update_err_signal
(
/* [IN] interface name */
l_ifc_handle iii,
l_u8 frm_id
)
{
const lin_configuration *conf;
l_u8 i;
l_u16* byte_offset_temp_ptr;
l_u8* bit_offset_temp_ptr;
l_u8 err_in_res;
lin_node_attribute *node_att_ptr;
conf = &(lin_ifc_configuration[iii]);
node_att_ptr = conf->node_attribute;
err_in_res = *(conf->error_in_response);
/* Set error signal equal to error in response */
if (LIN_FRM_EVNT != conf->frame_tbl[frm_id].frm_type)
{
for (i = 0; i < node_att_ptr->num_frame_have_esignal; i++)
{
byte_offset_temp_ptr = &node_att_ptr->response_error_byte_offset_ptr[i];
bit_offset_temp_ptr = &node_att_ptr->response_error_bit_offset_ptr[i];
lin_pFrameBuf[*byte_offset_temp_ptr] = (l_u8)((lin_pFrameBuf[*byte_offset_temp_ptr] & (~(1U << (*bit_offset_temp_ptr)))) |
(err_in_res << (*bit_offset_temp_ptr)));
}
}
}
void lin_update_rx_evnt_frame
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] PID of frame */
l_u8 pid
)
{
lin_associate_frame_struct *ptr;
l_u8 frame_index, i, ass_pid;
const lin_configuration *conf;
conf = &(lin_ifc_configuration[iii]);
/* Get frame index of the eventrigger frame */
frame_index = lin_get_frame_index(iii, pid);
if (0xFF != frame_index) /* This PID doesn't belong to this node */
{
/* calculate PID that associated with ETF */
ass_pid = lin_process_parity(conf->response_buffer[1], CHECK_PARITY);
ptr = (lin_associate_frame_struct*)(conf->frame_tbl[frame_index].frame_data);
for (i = 0; i < ptr->num_asct_uncn_pid; i++ )
{
/* First byte of response for event trigger is the PID of the associate frame */
if (conf->configuration_RAM[ptr->act_uncn_frm[i] - conf->frame_start + 1] == ass_pid )
{
/* Update unconditional frame */
lin_process_uncd_frame(iii, ass_pid, UPDATE_UNCONDITIONAL_FRAME);
/* break; */
i = ptr->num_asct_uncn_pid;
}
}
}
/* error */
return;
}
void lin_make_res_evnt_frame
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] PID of frame */
l_u8 pid
)
{
/* Create response */
lin_process_uncd_frame(iii, pid, MAKE_UNCONDITIONAL_FRAME);
/* Set associate PID */
lin_ifc_configuration[iii].response_buffer[1] = lin_process_parity(pid, MAKE_PARITY);
}
#endif /* End of (LIN_MODE == _MASTER_MODE_) */
/**
* @}
*/

View File

@ -0,0 +1,689 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup diagnostic_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_diagnostic_service.c
*
* @author FPT Software
*
* @brief Diagnostic Service slave functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090718 v1.0 First version
* 20111005 v1.1 Updated diagnostics service
*
*****************************************************************************/
#include "lin_commontl_proto.h"
#include "lin_diagnostic_service.h"
/* Define functionality */
#ifndef MULTI_PDU_SUPPORT
#define MULTI_PDU_SUPPORT 0 /**< multi PDU support */
#endif /* End MULTI_PDU_SUPPORT */
/********------------- Code supports SINGLE interface ----------------**********/
#if LIN_MODE == _SLAVE_MODE_
/*************************** FUNCTIONS *******************/
/* Unuse for GPIO */
#if ( _LIN_GPIO_ == 0 ) && !defined(_MC9S08SC4_H) && !defined(MCU_SKEAZN84)
#if LIN_PROTOCOL == PROTOCOL_21
void lin_diagservice_assign_frame_id()
{
l_u16 supid, msg_id,pid,current_id;
lin_tl_pdu_data *lin_tl_pdu;
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
l_u16 length;
l_u8 data[10];
/* get pdu from rx queue */
ld_receive_message(&length, data+2);
lin_tl_pdu = (lin_tl_pdu_data *)data;
#else /* Single frame support */
lin_tl_pdu = tl_current_rx_pdu_ptr;
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
supid = (l_u16)(((*lin_tl_pdu)[4]) << 8);
supid = supid |(l_u16)((*lin_tl_pdu)[3]);
//product_id.supplier_id = supid;
msg_id = (l_u16)(((*lin_tl_pdu)[6]) << 8);
msg_id = msg_id |(l_u16)((*lin_tl_pdu)[5]);
//product_id.function_id = fid;
pid = (*lin_tl_pdu)[7];
current_id = lin_process_parity(pid,CHECK_PARITY);
if(supid==0x0B00 || supid==0x7FFF){//iav测试台架发的spid与软件定义spid高位低位相反目前直接写死
if(msg_id==0x5001){
lin_configuration_RAM[1]= current_id;
lin_tl_make_slaveres_pdu(SERVICE_ASSIGN_FRAME_ID, POSITIVE, 0);
}
else if(msg_id==0x5000){
lin_configuration_RAM[2]= current_id;
lin_tl_make_slaveres_pdu(SERVICE_ASSIGN_FRAME_ID, POSITIVE, 0);
}
}
}
void lin_diagservice_assign_frame_id_range()
{
l_u8 start_index;
l_s8 j, i = 7;
lin_tl_pdu_data *lin_tl_pdu;
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
l_u16 length;
l_u8 data[10];
/* get pdu from rx queue */
ld_receive_message(&length, data+2);
lin_tl_pdu = (lin_tl_pdu_data *)data;
#else /* Single frame support */
lin_tl_pdu = tl_current_rx_pdu_ptr;
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Get start index in request */
start_index = (*lin_tl_pdu)[3];
// for (i = 7, j = start_index+4; j > start_index; i--, j-- )
// {
// if ((0xFF != (*lin_tl_pdu)[i]) && (j > LIN_CFG_FRAME_NUM))
// {
// lin_tl_make_slaveres_pdu(SERVICE_ASSIGN_FRAME_ID_RANGE, NEGATIVE, GENERAL_REJECT);
// return;
// }
// }
// /* Store PIDs */
// for (i = 4, j = start_index + 1; i < 8; i++, j++)
// {
// switch ((*lin_tl_pdu)[i])
// {
// case 0x00:
// /* Unassign frame */
// lin_configuration_RAM[j] = 0xFF;
// break;
// case 0xFF:
// /* keep the previous assigned value of this frame */
// break;
// default:
// /* Calculate frame ID & Assign ID to frame */
// lin_configuration_RAM[j] = lin_process_parity((*lin_tl_pdu)[i], CHECK_PARITY);
// break;
// }
// } /* End of for statement */
lin_tl_make_slaveres_pdu(SERVICE_ASSIGN_FRAME_ID_RANGE, POSITIVE, 0);
}
void lin_diagservice_read_by_identifier()
{
l_u8 id;
l_u16 supid, fid;
lin_tl_pdu_data *lin_tl_pdu;
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
l_u16 length;
l_u8 data[10];
/* get pdu from rx queue */
ld_receive_message(&length, data+2);
lin_tl_pdu = (lin_tl_pdu_data *)data;
#else /* Single frame support */
lin_tl_pdu = tl_current_rx_pdu_ptr;
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
//20200801:ȫ<><C8AB><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>Ӧ
//lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, POSITIVE, 0);
//return;
/* Get supplier and function indentification in request */
supid = (l_u16)(((*lin_tl_pdu)[5]) << 8);
supid = supid |(l_u16)((*lin_tl_pdu)[4]);
fid = (l_u16)(((*lin_tl_pdu)[7]) << 8);
fid = fid |(l_u16)((*lin_tl_pdu)[6]);
// /* Check Supplier ID and Function ID */
// if (((supid != product_id.supplier_id) && (supid != LD_ANY_SUPPLIER)) || \
// ((fid != product_id.function_id) && (fid != LD_ANY_FUNCTION)))
// {
// tl_slaveresp_cnt = 0;
// #if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
// tl_service_status = LD_SERVICE_IDLE;
// #endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
// return;
// }
id = (*lin_tl_pdu)[3];
switch (id)
{
case LIN_PRODUCT_IDENT:
if((supid==0x0B00 || supid==0x7FFF) && (fid==product_id.function_id || fid==0xFFFF))//iav测试台架发的spid与软件定义spid高位低位相反目前直接写死
{
lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, POSITIVE, 0);
}
break;
case SERIAL_NUMBER:
lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, POSITIVE, 1);
break;
default:
if (id >= LIN_READ_USR_DEF_MIN && id <= LIN_READ_USR_DEF_MAX)
{
lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, POSITIVE, id);
break;
//<2F><>֪<EFBFBD><D6AA>ΪʲôҪ<C3B4><D2AA><EFBFBD><EFBFBD>
// l_u8 data_callout[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
// l_u8 i;
// l_u8 retval = ld_read_by_id_callout(id, data_callout);
// /*If the User ID is supported, make positive response*/
// if (retval == LD_POSITIVE_RESPONSE)
// {
// for (i =0; i <5; i++)
// {
// if (data_callout[i] != 0xFF)
// {
// lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, POSITIVE, id);
// break;
// }
// /* If all data_callout is 0xFF, then make negative response*/
// if (i == 4)
// {
// /* Make a negative slave response PDU */
// lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, NEGATIVE, SUBFUNCTION_NOT_SUPPORTED);
// }
// }
// }
// else if (retval == LD_NEGATIVE_RESPONSE)
// /*If the User ID is not supported, make negative response*/
// {
// /* Make a negative slave response PDU */
// lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, NEGATIVE, SUBFUNCTION_NOT_SUPPORTED);
// }
// else if (retval == LD_ID_NO_RESPONSE)
// {
// /*Do not answer*/
// tl_slaveresp_cnt = 0;
// #if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
// tl_service_status = LD_SERVICE_IDLE;
// #endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
// }
}
else
{
/* Make a negative slave response PDU */
lin_tl_make_slaveres_pdu(SERVICE_READ_BY_IDENTIFY, NEGATIVE, SUBFUNCTION_NOT_SUPPORTED);
}
break;
} /* End of switch */
}
void lin_condittional_change_nad()
{
l_u8 id, byte, mask, invert;
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
id = lin_tl_rx_queue.tl_pdu[lin_tl_rx_queue.queue_header][3];
byte = lin_tl_rx_queue.tl_pdu[lin_tl_rx_queue.queue_header][4];
mask = lin_tl_rx_queue.tl_pdu[lin_tl_rx_queue.queue_header][5];
invert = lin_tl_rx_queue.tl_pdu[lin_tl_rx_queue.queue_header][6];
#else /* Single frame support */
id = (*tl_current_rx_pdu_ptr)[3];
byte = (*tl_current_rx_pdu_ptr)[4];
mask = (*tl_current_rx_pdu_ptr)[5];
invert = (*tl_current_rx_pdu_ptr)[6];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Possible positive ID */
if (id == 0)
{
if(byte>0 && byte<6)
{
/*Byte 1: Supplier ID LSB; Byte 2: Supplier ID MSB*/
if(byte>0 && byte<3)
{
byte = product_id.supplier_id >> ((byte-1)*8);
}
/*Byte 3: Function ID LSB; Byte 4: Function ID MSB*/
else if(byte>2 && byte<5)
{
byte = product_id.function_id >> ((byte-3)*8);
}
/* Byte 5: Variant */
else
{
byte = product_id.variant;
}
/* Do a bitwise XOR with Invert and Do a bitwise AND with Mask */
byte = (byte^invert)&mask;
/* If the final result is zero, then give positive response*/
if (byte == 0)
{
lin_tl_make_slaveres_pdu(SERVICE_CONDITIONAL_CHANGE_NAD, POSITIVE, 0);
/* If the final result is zero then change the NAD to New NAD */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
lin_configured_NAD = lin_tl_rx_queue.tl_pdu[lin_tl_rx_queue.queue_header][7];
#else/* Single frame support */
lin_configured_NAD = (*tl_current_rx_pdu_ptr)[7];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
}
}
}
}
#endif /* End (LIN_PROTOCOL == PROTOCOL_21) */
#endif /* End ( _LIN_GPIO_ == 0 ) && !defined(_MC9S08SC4_H) */
#if LIN_PROTOCOL == PROTOCOL_21
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
void lin_diagsrv_functional_service(void)
{
l_u16 length;
l_u8 data[10];
/* get pdu from rx queue */
ld_receive_message(&length, data);
/* do something here */
}
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
#endif /* End (LIN_PROTOCOL == PROTOCOL_21) */
#if LIN_PROTOCOL == PROTOCOL_J2602
void lin_diagservice_target_reset()
{
l_u8 *signal_data_ptr;
l_u8 nad;
lin_tl_pdu_data *lin_tl_pdu;
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
lin_tl_pdu = (lin_tl_pdu_data *)&lin_lld_response_buffer[1];
#else /* Single frame support */
lin_tl_pdu = tl_current_rx_pdu_ptr;
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Set the reset flag within the J2602 Status Byte */
/* Set error signal equal to error in response */
lin_pFrameBuf[response_error_byte_offset] = (lin_pFrameBuf[response_error_byte_offset] &
(~(0x07 << response_error_bit_offset))) |
(0x01 << response_error_bit_offset);
/* Create positive response */
/* Get NAD of node */
nad = (*lin_tl_pdu)[0];
if (LD_BROADCAST != nad)
{
lin_tl_make_slaveres_pdu(SERVICE_TARGET_RESET, POSITIVE, 0);
}
else
{
tl_slaveresp_cnt = 0;
}
}
#endif /* End (LIN_PROTOCOL == PROTOCOL_J2602) */
#endif /* End (LIN_MODE == _SLAVE_MODE_) */
/********------------ End of code for SINGLE Interface --------------**********/
/********------------- Code supports Multi interface ----------------**********/
#if LIN_MODE == _MASTER_MODE_
/*************************** FUNCTIONS *******************/
#if LIN_PROTOCOL == PROTOCOL_21
void lin_diagservice_assign_frame_id_range
(
/* [IN] interface name */
l_ifc_handle iii
)
{
const lin_configuration* conf;
l_s8 j, i = 0;
l_u8 start_index;
l_u8 cfg_frame_num = 0;
lin_tl_pdu_data *lin_tl_pdu;
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
l_u16 length;
l_u8 NAD, data[10];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Get current configuration */
conf = &lin_ifc_configuration[iii];
/* Do actions only for slave nodes */
if (conf->function == _SLAVE_)
{
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* receive message data */
ld_receive_message(iii, &length, &NAD, data+2);
lin_tl_pdu = (lin_tl_pdu_data *)data;
#else /* Single frame support */
/* Get current PDU pointer of RX queue */
lin_tl_pdu = (lin_tl_pdu_data *)&conf->response_buffer[1];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Get start index in request */
start_index = (*lin_tl_pdu)[3];
/* Find the number of configurable frame */
i = 1;
while (0xFFFF != (conf->configuration_ROM)[i])
{
i++;
cfg_frame_num++;
}
/* Check request validity */
for (i = 7, j = start_index+4; j > start_index; i--, j-- )
{
if ((0xFF != (*lin_tl_pdu)[i]) && (j > cfg_frame_num))
{
lin_tl_make_slaveres_pdu(iii, SERVICE_ASSIGN_FRAME_ID_RANGE, NEGATIVE, GENERAL_REJECT);
return;
}
}
/* Store PIDs */
for (i = 4, j = 1; i < 8; i++, j++)
{
switch ((*lin_tl_pdu)[i])
{
case 0x00:
/* Unassign frame */
(conf->configuration_RAM)[start_index + j] = 0xFF;
break;
case 0xFF:
/* keep the previous assigned value of this frame */
break;
default:
/* Calculate frame ID and Assign ID to frame */
(conf->configuration_RAM)[start_index + j] = lin_process_parity((*lin_tl_pdu)[i], CHECK_PARITY);
break;
}
} /* End of for statement */
lin_tl_make_slaveres_pdu(iii, SERVICE_ASSIGN_FRAME_ID_RANGE, POSITIVE, 0);
}
}
void lin_diagservice_read_by_identifier
(
/* [IN] interface name */
l_ifc_handle iii
)
{
const lin_configuration* conf;
const lin_node_attribute* node_conf;
lin_product_id ident;
lin_tl_descriptor *tl_conf;
lin_tl_pdu_data *lin_tl_pdu;
l_u8 id;
l_u16 supid, fid;
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
lin_tl_pdu_data pdu_data;
l_u16 length;
l_u8 NAD, data[10];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Get current configuration */
conf = &lin_ifc_configuration[iii];
/* Get TL description */
tl_conf = conf->tl_desc;
/* Do actions only for slave nodes */
if (conf->function == _SLAVE_)
{
/* Multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
lin_tl_pdu = (lin_tl_pdu_data *)&pdu_data;
/* receive message data */
ld_receive_message(iii, &length, &NAD, data+2);
lin_tl_pdu = (lin_tl_pdu_data *)data;
#else /* Single frame support */
lin_tl_pdu = (lin_tl_pdu_data *)&conf->response_buffer[1];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Get the node attribute */
node_conf = conf->node_attribute;
/* Get the product identification */
ident = node_conf->product_id;
/* Get supplier and function indentification in request */
supid = (l_u16)(((*lin_tl_pdu)[5]) << 8);
supid = supid |(l_u16)((*lin_tl_pdu)[4]);
fid = (l_u16)(((*lin_tl_pdu)[7]) << 8);
fid = fid |(l_u16)((*lin_tl_pdu)[6]);
/* Check Supplier ID and Function ID */
if (((supid != ident.supplier_id) && (supid != LD_ANY_SUPPLIER)) || \
((fid != ident.function_id) && (fid != LD_ANY_FUNCTION)))
{
tl_conf->tl_slaveresp_cnt = 0;
return;
}
/* Get the identifier of request */
id = (*lin_tl_pdu)[3];
switch (id)
{
case LIN_PRODUCT_IDENT:
lin_tl_make_slaveres_pdu(iii, SERVICE_READ_BY_IDENTIFY, POSITIVE, 0);
break;
case SERIAL_NUMBER:
lin_tl_make_slaveres_pdu(iii, SERVICE_READ_BY_IDENTIFY, NEGATIVE, SUBFUNCTION_NOT_SUPPORTED);
break;
default:
if (id >= LIN_READ_USR_DEF_MIN && id <= LIN_READ_USR_DEF_MAX)
{
l_u8 data_callout[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
l_u8 i;
l_u8 retval = ld_read_by_id_callout(iii,id, data_callout);
/*If the User ID is supported, make positive response*/
if (retval == LD_POSITIVE_RESPONSE)
{
for (i =0; i <5; i++)
{
if (data_callout[i] != 0xFF)
{
lin_tl_make_slaveres_pdu(iii,SERVICE_READ_BY_IDENTIFY, POSITIVE, id);
break;
}
/* If all data_callout is 0xFF, then make negative response*/
if (i == 4)
{
/* Make a negative slave response PDU */
lin_tl_make_slaveres_pdu(iii,SERVICE_READ_BY_IDENTIFY, NEGATIVE, SUBFUNCTION_NOT_SUPPORTED);
}
}
}
else if (retval == LD_NEGATIVE_RESPONSE)
/*If the User ID is not supported, make negative response*/
{
/* Make a negative slave response PDU */
lin_tl_make_slaveres_pdu(iii,SERVICE_READ_BY_IDENTIFY, NEGATIVE, SUBFUNCTION_NOT_SUPPORTED);
}
else if (retval == LD_ID_NO_RESPONSE)
{
/*Do not answer*/
tl_conf->tl_slaveresp_cnt = 0;
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
*conf->tl_service_status = LD_SERVICE_IDLE;
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
}
}
else
{
/* Make a negative slave response PDU */
lin_tl_make_slaveres_pdu(iii, SERVICE_READ_BY_IDENTIFY, NEGATIVE, SUBFUNCTION_NOT_SUPPORTED);
}
break;
} /* end of switch */
}
}
/*FUNCTION**********************************************************************
*
* Function Name : lin_condittional_change_nad
* Description :
*
*END**************************************************************************/
void lin_condittional_change_nad(l_ifc_handle iii)
{
l_u8 id, byte, mask, invert;
const lin_configuration* conf;
lin_node_attribute* node_conf;
lin_tl_descriptor *tl_conf;
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
lin_transport_layer_queue *rx_queue;
#else /* Single frame support */
lin_tl_pdu_data *lin_tl_pdu;
#endif
/* Get current configuration */
conf = &lin_ifc_configuration[iii];
/* Do actions only for slave nodes */
if (conf->function == _SLAVE_)
{
/* Get TL description */
tl_conf = conf->tl_desc;
/* Get the node attribute */
node_conf = conf->node_attribute;
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* Get receive queue */
rx_queue = tl_conf->tl_rx_queue;
id = rx_queue->tl_pdu[rx_queue->queue_header][3];
byte = rx_queue->tl_pdu[rx_queue->queue_header][4];
mask = rx_queue->tl_pdu[rx_queue->queue_header][5];
invert = rx_queue->tl_pdu[rx_queue->queue_header][6];
#else /* Single frame support */
/* Get current PDU pointer of RX buffer */
lin_tl_pdu = tl_conf->tl_current_rx_pdu_ptr;
id = (*lin_tl_pdu)[3];
byte = (*lin_tl_pdu)[4];
mask = (*lin_tl_pdu)[5];
invert = (*lin_tl_pdu)[6];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Possible positive ID */
/* Support only identifier 0 for LIN Product Identification */
if (id == 0)
{
if(byte>0 && byte<6)
{
/*Byte 1: Supplier ID LSB; Byte 2: Supplier ID MSB*/
if(byte>0 && byte<3)
{
byte = (node_conf->product_id).supplier_id >> ((byte-1)*8);
}
/*Byte 3: Function ID LSB; Byte 4: Function ID MSB*/
else if(byte>2 && byte<5)
{
byte = (node_conf->product_id).function_id >> ((byte-3)*8);
}
/* Byte 5: Variant */
else
{
byte = (node_conf->product_id).variant;
}
/* Do a bitwise XOR with Invert and Do a bitwise AND with Mask */
byte = (byte^invert)&mask;
/* If the final result is zero, then give positive response*/
if (byte == 0)
{
lin_tl_make_slaveres_pdu(iii,SERVICE_CONDITIONAL_CHANGE_NAD, POSITIVE, 0);
/* If the final result is zero then change the NAD to New NAD */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
node_conf->configured_NAD = rx_queue->tl_pdu[rx_queue->queue_header][7];
#else/* Single frame support */
node_conf->configured_NAD = (*lin_tl_pdu)[7];
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
}
}
}
}
}
#endif /* End (LIN_PROTOCOL == PROTOCOL_21) */
#if LIN_PROTOCOL == PROTOCOL_J2602
void lin_diagservice_target_reset
(
/* [IN] interface name */
l_ifc_handle iii
)
{
const lin_configuration *conf;
lin_tl_descriptor *tl_conf;
lin_tl_pdu_data *pdu;
l_u8 byte_offset_temp, bit_offset_temp;
l_u8 nad;
/* Get current configuration */
conf = &lin_ifc_configuration[iii];
/* Get TL configuration */
tl_conf = conf->tl_desc;
/* Get PDU from RX queue */
/* Get current PDU pointer of RX queue */
pdu = (lin_tl_pdu_data *)&conf->response_buffer[1];
/* Set the reset flag within the J2602 Status Byte */
byte_offset_temp = conf->node_attribute->response_error_byte_offset;
bit_offset_temp = conf->node_attribute->response_error_bit_offset;
/* Set error signal equal to error in response */
lin_pFrameBuf[byte_offset_temp] = (lin_pFrameBuf[byte_offset_temp] &
(~(0x07 << bit_offset_temp))) |
(0x01 << bit_offset_temp);
/* Create positive response */
/* Get NAD of node */
nad = (*pdu)[0];
if (LD_BROADCAST != nad)
{
lin_tl_make_slaveres_pdu(iii, SERVICE_TARGET_RESET, POSITIVE, 0);
}
else
{
tl_conf->tl_slaveresp_cnt = 0;
}
}
#endif /* End (LIN_PROTOCOL == PROTOCOL_J2602) */
#endif /* End (LIN_MODE == _MASTER_MODE_) */
/* ---------------- End of code for Multi Interface ----------------- */
/**
* @}
*/

View File

@ -0,0 +1,301 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/** @addtogroup common_core_api_group
* @{ */
/**************************************************************************//**
*
* @file lin_common_api.h
*
* @author FPT Software
*
* @brief Common LIN API functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
*
*****************************************************************************/
/** @} */
#ifndef _LIN_COMMON_API_H
#define _LIN_COMMON_API_H
#include "lin.h"
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_bool l_sys_init ( void )
* @brief This function performs the initialization of the LIN core
*
* @return #l_bool
*
* @SDD_ID LIN_SDD_238
* @endif
*
* @details
* This function performs the initialization of the LIN core
*
* @see #lin_lld_setup_xgate
* @see #lin_lld_timer_init
*
* @addtogroup driver_cluster_group
*//*END*----------------------------------------------------------------------*/
l_bool l_sys_init (void);
/** @} */
#if LIN_MODE == _MASTER_MODE_
/** @addtogroup schedule_management_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void l_sch_set (l_ifc_handle iii, l_schedule_handle schedule_iii, l_u8 entry)
* @brief Set up the next schedule to be followed by the l_sch_tick
*
* @param iii <B>[IN]</B> interface name
* @param schedule_iii <B>[IN]</B> schedule table for interface
* @param entry <B>[IN]</B> entry to be set
*
* @return #void
*
* @SDD_ID LIN_SDD_249
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Set up the next schedule to be followed by the l_sch_tick
* function for a certain interface. The new schedule will be
* activated as soon as the current schedule reaches
* its next schedule entry point
*
*//*END*----------------------------------------------------------------------*/
void l_sch_set (l_ifc_handle iii, l_schedule_handle schedule_iii, l_u8 entry);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 l_sch_tick (l_ifc_handle iii)
* @brief follows a schedule
*
* @param iii <B>[IN]</B> interface name
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_250
* @endif
*
* @details
* This function follows a schedule. When a frame becomes due, its
* transmission is initiated. When the end of the current schedule is reached,
* this function starts again at the beginning of the schedule.
*
* @see #lin_tick_callback_handler
*//*END*----------------------------------------------------------------------*/
l_u8 l_sch_tick (l_ifc_handle iii);
/** @} */
/** @addtogroup interface_management_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void l_ifc_goto_sleep (l_ifc_handle iii)
* @brief Request slave nodes to enter bus sleep mode
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_252
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Request slave nodes on the cluster connected to the interface to enter
* bus sleep mode by issuing one go to sleep command.
*
* @see #l_sch_set
*//*END*----------------------------------------------------------------------*/
void l_ifc_goto_sleep (l_ifc_handle iii);
/** @} */
#endif /* LIN_MODE == _MASTER_MODE_ */
/** @addtogroup interface_management_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_bool l_ifc_init (l_ifc_handle iii)
* @brief Initialize the controller specified by name
*
* @param iii <B>[IN]</B> interface name
*
* @return #l_bool
*
* @SDD_ID LIN_SDD_251
* @endif
*
* @details
* Initialize the controller specified by name, i.e. sets up internal
* functions such as the baud rate. The default schedule set by the l_ifc_init
* call will be the L_NULL_SCHEDULE where no frames will be sent and received.
* This is the first call a user must perform, before using any other interface
* related LIN API functions.
* The function returns zero if the initialization was successful and non-zero if failed.
*
* @see #lin_lld_init
*//*END*----------------------------------------------------------------------*/
l_bool l_ifc_init (l_ifc_handle iii);
/* l_ifc_ioctl */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void l_ifc_wake_up (l_ifc_handle iii)
* @brief Transmit the wake up signal.
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_253
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Transmit the wake up signal.
*
* @see #lin_lld_tx_wake_up
*//*END*----------------------------------------------------------------------*/
void l_ifc_wake_up (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void l_ifc_rx (l_ifc_handle iii)
* @brief Receive one frame
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_254
* @endif
*
* @details
* Receive one frame
*
*//*END*----------------------------------------------------------------------*/
void l_ifc_rx (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void l_ifc_tx (l_ifc_handle iii)
* @brief Transmit one frame
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_255
* @endif
*
* @details
* Transmit one frame
*
*//*END*----------------------------------------------------------------------*/
void l_ifc_tx (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u16 l_ifc_read_status (l_ifc_handle iii)
* @brief This function will return the status of the previous communication
*
* @param iii <B>[IN]</B> interface name
*
* @return #l_u16
*
* @SDD_ID LIN_SDD_259
* @endif
*
* @local_var
* -# <B>#l_u16</B> <I>tmp_word_status</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @static_global_var
* -# <B>#lin_word_status</B>
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function will return the status of the previous communication
*
*//*END*----------------------------------------------------------------------*/
l_u16 l_ifc_read_status (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void l_ifc_aux (l_ifc_handle iii)
* @brief synchronize to the break/sync field
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_256
* @endif
*
* @details
* This function may be used in the slave nodes to synchronize to the
* break/sync field sequence transmitted by the master node on the
* interface specified by name.
*
*//*END*----------------------------------------------------------------------*/
void l_ifc_aux (l_ifc_handle iii);
/** @} */
/** @addtogroup call_out_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u16 l_sys_irq_disable (l_ifc_handle iii)
* @brief Disable LIN related IRQ
*
* @param iii <B>[IN]</B> interface name
*
* @return #l_u16
*
* @SDD_ID LIN_SDD_257
* @endif
*
* @details
* Disable LIN related IRQ
*
* @see #lin_lld_int_disable
*//*END*----------------------------------------------------------------------*/
l_u16 l_sys_irq_disable (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void l_sys_irq_restore (l_ifc_handle iii)
* @brief Enable LIN related IRQ
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_258
* @endif
*
* @details
* Enable LIN related IRQ
*
* @see #lin_lld_int_enable
*//*END*----------------------------------------------------------------------*/
void l_sys_irq_restore (l_ifc_handle iii);
/** @} */
/** @addtogroup common_core_api_group
* @{ */
/** @} */
#endif /* _LIN_COMMON_API_H */

View File

@ -0,0 +1,804 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup common_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_common_proto.h
*
* @author FPT Software
*
* @brief Common LIN protocol functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
*
*****************************************************************************/
#ifndef _LIN_COMMON_PROTO_H
#define _LIN_COMMON_PROTO_H
#include "lin.h"
#define MAKE_UNCONDITIONAL_FRAME 0 /**< make unconditional frame */
#define UPDATE_UNCONDITIONAL_FRAME 1 /**< update unconditional frame */
#if LIN_MODE == _MASTER_MODE_
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_pid_response_callback_handler (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid)
* @brief The upper slave task is in charge of handling PID or Response complete events
*
* @param iii <B>[IN]</B> interface name
* @param event_id <B>[IN]</B> event id
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_264
* @endif
*
* @details
* The upper slave task is in charge of handling PID or Response complete events
*
* @see #lin_process_pid
* @see #lin_update_tx
* @see #lin_update_rx
* @see #lin_bus_activity_timeout
* @see #lin_handle_error
*//*END*----------------------------------------------------------------------*/
void lin_pid_response_callback_handler (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_tick_callback_handler (l_ifc_handle iii)
* @brief Tick handle function used for master task. This function is called periodically,
*
* @param iii <B>[IN]</B> interface name
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_265
* @endif
*
* @local_var
* -# <B>#lin_schedule_struct</B> <I>*sch</I>
* -# <B>#l_u8</B> <I>*current_entry</I>
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_queue</B> <I>*current_pdu</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#schedule_tbl</B>
*
* @details
* Tick handle function used for master task. This function is called periodically,
*
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
* @see #lin_collision_resolve
* @see #lin_switch_sch_table
* @see #lin_check_sporadic_update
* @see #lin_lld_tx_header
*//*END*----------------------------------------------------------------------*/
l_u8 lin_tick_callback_handler (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_process_pid (l_ifc_handle iii, l_u8 pid)
* @brief Handle the received PID and decide the next action of stack
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_266
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>action</I>
* -# <B>#l_u8</B> <I>associate_frame</I>
* -# <B>#lin_frame_struct</B> <I>*lin_frame_ptr</I>
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#lin_associate_frame_struct</B>
*
* @details
* Handle the received PID and decide the next action of Stack
*
* @see #lin_get_frame_index
* @see #lin_process_uncd_frame
* @see #lin_make_res_evnt_frame
* @see #lin_tl_make_mreq_pdu
* @see #lin_make_res_diag_frame
* @see #lin_lld_rx_response
* @see #lin_lld_set_response
* @see #lin_lld_ignore_response
*//*END*----------------------------------------------------------------------*/
void lin_process_pid (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_rx (l_ifc_handle iii, l_u8 pid)
* @brief Update signal, status and flags after received response
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_267
* @endif
*
* @local_var
* -# <B>#l_bool</B> <I>pid_found</I>
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#lin_flag_frame_handle_tbl</B>
*
* @details
* Update signal, status and flags after received response
*
* @see #lin_get_frame_index
* @see #lin_process_uncd_frame
* @see #lin_update_rx_evnt_frame
* @see #lin_update_rx_diag_frame
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
*//*END*----------------------------------------------------------------------*/
void lin_update_rx (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_tx (l_ifc_handle iii, l_u8 pid)
* @brief Update status and flags after transmit response
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_268
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
* -# <B>#const lin_frame_struct</B> <I>*lin_frame_ptr</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#frame_signal_error</B>
* -# <B>#lin_flag_frame_handle_tbl</B>
* -# <B>#lin_frame_flag_tbl</B>
* -# <B>#lin_associate_frame_struct</B>
*
* @details
* Update status and flags after transmit response
*
* @see #lin_get_frame_index
* @see #lin_update_tx_flags
* @see #tl_process_mreq
* @see #lin_update_err_signal
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
*//*END*----------------------------------------------------------------------*/
void lin_update_tx (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_handle_error (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid)
* @brief Handle error raised by low-level
*
* @param iii <B>[IN]</B> interface name
* @param event_id <B>[IN]</B> event id
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_269
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
* -# <B>#const lin_frame_struct</B> <I>*lin_frame_ptr</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#frame_signal_error</B>
* -# <B>#lin_flag_frame_handle_tbl</B>
* -# <B>#lin_frame_flag_tbl</B>
* -# <B>#lin_associate_frame_struct</B>
*
* @details
* Handle error raised by low-level
*
* @see #lin_get_frame_index
* @see #lin_update_tx_flags
* @see #tl_process_mreq
* @see #lin_update_err_signal
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
*//*END*----------------------------------------------------------------------*/
void lin_handle_error (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_bus_activity_timeout (l_ifc_handle iii, l_u8 pid)
* @brief Set bus activity timeout
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_270
* @endif
*
* @local_var
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Set bus activity timeout
*
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
* @see #lin_lld_set_low_power_mode
*//*END*----------------------------------------------------------------------*/
void lin_bus_activity_timeout (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_switch_sch_table (l_ifc_handle iii)
* @brief Check to see if the current schedule table is needed to change
* or not
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_271
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>tmp_sch_id</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Check to see if the current schedule table is needed to change
* or not. Used in tick callback function.
*
*//*END*----------------------------------------------------------------------*/
void lin_switch_sch_table (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_check_sporadic_update (l_ifc_handle iii, l_frame_handle frm_id)
* @brief Find the frame associated with a specified sporadic frame which is updated
*
* @param iii <B>[IN]</B> interface name
* @param frm_id <B>[IN]</B> index of frame
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_272
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>j</I>
* -# <B>#lin_associate_frame_struct</B> <I>*ptr</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Find the frame associated with a specified sporadic frame which is updated
*
*//*END*----------------------------------------------------------------------*/
l_u8 lin_check_sporadic_update (l_ifc_handle iii, l_frame_handle frm_id);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_tx_flags (l_ifc_handle iii, l_u8 frm_id)
* @brief Update transmit flags
*
* @param iii <B>[IN]</B> interface name
* @param frm_id <B>[IN]</B> index of frame
*
* @return #void
*
* @SDD_ID LIN_SDD_273
* @endif
*
* @local_var
* -# <B>#const lin_configuration</B> <I>*conf</I>
* -# <B>#const lin_frame_struct</B> <I>*frame_struct_ptr</I>
* -# <B>#lin_frm2sig</B> <I>*ptr</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u8</B> <I>signal_id</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#lin_flag_signal_handle_tbl</B>
*
* @details
* Update transmit flags
*
*//*END*----------------------------------------------------------------------*/
void lin_update_tx_flags (l_ifc_handle iii, l_u8 frm_id);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_rx_diag_frame (l_ifc_handle iii, l_u8 pid)
* @brief The function is to update the receive flags associated with signals/frames
* in case receive a diagnostic frame.
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_274
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u8</B> <I>j</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The function is to update the receive flags associated with signals/frames
* in case receive a diagnostic frame.
*
* @see #lin_lld_set_low_power_mode (iii)
* @see #lin_tl_handler (iii)
*//*END*----------------------------------------------------------------------*/
void lin_update_rx_diag_frame (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_process_uncd_frame (l_ifc_handle iii, l_u8 pid, l_u8 type)
* @brief This function to pack signals associated with unconditional frame into buffer
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
* @param type <B>[IN]</B> make or update
*
* @return #void
*
* @SDD_ID LIN_SDD_278
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u8</B> <I>tmp_offset</I>
* -# <B>#l_u8</B> <I>index</I>
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#l_u8</B> <I>signal_id</I>
* -# <B>#l_u8</B> <I>*response_buffer_ptr</I>
* -# <B>#l_u8</B> <I>tmp_sig_size</I>
* -# <B>#l_u8</B> <I>tmp_byte_data</I>
* -# <B>#l_s8</B> <I>length</I>
* -# <B>#l_s8</B> <I>to_fill</I>
* -# <B>#l_s8</B> <I>byte_offset</I>
* -# <B>#const lin_frame_struct</B> <I>*frame_struct_ptr</I>
* -# <B>#const lin_signal_struct</B> <I>*lin_signal_str_ptr</I>
* -# <B>#l_u16</B> <I>tmp16</I>
* -# <B>#lin_frm2sig</B> <I>*ptr</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#frame_signal_error</B>
* -# <B>#lin_flag_signal_handle_tbl</B>
*
* @details
* This function to pack signals associated with unconditional frame into buffer
*
* @see #lin_update_signal_scalar
* @see #l_bytes_rd
* @see #l_bytes_wr
*//*END*----------------------------------------------------------------------*/
void lin_process_uncd_frame(l_ifc_handle iii, l_u8 pid, l_u8 type);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_make_res_diag_frame (l_ifc_handle iii, l_u8 pid)
* @brief This function is to copy diagnostic data into buffer
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_275
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>lin_tl_pdu</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function is to copy diagnostic data into buffer
*
*//*END*----------------------------------------------------------------------*/
void lin_make_res_diag_frame (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_get_frame_index (l_ifc_handle iii, l_u8 pid)
* @brief This function is return the index of a frame in frame list or 0xFF if not found.
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_276
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function is return the index of a frame in frame list or 0xFF if not found.
*
*//*END*----------------------------------------------------------------------*/
l_u8 lin_get_frame_index (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_signal_scalar (const lin_configuration *conf_ptr, l_u16 value, l_signal_handle signal_name)
* @brief Check and update scalar signal
*
* @param conf_ptr <B>[IN]</B> current configuration
* @param value <B>[IN]</B> value to compare
* @param signal_name <B>[IN]</B> signal name
*
* @return #void
*
* @SDD_ID LIN_SDD_277
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>signal_size</I>
* -# <B>#l_u16</B> <I>sig_value</I>
*
* @details
* Check and update scalar signal
*
* @see #l_u16_wr
* @see #l_u8_wr
* @see #l_bool_wr
*//*END*----------------------------------------------------------------------*/
void lin_update_signal_scalar(const lin_configuration *conf_ptr, l_u16 value, l_signal_handle signal_name);
#endif /* end of LIN_MODE == _MASTER_MODE_ */
/* ---------------------------- For 1 interface -----------------------------------*/
#if LIN_MODE == _SLAVE_MODE_
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_pid_response_callback_handler (lin_lld_event_id event_id, l_u8 pid)
* @brief The upper slave task is in charge of handling PID or Response complete events
*
* @param event_id <B>[IN]</B> event id
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_287
* @endif
*
* @details
* The upper slave task is in charge of handling PID or Response complete events
*
* @see #lin_process_pid
* @see #lin_update_tx
* @see #lin_update_rx
* @see #lin_handle_error (event_id, pid)
*//*END*----------------------------------------------------------------------*/
void lin_pid_response_callback_handler (lin_lld_event_id event_id, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_process_pid (l_u8 pid)
* @brief Handle the received PID and decide the next action of the Stack
*
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_288
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>action</I>
* -# <B>#lin_frame_struct</B> <I>*lin_frame_ptr</I>
*
* @static_global_var
* -# <B>#frame_index</B>
* -# <B>#lin_frame_tbl</B>
* -# <B>#lin_frame_flag_tbl</B>
* -# <B>#lin_configuration_RAM</B>
* -# <B>#tl_slaveresp_cnt</B>
*
* @details
* Handle the received PID and decide the next action of the Stack
*
* @see #lin_get_frame_index
* @see #lin_make_res_evnt_frame
* @see #lin_process_uncd_frame
* @see #lin_make_res_diag_frame
* @see #lin_lld_rx_response
* @see #lin_lld_set_response
* @see #lin_lld_ignore_response
*//*END*----------------------------------------------------------------------*/
void lin_process_pid (l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_rx (l_u8 pid)
* @brief Update signal, status and flags after received response
*
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_289
* @endif
*
* @local_var
* -# <B>#l_bool</B> <I>pid_found</I>
*
* @static_global_var
* -# <B>#lin_successful_transfer</B>
* -# <B>#lin_frame_tbl</B>
* -# <B>#lin_flag_frame_handle_tbl</B>
*
* @details
* Update signal, status and flags after received response
*
* @see #lin_process_uncd_frame
* @see #lin_update_rx_diag_frame
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
*//*END*----------------------------------------------------------------------*/
void lin_update_rx (l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_tx (l_u8 pid)
* @brief Update status and flags after transmit response
*
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_290
* @endif
*
* @static_global_var
* -# <B>#lin_successful_transfer</B>
* -# <B>#lin_frame_flag_tbl</B>
* -# <B>#frame_index</B>
*
* @details
* Update status and flags after transmit response
*
* @see #lin_process_uncd_frame
* @see #lin_update_rx_diag_frame
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
*//*END*----------------------------------------------------------------------*/
void lin_update_tx (l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_handle_error (lin_lld_event_id event_id, l_u8 pid)
* @brief Handle error raised by low-level
*
* @param event_id <B>[IN]</B> event id
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_291
* @endif
*
* @static_global_var
* -# <B>#frame_index</B>
* -# <B>#lin_frame_tbl</B>
* -# <B>#lin_error_in_response</B>
* -# <B>#tl_slaveresp_cnt</B>
*
* @details
* Handle error raised by low-level
*
* @see #lin_get_frame_index
* @see #lin_update_err_signal
* @see #lin_update_word_status_lin21
* @see #lin_update_status_byte
* @see #lin_update_word_status_j2602
*//*END*----------------------------------------------------------------------*/
void lin_handle_error (lin_lld_event_id event_id, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_bus_activity_timeout (l_u8 pid)
* @brief Set bus activity timeout
*
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_292
* @endif
*
* @details
* Set bus activity timeout
*
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
* @see #lin_lld_set_low_power_mode
*//*END*----------------------------------------------------------------------*/
void lin_bus_activity_timeout (l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_tx_flags (l_u8 frm_id)
* @brief Update transmit flags
*
* @param frm_id <B>[IN]</B> index of frame
*
* @return #void
*
* @SDD_ID LIN_SDD_293
* @endif
*
* @local_var
* -# <B>#lin_frame_struct</B> <I>frame_struct_ptr</I>
* -# <B>#lin_frm2sig</B> <I>*ptr</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u8</B> <I>signal_id</I>
*
* @static_global_var
* -# <B>#lin_frame_tbl</B>
* -# <B>#lin_flag_signal_handle_tbl</B>
*
* @details
* Update transmit flags
*
*//*END*----------------------------------------------------------------------*/
void lin_update_tx_flags (l_u8 frm_id);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_rx_diag_frame ( void )
* @brief update the receive flags associated with signals/frames
* in case receive a diagnostic frame.
*
* @return #void
*
* @SDD_ID LIN_SDD_294
* @endif
*
* @static_global_var
* -# <B>#lin_lld_response_buffer</B>
* -# <B>#lin_goto_sleep_flg</B>
*
* @details
* The function is to update the receive flags associated with signals/frames
* in case receive a diagnostic frame.
*
* @see #lin_lld_set_low_power_mode
* @see #lin_tl_put_pdu
* @see #lin_tl_handler
*//*END*----------------------------------------------------------------------*/
void lin_update_rx_diag_frame (void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_process_uncd_frame (l_u8 pid, l_u8 type)
* @brief Update signal, status and flags after received response
*
* @param pid <B>[IN]</B> PID to process
* @param type <B>[IN]</B> make or update
*
* @return #void
*
* @SDD_ID LIN_SDD_297
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u8</B> <I>tmp_offset</I>
* -# <B>#l_u8</B> <I>index</I>
* -# <B>#l_u8</B> <I>signal_id</I>
* -# <B>#l_s8</B> <I>length</I>
* -# <B>#l_s8</B> <I>to_fill</I>
* -# <B>#l_s8</B> <I>byte_offset</I>
* -# <B>#l_s8</B> <I>tmp_byte_data</I>
* -# <B>#l_u16</B> <I>tmp16</I>
* -# <B>#l_u16</B> <I>tmp_sig_size</I>
* -# <B>#lin_frm2sig</B> <I>*ptr</I>
*
* @static_global_var
* -# <B>#frame_index</B>
* -# <B>#lin_frame_tbl</B>
* -# <B>#lin_lld_response_buffer</B>
* -# <B>#response_error</B>
* -# <B>#frame_signal_error</B>
* -# <B>#lin_flag_signal_handle_tbl</B>
* -# <B>#lin_signal_flag_tbl</B>
*
* @details
* Update signal, status and flags after received response
*
* @see #lin_get_frame_index
* @see #l_u16_wr
* @see #l_u8_wr
* @see #l_bool_wr
* @see #l_bytes_rd
* @see #l_bytes_wr
*//*END*----------------------------------------------------------------------*/
void lin_process_uncd_frame(l_u8 pid, l_u8 type);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_make_res_diag_frame ( void )
* @brief This function is to copy diagnostic data into buffer
*
* @return #void
*
* @SDD_ID LIN_SDD_295
* @endif
*
* @details
* This function is to copy diagnostic data into buffer
*
* @see #lin_tl_get_pdu
*//*END*----------------------------------------------------------------------*/
void lin_make_res_diag_frame (void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 lin_get_frame_index (l_u8 pid)
* @brief This function is return the index of a frame in frame list or 0xFF if not found.
*
* @param pid <B>[IN]</B> PID to process
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_296
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
*
* @static_global_var
* -# <B>#lin_configuration_RAM</B>
*
* @details
* This function is return the index of a frame in frame list or 0xFF if not found.
*
*//*END*----------------------------------------------------------------------*/
l_u8 lin_get_frame_index (l_u8 pid);
#endif /* end of LIN_MODE == _SLAVE_MODE_*/
#endif /* _LIN_COMMON_PROTO_H */
/** @} */

View File

@ -0,0 +1,868 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup commontl_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_commontl_api.h
*
* @author FPT Software
*
* @brief Common LIN transport layer and configuration functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
* 20111005 v1.1 Added porotytpe functions
*
*****************************************************************************/
#ifndef _LIN_COMMONTL_API_H
#define _LIN_COMMONTL_API_H
/** @} */
#include "lin.h"
/* Node configuration */
#define LD_READ_OK 0x33 /**< Read OK */
#define LD_LENGTH_TOO_SHORT 0x34 /**< Lenghth too short */
#define LD_DATA_ERROR 0x43 /**< Data error */
#define LD_LENGTH_NOT_CORRECT 0x44 /**< Lenghth not correct */
#define LD_SET_OK 0x45 /**< Set OK */
#if LIN_MODE == _MASTER_MODE_
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* Initialized transport layer */
/** @addtogroup initialization_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_init (l_ifc_handle iii)
* @brief initialize or reinitalize the raw and cooked layers
*
* @param iii <B>[IN]</B> lin interface handle
*
* @return #void
*
* @SDD_ID LIN_SDD_17
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This call will initialize or reinitalize the raw and cooked layers
* on the interface iii.
* All the transport layer buffers will be initialized.
*//*END*----------------------------------------------------------------------*/
void ld_init(l_ifc_handle iii);
/** @} */
/* Transport layer RAW APIs */
/** @addtogroup raw_api_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_put_raw (l_ifc_handle iii, const l_u8* const data)
* @brief The call queues the transmisson of 8 bytes of data in one frame
*
* @param iii <B>[IN]</B> lin interface handle
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @SDD_ID LIN_SDD_318
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>tl_queue</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call queues the transmisson of 8 bytes of data in one frame
* The data is sent in the next suitable frame.
*
* @see #tl_put_raw
*//*END*----------------------------------------------------------------------*/
void ld_put_raw(l_ifc_handle iii,const l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_get_raw (l_ifc_handle iii, l_u8* const data)
* @brief The call copies the oldest received diagnostic frame data to the memory
* specified by data
*
* @param iii <B>[IN]</B> lin interface handle
* @param data <B>[IN]</B> buffer for store data received
*
* @return #void
*
* @SDD_ID LIN_SDD_319
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>tl_queue</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call copies the oldest received diagnostic frame data to the memory
* specified by data.
* The data returned is received from master request frame for slave node
* and the slave response frame for master node.
*//*END*----------------------------------------------------------------------*/
void ld_get_raw(l_ifc_handle iii,l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_raw_tx_status (l_ifc_handle iii)
* @brief The call returns the status of the raw frame transmission function
*
* @param iii <B>[IN]</B> lin interface handle
*
* @return #void
*
* @SDD_ID LIN_SDD_320
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>tl_queue</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call returns the status of the raw frame transmission function:<br/>
* LD_QUEUE_EMPTY : The transmit queue is empty. In case previous calls to <br/>
* ld_put_raw, all frames in the queue have been <br/>
* trans-mitted. <br/>
* LD_QUEUE_AVAILABLE: The transmit queue contains entries, but is not full. <br/>
* LD_QUEUE_FULL : The transmit queue is full and can not accept further <br/>
* frames. <br/>
* LD_TRANSMIT_ERROR : LIN protocol errors occurred during the transfer; <br/>
* ini-tialize and redo the transfer.
*//*END*----------------------------------------------------------------------*/
l_u8 ld_raw_tx_status(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_raw_rx_status (l_ifc_handle iii)
* @brief The call returns the status of the raw frame receive function
*
* @param iii <B>[IN]</B> lin interface handle
*
* @return #void
*
* @SDD_ID LIN_SDD_321
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>tl_queue</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call returns the status of the raw frame receive function:
* LD_NO_DATA The receive queue is empty.
* LD_DATA_AVAILABLE The receive queue contains data that can be read.
* LD_RECEIVE_ERROR LIN protocol errors occurred during the transfer;
* ini-tialize and redo the transfer.
*//*END*----------------------------------------------------------------------*/
l_u8 ld_raw_rx_status(l_ifc_handle iii);
/** @} */
/* Transport layer COOKED APIs */
/** @addtogroup cooked_api_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_send_message (l_ifc_handle iii, l_u16 length, l_u8 NAD, const l_u8* const data)
* @brief The call packs the information specified by data and length into one or multiple diagnostic frames
*
* @param iii <B>[IN]</B> lin interface handle
* @param length <B>[IN]</B> length of data to send
* @param NAD <B>[IN]</B> Node address of slave node
* @param data <B>[IN]</B> data to be sent
* @return #void
*
* @SDD_ID LIN_SDD_322
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>tl_queue</I>
* -# <B>#lin_tl_pdu_data</B> <I>queue_data</I>
* -# <B>#lin_tl_pdu_data</B> <I>pdu</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u8</B> <I>message_size</I>
* -# <B>#l_u16</B> <I>data_index = 0</I>
* -# <B>#l_u16</B> <I>tmp_length = length</I>
* -# <B>#l_u16</B> <I>frame_counter = 0</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call packs the information specified by data and length into one or multiple
* diagnostic frames. If the call is made in a master node application the frames
* are transmitted to the slave node with the address NAD. If the call is made in
* a slave node application the frames are transmitted to the master node with the
* address NAD. The parameter NAD is not used in slave nodes.
*//*END*----------------------------------------------------------------------*/
/** @} */
void ld_send_message(l_ifc_handle iii, l_u16 length, l_u8 NAD, const l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_receive_message (l_ifc_handle iii, l_u16 *const length, l_u8 *const NAD, l_u8 *const data)
* @brief The call prepares the LIN diagnostic module to receive one message and store it in the buffer pointed to by data
*
* @param iii <B>[IN]</B> lin interface handle
* @param length <B>[OUT]</B> length of data to receive
* @param NAD <B>[OUT]</B> Node address of slave node
* @param data <B>[OUT]</B> data to be sent
*
* @return #void
*
* @SDD_ID LIN_SDD_323
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>tl_queue</I>
* -# <B>#lin_tl_pdu_data</B> <I>queue_data</I>
* -# <B>#lin_tl_pdu_data</B> <I>pdu</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u16</B> <I>data_index = 0</I>
* -# <B>#l_u16</B> <I>tmp_length</I>
* -# <B>#l_u16</B> <I>frame_counter</I>
* -# <B>#l_u8</B> <I>PCI_type</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call prepares the LIN diagnostic module to receive one message and store it in
* the buffer pointed to by data. At the call, length shall specify the maximum length
* allowed. When the reception has completed, length is changed to the actual length
* and NAD to the NAD in the message.
*//*END*----------------------------------------------------------------------*/
void ld_receive_message(l_ifc_handle iii, l_u16* const length, l_u8* const NAD, l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_tx_status (l_ifc_handle iii)
* @brief The call returns the status of the last made call to ld_send_message.
*
* @param iii <B>[IN]</B> lin interface handle
* @return #l_u8
*
* @SDD_ID LIN_SDD_324
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call returns the status of the last made call to ld_send_message.
* The following values can be returned:
* LD_IN_PROGRESS: The transmission is not yet completed.
* LD_COMPLETED: The transmission has completed successfully (and
* you can issue a new ld_send_message call). This
* value is also returned after initialization of
* the transport layer.
* LD_FAILED: The transmission ended in an error. The data was
* only partially sent. The transport layer shall
* be reinitialized before processing further messages.
* To find out why a transmission has failed, check
* the status management function l_read_status
* LD_N_AS_TIMEOUT: The transmission failed because of a N_As timeout,
*//*END*----------------------------------------------------------------------*/
l_u8 ld_tx_status(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_rx_status (l_ifc_handle iii)
* @brief The call returns the status of the last made call to ld_send_message.
*
* @param iii <B>[IN]</B> lin interface handle
* @return #void
*
* @SDD_ID LIN_SDD_325
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call returns the status of the last made call to ld_receive_message. <br/>
* The following values can be returned: <br/>
* LD_IN_PROGRESS: The reception is not yet completed. <br/>
* LD_COMPLETED: The reception has completed successfully and all <br/>
* information (length, NAD, data) is available. (You can <br/>
* also issue a new ld_receive_message call). This <br/>
* value is also returned after initialization of the <br/>
* transport layer. <br/>
* LD_FAILED: The reception ended in an error. The data was only <br/>
* partially received and should not be trusted. Initialize <br/>
* before processing further transport layer messages. <br/>
* To find out why a reception has failed, check the status <br/>
* management function l_read_status. <br/>
* LD_N_CR_TIMEOUT The reception failed because of a N_Cr timeout <br/>
* LD_WRONG_SN The reception failed because of an unexpected sequence number.
*//*END*----------------------------------------------------------------------*/
l_u8 ld_rx_status(l_ifc_handle iii);
/** @} */
/* Configuration and Identify APIs */
/** @addtogroup node_configuration_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_assign_NAD (l_ifc_handle iii, l_u8 initial_NAD, l_u16 supplier_id, l_u16 function_id, l_u8 new_NAD)
* @brief This call assigns the NAD (node diagnostic address) of all slave nodes that matches the initial_NAD, the supplier ID and the function ID.
*
* @param iii <B>[IN]</B> lin interface handle
* @param initial_NAD <B>[IN]</B> initial node address of the target node
* @param supplier_id <B>[IN]</B> supplier ID of the target node
* @param function_id <B>[IN]</B> function identifier of the target node
* @param new_NAD <B>[IN]</B> new node address
*
* @return #void
*
* @SDD_ID LIN_SDD_305
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>data[6]</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This call assigns the NAD (node diagnostic address) of all slave nodes
* that matches the initial_NAD, the supplier ID and the function ID.
* The new NAD of the slave node will be new_NAD.
*//*END*----------------------------------------------------------------------*/
#endif /*End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)*/
void ld_assign_NAD(l_ifc_handle iii, l_u8 initial_NAD, l_u16 supplier_id, l_u16 function_id, l_u8 new_NAD);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_conditional_change_NAD (l_ifc_handle iii, l_u8 NAD, l_u8 id, l_u8 byte, l_u8 mask, l_u8 invert, l_u8 new_NAD)
* @brief This call changes the NAD if the node properties fullfil the test specified by id, byte, mask and invert.
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> current NAD value of the target node
* @param id <B>[IN]</B> property ID of the target node
* @param byte <B>[IN]</B> byte location of property value to be read from the target node
* @param mask <B>[IN]</B> value for masking the read property byte
* @param invert <B>[IN]</B> value for excluding the read property byte
* @param new_NAD <B>[IN]</B> new NAD value to be assigned when the condition is met
*
* @return #void
*
* @SDD_ID LIN_SDD_206
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>data[6]</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This call changes the NAD if the node properties fullfil the test
* specified by id, byte, mask and invert.
*//*END*----------------------------------------------------------------------*/
void ld_conditional_change_NAD (l_ifc_handle iii, l_u8 NAD, l_u8 id, l_u8 byte, l_u8 mask, l_u8 invert, l_u8 new_NAD);
/** @} */
/** @addtogroup node_identification_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_read_by_id(l_ifc_handle iii, l_u8 NAD, l_u16 supplier_id, l_u16 function_id, l_u8 id, l_u8* const data)
* @brief The call requests the slave node selected with the NAD to return the property associated with the id parameter.
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> alue of the target node
* @param supplier_id <B>[IN]</B> supplier ID of the target node
* @param function_id <B>[IN]</B> function ID of the target node
* @param id <B>[IN]</B> ID of the target node
* @param data <B>[IN]</B> buffer for saving the data read from the node
*
* @return #void
*
* @SDD_ID LIN_SDD_307
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>buf[6]</I>
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The call requests the slave node selected with the NAD to return the
* property associated with the id parameter.
*//*END*----------------------------------------------------------------------*/
void ld_read_by_id (l_ifc_handle iii, l_u8 NAD, l_u16 supplier_id, l_u16 function_id, l_u8 id, l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_save_configuration(l_ifc_handle iii,l_u8 NAD)
* @brief This function to issue a save configuration request to a slave node
*
* @param iii <B>[IN]</B> interface name
* @param NAD <B>[IN]</B> node adress of target
*
* @return #void
*
* @SDD_ID LIN_SDD_xxx
* @endif
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> Node address of target
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
* -# <B>l_u8</B> <I>data[6]</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
*
* @details
* This function is called to send a save configuration request to a specific slave node <br>
* with the given NAD, or to all slave nodes if NAD is set to broadcast
* This function is implemented for Master Only
*//*END*----------------------------------------------------------------------*/
void ld_save_configuration(l_ifc_handle iii,l_u8 NAD);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_read_configuration(l_ifc_handle iii, l_u8* const data, l_u8* const length)
* @brief This function to copy current configuration in a reserved area
*
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_xxx
* @endif
*
* @param iii <B>[IN]</B> lin interface handle
* @param data <B>[IN]</B> data area to save configuration,
* @param length <B>[IN]</B> length of data arean (1+n, NAD+PIDs)
*
* @local_var
* -# <B>#i</B> <I>l_u8</I>
* -# <B>#temp</B> <I>l_u8</I>
* -# <B>#retval</B> <I>l_u8</I>
* -# <B>#expected_length</B> <I>l_u8</I>
*
* @static_global_var
* -# <B>#lin_configured_NAD</B>
* -# <B>#lin_configuration_RAM</B>
*
* @details
* This function is implemented Slave Only
*//*END*----------------------------------------------------------------------*/
l_u8 ld_read_configuration(l_ifc_handle iii, l_u8* const data, l_u8* const length);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_set_configuration(l_ifc_handle iii, const l_u8* const data, l_u16 length)
* @brief This function function to configure slave node according to data
*
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_xxx
* @endif
*
* @param iii <B>[IN]</B> lin interface handle
* @param data <B>[IN]</B> structure containing the NAD and all the n PIDs for the frames of the specified NAD,
* @param length <B>[IN]</B> length of data arean (1+n, NAD+PIDs)
*
* @local_var
* -# <B>#i</B> <I>l_u8</I>
* -# <B>#retval</B> <I>l_u8</I>
* -# <B>#expected_length</B> <I>l_u8</I>
*
* @static_global_var
* -# <B>#lin_configured_NAD</B>
* -# <B>#lin_configuration_RAM</B>
*
* @details
* This function is implemented Slave Only
*//*END*----------------------------------------------------------------------*/
l_u8 ld_set_configuration(l_ifc_handle iii, const l_u8* const data, l_u16 length);
/** @} */
#endif /* End LIN_MODE == _MASTER_MODE_ */
/* SLAVE MODE */
#if LIN_MODE == _SLAVE_MODE_
/* Unuse for GPIO */
#if (_LIN_GPIO_ == 0) && !defined(_MC9S08SC4_H)
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* INITIALIZATION */
/** @addtogroup initialization_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_init (void)
* @brief initialize or reinitalize the transport layer
*
* @return #void
*
* @SDD_ID LIN_SDD_341
* @endif
*
* @static_global_var
* -# <B>#lin_tl_tx_queue</B>
* -# <B>#lin_tl_rx_queue</B>
* -# <B>#tl_rx_msg_status</B>
* -# <B>#tl_rx_msg_index</B>
* -# <B>#tl_rx_msg_size</B>
* -# <B>#tl_receive_msg_status</B>
* -# <B>#tl_tx_msg_status</B>
* -# <B>#tl_tx_msg_index</B>
* -# <B>#tl_tx_msg_size</B>
* -# <B>#tl_last_cfg_result</B>
* -# <B>#tl_last_RSID</B>
* -# <B>#tl_ld_error_code</B>
* -# <B>#tl_frame_counter</B>
* -# <B>#tl_no_of_pdu</B>
* -# <B>#tl_slaveresp_cnt</B>
* -# <B>#tl_check_timeout_type</B>
* -# <B>#tl_check_timeout</B>
* -# <B>#tl_service_status</B>
*
* @details
* This call will initialize or reinitalize the raw and cooked layers
* on the interface iii.
* All the transport layer buffers will be initialized.
*//*END*----------------------------------------------------------------------*/
void ld_init(void);
/** @} */
/* RAW APIs */
/** @addtogroup raw_api_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_put_raw (const l_u8* const data)
* @brief The call queues the transmisson of 8 bytes of data in one frame
*
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @SDD_ID LIN_SDD_342
* @endif
*
* @details
* The call queues the transmisson of 8 bytes of data in one frame
* The data is sent in the next suitable frame.
*
* @see #tl_put_raw
*//*END*----------------------------------------------------------------------*/
void ld_put_raw(const l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_get_raw (l_u8* const data)
* @brief The call copies the oldest received diagnostic frame data to the memory
* specified by data
*
* @param data <B>[IN]</B> buffer for store data received
*
* @return #void
*
* @SDD_ID LIN_SDD_343
* @endif
*
* @details
* The call copies the oldest received diagnostic frame data to the memory
* specified by data.
* The data returned is received from master request frame for slave node
* and the slave response frame for master node.
* @see #tl_get_raw
*//*END*----------------------------------------------------------------------*/
void ld_get_raw(l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_raw_tx_status (void)
* @brief The call returns the status of the raw frame transmission function
*
* @return #void
*
* @SDD_ID LIN_SDD_344
* @endif
*
* @static_global_var
* -# <B>#lin_tl_tx_queue</B>
*
* @details
* The call returns the status of the raw frame transmission function:<br/>
* LD_QUEUE_EMPTY : The transmit queue is empty. In case previous calls to <br/>
* ld_put_raw, all frames in the queue have been <br/>
* trans-mitted. <br/>
* LD_QUEUE_AVAILABLE: The transmit queue contains entries, but is not full. <br/>
* LD_QUEUE_FULL : The transmit queue is full and can not accept further <br/>
* frames. <br/>
* LD_TRANSMIT_ERROR : LIN protocol errors occurred during the transfer; <br/>
* ini-tialize and redo the transfer.
*//*END*----------------------------------------------------------------------*/
l_u8 ld_raw_tx_status(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_raw_rx_status (void)
* @brief The call returns the status of the raw frame receive function
*
* @return #void
*
* @SDD_ID LIN_SDD_345
* @endif
*
* @static_global_var
* -# <B>#lin_tl_rx_queue</B>
*
* @details
* The call returns the status of the raw frame receive function:
* LD_NO_DATA The receive queue is empty.
* LD_DATA_AVAILABLE The receive queue contains data that can be read.
* LD_RECEIVE_ERROR LIN protocol errors occurred during the transfer;
* ini-tialize and redo the transfer.
*//*END*----------------------------------------------------------------------*/
l_u8 ld_raw_rx_status(void);
/** @} */
/* COOKED APIs */
/** @addtogroup cooked_api_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_send_message (l_u16 length, const l_u8* const data)
* @brief The call packs the information specified by data and length into one or multiple diagnostic frames
*
* @param length <B>[IN]</B> length of data to send
* @param data <B>[IN]</B> data to be sent
*
* @return #void
*
* @SDD_ID LIN_SDD_346
* @endif
*
* @local_var
* -# <B>#lin_tl_pdu_data</B> <I>pdu</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u8</B> <I>message_size</I>
* -# <B>#l_u16</B> <I>data_index</I>
* -# <B>#l_u16</B> <I>tmp_length</I>
* -# <B>#l_u16</B> <I>frame_counter</I>
*
* @static_global_var
* -# <B>#tl_tx_msg_status</B>
* -# <B>#tl_slaveresp_cnt</B>
* -# <B>#lin_tl_tx_queue</B>
* -# <B>#tl_tx_msg_index</B>
* -# <B>#tl_tx_msg_size</B>
* -# <B>#tl_tx_msg_status</B>
* -# <B>#lin_configured_NAD</B>
* -# <B>#tl_check_timeout</B>
* -# <B>#tl_check_timeout_type</B>
*
* @details
* The call packs the information specified by data and length into one or multiple
* diagnostic frames. If the call is made in a master node application the frames
* are transmitted to the slave node with the address NAD. If the call is made in
* a slave node application the frames are transmitted to the master node with the
* address NAD. The parameter NAD is not used in slave nodes.
*
* @see #ld_put_raw
*//*END*----------------------------------------------------------------------*/
void ld_send_message(l_u16 length, const l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_receive_message (l_u16 *const length, l_u8 *const data)
* @brief The call prepares the LIN diagnostic module to receive one message and store it in the buffer pointed to by data
*
* @param length <B>[OUT]</B> length of data to receive
* @param data <B>[OUT]</B> data to be sent
*
* @return #void
*
* @SDD_ID LIN_SDD_347
* @endif
*
* @local_var
* -# <B>#lin_tl_pdu_data</B> <I>pdu</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#l_u16</B> <I>data_index = 0</I>
* -# <B>#l_u16</B> <I>tmp_length</I>
* -# <B>#l_u16</B> <I>frame_counter</I>
* -# <B>#l_u8</B> <I>PCI_type</I>
*
* @static_global_var
* -# <B>#tl_rx_msg_status</B>
* -# <B>#tl_receive_msg_status</B>
*
* @details
* The call prepares the LIN diagnostic module to receive one message and store it in
* the buffer pointed to by data. At the call, length shall specify the maximum length
* allowed. When the reception has completed, length is changed to the actual length
* and NAD to the NAD in the message.
*
* @see #ld_get_raw
*//*END*----------------------------------------------------------------------*/
void ld_receive_message(l_u16* const length, l_u8* const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_tx_status ()
* @brief The call returns the status of the last made call to ld_send_message.
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_348
* @endif
*
* @static_global_var
* -# <B>#tl_tx_msg_status</B>
*
* @details
* The call returns the status of the last made call to ld_send_message.
* The following values can be returned:
* LD_IN_PROGRESS: The transmission is not yet completed.
* LD_COMPLETED: The transmission has completed successfully (and
* you can issue a new ld_send_message call). This
* value is also returned after initialization of
* the transport layer.
* LD_FAILED: The transmission ended in an error. The data was
* only partially sent. The transport layer shall
* be reinitialized before processing further messages.
* To find out why a transmission has failed, check
* the status management function l_read_status
* LD_N_AS_TIMEOUT: The transmission failed because of a N_As timeout,
*//*END*----------------------------------------------------------------------*/
l_u8 ld_tx_status(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_rx_status (void)
* @brief The call returns the status of the last made call to ld_send_message.
*
* @return #void
*
* @SDD_ID LIN_SDD_349
* @endif
*
* @static_global_var
* -# <B>#tl_rx_msg_status</B>
*
* @details
* The call returns the status of the last made call to ld_receive_message. <br/>
* The following values can be returned: <br/>
* LD_IN_PROGRESS: The reception is not yet completed. <br/>
* LD_COMPLETED: The reception has completed successfully and all <br/>
* information (length, NAD, data) is available. (You can <br/>
* also issue a new ld_receive_message call). This <br/>
* value is also returned after initialization of the <br/>
* transport layer. <br/>
* LD_FAILED: The reception ended in an error. The data was only <br/>
* partially received and should not be trusted. Initialize <br/>
* before processing further transport layer messages. <br/>
* To find out why a reception has failed, check the status <br/>
* management function l_read_status. <br/>
* LD_N_CR_TIMEOUT The reception failed because of a N_Cr timeout <br/>
* LD_WRONG_SN The reception failed because of an unexpected sequence number.
*//*END*----------------------------------------------------------------------*/
l_u8 ld_rx_status(void);
/** @} */
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_read_configuration()
* @brief This function to copy current configuration in a reserved area
*
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_xxx
* @endif
* @param data <B>[IN]</B> data area to save configuration,
* @param length <B>[IN]</B> length of data arean (1+n, NAD+PIDs)
*
* @local_var
* -# <B>#i</B> <I>l_u8</I>
* -# <B>#temp</B> <I>l_u8</I>
* -# <B>#retval</B> <I>l_u8</I>
* -# <B>#expected_length</B> <I>l_u8</I>
*
* @static_global_var
* -# <B>#lin_configured_NAD</B>
* -# <B>#lin_configuration_RAM</B>
*
* @details
* This function is implemented Slave Only
*//*END*----------------------------------------------------------------------*/
l_u8 ld_read_configuration(l_u8* const data, l_u8* const length);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_set_configuration()
* @brief This function function to configure slave node according to data
*
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_xxx
* @endif
*
* @param data <B>[IN]</B> structure containing the NAD and all the n PIDs for the frames of the specified NAD,
* @param length <B>[IN]</B> length of data arean (1+n, NAD+PIDs)
*
* @local_var
* -# <B>#i</B> <I>l_u8</I>
* -# <B>#retval</B> <I>l_u8</I>
* -# <B>#expected_length</B> <I>l_u8</I>
*
* @static_global_var
* -# <B>#lin_configured_NAD</B>
* -# <B>#lin_configuration_RAM</B>
*
* @details
* This function is implemented Slave Only
*//*END*----------------------------------------------------------------------*/
l_u8 ld_set_configuration(const l_u8* const data, l_u16 length);
#endif /* End (_LIN_GPIO_ == 0) && !defined(_MC9S08SC4_H) */
#endif /* End LIN_MODE == _SLAVE_MODE_ */
#endif /* _LIN_COMMONTL_API_H */

View File

@ -0,0 +1,576 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup transport_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_commontl_proto.h
*
* @author FPT Software
*
* @brief Common Handle LIN transport layer and configuration functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
* 20111005 v1.1 Added extern functions
*
*****************************************************************************/
#ifndef _LIN_COMMONTL_PROTO_H
#define _LIN_COMMONTL_PROTO_H
#include "lin.h"
/* define PCI type */
#define PCI_SF 0x00 /**< Single Frame */
#define PCI_FF 0x01 /**< First Frame */
#define PCI_CF 0x02 /**< Consecutive Frame */
/* For J2602 */
#define SERVICE_TARGET_RESET 0xB5 /**< target reset service */
#define RES_POSITIVE 0x40 /**< positive response */
/* For negative response */
#define RES_NEGATIVE 0x7F /**< negative response */
#define GENERAL_REJECT 0x10 /**< Error code raised when request for service not supported comes */
#define SERVICE_NOT_SUPPORTED 0x11 /**< Error code in negative response for not supported service */
#define SUBFUNCTION_NOT_SUPPORTED 0x12 /**< Error code in negative response for not supported subfunction */
/* Response type from Slave */
#define NEGATIVE 0 /**< negative response */
#define POSITIVE 1 /**< positive response */
/* multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* Transmission direction */
#define TRANSMISSION 0 /**< transmission */
#define RECEIVING 1 /**< receiveing */
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/* Define wildcards */
#define LD_BROADCAST 0x7F /**< NAD */
#define LD_FUNCTIONAL_NAD 0x7E /**< functional NAD */
#define LD_ANY_SUPPLIER 0x7FFF /**< Supplier */
#define LD_ANY_FUNCTION 0xFFFF /**< Function */
#define LD_ANY_MESSAGE 0xFFFF /**< Message */
/* Identifiers of node read by identifier service */
#define LIN_PRODUCT_IDENT 0x00 /**< Node product identifier */
#define SERIAL_NUMBER 0x01 /**< Serial number */
#if LIN_MODE == _SLAVE_MODE_
/* Unuse for GPIO */
#if (_LIN_GPIO_ == 0) && !defined(_MC9S08SC4_H)
extern l_u8 ld_read_by_id_callout(l_u8 id, l_u8 *data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_make_slaveres_pdu (l_u8 sid, l_u8 res_type, l_u8 error_code)
* @brief This function is implemented for Slave only
*
* @param sid <B>[IN]</B> service identifier
* @param res_type <B>[IN]</B> type of response
* @param error_code <B>[IN]</B> Error code in case of negative response, if positive = 0
*
* @return #void
*
* @SDD_ID LIN_SDD_350
* @endif
*
* @static_global_var
* -# <B>#tx_single_pdu_data</B>
* -# <B>#tl_current_tx_pdu_ptr</B>
* -# <B>#product_id</B>
* -# <B>#tl_pdu_frame_mode</B>
* -# <B>#tl_slaveresp_cnt</B>
* @details
* This function is implemented for Slave only
*//*END*----------------------------------------------------------------------*/
void lin_tl_make_slaveres_pdu(l_u8 sid, l_u8 res_type, l_u8 error_code);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_attach_service()
* @brief This function make a connection to Diag service class that support for LIN function
*
*
* @return #void
*
* @SDD_ID LIN_SDD_355
* @endif
*
* @local_var
* -# <B>#sci</B> <I>l_u8</I>
*
* @static_global_var
* -# <B>#tl_current_rx_pdu_ptr</B>
*
* @see lin_tl_make_slaveres_pdu
*
* @details
* This function make a connection to Diag service class that support for LIN function
* This function is implemented for Slave only
*//*END*----------------------------------------------------------------------*/
void lin_tl_attach_service(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_get_pdu()
* @brief This function copy the current PDU to Response Buffer in Low-level
*
*
* @return #void
*
* @SDD_ID LIN_SDD_351
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
*
* @static_global_var
* -# <B>#lin_lld_response_buffer[9]</B>
* -# <B>#tl_current_tx_pdu_ptr</B>
*
* @details
* This function copy the current PDU to Response Buffer in Low-level
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_get_pdu(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_put_pdu()
* @brief This function put response buffer (in Low-level ) to PDU data on the Transport Layer
*
*
* @return #void
*
* @SDD_ID LIN_SDD_352
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
*
* @static_global_var
* -# <B>#lin_lld_response_buffer</B>
* -# <B>#tl_current_rx_pdu_ptr</B>
* -# <B>#rx_single_pdu_data</B>
*
* @details
* This function put response buffer (in Low-level ) to PDU data on the Transport Layer
* Call in callback function
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_put_pdu(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_handler()
* @brief This function handles the diag service and control event and data in Transport Layer
*
*
* @return #void
*
* @SDD_ID LIN_SDD_353
* @endif
*
* @local_var
* -# <B>#pci_type</B> <I>l_u8</I>
* -# <B>#length</B> <I>l_u8</I>
*
* @static_global_var
* -# <B>#lin_initial_NAD[9]</B>
* -# <B>#tl_current_rx_pdu_ptr</B>
* -# <B>#lin_configured_NAD</B>
* -# <B>#lin_tl_attach_service</B>
*
* @details
* This function handles the diag service and control event and data in TL
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_handler(void);
#endif /* End (_LIN_GPIO_ == 0) && !defined(_MC9S08SC4_H) */
#endif /* End (LIN_MODE == _SLAVE_MODE_)*/
#if LIN_MODE == _MASTER_MODE_
extern l_u8 ld_read_by_id_callout(l_ifc_handle iii, l_u8 id, l_u8 *data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_make_mreq_pdu(l_ifc_handle iii)
* @brief This function will be called on Master Task in LIN protocol, it create a pointer to PDU data
*
* @param iii <B>[IN]</B> interface name
* @return #void
*
* @SDD_ID LIN_SDD_308
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
*
* @static_global_var
* -# <B>#tl_current_rx_pdu_ptr</B>
*
* @see lin_tl_make_slaveres_pdu
*
* @details
* This function will be called on Master Task in LIN protocol, it create a pointer to PDU data
* which available for Master request commmand, correspond to Diag frame to send
* This function is implemented for Master
*//*END*----------------------------------------------------------------------*/
/* multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
void lin_tl_make_mreq_pdu(l_ifc_handle iii);
#else /*Single frame support */
void lin_tl_make_mreq_pdu(l_ifc_handle iii,lin_tl_pdu_data *pdu_ptr);
#endif /*End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_get_response(l_ifc_handle iii)
* @brief This function check result of service, it is called when the Slave Response Frame received
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_315
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
* -# <B>#l_u8</B> <I>sci</I>*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
*
* @details
* This function check result of service, it is called when the Slave Response Frame received
* This function is implemented for Master only
*//*END*----------------------------------------------------------------------*/
void lin_tl_get_response(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_make_slaveres_pdu(l_ifc_handle iii, l_u8 sid, l_u8 res_type, l_u8 error_code)
* @brief This function is implemented for Slave only
*
* @param iii <B>[IN]</B> interface name
* @param sid <B>[IN]</B> service identifier
* @param res_type <B>[IN]</B> type of response
* @param error_code <B>[IN]</B> Error code in case of negative response, if positive = 0
*
* @return #void
*
* @SDD_ID LIN_SDD_309
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>lin_tl_pdu</I>
* -# <B>#lin_node_attribute</B> <I>node_conf</I>
* -# <B>#lin_product_id</B> <I>ident</I>
* -# <B>#l_u8</B> <I>i</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
*
* @details
* This function is implemented for Slave only
*//*END*----------------------------------------------------------------------*/
void lin_tl_make_slaveres_pdu(l_ifc_handle iii, l_u8 sid, l_u8 res_type, l_u8 error_code);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_attach_service(l_ifc_handle iii)
* @brief This function make a connection to Diag service class that support for LIN function
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_314
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>*tl_queue</I>
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
* -# <B>#l_u8</B> <I>sci</I>*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
*
* @details
* This function make a connection to Diag service class that support for LIN function
* This function is implemented for Slave only
*//*END*----------------------------------------------------------------------*/
void lin_tl_attach_service(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_get_pdu(l_ifc_handle iii)
* @brief This function copy the current PDU to Response Buffer in Low-level
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_311
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>lin_tl_pdu</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @see tl_get_raw
* @details
* This function copy the current PDU to Response Buffer in Low-level
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_get_pdu(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_handler(l_ifc_handle iii)
* @brief This function handles the diag service and control event and data in TL
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_313
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>pci_type</I>
* -# <B>#l_u8</B> <I>length</I>
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
* -# <B>#lin_node_attribute</B> <I>*node_conf</I>
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @see lin_process_pdu
*
* @details
* This function handles the diag service and control event and data in TL
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_handler(l_ifc_handle iii);
/* multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_handler_error(l_ifc_handle iii, l_u8 pid)
* @brief This function handles the diag service and control error in TL
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_328
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
*
* @details
* This function handles the diag service and control error in TL
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_handler_error(l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void tl_process_mreq(l_ifc_handle iii)
* @brief This function is process transport layer
* @param iii <B>[IN]</B> interface name
* @return #void
*
* @SDD_ID LIN_SDD_326
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#lin_transport_layer_queue</B> <I>tl_queue</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @see lin_tl_make_slaveres_pdu
*
* @details
* This function is process transport layer
*//*END*----------------------------------------------------------------------*/
void tl_process_mreq(l_ifc_handle iii);
#else /* Single frame support */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_no_response(l_ifc_handle iii)
* @brief set the result of service
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_316
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function set the result of service, it is called when the master has no Slave Response Frame. <br />
* This function is implemented for Master only
*//*END*----------------------------------------------------------------------*/
void lin_tl_no_response(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_update_tx_flag(l_ifc_handle iii)
* @brief update flags related to Diag frame when received and transmited successful
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_310
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function update flags related to Diag frame when received and transmited successful. <br />
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_update_tx_flag(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_tl_put_pdu(l_ifc_handle iii)
* @brief put response buffer (in Low-level ) to PDU data on the Transport Layer
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_312
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function put response buffer (in Low-level ) to PDU data on the Transport Layer
* Call in callback function
* This function is implemented for Slave and Master
*//*END*----------------------------------------------------------------------*/
void lin_tl_put_pdu(l_ifc_handle iii);
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)*/
#endif /* End (LIN_MODE == _MASTER_MODE_)*/
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* COMMON FUNCTIONS */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void tl_put_raw(const l_u8* const data, lin_transport_layer_queue *queue, l_u8 direction)
* @brief The call copies the raw data specified by data to the queue specified by queue.
*
* @param data <B>[IN]</B> buffer for the data
* @param *queue queue for containing data
* @param direction Direction
*
* @return #void
*
* @SDD_ID LIN_SDD_303
* @endif
*
* @local_var
* -# <B>#lin_tl_pdu_data</B> <I>*queue_data</I>
* -# <B>#l_u8</B> <I>i</I>
*
* @static_global_var
*
* @details
* The call copies the raw data specified by data to the queue specified by queue.
*//*END*----------------------------------------------------------------------*/
void tl_put_raw(const l_u8* const data,lin_transport_layer_queue *queue,l_u8 direction);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void tl_get_raw(l_u8* const data, lin_transport_layer_queue *queue, l_u8 direction)
* @brief
* The call gets the raw data from the queue specified by queue to
* the raw data specified by data
* specified by queue.
*
* @param data <B>[OUT]</B> buffer for store data received
* @param *queue queue for containing data
* @param direction Direction for transmission
*
* @return #void
*
* @SDD_ID LIN_SDD_304
* @endif
*
* @local_var
* -# <B>#lin_transport_layer_queue</B> <I>*tl_queue</I>
* -# <B>#lin_tl_pdu_data</B> <I>*queue_data</I>
* -# <B>#l_u8</B> <I>i</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
*
* @details
* The call gets the raw data from the queue specified by queue to
* the raw data specified by data
* specified by queue.
*//*END*----------------------------------------------------------------------*/
void tl_get_raw(l_u8* const data,lin_transport_layer_queue *queue,l_u8 direction);
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
#endif /* end of_LIN_COMMONTL_PROTO_H */
/** @} */

View File

@ -0,0 +1,293 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup diagnostic_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_diagnostic_service.h
*
* @author FPT Software
*
* @brief diagnostic service
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
*
*****************************************************************************/
#ifndef _LIN_DIAGNOSTIC_SERVICE_H
#define _LIN_DIAGNOSTIC_SERVICE_H
#include "lin.h"
#if LIN_MODE == _SLAVE_MODE_
/* Unuse for GPIO */
#if (_LIN_GPIO_ == 0) && !defined(_MC9S08SC4_H)&& !defined(MCU_SKEAZN84)
#if LIN_PROTOCOL == PROTOCOL_21
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_diagservice_assign_frame_id_range ( void )
* @brief process assign frame id range request, and also prepare its response data
*
*
* @return #void
*
* @SDD_ID LIN_SDD_359
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>start_index</I>
* -# <B>#l_s8</B> <I>i</I>
* -# <B>#l_s8</B> <I>j</I>
*
* @static_global_var
* -# <B>#tl_current_rx_pdu_ptr</B>
* -# <B>#lin_configuration_RAM</B>
*
* @details
* This function to process assign frame id range request, and also prepare its response data.
* This function is only for Slave Node.
* Required: Mandatory.
* For LIN 2.1
*
* @see #lin_tl_make_slaveres_pdu
* @see #lin_process_parity
*//*END*----------------------------------------------------------------------*/
void lin_diagservice_assign_frame_id();
void lin_diagservice_assign_frame_id_range(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_diagservice_read_by_identifier ( void )
* @brief process read by identifier request, and also prepare its response data
*
*
* @return #void
*
* @SDD_ID LIN_SDD_360
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>id</I>
* -# <B>#l_u16</B> <I>supid</I>
* -# <B>#l_u16</B> <I>fid</I>
*
* @static_global_var
* -# <B>#tl_current_rx_pdu_ptr</B>
* -# <B>#product_id</B>
* -# <B>#tl_slaveresp_cnt</B>
*
* @details
* This function to process read by identifier request, and also prepare its response data<BR>
* This function is only for Slave Node<BR>
* Required: Mandatory<BR>
* For LIN 2.1 and 2.0 <BR>
*
* @see #lin_tl_make_slaveres_pdu
*//*END*----------------------------------------------------------------------*/
void lin_diagservice_read_by_identifier(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_diagsrv_functional_service ( void )
* @brief process functional request
*
*
* @return #void
*
* @SDD_ID LIN_SDD_
* @endif
*
* @local_var
* -# <B>#l_u16</B> <I>length</I>
* -# <B>#l_u8</B> <I>data[]</I>
*
* @static_global_var
*
* @details
* This function to process functional request. Slave do not response when receive a functional request
* @see #ld_receive_message
*//*END*----------------------------------------------------------------------*/
void lin_diagsrv_functional_service(void);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_condittional_change_nad ( void )
* @brief process functional request
*
*
* @return #void
*
* @SDD_ID LIN_SDD_
* @endif
*
* @local_var
* -# <B>#l_u16</B> <I>length</I>
* -# <B>#l_u8</B> <I>data[]</I>
*
* @static_global_var
*
* @details
* This function to process functional request. Slave do not response when receive a functional request
* @see #ld_receive_message
*//*END*----------------------------------------------------------------------*/
void lin_condittional_change_nad(void);
#endif /* End (LIN_PROTOCOL == PROTOCOL_21) */
#if LIN_PROTOCOL == PROTOCOL_J2602
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_diagservice_target_reset ( void )
* @brief process read by identifier request, and also prepare its response data
*
*
* @return #void
*
* @SDD_ID LIN_SDD_361
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>*signal_data_ptr</I>
* -# <B>#l_u8</B> <I>nad</I>
*
* @static_global_var
* -# <B>#tl_current_rx_pdu_ptr</B>
* -# <B>#tl_slaveresp_cnt</B>
*
* @details
* This function to process read by identifier request, and also prepare its response data<BR>
* and Reset the Slave Node <BR>
* This function is only for Slave Node<BR>
* Required: Mandatory<BR>
* For J2602
*
* @see #lin_tl_make_slaveres_pdu
*//*END*----------------------------------------------------------------------*/
void lin_diagservice_target_reset(void);
#endif /* End (LIN_PROTOCOL == PROTOCOL_J2602) */
#endif /* End (_LIN_GPIO_ == 0) && !defined(_MC9S08SC4_H) */
#endif /* LIN_MODE == _SLAVE_MODE_ */
#if LIN_MODE == _MASTER_MODE_
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_diagservice_assign_frame_id_range ( l_ifc_handle iii )
* @brief process assign frame id range request, and also prepare its response data
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_356
* @endif
*
* @local_var
* -# <B>#const lin_configuration</B> <I>conf</I>
* -# <B>#lin_tl_descriptor</B> <I>tl_conf</I>
* -# <B>#l_s8</B> <I>i</I>
* -# <B>#l_s8</B> <I>j</I>
* -# <B>#l_u8</B> <I>start_index</I>
* -# <B>#l_u8</B> <I>cfg_frame_num</I>
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function to process assign frame id range request, and also prepare its response data
* This function is only for Slave Node
* Required: Mandatory
* For LIN 2.1
*
* @see #lin_tl_make_slaveres_pdu
* @see #lin_process_parity
*//*END*----------------------------------------------------------------------*/
void lin_diagservice_assign_frame_id_range(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_diagservice_read_by_identifier ( l_ifc_handle iii )
* @brief process assign frame id range request, and also prepare its response data
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_357
* @endif
*
* @local_var
* -# <B>#const lin_configuration</B> <I>*conf</I>
* -# <B>#const lin_node_attribute</B> <I>*node_conf</I>
* -# <B>#lin_product_id</B> <I>node_conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
* -# <B>#l_u8</B> <I>id</I>
* -# <B>#l_u16</B> <I>supid</I>
* -# <B>#l_u16</B> <I>fid</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function to process read by identifier request, and also prepare its response data
* This function is only for Slave Node
* Required: Mandatory
* For LIN 2.1 and 2.0
*
* @see #lin_tl_make_slaveres_pdu
*//*END*----------------------------------------------------------------------*/
void lin_diagservice_read_by_identifier(l_ifc_handle iii);
/* J2602 */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_diagservice_target_reset ( l_ifc_handle iii )
* @brief process read by identifier request, and also prepare its response data
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_358
* @endif
*
* @local_var
* -# <B>#const lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor1</B> <I>*tl_conf</I>
* -# <B>#lin_tl_pdu_data</B> <I>*pdu</I>
* -# <B>#l_u8</B> <I>*signal_data_ptr</I>
* -# <B>#l_u8</B> <I>*nad</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* -# <B>#lin_tl_pdu</B>
*
* @details
* This function to process read by identifier request, and also prepare its response data
* and Reset the Slave Node
* This function is only for Slave Node
* Required: Mandatory
* For J2602
*
* @see #lin_tl_make_slaveres_pdu
*//*END*----------------------------------------------------------------------*/
void lin_diagservice_target_reset(l_ifc_handle iii);
/*!
* @brief Process Conditional Change NAD request
*
* @param iii Interface name
* @return void
*/
void lin_condittional_change_nad(l_ifc_handle iii);
#endif /* End (LIN_MODE == _MASTER_MODE_) */
#endif /* _LIN_DIAGNOSTIC_SERVICE_H */
/* End of definition if _LIN_DIAGNOSTIC_SERVICE_H */
/** @} */

View File

@ -0,0 +1,72 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup J2602_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_j2602_api.h
*
* @author FPT Software
*
* @brief J2602 LIN core API functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
*
*****************************************************************************/
#ifndef _LIN_J2602_API_H
#define _LIN_J2602_API_H
#include "lin.h"
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_bool l_ifc_connect (l_ifc_handle iii)
* @brief Connect the interface iii to the LIN cluster and enable the transmission
*
* @param iii <B>[IN]</B> interface name
*
* @return #l_bool
*
* @SDD_ID LIN_SDD_260
* @endif
*
* @details
* Connect the interface iii to the LIN cluster and enable the transmission
* of headers and data to the bus. (For J2602 and LIN 2.0 only)
*
*//*END*----------------------------------------------------------------------*/
l_bool l_ifc_connect (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_bool l_ifc_disconnect (l_ifc_handle iii)
* @brief Disconnect the interface iii from the LIN cluster and thus disable the
* interaction with the other nodes in the cluster.
*
* @param iii <B>[IN]</B> interface name
*
* @return #l_bool
*
* @SDD_ID LIN_SDD_261
* @endif
*
* @details
* Disconnect the interface iii from the LIN cluster and thus disable the
* interaction with the other nodes in the cluster. (For J2602 and LIN 2.0 only)
*
*//*END*----------------------------------------------------------------------*/
l_bool l_ifc_disconnect (l_ifc_handle iii);
#endif /* _LIN_J2602_API_H */
/** @} */

View File

@ -0,0 +1,144 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup J2602_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_j2602_proto.h
*
* @author FPT Software
*
* @brief J2602 LIN protocol functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
*
*****************************************************************************/
#ifndef _LIN_J2602_PROTO_H
#define _LIN_J2602_PROTO_H
#include "lin.h"
#if LIN_MODE == _MASTER_MODE_
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_word_status_j2602 (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid)
* @brief Update date word status
*
* @param iii <B>[IN]</B> interface name
* @param event_id <B>[IN]</B> event id
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_285
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>err_in_res</I>
* -# <B>#l_u8</B> <I>suc_in_tras</I>
* -# <B>#lin_word_status_str</B> <I>*word_status</I>
* -# <B>#lin_configuration</B> <I>const *conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Update date word status
*
*//*END*----------------------------------------------------------------------*/
void lin_update_word_status_j2602 (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_status_byte (l_ifc_handle iii, lin_lld_event_id event_id)
* @brief The function is to perform the update of error signal in J2602 system
*
* @param iii <B>[IN]</B> interface name
* @param event_id <B>[IN]</B> event id
*
* @return #void
*
* @SDD_ID LIN_SDD_284
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>*signal_data_ptr</I>
* -# <B>#lin_configuration</B> <I>const *conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The function is to perform the update of error signal in J2602 system
*
*//*END*----------------------------------------------------------------------*/
void lin_update_status_byte (l_ifc_handle iii, lin_lld_event_id event_id);
#endif /* End (LIN_MODE == _MASTER_MODE_) */
/* ---------------------------- For 1 interface -----------------------------------*/
#if LIN_MODE == _SLAVE_MODE_
#if LIN_PROTOCOL != PROTOCOL_21
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_word_status_j2602 (lin_lld_event_id event_id, l_u8 pid)
* @brief Update date word status
*
* @param event_id <B>[IN]</B> event id
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_301
* @endif
*
* @static_global_var
* -# <B>#lin_word_status</B>
* -# <B>#lin_error_in_response</B>
* -# <B>#lin_successful_transfer</B>
*
* @details
* Update date word status
*
*//*END*----------------------------------------------------------------------*/
void lin_update_word_status_j2602 (lin_lld_event_id event_id, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_status_byte (lin_lld_event_id event_id)
* @brief The function is to perform the update of error signal in J2602 system
*
* @param event_id <B>[IN]</B> event id
*
* @return #void
*
* @SDD_ID LIN_SDD_302
* @endif
*
* @local_var
* -# <B>#l_u8</B> <I>*signal_data_ptr</I>
*
* @static_global_var
* -# <B>#response_error</B>
* @details
* The function is to perform the update of error signal in J2602 system
*
*//*END*----------------------------------------------------------------------*/
void lin_update_status_byte (lin_lld_event_id event_id);
#endif /* End (LIN_PROTOCOL != PROTOCOL_21) */
#endif /* End (LIN_MODE == _SLAVE_MODE_) */
#endif /* _LIN_J2602_PROTO_H */
/** @} */

View File

@ -0,0 +1,122 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup j2602tl_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_j2602tl_api.h
*
* @author FPT Software
*
* @brief J2602 LIN transport layer and configuration functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
*
*****************************************************************************/
/** @} */
#ifndef _LIN_J2602TL_API_H
#define _LIN_J2602TL_API_H
#include "lin.h"
#if LIN_MODE == _MASTER_MODE_
#if LIN_PROTOCOL == PROTOCOL_J2602
/** @addtogroup j2602tl_api_group
* @{ */
/* API functions */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_bool ld_is_ready(l_ifc_handle iii)
* @brief Verifies a state of node setting (using for J2602)
*
* @param iii <B>[IN]</B> lin interface handle
*
* @return #l_bool
*
* @SDD_ID LIN_SDD_338
* @endif
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Verifies a state of node setting (using for J2602)
*//*END*----------------------------------------------------------------------*/
l_bool ld_is_ready (l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_check_response(l_ifc_handle iii, l_u8* const RSID, l_u8* const error_code)
* @brief Verifies the state of response (using for J2602)
*
* @param iii <B>[IN]</B> lin interface handle
* @param RSID <B>[OUT]</B> buffer for saving the response ID
* @param error_code <B>[OUT]</B> buffer for saving the error code
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_339
* @endif
*
* @local_var
* -# <B>#lin_last_cfg_result</B> <I>temp</I>
* -# <B>#lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Verifies the state of response (using for J2602)
*//*END*----------------------------------------------------------------------*/
l_u8 ld_check_response (l_ifc_handle iii, l_u8* const RSID, l_u8* const error_code);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_assign_frame_id(l_ifc_handle iii, l_u8 initial_NAD, l_u16 supplier_id, l_u16 message_id, l_u8 PID)
* @brief
* This call assigns the protected identifier of a frame in the slave node
* with the address NAD and the specified supplier ID (using for J2602)
*
* @param iii <B>[IN]</B> lin interface handle
* @param initial_NAD <B>[IN]</B> initial node address of the target node
* @param supplier_id <B>[IN]</B> supplier ID of the target node
* @param message_id <B>[IN]</B> message ID of the target node
* @param PID <B>[IN]</B> protected ID of the target node
*
* @return #void
*
* @SDD_ID LIN_SDD_340
* @endif
*
* @local_var
* -# <B>#lin_tl_pdu_data</B> <I>*lin_tl_pdu</I>
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#lin_tl_descriptor</B> <I>*tl_conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This call assigns the protected identifier of a frame in the slave node
* with the address NAD and the specified supplier ID (using for J2602)
*//*END*----------------------------------------------------------------------*/
void ld_assign_frame_id (l_ifc_handle iii, l_u8 initial_NAD, l_u16 supplier_id, l_u16 message_id, l_u8 PID);
/** @} */
#endif /* End (LIN_PROTOCOL == PROTOCOL_J2602) */
#endif /* End (LIN_MODE == _MASTER_MODE_) */
#endif /* _LIN_J2602TL_API_H */

View File

@ -0,0 +1,35 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup LIN21_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_lin21_api.h
*
* @author FPT Software
*
* @brief Common LIN 2.1 API functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090407 v1.0 First version
*
*****************************************************************************/
#ifndef _LIN_LIN21_API_H
#define _LIN_LIN21_API_H
#include "lin.h"
#endif /* _LIN_LIN21_API_H */
/** @} */

View File

@ -0,0 +1,247 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup LIN21_core_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_lin21_proto.h
*
* @author FPT Software
*
* @brief Common LIN 2.1 protocol functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
*
*****************************************************************************/
#ifndef _LIN_LIN21_PROTO_H
#define _LIN_LIN21_PROTO_H
#include "lin.h"
#if LIN_MODE == _MASTER_MODE_
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_collision_resolve (l_ifc_handle iii, l_u8 pid)
* @brief Switch to collision resolve table
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_279
* @endif
*
* @local_var
* -# <B>#lin_associate_frame_struct</B> <I>*ptr</I>
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Switch to collision resolve table
*
* @see #lin_get_frame_index
*//*END*----------------------------------------------------------------------*/
void lin_collision_resolve (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_word_status_lin21 (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid)
* @brief Update date word status
*
* @param iii <B>[IN]</B> interface name
* @param event_id <B>[IN]</B> event id
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_280
* @endif
*
* @local_var
* -# <B>#l_bool</B> <I>pid_found</I>
*
* @static_global_var
* -# <B>#lin_successful_transfer</B>
* -# <B>#lin_frame_tbl</B>
* -# <B>#lin_flag_frame_handle_tbl</B>
*
* @details
* Update date word status
*
* @see #lin_process_uncd_frame
* @see #lin_update_rx_diag_frame
* @see #lin_update_word_status_lin21
* @see #lin_update_word_status_j2602
*//*END*----------------------------------------------------------------------*/
void lin_update_word_status_lin21 (l_ifc_handle iii, lin_lld_event_id event_id, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_err_signal (l_ifc_handle iii)
* @brief Update error signal
*
* @param iii <B>[IN]</B> interface name
*
* @return #void
*
* @SDD_ID LIN_SDD_281
* @endif
*
* @local_var
* -# <B>#const lin_configuration</B> <I>*conf</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Update error signal
*
*//*END*----------------------------------------------------------------------*/
void lin_update_err_signal (l_ifc_handle iii, l_u8 frm_id);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_rx_evnt_frame (l_ifc_handle iii, l_u8 pid)
* @brief The function is to update the receive flags associated with signals/frames
* in case receive an event trigger frame.
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_282
* @endif
*
* @local_var
* -# <B>#lin_associate_frame_struct</B> <I>*ptr</I>
* -# <B>#const lin_configuration</B> <I>*conf</I>
* -# <B>#l_u8</B> <I>frame_index</I>
* -# <B>#l_u8</B> <I>ass_pid</I>
* -# <B>#l_u8</B> <I>i</I>
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* The function is to update the receive flags associated with signals/frames
* in case receive an event trigger frame.
*
* @see #lin_get_frame_index
* @see #lin_process_parity
* @see #lin_process_uncd_frame
*//*END*----------------------------------------------------------------------*/
void lin_update_rx_evnt_frame (l_ifc_handle iii, l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_make_res_evnt_frame (l_ifc_handle iii, l_u8 pid)
* @brief This function is to pack signals associated with event trigger frame into buffer
*
* @param iii <B>[IN]</B> interface name
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_278
* @endif
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This function is to pack signals associated with event trigger frame into buffer
*
* @see #lin_process_uncd_frame
* @see #lin_process_parity
*//*END*----------------------------------------------------------------------*/
void lin_make_res_evnt_frame (l_ifc_handle iii, l_u8 pid);
#endif /* End (LIN_MODE == _MASTER_MODE_) */
/* ---------------------------- For 1 interface -----------------------------------*/
#if LIN_MODE == _SLAVE_MODE_
#if ((LIN_PROTOCOL == PROTOCOL_21) || (LIN_PROTOCOL == PROTOCOL_20))
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_word_status_lin21 (l_u8 pid)
* @brief Update date word status
*
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_298
* @endif
*
* @static_global_var
* -# <B>#lin_word_status</B>
* -# <B>#lin_error_in_response</B>
* -# <B>#lin_successful_transfer</B>
* -# <B>#lin_goto_sleep_flg</B>
*
* @details
* Update date word status
*
*//*END*----------------------------------------------------------------------*/
void lin_update_word_status_lin21 (l_u8 pid);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_update_err_signal ( void )
* @brief Update error signal
*
* @return #void
*
* @SDD_ID LIN_SDD_299
* @endif
*
* @local_var
* -# <B>#l_bool</B> <I>pid_found</I>
*
* @static_global_var
* -# <B>#response_error</B>
* -# <B>#lin_error_in_response</B>
*
* @details
* Update error signal
*
*//*END*----------------------------------------------------------------------*/
void lin_update_err_signal ( l_u8 frm_id);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void lin_make_res_evnt_frame (l_u8 pid)
* @brief This function is to pack signals associated with event trigger frame into buffer
*
* @param pid <B>[IN]</B> PID to process
*
* @return #void
*
* @SDD_ID LIN_SDD_300
* @endif
*
* @details
* This function is to pack signals associated with event trigger frame into buffer
*
* @see #lin_process_uncd_frame
* @see #lin_lld_response_buffer
*//*END*----------------------------------------------------------------------*/
void lin_make_res_evnt_frame (l_u8 pid);
#endif /* End (LIN_PROTOCOL == PROTOCOL_21) */
#endif /* End ( LIN_MODE == _SLAVE_MODE_) */
#endif /* _LIN_LIN21_PROTO_H */
/** @} */

View File

@ -0,0 +1,321 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup lin21tl_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_lin21tl_api.h
*
* @author FPT Software
*
* @brief LIN21 LIN transport layer and configuration functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090408 v1.0 First version
*
*****************************************************************************/
/** @} */
#ifndef _LIN_LIN21TL_API_H
#define _LIN_LIN21TL_API_H
#include "lin.h"
#if LIN_MODE == _MASTER_MODE_
#if LIN_PROTOCOL == PROTOCOL_21
/* API functions */
/** @addtogroup node_configuration_group
* @{ */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn l_u8 ld_is_ready(l_ifc_handle iii)
* @brief Verifies a state of node setting (using for LIN2.1)
*
* @param iii <B>[IN]</B> lin interface handle
*
* @return #l_u8
*
* @SDD_ID LIN_SDD_329
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Verifies a state of node setting (using for LIN2.1)
*//*END*----------------------------------------------------------------------*/
l_u8 ld_is_ready(l_ifc_handle iii);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_check_response(l_ifc_handle iii, l_u8* const RSID, l_u8* const error_code)
* @brief Verifies the state of response (using for LIN2.1)
*
* @param iii <B>[IN]</B> lin interface handle
* @param RSID <B>[OUT]</B> buffer for saving the response ID
* @param error_code <B>[OUT]</B> buffer for saving the error code
*
* @return #void
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
*
* @SDD_ID LIN_SDD_330
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* Verifies the state of response (using for LIN2.1)
*//*END*----------------------------------------------------------------------*/
void ld_check_response(
l_ifc_handle iii,
l_u8* const RSID,
l_u8* const error_code);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void ld_assign_frame_id_range(l_ifc_handle iii, l_u8 NAD, l_u8 start_index, const l_u8* const PIDs)
* @brief
* This call assigns the protected identifier of up to four frames in the slave node with the
* addressed NAD (using for LIN2.1)
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> NAD value of the target node
* @param start_index <B>[IN]</B> specifies which is the first frame to assign a PID
* @param PIDs <B>[IN]</B> list of protected identifier
*
* @return #void
*
* @local_var
* -# <B>#lin_configuration</B> <I>*conf</I>
* -# <B>#l_u8</B> <I>Buff</I>
*
* @SDD_ID LIN_SDD_331
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
*
* @details
* This call assigns the protected identifier of up to four frames in the slave node with the
* addressed NAD (using for LIN2.1)
*//*END*----------------------------------------------------------------------*/
void ld_assign_frame_id_range(l_ifc_handle iii,
l_u8 NAD,
l_u8 start_index,
const l_u8* const PIDs);
/** @} */
/* Multi frame support */
/** @addtogroup lin21tl_api_group
* @{ */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* Diagnostic class II services, they can be used in class III */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void diag_read_data_by_identifier(l_ifc_handle iii, const l_u8 NAD, l_u8 *const data)
* @brief This function is read data by identifier.
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> NAD value of the destination node for the transmission
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @local_var
* -# <B>#l_u16</B> <I>temp</I>
* -# <B>#l_u8</B> <I>Buff</I>
* -# <B>#lin_configuration</B> <I>*conf</I>
*
* @SDD_ID LIN_SDD_332
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* @see ld_send_message
*
* @details
* This function is read data by identifier. <br/>
* iii: name of interface <br/>
* NAD: NAD value of the destination node for the transmission <br/>
* data: buffer for the data to be transmitted <br/>
* 0x0202 - Read - A2D Values/Measurement <br/>
* 0x0206 - Read - LIN Stack Information <br/>
* 0xF18C - Read - ECU Barcode Number (Delphi) <br/>
*//*END*----------------------------------------------------------------------*/
void diag_read_data_by_identifier(l_ifc_handle iii, const l_u8 NAD, l_u8 * const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void diag_write_data_by_identifier(l_ifc_handle iii, l_u8 NAD,l_u16 data_length, l_u8 *const data)
* @brief This function is write data by identifier service (0x2E)
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> NAD value of the destination node for the transmission
* @param data_length <B>[IN]</B> data length of frame
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @local_var
* -# <B>#l_u16</B> <I>temp = 0</I>
* -# <B>#l_u8</B> <I>Buff</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @SDD_ID LIN_SDD_333
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* @see ld_send_message
*
* @details
* Write_Data_By_Identifier service (0x2E) <br/>
* iii: name of interface <br/>
* NAD: NAD value of the destination node for the transmission <br/>
* data: buffer for the data to be transmitted
*//*END*----------------------------------------------------------------------*/
void diag_write_data_by_identifier(l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, l_u8 * const data);
/* END diagnostic class II services */
/* Diagnostic class III services, these services only belong to diagnostic class III */
#if (_DIAG_CLASS_SUPPORT_ == _DIAG_CLASS_III_)
/* Session control */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void diag_session_control(l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data)
* @brief This function is session control service (service id: 0x10)
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> NAD value of the destination node for the transmission
* @param data_length <B>[IN]</B> data length of frame
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @local_var
* -# <B>#l_u8</B> <I>Buff</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @SDD_ID LIN_SDD_334
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* @see ld_send_message
*
* @details
* This function is used for master node only. It will packing data and send request to slave node with service ID = 0x10: Session control
*//*END*----------------------------------------------------------------------*/
void diag_session_control(l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data);
/* Fault memory */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void diag_fault_memory_read(l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data)
* @brief This function is fault management read service (SID = 0x19)
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> NAD value of the destination node for the transmission
* @param data_length <B>[IN]</B> data length of frame
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @local_var
* -# <B>#l_u8</B> <I>Buff</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @SDD_ID LIN_SDD_335
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* @see ld_send_message
*
* @details
* This function is used for master node only. It will packing data and send request to slave node with service ID = 0x19: Fault memory read
*//*END*----------------------------------------------------------------------*/
void diag_fault_memory_read (l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data);
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void diag_fault_memory_clear(l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data)
* @brief This function is fault management clear service (SID = 0x14)
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> NAD value of the destination node for the transmission
* @param data_length <B>[IN]</B> data length of frame
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @local_var
* -# <B>#l_u8</B> <I>Buff</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @SDD_ID LIN_SDD_336
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* @see ld_send_message
*
* @details
* This function is used for master node only. It will packing data and send request to slave node with service ID = 0x14: Fault memory clear
*//*END*----------------------------------------------------------------------*/
void diag_fault_memory_clear(l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data);
/* IO control */
/*FUNCTION*--------------------------------------------------------------*//**
* @fn void diag_IO_control(l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data)
* @brief This function is Input/Output control service (SID = 0x2F)
*
* @param iii <B>[IN]</B> lin interface handle
* @param NAD <B>[IN]</B> NAD value of the destination node for the transmission
* @param data_length <B>[IN]</B> data length of frame
* @param data <B>[IN]</B> buffer for the data to be transmitted
*
* @return #void
*
* @local_var
* -# <B>#l_u8</B> <I>Buff</I>
* -# <B>#l_u8</B> <I>i</I>
* -# <B>#lin_configuration</B> <I>conf</I>
*
* @SDD_ID LIN_SDD_337
* @endif
*
*
* @static_global_var
* -# <B>#lin_ifc_configuration</B>
* @see ld_send_message
*
* @details
* This function is used for master node only. It will packing data and send request to slave node with service ID = 0x2F: Input/Output control service
*//*END*----------------------------------------------------------------------*/
void diag_IO_control (l_ifc_handle iii, const l_u8 NAD,l_u16 data_length, l_u8 *const data);
#endif /* End (_DIAG_CLASS_SUPPORT_ == _DIAG_CLASS_III_) */
/* End diagnostic class III services */
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
#endif /* End of (LIN_PROTOCOL == PROTOCOL_21) */
#endif /* End (LIN_MODE == _MASTER_MODE_) */
/** @} */
#endif /* _LIN_LIN21TL_API_H */

1152
LIN_Stack/lowlevel/lin.c Normal file

File diff suppressed because it is too large Load Diff

1822
LIN_Stack/lowlevel/lin.h Normal file

File diff suppressed because it is too large Load Diff

340
LIN_Stack/mainpage.h Normal file
View File

@ -0,0 +1,340 @@
/** @mainpage LIN Stack Documentation
*
* @authors FPT Software<br>Copyright&nbsp;by&nbsp;Freescale&nbsp;Semiconductor,&nbsp;2008-2016
*<br>Copyright&nbsp;by&nbsp;NXP&nbsp;Semiconductors,&nbsp;2016-2017
*
* <BR>
* <h1>Introduction</h1>
* <ul>
* <li><h2>System Architecture</h2></li>
* <P>
* The layered architecture of the <A href="group___l_i_n21__core__api__group.html">LIN2.1</A>/ <A href="group___j2602__core__api__group.html">J2602</A> Stack package is shown on <A HREF="#figure1">Figure 1</A>. Such architecture approach aims maximum reusability of
* common code base for <A href="group___l_i_n21__core__api__group.html">LIN2.1</A> and <A href="group___j2602__core__api__group.html">J2602</A> standards for 8 bit and 16 bit Freescale automotive MCU portfolio. </P>
* <P>The core API layer of <A href="group___l_i_n21__core__api__group.html">LIN2.1</A>/ <A href="group___j2602__core__api__group.html">J2602</A> handles initialization, processing and signal based interaction between application and LIN Core.
* The <A href="group___l_i_n21__core__api__group.html">LIN2.1</A> TL (Transport Layer) provides methods for tester to transmit diagnostic requests. </P>
* <P>The low level layer offers method of handling signal transmission between user application and hardware independence
* such as byte sending, response receiving, break symbol detection, etc. </P>
* <P>The physical transport layer of the Stack supports three standard interfaces SCI, SLIC, GPIO to operate with 8 bit and 16 bit MCU hardware.</P>
* <A NAME="figure1"></A>
* @image html LIN_Stack_Architecture.jpg
* <CENTER><i>Figure 1. LIN Stack Architecture diagram</i></CENTER>
* <hr>
* <li><h2>Supported Derivatives</h2></li>
* <p>The following table displays the list of supported MCU derivatives including the functionalities. Note that all
* derivatives support the LIN 2.0, <A href="group___l_i_n21__core__api__group.html">LIN2.1</A> and <A href="group___j2602__core__api__group.html">J2602</A> variant.
*
* @image html support.jpg
* <CENTER><i>Figure 2. Supported Derivatives</i></CENTER>
*
* <hr>
* <li><h2>LIN Stack Package Components</h2></li>
*
* LIN Stack Package consists of two major parts:
*
* <ul>
* <li>Node Configuration Tool: PC based script for LIN Stack configuration generation.</li>
*
* <li>LIN Stack: Embedded SW package supporting the LIN 2.0, <A href="group___l_i_n21__core__api__group.html">LIN2.1</A> and <A href="group___j2602__core__api__group.html">J2602</A> communication</li>
* </li>
* </ul>
* </ul>
* <p>
* <p style="padding-left:20px">
* <ol>
* <li><B>Node Configuration Tool:</b></li><br>
*
* The Node Configuration Tool is a built-in script of the LIN Stack package which allows user to easily generate the node
* configuration .h and .c files based on LIN Configuration Description File (LCF) and Node Private Description File (LPF).
* Those files are then in compiler integrated with LIN Stack source code and user application and after compilation downloaded
* to the target derivative. <A HREF="#figure2">Figure 3</A>. shows the diagram of configuration data flow.
* <A NAME="figure2"></A>
* @image html ConfigurationData.JPG
* <CENTER><i>Figure 3. Configuration data</i></CENTER>
*
* The LDF file describes a complete LIN cluster including Master/slave mode definition and contains information to handle the cluster. <BR>
* The NPF file contains information about LIN nodes such as node name, number of interface, MCU clock frequency, used communication channel
* (e.g. SCI channel) and port (e.g. GPIO port), etc., required for full description of the node.
*
* <li><B>LIN Stack:</B></li><br>
*
* The <A href="#figure3">Figure 4</A>. shows the details of modules in the LIN Stack package. It also demonstrates the relationship among modules and the direction of function call among them.
* <A NAME="figure3"></A>
* @image html LIN_Stack_Architecture1.jpg
* <CENTER><i>Figure 4. LIN Stack Layer Diagram</i></CENTER>
*
*
* LIN Stack software package provides support for <A href="group___l_i_n21__core__api__group.html">LIN2.1</A>, LIN 2.0 and <A href="group___j2602__core__api__group.html">J2602</A> communication protocols. The stack package is divided into the layers as follows:
*
* <ol type=I>
* <li>The lowest layer, <a href="group__bsp__group.html">Board Support Package</a> (BSP) layer is comprised of codes, which implements the tasks dedicated to specific MCU platform:
* interrupt service routines, i/o port setup, memory handling and so on. There are three interfaces implemented within the stack package: <a href="group___s_c_i__group.html">SCI</a>, <a href="group___s_l_i_c__group.html">SLIC</a>, <a href="group___g_p_i_o__group.html">GPIO</a> and <a href="group___x_g_a_t_e__group.html">XGATE</a>.</li>
*
* <li><a href="group__lowlevel__group.html">Low level layer</a> consists of core functions for the LIN protocol such as the frames handling, signals transmission and reception,
* data preparation, etc. Besides, this layer contains common implementation functions for the lowest layer to provide the interface abstraction.
* Function for LIN cluster setup can be found here as well. This layer interacts with the core API layer through low level API functions.</li>
*
* <li><a href="group__coreapi__group.html">Core API layer</a> consists of API functions as defined by the <A href="group___l_i_n21__core__api__group.html">LIN2.1</A>/<A href="group___j2602__core__api__group.html">J2602</A> specification enabling the user to utilize the <A href="group___l_i_n21__core__api__group.html">LIN2.1</A>/<A href="group___j2602__core__api__group.html">J2602</A>
* communication within the user application. Both the static and dynamic modes for calling the API functions are supported. The core API layer
* interacts with the low level layer and can be called by such upper layers as <A href="group___l_i_n21__core__api__group.html">LIN2.1</A> TL API, LIN TL <A href="group___j2602__core__api__group.html">J2602</A> or application for diagnostic implementation</li>
*
* <li><a href="group__transport__group.html">Transport layer</a> stands between the application layer and the core API layer including <A href="group___l_i_n21__core__api__group.html">LIN2.1</A> TL API and LIN TL <A href="group___j2602__core__api__group.html">J2602</A>.
* This layer provides APIs for the transport protocol, node configuration and diagnostic. For <A href="group___l_i_n21__core__api__group.html">LIN2.1</A>, all components will be
* extended from LIN 2.0 specification. The node configuration for <A href="group___j2602__core__api__group.html">J2602</A> implements only some functions of LIN 2.0 specification.
* The layer contains some main components below:
* <ul>
* <li>Transport protocol:
* <ul>
* <li><A href="group___l_i_n21__core__api__group.html">LIN2.1</A>: Error handing and communication functions are added to LIN 2.0 specification.</li>
* </ul>
* </li>
*
* <li>Node configuration:
* <ul>
* <li><A href="group___l_i_n21__core__api__group.html">LIN2.1</A> extends slave configuration and assign frame with ID range to LIN 2.0. The assign frame with ID is removed.</li>
*
* <li><A href="group___j2602__core__api__group.html">J2602</A> simplifies LIN 2.0 Node configuration.</li>
* </ul>
* </li>
*
* <li><a href="group__diagnostic__group.html">Diagnostic</a>:
*
* <ul>
* <li>LIN 2.0 Diagnostic implements functions as diagnostic service. In the other hand, <A href="group___l_i_n21__core__api__group.html">LIN2.1</A> Diagnostic implements functions.</li>
* </ul>
* </li>
* </ul>
* </li>
*
* <li>Application layer is the highest layer which stands for applications of user.</li>
* </ol>
* </ol>
*
* </p>
*
*/
/**
* @defgroup LIN_Stack LIN stack */
/** @defgroup diagnostic_group Diagnostic services
* @ingroup LIN_Stack
* @brief Diagnostic services defines methods to implement diagnostic data transfer between a master node, respectively a diagnostic tester, and the slave nodes
* @details Three different classes of diagnostic nodes are defined. Class I is using normal signalling and class II and class III uses the transport layer.<br><br>
* The master node and the diagnostic tester are connected via a back-bone bus (e.g. CAN). The master
* node shall receive all diagnostic requests addressed to the slave nodes from the
* back-bone bus, and gateway them to the correct LIN cluster(s). Responses from the
* slave nodes shall be gatewayed back to the back-bone bus through the master node. <br><br>
* All diagnostic requests and responses (services) addressed to the slave nodes can be
* routed in the network layer (i.e. no application layer routing), if the Diagnostic and
* Transport Layer Protocol of tester back-bone-bus master node fulfills the respective
* needs. In this case, the master node must implement the LIN transport protocol, see
* Transport Layer Specification, as well as the transport protocols used on the back-
* bone busses (e.g. ISO15765-2 on CAN)
*/
/** @defgroup transport_group Transport layer API
* @ingroup LIN_Stack
* @brief Transport layer stands between the application layer and the core API layer
* @details
* This layer consists the implementation of data transportation which contains one or more LIN frames.
* It is situated between the application layer and the core API layer including LIN2.1 TL API and LIN TL J2602.
* This layer provides APIs for the transport protocol, node configuration and diagnostic.
* For LIN 2.1, all components will be extended from LIN 2.0 specification.
* The node configuration for J2602 implements only some functions of LIN 2.0 specification
*/
/** @defgroup coreapi_group LIN Core API
* @ingroup LIN_Stack
* @brief Refer to chappter 7, LIN 2.1 specification
* @details
* - Core API layer consists of API functions as defined by the LIN2.1/J2602 specification
* - Enabling the user to utilize the LIN2.1/J2602 communication within the user application.
* - Both the static and dynamic modes for calling the API functions are supported.
* - The core API layer interacts with the low level layer and can be called by such upper layers as LIN2.1 TL API,
* LIN TL J2602 or application for diagnostic implementation
*/
/** @defgroup lowlevel_group Low level API
* @ingroup LIN_Stack
* @brief Low level layer consists of core functions for the LIN protocol
* @details This layer contains the implementation of LIN protocol such as the frames handling,
* signals transmission and reception, data preparation, etc. Besides, this layer contains common implementation functions
* for the lowest layer to provide the interface abstraction. Function for LIN cluster setup can be found here as well.
* This layer interacts with the core API layer through low level API functions.
*/
/** @defgroup bsp_group Board Support Package
* @ingroup LIN_Stack
* @brief BSP (Board Support Package) is the lowest layer of the LIN Stack.
* @details BSP is comprised of codes,
* which implements the tasks dedicated to specific MCU platform: interrupt service routines, i/o port setup, memory handling and so on.
* There are four interfaces implemented within the stack package: SCI, SLIC, GPIO and SCI + XGATE, UART.
*/
/** @defgroup common_core_api_group Common Core API
* This group contains general core APIs that used for both protocol LIN 2.1 and J2602.
*
* @ingroup coreapi_group */
/** @defgroup LIN21_core_api_group LIN 2.1 Specific API
* LIN 2.1 is extended from in LIN 2.0 specification through diagnostic services and few functions were removed as obsolete.
* <ol>
* <li>LIN 2.1 is compatible with LIN 2.0:
*
* <ul>
* <li>A LIN 2.1 master node may handle a LIN 2.0 slave node if the master node also contains
* all functionality of a LIN 2.0 master node, e.g. obsolete functions like Assign frame Id. </li>
*
* <li>A LIN 2.1 slave node can be used in a cluster with a LIN 2.0 master node if the LIN 2.1 slave node
* is pre-configured, i.e. the LIN 2.1 slave node has a valid configuration after reset.</li>
* </ul>
* </li>
*
* <li>Changes between LIN 2.0 and LIN 2.1
*
* LIN2.1 enhance the capacity of LIN2.0 on event-triggered frame collision handling and diagnostic services supported.
* Besides, several features are add to fulfill powerful capacity of LIN network such as configuration service, assign frame ID range configuration, etc.
* </li></ol>
* @ingroup coreapi_group */
/** @defgroup J2602_core_api_group J2602 Specific API
* J2602 protocol is LIN 2.0 based. It contains LIN 2.0's modules to support Signal management, network management, scheduler and J2602 status management.
* The goal of J2602 is to improve the interoperability and interchangeability of LIN devices within a network by resolving those LIN2.0 requirements that are ambiguous, conflicting, or optional.
* Moreover, J2602 provides additional requirements that are not present in LIN2.0. For example: fault tolerant, operation, network topology, etc.
* Different to LIN2.1 protocol, J2602 does not support sporadic and event trigger frames in communication.
* @ingroup coreapi_group */
/** @defgroup GPIO_group GPIO interface
* GPIO interface uses GPIO pins to communicates with LIN network. This group provides functions that help higher layers communicate with it. Only 9S12QD4 is supported.
*
* @ingroup bsp_group */
/** @defgroup SLIC_group SLIC interface
* SLIC (Slave LIN Interface Controller) is one integrated module of MCU, it support MCU communicating with LIN network as slave node. Only 9S08EL32 is supported.
*
* @ingroup bsp_group */
/** @defgroup SCI_group SCI interface
* This group contains functions that help physical module can communicate with LIN network through SCI module.
* List of supported MCUs with version of SCI and number of SCI channels is in table below:
* @image html SCI_allversions.png
*
* @ingroup bsp_group */
/** @defgroup UART_group UART interface
* UART interface uses UART to communicate with LIN network.
* @ingroup bsp_group */
/** @defgroup XGATE_group XGATE interface
* This interface use SCI to communicate with LIN network and XGATE to process MCU's interrupts.
*
* @ingroup bsp_group */
/** @defgroup resync_group Resynchronize module
* Local interconnect network (LIN) is widely used standard for low cost automotive networks.
* In order to ensure reliable communication via LIN bus, a bus clock of MCU needs to be accurate enough to avoid errors.
* MCU can use crystal or ceramic resonator to provide very accurate bus clocks. However, LIN protocol was designed to allow more cost-effective solution.
* An automatic resynchronization feature allows more cost-effective solution: MCUs can use on-chip oscillators to implement LIN slaves, even though the on-chip oscillators have less accuracy than a crystal.
* The automatic resynchronization module use the LIN SYNC field which is composed of five falling edges to synchronize with the master baud rate.
* The module measures the sync byte field and adjusts the slave bus frequency after each LIN sync field reception from the master node.
*
* @ingroup bsp_group */
/** @defgroup autobaud_group Autobaud Feature
* AUTOBAUD is an extensive feature in LIN Driver which allows a peripheral MCU to detect baud rate of LIN bus and adapt its original baud rate to bus value.
* Auto Baud is applied when the baud rate of the incoming data is unknown or the baud rate is fixed with some specific values.
* Each LIN network might have different configuration on such baudrates.
* One MCU can work with different configurations without flashing.
* @ingroup bsp_group */
/** @defgroup 9s08qd4_group 9S08QD4 MCU
* @ingroup GPIO_group */
/** @defgroup 9s08el32_group 9S08EL32 MCU
* @ingroup SLIC_group */
/** @defgroup driver_cluster_group Driver and cluster management
*
* @brief initialization for LIN node.
*
* @details
*
* @ingroup common_core_api_group */
/** @defgroup signal_interract_group Signal interaction
*
* @brief This group contains APIs that help you communicate with signals of LIN node.
*
* @details
*
* @ingroup common_core_api_group */
/** @defgroup notification_group Notification
*
* @brief This group contains APIs that let you know when a signal's value changed.
*
* @details
*
* @ingroup common_core_api_group */
/** @defgroup schedule_management_group Schedule management
*
* @brief This group contains APIs that help you manage schedules table in master node only.
*
* @details
*
* @ingroup common_core_api_group */
/** @defgroup interface_management_group Interface management
*
* @brief This group contains APIs that help you manage interface(s) in LIN node.
*
* @details
*
* @ingroup common_core_api_group */
/** @defgroup call_out_group User provided call-outs
*
* @brief This group contains APIs which may be called from within the LIN module in order to enable/disable LIN communication interrupts.
*
* @details
*
* @ingroup common_core_api_group */
/** @defgroup commontl_api_group Common API
* @brief contains APIs that used for both protocols LIN2.1 and J2602
*
* @ingroup transport_group */
/** @defgroup lin21tl_api_group LIN 2.1 specific API
* @brief contains APIs that only used for LIN 2.1 protocol
*
* @ingroup transport_group */
/** @defgroup j2602tl_api_group J2602 specific API
* @brief contains APIs that only used for J2602 protocol
*
* @ingroup transport_group */
/** @defgroup node_configuration_group Node configuration
*
* @brief This group contains APIs that used for node configuration purpose.
*
* @details
*
* @ingroup lin21tl_api_group */
/** @defgroup node_identification_group Node identification
*
* @brief This group contains API that used for node identification purpose.
*
* @details
*
* @ingroup lin21tl_api_group */
/** @defgroup initialization_group Initialization
*
* @brief Initialize transport layer (queues, status, ...).
*
* @details
*
* @ingroup commontl_api_group */
/** @defgroup raw_api_group Raw API
*
* @brief The raw API is operating on PDU level and it is typically used to gateway PDUs
* between CAN and LIN.
*
* @details Usually, a FIFO is used to buffer PDUs in order to handle the
* different bus speeds.
*
* @ingroup commontl_api_group */
/** @defgroup cooked_api_group Cooked API
*
* @brief Cooked processing of diagnostic messages manages one complete message at a time.
*
* @ingroup commontl_api_group */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,146 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup j2602tl_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_j2602tl_api.c
*
* @author FPT Software
*
* @brief J2602 LIN transport layer and configuration functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090409 v1.0 First version
*
*****************************************************************************/
/**
* @}
*/
#include "lin_j2602tl_api.h"
#if LIN_MODE == _MASTER_MODE_
#if LIN_PROTOCOL == PROTOCOL_J2602
/** @addtogroup j2602tl_api_group
* @{ */
l_bool ld_is_ready
(
/* [IN] interface name */
l_ifc_handle iii
)
{
lin_configuration const *conf;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Check the service status */
if (LD_SERVICE_BUSY == conf->tl_desc->tl_service_status)
{
return 0;
}
return 1;
}
l_u8 ld_check_response
(
/* [IN] interface name */
l_ifc_handle iii,
/* [OUT] buffer for saving the response ID */
l_u8* const RSID,
/* [OUT] buffer for saving the error code */
l_u8* const error_code
)
{
lin_last_cfg_result temp;
lin_configuration const *conf;
lin_tl_descriptor *_tl_desc;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Get the TL configuration */
_tl_desc = conf->tl_desc;
/* Get the status of the last service */
temp = (lin_last_cfg_result)(_tl_desc->tl_last_cfg_result);
/* Check status of last configuration */
switch (temp)
{
case LD_SUCCESS:
*RSID = _tl_desc->tl_last_RSID;
break;
case LD_NEGATIVE:
*RSID = _tl_desc->tl_last_RSID;
*error_code = _tl_desc->tl_ld_error_code;
break;
default:
break;
} /* end of switch */
return (l_u8)temp;
}
void ld_assign_frame_id
(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] initial node address of the target node */
l_u8 initial_NAD,
/* [IN] supplier ID of the target node */
l_u16 supplier_id,
/* [IN] message ID of the target node */
l_u16 message_id,
/* [IN] protected ID of the target node */
l_u8 PID
)
{
lin_tl_pdu_data *lin_tl_pdu;
lin_configuration *conf;
lin_tl_descriptor *tl_conf;
/* Get current configuration */
conf = (lin_configuration *)&lin_ifc_configuration[iii];
/* Get TL configuration */
tl_conf = conf->tl_desc;
/* Get pointer to TX single frame PDU */
lin_tl_pdu = (lin_tl_pdu_data *)tl_conf->tl_tx_single_pdu;
/* check service is busy? */
if (LD_SERVICE_BUSY != tl_conf->tl_service_status)
{
/* Create data for PDU */
(*lin_tl_pdu)[0] = initial_NAD;
(*lin_tl_pdu)[1] = 0x06;
(*lin_tl_pdu)[2] = 0xB1;
(*lin_tl_pdu)[3] = supplier_id &0x00FF;
(*lin_tl_pdu)[4] = (supplier_id >> 8) & 0x00FF;
(*lin_tl_pdu)[5] = message_id &0x00FF;
(*lin_tl_pdu)[6] = (message_id >> 8) & 0x00FF;
(*lin_tl_pdu)[7] = PID;
/* Set state of service is BUSY */
tl_conf->tl_service_status = LD_SERVICE_BUSY;
/* Notify to Master task sending frame */
tl_conf->tl_cnt_to_send = 1;
} /* End of checking service status */
}
/** @} */
#endif /* End (LIN_PROTOCOL == PROTOCOL_J2602) */
#endif /* End LIN_MODE == _MASTER_MODE_ */

View File

@ -0,0 +1,425 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2008-2015 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************/
/**************************************************************************//**
* @addtogroup lin21tl_api_group
* @{
******************************************************************************/
/**************************************************************************//**
*
* @file lin_lin21tl_api.c
*
* @author FPT Software
*
* @brief LIN21 LIN transport layer and configuration functions
*
******************************************************************************/
/******************************************************************************
*
* History:
*
* 20090409 v1.0 First version
*
*****************************************************************************/
#include "lin_lin21tl_api.h"
#if LIN_MODE == _MASTER_MODE_
#if LIN_PROTOCOL == PROTOCOL_21
/** @} */
/** @addtogroup node_configuration_group
* @{ */
l_u8 ld_is_ready(
/* [IN] interface name */
l_ifc_handle iii)
{
/* multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
return (l_u8) (*lin_ifc_configuration[iii].tl_service_status);
#else /* single frame support */
lin_configuration const *conf;
/* Get current configuration */
conf = &lin_ifc_configuration[iii];
return (l_u8)(conf->tl_desc->tl_service_status);
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
}
void ld_check_response(
/* [IN] interface name */
l_ifc_handle iii,
/* [OUT] buffer for saving the response ID */
l_u8* const RSID,
/* [OUT] buffer for saving the error code */
l_u8* const error_code)
{
lin_configuration const *conf;
lin_tl_descriptor *_tl_desc;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Get TL configuration */
_tl_desc = conf->tl_desc;
/* Get last reponse service identifier */
*RSID = _tl_desc->tl_last_RSID;
/* Get the error code of the last config sercive if it is negative response */
if (LD_NEGATIVE == (_tl_desc->tl_last_cfg_result))
{
*error_code = _tl_desc->tl_ld_error_code;
}
}
void ld_assign_frame_id_range(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] NAD value of the target node */
l_u8 NAD,
/* [IN] specifies which is the first frame to assign a PID */
l_u8 start_index,
/* [IN] list of protected identifier */
const l_u8* const PIDs)
{
/* multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
const lin_configuration * conf;
l_u8 Buff[6];
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
if (*conf->tl_service_status != LD_SERVICE_BUSY)
{
/* pack data into a single frame */
Buff[0] = 0xB7;
Buff[1] = start_index;
Buff[2] = PIDs[0];
Buff[3] = PIDs[1];
Buff[4] = PIDs[2];
Buff[5] = PIDs[3];
/* put data into TX_QUEUE */
ld_send_message(iii, 6, NAD, Buff);
/* set node config status to busy */
*conf->tl_service_status = LD_SERVICE_BUSY;
}
#else /* single frame support */
lin_tl_pdu_data *lin_tl_pdu;
lin_configuration *conf;
lin_tl_descriptor *tl_conf;
/* Get current configuration */
conf = (lin_configuration *)&lin_ifc_configuration[iii];
/* Get TL configuration */
tl_conf = conf->tl_desc;
/* Get pointer to TX single frame PDU */
lin_tl_pdu = (lin_tl_pdu_data *)tl_conf->tl_tx_single_pdu;
/* check service is busy? */
if (LD_SERVICE_BUSY != tl_conf->tl_service_status)
{
/* Create data for PDU */
(*lin_tl_pdu)[0] = NAD;
(*lin_tl_pdu)[1] = 0x06;
(*lin_tl_pdu)[2] = 0xB7;
(*lin_tl_pdu)[3] = start_index;
(*lin_tl_pdu)[4] = PIDs[0];
(*lin_tl_pdu)[5] = PIDs[1];
(*lin_tl_pdu)[6] = PIDs[2];
(*lin_tl_pdu)[7] = PIDs[3];
/* Set state of service is BUSY */
tl_conf->tl_service_status = LD_SERVICE_BUSY;
/* Notify to Master task sending frame */
tl_conf->tl_cnt_to_send = 1;
/* Switch to master request schedule table */
*conf->previous_schedule_id = *conf->active_schedule_id;
*conf->active_schedule_id = conf->schedule_start + 2;
conf->schedule_start_entry[*conf->active_schedule_id] = 0;
/* End of switch to diagnostic schedule table */
} /* End of checking service status */
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
} /* End of checking service status */
/** @} */
/** @addtogroup lin21tl_api_group
* @{ */
/* multi frame support */
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
l_u8 diag_get_flag(
/* [IN] interface name */
l_ifc_handle iii,
/* [IN] flag order */
l_u8 flag_order)
{
lin_configuration *conf;
lin_tl_descriptor *tl_conf;
l_u8 *service_flag;
/* Get current configuration */
conf = (lin_configuration *) &lin_ifc_configuration[iii];
/* Get TL configuration */
tl_conf = conf->tl_desc;
service_flag = tl_conf->tl_service_flags;
if (flag_order >= tl_conf->number_support_sid)
{
return 0;
}
else
{
return (l_u8) service_flag[flag_order];
}
}
void diag_clear_flag(l_ifc_handle iii, l_u8 flag_order)
{
lin_configuration *conf;
lin_tl_descriptor *tl_conf;
l_u8 *service_flag;
/* Get current configuration */
conf = (lin_configuration *) &lin_ifc_configuration[iii];
/* Get TL configuration */
tl_conf = conf->tl_desc;
service_flag = tl_conf->tl_service_flags;
if (flag_order < tl_conf->number_support_sid)
{
service_flag[flag_order] = 0;
}
}
/* diagnostic services class II */
void diag_read_data_by_identifier(l_ifc_handle iii, const l_u8 NAD,
l_u8 * const data)
{
l_u8 Buff[3];
const lin_configuration *conf;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* check whether service status is idle or not */
if (*conf->tl_service_status != LD_SERVICE_BUSY)
{
/* check whether input data contains correct data */
/* pack data */
Buff[0] = 0x22;
Buff[1] = data[0];
Buff[2] = data[1];
/* send message to transport layer */
ld_send_message(iii, 3, NAD, Buff);
/* set service status to busy */
*conf->tl_service_status = LD_SERVICE_BUSY;
}
}
void diag_write_data_by_identifier(l_ifc_handle iii, const l_u8 NAD,
l_u16 data_length, l_u8 * const data)
{
l_u8 Buff[MAX_LENGTH_SERVICE];
l_u8 i;
l_u16 temp = 0;
const lin_configuration * conf;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Check if length of data is greater than length maximum */
if (data_length < MAX_LENGTH_SERVICE)
{
/* check whether service status is idle or not */
if (*conf->tl_service_status != LD_SERVICE_BUSY)
{
/* check whether input data contains correct data */
temp = data[0];
temp <<= 8;
temp |= data[1];
/* pack data */
Buff[0] = 0x2E;
if ((temp == 0x0092) || (temp == 0x0205))
{
for (i = 0; i < data_length; i++)
{
Buff[i + 1] = data[i];
}
ld_send_message(iii, data_length + 1, NAD, Buff);
/* set service status to busy */
*conf->tl_service_status = LD_SERVICE_BUSY;
}
}
}
}
/* Diagnostic services class III */
#if (_DIAG_CLASS_SUPPORT_ == _DIAG_CLASS_III_)
/* ----------------- Session control -------------------- */
void diag_session_control (l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, l_u8 *const data)
{
l_u8 Buff[MAX_LENGTH_SERVICE];
l_u8 i;
const lin_configuration * conf;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Check if length of data is greater than length maximum */
if (data_length < MAX_LENGTH_SERVICE)
{
/* check whether service status is idle or not */
if (*conf->tl_service_status != LD_SERVICE_BUSY)
{
/* pack data */
Buff[0] = 0x10;
for (i = 0; i < data_length; i++)
{
Buff[i+1] = data[i];
}
ld_send_message(iii, data_length+1, NAD, Buff);
/* set service status to busy */
*conf->tl_service_status = LD_SERVICE_BUSY;
}
}
}
/* ----------------- Fault memory -------------------- */
void diag_fault_memory_read (l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, l_u8 *const data)
{
l_u8 Buff[MAX_LENGTH_SERVICE];
l_u8 i;
l_u16 temp = 0;
const lin_configuration * conf;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Check if length of data is greater than length maximum */
if (data_length < MAX_LENGTH_SERVICE)
{
/* check whether service status is idle or not */
if (*conf->tl_service_status != LD_SERVICE_BUSY)
{
/* pack data */
Buff[0] = 0x19;
for (i = 0; i < data_length; i++)
{
Buff[i+1] = data[i];
}
ld_send_message(iii, data_length+1, NAD, Buff);
/* set service status to busy */
*conf->tl_service_status = LD_SERVICE_BUSY;
}
}
}
void diag_fault_memory_clear (l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, l_u8 *const data)
{
l_u8 Buff[MAX_LENGTH_SERVICE];
l_u8 i;
l_u16 temp = 0;
const lin_configuration * conf;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Check if length of data is greater than length maximum */
if (data_length < MAX_LENGTH_SERVICE)
{
/* check whether service status is idle or not */
if (*conf->tl_service_status != LD_SERVICE_BUSY)
{
/* pack data */
Buff[0] = 0x14;
for (i = 0; i < data_length; i++)
{
Buff[i+1] = data[i];
}
ld_send_message(iii, data_length+1, NAD, Buff);
/* set service status to busy */
*conf->tl_service_status = LD_SERVICE_BUSY;
}
}
}
/* ----------------- I/O control -------------------- */
void diag_IO_control (l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, l_u8 *const data)
{
l_u8 Buff[MAX_LENGTH_SERVICE];
l_u8 i;
l_u16 temp = 0;
const lin_configuration * conf;
/* Get the current configuration */
conf = &lin_ifc_configuration[iii];
/* Check if length of data is greater than length maximum */
if (data_length < MAX_LENGTH_SERVICE)
{
/* check whether service status is idle or not */
if (*conf->tl_service_status != LD_SERVICE_BUSY)
{
/* pack data */
Buff[0] = 0x2F;
for (i = 0; i < data_length; i++)
{
Buff[i+1] = data[i];
}
ld_send_message(iii, data_length+1, NAD, Buff);
/* set service status to busy */
*conf->tl_service_status = LD_SERVICE_BUSY;
}
}
}
#endif /* End (_DIAG_CLASS_SUPPORT_ == _DIAG_CLASS_III_) */
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
#endif /* End of (LIN_PROTOCOL == PROTOCOL_21) */
#endif /* End LIN_MODE == _MASTER_MODE_ */
#if LIN_MODE == _SLAVE_MODE_
#if (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_)
/* get diagnostic flag */
l_u8 diag_get_flag(l_u8 flag_order)
{
if (flag_order >= _DIAG_NUMBER_OF_SERVICES_)
{
return 0;
}
else
{
return (l_u8) lin_diag_services_flag[flag_order];
}
}
void diag_clear_flag(l_u8 flag_order)
{
if (flag_order < _DIAG_NUMBER_OF_SERVICES_)
{
lin_diag_services_flag[flag_order] = 0;
}
}
#endif /* End (_TL_FRAME_SUPPORT_ == _TL_MULTI_FRAME_) */
#endif/* End LIN_MODE == _SLAVE_MODE_ */
/** @} */

314
Lib/mc9s12zvl32.c Normal file
View File

@ -0,0 +1,314 @@
/* Based on CPU DB MC9S12ZVL32_48, version 3.00.000 (RegistersPrg V2.33) */
/* DataSheet : MC9S12ZVLRMV1 Rev. 0.09 December 10, 2012 */
#include <mc9s12zvl32.h>
/*lint -save -esym(765, *) */
/* * * * * 8-BIT REGISTERS * * * * * * * * * * * * * * * */
volatile INT_CFADDRSTR _INT_CFADDR; /* Interrupt Request Configuration Address Register; 0x00000017 */
volatile INT_CFDATA0STR _INT_CFDATA0; /* Interrupt Request Configuration Data Register 0; 0x00000018 */
volatile INT_CFDATA1STR _INT_CFDATA1; /* Interrupt Request Configuration Data Register 1; 0x00000019 */
volatile INT_CFDATA2STR _INT_CFDATA2; /* Interrupt Request Configuration Data Register 2; 0x0000001A */
volatile INT_CFDATA3STR _INT_CFDATA3; /* Interrupt Request Configuration Data Register 3; 0x0000001B */
volatile INT_CFDATA4STR _INT_CFDATA4; /* Interrupt Request Configuration Data Register 4; 0x0000001C */
volatile INT_CFDATA5STR _INT_CFDATA5; /* Interrupt Request Configuration Data Register 5; 0x0000001D */
volatile INT_CFDATA6STR _INT_CFDATA6; /* Interrupt Request Configuration Data Register 6; 0x0000001E */
volatile INT_CFDATA7STR _INT_CFDATA7; /* Interrupt Request Configuration Data Register 7; 0x0000001F */
volatile MODESTR _MODE; /* Mode Register; 0x00000070 */
volatile MMCPCHSTR _MMCPCH; /* Captured S12ZCPU Program Counter High; 0x00000085 */
volatile MMCPCMSTR _MMCPCM; /* Captured S12ZCPU Program Counter Middle; 0x00000086 */
volatile MMCPCLSTR _MMCPCL; /* Captured S12ZCPU Program Counter Low; 0x00000087 */
volatile DBGC1STR _DBGC1; /* Debug Control Register 1; 0x00000100 */
volatile DBGC2STR _DBGC2; /* Debug Control Register 2; 0x00000101 */
volatile DBGSCR1STR _DBGSCR1; /* Debug State Control Register 1; 0x00000107 */
volatile DBGSCR2STR _DBGSCR2; /* Debug State Control Register 2; 0x00000108 */
volatile DBGSCR3STR _DBGSCR3; /* Debug State Control Register 3; 0x00000109 */
volatile DBGEFRSTR _DBGEFR; /* Debug Event Flag Register; 0x0000010A */
volatile DBGSRSTR _DBGSR; /* Debug Status Register; 0x0000010B */
volatile DBGACTLSTR _DBGACTL; /* Debug Comparator A Control Register; 0x00000110 */
volatile DBGAAHSTR _DBGAAH; /* Debug Comparator A Address Register High; 0x00000115 */
volatile DBGAAMSTR _DBGAAM; /* Debug Comparator A Address Register Middle; 0x00000116 */
volatile DBGAALSTR _DBGAAL; /* Debug Comparator A Address Register Low; 0x00000117 */
volatile DBGAD0STR _DBGAD0; /* Debug Comparator A Data Register 0; 0x00000118 */
volatile DBGAD1STR _DBGAD1; /* Debug Comparator A Data Register 1; 0x00000119 */
volatile DBGAD2STR _DBGAD2; /* Debug Comparator A Data Register 2; 0x0000011A */
volatile DBGAD3STR _DBGAD3; /* Debug Comparator A Data Register 3; 0x0000011B */
volatile DBGADM0STR _DBGADM0; /* Debug Comparator A Data Mask Register 0; 0x0000011C */
volatile DBGADM1STR _DBGADM1; /* Debug Comparator A Data Mask Register 1; 0x0000011D */
volatile DBGADM2STR _DBGADM2; /* Debug Comparator A Data Mask Register 2; 0x0000011E */
volatile DBGADM3STR _DBGADM3; /* Debug Comparator A Data Mask Register 3; 0x0000011F */
volatile DBGBCTLSTR _DBGBCTL; /* Debug Comparator B Control Register; 0x00000120 */
volatile DBGBAHSTR _DBGBAH; /* Debug Comparator B Address Register High; 0x00000125 */
volatile DBGBAMSTR _DBGBAM; /* Debug Comparator B Address Register Middle; 0x00000126 */
volatile DBGBALSTR _DBGBAL; /* Debug Comparator B Address Register Low; 0x00000127 */
volatile DBGDCTLSTR _DBGDCTL; /* Debug Comparator D Control Register; 0x00000140 */
volatile DBGDAHSTR _DBGDAH; /* Debug Comparator D Address Register High; 0x00000145 */
volatile DBGDAMSTR _DBGDAM; /* Debug Comparator D Address Register Middle; 0x00000146 */
volatile DBGDALSTR _DBGDAL; /* Debug Comparator D Address Register Low; 0x00000147 */
volatile MODRR0STR _MODRR0; /* Module Routing Register 0; 0x00000200 */
volatile MODRR1STR _MODRR1; /* Module Routing Register 1; 0x00000201 */
volatile MODRR2STR _MODRR2; /* Module Routing Register 2; 0x00000202 */
volatile MODRR3STR _MODRR3; /* Module Routing Register 3; 0x00000203 */
volatile MODRR4STR _MODRR4; /* Module Routing Register 4; 0x00000204 */
volatile ECLKCTLSTR _ECLKCTL; /* ECLK Control Register; 0x00000208 */
volatile IRQCRSTR _IRQCR; /* Interrupt Control Register; 0x00000209 */
volatile PTESTR _PTE; /* Port E Data Register; 0x00000260 */
volatile PTIESTR _PTIE; /* Port E Input Register; 0x00000262 */
volatile DDRESTR _DDRE; /* Port E Data Direction Register; 0x00000264 */
volatile PERESTR _PERE; /* Port E Pull Device Enable Register; 0x00000266 */
volatile PPSESTR _PPSE; /* Port E Polarity Select Register; 0x00000268 */
volatile PTTSTR _PTT; /* Port T Data Register; 0x000002C0 */
volatile PTITSTR _PTIT; /* Port T Input Register; 0x000002C1 */
volatile DDRTSTR _DDRT; /* Port T Data Direction Register; 0x000002C2 */
volatile PERTSTR _PERT; /* Port T Pull Device Enable Register; 0x000002C3 */
volatile PPSTSTR _PPST; /* Port T Polarity Select Register; 0x000002C4 */
volatile PTSSTR _PTS; /* Port S Data Register; 0x000002D0 */
volatile PTISSTR _PTIS; /* Port S Input Register; 0x000002D1 */
volatile DDRSSTR _DDRS; /* Port S Data Direction Register; 0x000002D2 */
volatile PERSSTR _PERS; /* Port S Pull Device Enable Register; 0x000002D3 */
volatile PPSSSTR _PPSS; /* Port S Polarity Select Register; 0x000002D4 */
volatile PIESSTR _PIES; /* Port S Interrupt Enable Register; 0x000002D6 */
volatile PIFSSTR _PIFS; /* Port S Interrupt Flag Register; 0x000002D7 */
volatile WOMSSTR _WOMS; /* Port S Wired-Or Mode Register; 0x000002DF */
volatile PTPSTR _PTP; /* Port P Data Register; 0x000002F0 */
volatile PTIPSTR _PTIP; /* Port P Input Register; 0x000002F1 */
volatile DDRPSTR _DDRP; /* Port P Data Direction Register; 0x000002F2 */
volatile PERPSTR _PERP; /* Port P Pull Device Enable Register; 0x000002F3 */
volatile PPSPSTR _PPSP; /* Port P Polarity Select Register; 0x000002F4 */
volatile PIEPSTR _PIEP; /* Port P Interrupt Enable Register; 0x000002F6 */
volatile PIFPSTR _PIFP; /* Port P Interrupt Flag Register; 0x000002F7 */
volatile OCPEPSTR _OCPEP; /* Port P Over-Current Protection Enable Register; 0x000002F9 */
volatile OCIEPSTR _OCIEP; /* Port P Over-Current Interrupt Enable Register; 0x000002FA */
volatile OCIFPSTR _OCIFP; /* Port P Over-Current Interrupt Flag Register; 0x000002FB */
volatile RDRPSTR _RDRP; /* Port P Reduced Drive Register; 0x000002FD */
volatile PTJSTR _PTJ; /* Port J Data Register; 0x00000310 */
volatile PTIJSTR _PTIJ; /* Port J Input Register; 0x00000311 */
volatile DDRJSTR _DDRJ; /* Port J Data Direction Register; 0x00000312 */
volatile PERJSTR _PERJ; /* Port J Pull Device Enable Register; 0x00000313 */
volatile PPSJSTR _PPSJ; /* Port J Polarity Select Register; 0x00000314 */
volatile WOMJSTR _WOMJ; /* Port J Wired-Or Mode Register; 0x0000031F */
volatile PTILSTR _PTIL; /* Port L Input Register; 0x00000331 */
volatile PPSLSTR _PPSL; /* Port L Polarity Select Register; 0x00000334 */
volatile PIELSTR _PIEL; /* Port L Interrupt Enable Register; 0x00000336 */
volatile PIFLSTR _PIFL; /* Port L Interrupt Flag Register; 0x00000337 */
volatile DIENLSTR _DIENL; /* Port LDigital Input Enable Register; 0x0000033C */
volatile PTALSTR _PTAL; /* Port L Analog Access Register; 0x0000033D */
volatile PIRLSTR _PIRL; /* Port L Input Divider Ratio Selection Register; 0x0000033E */
volatile FCLKDIVSTR _FCLKDIV; /* Flash Clock Divider Register; 0x00000380 */
volatile FSECSTR _FSEC; /* Flash Security Register; 0x00000381 */
volatile FCCOBIXSTR _FCCOBIX; /* Flash CCOB Index Register; 0x00000382 */
volatile FPSTATSTR _FPSTAT; /* Flash Protection Status Register; 0x00000383 */
volatile FCNFGSTR _FCNFG; /* Flash Configuration Register; 0x00000384 */
volatile FERCNFGSTR _FERCNFG; /* Flash Error Configuration Register; 0x00000385 */
volatile FSTATSTR _FSTAT; /* Flash Status Register; 0x00000386 */
volatile FERSTATSTR _FERSTAT; /* Flash Error Status Register; 0x00000387 */
volatile FPROTSTR _FPROT; /* P-Flash Protection Register; 0x00000388 */
volatile DFPROTSTR _DFPROT; /* D-Flash Protection Register; 0x00000389 */
volatile FOPTSTR _FOPT; /* Flash Option Register; 0x0000038A */
volatile ECCSTATSTR _ECCSTAT; /* ECC Status Register; 0x000003C0 */
volatile ECCIESTR _ECCIE; /* ECC Interrupt Enable Register; 0x000003C1 */
volatile ECCIFSTR _ECCIF; /* ECC Interrupt Flag Register; 0x000003C2 */
volatile ECCDPTRHSTR _ECCDPTRH; /* ECC Debug Point Register High; 0x000003C7 */
volatile ECCDPTRMSTR _ECCDPTRM; /* ECC Debug Point Register Middle; 0x000003C8 */
volatile ECCDPTRLSTR _ECCDPTRL; /* ECC Debug Point Register Low; 0x000003C9 */
volatile ECCDESTR _ECCDE; /* ECC Debug ECC; 0x000003CE */
volatile ECCDCMDSTR _ECCDCMD; /* ECC Debug Comamnd; 0x000003CF */
volatile TIM1TIOSSTR _TIM1TIOS; /* Timer Input Capture/Output Compare Select; 0x00000400 */
volatile TIM1CFORCSTR _TIM1CFORC; /* Timer Compare Force Register; 0x00000401 */
volatile TIM1TSCR1STR _TIM1TSCR1; /* Timer System Control Register1; 0x00000406 */
volatile TIM1TTOVSTR _TIM1TTOV; /* Timer Toggle On Overflow Register; 0x00000407 */
volatile TIM1TCTL2STR _TIM1TCTL2; /* Timer Control Register 2; 0x00000409 */
volatile TIM1TCTL4STR _TIM1TCTL4; /* Timer Control Register 4; 0x0000040B */
volatile TIM1TIESTR _TIM1TIE; /* Timer Interrupt Enable Register; 0x0000040C */
volatile TIM1TSCR2STR _TIM1TSCR2; /* Timer System Control Register 2; 0x0000040D */
volatile TIM1TFLG1STR _TIM1TFLG1; /* Main Timer Interrupt Flag 1; 0x0000040E */
volatile TIM1TFLG2STR _TIM1TFLG2; /* Main Timer Interrupt Flag 2; 0x0000040F */
volatile TIM1OCPDSTR _TIM1OCPD; /* Output Compare Pin Disconnect Register; 0x0000042C */
volatile TIM1PTPSRSTR _TIM1PTPSR; /* Precision Timer Prescaler Select Register; 0x0000042E */
volatile PWMESTR _PWME; /* PWM Enable Register; 0x00000480 */
volatile PWMPOLSTR _PWMPOL; /* PWM Polarity Register; 0x00000481 */
volatile PWMCLKSTR _PWMCLK; /* PWM Clock Select Register; 0x00000482 */
volatile PWMPRCLKSTR _PWMPRCLK; /* PWM Prescale Clock Select Register; 0x00000483 */
volatile PWMCAESTR _PWMCAE; /* PWM Center Align Enable Register; 0x00000484 */
volatile PWMCTLSTR _PWMCTL; /* PWM Control Register; 0x00000485 */
volatile PWMCLKABSTR _PWMCLKAB; /* PWM Clock Select Register; 0x00000486 */
volatile PWMSCLASTR _PWMSCLA; /* PWM Scale A Register; 0x00000488 */
volatile PWMSCLBSTR _PWMSCLB; /* PWM Scale B Register; 0x00000489 */
volatile TIM0TIOSSTR _TIM0TIOS; /* Timer Input Capture/Output Compare Select; 0x000005C0 */
volatile TIM0CFORCSTR _TIM0CFORC; /* Timer Compare Force Register; 0x000005C1 */
volatile TIM0TSCR1STR _TIM0TSCR1; /* Timer System Control Register1; 0x000005C6 */
volatile TIM0TTOVSTR _TIM0TTOV; /* Timer Toggle On Overflow Register; 0x000005C7 */
volatile TIM0TCTL1STR _TIM0TCTL1; /* Timer Control Register 1; 0x000005C8 */
volatile TIM0TCTL2STR _TIM0TCTL2; /* Timer Control Register 2; 0x000005C9 */
volatile TIM0TCTL3STR _TIM0TCTL3; /* Timer Control Register 3; 0x000005CA */
volatile TIM0TCTL4STR _TIM0TCTL4; /* Timer Control Register 4; 0x000005CB */
volatile TIM0TIESTR _TIM0TIE; /* Timer Interrupt Enable Register; 0x000005CC */
volatile TIM0TSCR2STR _TIM0TSCR2; /* Timer System Control Register 2; 0x000005CD */
volatile TIM0TFLG1STR _TIM0TFLG1; /* Main Timer Interrupt Flag 1; 0x000005CE */
volatile TIM0TFLG2STR _TIM0TFLG2; /* Main Timer Interrupt Flag 2; 0x000005CF */
volatile TIM0OCPDSTR _TIM0OCPD; /* Output Compare Pin Disconnect Register; 0x000005EC */
volatile TIM0PTPSRSTR _TIM0PTPSR; /* Precision Timer Prescaler Select Register; 0x000005EE */
volatile ADC0STSSTR _ADC0STS; /* ADC0 Status Register; 0x00000602 */
volatile ADC0TIMSTR _ADC0TIM; /* ADC0 Timing Register; 0x00000603 */
volatile ADC0FMTSTR _ADC0FMT; /* ADC0 Format Register; 0x00000604 */
volatile ADC0FLWCTLSTR _ADC0FLWCTL; /* ADC0 Conversion Flow Control Register; 0x00000605 */
volatile ADC0EIESTR _ADC0EIE; /* ADC0 Error Interrupt Enable Register; 0x00000606 */
volatile ADC0IESTR _ADC0IE; /* ADC0 Interrupt Enable Register; 0x00000607 */
volatile ADC0EIFSTR _ADC0EIF; /* ADC0 Error Interrupt Flag Register; 0x00000608 */
volatile ADC0IFSTR _ADC0IF; /* ADC0 Interrupt Flag Register; 0x00000609 */
volatile ADC0EOLRISTR _ADC0EOLRI; /* ADC0 End Of List Result Information Register; 0x00000610 */
volatile ADC0CIDXSTR _ADC0CIDX; /* ADC0 Command Index Register; 0x0000061C */
volatile ADC0CBP_0STR _ADC0CBP_0; /* ADC0 Command Base Pointer Register 0; 0x0000061D */
volatile ADC0CBP_1STR _ADC0CBP_1; /* ADC0 Command Base Pointer Register 1; 0x0000061E */
volatile ADC0CBP_2STR _ADC0CBP_2; /* ADC0 Command Base Pointer Register 2; 0x0000061F */
volatile ADC0RIDXSTR _ADC0RIDX; /* ADC0 Result Index Register; 0x00000620 */
volatile ADC0RBP_0STR _ADC0RBP_0; /* ADC0 Result Base Pointer Register 0; 0x00000621 */
volatile ADC0RBP_1STR _ADC0RBP_1; /* ADC0 Result Base Pointer Register 1; 0x00000622 */
volatile ADC0RBP_2STR _ADC0RBP_2; /* ADC0 Result Base Pointer Register 2; 0x00000623 */
volatile ADC0CROFF0STR _ADC0CROFF0; /* ADC0 Command and Result Offset Register 0; 0x00000624 */
volatile ADC0CROFF1STR _ADC0CROFF1; /* ADC0 Command and Result Offset Register 1; 0x00000625 */
volatile CPMURFLGSTR _CPMURFLG; /* CPMU Reset Flags Register; 0x000006C3 */
volatile CPMUSYNRSTR _CPMUSYNR; /* CPMU Synthesizer Register; 0x000006C4 */
volatile CPMUREFDIVSTR _CPMUREFDIV; /* CPMU Reference Divider Register; 0x000006C5 */
volatile CPMUPOSTDIVSTR _CPMUPOSTDIV; /* CPMU Post Divider Register; 0x000006C6 */
volatile CPMUIFLGSTR _CPMUIFLG; /* CPMU Interrupt Flags Register; 0x000006C7 */
volatile CPMUINTSTR _CPMUINT; /* CPMU Interrupt Enable Register; 0x000006C8 */
volatile CPMUCLKSSTR _CPMUCLKS; /* CPMU Clock Select Register; 0x000006C9 */
volatile CPMUPLLSTR _CPMUPLL; /* CPMU PLL Control Register; 0x000006CA */
volatile CPMURTISTR _CPMURTI; /* CPMU RTI Control Register; 0x000006CB */
volatile CPMUCOPSTR _CPMUCOP; /* CPMU COP Control Register; 0x000006CC */
volatile CPMUARMCOPSTR _CPMUARMCOP; /* CPMU COP Timer Arm/Reset Register; 0x000006CF */
volatile CPMUHTCTLSTR _CPMUHTCTL; /* High Temperature Control Register; 0x000006D0 */
volatile CPMULVCTLSTR _CPMULVCTL; /* Low Voltage Control Register; 0x000006D1 */
volatile CPMUAPICTLSTR _CPMUAPICTL; /* Autonomous Periodical Interrupt Control Register; 0x000006D2 */
volatile CPMUACLKTRSTR _CPMUACLKTR; /* Autonomous Clock Trimming Register; 0x000006D3 */
volatile CPMUHTTRSTR _CPMUHTTR; /* High Temperature Trimming Register; 0x000006D7 */
volatile CPMUOSCSTR _CPMUOSC; /* CPMU Oscillator Register; 0x000006DA */
volatile CPMUPROTSTR _CPMUPROT; /* CPMUV1 Protection Register; 0x000006DB */
volatile CPMUVREGCTLSTR _CPMUVREGCTL; /* Voltage Regulator Control Register; 0x000006DD */
volatile CPMUOSC2STR _CPMUOSC2; /* CPMU Oscillator Register 2; 0x000006DE */
volatile BATESTR _BATE; /* BATS Module Enable Register; 0x000006F0 */
volatile BATSRSTR _BATSR; /* BATS Module Status Register; 0x000006F1 */
volatile BATIESTR _BATIE; /* BATS Interrupt Enable Register; 0x000006F2 */
volatile BATIFSTR _BATIF; /* BATS Interrupt Flag Register; 0x000006F3 */
volatile SCI0ACR2STR _SCI0ACR2; /* SCI 0 Alternative Control Register 2; 0x00000702 */
volatile SCI0CR2STR _SCI0CR2; /* SCI 0 Control Register 2; 0x00000703 */
volatile SCI0SR1STR _SCI0SR1; /* SCI 0 Status Register 1; 0x00000704 */
volatile SCI0SR2STR _SCI0SR2; /* SCI 0 Status Register 2; 0x00000705 */
volatile SCI0DRHSTR _SCI0DRH; /* SCI 0 Data Register High; 0x00000706 */
volatile SCI0DRLSTR _SCI0DRL; /* SCI 0 Data Register Low; 0x00000707 */
volatile SCI1ACR2STR _SCI1ACR2; /* SCI 1 Alternative Control Register 2; 0x00000712 */
volatile SCI1CR2STR _SCI1CR2; /* SCI 1 Control Register 2; 0x00000713 */
volatile SCI1SR1STR _SCI1SR1; /* SCI 1 Status Register 1; 0x00000714 */
volatile SCI1SR2STR _SCI1SR2; /* SCI 1 Status Register 2; 0x00000715 */
volatile SCI1DRHSTR _SCI1DRH; /* SCI 1 Data Register High; 0x00000716 */
volatile SCI1DRLSTR _SCI1DRL; /* SCI 1 Data Register Low; 0x00000717 */
volatile SPI0CR1STR _SPI0CR1; /* SPI 0 Control Register 1; 0x00000780 */
volatile SPI0CR2STR _SPI0CR2; /* SPI 0 Control Register 2; 0x00000781 */
volatile SPI0BRSTR _SPI0BR; /* SPI 0 Baud Rate Register; 0x00000782 */
volatile SPI0SRSTR _SPI0SR; /* SPI 0 Status Register; 0x00000783 */
volatile IIC0IBADSTR _IIC0IBAD; /* IIC Address Register; 0x000007C0 */
volatile IIC0IBFDSTR _IIC0IBFD; /* IIC Frequency Divider Register; 0x000007C1 */
volatile IIC0IBCRSTR _IIC0IBCR; /* IIC Control Register; 0x000007C2 */
volatile IIC0IBSRSTR _IIC0IBSR; /* IIC Status Register; 0x000007C3 */
volatile IIC0IBDRSTR _IIC0IBDR; /* IIC Data I/O Register; 0x000007C4 */
volatile IIC0IBCR2STR _IIC0IBCR2; /* IIC Control Register 2; 0x000007C5 */
volatile LP0DRSTR _LP0DR; /* Port LP Data Register; 0x00000980 */
volatile LP0CRSTR _LP0CR; /* LIN Control Register; 0x00000981 */
volatile LP0SLRMSTR _LP0SLRM; /* LIN Slew Rate Register; 0x00000983 */
volatile LP0SRSTR _LP0SR; /* LIN Status Register; 0x00000985 */
volatile LP0IESTR _LP0IE; /* LIN Interrupt Enable Register; 0x00000986 */
volatile LP0IFSTR _LP0IF; /* LIN Interrupt Flags Register; 0x00000987 */
/* NVFPROT - macro for reading non volatile register Non Volatile P-Flash Protection Register; 0x00FFFE0C */
/* Tip for register initialization in the user code: const byte NVFPROT_INIT @0x00FFFE0C = <NVFPROT_INITVAL>; */
/* NVDFPROT - macro for reading non volatile register Non Volatile D-Flash Protection Register; 0x00FFFE0D */
/* Tip for register initialization in the user code: const byte NVDFPROT_INIT @0x00FFFE0D = <NVDFPROT_INITVAL>; */
/* NVFOPT - macro for reading non volatile register Non Volatile Flash Option Register; 0x00FFFE0E */
/* Tip for register initialization in the user code: const byte NVFOPT_INIT @0x00FFFE0E = <NVFOPT_INITVAL>; */
/* NVFSEC - macro for reading non volatile register Non Volatile Flash Security Register; 0x00FFFE0F */
/* Tip for register initialization in the user code: const byte NVFSEC_INIT @0x00FFFE0F = <NVFSEC_INITVAL>; */
/* * * * * 16-BIT REGISTERS * * * * * * * * * * * * * * * */
volatile IVBRSTR _IVBR; /* Interrupt Vector Base Register; 0x00000010 */
volatile MMCECSTR _MMCEC; /* Error code register; 0x00000080 */
volatile MMCCCRSTR _MMCCCR; /* Captured S12ZCPU Condition Code Register Low; 0x00000082 */
volatile PTADSTR _PTAD; /* Port AD Data Register; 0x00000280 */
volatile PTIADSTR _PTIAD; /* Port AD Input Register; 0x00000282 */
volatile DDRADSTR _DDRAD; /* Port AD Data Direction Register; 0x00000284 */
volatile PERADSTR _PERAD; /* Port AD Pull Up Enable Register; 0x00000286 */
volatile PPSADSTR _PPSAD; /* Port AD Polarity Select Register; 0x00000288 */
volatile PIEADSTR _PIEAD; /* Port AD Interrupt Enable Register; 0x0000028C */
volatile PIFADSTR _PIFAD; /* Port AD Interrupt Flag Register; 0x0000028E */
volatile DIENADSTR _DIENAD; /* Digital Input Enable Register; 0x00000298 */
volatile FCCOB0STR _FCCOB0; /* Flash Common Command Object Register; 0x0000038C */
volatile FCCOB1STR _FCCOB1; /* Flash Common Command Object Register; 0x0000038E */
volatile FCCOB2STR _FCCOB2; /* Flash Common Command Object Register; 0x00000390 */
volatile FCCOB3STR _FCCOB3; /* Flash Common Command Object Register; 0x00000392 */
volatile FCCOB4STR _FCCOB4; /* Flash Common Command Object Register; 0x00000394 */
volatile FCCOB5STR _FCCOB5; /* Flash Common Command Object Register; 0x00000396 */
volatile ECCDDSTR _ECCDD; /* ECC Debug Data; 0x000003CC */
volatile TIM1TCNTSTR _TIM1TCNT; /* Timer Count Register; 0x00000404 */
volatile TIM1TC0STR _TIM1TC0; /* Timer Input Capture/Output Compare Register 0; 0x00000410 */
volatile TIM1TC1STR _TIM1TC1; /* Timer Input Capture/Output Compare Register 1; 0x00000412 */
volatile PWMCNT01STR _PWMCNT01; /* PWM Channel Counter 01 Register; 0x0000048C */
volatile PWMCNT23STR _PWMCNT23; /* PWM Channel Counter 23 Register; 0x0000048E */
volatile PWMCNT45STR _PWMCNT45; /* PWM Channel Counter 45 Register; 0x00000490 */
volatile PWMCNT67STR _PWMCNT67; /* PWM Channel Counter 67 Register; 0x00000492 */
volatile PWMPER01STR _PWMPER01; /* PWM Channel Period 01 Register; 0x00000494 */
volatile PWMPER23STR _PWMPER23; /* PWM Channel Period 23 Register; 0x00000496 */
volatile PWMPER45STR _PWMPER45; /* PWM Channel Period 45 Register; 0x00000498 */
volatile PWMPER67STR _PWMPER67; /* PWM Channel Period 67 Register; 0x0000049A */
volatile PWMDTY01STR _PWMDTY01; /* PWM Channel Duty 01 Register; 0x0000049C */
volatile PWMDTY23STR _PWMDTY23; /* PWM Channel Duty 23 Register; 0x0000049E */
volatile PWMDTY45STR _PWMDTY45; /* PWM Channel Duty 45 Register; 0x000004A0 */
volatile PWMDTY67STR _PWMDTY67; /* PWM Channel Duty 67 Register; 0x000004A2 */
volatile TIM0TCNTSTR _TIM0TCNT; /* Timer Count Register; 0x000005C4 */
volatile TIM0TC0STR _TIM0TC0; /* Timer Input Capture/Output Compare Register 0; 0x000005D0 */
volatile TIM0TC1STR _TIM0TC1; /* Timer Input Capture/Output Compare Register 1; 0x000005D2 */
volatile TIM0TC2STR _TIM0TC2; /* Timer Input Capture/Output Compare Register 2; 0x000005D4 */
volatile TIM0TC3STR _TIM0TC3; /* Timer Input Capture/Output Compare Register 3; 0x000005D6 */
volatile TIM0TC4STR _TIM0TC4; /* Timer Input Capture/Output Compare Register 4; 0x000005D8 */
volatile TIM0TC5STR _TIM0TC5; /* Timer Input Capture/Output Compare Register 5; 0x000005DA */
volatile ADC0CTLSTR _ADC0CTL; /* ADC0 Control Register; 0x00000600 */
volatile ADC0CONIESTR _ADC0CONIE; /* ADC0 Conversion Interrupt Enable Register; 0x0000060A */
volatile ADC0CONIFSTR _ADC0CONIF; /* ADC0 Conversion Interrupt Flag Register; 0x0000060C */
volatile ADC0IMDRISTR _ADC0IMDRI; /* ADC0 Intermediate Result Information Register; 0x0000060E */
volatile CPMUAPIRSTR _CPMUAPIR; /* Autonomous Periodical Interrupt Rate Register; 0x000006D4 */
volatile CPMUIRCTRIMSTR _CPMUIRCTRIM; /* CPMU IRC1M Trim Registers; 0x000006D8 */
volatile SCI0BDSTR _SCI0BD; /* SCI 0 Baud Rate Register; 0x00000700 */
volatile SCI1BDSTR _SCI1BD; /* SCI 1 Baud Rate Register; 0x00000710 */
volatile SPI0DRSTR _SPI0DR; /* SPI 0 Data Register; 0x00000784 */
/* BAKEY0 - macro for reading non volatile register Backdoor Comparison Key 0; 0x00FFFE00 */
/* Tip for register initialization in the user code: const byte BAKEY0_INIT @0x00FFFE00 = <BAKEY0_INITVAL>; */
/* BAKEY1 - macro for reading non volatile register Backdoor Comparison Key 1; 0x00FFFE02 */
/* Tip for register initialization in the user code: const byte BAKEY1_INIT @0x00FFFE02 = <BAKEY1_INITVAL>; */
/* BAKEY2 - macro for reading non volatile register Backdoor Comparison Key 2; 0x00FFFE04 */
/* Tip for register initialization in the user code: const byte BAKEY2_INIT @0x00FFFE04 = <BAKEY2_INITVAL>; */
/* BAKEY3 - macro for reading non volatile register Backdoor Comparison Key 3; 0x00FFFE06 */
/* Tip for register initialization in the user code: const byte BAKEY3_INIT @0x00FFFE06 = <BAKEY3_INITVAL>; */
/* PROTKEY - macro for reading non volatile register Non Volatile Protection Override Comparison Key; 0x00FFFE08 */
/* Tip for register initialization in the user code: const byte PROTKEY_INIT @0x00FFFE08 = <PROTKEY_INITVAL>; */
/* * * * * 32-BIT REGISTERS * * * * * * * * * * * * * * * */
volatile PARTIDSTR _PARTID; /* Part ID Register; 0x00000000 */
volatile ADC0CMDSTR _ADC0CMD; /* ADC0 Command Register; 0x00000614 */
/* * * * * 24-BIT ADDRESS REGISTERS * * * * * * * * * * * * * * * * * * * * * * */
volatile void* volatile MMCPC; /* Captured S12ZCPU Program Counter Low; 0x00000087 */
volatile void* volatile DBGAA; /* Debug Comparator A Address Register Low; 0x00000117 */
volatile void* volatile DBGBA; /* Debug Comparator B Address Register Low; 0x00000127 */
volatile void* volatile DBGDA; /* Debug Comparator D Address Register Low; 0x00000147 */
volatile void* volatile ECCDPTR; /* ECC Debug Point Register Low; 0x000003C9 */
volatile void* volatile ADC0CBP; /* ADC0 Command Base Pointer Register 0; 0x000003C9 */
volatile void* volatile ADC0RBP; /* ADC0 Result Base Pointer Register 0; 0x000003C9 */
/*lint -restore */
/* EOF */

View File

@ -0,0 +1,155 @@
#ifndef _DERIVATIVE__H
#define _DERIVATIVE__H
#include <mc9s12zvl32.h>
//输出口
#define V_12_Ctrl PTP_PTP6
#define O_STAT_DIS PTP_PTP5
#define O_STATUS PTJ_PTJ0
//输入口
#define Button_PHONE PTADL_PTADL7
#define Button_UP PTADH_PTADH0
#define Button_OK PTADH_PTADH1
#define Button_DOWN PTP_PTP1
#define Button_SIRI PTJ_PTJ1
#define Signal_HORN PTT_PTT7
#define Button_SEEK_Add PTADL_PTADL3
#define Button_MUTE PTADL_PTADL4
#define Button_V_Reduce PTADL_PTADL6
#define Button_SEEK_Reduce PTADL_PTADL5
#define Button_V_Add PTADL_PTADL2
/*
//背景灯驱动
#define O_LED_PWM PWMDTY7
*/
extern unsigned char FLAG_GO_TO_Sleep;
extern unsigned char M_ASK_S_Sleep;
extern unsigned char NO_DATA_Sleep;//超时睡眠
/********此处为PE_Types*************/
#define setRegBit(reg, bit) (reg |= reg##_##bit##_##MASK)
#define clrRegBit(reg, bit) (reg &= ~reg##_##bit##_##MASK)
#define getRegBit(reg, bit) (reg & reg##_##bit##_##MASK)
#define setReg(reg, val) (reg = (word)(val))
#define getReg(reg) (reg)
#define setRegBits(reg, mask) (reg |= (word)(mask))
#define getRegBits(reg, mask) (reg & (word)(mask))
#define clrRegBits(reg, mask) (reg &= (word)(~(mask)))
#define setRegBitGroup(reg, bits, val) (reg = (word)((reg & ~reg##_##bits##_##MASK) | ((val) << reg##_##bits##_##BITNUM)))
#define getRegBitGroup(reg, bits) ((reg & reg##_##bits##_##MASK) >> reg##_##bits##_##BITNUM)
#define setRegMask(reg, maskAnd, maskOr) (reg = (word)((getReg(reg) & ~(maskAnd)) | (maskOr)))
#define setRegBitVal(reg, bit, val) ((val) == 0 ? (reg &= ~reg##_##bit##_##MASK) : (reg |= reg##_##bit##_##MASK))
#define changeRegBits(reg, mask) (reg ^= (mask))
#define changeRegBit(reg, bit) (reg ^= reg##_##bit##_##MASK)
/******************************************************************/
/* Uniform multiplatform peripheral access macros - 16 bit access */
/******************************************************************/
#define setReg16Bit(RegName, BitName) (RegName |= RegName##_##BitName##_##MASK)
#define clrReg16Bit(RegName, BitName) (RegName &= ~(word)RegName##_##BitName##_##MASK)
#define invertReg16Bit(RegName, BitName) (RegName ^= RegName##_##BitName##_##MASK)
#define testReg16Bit(RegName, BitName) (RegName & RegName##_##BitName##_##MASK)
/* Whole peripheral register access macros */
#define setReg16(RegName, val) (RegName = (word)(val))
#define getReg16(RegName) (RegName)
/* Bits peripheral register access macros */
#define testReg16Bits(RegName, GetMask) (RegName & (GetMask))
#define clrReg16Bits(RegName, ClrMask) (RegName &= (word)(~(word)(ClrMask)))
#define setReg16Bits(RegName, SetMask) (RegName |= (word)(SetMask))
#define invertReg16Bits(RegName, InvMask) (RegName ^= (word)(InvMask))
#define clrSetReg16Bits(RegName, ClrMask, SetMask) (RegName = (RegName & (~(word)(ClrMask))) | (word)(SetMask))
#define seqClrSetReg16Bits(RegName, BitsMask, BitsVal) ((RegName &= ~(~(word)(BitsVal) & (word)(BitsMask))),\
(RegName |= (word)(BitsVal) & (word)(BitsMask)) )
#define seqSetClrReg16Bits(RegName, BitsMask, BitsVal) ((RegName |= (word)(BitsVal) & (word)(BitsMask)),\
(RegName &= ~(~(word)(BitsVal) & (word)(BitsMask))) )
#define seqResetSetReg16Bits(RegName, BitsMask, BitsVal) ((RegName &= ~(word)(BitsMask)),\
(RegName |= (word)(BitsVal) & (word)(BitsMask)) )
#define clrReg16BitsByOne(RegName, ClrMask, BitsMask) (RegName &= (word)(ClrMask) & (word)(BitsMask))
/* Bit group peripheral register access macros */
#define testReg16BitGroup(RegName, GroupName) (RegName & RegName##_##GroupName##_##MASK)
#define getReg16BitGroupVal(RegName, GroupName) ((RegName & RegName##_##GroupName##_##MASK) >> RegName##_##GroupName##_##BITNUM)
#define setReg16BitGroupVal(RegName, GroupName, GroupVal) (RegName = (RegName & ~(word)RegName##_##GroupName##_##MASK) | (((word)(GroupVal)) << RegName##_##GroupName##_##BITNUM))
#define seqClrSetReg16BitGroupVal(RegName,GroupName,GroupVal) ((RegName &= ~(~(((word)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & RegName##_##GroupName##_##MASK)),\
(RegName |= (((word)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & RegName##_##GroupName##_##MASK) )
#define seqSetClrReg16BitGroupVal(RegName,GroupName,GroupVal) ((RegName |= (((word)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & RegName##_##GroupName##_##MASK),\
(RegName &= ~(~(((word)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & RegName##_##GroupName##_##MASK)) )
#define seqResetSetReg16BitGroupVal(RegName,GroupName,GroupVal) ((RegName &= ~(word)RegName##_##GroupName##_##MASK),\
(RegName |= (((word)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & RegName##_##GroupName##_##MASK) )
/*****************************************************************/
/* Uniform multiplatform peripheral access macros - 8 bit access */
/*****************************************************************/
#define setReg8Bit(RegName, BitName) (RegName |= RegName##_##BitName##_##MASK)
#define clrReg8Bit(RegName, BitName) (RegName &= (byte)~(byte)RegName##_##BitName##_##MASK)
#define invertReg8Bit(RegName, BitName) (RegName ^= RegName##_##BitName##_##MASK)
#define testReg8Bit(RegName, BitName) (RegName & RegName##_##BitName##_##MASK)
/* Whole peripheral register access macros */
#define setReg8(RegName, val) (RegName = (byte)(val))
#define getReg8(RegName) (RegName)
/* Bits peripheral register access macros */
#define testReg8Bits(RegName, GetMask) (RegName & (GetMask))
#define clrReg8Bits(RegName, ClrMask) (RegName &= (byte)(~(byte)(ClrMask)))
#define setReg8Bits(RegName, SetMask) (RegName |= (byte)(SetMask))
#define invertReg8Bits(RegName, InvMask) (RegName ^= (byte)(InvMask))
#define clrSetReg8Bits(RegName, ClrMask, SetMask) (RegName = (RegName & ((byte)(~(byte)(ClrMask)))) | (byte)(SetMask))
#define seqClrSetReg8Bits(RegName, BitsMask, BitsVal) ((RegName &= (byte)~((byte)~((byte)(BitsVal)) & ((byte)(BitsMask)))),\
(RegName |= ((byte)(BitsVal)) & ((byte)(BitsMask))) )
#define seqSetClrReg8Bits(RegName, BitsMask, BitsVal) ((RegName |= (byte)(BitsVal) & (byte)(BitsMask)),\
(RegName &= (byte)~((byte)~((byte)(BitsVal)) & (byte)(BitsMask))) )
#define seqResetSetReg8Bits(RegName, BitsMask, BitsVal) ((RegName &= (byte)~((byte)(BitsMask))),\
(RegName |= (byte)(BitsVal) & (byte)(BitsMask)) )
#define clrReg8BitsByOne(RegName, ClrMask, BitsMask) (RegName &= (byte)(ClrMask) & (byte)(BitsMask))
/* Bit group peripheral register access macros */
#define testReg8BitGroup(RegName, GroupName) (RegName & RegName##_##GroupName##_##MASK)
#define getReg8BitGroupVal(RegName, GroupName) ((RegName & RegName##_##GroupName##_##MASK) >> RegName##_##GroupName##_##BITNUM)
#define setReg8BitGroupVal(RegName, GroupName, GroupVal) (RegName = (RegName & (byte)~(byte)RegName##_##GroupName##_##MASK) | (byte)(((byte)(GroupVal)) << RegName##_##GroupName##_##BITNUM))
#define seqClrSetReg8BitGroupVal(RegName,GroupName,GroupVal) ((RegName &= (byte)~((byte)~(byte)(((byte)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & (byte)RegName##_##GroupName##_##MASK)),\
(RegName |= (byte)(((byte)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & (byte)RegName##_##GroupName##_##MASK) )
#define seqSetClrReg8BitGroupVal(RegName,GroupName,GroupVal) ((RegName |= (byte)(((byte)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & (byte)RegName##_##GroupName##_##MASK),\
(RegName &= (byte)~((byte)~(byte)(((byte)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & (byte)RegName##_##GroupName##_##MASK)) )
#define seqResetSetReg8BitGroupVal(RegName,GroupName,GroupVal) ((RegName &= (byte)~(byte)RegName##_##GroupName##_##MASK),\
(RegName |= (byte)(((byte)(GroupVal)) << RegName##_##GroupName##_##BITNUM) & RegName##_##GroupName##_##MASK) )
/******此处为PE_Error的宏定义********/
#define ERR_OK 0U /* OK */
#define ERR_SPEED 1U /* This device does not work in the active speed mode. */
#define ERR_RANGE 2U /* Parameter out of range. */
#define ERR_VALUE 3U /* Parameter of incorrect value. */
#define ERR_OVERFLOW 4U /* Timer overflow. */
#define ERR_MATH 5U /* Overflow during evaluation. */
#define ERR_ENABLED 6U /* Device is enabled. */
#define ERR_DISABLED 7U /* Device is disabled. */
#define ERR_BUSY 8U /* Device is busy. */
#define ERR_NOTAVAIL 9U /* Requested value or method not available. */
#define ERR_RXEMPTY 10U /* No data in receiver. */
#define ERR_TXFULL 11U /* Transmitter is full. */
#define ERR_BUSOFF 12U /* Bus not available. */
#define ERR_OVERRUN 13U /* Overrun error is detected. */
#define ERR_FRAMING 14U /* Framing error is detected. */
#define ERR_PARITY 15U /* Parity error is detected. */
#define ERR_NOISE 16U /* Noise error is detected. */
#define ERR_IDLE 17U /* Idle error is detected. */
#define ERR_FAULT 18U /* Fault error is detected. */
#define ERR_BREAK 19U /* Break char is received during communication. */
#define ERR_CRC 20U /* CRC error is detected. */
#define ERR_ARBITR 21U /* A node losts arbitration. This error occurs if two nodes start transmission at the same time. */
#define ERR_PROTECT 22U /* Protection error is detected. */
#define ERR_UNDERFLOW 23U /* Underflow error is detected. */
#define ERR_UNDERRUN 24U /* Underrun error is detected. */
#define ERR_COMMON 25U /* Common error of a device. */
#define ERR_LINSYNC 26U /* LIN synchronization error is detected. */
#define ERR_FAILED 27U /* Requested functionality or process failed. */
#define ERR_QFULL 28U /* Queue is full. */
#endif

View File

@ -0,0 +1,24 @@
#ifndef _DIAGNOSTIC_SERVICE_SLAVE_H_
#define _DIAGNOSTIC_SERVICE_SLAVE_H_
#include "lin_commontl_api.h"
#include "lin.h"
#include "lin_lin21tl_api.h"
/*------------------------------------------*/
#define SERIAL_NUBER_INT 0x00
#define IO_CONTROL_STATUS_INT 0x00
#define SESSION_CONTROL_P3 0x01F4
#define SESSION_CONTROL_P3Ex 0x09C4
#define DTCSTATUSBTYE_INT 0x00
#define DTCFORMATIDENTIFER_INT 0x01
#define COUNTDTC_INT 0x00
/*------------------------------------------*/
/* diagnostic services class II */
void diagsrv_read_data_by_identifier(void);
void diagsrv_write_data_by_identifier(void);
void diagsrv_session_control(void);
void diagsrv_io_control_by_identifier(void);
void diagsrv_fault_memory_read(void);
void diagsrv_fault_memory_clear(void);
void slave_task(void);
#endif /* End _DIAGNOSTIC_SERVICE_SLAVE_H_ */

11137
Project_Headers/mc9s12zvl32.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
/* This is a linker parameter file for the MC9S12ZVL32 */
NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */
SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
/* Register space */
/* IO_SEG = PAGED 0x000000 TO 0x000FFF; intentionally not defined */
/* RAM */
RAM = READ_WRITE 0x001000 TO 0x0013FF;
/* EEPROM */
EEPROM = READ_ONLY 0x100000 TO 0x10007F;
/* non-paged FLASHs */
ROM = READ_ONLY 0xFF8000 TO 0xFFFDFF;
/* VECTORS = READ_ONLY 0xFFFE00 TO 0xFFFFFF; intentionally not defined: used for VECTOR commands below */
//OSVECTORS = READ_ONLY 0xFFFE10 TO 0xFFFFFF; /* OSEK interrupt vectors (use your vector.o) */
END
PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
_PRESTART, /* Used in HIWARE format: jump to _Startup at the code start */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
STRINGS, /* string literals */
VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */
//.ostext, /* OSEK */
NON_BANKED, /* runtime routines which must not be banked */
DEFAULT_ROM,
COPY INTO ROM;
//.stackstart, /* eventually used for OSEK kernel awareness: Main-Stack Start */
SSTACK, /* allocate stack first to avoid overwriting variables on overflow */
//.stackend, /* eventually used for OSEK kernel awareness: Main-Stack End */
DEFAULT_RAM INTO RAM;
//.vectors INTO OSVECTORS; /* OSEK */
END
ENTRIES /* keep the following unreferenced variables */
/* OSEK: always allocate the vector table and all dependent objects */
//_vectab OsBuildNumber _OsOrtiStackStart _OsOrtiStart
END
STACKSIZE 0x100
VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */
//VECTOR 0 Entry /* reset vector: this is the default entry point for an Assembly application. */
//INIT Entry /* for assembly applications: that this is as well the initialization entry point */

View File

@ -0,0 +1,102 @@
/*****************************************************
starts12z.c - startup code for S12Z (S12/L-ISA)
----------------------------------------------------
Copyright (c) Freescale Semiconductor
All rights reserved
*****************************************************/
#include "starts12z.h"
#ifdef __cplusplus
#define __EXTERN_C extern "C"
#else
#define __EXTERN_C
#endif
#if __ASM_DATA_ADDR_OPT__
const
#endif
struct _tagStartup _startupData
#if __ASM_DATA_ADDR_OPT__
#ifdef __cplusplus
= {}
#endif
#endif
; /* read-only: */
/* _startupData is allocated in ROM and */
/* initialized by the linker */
void main(void); /* prototype of main function */
static void DoZeroOut(void) {
__asm {
LD D6, _startupData.nofZeroOuts
BEQ end /* nothing to do */
LD X, _startupData.pZeroOut
zeroOutLoop:
LD Y, (0,X) /* X points to the first range */
LD D7, (3,X) /* D7 holds size */
doZeroOut:
CLR.b (Y+)
DBNE D7, doZeroOut
LEA X, (7,X)
DBNE D6, zeroOutLoop
end:
}
}
static void DoCopyDown(void) {
__asm {
LD Y, _startupData.toCopyDownBeg
BEQ end /* the pointer is NULL */
nextItemLoop:
LD D6, (Y+) /* load the size */
BEQ end
LD X, (Y+) /* load the destination */
copyLoop:
MOV.b (Y+), (X+) /* copy the data */
DBNE D6, copyLoop
BRA nextItemLoop
end:
}
}
#ifdef __cplusplus
static void __static_init(void) {
__asm {
LD D5, _startupData.nofInitBodies
BEQ end
LD X, _startupData.initBodies
initNextBody:
LD Y,(X+)
PSH ALL
JSR (Y+)
PUL ALL
DBNE D5, initNextBody
end:
}
}
#endif
extern int __SEG_END_SSTACK[];
__EXTERN_C void _Startup(void) {
__asm {
LD S, #__SEG_END_SSTACK-1 /* initialize SP */
#ifdef __ALIGN_STACK_OPT__
TFR S, D6 /* align SP to 4*/
AND D6, #-4
TFR D6, S
#endif
}
DoZeroOut();
DoCopyDown();
#ifdef __cplusplus
__static_init();
#endif
main();
}

100
ReferencedRSESystems.xml Normal file
View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file stores a copy of all RSE Systems referenced by the project
so the systems can be automatically recreated when the project is imported in a new workspace.
This file is automatically generated and updated by the Eclipse IDE.-->
<APSC_Memento>
<host>
<properties>
<property key="hidden.applicator.com.freescale.debugger.applicator.launchconfiguration.lc.DMK-EBO-77A-SW0312 FLASH.proj.DMK-EBO-77A-SW0312" value="com.freescale.debugger.applicator.launchconfiguration.lc.DMK-EBO-77A-SW0312 FLASH.proj.DMK-EBO-77A-SW0312"/>
<property key="host.address" value=""/>
<property key="host.defaultEncoding" value=""/>
<property key="host.defaultUser" value="Administrator"/>
<property key="host.description" value=""/>
<property key="host.name" value="LIN_TEST_Project_FLASH_PnE U-MultiLink"/>
<property key="host.promptable" value="false"/>
<property key="host.type" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware"/>
<property key="propertySet.[OptionalPropertySet].enableConnectorServicesPropertyPage" value="false"/>
<property key="propertySet.[OptionalPropertySet].enableGenericHostPropertyPage" value="false"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.freescale.cdt.debug.cw.CW_SHADOWED_PREF.Embedded Initialization.simulator" value=""/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.freescale.cdt.debug.cw.core.settings.GdiConnection.Common.PhysicalConnectionAttributeBase" value="com.pemicro.mcu.debug.connections.pne.s12z."/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.freescale.cdt.debug.cw.core.settings.GdiConnection.Common.SimulatorConnectionAttributeBase" value=""/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.CommandLineArgs" value=""/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.ConfigFile" value=""/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.Library" value="s12z_pne_gdi"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.PEDEBUG_ALTERNATIVE_ALGORITHM_CHECKBOX" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.PEDEBUG_ALTERNATIVE_ALGORITHM_PATH" value=""/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.PEDEBUG_AUTO_SYNC" value="1"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.PEDEBUG_CURRENT_ALGORITHM_INDEX" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.PEDEBUG_ENABLE_FLASH_PROGRAMMING_DIALOG" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.PEDEBUG_ERASE_PROGRAM_WITHOUT_ASKING" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.RESET_DELAY" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_CyclonePro_PowerDownDelay" value="250"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_CyclonePro_PowerUpDelay" value="250"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_CyclonePro_currentvoltage" value="255"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_CyclonePro_poweroffonexit" value="1"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_Multilink_PowerDownDelay" value="250"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_Multilink_PowerUpDelay" value="1000"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_PCI_DELAY" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_PORT" value="21"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_PORT_NAME_STRING" value=""/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_SPECIFY_IP" value="127.0.0.1"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_SPECIFY_IP_ENABLED" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_SPECIFY_NETWORKCARD" value="127.0.0.1"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_SPECIFY_NETWORKCARD_ENABLED" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_TraceLink_MaxBufferSize" value="1"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_USE_CYCLONEPRO_RELAYS" value="1"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_interface_selection" value="0"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.STARTUP_set_CLKSW_bit_on_reset" value="1"/>
<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.s12z].com.pemicro.mcu.debug.connections.pne.s12z.UUID" value="12c98de4-ceae-41ba-8fba-c998eabca081"/>
<property key="propertySet.[cw.dbg.conn].rseSystemId" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system.170220105705+0800"/>
<property key="propertySet.[cw.dbg.ct.bareboard.gdi].logData" value="false"/>
<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryConnectionOn" value="false"/>
<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryTimeout" value="20"/>
<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryWithTimeoutOn" value="false"/>
<property key="propertySet.[cw.dbg.ct.targetConnLost].TerminateConnectionOn" value="false"/>
<property key="propertySet.[cw.dbg.ct.targetConnLost].retryPromptUserActionOn" value="true"/>
<property key="propertySet.[cw.dbg.ct].Connection Type" value="com.pemicro.mcu.debug.connections.pne.s12z"/>
<property key="propertySet.[cw.dbg.main].templateId" value="None"/>
<property key="propertySet.[cw.ide.settingscache].hidden.HostID" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.170220105705+0800"/>
<property key="propertySet.[cw.ide.settingscache].hidden.TimeStamp" value="1729757163077"/>
</properties>
</host>
<host>
<properties>
<property key="host.address" value=""/>
<property key="host.defaultEncoding" value=""/>
<property key="host.defaultUser" value="Administrator"/>
<property key="host.description" value=""/>
<property key="host.name" value="LIN_TEST_Project_FLASH_PnE U-MultiLink Target"/>
<property key="host.promptable" value="false"/>
<property key="host.type" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system"/>
<property key="propertySet.[OptionalPropertySet].enableConnectorServicesPropertyPage" value="false"/>
<property key="propertySet.[OptionalPropertySet].enableGenericHostPropertyPage" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].enableHSSTIOModelConfig" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].enableNetworkIOModelConfig" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].enableSerialIOModelConfig" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].enableStopTransferIOModelConfig" value="true"/>
<property key="propertySet.[cw.dbg.ct.bareboard].ethernetController" value="UEC1"/>
<property key="propertySet.[cw.dbg.ct.bareboard].executeReset" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].initPath" value=""/>
<property key="propertySet.[cw.dbg.ct.bareboard].memConfigPath" value=""/>
<property key="propertySet.[cw.dbg.ct.bareboard].networkDebuggerAddress" value="127.0.0.1"/>
<property key="propertySet.[cw.dbg.ct.bareboard].networkGateway" value="127.0.0.1"/>
<property key="propertySet.[cw.dbg.ct.bareboard].networkMACAddress" value="**-**-**-**-**-**"/>
<property key="propertySet.[cw.dbg.ct.bareboard].networkNetMask" value="255.255.255.255"/>
<property key="propertySet.[cw.dbg.ct.bareboard].networkTargetAddress" value="127.0.0.1"/>
<property key="propertySet.[cw.dbg.ct.bareboard].networkUDPPort" value="1234"/>
<property key="propertySet.[cw.dbg.ct.bareboard].noIOModelConfig" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].runOutOfReset" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].targetIsPalladium" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].useInitFile" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].useMemoryConfigFile" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkGateway" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkMACAddress" value="false"/>
<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkUDPPort" value="false"/>
<property key="propertySet.[cw.dbg.main].systemType" value="com.freescale.cw.system.s12z.MC9S12ZVL.MC9S12ZVL32"/>
<property key="propertySet.[cw.ide.settingscache].hidden.HostID" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system.170220105705+0800"/>
<property key="propertySet.[cw.ide.settingscache].hidden.TimeStamp" value="1487559428139"/>
</properties>
</host>
</APSC_Memento>

203
Sources/AD1.c Normal file
View File

@ -0,0 +1,203 @@
#include "AD1.h"
#define IDLE 0x00U /* IDLE state */
#define SINGLE 0x01U /* SINGLE state */
#define MEASURE 0x02U /* MESURE state */
#define CONTINUOUS 0x04U /* CONTINUOUS state */
#define CMD_EOL 0xC0000000U /* Command End of list used as the last command in CSL */
#define CMD_EOL_CONTINUOUS 0x80000000U /* Command End of list with continuous measurement of the whole list used as the last command in CSL */
#define CLEAR_CMD_EOL 0x3FFFFFFFU /* Constant for clearing the EOL command - for channel methods */
static const word Table[] = { /* Table of mask constants */
0x01U,0x02U,0x04U,0x08U,0x10U,0x20U,0x40U,0x80U,0x0100U};
#pragma DATA_SEG DEFAULT /* Select data segment "DEFAULT" */
static volatile dword CSL[10] __attribute__ ((aligned (4))) = { /* Channel/Sample settings */
0x00D90000U,0x00D80000U,0x00D70000U,0x00D60000U,0x00D50000U,0x00D40000U,0x00D30000U,0x00D20000U,0xC0D10000U,CMD_EOL};
static volatile word RVL[18] __attribute__ ((aligned (4))); /* HW DMA result buffer */
static volatile word OutFlg; /* Measurement finish flag */
static volatile byte SumChan; /* Number of the measured channels */
static volatile word ModeFlg; /* Current state of device */
word AD1_OutV[9];
#define CMD_LAST_SAMPLE_PLUS_EOL 0xC0D10000U /* Last sample with command End of list */
#define CMD_LAST_SAMPLE_PLUS_EOL_CONTINUOUS 0x80D10000U /* Last sample with command End of list */
//word ADCVALUE[9]={0,0,0,0,0,0,0,0,0};
byte ADC_convert_over_flag=0;//AD转换完成标志
//AD转换完成中断函数
void AD1_OnEnd()
{
ADC_convert_over_flag=1;//AD转换完成
/*ADCVALUE[0]=AD1_OutV[0];//
ADCVALUE[1]=AD1_OutV[1];//
ADCVALUE[2]=AD1_OutV[2];//
ADCVALUE[3]=AD1_OutV[3];//
ADCVALUE[4]=AD1_OutV[4];//
ADCVALUE[5]=AD1_OutV[5];//
ADCVALUE[6]=AD1_OutV[6];//
ADCVALUE[7]=AD1_OutV[7];//
ADCVALUE[8]=AD1_OutV[8];*/
}
//AD转换错误中断
void AD1_OnError()
{
}
//AD转换终止中断
void AD1_OnAbort()
{
}
//Get AD average value
word AD_Average_Calculate(word *AD_Array,byte Arrsize)
{
byte AD_i=0;
word AD_Sum=0;
for(AD_i=0;AD_i<Arrsize;AD_i++)
{
AD_Sum+=AD_Array[AD_i];
}
return (word)(AD_Sum/Arrsize);
}
void AD1_Init(void)
{
OutFlg = 0x00U; /* No measured value */
ModeFlg = IDLE; /* Device isn't running */
/* ADC0CTL: ADC_EN=0,ADC_SR=0,FRZ_MOD=0,SWAI=0,ACC_CFG=0,STR_SEQA=0,MOD_CFG=0,CSL_BMOD=0,RVL_BMOD=0,SMOD_ACC=0,AUT_RSTA=0,??=0,??=0,??=0,??=0 */
setReg16(ADC0CTL, 0x00U); /* Disable periphery to make accesible WP bits in enable mode */
ADC0CBP = CSL;
ADC0RBP = RVL;
/* ADC0FMT: DJM=1,??=0,??=0,??=0,??=0,SRES=2 */
setReg8(ADC0FMT, 0x82U); /* Set Format register */
/* ADC0TIM: ??=0,PRS=0 */
setReg8(ADC0TIM, 0x00U); /* Set Timing register */
/* ADC0CROFF1: ??=0,CMDRES_OFF1=8 */
setReg8(ADC0CROFF1, 0x00U); /* Set Command and Result Offset 1 register */
/* ADC0EIF: IA_EIF=0,CMD_EIF=0,EOL_EIF=0,??=0,TRIG_EIF=0,RSTAR_EIF=1,LDOK_EIF=1,??=0 */
setReg8(ADC0EIF, 0x06U); /* Clear error flag that could be cleared by write 1 */
/* ADC0EIE: IA_EIE=1,CMD_EIE=1,EOL_EIE=1,??=1,TRIG_EIE=1,RSTAR_EIE=1,LDOK_EIE=0,??=0 */
setReg8(ADC0EIE, 0xFCU); /* Set Error interrupt enable register */
/* ADC0IF: SEQAD_IF=1,CONIF_OIF=1,??=0,??=0,??=0,??=0,??=0,??=0 */
setReg8(ADC0IF, 0xC0U); /* Clear other flags */
/* ADC0IE: SEQAD_IE=1,CONIF_OIE=1,??=0,??=0,??=0,??=0,??=0,??=0 */
setReg8(ADC0IE, 0xC0U); /* Set Abort and Conversion overrun interrupt */
/* ADC0CONIF: CON_IF15=0,CON_IF14=0,CON_IF13=0,CON_IF12=0,CON_IF11=0,CON_IF10=0,CON_IF9=0,CON_IF8=0,CON_IF7=0,CON_IF6=0,CON_IF5=0,CON_IF4=0,CON_IF3=0,CON_IF2=0,CON_IF1=0,EOL_IF=1 */
setReg16(ADC0CONIF, 0x01U); /* Clear scan cycle complete flag */
/* ADC0CONIE: CON_IE15=0,CON_IE14=0,CON_IE13=0,CON_IE12=0,CON_IE11=0,CON_IE10=0,CON_IE9=0,CON_IE8=0,CON_IE7=0,CON_IE6=0,CON_IE5=0,CON_IE4=0,CON_IE3=0,CON_IE2=0,CON_IE1=0,EOL_IE=1 */
setReg16(ADC0CONIE, 0x01U); /* Set End of list interrupt in Conversion interrupt enable register */
/* ADC0CTL: ADC_EN=1,ADC_SR=0,FRZ_MOD=0,SWAI=0,ACC_CFG=2,STR_SEQA=0,MOD_CFG=0,CSL_BMOD=1,RVL_BMOD=1,SMOD_ACC=0,AUT_RSTA=0,??=0,??=0,??=0,??=0 */
setReg16(ADC0CTL, 0x8800U); /* Set Control register */
}
byte AD1_Start(void)
{
byte FlwCtrl_Mask = ADC0FLWCTL_RSTA_MASK; /* Add request for the restart of the measurement into flow control register */
if (ModeFlg != IDLE) { /* Is the device in running mode? */
return ERR_BUSY; /* If yes then error */
}
ModeFlg = CONTINUOUS; /* Set state of device to the CONTINUOUS mode */
OutFlg = 0x00U; /* Reset measured value validity */
/* Note: Next 9 lines are speed optimized */
AD1_OutV[0] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[1] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[2] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[3] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[4] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[5] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[6] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[7] = 0U; /* Set variable for storing measured values to 0 */
AD1_OutV[8] = 0U; /* Set variable for storing measured values to 0 */
if ((ADC0STS & ADC0STS_CSL_SEL_MASK) != 0x00U) { /* Is the appropriate CSL selected? */
FlwCtrl_Mask |= ADC0FLWCTL_LDOK_MASK; /* If not add change of CSL to the request into flow control register */
}
while((ADC0STS & ADC0STS_READY_MASK) == 0x00U) {} /* Wait until the periphery is in idle state */
ADC0FLWCTL = FlwCtrl_Mask; /* Prepare start of the measurement */
while(ADC0FLWCTL != 0x00U) {} /* Wait until the restart event is not finished */
/* ADC0FLWCTL: SEQA=0,TRIG=1,RSTA=0,LDOK=0,??=0,??=0,??=0,??=0 */
setReg8(ADC0FLWCTL, 0x40U); /* TRIG for start of the measurement */
return ERR_OK; /* OK */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vadc0conv_compl ad_convert_over(void)
{
word temp0; /* MISRA side effect eliminator */
word temp1; /* MISRA side effect eliminator */
volatile word *ResPointer; /* Pointer to result buffer for reading of the current results */
/* ADC0CONIF: CON_IF15=0,CON_IF14=0,CON_IF13=0,CON_IF12=0,CON_IF11=0,CON_IF10=0,CON_IF9=0,CON_IF8=0,CON_IF7=0,CON_IF6=0,CON_IF5=0,CON_IF4=0,CON_IF3=0,CON_IF2=0,CON_IF1=0,EOL_IF=1 */
setReg16(ADC0CONIF, 0x01U); /* Clear scan cycle complete flag */
if (ModeFlg == IDLE) { /* Is the driver in IDLE mode? */
return;
}
ResPointer = ((ADC0EOLRI & ADC0EOLRI_RVL_EOL_MASK)?(RVL+ADC0CROFF1):RVL); /* Select the result buffer with current results */
if ((ModeFlg & 0x01U) == 0x00U) { /* Non channel mode active (MEASURE, CONTINUOUS, CONTINUOUS_INT_TRIGGER, CONTINUOUS_EXT_TRIGGER) */
AD1_OutV[0] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[1] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[2] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[3] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[4] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[5] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[6] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[7] = *ResPointer++; /* Save measured value to the output buffer */
AD1_OutV[8] = *ResPointer++; /* Save measured value to the output buffer */
OutFlg = 0x01FFU; /* Measured values are available */
if (ModeFlg == MEASURE) { /* Not running in trigger nor continuous mode? */
ModeFlg = IDLE; /* Set the component to the IDLE mode */
}
AD1_OnEnd(); /* If yes then invoke user event */
} else { /* Channel mode active (SINGLE, CONTINUOUS_INT_CHAN_TRIGGER, CONTINUOUS_EXT_CHAN_TRIGGER) */
AD1_OutV[SumChan] = *ResPointer; /* Save measured value to the output buffer */
temp1 = Table[SumChan]; /* Read mask of the measured sample */
OutFlg |= temp1; /* Measured values are available */
ModeFlg = IDLE; /* Set the component to the IDLE mode */
AD1_OnEnd(); /* If yes then invoke user event */
}
if (ModeFlg != IDLE) {
while((ADC0STS & ADC0STS_READY_MASK) == 0x00U) {} /* Wait until the periphery is in idle state */
/* ADC0FLWCTL: SEQA=0,TRIG=0,RSTA=1,LDOK=0,??=0,??=0,??=0,??=0 */
setReg8(ADC0FLWCTL, 0x20U); /* RSTA for prepare of the next measurement */
while(ADC0FLWCTL != 0x00U) {} /* Wait until the restart event is not finished */
/* ADC0FLWCTL: SEQA=0,TRIG=1,RSTA=0,LDOK=0,??=0,??=0,??=0,??=0 */
setReg8(ADC0FLWCTL, 0x40U); /* TRIG for start of the measurement */
}
}
#pragma CODE_SEG AD1_CODE
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vadc0err ad_error(void)
{
if ((ADC0EIF & CEASE_ERROR_MASK) != 0U) {
ModeFlg = IDLE;
/* ADC0CTL: ADC_SR=1 */
setReg16Bits(ADC0CTL, 0x4000U); /* Trigger the soft reset */
} else {
/* ADC0EIF: IA_EIF=0,CMD_EIF=0,EOL_EIF=0,??=0,TRIG_EIF=0,RSTAR_EIF=1,LDOK_EIF=1,??=0 */
setReg8(ADC0EIF, 0x06U); /* Clear Non cease error flag */
/* ADC0IF: SEQAD_IF=0,CONIF_OIF=1,??=0,??=0,??=0,??=0,??=0,??=0 */
setReg8(ADC0IF, 0x40U); /* Clear flags in the Interrupt flag register */
}
AD1_OnError(); /* If yes then invoke user event */
}
#pragma CODE_SEG AD1_CODE
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vadc0conv_seq_abrt ad_onabort(void)
{
/* ADC0IF: SEQAD_IF=1,CONIF_OIF=0,??=0,??=0,??=0,??=0,??=0,??=0 */
setReg8(ADC0IF, 0x80U); /* Clear Abort flag */
ModeFlg = IDLE;
AD1_OnAbort(); /* If yes then invoke user event */
}
#pragma CODE_SEG AD1_CODE

51
Sources/AD1.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef __AD1_H
#define __AD1_H
#include "derivative.h"
#define CEASE_ERROR_MASK 0xF8U /* Constant for check the error flags register of the Error type if it holds the cease flags or not */
#define ERR_FLG_CEASE_ERROR_MASK 0xF800U /* Constant for check the variable of the Error type if it holds the cease flags or not */
#define ERR_FLG_MASK 0xFE40U /* Constant for check the variable of the Error type if it holds any error flags or not */
#ifndef __BWUserType_AD1_TError
#define __BWUserType_AD1_TError
/*lint -save -esym(960,18.4) Disable MISRA rule (18.4) checking. */
typedef union {
word err;
struct {
/*lint -save -e46 Disable MISRA rule (6.4) checking. */
word : 1; /* Reserved */
word : 1; /* Reserved */
word : 1; /* Reserved */
word : 1; /* Reserved */
word : 1; /* Reserved */
word : 1; /* Reserved */
word ConversionOverrun_Error : 1; /* Overrun of the ADCxCONIF register */
word : 1; /* Reserved */
word : 1; /* Reserved */
word LDOK_Error : 1; /* Restart without Load OK */
word Restart_Error : 1; /* Restart in the wrong time */
word Trigger_Error : 1; /* Trigger in the wrong time or trigger overflow - Cease ADC operation. */
word CompareValue_Error : 1; /* Compare value not available - Cease ADC operation. */
word EOL_Error : 1; /* End of list command missing in the current CSL - Cease ADC operation. */
word CommandValue_Error : 1; /* Invalid conversion command loaded - Cease ADC operation. */
word IllegalAccess_Error : 1; /* Wrong DMA access to illegal memory area - Cease ADC operation. */
/*lint -restore Enable MISRA rule (6.4) checking. */
} errName;
} AD1_TError; /* Error flags. For languages which don't support bit access is byte access only to error flags possible. */
/*lint -restore +esym(960,18.4) Enable MISRA rule (18.4) checking. */
#endif
extern word AD1_OutV[9];
extern byte ADC_convert_over_flag;//ADת»»Íê³É±êÖ¾
byte AD1_Start(void);
byte AD1_GetValue(void* Values);
byte AD1_GetValue16(word *Values);
void AD1_Init(void);
//Get AD average value
word AD_Average_Calculate(word *AD_Array,byte Arrsize);
#endif

171
Sources/Button.c Normal file
View File

@ -0,0 +1,171 @@
/*
* Button.c
*
* Created on: Jan 31, 2018
* Author: Administrator
*/
#include "Button.h"
unsigned int Lin_switch_state;
unsigned int Button_1_count,Button_2_count,Button_3_count,Button_4_count,Button_5_count;
unsigned int Button_6_count,Button_7_count,Button_8_count,Button_9_count,Button_10_count,Button_11_count;
unsigned char initflag[11]={1,1,1,1,1,1,1,1,1,1,1};
unsigned char button_stick=0;
unsigned char lin_Signal_HORN;
extern unsigned char Sig_LI0_MFL_ButtonRight_err,Sig_LI0_MFL_ButtonLeft_err;
void Button_Scan(void)
{
unsigned char Lin_switch_state_Bit_Feed=0;
button_stick = 0;
//Left
Button_detect((unsigned char)Button_SEEK_Add, &Button_4_count,&Lin_switch_state,21,&initflag[3]);
Button_detect((unsigned char)Button_SEEK_Reduce,&Button_5_count,&Lin_switch_state,22,&initflag[4]);
Button_detect((unsigned char)Button_V_Add, &Button_6_count,&Lin_switch_state,16,&initflag[5]);
Button_detect((unsigned char)Button_V_Reduce, &Button_7_count,&Lin_switch_state,17,&initflag[6]);
Button_detect((unsigned char)Button_MUTE, &Button_10_count,&Lin_switch_state,32,&initflag[9]);
Sig_LI0_MFL_ButtonLeft_err = button_stick;
button_stick = 0;
//Right
Button_detect((unsigned char)Button_SIRI, &Button_8_count,&Lin_switch_state,25,&initflag[7]);
Button_detect((unsigned char)Button_PHONE, &Button_9_count,&Lin_switch_state,28,&initflag[8]);
Button_detect((unsigned char)Button_UP, &Button_1_count,&Lin_switch_state,4,&initflag[0]);
Button_detect((unsigned char)Button_DOWN, &Button_2_count,&Lin_switch_state,5,&initflag[1]);
Button_detect((unsigned char)Button_OK, &Button_3_count,&Lin_switch_state,7,&initflag[2]);
Sig_LI0_MFL_ButtonRight_err = button_stick;
Lin_switch_state_Bit_Feed=Lin_switch_state_Bit(&Lin_switch_state);
if(Lin_switch_state_Bit_Feed==0)
{
Sig_LI0_MFL_Tastencode_1=0;
Sig_LI0_MFL_Tastencode_2=0;
}
Signal_HORN_detect();
}
void Signal_HORN_detect(void)
{
if(!Signal_HORN)
{
Button_11_count++;
if(Button_11_count>=3)
{
lin_Signal_HORN=1;
}
}
else
{
Button_11_count=0;
lin_Signal_HORN=0;
}
}
void Button_detect(unsigned char Button_state,unsigned int *Button_delay_count,
unsigned int *Lin_switch_state,unsigned char Lin_switch_data,unsigned char *initcode)
{
unsigned char Lin_switch_state_Bit_Feed=0;
if(Button_state==0)
{
if(*initcode != 0)return;
(*Button_delay_count)++;
if(*Button_delay_count>=3 && *Button_delay_count<12000)
{
*Lin_switch_state|=1<<(Button_to_Bit(Lin_switch_data));//0X21
Lin_switch_state_Bit_Feed=Lin_switch_state_Bit(Lin_switch_state);
if(Lin_switch_state_Bit_Feed==1)
{
Sig_LI0_MFL_Tastencode_1=Lin_switch_data;
Sig_LI0_MFL_Tastencode_2=0;
}
else if(Lin_switch_state_Bit_Feed==2 && (Sig_LI0_MFL_Tastencode_1!=Lin_switch_data)&&(Sig_LI0_MFL_Tastencode_2==0))
{
Sig_LI0_MFL_Tastencode_2=Lin_switch_data;
}
}
if(*Button_delay_count>=12000)
{
*Button_delay_count = 12000;
button_stick = 1;
*Lin_switch_state&=~(1<<(Button_to_Bit(Lin_switch_data)));
}
}
else
{
*Button_delay_count=0;
*Lin_switch_state&=~(1<<(Button_to_Bit(Lin_switch_data)));
*initcode = 0;
}
/* 为啥放在这?
if(Button_to_Bit(Lin_switch_data)==9)
{
Lin_switch_state_Bit_Feed=Lin_switch_state_Bit(Lin_switch_state);
if(Lin_switch_state_Bit_Feed==0)
{
Sig_LI0_MFL_Tastencode_1=0;
Sig_LI0_MFL_Tastencode_2=0;
}
}
*/
}
unsigned char Button_to_Bit(unsigned char Button_Sig)
{
if(Button_Sig==4)
{
return 0;
}
else if(Button_Sig==5)
{
return 1;
}
else if(Button_Sig==7)
{
return 2;
}
else if(Button_Sig==21)
{
return 3;
}
else if(Button_Sig==22)
{
return 4;
}
else if(Button_Sig==16)
{
return 5;
}
else if(Button_Sig==17)
{
return 6;
}
else if (Button_Sig==25)
{
return 7;
}
else if(Button_Sig==28)
{
return 8;
}
else if(Button_Sig==32)
{
return 9;
}
}
unsigned char Lin_switch_state_Bit(unsigned int *Lin_switch_state)
{
unsigned char i,Switch_num=0;
for(i=0;i<10;i++)
{
if(*Lin_switch_state&(1<<i))
{
Switch_num++;
if(Switch_num==2)
{
return Switch_num;
}
}
}
return Switch_num;
}

19
Sources/Button.h Normal file
View File

@ -0,0 +1,19 @@
/*
* Button.h
*
* Created on: Jan 31, 2018
* Author: Administrator
*/
#ifndef BUTTON_H_
#define BUTTON_H_
#include "DMK-BC316-77.h"
void Button_Scan(void);
void Button_detect(unsigned char Button_state,unsigned int *Button_delay_count,
unsigned int *Lin_switch_state,unsigned char Lin_switch_data,unsigned char *initcode);
unsigned char Button_to_Bit(unsigned char Button_Sig);
unsigned char Lin_switch_state_Bit(unsigned int *Lin_switch_state);
void Signal_HORN_detect(void);
#endif /* BUTTON_H_ */

190
Sources/CPU.c Normal file
View File

@ -0,0 +1,190 @@
/*
* CPU.c
*
* Created on: Oct 4, 2016
* Author: Administrator
*/
#include "CPU.h"
//bus时钟为32M内部高速时钟为64M程序运行为32M
void CLK_CONFIG(void)
{
/*** !!! Here you can place your own code using property "User code before PE initialization" on the build options tab of the CPU compoennt. !!! ***/
/* ### MC9S12ZVL32_48 "Cpu" init code ... */
/* PE initialization code after reset */
/* IVBR: IVB_ADDR=0x7FFF,??=0 */
setReg16(IVBR, 0xFFFEU);
/* ECLKCTL: NECLK=1,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */
setReg8(ECLKCTL, 0x80U);
/* System clock initialization */
/* CPMUPROT: ??=0,??=0,??=1,??=0,??=0,??=1,??=1,PROT=0 */
setReg8(CPMUPROT, 0x26U); /* Disable protection of clock configuration registers */
/* CPMUCLKS: PSTP=0 */
clrReg8Bits(CPMUCLKS, 0x40U);
/* CPMUCLKS: PLLSEL=1 */
setReg8Bits(CPMUCLKS, 0x80U); /* Enable the PLL to allow write to divider registers */
/* CPMUPOSTDIV: ??=0,??=0,??=0,POSTDIV4=0,POSTDIV3=0,POSTDIV2=0,POSTDIV1=0,POSTDIV0=0 */
setReg8(CPMUPOSTDIV, 0x00U); /* Set the post divider register */
/* Whenever changing PLL reference clock (REFCLK) frequency to a higher value
it is recommended to write CPMUSYNR = 0x00 in order to stay within specified
maximum frequency of the MCU */
/* CPMUSYNR: VCOFRQ1=0,VCOFRQ0=0,SYNDIV5=0,SYNDIV4=0,SYNDIV3=0,SYNDIV2=0,SYNDIV1=0,SYNDIV0=0 */
setReg8(CPMUSYNR, 0x00U); /* Set the multiplier register */
/* CPMUPLL: ??=0,??=0,FM1=0,FM0=0,??=0,??=0,??=0,??=0 */
setReg8(CPMUPLL, 0x00U); /* Set the PLL frequency modulation */
/* CPMUSYNR: VCOFRQ1=0,VCOFRQ0=1,SYNDIV5=0,SYNDIV4=1,SYNDIV3=1,SYNDIV2=1,SYNDIV1=1,SYNDIV0=1 */
setReg8(CPMUSYNR, 0x5FU); /* Set the multiplier register */
while(CPMUIFLG_LOCK == 0U) { /* Wait until the PLL is within the desired tolerance of the target frequency */
}
/* CPMUPROT: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,PROT=0 */
setReg8(CPMUPROT, 0x00U); /* Enable protection of clock configuration registers */
/* CPMUCOP: RSBCK=0,WRTMASK=1 */
clrSetReg8Bits(CPMUCOP, 0x40U, 0x20U);
/* CPMUHTCTL: ??=0,??=0,VSEL=0,??=0,HTE=0,HTDS=0,HTIE=0,HTIF=0 */
setReg8(CPMUHTCTL, 0x00U);
/* CPMUVREGCTL: ??=0,??=0,??=0,??=0,??=0,??=0,EXTXON=0,INTXON=1 */
setReg8(CPMUVREGCTL, 0x81U);
/*** End of PE initialization code after reset ***/
}
void Peripheral_Init(void)
{
/* Int. priority initialization */
/* No. Address Pri XGATE Name Description */
setReg8(INT_CFADDR, 0x28U);
setReg8(INT_CFDATA3, 0x04U); /* 0x2B 0x00FFFEAC 4 no ivVtim1ch0 used by PE */
setReg8(INT_CFADDR, 0x60U);
setReg8(INT_CFDATA1, 0x04U); /* 0x61 0x00FFFF84 4 no ivVadc0conv_compl used by PE */
setReg8(INT_CFDATA2, 0x04U); /* 0x62 0x00FFFF88 4 no ivVadc0conv_seq_abrt used by PE */
setReg8(INT_CFDATA3, 0x04U); /* 0x63 0x00FFFF8C 4 no ivVadc0err used by PE */
/* Common initialization of the CPU registers */
/* DIENADL: DIENADL7=1,DIENADL6=1,DIENADL5=1,DIENADL4=1,DIENADL3=1,DIENADL2=1 */
setReg8Bits(DIENADL, 0xFCU);
/* PIEADL: PIEADL7=0,PIEADL6=0,PIEADL5=0,PIEADL4=0,PIEADL3=0,PIEADL2=0 */
clrReg8Bits(PIEADL, 0xFCU);
/* PERADL: PERADL7=0,PERADL6=0,PERADL5=0,PERADL4=0,PERADL3=0,PERADL2=0 */
clrReg8Bits(PERADL, 0xFCU);
/* DDRADL: DDRADL7=0,DDRADL6=0,DDRADL5=0,DDRADL4=0,DDRADL3=0,DDRADL2=0 */
clrReg8Bits(DDRADL, 0xFCU);
/* TIM1TSCR1: TEN=0,TSWAI=0,TSFRZ=0,TFFCA=0,PRNT=1,??=0,??=0,??=0 */
setReg8(TIM1TSCR1, 0x08U);
/* TIM1OCPD: OCPD0=1 */
setReg8Bits(TIM1OCPD, 0x01U);
/* TIM1TIOS: IOS0=1 */
setReg8Bits(TIM1TIOS, 0x01U);
/* TIM1TCTL2: OM0=0,OL0=0 */
clrReg8Bits(TIM1TCTL2, 0x03U);
/* TIM1TTOV: TOV0=0 */
clrReg8Bits(TIM1TTOV, 0x01U);
/* TIM1TSCR2: TOI=0 */
clrReg8Bits(TIM1TSCR2, 0x80U);
/* TIM1TFLG1: ??=1,??=1,??=1,??=1,??=1,??=1,C1F=1,C0F=1 */
setReg8(TIM1TFLG1, 0xFFU);
/* TIM1TIE: C0I=1 */
setReg8Bits(TIM1TIE, 0x01U);
/* TIM1PTPSR: PTPS7=0,PTPS6=0,PTPS5=0,PTPS4=0,PTPS3=0,PTPS2=0,PTPS1=0,PTPS0=0 */
setReg8(TIM1PTPSR, 0x00U);
/* PERJ: PERJ1=0 */
clrReg8Bits(PERJ, 0x02U);
/* DDRJ: DDRJ1=0 */
clrReg8Bits(DDRJ, 0x02U);
/* PIEP: PIEP6=0,PIEP1=0 */
clrReg8Bits(PIEP, 0x42U);
/* PERP: PERP6=0,PERP1=0 */
clrReg8Bits(PERP, 0x42U);
/* PTP: PTP6=0 */
clrReg8Bits(PTP, 0x40U);
/* DDRP: DDRP6=1,DDRP1=0 */
clrSetReg8Bits(DDRP, 0x02U, 0x40U);
/* DIENADH: DIENADH1=1,DIENADH0=1 */
setReg8Bits(DIENADH, 0x03U);
/* PIEADH: PIEADH1=0,PIEADH0=0 */
clrReg8Bits(PIEADH, 0x03U);
/* PERADH: PERADH1=0,PERADH0=0 */
clrReg8Bits(PERADH, 0x03U);
/* DDRADH: DDRADH1=0,DDRADH0=0 */
clrReg8Bits(DDRADH, 0x03U);
/* PERT: PERT7=0 */
clrReg8Bits(PERT, 0x80U);
/* DDRT: DDRT7=0 */
clrReg8Bits(DDRT, 0x80U);
/* CPMUINT: LOCKIE=0,OSCIE=0 */
clrReg8Bits(CPMUINT, 0x12U);
/* CPMULVCTL: LVIE=0 */
clrReg8Bits(CPMULVCTL, 0x02U);
/* ECCIE: SBEEIE=0 */
clrReg8Bits(ECCIE, 0x01U);
/* ECCDCMD: ECCDRR=0 */
clrReg8Bits(ECCDCMD, 0x80U);
/* RDRP: RDRP7=0,RDRP5=0,RDRP3=0,RDRP1=0 */
clrReg8Bits(RDRP, 0xAAU);
/* IRQCR: IRQEN=0 */
clrReg8Bits(IRQCR, 0x40U);
clrReg8Bits(PTP, 0x88U);
/* DDRP: DDRP7=1,DDRP5=0,DDRP3=1 */
clrSetReg8Bits(DDRP, 0x20U, 0x88U);
/* PIEP: PIEP5=0,PIEP3=0 */
clrReg8Bits(PIEP, 0x28U);
/* PERP: PERP5=0,PERP3=0 */
clrReg8Bits(PERP, 0x28U);
/* ### ADC "AD1" init code ... */
AD1_Init();
/* ### BitIO "Bit1" init code ... */
/* ### BitIO "Bit2" init code ... */
/* ### BitIO "Bit3" init code ... */
/* ### BitIO "Bit4" init code ... */
/* ### TimerInt "TI1" init code ... */
/* TIM1TC0: BIT=0x7D00 */
setReg16(TIM1TC0, 0x7D00U); /* Store given value to the compare register */
/* ### BitIO "Bit5" init code ... */
/* ### BitIO "Bit6" init code ... */
/* ### BitIO "Bit7" init code ... */
/* ### BitIO "Bit8" init code ... */
/* ### BitIO "Bit9" init code ... */
/* ### BitIO "Bit10" init code ... */
/* ### BitIO "Bit11" init code ... */
/* ### BitIO "Bit12" init code ... */
/* ### BitIO "Bit13" init code ... */
/* ### BitIO "Bit14" init code ... */
/* ### Programable pulse generation "PWM1" init code ... */
//PWM1_Init();
/* ### WatchDog "WDog1" init code ... */
/* CPMUPROT: ??=0,??=0,??=1,??=0,??=0,??=1,??=1,PROT=0 */
setReg8(CPMUPROT, 0x26U); /* Disable protection of clock-source register */
/* CPMUCLKS: CSAD=1,PCE=0,COPOSCSEL0=0 */
clrSetReg8Bits(CPMUCLKS, 0x05U, 0x20U);
/* CPMUPROT: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,PROT=0 */
setReg8(CPMUPROT, 0x00U); /* Re-Enable protection of clock-source register */
/* CPMURFLG: COPRF=0 */
setReg8(CPMURFLG, 0x00U); /* Clear COP reset flag */
/* CPMUCOP: WCOP=0,CR2=1,CR1=0,CR0=1 */
clrSetReg8Bits(CPMUCOP, 0x82U, 0x05U);
/* Common peripheral initialization - ENABLE */
/* TIM1TSCR1: TEN=1,TSWAI=0,TSFRZ=0,TFFCA=0,PRNT=1,??=0,??=0,??=0 */
setReg8(TIM1TSCR1, 0x88U);
AD1_Start();
EnableInterrupts;
}

19
Sources/CPU.h Normal file
View File

@ -0,0 +1,19 @@
/*
* CPU.h
*
* Created on: Oct 4, 2016
* Author: Administrator
*/
#ifndef CPU_H_
#define CPU_H_
#include "derivative.h"
#include <hidef.h>
#include "AD1.h"
#include "PWM1.h"
void CLK_CONFIG(void);
void Peripheral_Init(void);
#endif /* CPU_H_ */

346
Sources/DMK-BC316-77.c Normal file
View File

@ -0,0 +1,346 @@
/*
* DMK-S301-77.c
*
* Created on: Apr 21, 2017
* Author: Administrator
*/
#include "DMK-BC316-77.h"
unsigned char Ad_cal_Loop;
unsigned int Bat_power_Data;
unsigned int Bat_Values[4];
unsigned int Bat_power_Error_count;
unsigned char Bat_power_Error_Flag;
unsigned char Sig_LI0_DI_KL_58xs_run;
unsigned char InitButtonCode=0xF0;
//调光信号、15电信号、调光使能信号
unsigned char Sig_LI0_DI_KL_58xs,Sig_LI0_Klemme_15_MFL,Sig_LI0_Dimmung_01_gueltig;
//按键信号
unsigned char Sig_LI0_MFL_Toggle,Sig_LI0_MFL_ButtonRight_err=0,Sig_LI0_MFL_ButtonLeft_err=0;
unsigned char Sig_LI0_MFL_Tastencode_1,Sig_LI0_MFL_Tastencode_2;
unsigned char Sig_LI0_MFL_Eventcode_1,Sig_LI0_MFL_Eventcode_2;
extern unsigned char lin_Signal_HORN;
extern l_u8 MFS_RollingCounter;
unsigned char outputdelay1,outputdelay2;
unsigned char Toggle_start;
unsigned char Toggle_1s;
static unsigned char last1,last2,elast1,elast2;
void Apply_Task(void)
{
if(app_base_2mStick == 1)
{
app_base_2mStick = 0;
AD_Data_Deal();
}
if(app_base_5mStick == 1)
{
app_base_5mStick=0;
if(Sig_LI0_Klemme_15_MFL==1)
{
Button_Scan();
}
else
{
Sig_LI0_MFL_Tastencode_1=0;
Sig_LI0_MFL_Tastencode_2=0;
}
Eventcode_deal(Sig_LI0_MFL_Tastencode_1,Sig_LI0_MFL_Tastencode_2);
if(last1 != Sig_LI0_MFL_Tastencode_1 || last2 != Sig_LI0_MFL_Tastencode_2)
{
if(Toggle_start == 1 && Toggle_1s%20 == 0)
{
}
else
{
Toggle_1s = 0;
Sig_LI0_MFL_Toggle=!Sig_LI0_MFL_Toggle;
Toggle_start=1;
}
last1 = Sig_LI0_MFL_Tastencode_1;
last2 = Sig_LI0_MFL_Tastencode_2;
elast1 = Sig_LI0_MFL_Eventcode_1;
elast2 = Sig_LI0_MFL_Eventcode_2;
}
else if(elast1 != Sig_LI0_MFL_Eventcode_1 || elast2 != Sig_LI0_MFL_Eventcode_2)
{
if(Toggle_start == 1 && Toggle_1s%20 == 0)
{
}
else
{
Toggle_1s = 0;
Sig_LI0_MFL_Toggle=!Sig_LI0_MFL_Toggle;
Toggle_start=1;
}
elast1 = Sig_LI0_MFL_Eventcode_1;
elast2 = Sig_LI0_MFL_Eventcode_2;
last1 = Sig_LI0_MFL_Tastencode_1;
last2 = Sig_LI0_MFL_Tastencode_2;
}
if(Sig_LI0_MFL_Tastencode_1!=0 || Sig_LI0_MFL_Tastencode_2!=0)
{
}
else
{
if(Toggle_start==1)
{
Toggle_start=2;
Toggle_1s=0;
}
last1 = 0;
last2 = 0;
}
}
if(app_base_10mStick == 1)
{
app_base_10mStick=0;
Sleep_Command_Rece();
if(outputdelay1 > 0)
{
outputdelay1--;
}
if(outputdelay2 > 0)
{
outputdelay2--;
}
}
if(app_base_50mStick == 1)
{
app_base_50mStick=0;
Toggle_bit_deal(Sig_LI0_MFL_Tastencode_1,Sig_LI0_MFL_Tastencode_2);
LIN_Short_to_12v_Protect();
if((Sig_LI0_Dimmung_01_gueltig==1) && (Sig_LI0_DI_KL_58xs <= 100) && (Sig_LI0_DI_KL_58xs >= 0))
{
Sig_LI0_DI_KL_58xs_run=Sig_LI0_DI_KL_58xs;
}
//PWM1_SetRatio16(Sig_LI0_DI_KL_58xs_run*65535/100);
}
}
void AD_Data_Deal(void)
{
if(ADC_convert_over_flag == 1)//AD转换完成标志
{
ADC_convert_over_flag=0;//AD转换完成标志位清零
Bat_Values[Ad_cal_Loop]=AD1_OutV[0];
Ad_cal_Loop++;
if(Ad_cal_Loop>=4)
{
Ad_cal_Loop=0;
Bat_power_Data=AD_Average_Calculate(Bat_Values,4);
if(Bat_power_Data>657) //>16.7v
{
Bat_power_Error_count++;
if(Bat_power_Error_count>=500)//125为一秒也就是4秒
{
Bat_power_Error_Flag=1;
Bat_power_Error_count=0;
}
}
else if(Bat_power_Data>342 && Bat_power_Data<638)//>8.7v<16.2v
{
Bat_power_Error_count=0;
Bat_power_Error_Flag=0;
}
else if(Bat_power_Data<323)//<8.2v
{
Bat_power_Error_count++;
if(Bat_power_Error_count>=500)//125为一秒也就是4秒
{
Bat_power_Error_Flag=1;
Bat_power_Error_count=0;
}
}
else
{
}
}
}
}
void Lin_Task(void)
{
l_bool_wr_LI0_void(1);//1-lin_pFrameBuf[0]=0x80 0-lin_pFrameBuf[0]=0x00
l_u8_wr_LI0_MFL_Variante(4);//lin_pFrameBuf[4]=0x40
l_bool_wr_LI0_MFL_Signalhorn(lin_Signal_HORN);//1-lin_pFrameBuf[7]=0x01 0-lin_pFrameBuf[7]=0x00
l_bool_wr_LI0_MFL_Toggle(Sig_LI0_MFL_Toggle);//1-lin_pFrameBuf[0]=0x90 0-lin_pFrameBuf[0]=0x80
l_bool_wr_LI0_MFL_Taste_links_Err(Sig_LI0_MFL_ButtonLeft_err);
l_bool_wr_LI0_MFL_Taste_rechts_Err(Sig_LI0_MFL_ButtonRight_err);
if(InitButtonCode != 0)
{
l_u8_wr_LI0_MFL_Tastencode_1(InitButtonCode);
}
else
{
l_u8_wr_LI0_MFL_Tastencode_1(Sig_LI0_MFL_Tastencode_1);
}
l_u8_wr_LI0_MFL_Tastencode_2(Sig_LI0_MFL_Tastencode_2);
l_u8_wr_LI0_MFL_Eventcode_1(Sig_LI0_MFL_Eventcode_1);//Sig_LI0_MFL_Eventcode_1
l_u8_wr_LI0_MFL_Eventcode_2(Sig_LI0_MFL_Eventcode_2);//Sig_LI0_MFL_Eventcode_2
Sig_LI0_DI_KL_58xs=l_u8_rd_LI0_DI_KL_58xs();
Sig_LI0_Klemme_15_MFL=l_bool_rd_LI0_Klemme_15_MFL();
Sig_LI0_Dimmung_01_gueltig=l_bool_rd_LI0_Dimmung_01_gueltig();
l_u8_wr_LI0_MFL_Zaehler(MFS_RollingCounter);
}
void Sleep_Command_Rece(void)
{
if ((M_ASK_S_Sleep==1 || NO_DATA_Sleep==1) && (Sig_LI0_DI_KL_58xs==0X7e || Sig_LI0_DI_KL_58xs==0X7f || Sig_LI0_DI_KL_58xs==0 || Sig_LI0_DI_KL_58xs==1))
{
V_12_Ctrl=0;
FLAG_GO_TO_Sleep=1;
//关闭中断
SCI0CR2_RE=0;
SCI0CR2_TE=0;
SCI0CR2_RIE=0;
//开启中断
SCI0CR2_RE=1;
SCI0CR2_TE=1;
SCI0CR2_RIE=1;
PWM1_SetRatio16(0);
PTJ_PTJ1=0;
PTP_PTP7=0;
clrReg8Bits(PWME, 0x80U); /* Run counter */
CPU_ENTER_STOP_MODE();
}
}
void Eventcode_deal(unsigned char Sig_LI0_MFL_Tastencode_1_E,unsigned char Sig_LI0_MFL_Tastencode_2_E)
{
// 静态变量,用于记录按键时长计数
static unsigned int Event_code1_count,Event_code2_count;
if(Sig_LI0_MFL_Tastencode_1_E!=0)
{
Sig_LI0_MFL_Eventcode_1=1;
if(Event_code1_count<=600)
{
Event_code1_count++;
}
if(Event_code1_count>=160 && Event_code1_count<400)
{
Sig_LI0_MFL_Eventcode_1=4;
}
else if(Event_code1_count>=400 && Event_code1_count<600)
{
Sig_LI0_MFL_Eventcode_1=5;
}
else if(Event_code1_count>=600)
{
Sig_LI0_MFL_Eventcode_1=6;
}
}
else
{
Sig_LI0_MFL_Eventcode_1=0;
Event_code1_count=0;
}
if(Sig_LI0_MFL_Tastencode_2_E!=0)
{
Sig_LI0_MFL_Eventcode_2=1;
if(Event_code2_count<=600)
{
Event_code2_count++;
}
if(Event_code2_count>=160 && Event_code2_count<400)
{
Sig_LI0_MFL_Eventcode_2=4;
}
else if(Event_code2_count>=400 && Event_code2_count<600)
{
Sig_LI0_MFL_Eventcode_2=5;
}
else if(Event_code2_count>=600)
{
Sig_LI0_MFL_Eventcode_2=6;
}
}
else
{
Sig_LI0_MFL_Eventcode_2=0;
Event_code2_count=0;
}
}
void Toggle_bit_deal(unsigned char Sig_LI0_MFL_Tastencode_1_E,unsigned char Sig_LI0_MFL_Tastencode_2_E)
{
if(Toggle_start==1)
{
Toggle_1s++;
if(Toggle_1s%20==0)
{
Sig_LI0_MFL_Toggle=!Sig_LI0_MFL_Toggle;
if(Toggle_1s==80)
{
Toggle_1s=0;
}
}
}
if(Toggle_start==2)
{
Toggle_1s++;
if(Toggle_1s%20==0)
{
Sig_LI0_MFL_Toggle=!Sig_LI0_MFL_Toggle;
if(Toggle_1s==100)
{
Toggle_1s=0;
Toggle_start=0;
}
}
}
}
void LIN_Short_to_12v_Protect(void)
{
static unsigned char LIN_Short_count,LIN_Short_recover_count;
if(LP0IF_LPOCIF==1)
{
if(LIN_Short_count<=60)
{
LIN_Short_count++;
LP0IF_LPOCIF=1;
}
}
else
{
LIN_Short_recover_count++;
if(LIN_Short_recover_count>=20)
{
LIN_Short_recover_count=0;
LIN_Short_count=0;
}
}
}
//睡眠lin唤醒使能位
void LIN_STANDBY_Mode_wakeup_enable(void)
{
LP0CR_LPWUE=1;//在stop mode下若lin接收到数据则会在LPRXD产生一个上升沿
LP0CR_LPPUE=1;//选择上拉方式
}
//进入停止模式
void CPU_ENTER_STOP_MODE(void)
{
asm ANDCC #0x7F; //clear S bit - enable the stop mode. If the S bit is not
//cleared then STOP instruction has no effect and is
//executed as a dummy instruction NOP.
asm STOP;
}

71
Sources/DMK-BC316-77.h Normal file
View File

@ -0,0 +1,71 @@
/*
* DMK-S301-77.h
*
* Created on: Apr 21, 2017
* Author: Administrator
*/
#ifndef DMK_S301_77_H_
#define DMK_S301_77_H_
#include "CPU.h"
#include "lin.h"
#include "AD1.h"
#include "TI1.h"
#include "PWM1.h"
#include "WDog1.h"
#include "Button.h"
//一路AD一个按键
typedef struct
{
unsigned int *AD_switch_array;
unsigned char AD_channel;
unsigned char *S1_switch;
unsigned int *S1_delay_count;
unsigned char *AD_short_delay_count;
}AD_LIN_one_switch;
typedef struct
{
unsigned int *S1_delay_count;
unsigned char *AD_short_delay_count;
}io_one_switch;
//一路AD两个按键
typedef struct
{
unsigned int *AD_switch_array;
unsigned char AD_channel;
unsigned char *S1_switch;
unsigned char *S2_switch;
unsigned int *S1_delay_count;
unsigned int *S2_delay_count;
unsigned char *AD_short_delay_count;
}AD_LIN_two_switch;
typedef struct
{
unsigned int *AD_switch_array;
unsigned char AD_channel;
unsigned char *S1_switch;
unsigned char *S2_switch;
unsigned char *S3_switch;
unsigned int *S1_delay_count;
unsigned int *S2_delay_count;
unsigned int *S3_delay_count;
unsigned char *AD_short_delay_count;
}AD_LIN_three_switch;
extern unsigned char Sig_LI0_MFL_Tastencode_1,Sig_LI0_MFL_Tastencode_2;
extern unsigned char Sig_LI0_DI_KL_58xs_run;
void Apply_Task(void);
void Lin_Task(void);
void AD_Data_Deal(void);
void Sleep_Command_Rece(void);
void Eventcode_deal(unsigned char Sig_LI0_MFL_Tastencode_1_E,unsigned char Sig_LI0_MFL_Tastencode_2_E);
void Toggle_bit_deal(unsigned char Sig_LI0_MFL_Tastencode_1_E,unsigned char Sig_LI0_MFL_Tastencode_2_E);
void LIN_STANDBY_Mode_wakeup_enable(void);
void CPU_ENTER_STOP_MODE(void);
void LIN_Short_to_12v_Protect(void);
#endif /* DMK_S301_77_H_ */

204
Sources/PWM1.c Normal file
View File

@ -0,0 +1,204 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : PWM1.c
** Project : DMK-BC316-77-AUTO
** Processor : MC9S12ZVL32MLF
** Component : PWM
** Version : Component 02.240, Driver 01.16, CPU db: 3.00.000
** Compiler : CodeWarrior HCS12Z C Compiler
** Date/Time : 2018-03-24, 10:58, # CodeGen: 18
** Abstract :
** This component implements a pulse-width modulation generator
** that generates signal with variable duty and fixed cycle.
** Settings :
** Used output pin :
** ----------------------------------------------------
** Number (on package) | Name
** ----------------------------------------------------
** 39 | PP5_XIRQ_KWP5_PWM5
** ----------------------------------------------------
**
** Timer name : PWM5 [8-bit]
** Counter : PWMCNT5 [0x0491]
** Mode register : PWMCTL [0x0485]
** Run register : PWME [0x0480]
** Prescaler : PWMPRCLK [0x0483]
** Compare 1 register : PWMPER5 [0x0499]
** Compare 2 register : PWMDTY5 [0x04A1]
** Flip-flop 1 register : PWMPOL [0x0481]
**
** User handling procedure : not specified
**
** Output pin
**
** Port name : P
** Bit number (in port) : 5
** Bit mask of the port : 0x0020
** Port data register : PTP [0x02F0]
** Port control register : DDRP [0x02F2]
**
** Runtime setting period : none
** Runtime setting ratio : calculated
** Initialization:
** Aligned : Left
** Output level : low
** Timer : Enabled
** Event : Enabled
** High speed mode
** Prescaler : divide-by-1
** Clock : 53333 Hz
** Initial value of period pulse width (ratio 0%)
** Xtal ticks : 4781 0
** microseconds : 4781 0
** milliseconds : 5 0
** seconds (real) : 0.00478125 0.0
**
** Contents :
** SetRatio16 - byte PWM1_SetRatio16(word Ratio);
** SetDutyUS - byte PWM1_SetDutyUS(word Time);
** SetDutyMS - byte PWM1_SetDutyMS(word Time);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file PWM1.c
** @version 01.16
** @brief
** This component implements a pulse-width modulation generator
** that generates signal with variable duty and fixed cycle.
*/
/*!
** @addtogroup PWM1_module PWM1 module documentation
** @{
*/
/* MODULE PWM1. */
#include "PWM1.h"
#pragma DATA_SEG PWM1_DATA /* Select data segment "PWM1_DATA" */
#pragma CODE_SEG PWM1_CODE
static word RatioStore; /* Ratio of L-level to H-level */
/*
** ===================================================================
** Method : SetRatio (component PWM)
**
** Description :
** The method reconfigures the compare and modulo registers of
** the peripheral(s) when the speed mode changes. The method is
** called automatically as a part of the component
** SetHigh/SetLow/SetSlow methods.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void SetRatio(void)
{
PWMDTY7 = (byte)(((0xFFUL * (dword)RatioStore) + 0x8000UL) >> 0x10U); /* Calculate new value according to the given ratio */
}
/*
** ===================================================================
** Method : PWM1_SetRatio16 (component PWM)
** Description :
** This method sets a new duty-cycle ratio. Ratio is expressed
** as a 16-bit unsigned integer number. Value 0 - 65535 value
** is proportional to ratio 0 - 100%.
** Note: Calculated duty depends on the timer possibilities and
** on the selected period.
** The method is available only if method <SetPeriodMode> is
** not selected.
** Parameters :
** NAME - DESCRIPTION
** Ratio - Ratio to set. 0 - 65535 value is
** proportional to ratio 0 - 100%
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ===================================================================
*/
byte PWM1_SetRatio16(word Ratio)
{
RatioStore = Ratio; /* Store new value of the ratio */
SetRatio(); /* Calculate and set up new appropriate values of the duty and period registers */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : PWM1_Init (component PWM)
**
** Description :
** Initializes the associated peripheral(s) and the component's
** internal variables. The method is called automatically as a
** part of the application initialization code.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void PWM1_Init(void)
{
/* PWMCNT7: PWMCNT7=0 */
setReg8(PWMCNT7, 0x00U); /* Reset Counter */
RatioStore = 0xFFFFU; ; /* Store initial value of the ratio */
/* PWMDTY7: PWMDTY7=0x82 */
setReg8(PWMDTY7, 0x00U); /* Store initial value to the duty-compare register */
/* PWMPER7: PWMPER7=0xFF */
setReg8(PWMPER7, 0xFFU); /* and to the period register */
/* PWMPRCLK: ??=0,PCKB2=0,PCKB1=0,PCKB0=0,??=0,PCKA2=0,PCKA1=0,PCKA0=0 */
setReg8(PWMPRCLK, 0x00U); /* Set prescaler register */
/* PWMSCLB: BIT7=0,BIT6=0,BIT5=0,BIT4=0,BIT3=1,BIT2=1,BIT1=0,BIT0=0 */
setReg8(PWMSCLB, 0x0CU); /* Set scale register */
/* PWMCLK: PCLK7=1 */
setReg8Bits(PWMCLK, 0x80U); /* Select clock source */
/* PWME: PWME7=1 */
setReg8Bits(PWME, 0x80U); /* Run counter */
}
/* END PWM1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale HCS12Z series of microcontrollers.
**
** ###################################################################
*/

168
Sources/PWM1.h Normal file
View File

@ -0,0 +1,168 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : PWM1.h
** Project : DMK-BC316-77-AUTO
** Processor : MC9S12ZVL32MLF
** Component : PWM
** Version : Component 02.240, Driver 01.16, CPU db: 3.00.000
** Compiler : CodeWarrior HCS12Z C Compiler
** Date/Time : 2018-03-24, 10:58, # CodeGen: 18
** Abstract :
** This component implements a pulse-width modulation generator
** that generates signal with variable duty and fixed cycle.
** Settings :
** Used output pin :
** ----------------------------------------------------
** Number (on package) | Name
** ----------------------------------------------------
** 39 | PP5_XIRQ_KWP5_PWM5
** ----------------------------------------------------
**
** Timer name : PWM5 [8-bit]
** Counter : PWMCNT5 [0x0491]
** Mode register : PWMCTL [0x0485]
** Run register : PWME [0x0480]
** Prescaler : PWMPRCLK [0x0483]
** Compare 1 register : PWMPER5 [0x0499]
** Compare 2 register : PWMDTY5 [0x04A1]
** Flip-flop 1 register : PWMPOL [0x0481]
**
** User handling procedure : not specified
**
** Output pin
**
** Port name : P
** Bit number (in port) : 5
** Bit mask of the port : 0x0020
** Port data register : PTP [0x02F0]
** Port control register : DDRP [0x02F2]
**
** Runtime setting period : none
** Runtime setting ratio : calculated
** Initialization:
** Aligned : Left
** Output level : low
** Timer : Enabled
** Event : Enabled
** High speed mode
** Prescaler : divide-by-1
** Clock : 53333 Hz
** Initial value of period pulse width (ratio 0%)
** Xtal ticks : 4781 0
** microseconds : 4781 0
** milliseconds : 5 0
** seconds (real) : 0.00478125 0.0
**
** Contents :
** SetRatio16 - byte PWM1_SetRatio16(word Ratio);
** SetDutyUS - byte PWM1_SetDutyUS(word Time);
** SetDutyMS - byte PWM1_SetDutyMS(word Time);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file PWM1.h
** @version 01.16
** @brief
** This component implements a pulse-width modulation generator
** that generates signal with variable duty and fixed cycle.
*/
/*!
** @addtogroup PWM1_module PWM1 module documentation
** @{
*/
#ifndef __PWM1
#define __PWM1
/* MODULE PWM1. */
#include "derivative.h"
#include "CPU.h"
#pragma CODE_SEG PWM1_CODE
#define PWM1_PERIOD_VALUE 0xFFUL /* Initial period value in ticks of the timer */
#define PWM1_PERIOD_VALUE_HIGH 0xFFUL /* Initial period value in ticks of the timer in high speed mode */
byte PWM1_SetRatio16(word Ratio);
/*
** ===================================================================
** Method : PWM1_SetRatio16 (component PWM)
** Description :
** This method sets a new duty-cycle ratio. Ratio is expressed
** as a 16-bit unsigned integer number. Value 0 - 65535 value
** is proportional to ratio 0 - 100%.
** Note: Calculated duty depends on the timer possibilities and
** on the selected period.
** The method is available only if method <SetPeriodMode> is
** not selected.
** Parameters :
** NAME - DESCRIPTION
** Ratio - Ratio to set. 0 - 65535 value is
** proportional to ratio 0 - 100%
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ===================================================================
*/
void PWM1_Init(void);
/*
** ===================================================================
** Method : PWM1_Init (component PWM)
**
** Description :
** Initializes the associated peripheral(s) and the component's
** internal variables. The method is called automatically as a
** part of the application initialization code.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma CODE_SEG DEFAULT
/* END PWM1. */
#endif /* ifndef __PWM1 */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale HCS12Z series of microcontrollers.
**
** ###################################################################
*/

40
Sources/TI1.c Normal file
View File

@ -0,0 +1,40 @@
#include "TI1.h"
static unsigned int AppliTick=0;
bool app_base_2mStick,app_base_5mStick,app_base_10mStick,app_base_20mStick,app_base_50mStick,app_base_100mStick;
//1msÖжÏ
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vtim1ch0 TI1_OnInterrupt(void)
{
TIM1TC0 += 0x7D00U; /* Add value corresponding with period */
TIM1TFLG1 = 0x01U; /* Reset interrupt request flag */
AppliTick++;
if(AppliTick % 2 == 0)
{
app_base_2mStick = 1;
}
if(AppliTick % 5 == 0)
{
app_base_5mStick = 1;
}
if(AppliTick % 10 == 0)
{
app_base_10mStick = 1;
}
if(AppliTick % 20 == 0)
{
app_base_20mStick = 1;
}
if(AppliTick %50 == 0)
{
app_base_50mStick = 1;
}
if(AppliTick % 100 == 0)
{
app_base_100mStick = 1;
AppliTick=0;
}
}
#pragma CODE_SEG TI1_CODE

8
Sources/TI1.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __TI1
#define __TI1
#include "derivative.h"
extern bool app_base_2mStick,app_base_5mStick,app_base_10mStick,app_base_20mStick,app_base_50mStick,app_base_100mStick;
#endif

142
Sources/WDog1.c Normal file
View File

@ -0,0 +1,142 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : WDog1.c
** Project : DMK-BC316-77-AUTO
** Processor : MC9S12ZVL32MLF
** Component : WatchDog
** Version : Component 02.142, Driver 01.16, CPU db: 3.00.000
** Compiler : CodeWarrior HCS12Z C Compiler
** Date/Time : 2018-01-26, 14:54, # CodeGen: 2
** Abstract :
** This device "WatchDog" implements a watchdog.
** When enabled, the watchdog timer counts until it reaches
** a critical value corresponding to the period specified
** in 'Properties'. Then, the watchdog causes a CPU reset.
** Applications may clear the timer before it reaches the critical
** value. The timer then restarts the watchdog counter.
** Watchdog is used for increasing the safety of the system
** (unforeseeable situations can cause system crash or an
** infinite loop - watchdog can restart the system or handle
** the situation).
**
** Note: Watchdog can be enabled or disabled in the initialization
** code only. If the watchdog is once enabled user have
** to call Clear method in defined time intervals.
** Settings :
** Watchdog causes : Reset CPU
**
** Clock Source : Bus clock
**
** Initial Watchdog state : Enabled
**
** Mode of operation : Normal
**
** High speed mode
** Watchdog period/frequency
** microseconds : 4194304
** milliseconds : 4194
** seconds : 4
**
** Run register : CPMUCOP [0x06CC]
** Mode register : CPMUCOP [0x06CC]
** Prescaler register : CPMUCOP [0x06CC]
** Contents :
** Clear - byte WDog1_Clear(void);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file WDog1.c
** @version 01.16
** @brief
** This device "WatchDog" implements a watchdog.
** When enabled, the watchdog timer counts until it reaches
** a critical value corresponding to the period specified
** in 'Properties'. Then, the watchdog causes a CPU reset.
** Applications may clear the timer before it reaches the critical
** value. The timer then restarts the watchdog counter.
** Watchdog is used for increasing the safety of the system
** (unforeseeable situations can cause system crash or an
** infinite loop - watchdog can restart the system or handle
** the situation).
**
** Note: Watchdog can be enabled or disabled in the initialization
** code only. If the watchdog is once enabled user have
** to call Clear method in defined time intervals.
*/
/*!
** @addtogroup WDog1_module WDog1 module documentation
** @{
*/
/* MODULE WDog1. */
#include "WDog1.h"
#pragma DATA_SEG WDog1_DATA /* Select data segment "WDog1_DATA" */
#pragma CODE_SEG WDog1_CODE
/*
** ===================================================================
** Method : WDog1_Clear (component WatchDog)
** Description :
** Clears the watchdog timer (it makes the timer restart from
** zero).
** Parameters : None
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ERR_DISABLED - The component is disabled
** ===================================================================
*/
void WDog1_Clear(void)
{
CPMUARMCOP = 0x55U;
CPMUARMCOP = 0xAAU;
}
/* END WDog1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale HCS12Z series of microcontrollers.
**
** ###################################################################
*/

145
Sources/WDog1.h Normal file
View File

@ -0,0 +1,145 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : WDog1.h
** Project : DMK-BC316-77-AUTO
** Processor : MC9S12ZVL32MLF
** Component : WatchDog
** Version : Component 02.142, Driver 01.16, CPU db: 3.00.000
** Compiler : CodeWarrior HCS12Z C Compiler
** Date/Time : 2018-01-26, 14:54, # CodeGen: 2
** Abstract :
** This device "WatchDog" implements a watchdog.
** When enabled, the watchdog timer counts until it reaches
** a critical value corresponding to the period specified
** in 'Properties'. Then, the watchdog causes a CPU reset.
** Applications may clear the timer before it reaches the critical
** value. The timer then restarts the watchdog counter.
** Watchdog is used for increasing the safety of the system
** (unforeseeable situations can cause system crash or an
** infinite loop - watchdog can restart the system or handle
** the situation).
**
** Note: Watchdog can be enabled or disabled in the initialization
** code only. If the watchdog is once enabled user have
** to call Clear method in defined time intervals.
** Settings :
** Watchdog causes : Reset CPU
**
** Clock Source : Bus clock
**
** Initial Watchdog state : Enabled
**
** Mode of operation : Normal
**
** High speed mode
** Watchdog period/frequency
** microseconds : 4194304
** milliseconds : 4194
** seconds : 4
**
** Run register : CPMUCOP [0x06CC]
** Mode register : CPMUCOP [0x06CC]
** Prescaler register : CPMUCOP [0x06CC]
** Contents :
** Clear - byte WDog1_Clear(void);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file WDog1.h
** @version 01.16
** @brief
** This device "WatchDog" implements a watchdog.
** When enabled, the watchdog timer counts until it reaches
** a critical value corresponding to the period specified
** in 'Properties'. Then, the watchdog causes a CPU reset.
** Applications may clear the timer before it reaches the critical
** value. The timer then restarts the watchdog counter.
** Watchdog is used for increasing the safety of the system
** (unforeseeable situations can cause system crash or an
** infinite loop - watchdog can restart the system or handle
** the situation).
**
** Note: Watchdog can be enabled or disabled in the initialization
** code only. If the watchdog is once enabled user have
** to call Clear method in defined time intervals.
*/
/*!
** @addtogroup WDog1_module WDog1 module documentation
** @{
*/
#ifndef __WDog1
#define __WDog1
/* MODULE WDog1. */
#include "CPU.h"
#pragma CODE_SEG WDog1_CODE
/*
** ===================================================================
** Method : WDog1_Clear (component WatchDog)
** Description :
** Clears the watchdog timer (it makes the timer restart from
** zero).
** Parameters : None
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ERR_DISABLED - The component is disabled
** ===================================================================
*/
void WDog1_Clear(void);
#pragma CODE_SEG DEFAULT
/* END WDog1. */
#endif /* ifndef __WDog1 */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale HCS12Z series of microcontrollers.
**
** ###################################################################
*/

View File

@ -0,0 +1,143 @@
/*
* diagnostic_DID.c
*
* Created on: Feb 16, 2019
* Author: Administrator
*/
#include "diagnostic_DID.h"
/*******************************配置DID*************************************/
const TYPE_DIDSRVARR DID_CheckArr[DEF_DID_NUM]={
{0xF187, 11, &DIDsrv_ReadPartnumber},
{0xF189, 4, &DIDsrv_ReadSoftwareVersion},
{0xF191, 11, &DIDsrv_ReadPartnumber},
{0xF1A3, 3, &DIDsrv_ReadHardwareVersion},
{0x062E, 3, &DIDsrv_ReadSlaveCoding},
{0x065E, 11, &DIDsrv_ReadPartnumber},
{0x068E, 4, &DIDsrv_ReadSoftwareVersion},
{0x06BE, 11, &DIDsrv_ReadPartnumber},
{0x06EE, 3, &DIDsrv_ReadHardwareVersion},
{0x071E, 20, &DIDsrv_ReadSerialnumber},
{0x074E, 13, &DIDsrv_ReadSystemName},
{0x6031, 3, &DIDsrv_ReadSlaveCoding},
{0x6231, 11, &DIDsrv_ReadPartnumber},
{0x6431, 4, &DIDsrv_ReadSoftwareVersion},
{0x6631, 11, &DIDsrv_ReadPartnumber},
{0x6831, 3, &DIDsrv_ReadHardwareVersion},
{0x6A31, 20, &DIDsrv_ReadSerialnumber},
{0x6C31, 13, &DIDsrv_ReadSystemName},
{0xF15B, 9, &DIDsrv_ReadF15B},
{0xF186, 1, &DIDsrv_ReadF186},
//{0xF198, 13, &DIDsrv_ReadF198},//样件读取错误
//{0xF19E, 16, &DIDsrv_ReadF19E},//数据有风险
{0xF1A2, 6, &DIDsrv_ReadF1A2},
{0xF1DF, 1, &DIDsrv_ReadF1DF},
{0xF18C, 20, &DIDsrv_ReadSerialnumber},
{0xF17C, 23, &DIDsrv_ReadFAZIT},
{0xF197, 13, &DIDsrv_ReadSystemName},
};
//const char DIDList_SWVersion[8]@0xff7000="SW0102";
const char DIDList_SWVersion[4]="0308";
const char DIDList_HWVersion[3]="H04";
const unsigned char DIDList_PartNumber[8]={0x11,0x22,0x33,0x44};
const unsigned char DIDList_ManufacturingData[8]={0x20,0x20,0x07,0x22};
const char DIDList_ECUname[16]={"DMK-BC316-77"};
const char DIDList_PartNum[11]={"5CG959442B "};
const unsigned char DIDList_SlaveCoding[3]={0x24,0x00,0x00};//按照样件改为24 00 00
const char DIDList_SerialNum[20]={"0521910200700191DQ4J"};
const char DIDList_SystemName[13]={"E221__MFL-TAT"};
const char DIDList_F15B[9]={0,1,1,0,0,0,0,0,0};
const char DIDList_F186[1]={1};
const char DIDList_F198[1]={0xff};
const char DIDList_F19E[16]={"EV_MFLTRWVW250GP"};
const char DIDList_F1A2[6]={"001001"};
const char DIDList_F1DF[1]={0x40};
const char DIDList_FAZIT[23]={"S5G-DMG18.11.2400010001"};
/******************************************************************************/
void DIDsrv_ReadSoftwareVersion(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_SWVersion,addr,length);
}
void DIDsrv_ReadFAZIT(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_FAZIT,addr,length);
}
void DIDsrv_ReadHardwareVersion(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_HWVersion,addr,length);
}
void DIDsrv_ReadBootloaderVersion(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)0xfff000,addr,length);
}
void DIDsrv_ReadDMPartNumber(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_PartNumber,addr,length);
}
void DIDsrv_ReadManufacturingData(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_ManufacturingData,addr,length);
}
void DIDsrv_ReadECUname(unsigned char length,unsigned char * addr)
{
//unsigned char conf;
DataCopy8bit((unsigned char *)(DIDList_ECUname[0]),addr,length);
}
void DIDsrv_ReadPartnumber(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_PartNum,addr,length);
}
void DIDsrv_ReadSlaveCoding(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_SlaveCoding,addr,length);
}
void DIDsrv_ReadSerialnumber(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_SerialNum,addr,length);
}
void DIDsrv_ReadSystemName(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_SystemName,addr,length);
}
void DIDsrv_ReadF15B(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_F15B,addr,length);
}
void DIDsrv_ReadF186(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_F186,addr,length);
}
void DIDsrv_ReadF198(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_F198,addr,length);
}
void DIDsrv_ReadF19E(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_F19E,addr,length);
}
void DIDsrv_ReadF1A2(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_F1A2,addr,length);
}
void DIDsrv_ReadF1DF(unsigned char length,unsigned char * addr)
{
DataCopy8bit((unsigned char *)DIDList_F1DF,addr,length);
}
void DataCopy8bit(unsigned char* source,unsigned char* dest,unsigned char length)
{
while(length-- > 0)
{
*(dest++) = *(source++);
}
}

View File

@ -0,0 +1,47 @@
/*
* diagnostic_DID.h
*
* Created on: Feb 16, 2019
* Author: Administrator
*/
#ifndef DIAGNOSTIC_DID_H_
#define DIAGNOSTIC_DID_H_
#include "diagnostic_service_slave.h"
#define DEF_DID_NUM 25
typedef struct
{
unsigned int DID_id;
unsigned char length;
DIDSRVFUNCTION_DEF DID_Func;
}TYPE_DIDSRVARR;
extern const TYPE_DIDSRVARR DID_CheckArr[];
void DIDsrv_ReadSoftwareVersion(unsigned char length,unsigned char * addr);
void DIDsrv_ReadFAZIT(unsigned char length,unsigned char * addr);
void DIDsrv_ReadHardwareVersion(unsigned char length,unsigned char * addr);
void DIDsrv_ReadBootloaderVersion(unsigned char length,unsigned char * addr);
void DIDsrv_ReadDMPartNumber(unsigned char length,unsigned char * addr);
void DIDsrv_ReadManufacturingData(unsigned char length,unsigned char * addr);
void DIDsrv_ReadECUname(unsigned char length,unsigned char * addr);
void DataCopy8bit(unsigned char* source,unsigned char* dest,unsigned char length);
void DIDsrv_ReadPartnumber(unsigned char length,unsigned char * addr);
void DIDsrv_ReadSystemName(unsigned char length,unsigned char * addr);
void DIDsrv_ReadSerialnumber(unsigned char length,unsigned char * addr);
void DIDsrv_ReadSlaveCoding(unsigned char length,unsigned char * addr);
void DIDsrv_ReadF15B(unsigned char length,unsigned char * addr);
void DIDsrv_ReadF186(unsigned char length,unsigned char * addr);
void DIDsrv_ReadF198(unsigned char length,unsigned char * addr);
void DIDsrv_ReadF19E(unsigned char length,unsigned char * addr);
void DIDsrv_ReadF1A2(unsigned char length,unsigned char * addr);
void DIDsrv_ReadF1DF(unsigned char length,unsigned char * addr);
#endif /* DIAGNOSTIC_DID_H_ */

View File

@ -0,0 +1,453 @@
#include "lin_cfg.h"
#include "diagnostic_service_slave.h"
#include "diagnostic_DID.h"
#include "DMK-BC316-77.h"
//extern byte LED_value;
const unsigned long serial_number = SERIAL_NUBER_INT; /* for read & write serial_number services */
const unsigned char io_control_status = IO_CONTROL_STATUS_INT; /* for read & set io */
const unsigned int session_control_P3 = SESSION_CONTROL_P3; /* for session control service */
const unsigned int session_control_P3Ex = SESSION_CONTROL_P3Ex; /* for session control service */
const unsigned char DtcStatusByte = DTCSTATUSBTYE_INT ; /* for fault memory */
const unsigned char DtcFormatIdentifier = DTCFORMATIDENTIFER_INT; /* for fault memory */
const unsigned char CountDtc = COUNTDTC_INT; /* for fault memory */
const TYPE_DIAGSERVICEARR DiagServiceCheckArr[DEF_DIAGSERVICE_COUNT]={
{DIAGSRV_READ_DATA_BY_IDENTIFIER_ORDER,&diagsrv_read_data_by_identifier},//22
{DIAGSRV_WRITE_DATA_BY_IDENTIFIER_ORDER,&diagsrv_write_data_by_identifier},//2E
{DIAGSRV_SESSION_CONTROL_ORDER,&diagsrv_session_control},//10
{DIAGSRV_TESTERPRESENT_ORDER,&diagsrv_tester_present},//3E
{DIAGSRV_ECURESET_ORDER,&diagsrv_ECU_reset},//00
{DIAGSRV_COMMUNICATIONCONTROL_ORDER,&diagsrv_communication_control},//28
{DIAGSRV_ROUTINECONTROL_ORDER,&diagsrv_routine_control},//31
{DIAGSRV_ASSIGN_FRAME_ID_RANGE_ORDER,&diagsrv_B7},//B7
};
/**/
volatile l_u8 master_req_dat[MASTER_REQ_LENGTH_MAX];
volatile l_u16 master_req_length;
volatile l_u8 slave_resp_dat[MASTER_REQ_LENGTH_MAX];
volatile l_u16 slave_resp_length;
l_u8 resetflag=0;
void diagsrv_routine_control(void)
{
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
if(master_req_length != 4)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x13;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
if(master_req_dat[1] == 0x01)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x31;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x12;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
}
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_ROUTINECONTROL_ORDER);
}
void diagsrv_communication_control(void)
{
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
if(master_req_length != 3)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x13;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
if((master_req_dat[1]&0x7f) == 0x00 || (master_req_dat[1]&0x7f) == 0x01)
{
slave_resp_length = 3;
slave_resp_dat[0] = master_req_dat[0] + 0x40;
slave_resp_dat[1] = master_req_dat[1];
slave_resp_dat[2] = master_req_dat[2];
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x31;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
}
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_COMMUNICATIONCONTROL_ORDER);
}
void diagsrv_ECU_reset(void)
{
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
if(master_req_length != 2)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x13;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
if(master_req_dat[1] == 0x01)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x22;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x31;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
}
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_ECURESET_ORDER);
}
void diagsrv_tester_present(void)
{
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
if(master_req_length != 2)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x13;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
if(master_req_dat[1] == 0x00)
{
slave_resp_length = 2;
slave_resp_dat[0] = master_req_dat[0] + 0x40;
slave_resp_dat[1] = master_req_dat[1];
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else if(master_req_dat[1] == 0x80)
{
;//0x80ÎÞÏìÓ¦
}
else
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x31;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
}
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_TESTERPRESENT_ORDER);
}
void diagsrv_read_data_by_identifier(void)
{
/* Implement code of this service here */
unsigned char i;
unsigned int DID_id;
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
DID_id = master_req_dat[1];
DID_id <<= 8;
DID_id |= master_req_dat[2];
if(master_req_length != 3)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x13;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
diag_clear_flag(DIAGSRV_READ_DATA_BY_IDENTIFIER_ORDER);
return;
}
for(i=0;i<DEF_DID_NUM;i++)
{
if(DID_CheckArr[i].DID_id == DID_id)
{
DID_CheckArr[i].DID_Func(DID_CheckArr[i].length,(unsigned char *)slave_resp_dat+3);
slave_resp_length = 3+DID_CheckArr[i].length;
slave_resp_dat[0] = master_req_dat[0] + 0x40;
slave_resp_dat[1] = master_req_dat[1];
slave_resp_dat[2] = master_req_dat[2];
break;
}
}
if(DEF_DID_NUM == i)
{
;/* ·ñ¶¨ÏìÓ¦£¬²»Ö§³ÖÏìÓ¦DID */
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x31;//·ñ¶¨ÏìÓ¦Âë
}
/* get data from queue to data */
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_READ_DATA_BY_IDENTIFIER_ORDER);
}
#ifdef DIAGSRV_WRITE_DATA_BY_IDENTIFIER_ORDER
void diagsrv_write_data_by_identifier(void)
{
unsigned char conf,i;
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
/* process data */
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x31;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_WRITE_DATA_BY_IDENTIFIER_ORDER);
}
#endif
void diagsrv_session_control(void)
{
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
if(master_req_length != 2)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x13;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
if(master_req_dat[1] == 0x02)
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x22;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else if(master_req_dat[1] == 0x03)
{
slave_resp_length = 6;
slave_resp_dat[0] = master_req_dat[0] + 0x40;
slave_resp_dat[1] = master_req_dat[1];
slave_resp_dat[2] = 0x00;
slave_resp_dat[3] = 0x32;
slave_resp_dat[4] = 0x27;
slave_resp_dat[5] = 0x10;
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else if(master_req_dat[1] == 0x83)
{
;// 0x80 ÎÞÏìÓ¦
}
else
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x31;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
}
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_ECURESET_ORDER);
diag_clear_flag(DIAGSRV_SESSION_CONTROL_ORDER);
}
void diagsrv_io_control_by_identifier(void)
{
/* process recieved data from master request */
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
diag_clear_flag(DIAGSRV_IO_CONTROL_BY_IDENTIFIER_ORDER);
}
void diagsrv_fault_memory_read(void)
{
ld_receive_message((l_u16*)&master_req_length,(l_u8*)master_req_dat);
/* Implement code of this service here */
slave_resp_dat[0] = master_req_dat[0] + 0x40;
slave_resp_dat[1] = master_req_dat[1];
slave_resp_dat[2] = master_req_dat[2];
slave_resp_dat[3] = DtcStatusByte;
slave_resp_dat[4] = DtcFormatIdentifier;
slave_resp_dat[5] = CountDtc;
slave_resp_length = 0x06;
/* send a message to master */
ld_send_message((l_u16)slave_resp_length,(l_u8*)slave_resp_dat);
/*clear diagnostic flag */
lin_diag_services_flag[DIAGSRV_FAULT_MEMORY_READ_ORDER] = 0;
}
void diagsrv_fault_memory_clear(void)
{
ld_receive_message((l_u16*)&master_req_length,(l_u8*)master_req_dat);
/* Implement code of this service here */
slave_resp_dat[0] = master_req_dat[0] + 0x40;
slave_resp_dat[1] = master_req_dat[1];
slave_resp_dat[2] = master_req_dat[2];
slave_resp_length = 0x03;
/* Implement code of this service here */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
/*clear diagnostic flag */
diag_clear_flag(DIAGSRV_FAULT_MEMORY_CLEAR_ORDER);
//lin_diag_services_flag[DIAGSRV_FAULT_MEMORY_CLEAR_ORDER] = 0;
}
void diagsrv_B7(void)
{
ld_receive_message((l_u16*)&master_req_length, (l_u8*)master_req_dat);
if(master_req_length == 0x06)
{
slave_resp_length = 2;
slave_resp_dat[0] = master_req_dat[0] + 0x40;
slave_resp_dat[1] = master_req_dat[1];
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
else
{
slave_resp_length = 3;
slave_resp_dat[0] = 0x7F;
slave_resp_dat[1] = master_req_dat[0];
slave_resp_dat[2] = 0x13;//·ñ¶¨ÏìÓ¦Âë
/* send a message to master */
ld_send_message((l_u16)slave_resp_length, (l_u8*)slave_resp_dat);
}
diag_clear_flag(DIAGSRV_ASSIGN_FRAME_ID_RANGE_ORDER);
}
void diagsrv_security_access(void)
{
}
void diagsrv_send_data(void)
{
ld_receive_message((l_u16*)&master_req_length,(l_u8*)master_req_dat);
}
void diagsrv_download_request(void)
{
}
//extern volatile l_signal_handle slave_signal_handle;
extern volatile l_u8* slave_sig_data;
extern volatile unsigned char sw_flag;
void slave_diagnostic_task()
{
unsigned char i = 0x00;
unsigned char data;
for (i = 0; i < DEF_DIAGSERVICE_COUNT; i++)
{
if (diag_get_flag(DiagServiceCheckArr[i].DiagServiceFlagOrder))
{
DiagServiceCheckArr[i].DiagServiceFunc();
}
}
}
void SoftwareRest(void)
{
CPMUARMCOP = 0xff;
while(1);
}
void slave_diagnostic_init(void)
{
;
}
void SaveArray_LINResp(unsigned char * buf)
{
unsigned char i;
}
void ReadArray_LINResp(unsigned char * buf)
{
unsigned char i;
}
void SetConfiguration(unsigned char conf)
{
}
void resetDetect(void)
{
static resetcnt;
if(resetflag == 1)
{
resetcnt++;
if(resetcnt>10)
SoftwareRest();
}
else
{
resetcnt=0;
}
}

View File

@ -0,0 +1,57 @@
#ifndef _DIAGNOSTIC_SERVICE_SLAVE_H_
#define _DIAGNOSTIC_SERVICE_SLAVE_H_
#include "lin_commontl_api.h"
#include "lin.h"
#include "lin_lin21tl_api.h"
/*------------------------------------------*/
#define SERIAL_NUBER_INT 0x00
#define IO_CONTROL_STATUS_INT 0x00
#define SESSION_CONTROL_P3 0x01F4
#define SESSION_CONTROL_P3Ex 0x09C4
#define DTCSTATUSBTYE_INT 0x00
#define DTCFORMATIDENTIFER_INT 0x01
#define COUNTDTC_INT 0x00
/*------------------------------------------*/
/* DEFINITION */
#define MASTER_REQ_LENGTH_MAX 64
#define DEF_DIAGSERVICE_COUNT 8
/*------------------- Struct Define -----------------------*/
typedef void (*PT2FUNCTION_DEF)(void);
typedef void (*DIDSRVFUNCTION_DEF)(unsigned char,unsigned char*);
typedef struct
{
unsigned char DiagServiceFlagOrder;
PT2FUNCTION_DEF DiagServiceFunc;
}TYPE_DIAGSERVICEARR;
/* diagnostic services class II */
void diagsrv_read_data_by_identifier(void);
void diagsrv_write_data_by_identifier(void);
void diagsrv_session_control(void);
void diagsrv_io_control_by_identifier(void);
void diagsrv_fault_memory_read(void);
void diagsrv_fault_memory_clear(void);
void diagsrv_download_request(void);
void diagsrv_send_data(void);
void diagsrv_security_access(void);
void slave_diagnostic_task(void);
void SoftwareRest(void);
void slave_diagnostic_init(void);
void SaveArray_LINResp(unsigned char * buf);
void ReadArray_LINResp(unsigned char * buf);
unsigned char GetConfiguration(void);
void SetConfiguration(unsigned char c);
void resetDetect(void);
void diagsrv_routine_control(void);
void diagsrv_communication_control(void);
void diagsrv_ECU_reset(void);
void diagsrv_tester_present(void);
void diagsrv_B7(void);
#endif /* End _DIAGNOSTIC_SERVICE_SLAVE_H_ */

33
Sources/main.c Normal file
View File

@ -0,0 +1,33 @@
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "DMK-BC316-77.h"
#include "diagnostic_service_slave.h"
l_bool FLAG_GO_TO_Sleep=0;//进入睡眠模式标志
l_bool M_ASK_S_Sleep=0;//主机叫子机进入休眠
l_bool NO_DATA_Sleep=0;//超时睡眠
extern unsigned char Toggle_start;
extern unsigned char Toggle_1s;
/*
* Internal Clock 64MHz
* Bus Clock 32MHz
*
*/
void main(void)
{
CLK_CONFIG();
Peripheral_Init();
l_sys_init();
l_ifc_init(LI0);
ld_init();
LIN_STANDBY_Mode_wakeup_enable();
V_12_Ctrl=1;
Toggle_start=2;
Toggle_1s=0;
while(1)
{
Apply_Task();
Lin_Task();
slave_diagnostic_task();
WDog1_Clear();
}
}

View File

@ -0,0 +1,169 @@
/*---------GLOBAL DEFINITIONS-----------*/
LIN_description_file;
LIN_protocol_version = "2.1";
LIN_language_version = "2.1";
LIN_speed = 19.2 kbps;
/* ----------NODE DEFINITIONS---------- */
Nodes {
Master:
GW, /* Master node name */
5.0 ms, /* Time base */
0.1 ms; /* Jitter */
Slaves:
MFL;
}
/* ----------SIGNAL DEFINITIONS---------- */
Signals {
/* Signal_name : Size, Init, Publisher, Subscriber(s) */
MFL_Zaehler : 4, 0x0, MFL, GW;
MFL_Toggle : 1, 0x0, MFL, GW;
MFL_Lokalaktiv : 1, 0x0, MFL, GW;
MFL_M_Taste : 1, 0x0, MFL, GW;
void : 1, 0x0, MFL, GW;
MFL_Tastencode_1 : 8, 0x0, MFL, GW;
MFL_Tastencode_2 : 8, 0x0, MFL, GW;
MFL_Eventcode_1 : 4, 0x0, MFL, GW;
MFL_Eventcode_2 : 4, 0x0, MFL, GW;
MFL_Marke : 4, 0x0, MFL, GW;
MFL_Variante : 4, 0x0, MFL, GW;
MFL_Dummy_0_Signal_1 : 8, 0x0, MFL, GW;
MFL_Tip_Down : 1, 0x0, MFL, GW;
MFL_Tip_Up : 1, 0x0, MFL, GW;
MFL_SatModul_links_Err : 1, 0x0, MFL, GW;
MFL_SatModul_rechts_Err : 1, 0x0, MFL, GW;
MFL_Dummy_0_Signal_2 : 1, 0x0, MFL, GW;
MFL_Dummy_0_Signal_3 : 1, 0x0, MFL, GW;
MFL_LR_HZG_Status : 1, 0x0, MFL, GW;
MFL_LR_HZG_Err : 1, 0x0, MFL, GW;
MFL_Signalhorn : 1, 0x0, MFL, GW;
MFL_Signalhorn_Err : 1, 0x0, MFL, GW;
MFL_Tip_links_Err : 1, 0x0, MFL, GW;
MFL_Tip_rechts_Err : 1, 0x0, MFL, GW;
MFL_Taste_links_Err : 1, 0x0, MFL, GW;
MFL_Taste_rechts_Err : 1, 0x0, MFL, GW;
MFL_ECU_Err : 1, 0x0, MFL, GW;
MFL_Response_Err : 1, 0x0, MFL, GW;
DI_KL_58xs : 7, 0x0, GW, MFL;
DI_Emblem : 1, 0x0, GW, MFL;
Klemme_15_MFL : 1, 0x0, GW, MFL;
void_1 : 6, 0x0, GW, MFL;
Dimmung_01_gueltig : 1, 0x0, GW, MFL;
DI_KL_58xt : 7, 0x0, GW, MFL;
void_2 : 1, 0x0, GW, MFL;
void_3 : 7, 0x0, GW, MFL;
P_Mode_MFL : 1, 0x0, GW, MFL;
}
/* ----------DIAGNOSTIC SIGNAL DEFINITIONS---------- */
Diagnostic_signals {
/* MasterReq Reserved Signals */
MasterReqB0 : 8, 0;
MasterReqB1 : 8, 0;
MasterReqB2 : 8, 0;
MasterReqB3 : 8, 0;
MasterReqB4 : 8, 0;
MasterReqB5 : 8, 0;
MasterReqB6 : 8, 0;
MasterReqB7 : 8, 0;
/* SlaveResp Reserved Signals */
SlaveRespB0 : 8, 0;
SlaveRespB1 : 8, 0;
SlaveRespB2 : 8, 0;
SlaveRespB3 : 8, 0;
SlaveRespB4 : 8, 0;
SlaveRespB5 : 8, 0;
SlaveRespB6 : 8, 0;
SlaveRespB7 : 8, 0;
}
/* ----------UNCONDITIONAL FRAME DEFINITIONS---------- */
Frames {
MFLs_01 : 0xe, MFL , 8 {
MFL_Zaehler , 0;
MFL_Toggle , 4;
MFL_Lokalaktiv , 5;
MFL_M_Taste , 6;
void , 7;
MFL_Tastencode_1 , 8;
MFL_Tastencode_2 , 16;
MFL_Eventcode_1 , 24;
MFL_Eventcode_2 , 28;
MFL_Marke , 32;
MFL_Variante , 36;
MFL_Dummy_0_Signal_1, 40;
MFL_Tip_Down , 48;
MFL_Tip_Up , 49;
MFL_SatModul_links_Err, 50;
MFL_SatModul_rechts_Err, 51;
MFL_Dummy_0_Signal_2, 52;
MFL_Dummy_0_Signal_3, 53;
MFL_LR_HZG_Status , 54;
MFL_LR_HZG_Err , 55;
MFL_Signalhorn , 56;
MFL_Signalhorn_Err , 57;
MFL_Tip_links_Err , 58;
MFL_Tip_rechts_Err , 59;
MFL_Taste_links_Err , 60;
MFL_Taste_rechts_Err, 61;
MFL_ECU_Err , 62;
MFL_Response_Err , 63;
}
MFLe_01 : 0xd, GW , 4 {
DI_KL_58xs , 0;
DI_Emblem , 7;
Klemme_15_MFL , 8;
void_1 , 9;
Dimmung_01_gueltig , 15;
DI_KL_58xt , 16;
void_2 , 23;
void_3 , 24;
P_Mode_MFL , 31;
}
}
/* ----------DIAGNOSTIC FRAME DEFINITIONS---------- */
Diagnostic_frames {
MasterReq : 0x3c {
MasterReqB0 , 0;
MasterReqB1 , 8;
MasterReqB2 , 16;
MasterReqB3 , 24;
MasterReqB4 , 32;
MasterReqB5 , 40;
MasterReqB6 , 48;
MasterReqB7 , 56;
}
SlaveResp : 0x3d {
SlaveRespB0 , 0;
SlaveRespB1 , 8;
SlaveRespB2 , 16;
SlaveRespB3 , 24;
SlaveRespB4 , 32;
SlaveRespB5 , 40;
SlaveRespB6 , 48;
SlaveRespB7 , 56;
}
}
/* ----------NODE ATTRIBUTE DEFINITIONS---------- */
Node_attributes {
MFL {
LIN_protocol = "2.1"; /* Node protocol version */
configured_NAD = 0xa; /* configured NAD of node (1-125) */
initial_NAD = 0xa; /* initial NAD of node (1-125) */
product_id = 0xb, 0x1, 0xff; /* Product id */
response_error = MFL_Response_Err; /* Response error signal */
P2_min = 50 ms; /* P2_min */
ST_min = 10 ms; /* ST_min */
N_As_timeout = 1000 ms; /* N_As timeout value */
N_Cr_timeout = 1000 ms; /* N_Cr timeout value */
configurable_frames {
MFLe_01;
MFLs_01;
}
}
}
/* ----------SCHEDULE TABLE DEFINITIONS---------- */
Schedule_tables {
Dynamic {
MFLs_01 delay 10.0 ms;
MFLe_01 delay 10.0 ms;
}
}

View File

@ -0,0 +1,49 @@
/*** GENERAL DEFINITION ***/
LIN_node_config_file;
/*** MCU DEFINITION ***/
mcu {
mcu_name = MC9S12ZVL32;
bus_clock = 32000000; /* Frequency bus of system Hz*/
xgate_support = no; /* Support XGATE Co-Processor */
}
/*** LIN HARDWARE DEFINITION ***/
/* Sci config */
sci {
S12_sci0{
sci_channel = 0;
}
}
/*** NETWORK DEFINITION ***/
network {
idle_timeout = 4 s;
time_period = 500 us;
diagnostic_class = 3;
resynchronization_support = no;
autobaud_support = no;
max_message_length = 64;
LI0 {
node = MFL; /* Name of node described in LDF (must check consistence with LDF) */
file = "LDF_DMK-BC316-77.ldf"; /* Name of LDF file */
device = S12_sci0;
support_sid {
READ_BY_IDENTIFIER = 0xb2;
SAVE_CONFIGURATION = 0xb6;
ASSIGN_FRAME_ID_RANGE = 0xb7;
READ_DATA_BY_IDENTIFIER = 0x22;
SESSION_CONTROL = 0x10;
IO_CONTROL_BY_IDENTIFIER = 0x2f;
FAULT_MEMORY_READ = 0x19;
FAULT_MEMORY_CLEAR = 0x14;
WRITE_DATA_BY_IDENTIFIER = 0x2e;
RoutineControl = 0x31;
CommunicationControl = 0x28;
ECUReset = 0x11;
TesterPresent = 0x3e;
ASSIGN_FRAME_IDENTIFIER = 0xb1;
}
}
}

226
lin_cfg/lin_cfg.c Normal file
View File

@ -0,0 +1,226 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2024 NXP
* ALL RIGHTS RESERVED.
*
****************************************************************************//*!
*
* @file lin_cfg.c
*
* @author FPT Software
*
* @version 1.0
*
* @date Tue Nov 19 16:50:38 GMT+08:00 2024
*
* @brief Common LIN configuration, data structure
*
******************************************************************************/
#include "lin_cfg.h"
#include "lin.h"
/* Mapping interface with hardware */
const lin_hardware_name lin_virtual_ifc = SCI0;
l_u8 lin_lld_response_buffer[10];
l_u8 lin_successful_transfer;
l_u8 lin_error_in_response;
l_u8 lin_goto_sleep_flg;
/* Save configuration flag */
l_u8 lin_save_configuration_flg = 0;
lin_word_status_str lin_word_status;
l_u8 lin_current_pid;
const l_signal_handle LI0_response_error_signal = LI0_MFL_Response_Err;
volatile l_u8 buffer_backup_data[8];
/* definition and initialization of signal array */
l_u8 lin_pFrameBuf[LIN_FRAME_BUF_SIZE] =
{
0x00 /* 0 : 00000000 */ /* start of frame LI0_MFLs_01 */
,0x00 /* 1 : 00000000 */
,0x00 /* 2 : 00000000 */
,0x00 /* 3 : 00000000 */
,0x00 /* 4 : 00000000 */
,0x00 /* 5 : 00000000 */
,0x00 /* 6 : 00000000 */
,0x00 /* 7 : 00000000 */
,0x00 /* 8 : 00000000 */ /* start of frame LI0_MFLe_01 */
,0x00 /* 9 : 00000000 */
,0x00 /* 10 : 00000000 */
,0x00 /* 11 : 00000000 */
};
/* definition and initialization of signal array */
l_u8 lin_flag_handle_tbl[LIN_FLAG_BUF_SIZE] =
{
0xFF /* 0: start of flag frame LI0_MFLs_01 */
,0xFF /* 1: */
,0xFF /* 2: */
,0xFF /* 3: */
,0xFF /* 4: start of flag frame LI0_MFLe_01 */
,0xFF /* 5: */
};
/*************************** Flag set when signal is updated ******************/
/* Diagnostic signal */
l_u8 lin_diag_signal_tbl[16];
/*****************************event trigger frame*****************************/
/********************************** Frame table **********************************/
const lin_frame_struct lin_frame_tbl[LIN_NUM_OF_FRMS] ={
{ LIN_FRM_UNCD, 8, LIN_RES_PUB, 0, 0, 4 , (l_u8*)&LI0_response_error_signal }
,{ LIN_FRM_UNCD, 4, LIN_RES_SUB, 8, 4, 2 , (l_u8*)0 }
,{ LIN_FRM_DIAG, 8, LIN_RES_SUB, 0, 0, 0 , (l_u8*)0 }
,{ LIN_FRM_DIAG, 8, LIN_RES_PUB, 0, 0, 0 , (l_u8*)0 }
};
/*********************************** Frame flag Initialization **********************/
/*************************** Frame flag for send/receive successfully ***************/
l_bool lin_frame_flag_tbl[LIN_NUM_OF_FRMS] = {0, 0, 0, 0};
/*************************** Frame flag for updating signal in frame ****************/
volatile l_u8 lin_frame_updating_flag_tbl[LIN_NUM_OF_FRMS] = {0, 0, 0, 0};
/**************************** Lin configuration Initialization ***********************/
/* max_response_frame_timeout = round((1.4x(10+Nx10)xTbit)/Tbase_period) + 3 */
const l_u16 lin_max_frame_res_timeout_val[8]={
6, 7, 8, 8, 12, 13, 15, 16
};
l_u8 lin_configuration_RAM[LIN_SIZE_OF_CFG]= {0x00, 0x0E, 0x0D, 0x3C, 0x3D ,0xFF};
const l_u16 lin_configuration_ROM[LIN_SIZE_OF_CFG]= {0x00, 0x0E, 0x0D, 0x3C, 0x3D ,0xFFFF};
/***************************************** Node Attribute*****************************************/
l_u8 lin_configured_NAD = 0x0A; /*<configured_NAD>*/
const l_u8 lin_initial_NAD =0x0A; /*<initial_NAD>*/
const lin_product_id product_id = {0x000B, 0x0001, 0x00FF}; /* {<supplier_id>,<function_id>,<variant>} */
const l_signal_handle response_error = LI0_MFL_Response_Err;
const l_u8 num_frame_have_esignal = 1; /*number of frame contain error signal*/
const l_u16 lin_response_error_byte_offset[1] = {LIN_BYTE_OFFSET_LI0_MFL_Response_Err}; /*<interface_name>_< response_error>*/
const l_u8 lin_response_error_bit_offset[1] = {LIN_BIT_OFFSET_LI0_MFL_Response_Err}; /*<interface_name>_< response_error>*/
/************************** TL Layer and Diagnostic: SINGLE interface **************************/
/* QUEUE information */
lin_tl_pdu_data tl_tx_queue_data[MAX_QUEUE_SIZE]; /*transmit queue data */
lin_tl_pdu_data tl_rx_queue_data[MAX_QUEUE_SIZE]; /*receive queue data */
lin_transport_layer_queue lin_tl_tx_queue = {
0, /* the first element of queue */
0, /* the last element of queue */
LD_QUEUE_EMPTY, /* status of queue */
0, /* curernt size of queue */
MAX_QUEUE_SIZE, /* size of queue */
tl_tx_queue_data, /* data of queue */
};
lin_transport_layer_queue lin_tl_rx_queue = {
0, /* the first element of queue */
0, /* the last element of queue */
LD_QUEUE_EMPTY, /* status of queue */
0, /* curernt size of queue */
MAX_QUEUE_SIZE, /* size of queue */
tl_rx_queue_data, /* data of queue */
};
/* message information in transmit queue */
l_u16 tl_rx_msg_index; /* index of message in queue */
l_u16 tl_rx_msg_size; /* Size of message in queue */
/* message information in receive queue */
l_u16 tl_tx_msg_index; /* index of message in queue */
l_u16 tl_tx_msg_size; /* Size of message in queue */
lin_last_cfg_result tl_last_cfg_result; /* Status of the last configuration service in LIN 2.0, J2602 */
l_u8 tl_last_RSID; /* RSID of the last node configuration service */
l_u8 tl_ld_error_code; /* Error code in case of positive response */
l_u8 tl_no_of_pdu; /* number of received pdu */
l_u8 tl_frame_counter; /* frame counter in received message */
lin_message_timeout_type tl_check_timeout_type; /* timeout type */
l_u16 tl_check_timeout; /* timeout counter*/
l_u8 *tl_ident_data; /* To store address of RAM area contain response */
lin_diagnostic_state tl_diag_state = LD_DIAG_IDLE;
lin_service_status tl_service_status = LD_SERVICE_IDLE ; /* service status */
lin_message_status tl_receive_msg_status; /* receive message status */
lin_message_status tl_rx_msg_status; /* cooked rx status */
lin_message_status tl_tx_msg_status; /* cooked tx status */
/****************************Support SID Initialization ***********************/
const l_u8 lin_diag_services_supported[_DIAG_NUMBER_OF_SERVICES_] = {0xB2,0xB6,0xB7,0x22,0x10,0x2F,0x19,0x14,0x2E,0x31,0x28,0x11,0x3E,0xB1};
l_u8 lin_diag_services_flag[_DIAG_NUMBER_OF_SERVICES_] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
l_u8 tl_slaveresp_cnt = 0;
/*This ld_read_by_id_callout() function is used when the master node transmits a read by
identifier request with an identifier in the user defined area (id from 32 to 63).
The driver will call this function when such request is received.
* id: the identifier in the user defined area (32 to 63)
* data: pointer points to a data area with 5 bytes, used to give the positive response.
Driver uses 0xFF "do not care value" for unassigned data values.
Data length in PCI is (1 + number of assigned meaningful data values).
Driver will take as data for all data before and including the last value in the frame that is different from 0xFF.
PCI is 0x02-0x06, so data should have at least one value different from 0xFF.
For example, a response frame, (NAD) (PCI) (0xF2) (0xFF) (0x00) (0xFF) (0xFF) (0xFF),
PCI will be 0x03, since in this case driver takes all data before 0x00 and 0x00 as meaningful data,
and values after 0x00 are do not care value.
* return: LD_NEGATIVE_RESPONSE Respond with a negative response.
LD_POSTIVE_RESPONSE Respond with a positive response.
LD_ID_NO_RESPONSE The slave node will not answer.
*/
l_u8 ld_read_by_id_callout(l_u8 id, l_u8 *data)
{
l_u8 retval = LD_NEGATIVE_RESPONSE;
/* Following code is an example - Real implementation is application-dependent */
/* This example implement with ID = 32 - LIN_READ_USR_DEF_MIN */
if (id == LIN_READ_USR_DEF_MIN)
{
/* id received is user defined 32 */
data[0] = (l_u8) (id + 1); /* Data user define */
data[1] = (l_u8) (id + 2); /* Data user define */
data[2] = (l_u8) (id + 3); /* Data user define */
data[3] = (l_u8) (id + 4); /* Data user define */
data[4] = (l_u8) (id + 5); /* Data user define */
retval = LD_POSITIVE_RESPONSE;
}
else
{
/* other identifiers, respond with negative response by default*/
}
return retval;
}

1415
lin_cfg/lin_cfg.h Normal file

File diff suppressed because it is too large Load Diff

92
lin_cfg/lin_hw_cfg.h Normal file
View File

@ -0,0 +1,92 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2024 NXP
* ALL RIGHTS RESERVED.
*
****************************************************************************//*!
*
* @file lin_hw_cfg.h
*
* @author FPT Software
*
* @version 1.0
*
* @date Tue Nov 19 16:50:38 GMT+08:00 2024
*
* @brief Hardware configuration file
*
******************************************************************************/
#ifndef _LIN_HW_CFG_H
#define _LIN_HW_CFG_H
#include <MC9S12ZVL32.h>
typedef enum {
SCI0,
SCI1,
SCI2,
SCI3,
SCI4,
SCI5,
GPIO,
SLIC
} lin_hardware_name;
/* MCU type definition */
#define _S08_ 0
#define _S12_ 1
#define _S12X_ 2
#define _K_ 3
#define SCI_V2 0
#define SCI_V4 1
#define SCI_V5 2
#define SCI_V6 3
/* SCI version */
#define SCI_VERSION SCI_V6
/* Type of MCU */
#define _MCU_ _S12_
/* Resynchronization support */
#define __RESYN_EN 0
/* Autobaud support */
#define AUTOBAUD 0
/* Interface type that MCU uses */
#define XGATE_SUPPORT 0
#define _LIN_XGATE_ 0
#define _LIN_SCI_ 1
#define _LIN_UART_ 0
#define _LIN_SLIC_ 0
#define _LIN_GPIO_ 0
/*********** SCI HARDWARE SECTION *********/
#define NUM_OF_SCI_CHANNEL 2
/* SCI Base Register definition */
#define SCI0_ADDR 0x0700
#define SCI1_ADDR 0x0710
/* Use SCI Channel */
#define _SCI0_ 1
#define _SCI1_ 0
#define _SCI2_ 0
#define _SCI3_ 0
#define _SCI4_ 0
#define _SCI5_ 0
/* MCU bus frequency */
#define MCU_BUS_FREQ 32000000
/* Default interrupt period of the timer for LIN is TIME_BASE_PERIOD micro seconds */
#define TIME_BASE_PERIOD 500
/* max idle timeout for all networks = idle_timeout_value*1000000/time_base_period */
#define _MAX_IDLE_TIMEOUT_ 8000 /* idle_timeout_value = 4s */
#endif