Add BusPal to the right firmware.

This commit is contained in:
László Monda
2017-04-11 22:11:56 +02:00
parent b402a96007
commit e39c5be9a9
34 changed files with 6505 additions and 9 deletions

View File

@@ -63,8 +63,10 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.include.paths.2122094274" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.include.paths"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs.7801442172" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs" valueType="definedSymbols">
<listOptionValue builtIn="false" value="DEBUG"/>
<listOptionValue builtIn="false" value="BL_CONFIG_USB_HID=1"/>
<listOptionValue builtIn="false" value="__STARTUP_CLEAR_BSS"/>
<listOptionValue builtIn="false" value="UHK_PCB_MAJOR_VERSION=7"/>
<listOptionValue builtIn="false" value="BOOTLOADER_HOST"/>
</option>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.nostdinc.4189903161" name="Do not search system directories (-nostdinc)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.nostdinc" value="false" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.other.1539698818" name="Other assembler flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.other" value=" -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs " valueType="string"/>
@@ -75,6 +77,9 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.336878990" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../../../src"/>
<listOptionValue builtIn="false" value="../../../src/ksdk_usb"/>
<listOptionValue builtIn="false" value="../../../src/buspal"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bootloader"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bm_usb"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/osa"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/include"/>
@@ -87,6 +92,8 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.933718024" name="Language standard" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.gnu99" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs.62587551" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="_DEBUG=1"/>
<listOptionValue builtIn="false" value="BL_CONFIG_USB_HID=1"/>
<listOptionValue builtIn="false" value="BOOTLOADER_HOST"/>
<listOptionValue builtIn="false" value="UHK_PCB_MAJOR_VERSION=7"/>
<listOptionValue builtIn="false" value="CPU_MK22FN512VLH12"/>
<listOptionValue builtIn="false" value="USB_STACK_BM"/>
@@ -641,6 +648,9 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.58271126" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../../../src"/>
<listOptionValue builtIn="false" value="../../../src/ksdk_usb"/>
<listOptionValue builtIn="false" value="../../../src/buspal"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bootloader"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bm_usb"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/osa"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/include"/>
@@ -773,8 +783,10 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.include.paths.1619685061" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.include.paths"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs.671721773" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs" valueType="definedSymbols">
<listOptionValue builtIn="false" value="DEBUG"/>
<listOptionValue builtIn="false" value="BL_CONFIG_USB_HID=1"/>
<listOptionValue builtIn="false" value="__STARTUP_CLEAR_BSS"/>
<listOptionValue builtIn="false" value="UHK_PCB_MAJOR_VERSION=7"/>
<listOptionValue builtIn="false" value="BOOTLOADER_HOST"/>
</option>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.nostdinc.2110956724" name="Do not search system directories (-nostdinc)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.nostdinc" value="false" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.other.1101826118" name="Other assembler flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.other" value=" -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs " valueType="string"/>
@@ -784,6 +796,9 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.450812741" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../../../src"/>
<listOptionValue builtIn="false" value="../../../src/ksdk_usb"/>
<listOptionValue builtIn="false" value="../../../src/buspal"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bootloader"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bm_usb"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/osa"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/include"/>
@@ -796,6 +811,8 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.104109443" name="Language standard" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.std.gnu99" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs.1312429299" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="_DEBUG=1"/>
<listOptionValue builtIn="false" value="BOOTLOADER_HOST"/>
<listOptionValue builtIn="false" value="BL_CONFIG_USB_HID=1"/>
<listOptionValue builtIn="false" value="CPU_MK22FN512VLH12"/>
<listOptionValue builtIn="false" value="UHK_PCB_MAJOR_VERSION=7"/>
<listOptionValue builtIn="false" value="USB_STACK_BM"/>
@@ -926,6 +943,9 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.936678785" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../../../src"/>
<listOptionValue builtIn="false" value="../../../src/ksdk_usb"/>
<listOptionValue builtIn="false" value="../../../src/buspal"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bootloader"/>
<listOptionValue builtIn="false" value="../../../src/buspal/bm_usb"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/osa"/>
<listOptionValue builtIn="false" value="../../../../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/include"/>
@@ -1170,6 +1190,7 @@
<configuration configurationName="debug">
<resource resourceType="PROJECT" workspacePath="/uhk-right"/>
</configuration>
<configuration configurationName="v6-debug-srec"/>
<configuration configurationName="release">
<resource resourceType="PROJECT" workspacePath="/uhk-right"/>
</configuration>

View File

@@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1105552145374691790" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1293828268692755744" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1104295286316259438" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1295085127751188096" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -27,7 +27,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1105552145374691790" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1293828268692755744" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -38,7 +38,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1104295286316259438" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1295085127751188096" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -49,7 +49,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1104295286316259438" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1295085127751188096" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -60,7 +60,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1105552145374691790" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1293828268692755744" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -71,7 +71,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1104295286316259438" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1295085127751188096" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -82,7 +82,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1105552145374691790" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1293828268692755744" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

View File

