Add KBOOT.

This commit is contained in:
László Monda
2016-08-10 01:45:15 +02:00
commit e6c1fce5b4
9392 changed files with 3751375 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:blhost.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blhost", "src\blhost.vcxproj", "{A498A89A-E965-4B36-B926-850AABF31939}"
ProjectSection(ProjectDependencies) = postProject
{DE64A8C3-695A-491F-B3E3-24D6A3057A40} = {DE64A8C3-695A-491F-B3E3-24D6A3057A40}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blfwk", "..\..\apps\common\blfwk\blfwk.vcxproj", "{DE64A8C3-695A-491F-B3E3-24D6A3057A40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A498A89A-E965-4B36-B926-850AABF31939}.Debug|Win32.ActiveCfg = Debug|Win32
{A498A89A-E965-4B36-B926-850AABF31939}.Debug|Win32.Build.0 = Debug|Win32
{A498A89A-E965-4B36-B926-850AABF31939}.Release|Win32.ActiveCfg = Release|Win32
{A498A89A-E965-4B36-B926-850AABF31939}.Release|Win32.Build.0 = Release|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|Win32.ActiveCfg = Debug|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|Win32.Build.0 = Debug|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|Win32.ActiveCfg = Release|Win32
{DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,216 @@
#-----------------------------------------------
# Make command:
# make build=<build> all
# <build>: debug or release, release by default.
#-----------------------------------------------
#-----------------------------------------------
# setup variables
# ----------------------------------------------
BOOT_ROOT := $(abspath ../../..)
OUTPUT_ROOT := $(abspath ./)
APP_NAME = blhost
#-----------------------------------------------
# Debug or Release
# Release by default
#-----------------------------------------------
build ?= release
include $(BOOT_ROOT)/mk/common.mk
#-----------------------------------------------
# Include path. Add the include paths like this:
# INCLUDES += ./include/
#-----------------------------------------------
INCLUDES += $(BOOT_ROOT)/validation/blhost/src \
$(BOOT_ROOT)/src \
$(BOOT_ROOT)/src/include \
$(BOOT_ROOT)/src/blfwk \
$(BOOT_ROOT)/src/sbloader \
$(BOOT_ROOT)/src/bootloader \
$(BOOT_ROOT)/src/crc \
$(BOOT_ROOT)/src/packet \
$(BOOT_ROOT)/src/property \
$(BOOT_ROOT)/src/drivers/common \
$(BOOT_ROOT)/src/bm_usb
CXXFLAGS := -D LINUX -D BOOTLOADER_HOST -std=c++11
CFLAGS := -std=c99 -D LINUX -D BOOTLOADER_HOST -D _GNU_SOURCE
LD := g++
SOURCES := $(BOOT_ROOT)/validation/blhost/src/blhost.cpp \
$(BOOT_ROOT)/src/blfwk/src/Blob.cpp \
$(BOOT_ROOT)/src/blfwk/src/Bootloader.cpp \
$(BOOT_ROOT)/src/blfwk/src/BusPal.cpp \
$(BOOT_ROOT)/src/blfwk/src/BusPalPeripheral.cpp \
$(BOOT_ROOT)/src/blfwk/src/Command.cpp \
$(BOOT_ROOT)/src/blfwk/src/DataSource.cpp \
$(BOOT_ROOT)/src/blfwk/src/DataSourceImager.cpp \
$(BOOT_ROOT)/src/blfwk/src/DataTarget.cpp \
$(BOOT_ROOT)/src/blfwk/src/ELFSourceFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/ExcludesListMatcher.cpp \
$(BOOT_ROOT)/src/blfwk/src/format_string.cpp \
$(BOOT_ROOT)/src/blfwk/src/GHSSecInfo.cpp \
$(BOOT_ROOT)/src/blfwk/src/GlobMatcher.cpp \
$(BOOT_ROOT)/src/blfwk/src/hid-linux.c \
$(BOOT_ROOT)/src/blfwk/src/jsoncpp.cpp \
$(BOOT_ROOT)/src/blfwk/src/Logging.cpp \
$(BOOT_ROOT)/src/blfwk/src/options.cpp \
$(BOOT_ROOT)/src/blfwk/src/SBSourceFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/SearchPath.cpp \
$(BOOT_ROOT)/src/blfwk/src/serial.c \
$(BOOT_ROOT)/src/blfwk/src/SerialPacketizer.cpp \
$(BOOT_ROOT)/src/blfwk/src/SourceFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/SRecordSourceFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/IntelHexSourceFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/StELFFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/StExecutableImage.cpp \
$(BOOT_ROOT)/src/blfwk/src/StSRecordFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/StIntelHexFile.cpp \
$(BOOT_ROOT)/src/blfwk/src/Updater.cpp \
$(BOOT_ROOT)/src/blfwk/src/UartPeripheral.cpp \
$(BOOT_ROOT)/src/blfwk/src/UsbHidPacketizer.cpp \
$(BOOT_ROOT)/src/blfwk/src/UsbHidPeripheral.cpp \
$(BOOT_ROOT)/src/blfwk/src/utils.cpp \
$(BOOT_ROOT)/src/blfwk/src/Value.cpp \
$(BOOT_ROOT)/src/crc/src/crc16.c \
$(BOOT_ROOT)/src/crc/src/crc32.c \
#$(BOOT_ROOT)/src/blfwk/src/Simulator.cpp
#$(BOOT_ROOT)/src/blfwk/src/SimulatorMemory.cpp
#$(BOOT_ROOT)/src/blfwk/src/SimPacketizer.cpp
#$(BOOT_ROOT)/src/blfwk/src/SimPeripheral.cpp
#$(BOOT_ROOT)/src/bootloader/src/command.cpp
#$(BOOT_ROOT)/src/sbloader/src/sbloader.c
#$(BOOT_ROOT)/src/property/src/property.c
#$(BOOT_ROOT)/src/memory/src/memory.c
#$(BOOT_ROOT)/src/bootloader/src/bootloader_context.cpp
INCLUDES := $(foreach includes, $(INCLUDES), -I $(includes))
ifeq "$(build)" "debug"
DEBUG_OR_RELEASE := Debug
CFLAGS += -g
CXXFLAGS += -g
LDFLAGS += -g
else
DEBUG_OR_RELEASE := Release
endif
TARGET_OUTPUT_ROOT := $(OUTPUT_ROOT)/$(DEBUG_OR_RELEASE)
MAKE_TARGET := $(TARGET_OUTPUT_ROOT)/$(APP_NAME)
OBJS_ROOT = $(TARGET_OUTPUT_ROOT)/obj
# Strip sources.
SOURCES := $(strip $(SOURCES))
# Convert sources list to absolute paths and root-relative paths.
SOURCES_ABS := $(foreach s,$(SOURCES),$(abspath $(s)))
SOURCES_REL := $(subst $(BOOT_ROOT)/,,$(SOURCES_ABS))
# Get a list of unique directories containing the source files.
SOURCE_DIRS_ABS := $(sort $(foreach f,$(SOURCES_ABS),$(dir $(f))))
SOURCE_DIRS_REL := $(subst $(BOOT_ROOT)/,,$(SOURCE_DIRS_ABS))
OBJECTS_DIRS := $(addprefix $(OBJS_ROOT)/,$(SOURCE_DIRS_REL))
# Filter source files list into separate source types.
C_SOURCES = $(filter %.c,$(SOURCES_REL))
CXX_SOURCES = $(filter %.cpp,$(SOURCES_REL))
ASM_s_SOURCES = $(filter %.s,$(SOURCES_REL))
ASM_S_SOURCES = $(filter %.S,$(SOURCES_REL))
# Convert sources to objects.
OBJECTS_C := $(addprefix $(OBJS_ROOT)/,$(C_SOURCES:.c=.o))
OBJECTS_CXX := $(addprefix $(OBJS_ROOT)/,$(CXX_SOURCES:.cpp=.o))
OBJECTS_ASM := $(addprefix $(OBJS_ROOT)/,$(ASM_s_SOURCES:.s=.o))
OBJECTS_ASM_S := $(addprefix $(OBJS_ROOT)/,$(ASM_S_SOURCES:.S=.o))
# Complete list of all object files.
OBJECTS_ALL := $(sort $(OBJECTS_C) $(OBJECTS_CXX) $(OBJECTS_ASM) $(OBJECTS_ASM_S))
#-------------------------------------------------------------------------------
# Default target
#-------------------------------------------------------------------------------
# Note that prerequisite order is important here. The subdirectories must be built first, or you
# may end up with files in the current directory not getting added to libraries. This would happen
# if subdirs modified the library file after local files were compiled but before they were added
# to the library.
.PHONY: all
all: $(MAKE_TARGET)
## Recipe to create the output object file directories.
$(OBJECTS_DIRS) :
$(at)mkdir -p $@
# Object files depend on the directories where they will be created.
#
# The dirs are made order-only prerequisites (by being listed after the '|') so they won't cause
# the objects to be rebuilt, as the modification date on a directory changes whenver its contents
# change. This would cause the objects to always be rebuilt if the dirs were normal prerequisites.
$(OBJECTS_ALL): | $(OBJECTS_DIRS)
#-------------------------------------------------------------------------------
# Pattern rules for compilation
#-------------------------------------------------------------------------------
# We cd into the source directory before calling the appropriate compiler. This must be done
# on a single command line since make calls individual recipe lines in separate shells, so
# '&&' is used to chain the commands.
#
# Generate make dependencies while compiling using the -MMD option, which excludes system headers.
# If system headers are included, there are path problems on cygwin. The -MP option creates empty
# targets for each header file so that a rebuild will be forced if the file goes missing, but
# no error will occur.
# Compile C sources.
$(OBJS_ROOT)/%.o: $(BOOT_ROOT)/%.c
@$(call printmessage,c,Compiling, $(subst $(BOOT_ROOT)/,,$<))
$(at)$(CC) $(CFLAGS) $(SYSTEM_INC) $(INCLUDES) $(DEFINES) -MMD -MF $(basename $@).d -MP -o $@ -c $<
# Compile C++ sources.
$(OBJS_ROOT)/%.o: $(BOOT_ROOT)/%.cpp
@$(call printmessage,cxx,Compiling, $(subst $(BOOT_ROOT)/,,$<))
$(at)$(CXX) $(CXXFLAGS) $(SYSTEM_INC) $(INCLUDES) $(DEFINES) -MMD -MF $(basename $@).d -MP -o $@ -c $<
# For .S assembly files, first run through the C preprocessor then assemble.
$(OBJS_ROOT)/%.o: $(BOOT_ROOT)/%.S
@$(call printmessage,asm,Assembling, $(subst $(BOOT_ROOT)/,,$<))
$(at)$(CPP) -D__LANGUAGE_ASM__ $(INCLUDES) $(DEFINES) -o $(basename $@).s $< \
&& $(AS) $(ASFLAGS) $(INCLUDES) -MD $(OBJS_ROOT)/$*.d -o $@ $(basename $@).s
# Assembler sources.
$(OBJS_ROOT)/%.o: $(BOOT_ROOT)/%.s
@$(call printmessage,asm,Assembling, $(subst $(BOOT_ROOT)/,,$<))
$(at)$(AS) $(ASFLAGS) $(INCLUDES) -MD $(basename $@).d -o $@ $<
#------------------------------------------------------------------------
# Build the tagrget
#------------------------------------------------------------------------
# Wrap the link objects in start/end group so that ld re-checks each
# file for dependencies. Otherwise linking static libs can be a pain
# since order matters.
$(MAKE_TARGET): $(OBJECTS_ALL)
@$(call printmessage,link,Linking, $(APP_NAME))
$(at)$(LD) $(LDFLAGS) \
$(OBJECTS_ALL) \
-lc -lstdc++ -lm -ludev \
-o $@
@echo "Output binary:" ; echo " $(APP_NAME)"
#-------------------------------------------------------------------------------
# Clean
#-------------------------------------------------------------------------------
.PHONY: clean cleanall
cleanall: clean
clean:
$(at)rm -rf $(OBJECTS_ALL) $(OBJECTS_DIRS) $(MAKE_TARGET) $(APP_NAME)
# Include dependency files.
-include $(OBJECTS_ALL:.o=.d)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A498A89A-E965-4B36-B926-850AABF31939}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>blhost</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>BOOTLOADER_HOST;WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<CompileAs>CompileAsCpp</CompileAs>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\src\drivers\common;$(ProjectDir)..\..;$(ProjectDir)..\..\..\src;$(ProjectDir)..\..\..\src\bm_usb;$(ProjectDir)..\..\..\src\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>../../../apps/common/blfwk/$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>blfwk.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>BOOTLOADER_HOST;WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\src\drivers\common;$(ProjectDir)..\..;$(ProjectDir)..\..\..\src;$(ProjectDir)..\..\..\src\bm_usb;$(ProjectDir)..\..\..\src\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAs>CompileAsCpp</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>blfwk.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>../../../apps/common/blfwk/$(Configuration)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="blhost.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="blhost.cpp" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>-u -b i2c,0x10,100 -- get-property 1</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>-p COM1 -b can -- get-property 1</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2013-14, 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.
*/
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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,75 @@
/*
* Copyright (c) 2015, 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.
*/
#include <stdint.h>
#include "port/fsl_port.h"
#include "board.h"
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
/* Initialize Switch. */
void BOARD_InitSwitch(void)
{
gpio_pin_config_t switch_config = { kGPIO_DigitalInput, 0 };
GPIO_PinInit(BOARD_SW2_GPIO, BOARD_SW2_GPIO_PIN, &switch_config);
GPIO_PinInit(BOARD_SW3_GPIO, BOARD_SW3_GPIO_PIN, &switch_config);
}
/* Read Switch value. */
bool BOARD_ReadSwitch(uint32_t switch_num)
{
if (switch_num == kSwitch2)
{
return !(GPIO_ReadPinInput(BOARD_SW2_GPIO, BOARD_SW2_GPIO_PIN));
}
else if (switch_num == kSwitch3)
{
return !(GPIO_ReadPinInput(BOARD_SW3_GPIO, BOARD_SW3_GPIO_PIN));
}
else
{
return false;
}
}
/* Initialize led. */
void BOARD_InitLED(void)
{
gpio_pin_config_t LED_config = { kGPIO_DigitalOutput, 1 };
GPIO_PinInit(BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, &LED_config);
GPIO_PinInit(BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, &LED_config);
GPIO_PinInit(BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, &LED_config);
GPIO_PinInit(BOARD_LED_YELLOW_GPIO_PORT, BOARD_LED_YELLOW_GPIO_PIN, &LED_config);
}

View File