@@ -22,7 +22,7 @@ void InitUhkModules()
bool BridgeSlaveUhkModuleHandler(uint8_t uhkModuleId)
{
uhk_module_state_t *uhkModuleInternalState = UhkModuleStates + uhkModuleId;
uhk_module_state_t *uhkModuleExternalState = uhkModuleExternalStates + uhkModuleId;
//uhk_module_state_t *uhkModuleExternalState = uhkModuleExternalStates + uhkModuleId;
switch (currentUhkModuleField) {
case UhkModuleField_SendKeystatesRequestCommand:

View File

@@ -0,0 +1,4 @@
# BusPal Protocol Translator
BusPal is part of the [Kinetis Bootloader](http://www.nxp.com/products/reference-designs/kinetis-bootloader:KBOOT),
and it's used to translate the KBOOT protocol between the USB host and UHK slaves via I2C.

View File

@@ -0,0 +1,36 @@
#if !defined(__BOOTLOADER_HID_REPORT_IDS_H__)
#define __BOOTLOADER_HID_REPORT_IDS_H__
#include "packet/command_packet.h"
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief Report IDs to use for the bootloader.
enum _hid_report_ids
{
kBootloaderReportID_CommandOut = 1,
kBootloaderReportID_DataOut = 2,
kBootloaderReportID_CommandIn = 3,
kBootloaderReportID_DataIn = 4
};
//! @brief Structure of a bootloader HID header.
typedef struct _bl_hid_header
{
uint8_t reportID; //!< The report ID.
uint8_t _padding; //!< Pad byte necessary so that the length is 2-byte aligned and the data is 4-byte aligned. Set
//! to zero.
uint8_t packetLengthLsb; //!< Low byte of the packet length in bytes.
uint8_t packetLengthMsb; //!< High byte of the packet length in bytes.
} bl_hid_header_t;
//! @brief Structure of a bootloader HID report.
typedef struct _bl_hid_report
{
bl_hid_header_t header; //!< Header of the report.
uint8_t packet[kMinPacketBufferSize]; //!< The packet data that is transferred in the report.
} bl_hid_report_t;
#endif // __BOOTLOADER_HID_REPORT_IDS_H__

View File

@@ -0,0 +1,39 @@
#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_hid.h"
#include "usb_device_ch9.h"
#include "usb_descriptor.h"
#include "composite.h"
#include "fsl_device_registers.h"
#include <stdio.h>
#include <stdlib.h>
usb_device_class_config_struct_t g_composite_device[USB_COMPOSITE_INTERFACE_COUNT] = {
#if ((USB_DEVICE_CONFIG_HID) && (USB_DEVICE_CONFIG_HID > 0U))
{
usb_device_hid_generic_callback, (class_handle_t)NULL, &g_hid_generic_class,
},
#endif
#if USB_DEVICE_CONFIG_MSC
{
usb_device_msc_callback, (class_handle_t)NULL, &g_msc_class,
}
#endif
#if ((USB_DEVICE_CONFIG_HID == 0) && (USB_DEVICE_CONFIG_MSC == 0))
{
NULL, NULL, NULL,
}
#endif
};
usb_device_class_config_list_struct_t g_composite_device_config_list = {
g_composite_device, usb_device_callback, USB_COMPOSITE_INTERFACE_COUNT,
};

View File

@@ -0,0 +1,65 @@
#ifndef __USB_DEVICE_COMPOSITE_H__
#define __USB_DEVICE_COMPOSITE_H__ 1
//#include "msc_disk.h"
#include "hid_bootloader.h"
#include "usb_device_config.h"
#if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)
#define CONTROLLER_ID kUSB_ControllerEhci0
#endif
#if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0U)
#define CONTROLLER_ID kUSB_ControllerKhci0
#endif
#define USB_DEVICE_INTERRUPT_PRIORITY (4)
typedef struct _usb_device_composite_struct
{
usb_device_handle device_handle; // USB device handle.
#if ((defined(USB_DEVICE_CONFIG_HID)) && (USB_DEVICE_CONFIG_HID > 0U))
usb_hid_generic_struct_t hid_generic; // HID device structure
#endif
#if USB_DEVICE_CONFIG_MSC
usb_msc_struct_t msc_disk; // MSC disk device structure.
#endif // USB_DEVICE_CONFIG_MSC
uint8_t speed; // Speed of USB device. USB_SPEED_FULL/USB_SPEED_LOW/USB_SPEED_HIGH.
uint8_t attach; // A flag to indicate whether a usb device is attached. 1: attached, 0: not attached
uint8_t current_configuration; // Current configuration value.
uint8_t current_interface_alternate_setting[USB_COMPOSITE_INTERFACE_COUNT]; // Current alternate setting value for
// each interface.
} usb_device_composite_struct_t;
extern usb_status_t usb_device_callback(usb_device_handle handle, uint32_t event, void *param);
#if (BL_CONFIG_USB_HID || BL_CONFIG_HS_USB_HID)
// HID device initialization function
extern usb_status_t usb_device_hid_generic_init(usb_device_composite_struct_t *device_composite);
// HID class specific callback function
extern usb_status_t usb_device_hid_generic_callback(class_handle_t handle, uint32_t event, void *param);
// HID device set configuration function
extern usb_status_t usb_device_hid_generic_set_configure(class_handle_t handle, uint8_t configure);
// HID device set interface function
extern usb_status_t usb_device_hid_generic_set_interface(class_handle_t handle,
uint8_t interface,
uint8_t alternate_setting);
// HID device de-initialization function
extern usb_status_t usb_device_hid_generic_deinit(usb_device_composite_struct_t *device_composite);
#endif // #if BL_CONFIG_USB_HID
#if (BL_CONFIG_USB_MSC || BL_CONFIG_HS_USB_MSC)
// MSC disk device initialization function
extern usb_status_t usb_device_msc_disk_init(usb_device_composite_struct_t *device_composite);
// MSC class specific callback function
extern usb_status_t usb_device_msc_callback(class_handle_t handle, uint32_t event, void *param);
// MSC disk device set configuration function
extern usb_status_t usb_device_msc_disk_set_configure(class_handle_t handle, uint8_t configure);
// MSC disk device de-initialization function
extern usb_status_t usb_device_msc_disk_deinit(usb_device_composite_struct_t *device_composite);
void usb_device_msc_disk_pump(void);
#endif // #if BL_CONFIG_USB_MSC
extern usb_device_class_config_list_struct_t g_composite_device_config_list;
#endif

View File

@@ -0,0 +1,172 @@
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "usb_device_class.h"
#include "usb_device_hid.h"
#include "usb_device_ch9.h"
#include "usb_descriptor.h"
#include "hid_bootloader.h"
#include "fsl_device_registers.h"
#include "bootloader_hid_report_ids.h"
#include "utilities/fsl_rtos_abstraction.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "composite.h"
#if (BL_CONFIG_USB_HID || BL_CONFIG_HS_USB_HID)
/*******************************************************************************
* Variables
******************************************************************************/
extern usb_device_endpoint_struct_t g_hid_generic_endpoints[];
static usb_device_composite_struct_t *g_device_composite;
/* The hid class callback */
usb_status_t usb_device_hid_generic_callback(class_handle_t handle, uint32_t event, void *param)
{
usb_status_t error = kStatus_USB_Error;
usb_device_hid_report_struct_t *hid_report_param;
hid_report_param = (usb_device_hid_report_struct_t *)param;
const bl_hid_header_t *header;
switch (event)
{
case kUSB_DeviceHidEventSendResponse:
/*!< Send data completed */
if ((hid_report_param->reportLength == 0xFFFFFFFF) || (hid_report_param->reportLength == 0x0))
{
return kStatus_USB_Success;
}
if ((g_device_composite->hid_generic.hid_packet.sendSync > 0) &&
(g_device_composite->hid_generic.attach == 1))
// Protect against extra complete due to data abort.
{
// Signal that write has completed.
sync_signal(&g_device_composite->hid_generic.hid_packet.sendSync);
}
error = kStatus_USB_Success;
break;
case kUSB_DeviceHidEventRecvResponse:
/*!< Data received */
// Save the report size.
if ((hid_report_param->reportLength == 0xFFFFFFFF) || (hid_report_param->reportLength == 0x0))
{
return kStatus_USB_Success;
}
g_device_composite->hid_generic.hid_packet.reportSize = hid_report_param->reportLength;
g_device_composite->hid_generic.hid_packet.didReceiveFirstReport = true;
// Wake up the read packet handler.
sync_signal(&g_device_composite->hid_generic.hid_packet.receiveSync);
error = kStatus_USB_Success;
break;
case kUSB_DeviceHidEventGetReport:
/*!< Get report request */
// Send an empty report. The host should only be reading reports via the interrupt pipe.
memset(&g_device_composite->hid_generic.hid_packet.report, 0,
sizeof(g_device_composite->hid_generic.hid_packet.report));
param = (uint8_t *)&g_device_composite->hid_generic.hid_packet.report.header; // point to the report to send
// size is set to 0 above
break;
case kUSB_DeviceHidEventSetReport:
// Check for data phase abort packet.
header = (bl_hid_header_t *)param;
if ((header->packetLengthLsb == 0) && (header->packetLengthMsb == 0) &&
(header->reportID == kBootloaderReportID_CommandOut))
{
g_device_composite->hid_generic.hid_packet.didReceiveDataPhaseAbort = true;
break;
}
// Copy the report data into our local buffer.
memcpy(&g_device_composite->hid_generic.hid_packet.report.header, param, hid_report_param->reportLength);
// Save the report size.
g_device_composite->hid_generic.hid_packet.reportSize = hid_report_param->reportLength;
// Remember that we received a report.
g_device_composite->hid_generic.hid_packet.didReceiveFirstReport = true;
// Wake up the read packet handler.
sync_signal(&g_device_composite->hid_generic.hid_packet.receiveSync);
break;
case kUSB_DeviceHidEventRequestReportBuffer:
error = kStatus_USB_InvalidRequest;
break;
case kUSB_DeviceHidEventGetIdle:
case kUSB_DeviceHidEventGetProtocol:
case kUSB_DeviceHidEventSetIdle:
sync_init(&g_device_composite->hid_generic.hid_packet.receiveSync, false);
sync_init(&g_device_composite->hid_generic.hid_packet.sendSync, false);
break;
case kUSB_DeviceHidEventSetProtocol:
break;
}
return error;
}
/*!
* @brief HID device set configuration function.
*
* This function sets configuration for HID class.
*
* @param handle The HID class handle.
* @param configure The HID class configure index.
*
* @return A USB error code or kStatus_USB_Success.
*/
usb_status_t usb_device_hid_generic_set_configure(class_handle_t handle, uint8_t configure)
{
usb_status_t error = kStatus_USB_Success;
if (USB_COMPOSITE_CONFIGURE_INDEX == configure)
{
g_device_composite->hid_generic.attach = 1;
/* Set device configuration request */
error = USB_DeviceHidRecv(g_device_composite->hid_generic.hid_handle, USB_HID_GENERIC_ENDPOINT_OUT,
(uint8_t *)&g_device_composite->hid_generic.hid_packet.report.header,
sizeof(g_device_composite->hid_generic.hid_packet.report));
g_device_composite->hid_generic.current_configuration = configure;
}
return error;
}
usb_status_t usb_device_hid_generic_set_interface(class_handle_t handle, uint8_t interface, uint8_t alternate_setting)
{
usb_status_t error = kStatus_USB_Success;
if (interface < USB_HID_GENERIC_INTERFACE_COUNT)
{
g_device_composite->hid_generic.current_interface_alternate_setting[interface] = alternate_setting;
error = USB_DeviceHidRecv(g_device_composite->hid_generic.hid_handle, USB_HID_GENERIC_ENDPOINT_OUT,
(uint8_t *)&g_device_composite->hid_generic.hid_packet.report.header,
sizeof(g_device_composite->hid_generic.hid_packet.report));
}
return error;
}
usb_status_t usb_device_hid_generic_init(usb_device_composite_struct_t *device_composite)
{
g_device_composite = device_composite;
return kStatus_USB_Success;
}
usb_status_t usb_device_hid_generic_deinit(usb_device_composite_struct_t *device_composite)
{
g_device_composite = device_composite;
g_device_composite->hid_generic.hid_handle = (class_handle_t)NULL;
return kStatus_USB_Success;
}
#endif // BL_CONFIG_USB_HID

View File

@@ -0,0 +1,45 @@
#ifndef __USB_HID_MOUSE_H__
#define __USB_HID_MOUSE_H__ 1
#include "utilities/fsl_rtos_abstraction.h"
#include "bootloader_hid_report_ids.h"
#define USB_DEVICE_INTERRUPT_PRIORITY (4)
//! @brief Request parameters.
enum
{
kAppRequestParam_IdleRate = 0,
kAppRequestParam_Protocol,
kAppRequestParamCount
};
//! @brief State information for the USB HID packetizer.
typedef struct _usb_hid_packetizer_info
{
bool didReceiveFirstReport; //!< Whether the first report has been received.
bool didReceiveDataPhaseAbort; //!< Whether we received a data phase abort request.
bool isReceiveDataRequestRequired; //!< Whether an interrupt out pipe receive data request is required.
uint8_t appRequestParams[kAppRequestParamCount]; //!< Storage for request parameter values.
sync_object_t receiveSync; //!< Sync object used for reading packets.
sync_object_t sendSync; //!< Sync object used for sending packets.
uint32_t reportSize; //!< The size in bytes of a received report. May be greater than the packet contained within
//! the report plus the header, as the host can send up to the max report size bytes.
bl_hid_report_t report; //!< Buffer used to hold HID reports for sending and receiving.
} usb_hid_packetizer_info_t;
typedef struct _usb_hid_generic_struct
{
usb_device_handle device_handle;
class_handle_t hid_handle;
// uint32_t buffer[2][USB_HID_GENERIC_IN_BUFFER_LENGTH>>2];
// uint8_t buffer_index;
usb_hid_packetizer_info_t hid_packet;
uint8_t idle_rate;
uint8_t speed;
uint8_t attach;
uint8_t current_configuration;
uint8_t current_interface_alternate_setting[USB_HID_GENERIC_INTERFACE_COUNT];
} usb_hid_generic_struct_t;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,208 @@
#ifndef __USB_DESCRIPTOR_H__
#define __USB_DESCRIPTOR_H__ 1
#include "bootloader_common.h"
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
#include "usb_device_class.h"
#include "usb_device_hid.h"
#include "usb_descriptor.h"
#define USB_BCD_VERSION (0x0200)
/*******************************************************************************
* For generic HID
*******************************************************************************/
/* usb descritpor length */
#define USB_DEVICE_DESCRIPTOR_LENGTH (18)
#if (USB_DEVICE_CONFIG_HID == 0) && (USB_DEVICE_CONFIG_MSC == 1)
#define USB_CONFIGURE_DESCRIPTOR_LENGTH (32) // 64, HID_only = 41, MSC_ONLY = 32
#elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 0)
#define USB_CONFIGURE_DESCRIPTOR_LENGTH (41) // 64, HID_only = 41, MSC_ONLY = 32
#elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
#define USB_CONFIGURE_DESCRIPTOR_LENGTH (64) // 64, HID_only = 41, MSC_ONLY = 32
#else
#define USB_CONFIGURE_DESCRIPTOR_LENGTH (41) // 64, HID_only = 41, MSC_ONLY = 32
#endif
#define USB_HID_REPORT_DESC_SIZE (76)
#define USB_HID_GENERIC_DESCRIPTOR_LENGTH (32)
#define USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH (9)
#define USB_INTERFACE_DESCRIPTOR_LENGTH (9)
#define USB_HID_DESCRIPTOR_LENGTH (9)
#define USB_ENDPOINT_DESCRIPTOR_LENGTH (7)
#define USB_MSC_DISK_REPORT_DESCRIPTOR_LENGTH (63)
#define USB_IAD_DESC_SIZE (8)
#define USB_CONFIGURE_COUNT (1)
#define USB_STRING_COUNT (4)
#define USB_LANGUAGE_COUNT (1)
#if (USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
// HID + MSC composite device
#define USB_HID_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
#define USB_MSC_CONFIG_INDEX \
(USB_HID_CONFIG_INDEX + 2 * USB_ENDPOINT_DESCRIPTOR_LENGTH + USB_INTERFACE_DESCRIPTOR_LENGTH + \
USB_HID_DESCRIPTOR_LENGTH)
#elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 0)
// HID-Only device
#define USB_HID_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
#define USB_MSC_CONFIG_INDEX (0)
#elif(USB_DEVICE_CONFIG_HID == 0) && (USB_DEVICE_CONFIG_MSC == 1)
// MSC-only device
#define USB_HID_CONFIG_INDEX (0)
#define USB_MSC_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
#else
// No USB
#define USB_HID_CONFIG_INDEX (USB_CONFIGURE_ONLY_DESCRIPTOR_LENGTH)
#define USB_MSC_CONFIG_INDEX \
(USB_HID_CONFIG_INDEX + 2 * USB_ENDPOINT_DESCRIPTOR_LENGTH + USB_INTERFACE_DESCRIPTOR_LENGTH + \
USB_HID_DESCRIPTOR_LENGTH)
#endif
#define HS_BULK_IN_PACKET_SIZE (512)
#define HS_BULK_OUT_PACKET_SIZE (512)
#define FS_BULK_IN_PACKET_SIZE (64)
#define FS_BULK_OUT_PACKET_SIZE (64)
// MSC
#define USB_MSC_CLASS (0x08)
/* scsi command set */
#define USB_MSC_SUBCLASS (0x06)
/* bulk only transport protocol */
#define USB_MSC_PROTOCOL (0x50)
#define USB_MSC_CONFIGURE_INDEX (1)
#define USB_MSC_ENDPOINT_COUNT (2)
#define USB_MSC_BULK_IN_ENDPOINT (3)
#define USB_MSC_BULK_OUT_ENDPOINT (4)
#define USB_MSC_INTERFACE_COUNT (1)
#if (USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
#define USB_HID_GENERIC_INTERFACE_INDEX (0)
#define USB_MSC_INTERFACE_INDEX (1)
#else
#define USB_HID_GENERIC_INTERFACE_INDEX (0)
#define USB_MSC_INTERFACE_INDEX (0)
#endif
// HID
#define USB_HID_GENERIC_CONFIGURE_INDEX (1)
#define USB_HID_GENERIC_INTERFACE_COUNT (1)
#define USB_HID_GENERIC_IN_BUFFER_LENGTH (8)
#define USB_HID_GENERIC_OUT_BUFFER_LENGTH (8)
#define USB_HID_GENERIC_ENDPOINT_COUNT (2)
#define USB_HID_GENERIC_ENDPOINT_IN (1)
#define USB_HID_GENERIC_ENDPOINT_OUT (2)
#define USB_HID_GENERIC_CLASS (0x03)
#define USB_HID_GENERIC_SUBCLASS (0x00)
#define USB_HID_GENERIC_PROTOCOL (0x00)
#define HS_HID_GENERIC_INTERRUPT_OUT_PACKET_SIZE (64)
#define FS_HID_GENERIC_INTERRUPT_OUT_PACKET_SIZE (64)
#define HS_HID_GENERIC_INTERRUPT_OUT_INTERVAL (0x04) /* 2^(4-1) = 1ms */
#define FS_HID_GENERIC_INTERRUPT_OUT_INTERVAL (0x01)
#define HS_HID_GENERIC_INTERRUPT_IN_PACKET_SIZE (64)
#define FS_HID_GENERIC_INTERRUPT_IN_PACKET_SIZE (64)
#define HS_HID_GENERIC_INTERRUPT_IN_INTERVAL (0x04) /* 2^(4-1) = 1ms */
#define FS_HID_GENERIC_INTERRUPT_IN_INTERVAL (0x01)
#if (USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 1)
#define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_GENERIC_INTERFACE_COUNT + USB_MSC_INTERFACE_COUNT)
#elif(USB_DEVICE_CONFIG_HID == 1) && (USB_DEVICE_CONFIG_MSC == 0)
#define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_GENERIC_INTERFACE_COUNT)
#elif(USB_DEVICE_CONFIG_HID == 0) && (USB_DEVICE_CONFIG_MSC == 1)
#define USB_COMPOSITE_INTERFACE_COUNT (USB_MSC_INTERFACE_COUNT)
#else
#define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_GENERIC_INTERFACE_COUNT)
#endif
#define USB_COMPOSITE_CONFIGURE_INDEX (1)
#define USB_STRING_DESCRIPTOR_HEADER_LENGTH (0x02)
#define USB_STRING_DESCRIPTOR_0_LENGTH (0x02)
#define USB_STRING_DESCRIPTOR_1_LENGTH (56)
#define USB_STRING_DESCRIPTOR_2_LENGTH (40)
#if ((USB_DEVICE_CONFIG_MSC > 0U) && (USB_DEVICE_CONFIG_HID > 0U)) // MSC + HID
#define USB_STRING_DESCRIPTOR_3_LENGTH (60)
#elif((USB_DEVICE_CONFIG_MSC == 0U) && (USB_DEVICE_CONFIG_HID > 0U)) // Only HID
#define USB_STRING_DESCRIPTOR_3_LENGTH (44)
#elif((USB_DEVICE_CONFIG_MSC > 0U) && (USB_DEVICE_CONFIG_HID == 0U)) // Only MSC
#define USB_STRING_DESCRIPTOR_3_LENGTH (28)
#else
#define USB_STRING_DESCRIPTOR_3_LENGTH (2)
#endif
#define USB_STRING_DESCRIPTOR_ERROR_LENGTH (32)
#define USB_CONFIGURE_DRAWN (0x32)
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
enum _usb_descriptor_index
{
kUsbDescriptorIndex_VidLow = 8,
kUsbDescriptorIndex_VidHigh = 9,
kUsbDescriptorIndex_PidLow = 10,
kUsbDescriptorIndex_PidHigh = 11
};
typedef struct _usb_hid_config_descriptor
{
usb_descriptor_interface_t interface; /* Interface descriptor */
usb_descriptor_interface_t hid_report; /* Interface descriptor */
usb_descriptor_endpoint_t endpoint_in; /* Endpoint descriptor */
usb_descriptor_endpoint_t endpoint_out; /* Endpoint descriptor */
} usb_hid_config_descriptor_t;
typedef struct _usb_msc_config_descriptor
{
usb_descriptor_interface_t interface; /* Interface descriptor */
usb_descriptor_endpoint_t endpoint_in; /* Endpoint descriptor */
usb_descriptor_endpoint_t endpoint_out; /* Endpoint descriptor */
} usb_msc_config_descriptor_t;
extern usb_device_class_struct_t g_hid_generic_class;
extern usb_device_class_struct_t g_msc_class;
/* Configure the device according to the USB speed. */
extern usb_status_t usb_device_set_speed(usb_device_handle handle, uint8_t speed);
/* Get device descriptor request */
usb_status_t usb_device_get_device_descriptor(usb_device_handle handle,
usb_device_get_device_descriptor_struct_t *device_descriptor);
/* Get device configuration descriptor request */
usb_status_t usb_device_get_configuration_descriptor(
usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configuration_descriptor);
/* Get device string descriptor request */
usb_status_t usb_device_get_string_descriptor(usb_device_handle handle,
usb_device_get_string_descriptor_struct_t *string_descriptor);
/* Get hid descriptor request */
usb_status_t usb_device_get_hid_descriptor(usb_device_handle handle,
usb_device_get_hid_descriptor_struct_t *hid_descriptor);
/* Get hid report descriptor request */
usb_status_t usb_device_get_hid_report_descriptor(usb_device_handle handle,
usb_device_get_hid_report_descriptor_struct_t *hid_report_descriptor);
/* Get hid physical descriptor request */
usb_status_t usb_device_get_hid_physical_descriptor(
usb_device_handle handle, usb_device_get_hid_physical_descriptor_struct_t *hid_physical_descriptor);
extern uint8_t g_device_descriptor[];
extern usb_language_list_t g_language_list;
extern usb_language_list_t *g_language_ptr;
#endif /* __USB_DESCRIPTOR_H__ */

View File

@@ -0,0 +1,119 @@
#if !defined(__CONTEXT_H__)
#define __CONTEXT_H__
#include "bootloader_common.h"
#include "bootloader/bl_peripheral.h"
#include "memory/memory.h"
#include "packet/command_packet.h"
//#include "bootloader/bl_command.h"
#include "property/property.h"
#include "command.h"
#if !defined(BOOTLOADER_HOST)
#include "flash/fsl_flash.h"
#if BL_FEATURE_ENCRYPTION
#include "security/aes_security.h"
#endif // #if BL_FEATURE_ENCRYPTION
#endif // #if !defined(BOOTLOADER_HOST)
//! @addtogroup context
//! @{
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
#if !defined(BOOTLOADER_HOST)
//! @brief Interface for the flash driver.
typedef struct FlashDriverInterface
{
standard_version_t version; //!< flash driver API version number.
status_t (*flash_init)(flash_config_t *config);
status_t (*flash_erase_all)(flash_config_t *config, uint32_t key);
status_t (*flash_erase_all_unsecure)(flash_config_t *config, uint32_t key);
status_t (*flash_erase)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
status_t (*flash_program)(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes);
status_t (*flash_get_security_state)(flash_config_t *config, flash_security_state_t *state);
status_t (*flash_security_bypass)(flash_config_t *config, const uint8_t *backdoorKey);
status_t (*flash_verify_erase_all)(flash_config_t *config, flash_margin_value_t margin);
status_t (*flash_verify_erase)(flash_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
flash_margin_value_t margin);
status_t (*flash_verify_program)(flash_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
const uint32_t *expectedData,
flash_margin_value_t margin,
uint32_t *failedAddress,
uint32_t *failedData);
status_t (*flash_get_property)(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
status_t (*flash_register_callback)(flash_config_t *config, flash_callback_t callback);
status_t (*flash_program_once)(flash_config_t *config, uint32_t index, uint32_t *src, uint32_t lengthInBytes);
status_t (*flash_read_once)(flash_config_t *config, uint32_t index, uint32_t *dst, uint32_t lengthInBytes);
status_t (*flash_read_resource)(flash_config_t *config,
uint32_t start,
uint32_t *dst,
uint32_t lengthInBytes,
flash_read_resource_option_t option);
status_t (*flash_prepare_execute_in_ram_functions)(flash_config_t *config);
status_t (*flash_is_execute_only)(flash_config_t *config,
uint32_t start,
uint32_t lengthInBytes,
flash_execute_only_access_state_t *access_state);
status_t (*flash_erase_all_execute_only_segments)(flash_config_t *config, uint32_t key);
status_t (*flash_verify_erase_all_execute_only_segments)(flash_config_t *config, flash_margin_value_t margin);
status_t (*flash_set_flexram_function)(flash_config_t *config, flash_flexram_function_option_t option);
status_t (*flash_program_section)(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes);
} flash_driver_interface_t;
//! @brief Interface for AES 128 functions
typedef struct AesDriverInterface
{
void (*aes_init)(uint32_t *key);
void (*aes_encrypt)(uint32_t *in, uint32_t *key, uint32_t *out);
void (*aes_decrypt)(uint32_t *in, uint32_t *key, uint32_t *out);
} aes_driver_interface_t;
#else // #if !defined(BOOTLOADER_HOST)
// Provide stub definitions for flash driver types for the host.
typedef uint32_t flash_driver_interface_t;
typedef uint32_t flash_config_t;
typedef uint32_t aes_driver_interface_t;
#endif // #if !defined(BOOTLOADER_HOST)
//! @brief Structure of bootloader global context.
typedef struct _bootloaderContext
{
//! @name API tree
//@{
const memory_interface_t *memoryInterface; //!< Abstract interface to memory operations.
const memory_map_entry_t *memoryMap; //!< Memory map used by abstract memory interface.
const property_interface_t *propertyInterface; //!< Interface to property store.
const command_interface_t *commandInterface; //!< Interface to command processor operations.
const flash_driver_interface_t *flashDriverInterface; //!< Flash driver interface.
const peripheral_descriptor_t *allPeripherals; //!< Array of all peripherals.
const aes_driver_interface_t *aesInterface; //!< Interface to the AES driver
//@}
//! @name Runtime state
//@{
const peripheral_descriptor_t *activePeripheral; //!< The currently active peripheral.
flash_config_t flashState; //!< Flash driver instance.
//@}
} bootloader_context_t;
////////////////////////////////////////////////////////////////////////////////
// Externs
////////////////////////////////////////////////////////////////////////////////
extern bootloader_context_t g_bootloaderContext;
extern const flash_driver_interface_t g_flashDriverInterface;
extern const aes_driver_interface_t g_aesInterface;
//! @}
#endif // __CONTEXT_H__

View File

@@ -0,0 +1,126 @@
#ifndef _peripheral_h
#define _peripheral_h
#include <stdint.h>
#include "bootloader_common.h"
//! @addtogroup peripheral
//! @{
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
//! @brief Peripheral type bit mask definitions.
//!
//! These bit mask constants serve multiple purposes. They are each a unique value that identifies
//! a peripheral type. They are also the mask for the bits used in the bootloader configuration
//! flash region to list available peripherals and control which peripherals are enabled.
enum _peripheral_types
{
kPeripheralType_UART = (1 << 0),
kPeripheralType_I2CSlave = (1 << 1),
kPeripheralType_SPISlave = (1 << 2),
kPeripheralType_CAN = (1 << 3),
kPeripheralType_USB_HID = (1 << 4),
kPeripheralType_USB_CDC = (1 << 5),
kPeripheralType_USB_DFU = (1 << 6),
kPeripheralType_USB_MSC = (1 << 7)
};
//! @brief Pinmux types.
typedef enum _pinmux_types
{
kPinmuxType_Default = 0,
kPinmuxType_GPIO = 1,
kPinmuxType_Peripheral = 2
} pinmux_type_t;
// Forward declaration.
typedef struct PeripheralDescriptor peripheral_descriptor_t;
typedef void (*serial_byte_receive_func_t)(uint8_t);
//! @brief Peripheral control interface.
typedef struct _peripheral_control_interface
{
bool (*pollForActivity)(const peripheral_descriptor_t *self);
status_t (*init)(const peripheral_descriptor_t *self, serial_byte_receive_func_t function);
void (*shutdown)(const peripheral_descriptor_t *self);
void (*pump)(const peripheral_descriptor_t *self);
} peripheral_control_interface_t;
//! @brief Peripheral abstract byte interface.
typedef struct _peripheral_byte_inteface
{
status_t (*init)(const peripheral_descriptor_t *self);
#ifdef BOOTLOADER_HOST
status_t (*read)(const peripheral_descriptor_t *self, uint8_t *buffer, uint32_t requestedBytes);
#endif // #ifdef BOOTLOADER_HOST
status_t (*write)(const peripheral_descriptor_t *self, const uint8_t *buffer, uint32_t byteCount);
} peripheral_byte_inteface_t;
//! @brief Packet types.
typedef enum _packet_type
{
kPacketType_Command, //!< Send or expect a command packet
kPacketType_Data //!< Send or expect a data packet
} packet_type_t;
//! @brief Peripheral Packet Interface.
typedef struct _peripheral_packet_interface
{
status_t (*init)(const peripheral_descriptor_t *self);
status_t (*readPacket)(const peripheral_descriptor_t *self,
uint8_t **packet,
uint32_t *packetLength,
packet_type_t packetType);
status_t (*writePacket)(const peripheral_descriptor_t *self,
const uint8_t *packet,
uint32_t byteCount,
packet_type_t packetType);
void (*abortDataPhase)(const peripheral_descriptor_t *self);
status_t (*finalize)(const peripheral_descriptor_t *self);
uint32_t (*getMaxPacketSize)(const peripheral_descriptor_t *self);
void (*byteReceivedCallback)(uint8_t byte);
} peripheral_packet_interface_t;
//! @brief Peripheral descriptor.
//!
//! Instances of this struct describe a particular instance of a peripheral that is
//! available for bootloading.
struct PeripheralDescriptor
{
//! @brief Bit mask identifying the peripheral type.
//!
//! See #_peripheral_types for a list of valid bits.
uint32_t typeMask;
//! @brief The instance number of the peripheral.
uint32_t instance;
//! @brief Configure pinmux setting for the peripheral.
void (*pinmuxConfig)(uint32_t instance, pinmux_type_t pinmux);
//! @brief Control interface for the peripheral.
const peripheral_control_interface_t *controlInterface;
//! @brief Byte-level interface for the peripheral.
//!
//! May be NULL since not all periperhals support this interface.
const peripheral_byte_inteface_t *byteInterface;
//! @brief Packet level interface for the peripheral.
const peripheral_packet_interface_t *packetInterface;
};
////////////////////////////////////////////////////////////////////////////////
// Externs
////////////////////////////////////////////////////////////////////////////////
//! @brief Array of all peripherals available in this device.
extern const peripheral_descriptor_t g_peripherals[];
//! @}
#endif // _peripheral_h

View File

@@ -0,0 +1,70 @@
#if !defined(__BOOTLOADER_H__)
#define __BOOTLOADER_H__
#include "bootloader_common.h"
#include "bootloader/bl_peripheral.h"
//#include "bootloader/bl_command.h"
#include "bootloader/bl_context.h"
//#include "bootloader/bl_version.h"
//#include "bootloader/bl_user_entry.h"
//#include "bootloader/bl_peripheral_interface.h"
//#include "bootloader/bl_shutdown_cleanup.h"
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief Bootloader status codes.
//! @ingroup bl_core
enum _bootloader_status
{
kStatus_UnknownCommand = MAKE_STATUS(kStatusGroup_Bootloader, 0),
kStatus_SecurityViolation = MAKE_STATUS(kStatusGroup_Bootloader, 1),
kStatus_AbortDataPhase = MAKE_STATUS(kStatusGroup_Bootloader, 2),
kStatus_Ping = MAKE_STATUS(kStatusGroup_Bootloader, 3),
kStatus_NoResponse = MAKE_STATUS(kStatusGroup_Bootloader, 4),
kStatus_NoResponseExpected = MAKE_STATUS(kStatusGroup_Bootloader, 5)
};
//! @brief Root of the bootloader API tree.
//!
//! An instance of this struct resides in read-only memory in the bootloader. It
//! provides a user application access to APIs exported by the bootloader.
//!
//! @note The order of existing fields must not be changed.
//!
//! @ingroup context
#if 1 // Moved into each SOC based header file in future !!!!!!!!!!!!!
typedef struct BootloaderTree
{
void (*runBootloader)(void *arg); //!< Function to start the bootloader executing.
standard_version_t version; //!< Bootloader version number.
const char *copyright; //!< Copyright string.
const bootloader_context_t *runtimeContext; //!< Pointer to the bootloader's runtime context.
const flash_driver_interface_t *flashDriver; //!< Flash driver API.
const aes_driver_interface_t *aesDriver; //!< AES driver API.
} bootloader_tree_t;
#endif
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @brief Verify that a given address is ok to jump to.
*
* @param applicationAddress The entry point address to validate.
* @return Boolean indicating whether the address is valid.
*
* @ingroup bl_core
*/
bool is_valid_application_location(uint32_t applicationAddress);
#if defined(__cplusplus)
}
#endif
#endif // __BOOTLOADER_H__

View File

@@ -0,0 +1,278 @@
#ifndef __BOOTLOADER_COMMON_H__
#define __BOOTLOADER_COMMON_H__
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#if !defined(WIN32)
#include <stdbool.h>
#endif
#include "bootloader_common.h"
#include "fsl_common.h"
#if defined(BOOTLOADER_HOST)
//#include "blfwk/bootloader_config.h"
#elif defined(BUSPAL)
#include "../src/buspal_config.h"
#else
#include "bootloader_config.h"
#include "target_config.h"
#endif
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
#ifndef NULL
#define NULL 0
#endif
// The following macros are to be used when trying to save code size for specific peripheral configurations
// that will only be using one peripheral instance. most of the peripheral driver code can use multiple instances but by
// just using one
// we can save space
#define USE_ONLY_UART(instance) (defined(BL_FEATURE_UART_OPTIMIZE) && (BL_UART_USED_INSTANCE == instance))
#define USE_ONLY_SPI(instance) (defined(BL_FEATURE_SPI_OPTIMIZE) && (BL_SPI_USED_INSTANCE == instance))
#define USE_ONLY_I2C(instance) (defined(BL_FEATURE_I2C_OPTIMIZE) && (BL_I2C_USED_INSTANCE == instance))
//! @name Min/max macros
//@{
#if !defined(MIN)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#if !defined(MAX)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
//@}
//! @brief Computes the number of elements in an array.
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
//! @name Byte swap macros
//@{
#define BSWAP_16(x) (uint16_t)((((x)&0xFF00) >> 0x8) | (((x)&0xFF) << 0x8))
#define BSWAP_32(val) \
(uint32_t)((BSWAP_16((uint32_t)(val) & (uint32_t)0xFFFF) << 0x10) | (BSWAP_16((uint32_t)((val) >> 0x10))))
//@}
//! @name Alignment macros
//@{
#ifndef ALIGN_DOWN
#define ALIGN_DOWN(x, a) ((x) & -(a))
#endif
#ifndef ALIGN_UP
#define ALIGN_UP(x, a) (-(-(x) & -(a)))
#endif
//@}
//! @brief Build a 32-bit code from four character values.
//!
//! The resulting value is built with a byte order such that the string
//! being readable in expected order when viewed in a hex editor, if the value
//! is treated as a 32-bit little endian value.
#define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a)))
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(DEBUG_PRINT_DISABLE)
static inline void debug_printf(const char *format, ...);
//! @brief Debug print utility.
//!
//! This print function will only output text when the @a DEBUG macro is defined.
static inline void debug_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
vprintf(format, args);
// Temporarily disable MISRA rule 14.2
#if defined(__ICCARM__)
#pragma diag_suppress = Pm049
#endif
va_end(args);
#if defined(__ICCARM__)
#pragma diag_default = Pm049
#endif
}
#else // (DEBUG || _DEBUG) && !DEBUG_PRINT_DISABLE
// Empty macro to cause debug_printf() calls to disappear.
#define debug_printf(x, ...) \
do \
{ \
} while (false)
#endif // (DEBUG || _DEBUG) && !DEBUG_PRINT_DISABLE
//! @brief Callback function invoked for a pin change interrupt.
//!
//! @ingroup bl_hw
typedef void (*pin_irq_callback_t)(uint32_t instance);
//! @brief Bootloader status group numbers.
//!
//! @ingroup bl_core
enum _bl_status_groups
{
kStatusGroup_Bootloader = kStatusGroup_ApplicationRangeStart, //!< Bootloader status group number (100).
kStatusGroup_SBLoader, //!< SB loader status group number (101).
kStatusGroup_MemoryInterface, //!< Memory interface status group number (102).
kStatusGroup_PropertyStore, //!< Property store status group number (103).
kStatusGroup_AppCrcCheck, //!< Application crc check status group number (104).
kStatusGroup_Packetizer, //!< Packetizer status group number (105).
kStatusGroup_ReliableUpdate //!< Reliable Update status groupt number (106).
};
//! @brief Driver status group numbers.
//!
//! @ingroup bl_core
enum _bl_driver_status_groups
{
kStatusGroup_QuadSPIDriver = 4, //!< QSPI driver status group number.
kStatusGroup_OTFADDriver = 5, //!< OTFAD driver status group number.
};
#if defined(__CC_ARM)
#pragma anon_unions
#endif
//! @brief Structure of version property.
//!
//! @ingroup bl_core
typedef union StandardVersion
{
struct
{
uint8_t bugfix; //!< bugfix version [7:0]
uint8_t minor; //!< minor version [15:8]
uint8_t major; //!< major version [23:16]
char name; //!< name [31:24]
};
uint32_t version; //!< combined version numbers
#if defined(__cplusplus)
StandardVersion()
: version(0)
{
}
StandardVersion(uint32_t version)
: version(version)
{
}
#endif
} standard_version_t;
// #define MAKE_VERSION(bugfix, minor, major, name) (((name) << 24) | ((major) << 16) | ((minor) << 8 ) | (bugfix))
//! @brief External memory identifiers.
//!
//! @ingroup bl_core
enum _external_mem_identifiers
{
kExternalMemId_QuadSPI0 = 1,
};
//! @brief Bootloader clock option
typedef enum _bootloader_clock_option
{
kClockOption_EnterBootloader = 0, //!< Clock option for entering bootloader
kClockOption_ExitBootloader = 1, //!< Clock option for exiting bootloader
} bootloader_clock_option_t;
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
//! @addtogroup bl_hw
//! @{
//! @brief Initialize the hardware such as pinmux.
void init_hardware(void);
//! @brief DeInitialize the hardware such as disabling port clock gate
void deinit_hardware(void);
//! @brief Update available peripherals based on specific chips
void update_available_peripherals(void);
//! @brief Returns the logic level of the board specific GPIO pin used for autobaud.
// uint32_t read_autobaud_pin(uint32_t instance);
//! @brief Configure hardware clocks.
void configure_clocks(bootloader_clock_option_t option);
//! @brief Returns the available lirc clock frequency in Hertz.
uint32_t get_available_lirc_clock(void);
//! @brief Returns the current bus clock frequency in Hertz.
uint32_t get_bus_clock(void);
//! @brief Returns the current core clock frequency in Hertz.
uint32_t get_system_core_clock(void);
//! @brief Configure usb clock
bool usb_clock_init(void);
//! @brief Returns the value in MHz of the UART clock based on the instance.
uint32_t get_uart_clock(uint32_t instance);
//! @brief Returns true if reset BOOTROM mode is selected.
bool is_boot_pin_asserted(void);
//! @brief Enables the autobaud pin IRQ for the specific instance passed.
void enable_autobaud_pin_irq(uint32_t instance, pin_irq_callback_t func);
//! @brief Disables the autobaud pin IRQ for the instance passed.
void disable_autobaud_pin_irq(uint32_t instance);
//! @brief Declaration for the reset handler, which is defined in assembler.
void Reset_Handler(void);
//! @brief Initialize watchdog
void bootloader_watchdog_init(void);
//! @brief Service watchdog
void bootloader_watchdog_service(void);
//! @brief De-initialize watchdog
void bootloader_watchdog_deinit(void);
//! @brief Determine if QSPI module to be configured.
bool qspi_need_configure(void);
//! @brief Initialize QSPI and OTFAD module.
//! @param none
status_t otfad_init_as_needed(void);
//! @brief Bypass OTFAD module as needed.
//! @param none
status_t otfad_bypass_as_needed(void);
//! @brief Resume OTFAD module as needed.
//! @param none
status_t oftfad_resume_as_needed(void);
//! @brief Determine if QSPI memory is present or not.
bool is_qspi_present(void);
//! @brief Determine if OTFAD module is present or not.
bool is_otfad_present(void);
//! @brief Determine if LTC module is present or not.
bool is_ltc_present(void);
//! @brief Return status for intializing qspi and otfad modules
status_t get_qspi_otfad_init_status(void);
//!@bief Update status for intializing qspi and otfad modules
void update_qspi_otfad_init_status(status_t initStatus);
//!@brief Determine is the Secondary I2C slave address is enabled.
bool is_secondary_i2c_slave_address_enabled(void);
//!@brief Check if data to be accessed is in execute-only region.
bool is_in_execute_only_region(uint32_t start, uint32_t lengthInBytes);
//!@brief Check if second core is present.
bool is_second_core_present(void);
//! @}
#endif // __BOOTLOADER_COMMON_H__

View File

@@ -0,0 +1,103 @@
#ifndef __BOOTLOADER_CONFIG_H__
#define __BOOTLOADER_CONFIG_H__
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//
// Bootloader configuration options
//
//! @name Peripheral configuration macros
//@{
#if !defined(BL_CONFIG_SCUART)
#define BL_CONFIG_SCUART (0)
#endif
#if !defined(BL_CONFIG_I2C)
#define BL_CONFIG_I2C (1)
#endif
#if !defined(BL_CONFIG_DSPI)
#define BL_CONFIG_DSPI (0)
#endif
#if !defined(BL_CONFIG_USB_HID)
#define BL_CONFIG_USB_HID (1)
#endif
#if !defined(BL_CONFIG_USB_MSC)
#define BL_CONFIG_USB_MSC (0)
#endif
//@}
#if !defined(BL_TARGET_FLASH) && !defined(BL_TARGET_RAM)
#define BL_TARGET_FLASH (0)
#endif
#if defined(BL_TARGET_RAM)
#define BL_FEATURE_FLASH_SECURITY (0)
#else
#define BL_FEATURE_FLASH_SECURITY (1)
#endif
#define BL_FEATURE_QSPI_MODULE (0)
#define BL_FEATURE_ENCRYPTION (0)
// 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
#if !defined(BL_TARGET_RAM)
#define BL_FEATURE_CRC_CHECK (1)
#endif
#define BL_FEATURE_UART_AUTOBAUD_IRQ (1)
// 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__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
#if !defined(__BUS_PAL_HARDWARE_H__)
#define __BUS_PAL_HARDWARE_H__
#include "fsl_dspi.h"
#include "fsl_i2c.h"
#include "bl_peripheral.h"
uint32_t get_bus_clock(void);
/*!
* @brief user config from host for i2c
*/
typedef struct _i2c_user_config
{
uint8_t slaveAddress;
uint16_t baudRate_kbps;
} i2c_user_config_t;
/*!
* @brief user config from host for spi
*/
typedef struct _dspi_user_config
{
dspi_clock_polarity_t polarity; /*!< Clock polarity */
dspi_clock_phase_t phase; /*!< Clock phase */
dspi_shift_direction_t direction; /*!< MSB or LSB */
uint32_t baudRate_Bps; /*!< Baud Rate for SPI in Hz */
uint32_t clock_Hz;
} dspi_user_config_t;
/*!
* @brief hardware initialization
*/
void init_hardware(void);
//! @brief sending host bytes command process
void write_bytes_to_host(uint8_t *src, uint32_t length);
//! @brief receiving host start command process
void host_start_command_rx(uint8_t *dest, uint32_t length);
//! @brief receiving host stop command process
void host_stop_command_rx(void);
//! @brief receiving host get bytes command process
uint32_t get_bytes_received_from_host(void);
//! @brief i2c config address process
void configure_i2c_address(uint8_t address);
//! @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 GPIO config processing
void configure_gpio(uint8_t port, uint8_t pinNum, uint8_t muxVal);
//! @brief GPIO set up function
void set_gpio(uint8_t port, uint8_t pinNum, uint8_t level);
//! @brief fpga clock set function
void set_fpga_clock(uint32_t clock);
bool usb_hid_poll_for_activity(const peripheral_descriptor_t *self);
status_t usb_hid_packet_init(const peripheral_descriptor_t *self);
status_t usb_hid_packet_read(const peripheral_descriptor_t *self,
uint8_t **packet,
uint32_t *packetLength,
packet_type_t packetType);
status_t usb_hid_packet_write(const peripheral_descriptor_t *self,
const uint8_t *packet,
uint32_t byteCount,
packet_type_t packetType);
#endif // __BUS_PAL_HARDWARE_H__

644
right/src/buspal/command.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
#ifndef _command_h
#define _command_h
#include "packet/serial_packet.h"
#include "packet/command_packet.h"
//! @addtogroup command
//! @{
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief Command state machine states.
enum _command_state
{
kCommandState_CommandPhase,
kCommandState_DataPhase,
kCommandState_DataPhaseRead,
kCommandState_DataPhaseWrite
};
typedef enum _buspal_state
{
kBuspal_Idle,
kBuspal_I2c,
} buspal_state_t;
typedef struct ConfigI2cCmdPacket
{
command_packet_t commandPacket; //!< header
uint32_t address; //!< Parameter 0: i2c slave address.
uint32_t speed; //!< Parameter 1: i2c speed in kHz
} config_i2c_cmd_packet_t;
//! @brief Format of command handler entry.
typedef struct CommandHandlerEntry
{
void (*handleCommand)(uint8_t *packet, uint32_t packetLength);
status_t (*handleData)(bool *hasMoreData);
} command_handler_entry_t;
//! @brief Command processor data format.
typedef struct CommandProcessorData
{
int32_t state; //!< Current state machine state
uint8_t *packet; //!< Pointer to packet in process
uint32_t packetLength; //!< Length of packet in process
struct DataPhase
{
uint8_t *data; //!< Data for data phase
uint32_t count; //!< Remaining count to produce/consume
uint32_t address; //!< Address for data phase
uint32_t dataBytesAvailable; //!< Number of bytes available at data pointer
uint8_t commandTag; //!< Tag of command running data phase
uint8_t option; //!< option for special command
} dataPhase;
const command_handler_entry_t *handlerEntry; //! Pointer to handler table entry for packet in process
} command_processor_data_t;
//! @brief Interface to command processor operations.
typedef struct CommandInterface
{
status_t (*init)(void);
status_t (*pump)(void);
const command_handler_entry_t *handlerTable;
command_processor_data_t *stateData;
} command_interface_t;
////////////////////////////////////////////////////////////////////////////////
// Externals
////////////////////////////////////////////////////////////////////////////////
//! @brief Default command interface.
extern command_interface_t g_commandInterface;
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
//! @brief Initialize the command processor component.
status_t bootloader_command_init(void);
//! @brief Pump the command state machine.
//!
//! Executes one command or data phase transaction.
status_t bootloader_command_pump(void);
#if defined(__cplusplus)
}
#endif // __cplusplus
//! @}
#endif // _command.h_

View File

@@ -0,0 +1,56 @@
#ifndef _CRC16_H_
#define _CRC16_H_
#include <stdint.h>
//! @addtogroup crc16
//! @{
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief State information for the CRC16 algorithm.
typedef struct Crc16Data
{
uint16_t currentCrc; //!< Current CRC value.
} crc16_data_t;
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#if __cplusplus
extern "C" {
#endif
//! @name CRC16
//@{
//! @brief Initializes the parameters of the crc function, must be called first.
//!
//! @param crc16Config Instantiation of the data structure of type crc16_data_t.
void crc16_init(crc16_data_t *crc16Config);
//! @brief A "running" crc calculator that updates the crc value after each call.
//!
//! @param crc16Config Instantiation of the data structure of type crc16_data_t.
//! @param src Pointer to the source buffer of data.
//! @param lengthInBytes The length, given in bytes (not words or long-words).
void crc16_update(crc16_data_t *crc16Config, const uint8_t *src, uint32_t lengthInBytes);
//! @brief Calculates the final crc value, padding with zeros if necessary, must be called last.
//!
//! @param crc16Config Instantiation of the data structure of type crc16_data_t.
//! @param hash Pointer to the value returned for the final calculated crc value.
void crc16_finalize(crc16_data_t *crc16Config, uint16_t *hash);
//@}
#if __cplusplus
}
#endif
//! @}
#endif

View File

@@ -0,0 +1,61 @@
#ifndef _CRC_H_
#define _CRC_H_
#include <stdint.h>
#include "bootloader_common.h"
//! @addtogroup crc32
//! @{
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief State information for the CRC32 algorithm.
typedef struct Crc32Data
{
uint32_t currentCrc; //!< Current CRC value.
uint32_t byteCountCrc; //!< Number of bytes processed.
} crc32_data_t;
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#if __cplusplus
extern "C" {
#endif
//! @name CRC32
//@{
//! @brief Initializes the parameters of the crc function, must be called first
//!
//! @param crc32Config Instantiation of the data structure of type crc32_data_t
//! @retval kStatus_Success
void crc32_init(crc32_data_t *crc32Config);
//! @brief A "running" crc calculator that updates the crc value after each call
//!
//! @param crc32Config Instantiation of the data structure of type crc32_data_t
//! @param src Pointer to the source buffer of data
//! @param lengthInBytes The length, given in bytes (not words or long-words)
//! @retval kStatus_Success
void crc32_update(crc32_data_t *crc32Config, const uint8_t *src, uint32_t lengthInBytes);
//! @brief Calculates the final crc value, padding with zeros if necessary, must be called last
//!
//! @param crc32Config Instantiation of the data structure of type crc32_data_t
//! @param hash Pointer to the value returned for the final calculated crc value
//! @retval kStatus_Success
void crc32_finalize(crc32_data_t *crc32Config, uint32_t *hash);
//@}
#if __cplusplus
}
#endif
//! @}
#endif

View File

@@ -0,0 +1,112 @@
#include "bootloader_common.h"
#include "crc/crc16.h"
//#include "utilities/fsl_assert.h"
//#include "utilities/fsl_rtos_abstraction.h"
#if !defined(BOOTLOADER_HOST)
#include "fsl_device_registers.h"
#include "utilities/fsl_rtos_abstraction.h"
#endif // !BOOTLOADER_HOST
#if !defined(BOOTLOADER_HOST) && FSL_FEATURE_SOC_CRC_COUNT && !defined(BL_TARGET_RAM)
#include "fsl_crc.h"
/* Table of base addresses for crc instances. */
static CRC_Type *const g_crcBase[1] = CRC_BASE_PTRS;
void crc16_init(crc16_data_t *crc16Config)
{
assert(crc16Config);
crc16Config->currentCrc = 0x0000U;
}
void crc16_update(crc16_data_t *crc16Config, const uint8_t *src, uint32_t lengthInBytes)
{
assert(crc16Config);
assert(src);
crc_config_t crcUserConfigPtr;
CRC_GetDefaultConfig(&crcUserConfigPtr);
crcUserConfigPtr.crcBits = kCrcBits16;
crcUserConfigPtr.seed = crc16Config->currentCrc;
crcUserConfigPtr.polynomial = 0x1021U;
crcUserConfigPtr.complementChecksum = false;
crcUserConfigPtr.reflectIn = false;
crcUserConfigPtr.reflectOut = false;
// Init CRC module and then run it
//! Note: We must init CRC module here, As we may seperate one crc calculation into several times
//! Note: It is better to use lock to ensure the integrity of current updating operation of crc calculation
// in case crc module is shared by multiple crc updating requests at the same time
if (lengthInBytes)
{
lock_acquire();
CRC_Init(g_crcBase[0], &crcUserConfigPtr);
CRC_WriteData(g_crcBase[0], src, lengthInBytes);
crcUserConfigPtr.seed = CRC_Get16bitResult(g_crcBase[0]);
lock_release();
}
crc16Config->currentCrc = crcUserConfigPtr.seed;
}
void crc16_finalize(crc16_data_t *crc16Config, uint16_t *hash)
{
assert(crc16Config);
assert(hash);
*hash = crc16Config->currentCrc;
// De-init CRC module when we complete a full crc calculation
CRC_Deinit(g_crcBase[0]);
}
#else
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////
void crc16_init(crc16_data_t *crc16Config)
{
assert(crc16Config);
// initialize running crc and byte count
crc16Config->currentCrc = 0;
}
void crc16_update(crc16_data_t *crc16Config, const uint8_t *src, uint32_t lengthInBytes)
{
assert(crc16Config);
assert(src);
uint32_t crc = crc16Config->currentCrc;
uint32_t j;
for (j = 0; j < lengthInBytes; ++j)
{
uint32_t i;
uint32_t byte = src[j];
crc ^= byte << 8;
for (i = 0; i < 8; ++i)
{
uint32_t temp = crc << 1;
if (crc & 0x8000)
{
temp ^= 0x1021;
}
crc = temp;
}
}
crc16Config->currentCrc = crc;
}
void crc16_finalize(crc16_data_t *crc16Config, uint16_t *hash)
{
assert(crc16Config);
assert(hash);
*hash = crc16Config->currentCrc;
}
#endif

View File

@@ -0,0 +1,167 @@
#include "bootloader_common.h"
#include "crc/crc32.h"
//#include "utilities/fsl_assert.h"
#if !defined(BOOTLOADER_HOST)
#include "fsl_device_registers.h"
#include "utilities/fsl_rtos_abstraction.h"
#endif // !BOOTLOADER_HOST
#if !defined(BOOTLOADER_HOST) && FSL_FEATURE_SOC_CRC_COUNT && !defined(BL_TARGET_RAM)
#include "fsl_crc.h"
/* Table of base addresses for crc instances. */
static CRC_Type *const g_crcBase[1] = CRC_BASE_PTRS;
// initialize the members of the allocated crc32_data_t struct
void crc32_init(crc32_data_t *crc32Config)
{
assert(crc32Config);
crc32Config->currentCrc = 0xffffffffU;
crc32Config->byteCountCrc = 0;
}
// "running" crc32 calculation
void crc32_update(crc32_data_t *crc32Config, const uint8_t *src, uint32_t lengthInBytes)
{
assert(crc32Config);
assert(src);
crc_config_t crcUserConfigPtr;
CRC_GetDefaultConfig(&crcUserConfigPtr);
crcUserConfigPtr.crcBits = kCrcBits32;
crcUserConfigPtr.seed = crc32Config->currentCrc;
crcUserConfigPtr.polynomial = 0x04c11db7U;
crcUserConfigPtr.complementChecksum = false;
crcUserConfigPtr.reflectIn = false;
crcUserConfigPtr.reflectOut = false;
// Init CRC module and then run it
//! Note: We must init CRC module here, As we may seperate one crc calculation into several times
//! Note: It is better to use lock to ensure the integrity of current updating operation of crc calculation
// in case crc module is shared by multiple crc updating requests at the same time
if (lengthInBytes)
{
lock_acquire();
CRC_Init(g_crcBase[0], &crcUserConfigPtr);
CRC_WriteData(g_crcBase[0], src, lengthInBytes);
crcUserConfigPtr.seed = CRC_Get32bitResult(g_crcBase[0]);
lock_release();
}
crc32Config->currentCrc = crcUserConfigPtr.seed;
crc32Config->byteCountCrc += lengthInBytes;
}
// finalize the crc32 calculation for non-word-aligned counts
void crc32_finalize(crc32_data_t *crc32Config, uint32_t *hash)
{
assert(crc32Config);
assert(hash);
uint32_t extraBytes = crc32Config->byteCountCrc % 4;
// pad with zeroes
if (extraBytes)
{
uint8_t temp[3] = { 0, 0, 0 };
crc32_update(crc32Config, temp, 4 - extraBytes);
}
*hash = crc32Config->currentCrc;
// De-init CRC module when we complete a full crc calculation
CRC_Deinit(g_crcBase[0]);
}
#else
////////////////////////////////////////////////////////////////////////////////
// Variables
////////////////////////////////////////////////////////////////////////////////
//! Table of CRC-32's of all single byte values. The values in
//! this table are those used in the Ethernet CRC algorithm.
static const uint32_t s_crc32Table[] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 0x2608edb8,
0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, 0x639b0da6,
0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84,
0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a,
0xec7dd02d, 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, 0xaca5c697, 0xa864db20, 0xa527fdf9,
0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b,
0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c,
0x774bb0eb, 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, 0x0315d626,
0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a,
0x8cf30bad, 0x81b02d74, 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093,
0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679,
0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, 0x8d79e0be, 0x803ac667,
0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////
// initialize the members of the allocated crc32_data_t struct
void crc32_init(crc32_data_t *crc32Config)
{
// initialize running crc and byte count
crc32Config->currentCrc = 0xFFFFFFFF;
crc32Config->byteCountCrc = 0;
}
// "running" crc32 calculation
void crc32_update(crc32_data_t *crc32Config, const uint8_t *src, uint32_t lengthInBytes)
{
assert(src);
uint32_t crc = crc32Config->currentCrc;
crc32Config->byteCountCrc += lengthInBytes;
while (lengthInBytes--)
{
uint8_t c = *src++ & 0xff;
crc = (crc << 8) ^ s_crc32Table[(crc >> 24) ^ c];
}
crc32Config->currentCrc = crc;
}
// finalize the crc32 calculation for non-word-aligned counts
void crc32_finalize(crc32_data_t *crc32Config, uint32_t *hash)
{
uint32_t crc = crc32Config->currentCrc;
uint32_t byteCount = crc32Config->byteCountCrc;
// pad with zeroes
if (byteCount % 4)
{
uint32_t i;
for (i = byteCount % 4; i < 4; i++)
{
crc = (crc << 8) ^ s_crc32Table[(crc >> 24) ^ 0];
}
}
crc32Config->currentCrc = crc;
*hash = crc32Config->currentCrc;
}
#endif

View File

@@ -0,0 +1,245 @@
#ifndef _memory_h
#define _memory_h
#include <stdint.h>
#include "bootloader_common.h"
//! @addtogroup memif
//! @{
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
//! @brief Memory interface status codes.
enum _memory_interface_status
{
kStatusMemoryRangeInvalid = MAKE_STATUS(kStatusGroup_MemoryInterface, 0),
kStatusMemoryReadFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 1),
kStatusMemoryWriteFailed = MAKE_STATUS(kStatusGroup_MemoryInterface, 2),
kStatusMemoryCumulativeWrite = MAKE_STATUS(kStatusGroup_MemoryInterface, 3),
kStatusMemoryAppOverlapWithExecuteOnlyRegion = MAKE_STATUS(kStatusGroup_MemoryInterface, 4)
};
// !@brief Executable enum codes
enum
{
kMemoryNotExecutable = false, //!< The memory doesn't support executing in place.
kMemoryIsExecutable = true, //!< The memory supports executing in place.
};
//! @brief Interface to memory operations.
//!
//! This is the main abstract interface to all memory operations.
typedef struct _memory_interface
{
status_t (*init)(void);
status_t (*read)(uint32_t address, uint32_t length, uint8_t *buffer);
status_t (*write)(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t (*fill)(uint32_t address, uint32_t length, uint32_t pattern);
status_t (*flush)(void);
status_t (*erase)(uint32_t address, uint32_t length);
} memory_interface_t;
//! @brief Interface to memory operations for one region of memory.
typedef struct _memory_region_interface
{
status_t (*init)(void);
status_t (*read)(uint32_t address, uint32_t length, uint8_t *buffer);
status_t (*write)(uint32_t address, uint32_t length, const uint8_t *buffer);
status_t (*fill)(uint32_t address, uint32_t length, uint32_t pattern);
status_t (*flush)(void);
status_t (*erase)(uint32_t address, uint32_t length);
} memory_region_interface_t;
//! @brief Structure of a memory map entry.
typedef struct _memory_map_entry
{
uint32_t startAddress;
uint32_t endAddress;
bool isExecutable;
const memory_region_interface_t *memoryInterface;
} memory_map_entry_t;
//! @brief Memory Map index constants
enum _memorymap_constants
{
kIndexFlashArray = 0,
kIndexSRAM = 1,
#if CPU_IS_ARM_CORTEX_M7
kIndexDTCM = 2,
kIndexOCRAM = 3,
#endif // CPU_IS_ARM_CORTEX_M7
#if BL_FEATURE_QSPI_MODULE
kIndexQspiMemory = 2,
kIndexQspiAliasArea = 3,
#endif // BL_FEATURE_QSPI_MODULE
kSRAMSeparatrix = (uint32_t)0x20000000 //!< This value is the start address of SRAM_U
};
//! @brief flash memory erase all options.
typedef enum _flash_erase_all_option
{
kFlashEraseAllOption_Blocks = 0,
kFlashEraseAllOption_ExecuteOnlySegments = 1
} flash_erase_all_option_t;
////////////////////////////////////////////////////////////////////////////////
// Externs
////////////////////////////////////////////////////////////////////////////////
//! @brief Memory map for the system.
extern memory_map_entry_t g_memoryMap[];
//! @name Memory interfaces
//@{
//! @brief Abstract memory interface.
//!
//! This interface utilizes the memory map to perform different memory operations
//! depending on the region of memory being accessed.
extern const memory_interface_t g_memoryInterface;
//! @brief Flash memory interface.
extern const memory_region_interface_t g_flashMemoryInterface;
//! @brief Memory interface for memory with Normal type.
//!
//! Use of multiword loads and stores is allowed with this memory type.
extern const memory_region_interface_t g_normalMemoryInterface;
#if CPU_IS_ARM_CORTEX_M7
//! @brief Memory interface for memory with Normal type.
//!
//! Use of multiword loads and stores is allowed with this memory type.
extern const memory_region_interface_t g_normalDTCMInterface;
//! @brief Memory interface for memory with Normal type.
//!
//! Use of multiword loads and stores is allowed with this memory type.
extern const memory_region_interface_t g_normalOCRAMInterface;
#endif
//! @brief Memory interface for memory with Device or Strongly-ordered type.
//!
//! This memory type does not support multiword loads and stores.
extern const memory_region_interface_t g_deviceMemoryInterface;
#if defined BL_FEATURE_QSPI_MODULE
extern const memory_region_interface_t g_qspiMemoryInterface;
#if BL_FEATURE_QSPI_ALIAS_AREA
extern const memory_region_interface_t g_qspiAliasAreaInterface;
#endif // BL_FEATURE_QSPI_ALIAS_AREA
#endif // BL_FEATURE_QSPI_MODULE
//@}
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
//! @name Generic memory interface implementation
//@{
//! @brief Initialize memory interface.
status_t mem_init(void);
//! @brief Read memory.
status_t mem_read(uint32_t address, uint32_t length, uint8_t *buffer);
//! @brief Write memory.
status_t mem_write(uint32_t address, uint32_t length, const uint8_t *buffer);
//! @brief Fill memory with a word pattern.
status_t mem_fill(uint32_t address, uint32_t length, uint32_t pattern);
//! @brief Erase memory:
status_t mem_erase(uint32_t address, uint32_t length);
//! @brief Flush meory:
status_t mem_flush(void);
//! @brief Find a map entry that matches address and length.
status_t find_map_entry(uint32_t address, uint32_t length, const memory_map_entry_t **map);
//!@brief Check is the specified memory region is erased.
bool mem_is_erased(uint32_t address, uint32_t length);
//@}
//! @name Memory utilities
//@{
//! @brief Determine if all or part of block is in a reserved region.
bool mem_is_block_reserved(uint32_t address, uint32_t length);
//@}
//! @name Flash erase operations
//@{
//! @brief Erase Flash memory.
status_t flash_mem_erase(uint32_t address, uint32_t length);
#if BL_FEATURE_FAC_ERASE
//! @brief Erase all Flash memory or all Flash execute-only segments.
//!
//! It is only valid for non-flash resident bootloader when option is erasing execute-only segments.
status_t flash_mem_erase_all(flash_erase_all_option_t eraseOption);
#else
//! @brief Erase all Flash memory.
//!
//! If building for flash resident bootloader, we have to decompose the the flash erase all
//! operation into two region erases. This allows the user to still do an erase all, but not
//! wipe out the bootloader itself.
status_t flash_mem_erase_all(void);
#endif
//! @brief Erase all Flash memory (unsecure).
status_t flash_mem_erase_all_unsecure(void);
//@}
//! @name QSPI erase operation
//@{
//! @brief Erase all QSPI memory
status_t qspi_mem_erase_all(void);
//@}
#if defined(__cplusplus)
}
#endif // __cplusplus
#if defined(BOOTLOADER_HOST)
////////////////////////////////////////////////////////////////////////////////
// Simulator host prototypes
////////////////////////////////////////////////////////////////////////////////
#if __cplusplus
extern "C" {
#endif
//! @brief Erase all flash.
void host_flash_erase_all(void);
//! @brief Erase all flash (unsecure).
void host_flash_erase_all_unsecure(void);
//! @brief Erase a region of flash.
void host_flash_erase_region(uint32_t address, uint32_t count);
#if __cplusplus
}
#endif
#endif // BOOTLOADER_HOST
//! @}
#endif // _memory_h

View File

@@ -0,0 +1,50 @@
/*
* @file microseconds.h
* @brief Microseconds timer driver based on PIT(Periodic Interrupt Timer)
*
* Notes:
*/
#ifndef ___MICROSECONDS_H__
#define ___MICROSECONDS_H__
#include <stdio.h>
#include "fsl_device_registers.h"
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
/********************************************************************/
//! @brief Initialize timer facilities.
void microseconds_init(void);
//! @brief Shutdown the microsecond timer
void microseconds_shutdown(void);
//! @brief Read back the running tick count
uint64_t microseconds_get_ticks(void);
//! @brief Returns the conversion of ticks to actual microseconds
//! This is used to seperate any calculations from getting a tick
// value for speed critical scenarios
uint32_t microseconds_convert_to_microseconds(uint32_t ticks);
//! @brief Returns the conversion of microseconds to ticks
uint64_t microseconds_convert_to_ticks(uint32_t microseconds);
//! @brief Delay specified time
void microseconds_delay(uint32_t us);
//! @brief Gets the clock value used for microseconds driver
uint32_t microseconds_get_clock(void);
#if defined(__cplusplus)
}
#endif // __cplusplus
#endif /* ___MICROSECONDS_H__ */

View File

@@ -0,0 +1,145 @@
/*
* @file microseconds.c
* @brief Microseconds timer driver source file
*
* Notes: The driver configure PIT as lifetime timer
*/
#include "microseconds/microseconds.h"
#include <stdarg.h>
//#include "bootloader_common.h"
#include "bus_pal_hardware.h"
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
// Below MACROs are defined in order to keep this driver compabtile among all targets.
#if defined(PIT0)
#define PIT PIT0
#endif
#if defined(SIM_SCGC6_PIT0_MASK)
#define SIM_SCGC6_PIT_MASK SIM_SCGC6_PIT0_MASK
#endif
enum
{
kFrequency_1MHz = 1000000UL
};
////////////////////////////////////////////////////////////////////////////////
// Variables
////////////////////////////////////////////////////////////////////////////////
uint32_t s_tickPerMicrosecondMul8; //!< This value equal to 8 times ticks per microseconds
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////
//! @brief Initialize timer facilities.
//!
//! It is initialize the timer to lifetime timer by chained channel 0
//! and channel 1 together, and set b0th channels to maximum counting period
void microseconds_init(void)
{
uint32_t busClock;
// PIT clock gate control ON
SIM->SCGC6 |= SIM_SCGC6_PIT_MASK;
// Turn on PIT: MDIS = 0, FRZ = 0
PIT->MCR = 0x00;
// Set up timer 1 to max value
PIT->CHANNEL[1].LDVAL = 0xFFFFFFFF; // setup timer 1 for maximum counting period
PIT->CHANNEL[1].TCTRL = 0; // Disable timer 1 interrupts
PIT->CHANNEL[1].TFLG = 1; // clear the timer 1 flag
PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_CHN_MASK; // chain timer 1 to timer 0
PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK; // start timer 1
// Set up timer 0 to max value
PIT->CHANNEL[0].LDVAL = 0xFFFFFFFF; // setup timer 0 for maximum counting period
PIT->CHANNEL[0].TFLG = 1; // clear the timer 0 flag
PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TEN_MASK; // start timer 0
/* Calculate this value early
* The reason why use this solution is that lowest clock frequency supported by L0PB and L4KS
* is 0.25MHz, this solution will make sure ticks per microscond is greater than 0.
*/
busClock = get_bus_clock();
s_tickPerMicrosecondMul8 = (busClock * 8) / kFrequency_1MHz;
// Make sure this value is greater than 0
if (!s_tickPerMicrosecondMul8)
{
s_tickPerMicrosecondMul8 = 1;
}
}
//! @brief Shutdown the microsecond timer
void microseconds_shutdown(void)
{
// Turn off PIT: MDIS = 1, FRZ = 0
PIT->MCR |= PIT_MCR_MDIS_MASK;
}
//! @brief Read back running tick count
uint64_t microseconds_get_ticks(void)
{
uint64_t valueH;
uint32_t valueL;
#if defined(FSL_FEATURE_PIT_HAS_LIFETIME_TIMER) && (FSL_FEATURE_PIT_HAS_LIFETIME_TIMER == 1)
valueH = PIT->LTMR64H;
valueL = PIT->LTMR64L;
#else
// Make sure that there are no rollover of valueL.
// Because the valueL always decreases, so, if the formal valueL is greater than
// current value, that means the valueH is updated during read valueL.
// In this case, we need to re-update valueH and valueL.
do
{
valueH = PIT->CHANNEL[1].CVAL;
valueL = PIT->CHANNEL[0].CVAL;
} while (valueL < PIT->CHANNEL[0].CVAL);
#endif // FSL_FEATURE_PIT_HAS_LIFETIME_TIMER
// Invert to turn into an up counter
return ~((valueH << 32) | valueL);
}
//! @brief Returns the conversion of ticks to actual microseconds
//! This is used to seperate any calculations from getting a timer
// value for speed critical scenarios
uint32_t microseconds_convert_to_microseconds(uint32_t ticks)
{
// return the total ticks divided by the number of Mhz the system clock is at to give microseconds
return (8 * ticks / s_tickPerMicrosecondMul8); //!< Assumes system clock will never be < 0.125 Mhz
}
//! @brief Returns the conversion of microseconds to ticks
uint64_t microseconds_convert_to_ticks(uint32_t microseconds)
{
return ((uint64_t)microseconds * s_tickPerMicrosecondMul8 / 8);
}
//! @brief Delay specified time
//!
//! @param us Delay time in microseconds unit
void microseconds_delay(uint32_t us)
{
uint64_t currentTicks = microseconds_get_ticks();
//! The clock value in Mhz = ticks/microsecond
uint64_t ticksNeeded = ((uint64_t)us * s_tickPerMicrosecondMul8 / 8) + currentTicks;
while (microseconds_get_ticks() < ticksNeeded)
{
;
}
}
//! @brief Gets the clock value used for microseconds driver
uint32_t microseconds_get_clock(void)
{
return get_bus_clock();
}