@@ -0,0 +1,169 @@
/*
* Copyright (c) 2015, 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.
*/
#ifndef _BOARD_H_
#define _BOARD_H_
#include "gpio/fsl_gpio.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief The board name */
#define BOARD_NAME "TWR-K65F180M"
/*! @brief The UART to use for debug messages. */
#define BOARD_USE_UART
#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART2
#define BOARD_DEBUG_UART_CLKSRC BUS_CLK
#ifndef BOARD_DEBUG_UART_BAUDRATE
#define BOARD_DEBUG_UART_BAUDRATE 115200
#endif /* BOARD_DEBUG_UART_BAUDRATE */
/*! @brief The CAN instance used for board */
#define BOARD_CAN_BASEADDR CAN0
/*! @brief The i2c instance used for i2c connection by default */
#define BOARD_I2C_BASEADDR I2C0
/*! @brief The Flextimer instance/channel used for board */
#define BOARD_FTM_BASEADDR FTM0
#define BOARD_FTM_CHANNEL 2
/*! @brief The TPM instance/channel used for board */
#define BOARD_TPM_BASEADDR TPM2
#define BOARD_TPM_CHANNEL 0
/*! @brief The Enet instance used for board. */
#define BOARD_ENET_BASEADDR ENET
/*! @brief The FlexBus instance used for board.*/
#define BOARD_FLEXBUS_BASEADDR FB
#define BOARD_TSI_ELECTRODE_CNT 2
/*! @brief Indexes of the TSI channels for on board electrodes */
#define BOARD_TSI_ELECTRODE_1 11
#define BOARD_TSI_ELECTRODE_2 12
/*! @brief The SDHC instance/channel used for board */
#define BOARD_SDHC_BASEADDR SDHC
#define BOARD_SDHC_CD_GPIO_IRQ_HANDLER PORTA_IRQHandler
/*! @brief The CMP instance/channel used for board. */
#define BOARD_CMP_BASEADDR CMP2
#define BOARD_CMP_CHANNEL 2
/*! @brief The i2c instance used for sai demo */
#define BOARD_SAI_DEMO_I2C_BASEADDR I2C0
/*! @brief The rtc instance used for rtc_func */
#define BOARD_RTC_FUNC_BASEADDR RTC
/*! @brief If connected the TWR_MEM, this is spi sd card */
#define BOARD_SDCARD_CARD_DETECTION_GPIO_PORT GPIOD
#define SDCARD_CARD_DETECTION_GPIO_PIN 15
#define SDCARD_CARD_WRITE_PROTECTION_GPIO_PORT GPIOC
#define SDCARD_CARD_WRITE_PROTECTION_GPIO_PIN 13
#define SDCARD_SPI_HW_BASEADDR SPI1
#define SDCARD_CARD_INSERTED 0
/*! @brief Define the port interrupt number for the board switches */
enum
{
kSwitch1,
kSwitch2,
kSwitch3,
};
#define BOARD_SW2_GPIO GPIOA
#define BOARD_SW2_PORT PORTA
#define BOARD_SW2_GPIO_PIN 4
#define BOARD_SW2_IRQ PORTA_IRQn
#define BOARD_SW2_IRQ_HANDLER PORTA_IRQHandler
#define BOARD_SW2_NAME "SW2"
#define BOARD_SW2_MASK (1u << BOARD_SW2_GPIO_PIN)
#define BOARD_SW3_GPIO GPIOA
#define BOARD_SW3_PORT PORTA
#define BOARD_SW3_GPIO_PIN 10
#define BOARD_SW3_IRQ PORTA_IRQn
#define BOARD_SW3_IRQ_HANDLER PORTA_IRQHandler
#define BOARD_SW3_NAME "SW3"
#define BOARD_SW3_MASK (1u << BOARD_SW3_GPIO_PIN)
#define BOARD_SW_IRQ_HANDLER PORTA_IRQHandler
#define BOARD_LED_RED_GPIO_PORT GPIOB
#define BOARD_LED_RED_GPIO_PIN 5
#define BOARD_LED_RED_MASK (1u << BOARD_LED_RED_GPIO_PIN)
#define BOARD_LED_GREEN_GPIO_PORT GPIOA
#define BOARD_LED_GREEN_GPIO_PIN 28
#define BOARD_LED_GREEN_MASK (1u << BOARD_LED_GREEN_GPIO_PIN)
#define BOARD_LED_BLUE_GPIO_PORT GPIOA
#define BOARD_LED_BLUE_GPIO_PIN 29
#define BOARD_LED_BLUE_MASK (1u << BOARD_LED_BLUE_GPIO_PIN)
#define BOARD_LED_YELLOW_GPIO_PORT GPIOB
#define BOARD_LED_YELLOW_GPIO_PIN 4
#define BOARD_LED_YELLOW_MASK (1u << BOARD_LED_YELLOW_GPIO_PIN)
#define LED_RED_ON GPIO_ClearPinsOutput(BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_MASK)
#define LED_RED_OFF GPIO_SetPinsOutput(BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_MASK)
#define LED_GREEN_ON GPIO_ClearPinsOutput(BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_MASK)
#define LED_GREEN_OFF GPIO_SetPinsOutput(BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_MASK)
#define LED_BLUE_ON GPIO_ClearPinsOutput(BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_MASK)
#define LED_BLUE_OFF GPIO_SetPinsOutput(BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_MASK)
#define LED_YELLOW_ON GPIO_ClearPinsOutput(BOARD_LED_YELLOW_GPIO_PORT, BOARD_LED_YELLOW_MASK)
#define LED_YELLOW_OFF GPIO_SetPinsOutput(BOARD_LED_YELLOW_GPIO_PORT, BOARD_LED_YELLOW_MASK)
/*! @brief Define the port interrupt number for the usb id gpio pin */
#define BOARD_ID_GPIO GPIOE
#define BOARD_ID_PORT PORTE
#define BOARD_ID_GPIO_PIN 10U
#define BOARD_ID_IRQ PORTE_IRQn
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*******************************************************************************
* API
******************************************************************************/
extern void BOARD_InitHardware(void);
void BOARD_InitSwitch(void);
void BOARD_InitLED(void);
bool BOARD_ReadSwitch(uint32_t switch_num);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* _BOARD_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2013 - 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.
*/
#if !defined(__HOST_HARDWARE_H__)
#define __HOST_HARDWARE_H__
#include "bootloader_common.h"
#include "microseconds/microseconds.h"
#include "dspi/fsl_dspi.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define UART_INSTANCE 4
#define SPI_INSTANCE 2
#define I2C_INSTANCE 0
#define FLEXCAN_INSTANCE 0
/*! @brief uart baud rate value limit */
enum _uart_baud_value
{
kUART_MIN_BAUD = 19200,
kUART_MAX_BAUD = 230400,
kUART_DEFAULT_BAUD = 57600
};
/*! @brief FelxCAN frequency */
enum _flexcan_freq_value
{
kFLEXCAN_125K = 125,
kFLEXCAN_250K = 250,
kFLEXCAN_500K = 500,
kFLEXCAN_750K = 750,
kFLEXCAN_1000K = 1000,
};
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*! @brief initialize all hardware */
void hardware_init(void);
/*! @brief receiving host char command process */
bool wait_uart_char(uint8_t *data);
uint8_t wait_uart_char_blocking(void);
/*! @brief spi config speed process */
void configure_spi_speed(uint32_t speedkhz);
/*! @brief spi receiving data process */
status_t receive_spi_data(uint8_t *dest, uint32_t readLength);
/*! @brief spi send data process */
status_t send_spi_data(uint8_t *src, uint32_t writeLength);
/*! @brief i2c config speed process */
void configure_i2c_speed(uint32_t speedkhz);
/*! @brief i2c sending data process */
status_t send_i2c_data(uint8_t *src, uint32_t writeLength);
/*! @brief i2c receiving data process */
status_t receive_i2c_data(uint8_t *dest, uint32_t readLength);
/*! @brief uart config speed process */
void configure_uart_speed(uint32_t baud);
/*! @brief uart send data process */
status_t send_uart_data(uint8_t *src, uint32_t writeLength);
/*! @brief uart receiving data process */
status_t receive_uart_data(uint8_t *dest, uint32_t readLength);
/*! @brief flexCAN config speed process */
void configure_can_speed(uint32_t speed);
/*! @brief flexCAN sending data process */
status_t send_can_data(uint8_t *src, uint32_t writeLength);
/*! @brief flexCAN receiving data process */
status_t receive_can_data(uint8_t *dest, uint32_t readLength);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* __HOST_HARDWARE_H__ */

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2015, 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.
*/
#include "fsl_device_registers.h"
#include "port/fsl_port.h"
#include "pin_mux.h"
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Initialize all pins used in this example
*
* @param disablePortClockAfterInit disable port clock after pin
* initialization or not.
*/
void BOARD_InitPins(void)
{
port_pin_config_t pinConfig;
pinConfig.pullSelect = kPORT_PullUp;
pinConfig.openDrainEnable = kPORT_OpenDrainEnable;
/* Ungate the port clock */
SIM->SCGC5 |= (SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK |
SIM_SCGC5_PORTE_MASK);
/* Initialize UART2(OpenSDA) pins below */
PORT_SetPinMux(PORTE, 16u, kPORT_MuxAlt3); /* Affects PORTE_PCR16 register */
PORT_SetPinMux(PORTE, 17u, kPORT_MuxAlt3); /* Affects PORTE_PCR17 register */
/* Enable pins for UART4 on PTE24 - PTE25. */
PORT_SetPinMux(PORTE, 25u, kPORT_MuxAlt3); /* UART4_RX is ALT3 for pin PTE25 */
PORT_SetPinMux(PORTE, 24u, kPORT_MuxAlt3); /* UART4_TX is ALT3 for pin PTE24 */
/* Enable pins for I2C0 on PTE18 - PTE19. */
PORT_SetPinConfig(PORTE, 18u, &pinConfig); /* I2C0_SCL set for open drain */
PORT_SetPinConfig(PORTE, 19u, &pinConfig); /* I2C0_SDA set for open drain */
PORT_SetPinMux(PORTE, 18u, kPORT_MuxAlt4); /* I2C0_SCL is ALT4 for pin PTE18 */
PORT_SetPinMux(PORTE, 19u, kPORT_MuxAlt4); /* I2C0_SDA is ALT4 for pin PTE19 */
/* Enable pins for SPI0 on PTD0 - PTD3. */
PORT_SetPinMux(PORTD, 11u, kPORT_MuxAlt2); /* SPI0_PCS0 is ALT2 for pin PTD11 */
PORT_SetPinMux(PORTD, 12u, kPORT_MuxAlt2); /* SPI0_SCK is ALT2 for pin PTD12 */
PORT_SetPinMux(PORTD, 13u, kPORT_MuxAlt2); /* SPI0_SOUT is ALT2 for pin PTD13 */
PORT_SetPinMux(PORTD, 14u, kPORT_MuxAlt2); /* SPI0_SIN is ALT2 for pin PTD14 */
/* LED PTA28 */
PORT_SetPinMux(PORTA, 28u, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTA, 29u, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTB, 4u, kPORT_MuxAsGpio);
PORT_SetPinMux(PORTB, 5u, kPORT_MuxAsGpio);
/* SW2 PTA4 */
PORT_SetPinMux(PORTA, 4u, kPORT_MuxAsGpio);
/* SW3 PTA10 */
PORT_SetPinMux(PORTA, 10u, kPORT_MuxAsGpio);
/* Enable pins for FLEXCAN0 on PTA30 - PTA31. */
PORT_SetPinMux(PORTA, 30u, kPORT_MuxAlt2); /* FLEXCAN0_TX is ALT2 for pin PTA30 */
PORT_SetPinMux(PORTA, 31u, kPORT_MuxAlt2); /* FLEXCAN0_RX is ALT2 for pin PTA31 */
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2015, 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.
*/
#ifndef _PIN_MUX_H_
#define _PIN_MUX_H_
#include <stdbool.h>
#include "fsl_common.h"
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus*/
/*!
* @brief configure all pins for this demo/example
*/
void BOARD_InitPins(void);
#if defined(__cplusplus)
}
#endif /* __cplusplus*/
#endif /* _PIN_MUX_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,433 @@
/*
** ###################################################################
** Processors: MK65FN2M0CAC18
** MK65FX1M0CAC18
** MK65FN2M0VMI18
** MK65FX1M0VMI18
**
** Compilers: Keil ARM C/C++ Compiler
** Freescale C/C++ for Embedded ARM
** GNU C Compiler
** IAR ANSI C/C++ Compiler for ARM
**
** Reference manual: K65P169M180SF5RMV2, Rev. 1, Mar 2015
** Version: rev. 3.0, 2015-03-25
** Build: b151215
**
** Abstract:
** Provides a system configuration function and a global variable that
** contains the system frequency. It configures the device and initializes
** the oscillator (PLL) that is part of the microcontroller device.
**
** Copyright (c) 2015 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
**
** Revisions:
** - rev. 1.0 (2013-09-02)
** Initial version.
** - rev. 2.0 (2014-02-17)
** Register accessor macros added to the memory map.
** Symbols for Processor Expert memory map compatibility added to the memory map.
** Startup file for gcc has been updated according to CMSIS 3.2.
** Definition of BITBAND macros updated to support peripherals with 32-bit acces disabled.
** Update according to reference manual rev. 2
** - rev. 2.1 (2014-04-16)
** Update of SystemInit() and SystemCoreClockUpdate() functions.
** - rev. 2.2 (2014-10-14)
** Interrupt INT_LPTimer renamed to INT_LPTMR0, interrupt INT_Watchdog renamed to INT_WDOG_EWM.
** - rev. 2.3 (2014-11-20)
** Update according to reverence manual K65P169M180SF5RMV2_NDA, Rev. 0 Draft A, October 2014.
** Update of SystemInit() to use 16MHz external crystal.
** - rev. 2.4 (2015-02-19)
** Renamed interrupt vector LLW to LLWU.
** - rev. 3.0 (2015-03-25)
** Registers updated according to the reference manual revision 1, March 2015
**
** ###################################################################
*/
/*!
* @file MK65F18
* @version 3.0
* @date 2015-03-25
* @brief Device specific configuration file for MK65F18 (header file)
*
* Provides a system configuration function and a global variable that contains
* the system frequency. It configures the device and initializes the oscillator
* (PLL) that is part of the microcontroller device.
*/
#ifndef _SYSTEM_MK65F18_H_
#define _SYSTEM_MK65F18_H_ /**< Symbol preventing repeated inclusion */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#ifndef DISABLE_WDOG
#define DISABLE_WDOG 1
#endif
/* MCG mode constants */
#define MCG_MODE_FEI 0U
#define MCG_MODE_FBI 1U
#define MCG_MODE_BLPI 2U
#define MCG_MODE_FEE 3U
#define MCG_MODE_FBE 4U
#define MCG_MODE_BLPE 5U
#define MCG_MODE_PBE 6U
#define MCG_MODE_PEE 7U
/* Predefined clock setups
0 ... Default part configuration
Multipurpose Clock Generator (MCG) in FEI mode.
Reference clock source for MCG module: Slow internal reference clock
Core clock = 20.97152MHz
Bus clock = 20.97152MHz
1 ... Maximal speed configuration
Multipurpose Clock Generator (MCG) in PEE mode.
Reference clock source for MCG module: System oscillator 0 reference clock
Core clock = 180MHz
Bus clock = 60MHz
2 ... Chip internally clocked, ready for Very Low Power Run mode.
Multipurpose Clock Generator (MCG) in BLPI mode.
Reference clock source for MCG module: Fast internal reference clock
Core clock = 4MHz
Bus clock = 4MHz
3 ... Chip externally clocked, ready for Very Low Power Run mode.
Multipurpose Clock Generator (MCG) in BLPE mode.
Reference clock source for MCG module: System oscillator 0 reference clock
Core clock = 4MHz
Bus clock = 4MHz
4 ... USB clock setup
Multipurpose Clock Generator (MCG) in PEE mode.
Reference clock source for MCG module: System oscillator 0 reference clock
Core clock = 120MHz
Bus clock = 60MHz
5 ... Maximum achievable clock frequency configuration in RUN mode
Multipurpose Clock Generator (MCG) in PEE mode.
Reference clock source for MCG module: System oscillator 0 reference clock
Core clock = 120MHz
Bus clock = 60MHz
*/
/* Define clock source values */
#define CPU_XTAL_CLK_HZ \
16000000U /* Value of the external crystal or oscillator clock frequency of the system oscillator (OSC) in Hz */
#define CPU_XTAL32k_CLK_HZ \
32768U /* Value of the external 32k crystal or oscillator clock frequency of the RTC in Hz \ \
*/
#define CPU_INT_SLOW_CLK_HZ 32768U /* Value of the slow internal oscillator clock frequency in Hz */
#define CPU_INT_FAST_CLK_HZ 4000000U /* Value of the fast internal oscillator clock frequency in Hz */
#define CPU_INT_IRC_CLK_HZ 48000000U /* Value of the 48M internal oscillator clock frequency in Hz */
/* RTC oscillator setting */
/* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0,CLKO=1,OSCE=1,WPS=0,UM=0,SUP=0,WPE=0,SWR=0 */
#define SYSTEM_RTC_CR_VALUE 0x0300U /* RTC_CR */
/* Low power mode enable */
/* SMC_PMPROT: AHSRUN=1,AVLP=1,ALLS=1,AVLLS=1 */
#define SYSTEM_SMC_PMPROT_VALUE 0xAAU /* SMC_PMPROT */
/* Internal reference clock trim */
/* #undef SLOW_TRIM_ADDRESS */ /* Slow oscillator not trimmed. Commented out for MISRA compliance. */
/* #undef SLOW_FINE_TRIM_ADDRESS */ /* Slow oscillator not trimmed. Commented out for MISRA compliance. */
/* #undef FAST_TRIM_ADDRESS */ /* Fast oscillator not trimmed. Commented out for MISRA compliance. */
/* #undef FAST_FINE_TRIM_ADDRESS */ /* Fast oscillator not trimmed. Commented out for MISRA compliance. */
#ifdef CLOCK_SETUP
#if (CLOCK_SETUP == 0)
#define DEFAULT_SYSTEM_CLOCK 20971520U /* Default System clock value */
#define MCG_MODE MCG_MODE_FEI /* Clock generator mode */
/* MCG_C1: CLKS=0,FRDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */
#define SYSTEM_MCG_C1_VALUE 0x06U /* MCG_C1 */
/* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
#define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
/* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
#define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
/* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
#define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
/* MCG_C5: PLLCLKEN=0,PLLSTEN=0,PRDIV=0 */
#define SYSTEM_MCG_C5_VALUE 0x00U /* MCG_C5 */
/* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV=0 */
#define SYSTEM_MCG_C6_VALUE 0x00U /* MCG_C6 */
/* MCG_C7: OSCSEL=0 */
#define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
/* MCG_C9: PLL_CME=0,PLL_LOCRE=0,EXT_PLL_LOCS=0 */
#define SYSTEM_MCG_C9_VALUE 0x00U /* MCG_C9 */
/* MCG_C11: PLLCS=0 */
#define SYSTEM_MCG_C11_VALUE 0x00U /* MCG_C11 */
/* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
#define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
/* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
#define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
/* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=1,OUTDIV4=1 */
#define SYSTEM_SIM_CLKDIV1_VALUE 0x00110000U /* SIM_CLKDIV1 */
/* SIM_CLKDIV2: USBDIV=1,USBFRAC=0 */
#define SYSTEM_SIM_CLKDIV2_VALUE 0x02U /* SIM_CLKDIV2 */
/* SIM_CLKDIV3: PLLFLLDIV=0,PLLFLLFRAC=0 */
#define SYSTEM_SIM_CLKDIV3_VALUE 0x00U /* SIM_CLKDIV3 */
/* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,RAMSIZE=0 */
#define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
/* SIM_SOPT2:
* SDHCSRC=0,LPUARTSRC=0,TPMSRC=1,TIMESRC=0,RMIISRC=0,USBSRC=0,PLLFLLSEL=0,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0,USBREGEN=0,USBSLSRC=0
*/
#define SYSTEM_SIM_SOPT2_VALUE 0x01000000U /* SIM_SOPT2 */
#elif(CLOCK_SETUP == 1)
#define DEFAULT_SYSTEM_CLOCK 180000000U /* Default System clock value */
#define MCG_MODE MCG_MODE_PEE /* Clock generator mode */
/* MCG_C1: CLKS=0,FRDIV=4,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
#define SYSTEM_MCG_C1_VALUE 0x22U /* MCG_C1 */
/* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
#define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
/* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
#define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
/* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
#define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
/* MCG_C5: PLLCLKEN=0,PLLSTEN=0,PRDIV=1 */
#define SYSTEM_MCG_C5_VALUE 0x01U /* MCG_C5 */
/* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV=0x1D */
#define SYSTEM_MCG_C6_VALUE 0x5DU /* MCG_C6 */
/* MCG_C7: OSCSEL=0 */
#define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
/* MCG_C9: PLL_CME=1,PLL_LOCRE=0,EXT_PLL_LOCS=0 */
#define SYSTEM_MCG_C9_VALUE 0x20U /* MCG_C9 */
/* MCG_C11: PLLCS=0 */
#define SYSTEM_MCG_C11_VALUE 0x00U /* MCG_C11 */
/* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
#define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
/* SMC_PMCTRL: RUNM=3,STOPA=0,STOPM=0 */
#define SYSTEM_SMC_PMCTRL_VALUE 0x60U /* SMC_PMCTRL */
/* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=2,OUTDIV3=2,OUTDIV4=6 */
#define SYSTEM_SIM_CLKDIV1_VALUE 0x02260000U /* SIM_CLKDIV1 */
/* SIM_CLKDIV2: USBDIV=6,USBFRAC=0 */
#define SYSTEM_SIM_CLKDIV2_VALUE 0x0CU /* SIM_CLKDIV2 */
/* SIM_CLKDIV3: PLLFLLDIV=0,PLLFLLFRAC=0 */
#define SYSTEM_SIM_CLKDIV3_VALUE 0x00U /* SIM_CLKDIV3 */
/* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,RAMSIZE=0 */
#define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
/* SIM_SOPT2:
* SDHCSRC=0,LPUARTSRC=0,TPMSRC=1,TIMESRC=0,RMIISRC=0,USBSRC=0,PLLFLLSEL=1,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0,USBREGEN=0,USBSLSRC=0
*/
#define SYSTEM_SIM_SOPT2_VALUE 0x01010000U /* SIM_SOPT2 */
#elif(CLOCK_SETUP == 2)
#define DEFAULT_SYSTEM_CLOCK 4000000U /* Default System clock value */
#define MCG_MODE MCG_MODE_BLPI /* Clock generator mode */
/* MCG_C1: CLKS=1,FRDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */
#define SYSTEM_MCG_C1_VALUE 0x46U /* MCG_C1 */
/* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=1,IRCS=1 */
#define SYSTEM_MCG_C2_VALUE 0x27U /* MCG_C2 */
/* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
#define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
/* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
#define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
/* MCG_C5: PLLCLKEN=0,PLLSTEN=0,PRDIV=0 */
#define SYSTEM_MCG_C5_VALUE 0x00U /* MCG_C5 */
/* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV=0 */
#define SYSTEM_MCG_C6_VALUE 0x00U /* MCG_C6 */
/* MCG_C7: OSCSEL=0 */
#define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
/* MCG_C9: PLL_CME=0,PLL_LOCRE=0,EXT_PLL_LOCS=0 */
#define SYSTEM_MCG_C9_VALUE 0x00U /* MCG_C9 */
/* MCG_C11: PLLCS=0 */
#define SYSTEM_MCG_C11_VALUE 0x00U /* MCG_C11 */
/* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
#define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
/* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
#define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
/* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=0,OUTDIV4=4 */
#define SYSTEM_SIM_CLKDIV1_VALUE 0x00040000U /* SIM_CLKDIV1 */
/* SIM_CLKDIV2: USBDIV=0,USBFRAC=0 */
#define SYSTEM_SIM_CLKDIV2_VALUE 0x00U /* SIM_CLKDIV2 */
/* SIM_CLKDIV3: PLLFLLDIV=0,PLLFLLFRAC=0 */
#define SYSTEM_SIM_CLKDIV3_VALUE 0x00U /* SIM_CLKDIV3 */
/* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,RAMSIZE=0 */
#define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
/* SIM_SOPT2:
* SDHCSRC=0,LPUARTSRC=0,TPMSRC=1,TIMESRC=0,RMIISRC=0,USBSRC=0,PLLFLLSEL=3,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0,USBREGEN=0,USBSLSRC=0
*/
#define SYSTEM_SIM_SOPT2_VALUE 0x01030000U /* SIM_SOPT2 */
#elif(CLOCK_SETUP == 3)
#define DEFAULT_SYSTEM_CLOCK 4000000U /* Default System clock value */
#define MCG_MODE MCG_MODE_BLPE /* Clock generator mode */
/* MCG_C1: CLKS=2,FRDIV=4,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
#define SYSTEM_MCG_C1_VALUE 0xA2U /* MCG_C1 */
/* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=1,IRCS=1 */
#define SYSTEM_MCG_C2_VALUE 0x27U /* MCG_C2 */
/* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
#define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
/* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=1,LOCS0=0 */
#define SYSTEM_MCG_SC_VALUE 0x02U /* MCG_SC */
/* MCG_C5: PLLCLKEN=0,PLLSTEN=0,PRDIV=0 */
#define SYSTEM_MCG_C5_VALUE 0x00U /* MCG_C5 */
/* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV=0 */
#define SYSTEM_MCG_C6_VALUE 0x00U /* MCG_C6 */
/* MCG_C7: OSCSEL=0 */
#define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
/* MCG_C9: PLL_CME=0,PLL_LOCRE=0,EXT_PLL_LOCS=0 */
#define SYSTEM_MCG_C9_VALUE 0x00U /* MCG_C9 */
/* MCG_C11: PLLCS=0 */
#define SYSTEM_MCG_C11_VALUE 0x00U /* MCG_C11 */
/* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
#define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
/* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
#define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
/* SIM_CLKDIV1: OUTDIV1=3,OUTDIV2=3,OUTDIV3=3,OUTDIV4=0x0F */
#define SYSTEM_SIM_CLKDIV1_VALUE 0x333F0000U /* SIM_CLKDIV1 */
/* SIM_CLKDIV2: USBDIV=0,USBFRAC=0 */
#define SYSTEM_SIM_CLKDIV2_VALUE 0x00U /* SIM_CLKDIV2 */
/* SIM_CLKDIV3: PLLFLLDIV=0,PLLFLLFRAC=0 */
#define SYSTEM_SIM_CLKDIV3_VALUE 0x00U /* SIM_CLKDIV3 */
/* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,RAMSIZE=0 */
#define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
/* SIM_SOPT2:
* SDHCSRC=0,LPUARTSRC=0,TPMSRC=1,TIMESRC=0,RMIISRC=0,USBSRC=0,PLLFLLSEL=3,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0,USBREGEN=0,USBSLSRC=0
*/
#define SYSTEM_SIM_SOPT2_VALUE 0x01030000U /* SIM_SOPT2 */
#elif(CLOCK_SETUP == 4)
#define DEFAULT_SYSTEM_CLOCK 120000000U /* Default System clock value */
#define MCG_MODE MCG_MODE_PEE /* Clock generator mode */
/* MCG_C1: CLKS=0,FRDIV=4,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
#define SYSTEM_MCG_C1_VALUE 0x22U /* MCG_C1 */
/* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
#define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
/* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
#define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
/* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
#define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
/* MCG_C5: PLLCLKEN=0,PLLSTEN=0,PRDIV=1 */
#define SYSTEM_MCG_C5_VALUE 0x01U /* MCG_C5 */
/* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV=0x0E */
#define SYSTEM_MCG_C6_VALUE 0x4EU /* MCG_C6 */
/* MCG_C7: OSCSEL=0 */
#define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
/* MCG_C9: PLL_CME=0,PLL_LOCRE=0,EXT_PLL_LOCS=0 */
#define SYSTEM_MCG_C9_VALUE 0x00U /* MCG_C9 */
/* MCG_C11: PLLCS=0 */
#define SYSTEM_MCG_C11_VALUE 0x00U /* MCG_C11 */
/* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
#define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
/* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
#define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
/* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=1,OUTDIV3=1,OUTDIV4=4 */
#define SYSTEM_SIM_CLKDIV1_VALUE 0x01140000U /* SIM_CLKDIV1 */
/* SIM_CLKDIV2: USBDIV=1,USBFRAC=0 */
#define SYSTEM_SIM_CLKDIV2_VALUE 0x12U /* SIM_CLKDIV2 */
/* SIM_CLKDIV3: PLLFLLDIV=0,PLLFLLFRAC=0 */
#define SYSTEM_SIM_CLKDIV3_VALUE 0x00U /* SIM_CLKDIV3 */
/* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,RAMSIZE=0 */
#define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
/* SIM_SOPT2:
* SDHCSRC=0,LPUARTSRC=0,TPMSRC=1,TIMESRC=0,RMIISRC=0,USBSRC=0,PLLFLLSEL=1,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0,USBREGEN=0,USBSLSRC=0
*/
#define SYSTEM_SIM_SOPT2_VALUE 0x01010000U /* SIM_SOPT2 */
#elif(CLOCK_SETUP == 5)
#define DEFAULT_SYSTEM_CLOCK 120000000U /* Default System clock value */
#define MCG_MODE MCG_MODE_PEE /* Clock generator mode */
/* MCG_C1: CLKS=0,FRDIV=4,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
#define SYSTEM_MCG_C1_VALUE 0x22U /* MCG_C1 */
/* MCG_C2: LOCRE0=0,FCFTRIM=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
#define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
/* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
#define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
/* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
#define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
/* MCG_C5: PLLCLKEN=0,PLLSTEN=0,PRDIV=1 */
#define SYSTEM_MCG_C5_VALUE 0x01U /* MCG_C5 */
/* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV=0x0E */
#define SYSTEM_MCG_C6_VALUE 0x4EU /* MCG_C6 */
/* MCG_C7: OSCSEL=0 */
#define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
/* MCG_C9: PLL_CME=0,PLL_LOCRE=0,EXT_PLL_LOCS=0 */
#define SYSTEM_MCG_C9_VALUE 0x00U /* MCG_C9 */
/* MCG_C11: PLLCS=0 */
#define SYSTEM_MCG_C11_VALUE 0x00U /* MCG_C11 */
/* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
#define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
/* SMC_PMCTRL: RUNM=0,STOPA=0,STOPM=0 */
#define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
/* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=1,OUTDIV3=1,OUTDIV4=4 */
#define SYSTEM_SIM_CLKDIV1_VALUE 0x01140000U /* SIM_CLKDIV1 */
/* SIM_CLKDIV2: USBDIV=1,USBFRAC=0 */
#define SYSTEM_SIM_CLKDIV2_VALUE 0x12U /* SIM_CLKDIV2 */
/* SIM_CLKDIV3: PLLFLLDIV=0,PLLFLLFRAC=0 */
#define SYSTEM_SIM_CLKDIV3_VALUE 0x00U /* SIM_CLKDIV3 */
/* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=2,RAMSIZE=0 */
#define SYSTEM_SIM_SOPT1_VALUE 0x00080000U /* SIM_SOPT1 */
/* SIM_SOPT2:
* SDHCSRC=0,LPUARTSRC=0,TPMSRC=1,TIMESRC=0,RMIISRC=0,USBSRC=0,PLLFLLSEL=1,TRACECLKSEL=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0,USBREGEN=0,USBSLSRC=0
*/
#define SYSTEM_SIM_SOPT2_VALUE 0x01010000U /* SIM_SOPT2 */
#else
#error The selected clock setup is not supported.
#endif
#else
#define DEFAULT_SYSTEM_CLOCK 20971520u
#endif
/**
* @brief System clock frequency (core clock)
*
* The system clock frequency supplied to the SysTick timer and the processor
* core clock. This variable can be used by the user application to setup the
* SysTick timer or configure other parameters. It may also be used by debugger to
* query the frequency of the debug timer or configure the trace clock speed
* SystemCoreClock is initialized with a correct predefined value.
*/
extern uint32_t SystemCoreClock;
/**
* @brief Setup the microcontroller system.
*
* Typically this function configures the oscillator (PLL) that is part of the
* microcontroller device. For systems with variable clock speed it also updates
* the variable SystemCoreClock. SystemInit is called from startup_device file.
*/
void SystemInit(void);
/**
* @brief Updates the SystemCoreClock variable.
*
* It must be called whenever the core clock is changed during program
* execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates
* the current core clock.
*/
void SystemCoreClockUpdate(void);
#ifdef __cplusplus
}
#endif
#endif /* _SYSTEM_MK65F18_H_ */

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 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.
*/
#if !defined(__TARGET_CONFIG_H__)
#define __TARGET_CONFIG_H__
/*******************************************************************************
* Definitions
******************************************************************************/
//! @brief Constants for clock frequencies.
enum _target_clocks
{
kDefaultClock = 20971520u,
kMcgOutWithFullSpeedUsb = 48000000u,
kMcgOutWithHighSpeedUsb = 120000000u,
kMinCoreClockWithFsUsbSupport = 20000000u,
kMaxCoreClock = 180000000u,
kMaxBusClock = 60000000u,
kMaxFlexBusClock = 60000000u,
kMaxFlashClock = 28000000u,
kDivider_Min = 1,
kDivider_Max = 16,
};
//! @brief Constants for sram partition
enum _sram_partition
{
kSram_LowerPart = 1,
kSram_UpperPart = 3,
};
//! @brief Version constants for the target.
enum _target_version_constants
{
kTarget_Version_Name = 'T',
kTarget_Version_Major = 1,
kTarget_Version_Minor = 0,
kTarget_Version_Bugfix = 0
};
#endif // __TARGET_CONFIG_H__

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\MK65F18\embedded_host.ewp</path>
</project>
<batchBuild/>
</workspace>