View File

@@ -0,0 +1,132 @@
/*
* @file microseconds_sysclk.c
* @brief Microseconds sysclk timer driver source file
*
* Notes: The driver configure sysclk as lifetime timer
*/
//#include "bootloader_common.h"
#include "microseconds/microseconds.h"
#include "fsl_device_registers.h"
#include <stdarg.h>
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
enum
{
kFrequency_1MHz = 1000000UL
};
////////////////////////////////////////////////////////////////////////////////
// Variables
////////////////////////////////////////////////////////////////////////////////
//! @brief Tracks number of timer rollovers for extended time keeping
//! with 32 bits here + the 24 bits of the counter for lower resolution
//! it will be years worth of time
volatile uint32_t s_highCounter;
uint32_t s_tickPerMicrosecondMul8; //!< This value equal to 8 times ticks per microseconds
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////
//! @brief Initialize and start the timer facilities using the SysTick.
void microseconds_init(void)
{
s_highCounter = 0;
SysTick->LOAD = SysTick_LOAD_RELOAD_Msk; // Set reload register to max value
SysTick->VAL = 0; // As per ARM reference initialization, set initial value to 0
// interrupts are only triggered when going from 1 to 0
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | // Set timer to core clock frequency
SysTick_CTRL_TICKINT_Msk | // Enable interrupts on timeout
SysTick_CTRL_ENABLE_Msk; // Enable SysTick IRQ and SysTick Timer
/* Calculate this value early
* The reason why use this solution is that lowest clock frequency supported by L0PB and L4KS
* is 0.25MHz, this solution will make sure ticks per microscond is greater than 0.
*/
s_tickPerMicrosecondMul8 = (SystemCoreClock * 8) / kFrequency_1MHz;
// Make sure this value is greater than 0
if (!s_tickPerMicrosecondMul8)
{
s_tickPerMicrosecondMul8 = 1;
}
}
//! @brief Shutdown the microsecond timer
void microseconds_shutdown(void)
{
// Disable the timer and interrupts from it
SysTick->CTRL = SysTick->CTRL & ~(SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk);
// Clear the current value register
SysTick->VAL = 0;
}
//! @brief Read back the running tick count
uint64_t microseconds_get_ticks(void)
{
uint64_t retVal;
//! The rollover counter keeps track of increments higher than the 24 bit SysTick counter
//! to combine them shift rollover up 24 bits and add the current ticks
uint32_t high;
uint32_t low;
// Check for an overflow condition between the two reads above
do
{
high = s_highCounter;
low = ~SysTick->VAL & SysTick_LOAD_RELOAD_Msk;
} while (high != s_highCounter);
retVal = ((uint64_t)high << 24) + low;
return retVal;
}
//! @brief Returns the conversion of ticks to actual microseconds
//! This is used to seperate any calculations from getting a timer
// value for timing sensitive scenarios
uint32_t microseconds_convert_to_microseconds(uint32_t ticks)
{
// return the total ticks divided by the number of Mhz the system clock is at to give microseconds
return (8 * ticks / s_tickPerMicrosecondMul8); //!< Assumes system clock will never be < 0.125 Mhz
}
//! @brief Returns the conversion of microseconds to ticks
uint64_t microseconds_convert_to_ticks(uint32_t microseconds)
{
return ((uint64_t)microseconds * s_tickPerMicrosecondMul8 / 8);
}
//! @brief Delay specified time
//!
//! @param us Delay time in microseconds unit
void microseconds_delay(uint32_t us)
{
uint64_t currentTicks = microseconds_get_ticks();
//! The clock value in Mhz = ticks/microsecond
uint64_t ticksNeeded = ((uint64_t)us * s_tickPerMicrosecondMul8 / 8) + currentTicks;
while (microseconds_get_ticks() < ticksNeeded)
{
;
}
}
//! @brief Gets the clock value used for microseconds driver
uint32_t microseconds_get_clock(void)
{
return SystemCoreClock;
}
//! @brief Interrupt handler for the SysTick timer, this will just increment
// the rollover counter for extended time keeping
void SysTick_Handler(void)
{
s_highCounter++;
}