View File

@@ -0,0 +1,158 @@
/*
* Copyright (c) 2014-2015, 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.
*/
#ifndef __BOOTLOADER_CONFIG_H__
#define __BOOTLOADER_CONFIG_H__
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//
// Bootloader configuration options
//
//! @name Peripheral configuration macros
//@{
#if !defined(BL_CONFIG_UART)
#define BL_CONFIG_UART (1)
#endif
#if !defined(BL_CONFIG_SCUART)
#define BL_CONFIG_SCUART (1)
#endif
#if !defined(BL_CONFIG_LPUART)
#define BL_CONFIG_LPUART (1)
#endif
#if !defined(BL_CONFIG_CAN)
#define BL_CONFIG_CAN (1)
#endif
#if !defined(BL_CONFIG_I2C)
#define BL_CONFIG_I2C (1)
#endif
#if !defined(BL_CONFIG_SPI)
#define BL_CONFIG_SPI (1)
#endif
#if !defined(BL_CONFIG_DSPI)
#define BL_CONFIG_DSPI (1)
#endif
#if !defined(BL_CONFIG_USB)
#define BL_CONFIG_USB (1)
#endif
#if !defined(BL_CONFIG_USB_HID)
#define BL_CONFIG_USB_HID (0)
#endif
#if !defined(BL_CONFIG_USB_MSC)
#define BL_CONFIG_USB_MSC (1)
#endif
#if !defined(BL_CONFIG_USB_HID)
#define BL_CONFIG_USB_HID (1)
#endif
#if !defined(BL_CONFIG_HS_USB_HID)
#define BL_CONFIG_HS_USB_HID (0) // For TOWER and FRDM boards
#endif
#if !defined(BL_CONFIG_HS_USB_MSC)
#define BL_CONFIG_HS_USB_MSC (1) // For TOWER and FRDM boards
#endif
//@}
#if !defined(BL_TARGET_FLASH) && !defined(BL_TARGET_RAM)
#define BL_TARGET_FLASH (1)
#endif
#if !defined(BL_TARGET_RAM)
#define BL_FEATURE_CRC_CHECK (1)
#endif
#define BL_FEATURE_QSPI_MODULE (0)
#define BL_FEATURE_ENCRYPTION (1)
#define BL_FEATURE_UART_AUTOBAUD_IRQ (1)
// Bootloader peripheral detection default timeout in milliseconds
// After coming out of reset the bootloader will spin in a peripheral detection
// loop for this amount of time. A zero value means no time out.
#if DEBUG
#define BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT 0
#else
#define BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT 5000
#endif // DEBUG
#define BL_FEATURE_POWERDOWN (0)
// Bootloader powerdown timeout in milliseconds
// The bootloader enters a low power mode after waiting for this amount of time. A zero value means // no time out. Only
// applicable if BL_FEATURE_POWERDOWN is enabled.
#if DEBUG
#define BL_DEFAULT_POWERDOWN_TIMEOUT 10000
#else
#define BL_DEFAULT_POWERDOWN_TIMEOUT 600000
#endif // DEBUG
// The bootloader will check this address for the application vector table upon startup.
#if !defined(BL_APP_VECTOR_TABLE_ADDRESS)
#define BL_APP_VECTOR_TABLE_ADDRESS 0xa000
#endif
/* Serial Port Info */
/**************************************************************************
* Note:
*
* Because of the changes to the UART modules, we can no longer define
* the TERM_PORT as a base pointer. The uart functions have been modified
* accommodate this change. Now, TERM_PORT_NUM must be defined as the
* number of the UART port desired to use
*
* TERM_PORT_NUM = 0 -- This allows you to use UART0; default pins are
* PTA14 and PTA15
*
* TERM_PORT_NUM = 1 -- This allows you to use UART1; default pins are
* PTC3 and PTC4
*
* TERM_PORT_NUM = 2 -- This allows you to use UART2; default pins are
* PTD2 and PTD3
*
*************************************************************************/
#define TERM_PORT_NUM 0
#define TERMINAL_BAUD 19200
#undef HW_FLOW_CONTROL
#endif // __BOOTLOADER_CONFIG_H__
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2015, 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.
*/
#ifndef __USB_DISK_H__
#define __USB_DISK_H__ 1
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "usb_device_class.h"
#include "usb_device_msc.h"
#include "usb_device_ch9.h"
#include "usb_descriptor.h"
#include "flash/fsl_flash.h"
#include "executable_image.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
#define CONTROLLER_ID kUSB_ControllerEhci0
#endif
#if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
#define CONTROLLER_ID kUSB_ControllerKhci0
#endif
#define USB_DEVICE_INTERRUPT_PRIORITY (4)
/* Length of Each Logical Address Block */
#define LENGTH_OF_EACH_LBA (512)
/* total number of logical blocks present */
#define TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL (48)
/* Net Disk Size , default disk is 48*512, that is 24kByte, however , the disk reconnised by that PC only has 4k Byte,
* This is caused by that the file system also need memory*/
#define DISK_SIZE_NORMAL (TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL * LENGTH_OF_EACH_LBA)
#define LOGICAL_UNIT_SUPPORTED (1U)
#define USB_DEVICE_MSC_WRITE_BUFF_NUM 2
#define USB_DEVICE_MSC_WRITE_BUFF_SIZE 512
#define USB_DEVICE_MSC_READ_BUFF_SIZE 512
#define MSD_FLASH_BASE IMAGE_START_ADDRESS
// Program Flash block information
#define P_FLASH_BASE 0x00000000
#define P_FLASH_SIZE (FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE * FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT)
#define P_BLOCK_NUM FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT
#define P_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
typedef struct _usb_msc_struct
{
usb_device_handle deviceHandle;
class_handle_t mscHandle;
uint8_t storageDisk[DISK_SIZE_NORMAL];
uint8_t diskLock;
uint8_t read_write_error;
uint8_t currentConfiguration;
uint8_t currentInterfaceAlternateSetting[USB_MSC_INTERFACE_COUNT];
uint8_t speed;
uint8_t attach;
} usb_msc_struct_t;
extern flash_config_t s_flashInstance;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
void disk_init(void);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,183 @@
/*
* Copyright (c) 2013, 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.
*/
#if !defined(_FAT_DIRECTORY_ENTRY_H_)
#define _FAT_DIRECTORY_ENTRY_H_
#include "bootloader_common.h"
#include <wchar.h>
//! @addtogroup fat_dir_entry
//! @{
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief FAT filesystem directory entry attributes.
enum _fat_directory_attributes
{
kReadOnlyAttribute = 0x01, //!< Read only.
kHiddenAttribute = 0x02, //!< Hidden.
kSystemAttribute = 0x04, //!< System.
kVolumeIdAttribute = 0x08, //!< Volume ID.
kDirectoryAttribute = 0x10, //!< Directory.
kArchiveAttribute = 0x20, //!< Archive
//! Attribute value to identify a long file name entry.
kLongNameAttribute = kReadOnlyAttribute | kHiddenAttribute | kSystemAttribute | kVolumeIdAttribute,
//! Marker flag for long name entry order field to indicate the final long name entry.
kLastLongNameEntry = 0x40,
//! The first name byte is set to this value to mark a directory entry as free.
kFreeEntryMarkerByte = 0xe5
};
#pragma pack(push)
#pragma pack(1)
//! @brief FAT filesystem directory entry.
//!
//! This union can represent either a standard file or directory entry, or a long file name entry.
//!
//! The upper 2 bits of the attribute byte are reserved and should always be set to 0 when a
//! file is created and never modify or look at it after that.
//!
//! The ntReserved field must be set to 0 when file is created and never modified or look at it after that.
//!
//! The creationTimeTenths field actually contains a count of tenths of a second. The granularity
//! of the seconds part of the creationTime is two seconds so this field is a count of tenths of a
//! second and its valid value range is 0-199 inclusive.
//!
//! Note that there is no last access time, only a date. This is the date of last read or
//! write. In the case of a write, this should be set to the same date as DIR_WrtDate.
//!
//! The firstClusterHigh field will always be 0 for a FAT12 or FAT16 volume.
//!
//! Note that file creation is considered a write.
typedef union FatDirectoryEntry
{
//! Standard file or directory entry with a short name.
struct
{
uint8_t name[11]; //!< Short file name.
uint8_t attributes; //!< File attributes.
uint8_t ntReserved; //!< Reserved.
uint8_t creationTimeTenths; //!< Millisecond stamp at file creation time.
uint16_t creationTime; //!< Time file was created.
uint16_t creationDate; //!< Date file was created.
uint16_t lastAccessDate; //!< Last access date.
uint16_t firstClusterHigh; //!< High two bytes of this entry's first cluster number.
uint16_t writeTime; //!< Time of last write.
uint16_t writeDate; //!< Date of last write.
uint16_t firstClusterLow; //!< Low two bytes of this entry's first cluster number.
uint32_t fileSize; //!< This file's size in bytes.
} entry;
//! Long file name directory entry.
struct
{
uint8_t order; //!< Order of this long file name entry. May be masked with #kLastLongNameEntry.
wchar_t name1[5]; //!< Characters 1-5 of the long name.
uint8_t attributes; //!< Must be set to #kLongNameAttribute.
uint8_t entryType; //!< Should be 0 for long file name directory entries.
uint8_t checksum; //!< Checksum of the short file name.
wchar_t name2[6]; //!< Characters 6-11 of the long name.
uint16_t firstClusterLow; //!< Must be set to 0 for compatibility.
wchar_t name3[2]; //!< Character 12-13 of the long name.
} longName;
} fat_directory_entry_t;
#pragma pack(pop)
//! @brief Macro to help build a standard directory entry.
#define MAKE_FAT_VOLUME_LABEL(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, t, d) \
{ \
.entry = { \
.name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
.attributes = kVolumeIdAttribute, \
.writeTime = (t), \
.writeDate = (d), \
} \
}
//! @brief Macro to help build a standard directory entry.
//!
//! Creation, last access, and write times/dates are all set to the same value.
//!
//! @param c1-c11 Characters of the file/directory name in 8.3 format.
//! @param a Attribute value.
//! @param t Time value.
//! @param d Date value.
//! @param cluster First cluster low. The first cluster high is set to 0.
//! @param s File size in bytes.
#define MAKE_FAT_DIR_ENTRY(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, a, t, d, cluster, s) \
{ \
.entry = {.name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
.attributes = (a), \
.creationTime = (t), \
.creationDate = (d), \
.lastAccessDate = (d), \
.writeTime = (t), \
.writeDate = (d), \
.firstClusterLow = (cluster), \
.fileSize = (s) } \
}
//! @brief Macro to help build a long name directory entry.
//!
//! @param o The order number for this entry.
//! @param c1-c13 Thirteen UTF16 characters.
//! @param k Checksum over the short name.
//! @param l Pass #kLastLongNameEntry if this is the last long file entry, or 0 otherwise.
#define MAKE_FAT_LONG_NAME(o, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, k, l) \
{ \
.longName = {.order = (o) | (l), \
.name1 = { (c1), (c2), (c3), (c4), (c5) }, \
.attributes = kLongNameAttribute, \
.checksum = (k), \
.name2 = { (c6), (c7), (c8), (c9), (c10), (c11) }, \
.name3 = { (c12), (c13) } } \
}
//! @brief Construct a FAT date value.
//!
//! Bits 0<><30>?: Day of month, valid value range 1-31 inclusive.<br/>
//! Bits 5<><35>?: Month of year, 1 = January, valid value range 1<><31>?2 inclusive.<br/>
//! Bits 9<><39>?5: Count of years from 1980, valid value range 0<><30>?27 inclusive (1980<38><30>?107).
#define MAKE_FAT_DATE(d, m, y) ((uint16_t)(((((y)-1980) & 0x7f) << 9) | (((m)&0xf) << 5) | ((d)&0x1f)))
//! @brief Construct a FAT time value.
//!
//! Bits 0<><30>?: 2-second count, valid value range 0<><30>?9 inclusive (0 <20><>?58 seconds).<br/>
//! Bits 5<><35>?0: Minutes, valid value range 0<><30>?9 inclusive.<br/>
//! Bits 11<31><31>?5: Hours, valid value range 0<><30>?3 inclusive.
#define MAKE_FAT_TIME(h, m, s) ((uint16_t)((((h)&0x1f) << 11) | (((m)&0x3f) << 5) | (((s) / 2) & 0x1f)))
//! @}
#endif // _FAT_DIRECTORY_ENTRY_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2015, 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.
*/
#ifndef __USB_DEVICE_DESCRIPTOR_H__
#define __USB_DEVICE_DESCRIPTOR_H__
/*******************************************************************************
* Definitions
******************************************************************************/
#define USB_DEVICE_SPECIFIC_BCD_VERSION (0x0200U)
#define USB_DEVICE_DEMO_BCD_VERSION (0x0101U)
#define USB_DEVICE_MAX_POWER (0x32U)
#define USB_CONFIGURE_COUNT (1U)
#define USB_DEVICE_STRING_COUNT (4U)
#define USB_DEVICE_LANGUAGE_COUNT (1U)
#define USB_INTERFACE_COUNT (1U)
#define USB_MSC_CONFIGURE_INDEX (1U)
#define USB_MSC_ENDPOINT_COUNT (2U)
#define USB_MSC_BULK_IN_ENDPOINT (1U)
#define USB_MSC_BULK_OUT_ENDPOINT (2U)
/* usb descritpor length */
#define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL \
(USB_DESCRIPTOR_LENGTH_CONFIGURE + USB_DESCRIPTOR_LENGTH_INTERFACE + \
USB_DESCRIPTOR_LENGTH_ENDPOINT * USB_MSC_ENDPOINT_COUNT)
#define HS_MSC_BULK_IN_PACKET_SIZE (512U)
#define HS_MSC_BULK_OUT_PACKET_SIZE (512U)
#define FS_MSC_BULK_IN_PACKET_SIZE (64U)
#define FS_MSC_BULK_OUT_PACKET_SIZE (64U)
#define USB_STRING_DESCRIPTOR_HEADER_LENGTH (0x02U)
#define USB_STRING_DESCRIPTOR_0_LENGTH (0x02U)
#define USB_STRING_DESCRIPTOR_1_LENGTH (56U)
#define USB_STRING_DESCRIPTOR_2_LENGTH (32U)
#define USB_STRING_DESCRIPTOR_3_LENGTH (32U)
#define USB_STRING_DESCRIPTOR_ERROR_LENGTH (32U)
#define USB_MSC_INTERFACE_INDEX (0U)
#define USB_MSC_INTERFACE_COUNT (1U)
#define USB_DEVICE_CLASS (0x00U)
#define USB_DEVICE_SUBCLASS (0x00U)
#define USB_DEVICE_PROTOCOL (0x00U)
#define USB_MSC_CLASS (0x08U)
/* scsi command set */
#define USB_MSC_SUBCLASS (0x06U)
/* bulk only transport protocol */
#define USB_MSC_PROTOCOL (0x50U)
extern usb_device_class_struct_t g_UsbDeviceMscConfig;
extern usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed);
usb_status_t USB_DeviceGetDeviceDescriptor(usb_device_handle handle,
usb_device_get_device_descriptor_struct_t *deviceDescriptor);
usb_status_t USB_DeviceGetConfigurationDescriptor(
usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor);
usb_status_t USB_DeviceGetStringDescriptor(usb_device_handle handle,
usb_device_get_string_descriptor_struct_t *stringDescriptor);
#endif

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2015, 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.
*/
#ifndef _USB_DEVICE_CONFIG_H_
#define _USB_DEVICE_CONFIG_H_
/*******************************************************************************
* Definitions
******************************************************************************/
/*!
* @addtogroup usb_device_configuration
* @{
*/
/*!
* @name Hardware instance define
* @{
*/
/*! @brief KHCI instance count */
#define USB_DEVICE_CONFIG_KHCI (1U)
/*! @brief EHCI instance count */
#define USB_DEVICE_CONFIG_EHCI (0U)
/*! @brief Device instance count, the sum of KHCI and EHCI instance counts*/
#define USB_DEVICE_CONFIG_NUM (USB_DEVICE_CONFIG_KHCI + USB_DEVICE_CONFIG_EHCI)
/* @} */
/*!
* @name class instance define
* @{
*/
/*! @brief HID instance count */
#define USB_DEVICE_CONFIG_HID (0U)
/*! @brief CDC ACM instance count */
#define USB_DEVICE_CONFIG_CDC_ACM (0U)
/*! @brief MSC instance count */
#define USB_DEVICE_CONFIG_MSC (1U)
/*! @brief Audio instance count */
#define USB_DEVICE_CONFIG_AUDIO (0U)
/*! @brief PHDC instance count */
#define USB_DEVICE_CONFIG_PHDC (0U)
/*! @brief Video instance count */
#define USB_DEVICE_CONFIG_VIDEO (0U)
/*! @brief CCID instance count */
#define USB_DEVICE_CONFIG_CCID (0U)
/*! @brief Printer instance count */
#define USB_DEVICE_CONFIG_PRINTER (0U)
/*! @brief DFU instance count */
#define USB_DEVICE_CONFIG_DFU (0U)
/* @} */
/*! @brief Whether device is self power. 1U supported, 0U not supported */
#define USB_DEVICE_CONFIG_SELF_POWER (1U)
/*! @brief Whether device remote wakeup supported. 1U supported, 0U not supported */
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP (0U)
/*! @brief How many endpoints are supported in the stack. */
#define USB_DEVICE_CONFIG_ENDPOINTS (4U)
/*! @brief Whether the device task is enabled. */
#define USB_DEVICE_CONFIG_USE_TASK (0U)
/*! @brief How many the notification message are supported when the device task enabled. */
#define USB_DEVICE_CONFIG_MAX_MESSAGES (8U)
#if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U))
/*! @brief The MAX buffer length for the KHCI DMA workaround.*/
#define USB_DEVICE_CONFIG_KHCI_DMA_ALIGN_BUFFER_LENGTH (64U)
/*! @brief Whether handle the USB KHCI bus error. */
#define USB_DEVICE_CONFIG_KHCI_ERROR_HANDLING (0U)
#endif
#if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U))
/*! @brief How many the DTD are supported. */
#define USB_DEVICE_CONFIG_EHCI_MAX_DTD (16U)
/*! @brief Whether handle the USB EHCI bus error. */
#define USB_DEVICE_CONFIG_EHCI_ERROR_HANDLING (0U)
/*! @brief Whether test mode enabled. */
#define USB_DEVICE_CONFIG_EHCI_TEST_MODE (0U)
/*! @brief Whether the EHCI ID pin detect feature enabled. */
#define USB_DEVICE_CONFIG_EHCI_ID_PIN_DETECT (0U)
#endif
/*! @brief Whether the keep alive feature enabled. */
#define USB_DEVICE_CONFIG_KEEP_ALIVE_MODE (0U)
/*! @brief Whether the transfer buffer is cache-enabled or not. */
#define USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE (0U)
/*! @brief Whether the low power mode is enabled or not. */
#define USB_DEVICE_CONFIG_LOW_POWER_MODE (0U)
/*! @brief Whether the device detached feature is enabled or not. */
#define USB_DEVICE_CONFIG_DETACH_ENABLE (0U)
/* @} */
#endif /* _USB_DEVICE_CONFIG_H_ */