View File

@@ -0,0 +1,298 @@
#if !defined(__COMMAND_PACKET_H__)
#define __COMMAND_PACKET_H__
//#include "bootloader_common.h"
#include "stdint.h"
//! @addtogroup packet
//! @{
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
//! @brief Command/Data Packet constants.
enum _command_packet_constants
{
kMinPacketBufferSize = 32,
kDefaultMaxPacketSize = kMinPacketBufferSize,
kMaxPropertyReturnValues =
(kMinPacketBufferSize / sizeof(uint32_t)) - 2, //!< Max number of words a property can return
//! One word is header, one parameter reserved for status
kMaxProgramOnceValues =
(kMinPacketBufferSize / sizeof(uint32_t)) - 3, //!< Max number of words a program once command can write
//! One word is header, two parameters reserved for index and byteCount
kCommandTagCount = 12 //!< Number of non-response command tags
};
//! @brief Commands codes.
enum _command_tags
{
kCommandTag_GenericResponse = 0xa0,
kCommandTag_FlashEraseAll = 0x01,
kCommandTag_FlashEraseRegion = 0x02,
kCommandTag_ReadMemory = 0x03,
kCommandTag_ReadMemoryResponse = 0xa3,
kCommandTag_WriteMemory = 0x04,
kCommandTag_FillMemory = 0x05,
kCommandTag_FlashSecurityDisable = 0x06,
kCommandTag_GetProperty = 0x07,
kCommandTag_GetPropertyResponse = 0xa7,
kCommandTag_ReceiveSbFile = 0x08,
kCommandTag_Execute = 0x09,
kCommandTag_Call = 0x0a,
kCommandTag_Reset = 0x0b,
kCommandTag_SetProperty = 0x0c,
kCommandTag_FlashEraseAllUnsecure = 0x0d,
kCommandTag_FlashProgramOnce = 0x0e,
kCommandTag_FlashReadOnce = 0x0f,
kCommandTag_FlashReadOnceResponse = 0xaf,
kCommandTag_FlashReadResource = 0x10,
kCommandTag_FlashReadResourceResponse = 0xb0,
kCommandTag_ConfigureQuadSpi = 0x11,
kCommandTag_ReliableUpdate = 0x12,
kCommandTag_ConfigureI2c = 0xc1, //! Reserved command tag for Bus Pal
kCommandTag_ConfigureSpi = 0xc2, //! Reserved command tag for Bus Pal
kCommandTag_ConfigureCan = 0xc3, //! Reserved command tag for Bus Pal
kFirstCommandTag = kCommandTag_FlashEraseAll,
//! Maximum linearly incrementing command tag value, excluding the response commands and bus pal commands.
kLastCommandTag = kCommandTag_ReliableUpdate,
kResponseCommandHighNibbleMask =
0xa0 //!< Mask for the high nibble of a command tag that identifies it as a response command.
};
//! @brief Command packet flags.
enum _command_packet_flags
{
kCommandFlag_None = 0,
kCommandFlag_HasDataPhase = 1
};
//! @brief Flash memory identifiers.
enum _flash_mem_id
{
kFlashMemInternal = 0,
kFlashMemQuadSpi0 = 1,
kFlashMemExecuteOnly = 0x10
};
//! @brief Command packet format.
typedef struct CommandPacket
{
uint8_t commandTag; //!< A command tag.
uint8_t flags; //!< Combination of packet flags.
uint8_t reserved; //!< Reserved, helpful for alignment, set to zero.
uint8_t parameterCount; //!< Number of parameters that follow in buffer.
} command_packet_t;
//! @name Command Packet formats
//@{
//! @brief FlashEraseAll packet format.
typedef struct FlashEraseAllPacket
{
command_packet_t commandPacket; //!< header
uint32_t memoryId; //!< Paremeter 0: Flash memory identifiers.
} flash_erase_all_packet_t;
//! @brief FlashEraseRegion packet format.
typedef struct FlashEraseRegionPacket
{
command_packet_t commandPacket; //!< header
uint32_t startAddress; //!< Paremeter 0: start address.
uint32_t byteCount; //!< Parameter 1: number of bytes.
} flash_erase_region_packet_t;
//! @brief GetProperty packet format.
typedef struct GetPropertyPacket
{
command_packet_t commandPacket; //!< header
uint32_t propertyTag; //!< Parameter 0: requested property tag.
uint32_t memoryId; //!< Parameter 1: requested property for certain external memory
} get_property_packet_t;
//! @brief SetProperty packet format.
typedef struct SetPropertyPacket
{
command_packet_t commandPacket; //!< header
uint32_t propertyTag; //!< Paremeter 0: property tag.
uint32_t propertyValue; //!< Parameter 1: value to set.
} set_property_packet_t;
//! @brief ReceiveSbFile packet format.
typedef struct ReceiveSbFilePacket
{
command_packet_t commandPacket; //!< header
uint32_t byteCount; //!< Parameter 0: Number of bytes to receive.
} receive_sb_file_packet_t;
//! @brief WriteMemory packet format.
typedef struct WriteMemoryPacket
{
command_packet_t commandPacket; //!< header
uint32_t startAddress; //!< Paremeter 0: Start address of memory to write to.
uint32_t byteCount; //!< Parameter 1: Number of bytes to write.
} write_memory_packet_t;
//! @brief ReadMemory packet format.
typedef struct ReadMemoryPacket
{
command_packet_t commandPacket; //!< header
uint32_t startAddress; //!< Paremeter 0: Start address of memory to read from.
uint32_t byteCount; //!< Parameter 1: Number of bytes to read.
} read_memory_packet_t;
//! @brief FillMemory packet format.
typedef struct FillMemoryPacket
{
command_packet_t commandPacket; //!< header
uint32_t startAddress; //!< Paremeter 0: start address.
uint32_t byteCount; //!< Parameter 1: number of bytes.
uint32_t patternWord; //!< Parameter 1: pattern word.
} fill_memory_packet_t;
//! @brief Execute/Call command function pointer definition.
typedef status_t (*call_function_t)(uint32_t);
//! @brief Execute/Call packet format.
typedef struct ExecuteCallPacket
{
command_packet_t commandPacket; //!< header
uint32_t callAddress; //!< Paremeter 0: function address.
uint32_t argumentWord; //!< Parameter 1: argument.
uint32_t stackpointer; //!< Parameter 2: stack pointer
} execute_call_packet_t;
//! @brief FlashSecurityDisable packet format.
typedef struct FlashSecurityDisablePacket
{
command_packet_t commandPacket; //!< header
uint32_t keyLow; //!< Paremeter 0: key bytes 0-3.
uint32_t keyHigh; //!< Parameter 1: key bytes 4-7.
} flash_security_disable_packet_t;
//! @brief FlashProgramOnce packet format
typedef struct ProgramOncePacket
{
command_packet_t commandPacket; //!< header
uint32_t index; //!< Parameter 0: index of pragram once field
uint32_t byteCount; //!< Parameter 1: number of bytes
uint32_t data[kMaxProgramOnceValues]; //!< Parameter 2: data to be programmed
} flash_program_once_packet_t;
//! @brief FlashReadOnce packet format
typedef struct ReadOncePacket
{
command_packet_t commandPacket; //!< header
uint32_t index; //!< Parameter 0: index of pragram once field to be read
uint32_t byteCount; //!< Parameter 1: number of bytes
} flash_read_once_packet_t;
//! @brief FlashReadResource packet format
typedef struct FlashReadResourcePacket
{
command_packet_t commandPacket; //!< header
uint32_t startAddress; //!< Parameter 0: start address
uint32_t byteCount; //!< Parameter 1: number of bytes
uint32_t option; //!< Parameter 2: option for flash read resource command
} flash_read_resource_packet_t;
//! @brief ConfigureQuadSpi packet format
typedef struct ConfigureQuadSpiPacket
{
command_packet_t commandPacket; //!< header
uint32_t flashMemId; //!< Parameter 0: quadspi ID
uint32_t configBlockAddress; //!< Parameter 1: address of config block to use
} configure_quadspi_packet_t;
//! @brief ReliableUpdate packet format
typedef struct ReliableUpdatePacket
{
command_packet_t commandPacket; //!< header
uint32_t address; //!< Parameter 0: For software implementation , this is backup app start address;
//!< Parameter 0: For hardware implementation , this is swap indicator address;
} reliable_update_packet_t;
//! @brief ConfigureI2c packet format
typedef struct ConfigureI2cPacket
{
command_packet_t commandPacket; //!< header
uint32_t address; //!< Parameter 0: address
uint32_t speed; //!< Parameter 1: speed
} configure_i2c_packet_t;
//! @brief ConfigureSpi packet format
typedef struct ConfigureSpiPacket
{
command_packet_t commandPacket; //!< header
uint32_t speedKhz; //!< Parameter 0: spped Khz
uint32_t polarity; //!< Parameter 1: polarity
uint32_t phase; //!< Parameter 2: phase
uint32_t direction; //!< Parameter 3: directionpolarity
} configure_spi_packet_t;
//! @brief ConfigureCan packet format
typedef struct ConfigureCanPacket
{
command_packet_t commandPacket; //!< header
uint32_t speed; //!< Parameter 0: spped index
uint32_t txid; //!< Parameter 1: txid
uint32_t rxid; //!< Parameter 2: rxid
} configure_can_packet_t;
//@}
//! @name Response Packet formats
//@{
//! @brief Generic response packet format.
typedef struct GenericResponsePacket
{
command_packet_t commandPacket; //!< header
uint32_t status; //!< parameter 0
uint32_t commandTag; //!< parameter 1
} generic_response_packet_t;
//! @brief Get Property response packet format.
typedef struct GetPropertyResponsePacket
{
command_packet_t commandPacket; //!< header
uint32_t status; //!< parameter 0
uint32_t propertyValue[kMaxPropertyReturnValues]; //!< up to 6 other parameters
} get_property_response_packet_t;
//! @brief Read Memory response packet format.
typedef struct ReadMemoryResponsePacket
{
command_packet_t commandPacket; //!< header
uint32_t status; //!< parameter 0
uint32_t dataByteCount; //!< parameter 1
} read_memory_response_packet_t;
//! @brief Flash Read Once response packet format.
typedef struct FlashReadOnceResponsePacket
{
command_packet_t commandPacket; //!< header
uint32_t status; //!< parameter 0
uint32_t byteCount; //!< parameter 1
uint32_t data[kMaxProgramOnceValues]; //!< parameter 2
} flash_read_once_response_packet_t;
//! @brief Flash Read Resource response packet format.
typedef struct FlashReadResourceResponsePacket
{
command_packet_t commandPacket; //!< header
uint32_t status; //!< parameter 0
uint32_t dataByteCount; //!< parameter 1
} flash_read_resource_response_packet_t;
//@}
//! @}
#endif // __COMMAND_PACKET_H__