View File

@@ -0,0 +1,356 @@
/*
* Copyright (c) 2013, 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.
*/
#include "usb_msd_disk.h"
#include "fat_directory_entry.h"
/*******************************************************************************
* Definitions
******************************************************************************/
//! @brief Date and time constants for directory entries.
enum _date_time_constants
{
kFileDate = MAKE_FAT_DATE(12, 1, 2013), //!< 01-Dec-2013
kFileTime = MAKE_FAT_TIME(12, 0, 0) //!< 12:00:00 noon
};
/*******************************************************************************
* Variables
******************************************************************************/
//! @brief Partition boot sector.
//!
//! Defines the FAT16 file system.
//!
//! The 0xaa55 signature at the end of the sector is not stored in this data. Instead, it is
//! filled in at runtime. This is done in order to save const data space.
static const uint8_t k_pbs[] = {
0xEB,
0x3C,
0x90, // x86 JMP instruction
'M',
'S',
'W',
'I',
'N',
'4',
'.',
'1', // 'MSWIN4.1'
U16_LE(kDiskSectorSize), // bytes per sector = 512
0x01, // sectors per cluster = 1
U16_LE(1), // number of reserved sectors = 1 (FAT12/16)
0x02, // number of FATs = 2
U16_LE(32), // maximum number of root directory entries = 32
U16_LE(kDiskTotalLogicalBlocks - 1), // total volume sectors starting with PBS (16-bit count)
0xF0, // media type, must match FAT[0] = 0xf0 (removable media)
U16_LE(kDiskSectorsPerFat), // sectors per FAT = 1
U16_LE(1), // sectors per track = 1
U16_LE(1), // number of heads = 1
U32_LE(1), // sectors before start of PBS including MBR = 1
U32_LE(kDiskTotalLogicalBlocks - 1), // total volume sectors starting with PBS
0x00, // driver number (0x80 for hard disks) = 0
0x00, // reserved
0x29, // boot signature
'1',
'2',
'3',
'4', // volume ID = '1234'
'K',
'i',
'n',
'e',
't',
'i',
's',
' ',
'U',
'S',
'B', // volume label = 'Kinetis USB'
// ..448 reserved bytes
// 0x55,0xaa signature bytes - must be filled in at runtime
};
static const uint16_t k_fat1[] = {
0xfff0, // unused cluster 0 (low byte must match media type in PBS)
0xffff, // unused cluster 1
0xffff, // '.fseventsd' directory
0xffff, // 'System Volume Information' directory
0xffff, // 'IndexerVolumeGuid' file
0xffff, // 'info.txt' file
0xffff, // 'status.txt' file
};
//! @brief Root directory.
//!
//! Volume label: FSL Loader
//!
//! Contents:
//! - .fseventsd (FSEVEN~1)
//! - .metadata_never_index (METADA~1)
//! - .Trashes (TRASHE~1)
//! - System Volume Information (SYSTEM~1)
//! - info.txt
//! - status.txt
static const fat_directory_entry_t k_rootDir[] = {
// Volume label 'FSL Loader'
MAKE_FAT_VOLUME_LABEL('F', 'S', 'L', ' ', 'L', 'o', 'a', 'd', 'e', 'r', ' ', kFileTime, kFileDate),
// Mac OS X '.fseventsd' directory
MAKE_FAT_LONG_NAME(
1, L'.', L'f', L's', L'e', L'v', L'e', L'n', L't', L's', L'd', 0, 0xffff, 0xffff, 0xda, kLastLongNameEntry),
MAKE_FAT_DIR_ENTRY('F',
'S',
'E',
'V',
'E',
'N',
'~',
'1',
' ',
' ',
' ',
(kDirectoryAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kMacFseventsdDirSector),
0),
// Mac OS X '.metadata_never_index' file
MAKE_FAT_LONG_NAME(
2, L'e', L'r', L'_', L'i', L'n', L'd', L'e', L'x', 0, 0xffff, 0xffff, 0xffff, 0xffff, 0xa8, kLastLongNameEntry),
MAKE_FAT_LONG_NAME(1, L'.', L'm', L'e', L't', L'a', L'd', L'a', L't', L'a', L'_', L'n', L'e', L'v', 0xa8, 0),
MAKE_FAT_DIR_ENTRY('M',
'E',
'T',
'A',
'D',
'A',
'~',
'1',
' ',
' ',
' ',
(kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
0,
0),
// Mac OS X '.Trashes' file
MAKE_FAT_LONG_NAME(
1, L'.', L'T', L'r', L'a', L's', L'h', L'e', L's', 0, 0xffff, 0xffff, 0xffff, 0xffff, 0x25, kLastLongNameEntry),
MAKE_FAT_DIR_ENTRY('T',
'R',
'A',
'S',
'H',
'E',
'~',
'1',
' ',
' ',
' ',
(kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
0,
0),
// Windows 'System Volume Information' directory
MAKE_FAT_LONG_NAME(
2, L' ', L'I', L'n', L'f', L'o', L'r', L'm', L'a', L't', L'i', L'o', L'n', 0, 0x72, kLastLongNameEntry),
MAKE_FAT_LONG_NAME(1, L'S', L'y', L's', L't', L'e', L'm', L' ', L'V', L'o', L'l', L'u', L'm', L'e', 0x72, 0),
MAKE_FAT_DIR_ENTRY('S',
'Y',
'S',
'T',
'E',
'M',
'~',
'1',
' ',
' ',
' ',
(kDirectoryAttribute | kSystemAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kWindowsSysVolInfoDirSector),
0),
// Info and status files
MAKE_FAT_DIR_ENTRY('I',
'N',
'F',
'O',
' ',
' ',
' ',
' ',
'T',
'X',
'T',
kReadOnlyAttribute,
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kInfoFileSector),
1), // File size is filled in at runtime
MAKE_FAT_DIR_ENTRY('S',
'T',
'A',
'T',
'U',
'S',
' ',
' ',
'T',
'X',
'T',
kReadOnlyAttribute,
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kStatusFileSector),
1), // File size is filled in at runtime
};
//! @brief .fseventsd directory.
//!
//! Contents:
//! - .
//! - ..
//! - no_log
static const fat_directory_entry_t k_fseventsdDir[] = {
// . and .. directories
MAKE_FAT_DIR_ENTRY('.',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
(kDirectoryAttribute | kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kMacFseventsdDirSector),
0),
MAKE_FAT_DIR_ENTRY(
'.', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', kDirectoryAttribute, kFileTime, kFileDate, 0, 0),
// Special 'no_log' file with reserved byte set to 0x08.
{.entry = {.name = { 'N', 'O', '_', 'L', 'O', 'G', ' ', ' ', ' ', ' ', ' ' },
.attributes = kArchiveAttribute,
.ntReserved = 0x08,
.creationTime = kFileTime,
.creationDate = kFileDate,
.lastAccessDate = kFileDate,
.firstClusterHigh = 0,
.writeTime = kFileTime,
.writeDate = kFileDate,
.firstClusterLow = 0,
.fileSize = 0 } },
};
static const wchar_t k_indexerVolumeGuidFile[] = L"{37203BF8-FD83-4321-A4C4-9A9ABF8FBCFD}";
//! @brief System Volume Information directory.
//!
//! Contents:
//! - .
//! - ..
//! - IndexerVolumeGuid (INDEXE~1)
static const fat_directory_entry_t k_sysVolInfoDir[] = {
// . and .. directories
MAKE_FAT_DIR_ENTRY('.',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
(kDirectoryAttribute | kArchiveAttribute | kHiddenAttribute),
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kWindowsSysVolInfoDirSector),
0),
MAKE_FAT_DIR_ENTRY(
'.', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', kDirectoryAttribute, kFileTime, kFileDate, 0, 0),
// 'IndexerVolumeGuid' file
MAKE_FAT_LONG_NAME(
2, L'G', L'u', L'i', L'd', 0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 0, 0xff, kLastLongNameEntry),
MAKE_FAT_LONG_NAME(1, L'I', L'n', L'd', L'e', L'x', L'e', L'r', L'V', L'o', L'l', L'u', L'm', L'e', 0xff, 0),
MAKE_FAT_DIR_ENTRY('I',
'N',
'D',
'E',
'X',
'E',
'~',
'1',
' ',
' ',
' ',
kArchiveAttribute,
kFileTime,
kFileDate,
CLUSTER_FROM_SECTOR(kWindowsIndexerVolumeGuidSector),
(sizeof(k_indexerVolumeGuidFile) - 1)), // subtract 1 to remove the trailing null byte
};
const sector_info_t g_msdDiskSectors[] = {
{ kPbsSector, k_pbs, sizeof(k_pbs) },
{ kFat1Sector, (const uint8_t *)k_fat1, sizeof(k_fat1) },
{ kRootDir1Sector, (const uint8_t *)k_rootDir, sizeof(k_rootDir) },
// Support for Mac OS X: .fseventsd directory
{ kMacFseventsdDirSector, (const uint8_t *)k_fseventsdDir, sizeof(k_fseventsdDir) },
// Support for Window 8.1: System Volume Information directory
{ kWindowsSysVolInfoDirSector, (const uint8_t *)k_sysVolInfoDir, sizeof(k_sysVolInfoDir) },
{ kWindowsIndexerVolumeGuidSector, (const uint8_t *)k_indexerVolumeGuidFile,
sizeof(k_indexerVolumeGuidFile) - 1 }, // subtract 1 to remove the trailing null byte
// contains info.txt
// { kInfoFileSector, (const uint8_t *)((const uint8_t *)BlockBuf + 512), 512 },
//
// // contains status.txt
// { kStatusFileSector, (const uint8_t *)((const uint8_t *)BlockBuf + 1024), 512 },
// Terminator
{ 0 }
};

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 2013, 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.
*/
#if !defined(_USB_MSD_DISK_H_)
#define _USB_MSD_DISK_H_
//#include "bootloader_common.h"
#include "fsl_common.h"
//! @addtogroup usb_msd_disk
//! @{
/*******************************************************************************
* Definitions
******************************************************************************/
//! @name Data format macros
//@{
//! @brief Format a 32-bit little endian word as four bytes separated by commas.
#define U32_LE(n) ((n)&0xff), (((n) >> 8) & 0xff), (((n) >> 16) & 0xff), (((n) >> 24) & 0xff)
//! @brief Format a 16-bit little endian half-word as two bytes separated by commas.
#define U16_LE(n) ((n)&0xff), (((n) >> 8) & 0xff)
//@}
//! @brief Disk related constants.
enum _disk_constants
{
kDiskSectorSize = 512, //!< Size in bytes of each sector of the disk.
kDiskTotalLogicalBlocks = 2048, //!< Total number of sectors in the disk.
kDiskSizeInBytes = kDiskTotalLogicalBlocks * kDiskSectorSize, //!< Size in bytes of the total disk.
kDiskLogicalUnits = 1, //!< Number of SCSI LUNs.
kDiskHeaderSectorCount = 1, //!< PBS
kDiskFat16EntrySize = 2, //!< Two bytes per FAT16 entry.
kDiskClusterSize = 1, //!< Number of sectors per cluster.
kDiskDataClusterCount = (kDiskTotalLogicalBlocks - kDiskHeaderSectorCount) / kDiskClusterSize,
kDiskSectorsPerFat = (kDiskDataClusterCount * kDiskFat16EntrySize + kDiskSectorSize - 1) /
kDiskSectorSize, //!< Number of sectors occupied by each FAT, rounded up.
};
//! @brief Sector number constants.
enum _sector_numbers
{
kPbsSector = 0, //!< Partition Boot Sector
kFat1Sector = kPbsSector + 1, //!< FAT1
kFat2Sector = kFat1Sector + kDiskSectorsPerFat, //!< FAT2 (unused)
kRootDir1Sector = kFat2Sector + kDiskSectorsPerFat, //!< Root directory 1 (16 x 32-byte entries)
kRootDir2Sector, //!< Root directory 2 (16 x 32-byte entries)
kMacFseventsdDirSector, //!< Mac OS X '.fseventsd' directory
kWindowsSysVolInfoDirSector, //!< Windows 8.1 'System Volume Information' directory
kWindowsIndexerVolumeGuidSector, //!< Windows 8.1 'IndexerVolumeGuid' file
kInfoFileSector, //!< Info .txt file
kStatusFileSector, //!< Status .txt file
kFirstUnusedSector, //!< First sector available for data.
kFirstClusterSector = kRootDir1Sector, //!< Sector number of the first cluster.
};
//! @brief Convert a sector number to a cluster number.
#define CLUSTER_FROM_SECTOR(s) (((s)-kFirstClusterSector) / kDiskClusterSize)
//! @brief Root directory entry constants.
enum _root_dir_entry_numbers
{
kInfoFileDirEntry = 11,
kStatusFileDirEntry = 12,
kFirstUnusedDirEntry = 13
};
//! @brief Sector information.
//!
//! Information about canned sectors. The sector data does not have to completely fill the
//! sector. Any remainder bytes will be cleared to zero in the sector read function.
typedef struct SectorInfo
{
uint32_t sector; //!< Sector number.
const uint8_t *data; //!< Data for the sector.
uint32_t length; //!< Number of bytes of data.
} sector_info_t;
/*******************************************************************************
* Variables
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
extern const sector_info_t g_msdDiskSectors[];
#if defined(__cplusplus)
}
#endif /* __cplusplus */
//! @}
#endif // _USB_MSD_DISK_H_

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013 - 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.
*/
#include "SB_image.h"
#include "blsh/host_command.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
static uint32_t get_SB_image_length(uint32_t image_address);
/*******************************************************************************
* Code
******************************************************************************/
recordStatus_t SB_image_program(uint32_t image_address)
{
uint32_t image_length = get_SB_image_length(image_address);
if (handle_receiveSBFile_command(IMAGE_START_ADDRESS, image_length) != kStatus_Success)
{
return kRecordStatus_Fail;
}
return kRecordStatus_Success;
}
/*!
* @brief get SB image length
*
* @param image_address image address in target flash.
* @return the length of sb image
*/
static uint32_t get_SB_image_length(uint32_t image_address)
{
/* uint8_t hex[4] = {0}; */
uint32_t image_blocks = 0;
image_blocks = read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET + 3) << 24;
image_blocks |= read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET + 2) << 16;
image_blocks |= read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET + 1) << 8;
image_blocks |= read_flash_char(image_address, SB_IMAGE_BLOCKS_OFFSET);
/* Size of each block is 16 bytes */
return (image_blocks << 4);
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2013 - 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.
*/
#ifndef __SB_image_H__
#define __SB_image_H__
#include "executable_image.h"
/*******************************************************************************
* Definitions
******************************************************************************/
enum
{
/*! Image blocks offset */
SB_IMAGE_BLOCKS_OFFSET = 28,
};
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*! @brief parse SB image */
recordStatus_t SB_image_program(uint32_t image_address);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* __SB_image_H__ */

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2013 - 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.
*/
#include "binary_image.h"
#include "blsh/host_command.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Code
******************************************************************************/
recordStatus_t binary_image_program(uint32_t image_address, uint32_t image_length)
{
for (s_image_buffer_index = 0; s_image_buffer_index < image_length; s_image_buffer_index++)
{
s_image_buffer[s_image_buffer_index] = read_flash_char(image_address, s_image_buffer_index);
}
s_image_start_address = 0x8000;
if (handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index) != kStatus_Success)
{
return kRecordStatus_Fail;
}
return kRecordStatus_Success;
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2013 - 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.
*/
#ifndef __binary_image_H__
#define __binary_image_H__
#include "executable_image.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/* @brief parse srecord image */
recordStatus_t binary_image_program(uint32_t image_address, uint32_t image_length);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* __binary_image_H__ */

View File

@@ -0,0 +1,117 @@
/*
* Copyright (c) 2013 - 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.
*/
#include "executable_image.h"
#include "blsh/bllibc.h"
#include "srecord_image.h"
#include "intelhex_image.h"
#include "binary_image.h"
#include "SB_image.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
uint8_t s_image_buffer[IMAGE_BUFFER_SIZE] = { 0 };
uint32_t s_image_buffer_index = 0;
uint32_t s_image_start_address = 0;
uint32_t s_image_next_address = 0;
uint32_t s_image_base_address = 0;
/*******************************************************************************
* Code
******************************************************************************/
uint8_t read_flash_char(uint32_t address, uint32_t index)
{
return *(uint8_t *)(address + index);
}
uint8_t get_image_type()
{
if (read_flash_char(IMAGE_START_ADDRESS, SRECORD_SIGN_OFFSET) == SRECORD_SIGN)
{
return kImageType_Srecord;
}
else if (read_flash_char(IMAGE_START_ADDRESS, INTELHEX_SIGN_OFFSET) == INTELHEX_SIGN)
{
return kImageType_Intelhex;
}
else if ((read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET1) == SB_SIGN1) &&
(read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET2) == SB_SIGN2) &&
(read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET3) == SB_SIGN3) &&
(read_flash_char(IMAGE_START_ADDRESS, SB_SIGN_OFFSET4) == SB_SIGN4))
{
return kImageType_SB;
}
else if ((read_flash_char(IMAGE_START_ADDRESS, 0) != 0xff) || (read_flash_char(IMAGE_START_ADDRESS, 1) != 0xff) ||
(read_flash_char(IMAGE_START_ADDRESS, 2) != 0xff) || (read_flash_char(IMAGE_START_ADDRESS, 3) != 0xff))
{
return kImageType_Binary;
}
else
{
return kImageType_Invalid;
}
}
recordStatus_t flash_image(flash_image_status_t function)
{
uint8_t image_type = get_image_type();
uint32_t status = kRecordStatus_InvalidStart;
if (image_type == kImageType_Srecord)
{
status = srecord_image_program(IMAGE_START_ADDRESS);
}
else if (image_type == kImageType_Intelhex)
{
status = intelhex_image_program(IMAGE_START_ADDRESS);
}
else if (image_type == kImageType_SB)
{
status = SB_image_program(IMAGE_START_ADDRESS);
}
else if (image_type == kImageType_Binary)
{
// status = binary_image_program(IMAGE_START_ADDRESS, 1788);
status = kRecordStatus_InvalidType;
}
if (function != 0)
{
function(status);
}
return status;
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c) 2013 - 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.
*/
#ifndef __executable_image_H__
#define __executable_image_H__
#include <stdint.h>
/*******************************************************************************
* Definitions
******************************************************************************/
#define IMAGE_BUFFER_SIZE 1024 * 16
#define IMAGE_START_ADDRESS 0x00010000
/*! Image type value. */
enum
{
kImageType_SB = 0,
kImageType_Srecord = 1,
kImageType_Intelhex = 2,
kImageType_Binary = 3,
kImageType_Invalid = 4
};
enum
{
/*! The sb image sign. */
SB_SIGN1 = 'S',
SB_SIGN2 = 'T',
SB_SIGN3 = 'M',
SB_SIGN4 = 'P',
/*! The sign offeset form start address. */
SB_SIGN_OFFSET1 = 20,
SB_SIGN_OFFSET2 = 21,
SB_SIGN_OFFSET3 = 22,
SB_SIGN_OFFSET4 = 23
};
enum
{
/*! The srecord image sign. */
SRECORD_SIGN = 'S',
/*! The sign offeset form start address. */
SRECORD_SIGN_OFFSET = 0
};
enum
{
/*! The intelhex image sign. */
INTELHEX_SIGN = ':',
/*! The sign offeset form start address. */
INTELHEX_SIGN_OFFSET = 0
};
enum _recordStatus_t
{
kRecordStatus_Success = 0,
kRecordStatus_Fail = 1,
kRecordStatus_InvalidLength = 2,
kRecordStatus_InvalidStart = 3,
kRecordStatus_InvalidType = 4,
kRecordStatus_InvalidChecksum = 5,
kRecordStatus_FlashOver = 6,
kRecordStatus_FlashPartly = 7,
kRecordStatus_EraseOver = 8,
kRecordStatus_ErasePartly = 9
};
typedef uint8_t recordStatus_t;
//! @brief Type of callback for flash image status
typedef void (*flash_image_status_t)(recordStatus_t status);
extern uint8_t s_image_buffer[IMAGE_BUFFER_SIZE];
extern uint32_t s_image_buffer_index;
extern uint32_t s_image_start_address;
extern uint32_t s_image_next_address;
extern uint32_t s_image_base_address;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*! @brief read a char from flash region */
uint8_t read_flash_char(uint32_t address, uint32_t index);
/*! @brief get image type */
uint8_t get_image_type();
/*! @brief falsh_image function */
recordStatus_t flash_image(flash_image_status_t function);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* __executable_image_H__ */