View File

@@ -0,0 +1,178 @@
#ifndef _packet_h
#define _packet_h
#include "bootloader_common.h"
#include "bootloader/bl_peripheral.h"
#include "command_packet.h"
//#include "property/property.h"
#include "stdbool.h"
//! @addtogroup packet
//! @{
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
//! @brief Version constants for serial framing protocol.
//! @note Recalculate crc16 in k_PingResponse if these values change.
enum _serial_protocol_version_constants
{
kSerialProtocol_Version_Name = 'P',
kSerialProtocol_Version_Major = 1,
kSerialProtocol_Version_Minor = 2,
kSerialProtocol_Version_Bugfix = 0
};
//! @brief Serial framing packet constants.
enum _framing_packet_constants
{
kFramingPacketStartByte = 0x5a,
kFramingPacketType_Ack = 0xa1,
kFramingPacketType_Nak = 0xa2,
kFramingPacketType_AckAbort = 0xa3,
kFramingPacketType_Command = 0xa4,
kFramingPacketType_Data = 0xa5,
kFramingPacketType_Ping = 0xa6,
kFramingPacketType_PingResponse = 0xa7
};
//! @brief Timeout and other constants.
enum _timing_constants
{
kHostMaxStartByteReadCount = 2,
kDefaultByteReadTimeoutMs = 10, //!< Default value for receiving 1 byte timeout
kCallbackBufferSize = 64 //!< Size for callback buffer, Must be power of 2 for easy wrap
};
//! @brief Incoming data buffer allocation size.
enum _serial_packet_constants
{
kIncomingPacketBufferSize = kMinPacketBufferSize,
kOutgoingPacketBufferSize = kMinPacketBufferSize
};
//! @brief Packet state machine modes.
enum _serial_packet_mode
{
kSerialModeCmd,
kSerialModeAck,
kSerialModeIdle
};
//! @brief Serial framing header.
typedef struct FramingHeader
{
uint8_t startByte; //!< #kFramingPacketStartByte
uint8_t packetType; //!< Framing packet type
} framing_header_t;
//! @brief Serial framing sync packet.
typedef struct FramingSyncPacket
{
framing_header_t header; //!< Framing packet header
} framing_sync_packet_t;
//! @brief Serial framing data packet.
#pragma pack(1)
typedef struct FramingDataPacket
{
framing_header_t header; //!< Framing packet header
uint16_t length; //!< Number of data bytes that follow
uint16_t crc16; //!< CRC-16 of data packet header and data
} framing_data_packet_t;
#pragma pack()
//! @brief Framing packet with data area.
typedef struct SerialFramingPacket
{
framing_data_packet_t dataPacket; //!< Packet header.
uint8_t data[kOutgoingPacketBufferSize]; //!< Payload.
} serial_framing_packet_t;
//! @brief Format of global context data.
typedef struct SerialData
{
uint8_t data[kIncomingPacketBufferSize]; //!< Buffer for incomming packet data payload, must be uint32_t aligned.
uint8_t callbackBuffer[kCallbackBufferSize]; //!< Buffer for incoming data from the byte callback
serial_framing_packet_t framingPacket; //!< Buffer for outgoing packet.
volatile uint32_t writeOffset; //!< The offset into the buffer that the ISR will queue data into
uint32_t readOffset; //!< The offset into the buffer that the app has read out
bool isAckNeeded; //!< True if need to send ACK to previously received packet
bool isBackToBackWrite; //!< True if executing back-to-back write
bool isAckAbortNeeded; //!< True if next ACK should be ACK Abort
} serial_data_t;
//! @brief Serial ping response format.
//!
//! This is the format of the response to a Ping packet.
typedef struct PingResponse
{
standard_version_t version; //!< Serial framing protocol version
uint16_t options; //!< Serial framing protocol options bitfield
uint16_t crc16; //!< CRC-16 of other fields
} ping_response_t;
////////////////////////////////////////////////////////////////////////////////
// Externs
////////////////////////////////////////////////////////////////////////////////
extern const peripheral_packet_interface_t g_framingPacketInterface;
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
//! @brief Initialize component.
status_t serial_packet_init(const peripheral_descriptor_t *self);
//! @brief Read packet using serial framing.
//!
//! On return, caller must call flow control method to send AckContinue or AckWait followed by Continue.
status_t serial_packet_read(const peripheral_descriptor_t *self,
uint8_t **packet,
uint32_t *packetLength,
packet_type_t packetType);
//! @brief Write packet using serial framing.
status_t serial_packet_write(const peripheral_descriptor_t *self,
const uint8_t *packet,
uint32_t byteCount,
packet_type_t packetType);
//! @brief Abort data phase.
//!
//! Respond to next host data packet with AckAbort instead of Ack
//! (i.e. receiver data phase abort).
void serial_packet_abort(const peripheral_descriptor_t *self);
//! @brief Finalize.
status_t serial_packet_finalize(const peripheral_descriptor_t *self);
//! @brief Get max packet size.
uint32_t serial_packet_get_max_packet_size(const peripheral_descriptor_t *self);
//! @brief Send a sync packet of the specified type.
status_t serial_packet_send_sync(uint8_t framingPacketType);
//! @brief Send a ping message back in response to a ping.
status_t serial_send_ping_response(const peripheral_descriptor_t *peripheral);
//! @brief Queues a byte received by the active peripheral
void serial_packet_queue_byte(uint8_t byte);
#if defined(BOOTLOADER_HOST)
void host_delay(uint32_t milliseconds);
#endif // BOOTLOADER_HOST
#if defined(__cplusplus)
}
#endif // __cplusplus
//! @}
#endif // _packet_h

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,362 @@
#ifndef _property_h
#define _property_h
#include <stdint.h>
#include "bootloader_common.h"
#include "packet/command_packet.h"
#if !defined(BOOTLOADER_HOST)
#include "fsl_device_registers.h"
#include "utilities/vector_table_info.h"
#endif
//! @addtogroup property
//! @{
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
//! @name Command Availability
//@{
//! Sets a bit in the available commands property value to indicate a command with
//! the given tag is available.
#define HAS_CMD(tag) (1 << ((tag)-kFirstCommandTag))
//! Checks whether a command with the specified tag is present in the provided command
//! availability mask.
#define IS_CMD_AVAILABLE(mask, tag) (((mask)&HAS_CMD(tag)) != 0)
enum _available_commands
{
kAvailableCommands = (
#if !BL_FEATURE_MIN_PROFILE
HAS_CMD(kCommandTag_FlashEraseAll) | HAS_CMD(kCommandTag_FlashEraseRegion) | HAS_CMD(kCommandTag_WriteMemory)
#if BL_FEATURE_FLASH_SECURITY
|
HAS_CMD(kCommandTag_FlashSecurityDisable)
#endif // BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_GetProperty) | HAS_CMD(kCommandTag_Execute) | HAS_CMD(kCommandTag_Reset) |
HAS_CMD(kCommandTag_SetProperty) | HAS_CMD(kCommandTag_ReadMemory) | HAS_CMD(kCommandTag_FillMemory) |
HAS_CMD(kCommandTag_ReceiveSbFile) | HAS_CMD(kCommandTag_Call)
#if BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_FlashEraseAllUnsecure)
#endif // BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_FlashReadOnce) | HAS_CMD(kCommandTag_FlashProgramOnce) |
HAS_CMD(kCommandTag_FlashReadResource)
#if BL_FEATURE_QSPI_MODULE
|
HAS_CMD(kCommandTag_ConfigureQuadSpi)
#endif // BL_FEATURE_QSPI_MODULE
#if BL_FEATURE_RELIABLE_UPDATE
|
HAS_CMD(kCommandTag_ReliableUpdate)
#endif // BL_FEATURE_RELIABLE_UPDATE
#else // BL_FEATURE_MIN_PROFILE
HAS_CMD(kCommandTag_FlashEraseAll) | HAS_CMD(kCommandTag_FlashEraseRegion) | HAS_CMD(kCommandTag_WriteMemory)
#if BL_FEATURE_FLASH_SECURITY
|
HAS_CMD(kCommandTag_FlashSecurityDisable)
#endif // BL_FEATURE_FLASH_SECURITY
|
HAS_CMD(kCommandTag_GetProperty) | HAS_CMD(kCommandTag_Execute) | HAS_CMD(kCommandTag_Reset) |
HAS_CMD(kCommandTag_SetProperty)
#if BL_FEATURE_READ_MEMORY
|
HAS_CMD(kCommandTag_ReadMemory)
#endif // BL_FEATURE_READ_MEMORY
#if BL_FEATURE_FILL_MEMORY
|
HAS_CMD(kCommandTag_FillMemory)
#endif // BL_FEATURE_FILL_MEMORY
#if BL_FEATURE_ERASEALL_UNSECURE
|
HAS_CMD(kCommandTag_FlashEraseAllUnsecure)
#endif // BL_FEATURE_ERASEALL_UNSECURE
#endif // BL_FEATURE_MIN_PROFILE
)
};
//@}
//! @brief Property store status codes.
enum _property_errors
{
kStatus_UnknownProperty = MAKE_STATUS(kStatusGroup_PropertyStore, 0),
kStatus_ReadOnlyProperty = MAKE_STATUS(kStatusGroup_PropertyStore, 1), //!< Property is read-only.
kStatus_InvalidPropertyValue = MAKE_STATUS(kStatusGroup_PropertyStore, 2) //!< Property value is out of range.
};
//! @brief Property tags.
//! @note Do not change any tag values. Add tags at the end.
enum _property_tag
{
kPropertyTag_ListProperties = 0x00,
kPropertyTag_BootloaderVersion = 0x01,
kPropertyTag_AvailablePeripherals = 0x02,
kPropertyTag_FlashStartAddress = 0x03,
kPropertyTag_FlashSizeInBytes = 0x04,
kPropertyTag_FlashSectorSize = 0x05,
kPropertyTag_FlashBlockCount = 0x06,
kPropertyTag_AvailableCommands = 0x07,
kPropertyTag_CrcCheckStatus = 0x08,
kPropertyTag_Reserved9 = 0x09,
kPropertyTag_VerifyWrites = 0x0a,
kPropertyTag_MaxPacketSize = 0x0b,
kPropertyTag_ReservedRegions = 0x0c,
kPropertyTag_Reserved13 = 0x0d,
kPropertyTag_RAMStartAddress = 0x0e,
kPropertyTag_RAMSizeInBytes = 0x0f,
kPropertyTag_SystemDeviceId = 0x10,
kPropertyTag_FlashSecurityState = 0x11,
kPropertyTag_UniqueDeviceId = 0x12,
kPropertyTag_FacSupport = 0x13,
kPropertyTag_FlashAccessSegmentSize = 0x14,
kPropertyTag_FlashAccessSegmentCount = 0x15,
kPropertyTag_FlashReadMargin = 0x16,
kPropertyTag_QspiInitStatus = 0x17,
kPropertyTag_TargetVersion = 0x18,
kPropertyTag_ExternalMemoryAttributes = 0x19,
kPropertyTag_ReliableUpdateStatus = 0x1a,
kPropertyTag_InvalidProperty = 0xFF,
};
//! @brief Property constants.
enum _property_constants
{
kProperty_ReservedRegionsCount = 2,
kProperty_FlashReservedRegionIndex = 0,
kProperty_RamReservedRegionIndex = 1,
kProperty_FlashVersionIdSizeInBytes = 8,
};
//! @brief Bit positions for clock flags in configuration data.
enum _clock_flags
{
kClockFlag_HighSpeed = (1 << 0)
};
//! @brief Bit positions for boot flags in configuration data
enum _boot_flags
{
kBootFlag_DirectBoot = (1 << 0)
};
#if !defined(BOOTLOADER_HOST)
//! @brief Flash constants.
enum _flash_constants
{
//! @brief The bootloader configuration data location .
//!
//! A User Application should populate a BootloaderConfigurationData
//! struct at 0x3c0 from the beginning of the application image which must
//! be the User Application vector table for the flash-resident bootloader
//! collaboration.
kBootloaderConfigAreaAddress = (uint32_t)(APP_VECTOR_TABLE) + 0x3c0
};
#endif // BOOTLOADER_HOST
//! @brief Format of bootloader configuration data on Flash.
typedef struct BootloaderConfigurationData
{
uint32_t tag; //!< [00:03] Tag value used to validate the bootloader configuration data. Must be set to 'kcfg'.
uint32_t crcStartAddress; //!< [04:07]
uint32_t crcByteCount; //!< [08:0b]
uint32_t crcExpectedValue; //!< [0c:0f]
uint8_t enabledPeripherals; //!< [10:10]
uint8_t i2cSlaveAddress; //!< [11:11]
uint16_t peripheralDetectionTimeoutMs; //!< [12:13] Timeout in milliseconds for peripheral detection before jumping
//! to application code
uint16_t usbVid; //!< [14:15]
uint16_t usbPid; //!< [16:17]
uint32_t usbStringsPointer; //!< [18:1b]
uint8_t clockFlags; //!< [1c:1c] High Speed and other clock options
uint8_t clockDivider; //!< [1d:1d] One's complement of clock divider, zero divider is divide by 1
uint8_t bootFlags; //!< [1e:1e] One's complemnt of direct boot flag, 0xFE represents direct boot
uint8_t pad0; //!< [1f:1f] Reserved, set to 0xFF
uint32_t mmcauConfigPointer; //!< [20:23] Holds a pointer value to the MMCAU configuration
uint32_t keyBlobPointer; //!< [24:27] Holds a pointer value to the key blob array used to configure OTFAD
uint8_t pad1; //!< [28:28] reserved
uint8_t canConfig1; //!< [29:29] ClkSel[1], PropSeg[3], SpeedIndex[4]
uint16_t canConfig2; //!< [2a:2b] Pdiv[8], Pseg1[3], Pseg2[3], rjw[2]
uint16_t canTxId; //!< [2c:2d] txId
uint16_t canRxId; //!< [2e:2f] rxId
uint32_t qspi_config_block_pointer; //!< [30:33] QSPI config block pointer.
} bootloader_configuration_data_t;
//! @brief Structure of a reserved regions entry.
typedef struct ReservedRegion
{
uint32_t startAddress;
uint32_t endAddress;
} reserved_region_t;
//! @brief Structure of a unique device id.
typedef struct UniqueDeviceId
{
uint32_t uidl;
uint32_t uidml;
uint32_t uidmh;
#if defined(BOOTLOADER_HOST) | defined(SIM_UIDH)
uint32_t uidh;
#endif
} unique_device_id_t;
//! @brief External Memory Properties tag
enum _external_memory_property_tags
{
kExternalMemoryPropertyTag_InitStatus = 0, //!< Init status tag
kExternalMemoryPropertyTag_StartAddress = 1, //!< Start address tag
kExternalMemoryPropertyTag_MemorySizeInKbytes = 2, //!< Memory size tag
kExternalMemoryPropertyTag_PageSize = 3, //!< Pag size tag
kExternalMemoryPropertyTag_SectorSize = 4, //!< Sector size tag
kExternalMemoryPropertyTag_BlockSize = 5, //!< Block size tag
kExternalMemoryPropertyTag_Start = kExternalMemoryPropertyTag_StartAddress,
kExternalMemoryPropertyTag_End = kExternalMemoryPropertyTag_BlockSize,
};
//! @brief Exernal Memory attribute store
typedef struct
{
uint32_t availableAttributesFlag; //!< Available Atrributes, bit map
uint32_t startAddress; //!< start Address of external memory
uint32_t flashSizeInKB; //!< flash size of external memory
uint32_t pageSize; //!< page size of external memory
uint32_t sectorSize; //!< sector size of external memory
uint32_t blockSize; //!< block size of external memory
} external_memory_property_store_t;
enum _ram_constants
{
#if CPU_IS_ARM_CORTEX_M7
kRAMCount = 3,
#else
kRAMCount = 1,
#endif
};
//! @brief Structure of property store.
typedef struct PropertyStore
{
standard_version_t bootloaderVersion; //!< Current bootloader version.
standard_version_t serialProtocolVersion; //!< Serial protocol version number.
standard_version_t targetVersion; //!< Target version number.
uint32_t availablePeripherals; //!< The set of peripherals supported available on this chip. See enum
//!_peripheral_types in bl_peripheral.h.
uint32_t flashStartAddress; //!< Start address of program flash.
uint32_t flashSizeInBytes; //!< Size in bytes of program flash.
uint32_t flashSectorSize; //!< The size in bytes of one sector of program flash. This is the minimum erase size.
uint32_t flashBlockSize; //!< The size in bytes of one block of program flash.
uint32_t flashBlockCount; //!< Number of blocks in the flash array.
uint32_t ramStartAddress[kRAMCount]; //!< Start address of RAM
uint32_t ramSizeInBytes[kRAMCount]; //!< Size in bytes of RAM
uint32_t crcCheckStatus; //!< Status code from the last CRC check operation.
uint32_t verifyWrites; //!< Boolean controlling whether the bootloader will verify writes to flash. Non-zero enables
//! verificaton. Writable by host.
uint32_t availableCommands; //!< Bit mask of the available commands.
unique_device_id_t UniqueDeviceId; //!< Unique identification for the device.
uint32_t flashFacSupport; //!< Boolean indicating whether the FAC feature is supported
uint32_t flashAccessSegmentSize; //!< The size in bytes of one segment of flash
uint32_t flashAccessSegmentCount; //!< The count of flash access segment within flash module
uint32_t flashReadMargin; //!< The margin level setting for flash erase and program Verify CMDs
uint32_t qspiInitStatus; //!< Result of QSPI+OTFAD init during bootloader startup
reserved_region_t reservedRegions[kProperty_ReservedRegionsCount]; //!< Flash and Ram reserved regions.
bootloader_configuration_data_t
configurationData; //!< Configuration data from flash address 0x3c0-0x3ff in sector 0 (64 bytes max)
external_memory_property_store_t externalMemoryPropertyStore; //!< Property store for external memory
uint32_t reliableUpdateStatus; //!< Status of reliable update
} property_store_t;
enum _property_store_tags
{
//! @brief Tag value used to validate the bootloader configuration data.
kPropertyStoreTag = FOUR_CHAR_CODE('k', 'c', 'f', 'g')
};
//! @brief External Memory properties interface
typedef struct ExternalMemoryPropertyInterface
{
uint32_t memoryId;
status_t (*get)(uint32_t tag, uint32_t *value);
} external_memory_property_interface_t;
//! @brief Interface to property operations.
typedef struct PropertyInterface
{
status_t (*load_user_config)(void); //!< Load the user configuration data
status_t (*init)(void); //!< Initialize
status_t (*get)(uint8_t tag, uint8_t id, const void **value, uint32_t *valueSize); //!< Get property
status_t (*set_uint32)(uint8_t tag, uint32_t value); //!< Set uint32_t property
property_store_t *store; //!< The property store
} property_interface_t;
////////////////////////////////////////////////////////////////////////////////
// Externs
////////////////////////////////////////////////////////////////////////////////
//! @brief Property interface.
extern const property_interface_t g_propertyInterface;
////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
#if __cplusplus
extern "C" {
#endif
//! @name Property Store
//@{
//! @brief Early initialization function to get user configuration data
status_t bootloader_property_load_user_config(void);
//! @brief Initialize the property store.
status_t bootloader_property_init(void);
//! @brief Get a property.
//!
//! Example calling sequence for uint32_t property:
//! @code
//! void * value;
//! uint32_t valueSize;
//! status_t status = bootloader_property_get(sometag, &value, &valueSize);
//! uint32_t result = *(uint32_t *)value;
//! @endcode
//!
//! @param tag Tag of the requested property
//! @param memoryId Id for specified external memory, for example: 1 represent QuadSPI 0
//! @param value Pointer to where to write a pointer to the result, may be NULL
//! @param valueSize Size in bytes of the property value, may be NULL
//!
//! @retval kStatus_Success
//! @retval kStatus_UnknownProperty
status_t bootloader_property_get(uint8_t tag, uint8_t memoryId, const void **value, uint32_t *valueSize);
//! @brief Set a property.
//!
//! Only uint32_t properties can be set with this function.
//!
//! @param tag Tag of the property to set
//! @param value New property value
//!
//! @retval kStatus_Success
//! @retval kStatus_UnknownProperty
//! @retval kStatus_ReadOnlyProperty
status_t bootloader_property_set_uint32(uint8_t tag, uint32_t value);
//@}
#if __cplusplus
}
#endif
//! @}
#endif // _property_h