View File

@@ -0,0 +1,477 @@
/*
* Copyright (c) 2013 - 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.
*/
#include "fsl_common.h"
#include "intelhex_image.h"
#include "blsh/bllibc.h"
#include "blsh/host_command.h"
/*******************************************************************************
* Definitions
******************************************************************************/
typedef struct _intelhex_record_t
{
uint8_t dataCount; /*!< The number of bytes in the data field. */
uint32_t address; /*!< The address offset of the data. */
uint8_t type; /*!< Type of the data field. 00: Data */
/*!< 01: End of File */
/*!< 02: Extended Segment Address */
/*!< 03: Start Segment Address */
/*!< 04: Extended Linear Address */
/*!< 05: Start Linear Address */
uint8_t data[256]; /*!< Pointer to data, or NULL if no data for this record. */
uint8_t checksum; /*!< The checksum byte used to verify the record. */
} intelhex_record_t;
/*******************************************************************************
* Variables
******************************************************************************/
static intelhex_record_t s_new_record = { 0 };
/*******************************************************************************
* Prototypes
******************************************************************************/
static recordStatus_t intelhex_record_parse_line(uint8_t *line, uint8_t line_length);
static recordStatus_t intelhex_record_build_image(intelhex_record_t *new_record);
static recordStatus_t intelhex_record_erase_target(uint32_t image_address);
static recordStatus_t intelhex_record_erase_region(intelhex_record_t *new_record);
/*******************************************************************************
* Code
******************************************************************************/
recordStatus_t intelhex_image_program(uint32_t image_address)
{
uint8_t image_char = 0;
uint32_t image_index = 0;
uint8_t line_buffer[256] = { 0 };
uint8_t line_index = 0;
recordStatus_t status = kRecordStatus_Fail;
/* Traverse the first time to erase target flash regions */
intelhex_record_erase_target(image_address);
/* Clear globle variable */
s_image_buffer_index = 0;
s_image_start_address = 0;
s_image_next_address = 0;
s_image_base_address = 0;
/* Traverse the second time to program target */
while (status != kRecordStatus_FlashOver)
{
image_char = read_flash_char(image_address, image_index);
image_index++;
if (image_char == '\n')
{
status = intelhex_record_parse_line(line_buffer, line_index);
if (status != kRecordStatus_Success)
{
return status;
}
line_index = 0;
/* Build image and program target */
status = intelhex_record_build_image(&s_new_record);
if (status == kRecordStatus_Fail)
{
return kStatus_Fail;
}
}
else if (image_char == '\r')
{
continue;
}
else
{
line_buffer[line_index++] = image_char;
}
}
return kRecordStatus_Success;
}
/*!
* @brief parse one line of intelhex record image
*
* @param line one line of the intelhex record.
* @param line_length the length of the line.
* @return parse status
*/
static recordStatus_t intelhex_record_parse_line(uint8_t *line, uint8_t line_length)
{
uint32_t checksum = 0;
uint32_t i = 0;
intelhex_record_t *new_record = &s_new_record;
/* Must be at least a certain length */
if (line_length < INTELHEX_MIN_LENGTH)
{
return kRecordStatus_InvalidLength;
}
/* Start char must be ':' */
if (line[0] != INTELHEX_START_CHAR)
{
return kRecordStatus_InvalidStart;
}
/* Parse count field */
new_record->dataCount = read_hex_byte(line, 1);
checksum += new_record->dataCount;
/* verify the record length now that we know the count */
if (line_length != 11 + new_record->dataCount * 2)
{
return kRecordStatus_InvalidLength;
}
/* Read address */
uint32_t address = 0;
for (i = 0; i < 2; ++i)
{
uint8_t address_byte = read_hex_byte(line, INTELHEX_ADDRESS_START_CHAR_INDEX + i * 2);
address = (address << 8) | address_byte;
checksum += address_byte;
}
new_record->address = address;
/* Handle data type */
new_record->type = read_hex_byte(line, INTELHEX_TYPE_START_CHAR_INDEX);
checksum += new_record->type;
switch (new_record->type)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
break;
default:
return kRecordStatus_InvalidType;
}
/* Read data */
if (new_record->dataCount)
{
for (i = 0; i < new_record->dataCount; ++i)
{
uint8_t data_byte = read_hex_byte(line, INTELHEX_DATA_START_CHAR_INDEX + i * 2);
new_record->data[i] = data_byte;
checksum += data_byte;
}
}
/* Read and compare checksum byte */
checksum = (~checksum + 1) & 0xff; /* low byte of one's complement of sum of other bytes */
new_record->checksum = read_hex_byte(line, line_length - 2);
if (checksum != new_record->checksum)
{
return kRecordStatus_InvalidChecksum;
}
return kRecordStatus_Success;
}
/*!
* @brief build intelhex srecord image and flash target
*
* @param new_record one line of the intelhex record.
* @return parse status
*/
static recordStatus_t intelhex_record_build_image(intelhex_record_t *new_record)
{
uint8_t is_data_record = 0;
uint8_t is_entry_record = 0;
uint8_t is_address_record = 0;
uint8_t is_eof_record = 0;
uint32_t status = 0;
if (new_record->type == INTELHEX_RECORD_DATA)
{
is_data_record = 1;
}
else if ((new_record->type == INTELHEX_RECORD_START_SEGMENT_ADDRESS) ||
(new_record->type == INTELHEX_RECORD_START_LINEAR_ADDRESS))
{
is_entry_record = 1;
}
else if ((new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS) ||
(new_record->type == INTELHEX_RECORD_EXTENDED_LINEAR_ADDRESS))
{
is_address_record = 1;
}
else if (new_record->type == INTELHEX_RECORD_END_OF_FILE)
{
is_eof_record = 1;
}
s_image_base_address = 0;
/* Handle 00 data record */
if (is_data_record)
{
if (s_image_buffer_index)
{
/* If this record's data would overflow the collection buffer, or if the */
/* record is not contiguous with the rest of the data in the collection */
/* buffer, then flush the buffer to the target and restart. */
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
(new_record->address != s_image_next_address))
{
/* flush the buffer to the target */
status = handle_writeMemory_command(s_image_start_address + s_image_base_address, s_image_buffer,
s_image_buffer_index);
s_image_buffer_index = 0;
if (status == kStatus_Fail)
{
return kStatus_Fail;
}
}
}
/* Capture addresses when starting an empty buffer. */
if (s_image_buffer_index == 0)
{
s_image_start_address = new_record->address;
s_image_next_address = s_image_start_address;
}
/* Copy record data into place in the collection buffer and update */
/* size and address. */
memcpy(&s_image_buffer[s_image_buffer_index], new_record->data, new_record->dataCount);
s_image_buffer_index += new_record->dataCount;
s_image_next_address += new_record->dataCount;
}
/* Hnadle 02, 04 record */
else if (is_address_record)
{
/* If there are data in the collection buffer, then flush the buffer to the target. */
if (s_image_buffer_index)
{
status = handle_writeMemory_command(s_image_start_address + s_image_base_address, s_image_buffer,
s_image_buffer_index);
s_image_buffer_index = 0;
if (status == kStatus_Fail)
{
return kStatus_Fail;
}
}
/* extended address stored at data field. */
s_image_base_address = (new_record->data[0] << 8) | new_record->data[1];
if (new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS)
{
s_image_base_address <<= 4;
}
else
{
s_image_base_address <<= 16;
}
}
/* Handle 03, 05 record */
else if (is_entry_record)
{
/* Nothing to do */
}
/* Handle 01 record */
else if (is_eof_record)
{
/* Flash any leftover data to target. */
if (s_image_buffer_index)
{
status = handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index);
s_image_buffer_index = 0;
if (status == kStatus_Fail)
{
return kStatus_Fail;
}
return kRecordStatus_FlashOver;
}
}
return kRecordStatus_Success;
}
/*!
* @brief erase target flash before program target
*
* @param image_address address of the image in host flash.
* @return parse status
*/
static recordStatus_t intelhex_record_erase_target(uint32_t image_address)
{
uint8_t image_char = 0;
uint32_t image_index = 0;
uint8_t line_buffer[256] = { 0 };
uint8_t line_index = 0;
recordStatus_t status = kRecordStatus_Fail;
while (status != kRecordStatus_EraseOver)
{
image_char = read_flash_char(image_address, image_index);
image_index++;
if (image_char == '\n')
{
status = intelhex_record_parse_line(line_buffer, line_index);
if (status != kRecordStatus_Success)
{
return status;
}
line_index = 0;
/* Erase flash regions */
status = intelhex_record_erase_region(&s_new_record);
}
else if (image_char == '\r')
{
continue;
}
else
{
line_buffer[line_index++] = image_char;
}
}
return kRecordStatus_Success;
}
/*!
* @brief eraset flash region based on record
*
* @param new_record one line of the intelhex record.
* @return parse status
*/
static recordStatus_t intelhex_record_erase_region(intelhex_record_t *new_record)
{
uint8_t is_data_record = 0;
uint8_t is_entry_record = 0;
uint8_t is_address_record = 0;
uint8_t is_eof_record = 0;
if (new_record->type == INTELHEX_RECORD_DATA)
{
is_data_record = 1;
}
else if ((new_record->type == INTELHEX_RECORD_START_SEGMENT_ADDRESS) ||
(new_record->type == INTELHEX_RECORD_START_LINEAR_ADDRESS))
{
is_entry_record = 1;
}
else if ((new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS) ||
(new_record->type == INTELHEX_RECORD_EXTENDED_LINEAR_ADDRESS))
{
is_address_record = 1;
}
else if (new_record->type == INTELHEX_RECORD_END_OF_FILE)
{
is_eof_record = 1;
}
s_image_base_address = 0;
/* Handle 00 data record */
if (is_data_record)
{
if (s_image_buffer_index)
{
/* If this record's data would overflow the collection buffer, or if the */
/* record is not contiguous with the rest of the data in the collection */
/* buffer, then erase flash region and restart. */
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
(new_record->address != s_image_next_address))
{
/* Erase target flash region */
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
s_image_buffer_index = 0;
}
}
/* Capture addresses when starting an empty buffer. */
if (s_image_buffer_index == 0)
{
s_image_start_address = new_record->address;
s_image_next_address = s_image_start_address;
}
/* update size and address. */
s_image_buffer_index += new_record->dataCount;
s_image_next_address += new_record->dataCount;
}
/* Hnadle 02, 04 record */
else if (is_address_record)
{
/* If there are data in the collection buffer, then flush the buffer to the executable image. */
if (s_image_buffer_index)
{
/* Erase target flash region */
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
s_image_buffer_index = 0;
}
/* extended address stored at data field. */
s_image_base_address = (new_record->data[0] << 8) | new_record->data[1];
if (new_record->type == INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS)
{
s_image_base_address <<= 4;
}
else
{
s_image_base_address <<= 16;
}
}
/* Handle 03, 05 record */
else if (is_entry_record)
{
/* Nothing to do */
}
/* Handle 01 record */
else if (is_eof_record)
{
/* Flash any leftover data to target. */
if (s_image_buffer_index)
{
/* Erase target flash region */
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
s_image_buffer_index = 0;
return kRecordStatus_EraseOver;
}
}
return kRecordStatus_Success;
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 2013 - 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.
*/
#ifndef __intelhex_image_H__
#define __intelhex_image_H__
#include "executable_image.h"
/*******************************************************************************
* Definitions
******************************************************************************/
enum
{
/*! The required first character of a Intel Hex */
INTELHEX_START_CHAR = ':',
/*! The minimum length of a Hex. This is the start char (1) + datacount (2) + addr (4) + type (2) + check sum (2).
*/
INTELHEX_MIN_LENGTH = 11,
/*! Index of the first character of the address field. */
INTELHEX_ADDRESS_START_CHAR_INDEX = 3,
/*! Index of the first character of the record type field. */
INTELHEX_TYPE_START_CHAR_INDEX = 7,
/*! Index of the first character of the record type field. */
INTELHEX_DATA_START_CHAR_INDEX = 9
};
/*! Intel Hex Record Type */
enum
{
/*! Data Record, which contains data and a 16-bit start address for the data. */
INTELHEX_RECORD_DATA = 0x00,
/*! End of File Record, which specifies the end of the hex file, and */
/*! must occur exactly once per file in the last line of the file. */
INTELHEX_RECORD_END_OF_FILE = 0x01,
/*! Extended Segment Address Record, which is used to specify bits 4- 19 of the Segment Base Address. */
INTELHEX_RECORD_EXTENDED_SEGMENT_ADDRESS = 0x02,
/*! Start Segment Address Record, which is used to specify the execution start address for the object file. */
INTELHEX_RECORD_START_SEGMENT_ADDRESS = 0x03,
/*! Extended Linear Address Record, which is used to specify bits 16- 31 of the Linear Base Address. */
INTELHEX_RECORD_EXTENDED_LINEAR_ADDRESS = 0x04,
/*! Start Linear Address Record, which is used to specify the execution start address for the object file. */
INTELHEX_RECORD_START_LINEAR_ADDRESS = 0x05
};
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*! @brief parse srecord image */
recordStatus_t intelhex_image_program(uint32_t image_address);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* __intelhex_image_H__ */

View File

@@ -0,0 +1,406 @@
/*
* Copyright (c) 2013 - 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.
*/
#include "fsl_common.h"
#include "srecord_image.h"
#include "blsh/bllibc.h"
#include "blsh/host_command.h"
/*******************************************************************************
* Definitions
******************************************************************************/
typedef struct _srecord_t
{
uint8_t type; /*!< Record number type, such as 9 for "S9", 3 for "S3" and so on.*/
uint8_t count; /*!< Number of character pairs (bytes) from address through checksum.*/
uint32_t address; /*!< The address specified as part of the S-record.*/
uint8_t dataCount; /*!< Number of bytes of data.*/
uint8_t data[256]; /*!< Pointer to data, or NULL if no data for this record type.*/
uint8_t checksum; /*!< The checksum byte present in the S-record.*/
} srecord_t;
/*******************************************************************************
* Variables
******************************************************************************/
static srecord_t s_new_record = { 0 };
/*******************************************************************************
* Prototypes
******************************************************************************/
static recordStatus_t srecord_parse_line(uint8_t *line, uint8_t line_length);
static recordStatus_t srecord_build_image(srecord_t *new_record);
static recordStatus_t srecord_erase_target(uint32_t image_address);
static recordStatus_t srecord_erase_region(srecord_t *new_record);
/*******************************************************************************
* Code
******************************************************************************/
recordStatus_t srecord_image_program(uint32_t image_address)
{
uint8_t image_char = 0;
uint32_t image_index = 0;
uint8_t line_buffer[256] = { 0 };
uint8_t line_index = 0;
recordStatus_t status = kRecordStatus_Fail;
/* Traverse the first time to erase target flash regions*/
srecord_erase_target(image_address);
/* Clear globle variable*/
s_image_buffer_index = 0;
s_image_start_address = 0;
s_image_next_address = 0;
s_image_base_address = 0;
/* Traverse the second time to program target*/
while (status != kRecordStatus_FlashOver)
{
image_char = read_flash_char(image_address, image_index);
image_index++;
if (image_char == '\n')
{
status = srecord_parse_line(line_buffer, line_index);
if (status != kRecordStatus_Success)
{
return status;
}
line_index = 0;
/* Build image and flash target*/
status = srecord_build_image(&s_new_record);
if (status == kRecordStatus_Fail)
{
return kStatus_Fail;
}
}
else if (image_char == '\r')
{
continue;
}
else
{
line_buffer[line_index++] = image_char;
}
}
return kRecordStatus_Success;
}
/*!
* @brief parse one line of srecord record image
*
* @param line one line of the srecord record.
* @param line_length the length of the line.
* @return parse status
*/
static recordStatus_t srecord_parse_line(uint8_t *line, uint8_t line_length)
{
uint32_t checksum = 0;
uint32_t i = 0;
srecord_t *new_record = &s_new_record;
if (line_length < SRECORD_MIN_LENGTH)
{
return kRecordStatus_InvalidLength;
}
if (line[0] != SRECORD_START_CHAR)
{
return kRecordStatus_InvalidStart;
}
/* Parse type field*/
if ((line[1] > '9') || (line[1] < '0'))
{
return kRecordStatus_InvalidType;
}
new_record->type = line[1] - '0';
/* Parse count field*/
new_record->count = read_hex_byte(line, 2);
checksum += new_record->count;
/* verify the record length now that we know the count*/
if (line_length != 4 + new_record->count * 2)
{
return kRecordStatus_InvalidLength;
}
/* Get address length*/
uint8_t address_length = 0;
uint8_t has_data = 0;
switch (new_record->type)
{
case 0:
address_length = 2;
has_data = 1;
break;
case 1:
address_length = 2;
has_data = 1;
break;
case 2:
address_length = 3;
has_data = 1;
break;
case 3:
address_length = 4;
has_data = 1;
break;
case 5:
address_length = 2;
break;
case 7:
address_length = 4;
break;
case 8:
address_length = 3;
break;
case 9:
address_length = 2;
break;
default:
return kRecordStatus_InvalidType;
}
/* Read address*/
uint32_t address = 0;
for (i = 0; i < address_length; i++)
{
uint8_t address_byte = read_hex_byte(line, SRECORD_ADDRESS_START_CHAR_INDEX + i * 2);
address = (address << 8) | address_byte;
checksum += address_byte;
}
new_record->address = address;
/* Read data*/
if (has_data)
{
int32_t data_start_char_index = 4 + address_length * 2;
int32_t data_length = new_record->count - address_length - 1;
for (i = 0; i < data_length; i++)
{
uint8_t data_byte = read_hex_byte(line, data_start_char_index + i * 2);
new_record->data[i] = data_byte;
checksum += data_byte;
}
new_record->dataCount = data_length;
}
/* Read and compare checksum byte*/
checksum = (~checksum) & 0xff; /* low byte of one's complement of sum of other bytes */
new_record->checksum = read_hex_byte(line, line_length - 2);
if (checksum != new_record->checksum)
{
return kRecordStatus_InvalidChecksum;
}
return kRecordStatus_Success;
}
/*!
* @brief build srecord image and flash target
*
* @param new_record one line of the intelhex record.
* @return parse status
*/
static recordStatus_t srecord_build_image(srecord_t *new_record)
{
uint8_t is_data_record = 0;
uint8_t has_data = 0;
uint32_t status = 0;
/* Handle S3, 2, 1 records */
if ((new_record->type == 3) || (new_record->type == 2) || (new_record->type == 1))
{
is_data_record = 1;
}
has_data = (new_record->data) && (new_record->dataCount);
if (is_data_record && has_data)
{
if (s_image_buffer_index)
{
/* If this record's data would overflow the collection buffer, or if the */
/* record is not contiguous with the rest of the data in the collection */
/* buffer, then flush the buffer to the executable image and restart. */
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
(new_record->address != s_image_next_address))
{
/* TO-DO flush */
status = handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index);
s_image_buffer_index = 0;
if (status == kStatus_Fail)
{
return kStatus_Fail;
}
}
}
/* Capture addresses when starting an empty buffer. */
if (s_image_buffer_index == 0)
{
s_image_start_address = new_record->address;
s_image_next_address = s_image_start_address;
}
/* Copy record data into place in the collection buffer and update */
/* size and address. */
memcpy(&s_image_buffer[s_image_buffer_index], new_record->data, new_record->dataCount);
s_image_buffer_index += new_record->dataCount;
s_image_next_address += new_record->dataCount;
}
else if ((new_record->type == 7) || (new_record->type == 8) || (new_record->type == 9))
{
/* Flash any leftover data to target. */
if (s_image_buffer_index)
{
status = handle_writeMemory_command(s_image_start_address, s_image_buffer, s_image_buffer_index);
s_image_buffer_index = 0;
if (status == kStatus_Fail)
{
return kRecordStatus_Fail;
}
return kRecordStatus_FlashOver;
}
}
return kRecordStatus_Success;
}
/*!
* @brief erase target flash before program target
*
* @param image_address address of the image in host flash.
* @return parse status
*/
static recordStatus_t srecord_erase_target(uint32_t image_address)
{
uint8_t image_char = 0;
uint32_t image_index = 0;
uint8_t line_buffer[256] = { 0 };
uint8_t line_index = 0;
recordStatus_t status = kRecordStatus_Fail;
while (status != kRecordStatus_EraseOver)
{
image_char = read_flash_char(image_address, image_index);
image_index++;
if (image_char == '\n')
{
status = srecord_parse_line(line_buffer, line_index);
if (status != kRecordStatus_Success)
{
return status;
}
line_index = 0;
/* Erase target */
status = srecord_erase_region(&s_new_record);
}
else if (image_char == '\r')
{
continue;
}
else
{
line_buffer[line_index++] = image_char;
}
}
return kRecordStatus_Success;
}
/*!
* @brief eraset flash region based on record
*
* @param new_record one line of the intelhex record.
* @return parse status
*/
static recordStatus_t srecord_erase_region(srecord_t *new_record)
{
uint8_t is_data_record = 0;
uint8_t has_data = 0;
/* Handle S3, 2, 1 records */
if ((new_record->type == 3) || (new_record->type == 2) || (new_record->type == 1))
{
is_data_record = 1;
}
has_data = (new_record->data) && (new_record->dataCount);
if (is_data_record && has_data)
{
if (s_image_buffer_index)
{
/* If this record's data would overflow the collection buffer, or if the */
/* record is not contiguous with the rest of the data in the collection */
/* buffer, then erase the flash region and restart. */
if (((s_image_buffer_index + new_record->dataCount) > IMAGE_BUFFER_SIZE) ||
(new_record->address != s_image_next_address))
{
/* Erase target flash region */
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
s_image_buffer_index = 0;
}
}
/* Capture addresses when starting an empty buffer. */
if (s_image_buffer_index == 0)
{
s_image_start_address = new_record->address;
s_image_next_address = s_image_start_address;
}
/* Update size and address. */
s_image_buffer_index += new_record->dataCount;
s_image_next_address += new_record->dataCount;
}
else if ((new_record->type == 7) || (new_record->type == 8) || (new_record->type == 9))
{
/* Erase target flash region */
if (s_image_buffer_index)
{
handle_flashEraseRegion_command(s_image_start_address, s_image_buffer_index);
s_image_buffer_index = 0;
return kRecordStatus_EraseOver;
}
}
return kRecordStatus_Success;
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2013 - 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.
*/
#ifndef __srecord_image_H__
#define __srecord_image_H__
#include "executable_image.h"
/*******************************************************************************
* Definitions
******************************************************************************/
enum
{
/*! The required first character of an S-record. */
SRECORD_START_CHAR = 'S',
/*! The minimum length of a S-record. This is the type (2) + count (2) + addr (4) + cksum (2). */
SRECORD_MIN_LENGTH = 10,
/*! Index of the first character of the address field. */
SRECORD_ADDRESS_START_CHAR_INDEX = 4
};
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*! @brief parse srecord image */
recordStatus_t srecord_image_program(uint32_t image_address);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* __srecord_image_H__ */

View File

@@ -0,0 +1,204 @@
/*
* Copyright (c) 2013 - 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.
*/
#include "host_hardware.h"
#include "blsh/host_blsh_cmd.h"
#include "blsh/host_command.h"
#include "microseconds/microseconds.h"
#include "board.h"
#include "gpio/fsl_gpio.h"
#include "executable_image.h"
enum
{
kSwitchStatus_Idle = 0,
kSwitchStatus_Lock = 1,
kSwitchStatus_Confirm = 2
};
static uint32_t s_switch2_press = 0;
static uint32_t s_switch3_press = kSPI_mode;
void embedded_host_blsh_init(void);
void flash_image_status_callback(recordStatus_t status);
/*!
* @brief embedded host main function.
*/
#if defined(__CC_ARM) || defined(__GNUC__)
int main(void)
#else
void main(void)
#endif
{
hardware_init();
host_blsh_cmd_init();
embedded_host_blsh_init();
while (!blsh_exit())
{
/* Wait blsh command */
blsh_run();
/* Fisrt press to lock the selection */
if (s_switch2_press == kSwitchStatus_Lock)
{
LED_YELLOW_ON;
}
/* Second press to ensure the selection */
else if (s_switch2_press == kSwitchStatus_Confirm)
{
microseconds_init();
/* Enter spi transfer mode */
if (s_switch3_press == kSPI_mode)
{
configure_transfer_bus(kSPI_mode, 100);
}
/* Enter i2c transfer mode */
else if (s_switch3_press == kI2C_mode)
{
configure_transfer_bus(kI2C_mode, 100);
}
/* Enter uart transfer mode */
else if (s_switch3_press == kUART_mode)
{
configure_transfer_bus(kUART_mode, 57600);
}
else if (s_switch3_press == kCAN_mode)
{
configure_transfer_bus(kCAN_mode, 125);
}
flash_image(flash_image_status_callback);
microseconds_shutdown();
LED_YELLOW_OFF;
s_switch2_press = kSwitchStatus_Idle;
}
}
#if (defined(__CC_ARM) || defined(__GNUC__))
return 1;
#endif
}
void flash_image_status_callback(recordStatus_t status)
{
if (status != kRecordStatus_Success)
{
LED_RED_ON;
blsh_printf("\r\n Flash image fail! \r\n > ");
}
else
{
LED_YELLOW_OFF;
LED_GREEN_OFF;
LED_BLUE_OFF;
LED_RED_OFF;
s_switch3_press = kSPI_mode;
blsh_printf("\r\n Flash image success. \r\n > ");
}
}
void embedded_host_blsh_init(void)
{
command_add(&flash_image_cmd);
command_add(&write_memory_cmd);
command_add(&read_memory_cmd);
command_add(&fill_memory_cmd);
command_add(&flash_security_disable_cmd);
command_add(&flash_erase_all_unsecure_cmd);
command_add(&flash_erase_all_cmd);
command_add(&flash_erase_region_cmd);
command_add(&execute_cmd);
command_add(&call_cmd);
command_add(&flash_program_once_cmd);
command_add(&flash_read_once_cmd);
command_add(&flash_read_resource_cmd);
}
/*!
* @brief Switch interrupt irq hander.
*/
void BOARD_SW_IRQ_HANDLER(void)
{
/* Clear external interrupt flag. */
uint32_t int_flags = GPIO_GetPinsInterruptFlags(BOARD_SW3_GPIO);
GPIO_ClearPinsInterruptFlags(BOARD_SW3_GPIO, 1U << BOARD_SW3_GPIO_PIN);
GPIO_ClearPinsInterruptFlags(BOARD_SW2_GPIO, 1U << BOARD_SW2_GPIO_PIN);
if (int_flags & BOARD_SW2_MASK)
{
s_switch2_press++;
if (s_switch2_press > kSwitchStatus_Confirm)
{
s_switch2_press = kSwitchStatus_Idle;
}
}
else if (int_flags & BOARD_SW3_MASK)
{
if (!s_switch2_press)
{
if (++s_switch3_press > kCAN_mode)
{
s_switch3_press = kSPI_mode;
}
if (s_switch3_press == kSPI_mode)
{
LED_GREEN_OFF;
LED_BLUE_OFF;
}
if (s_switch3_press == kI2C_mode)
{
LED_GREEN_ON;
LED_BLUE_OFF;
}
else if (s_switch3_press == kUART_mode)
{
LED_GREEN_OFF;
LED_BLUE_ON;
}
else if (s_switch3_press == kCAN_mode)
{
LED_GREEN_ON;
LED_BLUE_ON;
}
}
else
{
s_switch2_press = kSwitchStatus_Idle;
LED_YELLOW_OFF;
}
}
}