View File

@@ -0,0 +1,39 @@
#if !defined(__TARGET_CONFIG_H__)
#define __TARGET_CONFIG_H__
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief Constants for clock frequencies.
enum _target_clocks
{
kDefaultClock = 20971520u,
kHIRC = 48000000u,
kMinCoreClockWithUsbSupport = 20000000u,
kMaxCoreClock = 120000000u,
kMaxBusClock = 60000000u,
kMaxFlexBusClock = 50000000u,
kMaxFlashClock = 25000000u,
kDivider_Min = 1,
kDivider_Max = 16,
};
//! @brief Constants for sram partition
enum _sram_partition
{
kSram_LowerPart = 1,
kSram_UpperPart = 1,
};
//! @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,234 @@
#if !defined(__FSL_RTOS_ABSTRACTION_H__)
#define __FSL_RTOS_ABSTRACTION_H__
#include <stdint.h>
#include <stdbool.h>
//! @addtogroup rtos_irq_sync
//! @{
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
typedef enum _osa_status_t
{
kStatus_OSA_Success = 0U, /*!< Success */
kStatus_OSA_Error = 1U, /*!< Failed */
kStatus_OSA_Timeout = 2U, /*!< Timeout occurs while waiting */
kStatus_OSA_Idle = 3U /*!< Used for bare metal only, the wait object is not ready
and timeout still not occur */
} osa_status_t;
typedef struct Semaphore
{
volatile bool isWaiting; /*!< Is any task waiting for a timeout on this object */
volatile uint8_t semCount; /*!< The count value of the object */
uint64_t tickStart; /*!< The ticks to start timeout */
uint32_t timeout; /*!< Timeout to wait in milliseconds */
} semaphore_t;
//! @brief Type for an interrupt synchronization object.
typedef volatile int32_t sync_object_t;
//! @brief Type for an interrupt lock object.
typedef volatile uint32_t lock_object_t;
enum sync_timeouts
{
//! @brief Constant to pass for the sync_wait() timeout in order to wait indefinitely.
kSyncWaitForever = 0xffffffffU
};
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C" {
#endif
//! @name Interrupt handler synchronization
//@{
/*!
* @name Counting Semaphore
* @{
*/
/*!
* @brief Creates a semaphore with a given value.
*
* This function creates a semaphore and sets the value to the parameter
* initValue.
*
* @param pSem Pointer to the semaphore.
* @param initValue Initial value the semaphore will be set to.
*
* @retval kStatus_OSA_Success The semaphore is created successfully.
* @retval kStatus_OSA_Error The semaphore can not be created.
*
* Example:
@code
semaphore_t mySem;
OSA_SemaCreate(&mySem, 0);
@endcode
*
*/
osa_status_t OSA_SemaCreate(semaphore_t *pSem, uint8_t initValue);
/*!
* @brief Pending a semaphore with timeout.
*
* This function checks the semaphore's counting value. If it is positive,
* decreases it and returns kStatus_OSA_Success. Otherwise, a timeout is used
* to wait.
*
* @param pSem Pointer to the semaphore.
* @param timeout The maximum number of milliseconds to wait if semaphore is not
* positive. Pass OSA_WAIT_FOREVER to wait indefinitely, pass 0
* will return kStatus_OSA_Timeout immediately.
*
* @retval kStatus_OSA_Success The semaphore is received.
* @retval kStatus_OSA_Timeout The semaphore is not received within the specified 'timeout'.
* @retval kStatus_OSA_Error An incorrect parameter was passed.
* @retval kStatus_OSA_Idle The semaphore is not available and 'timeout' is not exhausted,
* This is only for bare metal.
*
* @note With bare metal, a semaphore can not be waited by more than one task
* at the same time.
*
* Example:
* @code
osa_status_t status;
status = OSA_SemaWait(&mySem, 100);
switch(status)
{
//...
}
@endcode
*
*/
osa_status_t OSA_SemaWait(semaphore_t *pSem, uint32_t timeout);
/*!
* @brief Signals for someone waiting on the semaphore to wake up.
*
* Wakes up one task that is waiting on the semaphore. If no task is waiting, increases
* the semaphore's counting value.
*
* @param pSem Pointer to the semaphore to signal.
*
* @retval kStatus_OSA_Success The semaphore is successfully signaled.
* @retval kStatus_OSA_Error The object can not be signaled or invalid parameter.
*
* Example:
* @code
osa_status_t status;
status = OSA_SemaPost(&mySem);
switch(status)
{
//...
}
@endcode
*
*/
osa_status_t OSA_SemaPost(semaphore_t *pSem);
/*!
* @brief Destroys a previously created semaphore.
*
* @param pSem Pointer to the semaphore to destroy.
*
* @retval kStatus_OSA_Success The semaphore is successfully destroyed.
* @retval kStatus_OSA_Error The semaphore can not be destroyed.
*
* Example:
* @code
osa_status_t status;
status = OSA_SemaDestroy(&mySem);
switch(status)
{
//...
}
@endcode
*
*/
osa_status_t OSA_SemaDestroy(semaphore_t *pSem);
/*!
* @brief Delays execution for a number of milliseconds.
*
* @param delay The time in milliseconds to wait.
*/
void OSA_TimeDelay(uint32_t delay);
//@}
//! @}
//! @name Interrupt handler synchronization
//@{
/*!
* @brief Initialize a synchronization object to a given state.
*
* @param obj The sync object to initialize.
* @param state The initial state of the object. Pass true to make the sync object start
* out locked, or false to make it unlocked.
*/
void sync_init(sync_object_t *obj, bool state);
/*!
* @brief Wait for a synchronization object to be signalled.
*
* @param obj The synchronization object.
* @param timeout The maximum number of milliseconds to wait for the object to be signalled.
* Pass the #kSyncWaitForever constant to wait indefinitely for someone to signal the object.
* If 0 is passed for this timeout, then the function will return immediately if the object
* is locked.
*
* @retval true The object was signalled.
* @retval false A timeout occurred.
*/
bool sync_wait(sync_object_t *obj, uint32_t timeout);
/*!
* @brief Signal for someone waiting on the syncronization object to wake up.
*
* @param obj The synchronization object to signal.
*/
void sync_signal(sync_object_t *obj);
/*!
* @brief Reset the synchronization object
*
* @param obj The synchronization object to signal.
*/
void sync_reset(sync_object_t *obj);
//@}
//! @addtogroup irq_lock
//! @{
//! @name Interrupt handler lock
//@{
//! @brief Initialize the lock object
void lock_init(void);
//! @brief Disable global irq and store previous state.
void lock_acquire(void);
//! @brief Restore previous state.
void lock_release(void);
//@}
//! @}
#if defined(__cplusplus)
}
#endif
#endif // __FSL_RTOS_ABSTRACTION_H__